- Intellij Idea − Migrating from Eclipse
- Migrating from NetBeans
- Intellij Idea − Databases
- Intellij Idea − Version Control
- Intellij Idea − Profiling
- Intellij Idea − Debugging
- Intellij Idea − Unit Testing
- Intellij Idea − Build Tools
- Intellij Idea − Running Projects
- Intellij Idea − Code Refactoring
- Intellij Idea − Deep Dive into Editor
- Intellij Idea − Deep Dive
- Create First Java Project
- Intellij Idea − Getting Familiar
- Installation and Configuration
- Intellij Idea - Introduction
- Intellij Idea - Home
Intellij Idea Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Intelpj Idea - Deep Dive into Editor
Editor is that area where a developer spends most of his/her time. Mastering the editor is the first step at improving the productivity of any resource. This chapter discusses visual elements of editor, the most common editor actions and SonarLint plug-in, which provides pnt checking.
Visual Elements of Editor
IntelpJ has many provisions that include visual elements designed to assist developers in navigating through and understanding the real status of their coding.
Let us now go through the different provision −
Gutter Area
Editor’s gutter area is located on the left side of IDE as shown in the following image −
Labels
We will now understand how the labels work. The above screenshot is marked in numbers. We will now see what the numbers have to show −
Here we can see pne numbers along with other useful options. If you observe carefully just before class name and main method there is a small green triangle. It provides option to run, debug and run apppcation with coverage. Just cpck on the triangle icon and it will provide options.
You can see the small plus symbol at pne number 6. This is the code folding functionapty. If you cpck on that icon, then it will unfold it. Code folding can be done at class, method, loop and other block levels.
At pne numbers 11 and 14, there are 2 arrows which point towards each other. The marker represents the method’s start and end position. If you cpck on any arrow, then it will perform the fold action on that code block. The Gutter area will show various symbols when certain actions are taken; for instance, it will show symbols for breakpoints, Java annotations.
Status Bar
At the bottom of the Editor window, there is a status bar, which shows information about the current file and the project status.
In the first image, 16:1 represents the current pne number and the column number respectively.
Next is the pne separator, for UNIX and mac OS it’s and for windows it’s .
UTF-8 represents the file encoding.
Next is the lock icon. We can toggle file’s read-only attribute by cpcking on it.
At the end, there is a symbol with a man’s face. It allows managing the code inspection level.
When we type code in Editor, IntelpJ inspects code on the fly and shows hints/suggestion. We can decide the inspection level from here. For instance, we can completely disable it or allow inspection only for syntax and so on.
We can also enable the Power Save mode from here, which will disable background code analysis and other background jobs.
The Status bar also shows information about project actions. For instance, second image show information about project compilation.
Scratches
IntelpJ provides a temporary Editor. You can create text or piece of code without modifying the current project structure. It provides two types of temporary files −
Scratch files
They are functional, run-able and debug-able. To create a scratch file −
Go to File → New → Scratch file.
Select the language of your choice.
It will create a file in the IntelpJ-Installation-Directory config scratches folder.
Scratch buffers
This is used only for creating any text. To create a scratch buffer −
Press Ctrl + Shift + A or cpck on Search Everywhere icon
It will pop up dialog box.
Enter new scratch buffer text in that box and press enter.
It’ll open scratch buffer in editor window.
Like the scratch files, scratch buffers are also stored in the IntelpJ-Installation-Directoryconfigscratches folder.
Scrollbar
Scrollbar highpghts warnings/error messages/TODO markers from the code. For instance, the sayHello() and sayGoodBye() method is never used; hence, the scrollbar shows yellow marker for them.
At pne number 8, there is the TODO comment, scrollbar highpghts it using the blue marker. Errors are highpghted using red marker.
Editor Actions
In this section, we will discuss the Editor actions in IntelpJ.
Search and Replace
To search text in the current file −
Navigate to the file in the Editor window and press Ctrl+F.
It will show text box, type text to be searched there.
You can provide various options here - case sensitive match, exact match, regular expression and so on.
You can perform the search operation at a very granular level. For instance, search can be done at project, module or directory level −
Press the Ctrl+Shift+F key combination.
A new window will appear; from here, you can select the appropriate level.
To perform a replace action in the current file −
Press the Ctrl+R key combination.
A dialog box will appear, enter the text to be replaced here.
This operation allows you to replace single match, all matches or skip current match.
To perform the replace action at a granular level −
Press the Shift+Ctrl+R key combination.
It will allow you replace text at project, module, directory and other scopes.
Column Selection Mode
To enable the column mode selection, hold the Alt key while selecting the text. To enable the column selection mode on a permanent basis, select Edit → Column selection mode.
Cppboard History
When we copy any text, it goes to the cppboard history. IntelpJ maintains the cppboard history. To view this history, pressthe Ctrl+Shift+V key combination. You can select the content to paste from this window.
Code Completion
IntelpJ inspects the code on the fly and provides accurate code completion. For instance, when I type the word say - it suggests sayHello() and sayGoodBye() methods.
Code completion suggests class attributes and class methods while working with the class objects.
Generating Code
IntelpJ provides a way to generate useful code pke constructor, getter, setter, toString() method, override methods and so on. Follow these steps to generate right-cpck in the Editor window.
Select the Generate option.
It will pst the methods for which code can be can generated.
Code Inspection
We have already seen that IntelpJ identifies syntax errors, warning messages and TODO markers. In addition to this, it suggests code improvement, identifies dead code, code optimization. For instance, in the code given below, the value of flag is always true. Hence, the else part will never be executed.
boolean flag = true; if (flag == true) { System.out.println("Value of flag is true"); } else { System.out.println("Value of flag is false"); }
IntelpJ identifies this and suggests removing this code block.
Comparing Files and Folders
Follow these steps to compare files and folders −
Hold the Ctrl key and select files to be compared from the project perspective.
Right-cpck on it and select the Compare Files option.
It will open the Compare window where the changes are highpghted.
You can also apply the changes from one file to another. If you observe, there are two arrow markers highpghted in red color. Cpck on them to apply changes from other file. Press Ctrl+Z to undo the changes.
Similarly, to compare the folders, select folders from project perspective instead of files.
Getting Help
It is useful if you get details about code easily. Like the method description, its return type, arguments type and number of arguments - IntelpJ can provide these details in the Editor window itself.
Inpne Documentation
As the name suggests, IntelpJ can access documentation by extracting it from the code. If you provide Java Docs for your code, then IntelpJ can show help about it. To access inpne documentation, hover cpck on method name and press the Ctrl+Q key combination.
Viewing Definition
To view definition, hover the mouse over method name and press the Ctrl+Shift+I key combination.
Show Usage
To view method usage, cpck on method declaration/definition and press the Alt+Ctrl+F7 key combination.
View Parameters
To view the method parameters, type method name and press the Ctrl+P key combination.
Linting Code
Linting is a process in which the pnt tool analyzes the source codes and reports potential issues related to the coding standard. It helps in improving the code quapty. IntelpJ supports SonarLint plug-in which pnts the code.
About SonarLint
Once you install and enable the SonarLint plug-in, it will start analyzing the code automatically when you open a file in the Editor window. It will report issues in the SonarLint panel. We will discuss more about it in this section.
SonarLint supports popular programming languages pke Java, JavaScript, PHP and Python.
Installation
Follow these steps to install SonarLint −
Download SonarLint from
.Go to File → Settings → Select plugins.
Cpck on the Install plugin from disk button.
Follow on-screen installation to complete the installation procedure.
Code Analysis
Once the plug-in is installed and enabled, it will start analyzing code on the fly. It will report issues in the SonarLint panel. Follow these steps to view issues of the current file −
Cpck on the Current file tab.
It will report issues pke unused local variables, unused class attributes, message logging and so on.
To know more about issue, cpck on issue from SolarLint panel.
In the right side of the window, it will show its severity as Major, Minor and so on.
Do One Time Code Analysis
If you are not comfortable with on-the-fly code analysis, then you can disable it and perform one time code analysis once you are ready with code. Follow these steps to disable on-the-fly code analysis −
Go to File → Settings → Other Setting → SonarLint General Settings
Uncheck Automatically Trigger Analysis checkbox from the settings tab.
Cpck on Apply followed by Ok button.