blob: 479856e703dcc17a48ac621945c9023a9adce64d [file] [log] [blame]
<!doctype html>
<html class="no-js" lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Editing and Navigating C/C++ Source Files - NetBeans IDE Tutorial</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Editing and Navigating C/C++ Source Files - NetBeans IDE Tutorial - Apache NetBeans">
<meta name="author" content="Apache NetBeans">
<meta name="description" content="Editing and Navigating C/C++ Source Files - NetBeans IDE Tutorial - Apache NetBeans">
<meta name="keywords" content="Apache NetBeans, Tutorials, Editing and Navigating C/C++ Source Files - NetBeans IDE Tutorial">
<meta name="generator" content="Apache NetBeans">
<link rel="stylesheet" href="../../../../../../_/css/font-awesome.min.css">
<link rel="alternate" type="application/atom+xml" title="Apache NetBeans Blog" href="https://netbeans.apache.org/blogs/atom" />
<link rel="stylesheet" href="../../../../../../_/css/highlightjs/default.min.css">
<link rel="stylesheet" href="../../../../../../_/css/netbeans.css">
<link rel="apple-touch-icon" sizes="180x180" href="../../../../../../_/images/fav/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="../../../../../../_/images/fav/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="../../../../../../_/images/fav/favicon-16x16.png">
<link rel="manifest" href="../../../../../../_/images/fav/site.webmanifest">
<link rel="mask-icon" href="../../../../../../_/images/fav/safari-pinned-tab.svg" color="#5bbad5">
<meta name="msapplication-TileColor" content="#ffc40d">
<meta name="theme-color" content="#ffffff">
<link href="../../../../../../_/css/font-open-sans.css" rel="stylesheet">
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
</head>
<body>
<div class="title-bar" data-responsive-toggle="responsive-menu" data-hide-for="medium">
<button type="button" data-toggle="responsive-menu"><i style='font-size: 32px; color: #fff; padding: 8px' class='fa fa-bars'></i></button>
<div class="title-bar-title">Apache NetBeans</div>
</div>
<div class="top-bar" id="responsive-menu">
<div class='top-bar-left'>
<a class='title' href="../../../../../../index.html"><img src='../../../../../../_/images/apache-netbeans.svg' style='padding: 8px; height: 48px;'> Apache NetBeans</a>
</div>
<div class="top-bar-right">
<ul class="vertical medium-horizontal menu" data-responsive-menu="drilldown medium-dropdown">
<li> <input id="search-input" type="text" placeholder="Search the docs"> </li>
<li> <a href="../../../../../../front/main/community">Community</a> </li>
<li> <a href="../../../../../../front/main/participate">Participate</a> </li>
<li> <a href="../../../../../../front/main/blogs">Blog</a></li>
<li> <a href="../../../../../../front/main/help">Get Help</a> </li>
<li> <a href="https://plugins.netbeans.apache.org/">Plugins</a> </li>
<li> <a href="../../../../../../front/main/download">Download</a> </li>
</ul>
</div>
</div>
<!-- src/templates/news -->
<section class="hero news alternate">
<div class='grid-container'>
<div class='cell'>
<div class="annotation">Latest release</div>
<h1>Apache NetBeans 27</h1>
<p><a class="button success" href="../../../../../../front/main/download/nb27">Download</a></p>
</div>
</div>
</section>
<div class='grid-container main-content tutorial'>
<article class="doc">
<h1 class="sect0">Editing and Navigating C/C++ Source Files - NetBeans IDE Tutorial</h1>
<div class="sectionbody">
<div class="admonitionblock note">
<table>
<tbody><tr>
<td class="icon"><i class="fa icon-note" title="Note"></i></td>
<td class="content">This tutorial needs a review.
You can <a href="https://github.com/apache/netbeans-antora-tutorials/edit/main/modules/ROOT/pages/kb/docs/cnd/navigating-editing.adoc" title="Edit this tutorial in github">edit it in GitHub </a>
following these <a href="../../../../../../tutorial/main/kb/docs/contributing">contribution guidelines.</a></td>
</tr></tbody>
</table>
</div>
</div>
<div id="toc" class="toc">
<div id="toctitle"></div>
<ul class="sectlevel1">
<li><a href="#_requirements">Requirements</a></li>
<li><a href="#_creating_the_sample_project">Creating the Sample Project</a></li>
<li><a href="#_editing_c_and_c_source_files">Editing C and C++ Source Files</a>
<ul class="sectlevel2">
<li><a href="#_setting_the_formatting_style">Setting the Formatting Style</a></li>
<li><a href="#_folding_blocks_of_code_in_c_and_c_files">Folding Blocks of Code in C and C++ Files</a></li>
<li><a href="#_using_semantic_highlighting">Using Semantic Highlighting</a></li>
<li><a href="#_using_code_completion_and_documentation">Using Code Completion and Documentation</a></li>
<li><a href="#_adding_source_code_documentation">Adding Source Code Documentation</a></li>
<li><a href="#_using_code_templates">Using Code Templates</a></li>
<li><a href="#_using_pair_completion">Using Pair Completion</a></li>
<li><a href="#_finding_text_in_project_files">Finding Text in Project Files</a></li>
</ul>
</li>
<li><a href="#_navigating_c_and_c_source_files">Navigating C and C++ Source Files</a>
<ul class="sectlevel2">
<li><a href="#_using_the_classes_window">Using the Classes Window</a></li>
<li><a href="#_using_the_navigator_window">Using the Navigator Window</a></li>
<li><a href="#_finding_class_method_and_field_usages">Finding Class, Method, and Field Usages</a></li>
<li><a href="#_using_the_call_graph">Using the Call Graph</a></li>
<li><a href="#_using_hyperlinks">Using Hyperlinks</a></li>
<li><a href="#_using_the_includes_hierarchy">Using the Includes Hierarchy</a></li>
<li><a href="#_using_the_type_hierarchy">Using the Type Hierarchy</a></li>
</ul>
</li>
<li><a href="#_next_steps">Next Steps</a></li>
</ul>
</div>
<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>The following short tutorial takes you through some of the features for navigating and editing the source files in a C or C++ project in NetBeans IDE.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_requirements"><a class="anchor" href="#_requirements"></a>Requirements</h2>
<div class="sectionbody">
<div class="paragraph">
<p><strong>To follow this tutorial, you need the following software and resources.</strong></p>
</div>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Software or Resource</th>
<th class="tableblock halign-left valign-top">Version Required</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">NetBeans IDE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">xref../../../download/index.adoc[ version 7.4 or 8.0 with NetBeans C/C&#43;&#43; plugin]</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Java Developer Kit (JDK)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://www.oracle.com/java/technologies/downloads/">version 7 or 8</a></p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>See the <a href="../../../../../../front/main/download/" class="xref page">NetBeans IDE 8.0 Installation Instructions</a> and <a href="../cpp-setup-instructions/" class="xref page">Configuring the NetBeans IDE for C/C&#43;&#43;/Fortran</a>
for information about downloading and installing the required software.</p>
</div>
<div class="paragraph">
<p><strong>Sample Projects</strong></p>
</div>
<div class="paragraph">
<p>Just want to play with some projects? In the IDE, choose File &gt; New Project, then open the Samples category and the C/C&#43;&#43; subcategory. The IDE provides several sample C and C++ projects to help you familiarize yourself with the IDE.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_creating_the_sample_project"><a class="anchor" href="#_creating_the_sample_project"></a>Creating the Sample Project</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The NetBeans IDE with the C/C&#43;&#43; plugin provides advanced editing features for modifying your source code. To explore these features, we&#8217;ll use the <code>Quote</code> project. If you have not already created this project, do the following:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Choose File &gt; New Project.</p>
</li>
<li>
<p>In the project wizard, expand the Samples category and select the C/C++ subcategory.</p>
</li>
<li>
<p>Select the <code>Quote</code> project. Click Next, then click Finish.</p>
</li>
</ol>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_editing_c_and_c_source_files"><a class="anchor" href="#_editing_c_and_c_source_files"></a>Editing C and C++ Source Files</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_setting_the_formatting_style"><a class="anchor" href="#_setting_the_formatting_style"></a>Setting the Formatting Style</h3>
<div class="paragraph">
<p>You can use the Options window to configure default formatting style for your C and C++ projects.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Choose Tools &gt; Options.</p>
</li>
<li>
<p>Click Editor in the top pane of the window.</p>
</li>
<li>
<p>Click the Formatting tab.</p>
</li>
<li>
<p>Select the C language from the Language drop-down list because the Quote project uses C.</p>
</li>
<li>
<p>Select the style you want to set from the Style drop-down list.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/formatting_style.png" alt="formatting style">
</div>
</div>
<div class="olist arabic">
<ol class="arabic" start="6">
<li>
<p>Modify the style properties as desired.</p>
</li>
</ol>
</div>
</div>
<div class="sect2">
<h3 id="_folding_blocks_of_code_in_c_and_c_files"><a class="anchor" href="#_folding_blocks_of_code_in_c_and_c_files"></a>Folding Blocks of Code in C and C++ Files</h3>
<div class="paragraph">
<p>For some types of files, you can use the code folding feature to collapse blocks of code so that only the first line of the block appears in the Source Editor.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>In the <code>Quote_1</code> application project, open the Source Files folder, then double-click the <code>cpu.cc</code> file to open it in the Source Editor.</p>
</li>
<li>
<p>Click the collapse icon (small box with minus sign) in the left margin to fold the code of one of the methods.</p>
</li>
<li>
<p>Mouse over the <code>{&#8230;&#8203;}</code> symbol to the right of the folded block to display the code in the block.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/code_folding.png" alt="code folding">
</div>
</div>
</div>
<div class="sect2">
<h3 id="_using_semantic_highlighting"><a class="anchor" href="#_using_semantic_highlighting"></a>Using Semantic Highlighting</h3>
<div class="paragraph">
<p>You can set an option so that when you click on a class, function, variable, or macro, all occurrences of that class, function, variable, or macro in the current file are highlighted.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Choose Tools &gt; Options.</p>
</li>
<li>
<p>Click Editor in the top pane of the window.</p>
</li>
<li>
<p>Click the Highlighting tab.</p>
</li>
<li>
<p>Make sure that all of the check boxes contain checkmarks.</p>
</li>
<li>
<p>Click OK.</p>
</li>
<li>
<p>In the <code>customer.cc</code> file of the <code>Quote_1</code> project, notice that the method names are highlighted in bold.</p>
</li>
<li>
<p>Click on an occurrence of the <code>Customer</code> class.</p>
</li>
<li>
<p>All of the occurrences of the <code>Customer</code> class in the file are highlighted with a yellow background. The right margin also shows markings that indicate points where an occurrence is located in the file. The markings let you see how many occurrences there are without scrolling through the file. You can click the markings to jump to the occurrences that they represent.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/highlighting1.png" alt="highlighting1">
</div>
</div>
<div class="olist arabic">
<ol class="arabic" start="9">
<li>
<p>To easily navigate between the occurrences, press Alt+Down to go to the next occurrence, and press Alt+Up to go to the previous occurrence.</p>
</li>
</ol>
</div>
<div class="olist arabic">
<ol class="arabic" start="10">
<li>
<p>Open the <code>customer.h</code> file, located in the Headers folder, and notice that class names are again highlighted in bold.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/highlighting2.png" alt="highlighting2">
</div>
</div>
</div>
<div class="sect2">
<h3 id="_using_code_completion_and_documentation"><a class="anchor" href="#_using_code_completion_and_documentation"></a>Using Code Completion and Documentation</h3>
<div class="paragraph">
<p>The IDE has a dynamic C and C++ code completion feature that enables you to type one or more characters and then see a list of possible classes, methods, variables, and so on that can be used to complete the expression.</p>
</div>
<div class="paragraph">
<p>The IDE also dynamically searches for documentation for the classes, functions, methods and so on, and displays the documentation in a popup window.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Open the <code>quote.cc</code> file in the <code>Quote_1</code> project.</p>
</li>
<li>
<p>On the first blank line of the <code>quote.cc</code> , type a capital C and press Ctrl-Space. The code completion box displays a short list that includes the <code>Cpu</code> and <code>Customer</code> classes. A documentation window also opens but displays "No documentation found" because the project source does not include documentation for its code.</p>
</li>
<li>
<p>Expand the list of items by pressing Ctrl-Space again.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/code_completion1.png" alt="code completion1">
</div>
</div>
<div class="olist arabic">
<ol class="arabic" start="4">
<li>
<p>Use your arrow keys or mouse to highlight a standard library function such as <code>calloc</code> from the list, and the documentation window displays the man page for that function if the man page is accessible to the IDE.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/code-completion-documentation.png" alt="code completion documentation">
</div>
</div>
<div class="olist arabic">
<ol class="arabic" start="5">
<li>
<p>Select the <code>Customer</code> class and press Enter.</p>
</li>
</ol>
</div>
<div class="olist arabic">
<ol class="arabic" start="6">
<li>
<p>Complete the new instance of the <code>Customer</code> class by typing " <code>andrew;</code> ". On the next line, type the letter <code>a</code> and press Ctrl-Space twice. The code completion box displays a list of choices starting with the letter <code>a</code> , such as method arguments, class fields, and global names, that are accessible from the current context.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/code_completion2.png" alt="code completion2">
</div>
</div>
<div class="olist arabic">
<ol class="arabic" start="7">
<li>
<p>Double-click the <code>andrew</code> option to accept it and type a period after it. Press Ctrl-Space and you are provided with a list of the public methods and fields of the <code>Customer</code> class.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/code_completion3.png" alt="code completion3">
</div>
</div>
<div class="olist arabic">
<ol class="arabic" start="8">
<li>
<p>Delete the code you have added.</p>
</li>
</ol>
</div>
</div>
<div class="sect2">
<h3 id="_adding_source_code_documentation"><a class="anchor" href="#_adding_source_code_documentation"></a>Adding Source Code Documentation</h3>
<div class="paragraph">
<p>You can add comments to your code to automatically generate documentation for your functions, classes, and methods. The IDE recognizes comments that use Doxygen syntax and automatically generates documentation. The IDE can also automatically generate a comment block to document the function below the comment.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>In the <code>quote.cc</code> file, place your cursor on line 75, or the line above the line
<code>int readNumberOf(const char* item, int min, int max) {</code></p>
</li>
</ol>
</div>
<div class="olist arabic">
<ol class="arabic" start="2">
<li>
<p>Type a slash and two asterisks and press Enter. The editor inserts a Doxygen-formatted comment for the <code>readNumberOf</code> class.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/doxygen_comment.png" alt="doxygen comment">
</div>
</div>
<div class="olist arabic">
<ol class="arabic" start="3">
<li>
<p>Add some descriptive text to each of the @param lines and save the file.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/doxygen_comment_edited.png" alt="doxygen comment edited">
</div>
</div>
<div class="olist arabic">
<ol class="arabic" start="4">
<li>
<p>Click the <code>readNumberOf</code> class to highlight it in yellow, and click one of the occurrences marks on the right to jump to a location where the class is used.</p>
</li>
</ol>
</div>
<div class="olist arabic">
<ol class="arabic" start="5">
<li>
<p>Click the <code>readNumberOf</code> class in the line you jumped to, and press Ctrl-Shift-Space to show the documentation that you just added for the parameters.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/doxygen_displayed.png" alt="doxygen displayed">
</div>
</div>
<div class="olist arabic">
<ol class="arabic" start="6">
<li>
<p>Click anywhere else in the file to close the documentation window, and click on the <code>readNumberOf</code> class again.</p>
</li>
</ol>
</div>
<div class="olist arabic">
<ol class="arabic" start="7">
<li>
<p>Choose Source &gt; Show Documentation to open the documentation window for the class again.</p>
</li>
</ol>
</div>
</div>
<div class="sect2">
<h3 id="_using_code_templates"><a class="anchor" href="#_using_code_templates"></a>Using Code Templates</h3>
<div class="paragraph">
<p>The Source Editor has a set of customizable code templates for common snippets of C and C++ code. You can generate the full code snippet by typing its abbreviation and pressing the Tab key. For example, in the <code>quote.cc</code> file of the <code>Quote</code> project:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Type <code>uns</code> followed by a tab and <code>uns</code> expands to <code>unsigned</code> .</p>
</li>
<li>
<p>Type <code>iff</code> followed by a tab and <code>iff</code> expands to <code>if (exp) {}</code> .</p>
</li>
<li>
<p>Type <code>ife</code> followed by a tab and <code>ife</code> expands to <code>if (exp) {} else {}</code> .</p>
</li>
<li>
<p>Type <code>fori</code> followed by a tab and <code>fori</code> expands to <code>for (int i = 0; i &lt; size; i++) { Object elem = array[i];</code> .</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>To see all the available code templates, modify the code templates, create your own code templates, or select a different key to expand the code templates:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Choose Tools &gt; Options.</p>
</li>
<li>
<p>In the Options dialog box, select Editor, and click the Code Templates tab.</p>
</li>
<li>
<p>Select the appropriate language from the Language drop-down list.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/code_templates.png" alt="code templates">
</div>
</div>
</div>
<div class="sect2">
<h3 id="_using_pair_completion"><a class="anchor" href="#_using_pair_completion"></a>Using Pair Completion</h3>
<div class="paragraph">
<p>When you edit your C and C++ source files, the Source Editor does "smart" matching of pair characters such as brackets, parentheses, and quotation marks. When you type one of these characters, the Source Editor automatically inserts the closing character.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>In the <code>Quote_1</code> project, place the cursor on the blank line 115 of the <code>module.cc</code> file and press Return to open a new line.</p>
</li>
<li>
<p>Type <code>enum state {</code> and press Return. The closing curly bracket and semi-colon are added automatically and the cursor is placed on the line between the brackets.</p>
</li>
<li>
<p>Type <code>invalid=0, success=1</code> on the line between the brackets to complete the enumeration.</p>
</li>
<li>
<p>On the line after the closing <code>};</code> of the enumeration, type <code>if (</code> and you should see that a closing parenthesis is added automatically and the cursor is placed between the parentheses.</p>
</li>
<li>
<p>Type <code>v==null</code> between the parentheses. Then type <code> {</code> and newline after the right parenthesis. The closing bracket is added automatically.</p>
</li>
<li>
<p>Delete the code you have added.</p>
</li>
</ol>
</div>
</div>
<div class="sect2">
<h3 id="_finding_text_in_project_files"><a class="anchor" href="#_finding_text_in_project_files"></a>Finding Text in Project Files</h3>
<div class="paragraph">
<p>You can use the Find In Projects dialog box to search projects for instances of specified text or a regular expression.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Open the Find In Projects dialog box by doing one of the following:</p>
<div class="ulist">
<ul>
<li>
<p>Choose Edit &gt; Find In Projects.</p>
</li>
<li>
<p>Right-click a project in the Projects window and choose Find.</p>
</li>
<li>
<p>Press Ctrl+Shift+F.</p>
</li>
</ul>
</div>
</li>
</ol>
</div>
<div class="olist arabic">
<ol class="arabic" start="2">
<li>
<p>In the Find In Projects dialog box, select the Default Search tab or the Grep tab. The Grep tab uses the <code>grep</code> utility, which provides a faster search, especially for remote projects.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/find_in_projects.png" alt="find in projects">
</div>
</div>
<div class="olist arabic">
<ol class="arabic" start="3">
<li>
<p>In the Grep tab, type the text or regular expression for which you want to search, specify the search scope and file name pattern, and select the check box Open in New Tab so you can save multiple searches in separate tabs.</p>
</li>
</ol>
</div>
<div class="olist arabic">
<ol class="arabic" start="4">
<li>
<p>Click Find.
The Search Results tab lists the files in which the text or regular expression is found.</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>Buttons in the left margin enable you to change your view of the search results.</p>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/find_in_projects2.png" alt="find in projects2">
</div>
</div>
<div class="olist arabic">
<ol class="arabic" start="5">
<li>
<p>Click the Expand/Collapse button to collapse the list of files so only the filenames are shown. Click the other buttons to show the search results as a directory tree or as a list of files. These options are useful when you perform a search across multiple projects.</p>
</li>
</ol>
</div>
<div class="olist arabic">
<ol class="arabic" start="6">
<li>
<p>Double-click one of the items in the list and the IDE takes you to the corresponding location in the source editor.</p>
</li>
</ol>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_navigating_c_and_c_source_files"><a class="anchor" href="#_navigating_c_and_c_source_files"></a>Navigating C and C++ Source Files</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The NetBeans IDE with the C/C++ plugin provides advanced navigation features for viewing your source code. To explore these features, continue using the <code>Quote_1</code> project.</p>
</div>
<div class="sect2">
<h3 id="_using_the_classes_window"><a class="anchor" href="#_using_the_classes_window"></a>Using the Classes Window</h3>
<div class="paragraph">
<p>The Classes window lets you see all of the classes in your project, and the members and fields for each class.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Click the Classes tab to display the Classes window. If the Classes tab is not displayed, choose Window &gt; Classes</p>
</li>
<li>
<p>Expand the <code>Quote_1</code> node in the Classes window. All classes in the project are listed.</p>
</li>
<li>
<p>Expand the <code>Customer</code> class.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/classes_window.png" alt="classes window">
</div>
</div>
<div class="olist arabic">
<ol class="arabic" start="4">
<li>
<p>Double-click the <code>name</code> variable to open the <code>customer.h</code> header file.</p>
</li>
</ol>
</div>
</div>
<div class="sect2">
<h3 id="_using_the_navigator_window"><a class="anchor" href="#_using_the_navigator_window"></a>Using the Navigator Window</h3>
<div class="paragraph">
<p>The Navigator window provides a compact view of the file that is currently selected, and simplifies navigation between different parts of the file. If the Navigator window is not displayed, choose Window &gt; Navigating &gt; Navigator to open it.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Click anywhere in the <code>quote.cc</code> file in the Editor window.</p>
</li>
<li>
<p>A compact view of the file is displayed in the Navigator window.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/navigator_window.png" alt="navigator window">
</div>
</div>
<div class="olist arabic">
<ol class="arabic" start="3">
<li>
<p>To navigate to an element of the file, double-click the element in the Navigator window and the cursor in the Editor window moves to that element.</p>
</li>
</ol>
</div>
<div class="olist arabic">
<ol class="arabic" start="4">
<li>
<p>Right-click in the Navigator to choose a different way to sort the elements, or group the items, or filter them.</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>To find out what the icons in the Navigator represent, open the IDE online help by choosing Help &gt; Help Contents, and search for "navigator icons" in the help window.</p>
</div>
</div>
<div class="sect2">
<h3 id="_finding_class_method_and_field_usages"><a class="anchor" href="#_finding_class_method_and_field_usages"></a>Finding Class, Method, and Field Usages</h3>
<div class="paragraph">
<p>You can use the Usages window to show you everywhere a class (structure), function, variable, macro, or file is used in your project&#8217;s source code.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>In the <code>customer.cc</code> file, right-click the <code>Customer</code> class on line 42, and choose Find Usages.</p>
</li>
<li>
<p>In the Find Usages dialog box, click Find.</p>
</li>
<li>
<p>The Usages window opens and displays all of the usages of the <code>Customer</code> class in the source files of the project.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/usages_window.png" alt="usages window">
</div>
</div>
<div class="olist arabic">
<ol class="arabic" start="4">
<li>
<p>Click the arrow buttons in the left margin to step through the occurrences and show them in the Editor, or change between logical and physical view. You can also filter the information using a second column of buttons in the left margin.</p>
</li>
</ol>
</div>
</div>
<div class="sect2">
<h3 id="_using_the_call_graph"><a class="anchor" href="#_using_the_call_graph"></a>Using the Call Graph</h3>
<div class="paragraph">
<p>The Call Graph window displays two views of the calling relationships between functions in the project. A tree view shows the functions called from a selected function, or the functions that call the selected function. A graphical view shows the calling relationships using arrows between the called and calling functions.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>In the <code>quote.cc</code> file, right-click on the <code>main</code> function and choose Show Call Graph.</p>
</li>
<li>
<p>The Call Graph window opens and displays a tree and graphical view of all functions called from the <code>main</code> function.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/call_graph1.png" alt="call graph1">
</div>
</div>
<div class="paragraph">
<p>If you do not see all the functions as shown here, click the third button on the left side of the Call Graph window to show "who is called from this function."</p>
</div>
<div class="olist arabic">
<ol class="arabic" start="3">
<li>
<p>Expand the <code>endl</code> node to display the functions called by that function. Notice the graph is updated to show the functions called by <code>endl</code> as well.</p>
</li>
</ol>
</div>
<div class="olist arabic">
<ol class="arabic" start="4">
<li>
<p>Click the second button, called Bring Into Focus, on the left side of the window to focus on the <code>endl</code> function, then click the fourth button Who Calls this Function to view all the functions that call the <code>endl</code> function.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/call_graph2.png" alt="call graph2">
</div>
</div>
<div class="olist arabic">
<ol class="arabic" start="5">
<li>
<p>Expand some of the nodes in the tree to see more functions.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/call_graph3.png" alt="call graph3">
</div>
</div>
</div>
<div class="sect2">
<h3 id="_using_hyperlinks"><a class="anchor" href="#_using_hyperlinks"></a>Using Hyperlinks</h3>
<div class="paragraph">
<p>Hyperlink navigation lets you jump from the invocation of a class, method, variable, or constant to its declaration, and from its declaration to its definition. Hyperlinks also let you jump from a method that is overridden to the method that overrides it, and vice versa.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>In the <code>cpu.cc</code> file of the <code>Quote_1</code> project, mouse over line 37 while pressing Ctrl. The <code>ComputeSupportMetric</code> function is highlighted and an annotation displays information about the function.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/hyperlinks1.png" alt="hyperlinks1">
</div>
</div>
<div class="olist arabic">
<ol class="arabic" start="2">
<li>
<p>Click the hyperlink and the editor jumps to the definition of the function.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/hyperlinks2.png" alt="hyperlinks2">
</div>
</div>
<div class="olist arabic">
<ol class="arabic" start="3">
<li>
<p>Mouse over the definition while pressing Ctrl, and click the hyperlink. The editor jumps to the declaration of the function in the <code>cpu.h</code> header file.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/hyperlinks3.png" alt="hyperlinks3">
</div>
</div>
<div class="olist arabic">
<ol class="arabic" start="4">
<li>
<p>Click the left arrow in the editor toolbar (second button from the left) and the editor jumps back to the definition in <code>cpu.cc</code> .</p>
</li>
</ol>
</div>
<div class="olist arabic">
<ol class="arabic" start="5">
<li>
<p>Hover the mouse cursor over the green circle in the left margin and see the annotation that indicates that this method overrides another method.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/overide_annotation.png" alt="overide annotation">
</div>
</div>
<div class="olist arabic">
<ol class="arabic" start="6">
<li>
<p>Click the green circle to go to the overridden method and you jump to the <code>module.h</code> header file, which shows a gray circle in the margin to indicate the method is overridden.</p>
</li>
</ol>
</div>
<div class="olist arabic">
<ol class="arabic" start="7">
<li>
<p>Click the gray circle and the editor displays a list of methods that override this method.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/overridden_by_list.png" alt="overridden by list">
</div>
</div>
<div class="olist arabic">
<ol class="arabic" start="8">
<li>
<p>Click the <code>Cpu::ComputeSupportMetric</code> item and you jump back to the declaration of the method in the <code>cpu.h</code> header file.</p>
</li>
</ol>
</div>
</div>
<div class="sect2">
<h3 id="_using_the_includes_hierarchy"><a class="anchor" href="#_using_the_includes_hierarchy"></a>Using the Includes Hierarchy</h3>
<div class="paragraph">
<p>The Includes Hierarchy window lets you inspect all header and source files that are directly or indirectly included in a source file, or all source and header files that directly or indirectly include a header file.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>In the <code>Quote_1</code> project, open the <code>module.cc</code> file in the Source Editor.</p>
</li>
<li>
<p>Right-click on the <code>#include "module.h"</code> line in the file and choose Navigate &gt; View Includes Hierarchy.</p>
</li>
<li>
<p>By default, the Hierarchy window displays a plain list of files that directly include the header file. Click the right-most button at the bottom of the window to change the display to a tree view. Click the second button from the right to change the display to all files that include or are included. Expand the nodes in the tree view to see all of the source files that include the header file.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/includes_hierarchy.png" alt="includes hierarchy">
</div>
</div>
</div>
<div class="sect2">
<h3 id="_using_the_type_hierarchy"><a class="anchor" href="#_using_the_type_hierarchy"></a>Using the Type Hierarchy</h3>
<div class="paragraph">
<p>The Type Hierarchy window lets you inspect all subtypes or supertypes of a class.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>In the <code>Quote_1</code> project, open the <code>module.h</code> file.</p>
</li>
<li>
<p>Right-click on the declaration of the <code>Module</code> class and choose Navigate &gt; View Type Hierarchy.</p>
</li>
<li>
<p>The Hierarchy window displays all of the subtypes of the Module class.</p>
</li>
</ol>
</div>
<div class="imageblock">
<div class="content">
<img src="../../../../_images/kb/docs/cnd/type_hierarchy.png" alt="type hierarchy">
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_next_steps"><a class="anchor" href="#_next_steps"></a>Next Steps</h2>
<div class="sectionbody">
<div class="paragraph">
<p>See <a href="../debugging/" class="xref page">Debugging C/C&#43;&#43; Projects</a> for a tutorial on using some of the features for debugging a C or C++ project in NetBeans IDE.</p>
</div>
<div class="paragraph">
<p><a href="../../../../../../front/main/community/mailing-lists/" class="xref page">Send Us Your Feedback</a></p>
</div>
</div>
</div>
<section class='tools'>
<ul class="menu align-center">
<li><a title="Facebook" href="https://www.facebook.com/NetBeans"><i class="fa fa-md fa-facebook"></i></a></li>
<li><a title="Twitter" href="https://twitter.com/netbeans"><i class="fa fa-md fa-twitter"></i></a></li>
<li><a title="Github" href="https://github.com/apache/netbeans"><i class="fa fa-md fa-github"></i></a></li>
<li><a title="YouTube" href="https://www.youtube.com/user/netbeansvideos"><i class="fa fa-md fa-youtube"></i></a></li>
<li><a title="Atom Feed" href="https://netbeans.apache.org/blogs/atom"><i class="fa fa-mf fa-rss"></i></a></li>
<li><a title="Slack" href="https://tinyurl.com/netbeans-slack-signup/"><i class="fa fa-md fa-slack"></i></a></li>
<li><a title="Issues" href="https://github.com/apache/netbeans/issues"><i class="fa fa-mf fa-bug"></i></a></li>
</ul>
<ul class="menu align-center">
<li><a href="https://github.com/apache/netbeans-antora-tutorials/edit/main/modules/ROOT/pages/kb/docs/cnd/navigating-editing.adoc" title="See this page in github"><i class="fa fa-md fa-edit"></i> See this page in GitHub.</a></li>
</ul>
</section>
</article>
</div>
<div class='grid-container incubator-area' style='margin-top: 64px'>
<div class='grid-x grid-padding-x'>
<div class='large-auto cell text-center'>
<a href="https://www.apache.org/">
<img style="height: 60px" title="Apache Software Foundation" src="../../../../../../_/images/asf_logo_wide.svg" />
</a>
</div>
<div class='large-auto cell text-center'>
<a href="https://www.apache.org/events/current-event.html">
<img style="width:234px; height: 60px;" title="Apache Software Foundation current event" src="https://www.apache.org/events/current-event-234x60.png"/>
</a>
</div>
</div>
</div>
<footer>
<div class="grid-container">
<div class="grid-x grid-padding-x">
<div class="large-auto cell">
<h1><a href="../../../../../../front/main/about">About</a></h1>
<ul>
<li><a href="../../../../../../front/main/community/who">Who's Who</a></li>
<li><a href="https://www.apache.org/foundation/thanks.html">Thanks</a></li>
<li><a href="https://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li>
<li><a href="https://www.apache.org/security/">Security</a></li>
</ul>
</div>
<div class="large-auto cell">
<h1><a href="../../../../../../front/main/community">Community</a></h1>
<ul>
<li><a href="../../../../../../front/main/community/mailing-lists">Mailing lists</a></li>
<li><a href="../../../../../../front/main/community/committer">Becoming a committer</a></li>
<li><a href="../../../../../../front/main/community/events">NetBeans Events</a></li>
<li><a href="https://www.apache.org/events/current-event.html">Apache Events</a></li>
</ul>
</div>
<div class="large-auto cell">
<h1><a href="../../../../../../front/main/participate">Participate</a></h1>
<ul>
<li><a href="../../../../../../front/main/participate/submit-pr">Submitting Pull Requests</a></li>
<li><a href="../../../../../../front/main/participate/report-issue">Reporting Issues</a></li>
<li><a href="../../../../../../front/main/participate/#documentation">Improving the documentation</a></li>
</ul>
</div>
<div class="large-auto cell">
<h1><a href="../../../../../../front/main/help">Get Help</a></h1>
<ul>
<li><a href="../../../../../../front/main/help/#documentation">Documentation</a></li>
<li><a href="../../../../../../wiki/main/wiki">Wiki</a></li>
<li><a href="../../../../../../front/main/help/#support">Community Support</a></li>
<li><a href="../../../../../../front/main/help/commercial-support">Commercial Support</a></li>
</ul>
</div>
<div class="large-auto cell">
<h1><a href="../../../../../../front/main/download">Download</a></h1>
<ul>
<li><a href="../../../../../../front/main/download">Releases</a></li>
<li><a href="https://plugins.netbeans.apache.org/">Plugins</a></li>
<li><a href="../../../../../../front/main/download/#_daily_builds_and_building_from_source">Building from source</a></li>
<li><a href="../../../../../../front/main/download/#_older_releases">Previous releases</a></li>
</ul>
</div>
</div>
</div>
</footer>
<div class='footer-disclaimer'>
<div class="footer-disclaimer-content">
<p>Copyright &copy; 2017-2025 <a href="https://www.apache.org">The Apache Software Foundation</a>.</p>
<p>Licensed under the Apache <a href="https://www.apache.org/licenses/">license</a>, version 2.0</p>
<div style='max-width: 40em; margin: 0 auto'>
<p>Apache, Apache NetBeans, NetBeans, the Apache feather logo and the Apache NetBeans logo are trademarks of <a href="https://www.apache.org">The Apache Software Foundation</a>.</p>
<p>Oracle and Java are registered trademarks of Oracle and/or its affiliates.</p>
<p>The Apache NetBeans website conforms to the <a href="https://privacy.apache.org/policies/privacy-policy-public.html">Apache Software Foundation Privacy Policy</a></p>
</div>
</div>
</div>
<script src="../../../../../../_/js/vendor/lunr.js"></script>
<script src="../../../../../../_/js/search-ui.js" id="search-ui-script" data-site-root-path="../../../../../.." data-snippet-length="100" data-stylesheet="../../../../../../_/css/search.css"></script>
<script async src="../../../../../../search-index.js"></script>
<script src="../../../../../../_/js/vendor/jquery.min.js"></script>
<script src="../../../../../../_/js/vendor/what-input.min.js"></script>
<script src="../../../../../../_/js/vendor/foundation.min.js"></script>
<script src="../../../../../../_/js/vendor/jquery.colorbox-min.js"></script>
<script src="../../../../../../_/js/netbeans.js"></script>
<script>
$(function(){ $(document).foundation(); });
</script>
<script src="../../../../../../_/js/vendor/highlight.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', (event) => {
document.querySelectorAll('pre code').forEach((el) => {
hljs.highlightElement(el);
});
});
</script>
</body>
</html>