Наслаждайтесь миллионами электронных книг, аудиокниг, журналов и других видов контента

Только $11.99 в месяц после пробной версии. Можно отменить в любое время.

Learn IntelliJ IDEA - Part 2: IntelliJ IDEA, #2

Learn IntelliJ IDEA - Part 2: IntelliJ IDEA, #2

Автор HASANRAZA ANSARI

Читать отрывок

Learn IntelliJ IDEA - Part 2: IntelliJ IDEA, #2

Автор HASANRAZA ANSARI

Длина:
443 страницы
2 часа
Издатель:
Издано:
19 мая 2022 г.
ISBN:
9781393377054
Формат:
Книга

Описание

** We prefer you to this book in the series number-wise.**

IntelliJ IDEA (hereafter referred to as IntelliJ) is one of the most powerful and popular Integrated Development Environments (IDE) for Java. It was developed and is maintained by JetBrains, and is available in the community and ultimate edition. This feature-rich IDE enables rapid development and helps in improving code quality. This book starts with a basic introduction and slowly dives deep into the advanced features.

This book is targeted at first-time learners, as well as moderate users of IntelliJ. Beginners will get a fair understanding of IntelliJ and its functioning, and others will be able to take their knowledge on this subject to the next level.

This book requires that the readers have some preliminary knowledge of the software development process, along with the Java programming language. In the later sections of this book, we will discuss integration with build tools, unit testing frameworks, debugger, profiling, version control system, and database. It is assumed that the required tools are installed and configured on the system and the reader is familiar with those tools.

Издатель:
Издано:
19 мая 2022 г.
ISBN:
9781393377054
Формат:
Книга

Об авторе


Связано с Learn IntelliJ IDEA - Part 2

Похожие Книги

Похожие статьи

Предварительный просмотр книги

Learn IntelliJ IDEA - Part 2 - HASANRAZA ANSARI

Search for a target within a file

You can quickly find and replace text strings in the current document. Using different options, you can narrow your search process, use regular expressions in your search, and manage your search results.

Find the search string in a file

Open your file in the editor.

Press Ctrl+F or select Edit | Find | Find from the main menu.

If you want to extend the search of your target beyond the current file, press Ctrl+Shift+F. For more information, see Search and replace a target within a project.

In the search field that opens, enter your search string. IntelliJ IDEA highlights the results of your search in the file. Alternatively, in the editor, highlight the string you want to find and press Ctrl+F. IntelliJ IDEA places the highlighted string into the search field.

search string

Place a caret at any string in your file and press Ctrl+F to find its occurrences or from the main menu, select Edit | Find | Next Occurrence of the Word at Caret.

Find in selection

You can search for a text string inside the multi-line selection.

IntelliJ IDEA handles replacing in the multi-line selection the same way.

Select a multi-line fragment and press Ctrl+F.

Click  the In Selection button  and type your search string. IntelliJ IDEA will search for the target inside the selected fragment first.

If you release  the In Selection button , IntelliJ IDEA will switch the search process back to the whole file.

Gif

If you want to search for the multi-line fragment itself, select it and press Ctrl+F.

Multi-line selection search

Manage your search

IntelliJ IDEA lets you adjust your search process and perform various actions with the displayed search results.

If you want to see the list of previous searches, press ⌥↓ in the search field.

search history

If you want to enter a multi-line string, click the Enter a new line icon in the search field for a new line.

With the Regex icon selected, IntelliJ IDEA automatically escapes special regex symbols with backslash \ when you search for a text string that contains them.

Keep in mind that if you copy (Ctrl+C) the string first and then paste (Ctrl+V) it in the search field, the regex symbols will not be taken into account.

Escape regex symbols

For more details on regex, refer to the search with regex documentation.

Use the Previous occurrence and Next occurrence arrows to navigate to the previous or the next occurrence.

Work with the list of occurrences Alt+F7 in theFindtool window, where you have other options, for example, to group your results or to open them in a separate window.

Found Occurrences in the Find tool window

Click the Add selection for the next occurrence or unselect the previous occurrence icon to add a selection of the next occurrence or deselect the previous occurrence Alt+J or Alt+Shift+J.

If you want to quickly replace the target of your search in the whole file, press Ctrl+Alt+Shift+J and type a new string.

Gif

You can narrow your search when you click the Words icon , the Match case icon in the search field, or click the filter icon to select a scope for your search.

You can press ^⌥X (previously known as ⌥G) to quickly toggle the Regex icon theRegexoption. You can useregular expressionsto opt for more challenging searches.

Press Ctrl+F7 to see usages of any element in the opened file.

If you don't want IntelliJ IDEA to highlight all found usages in the file, open the Settings/Preferences dialog Ctrl+Alt+S and on the Editor | General page clear the Highlight usages of element at caret option.

Press Alt+F7 to search for usages beyond the current file or Ctrl+Alt+F7 to open the search results in a separate popup. If you need to configure some options before the search, press Ctrl+Alt+Shift+F7 to open the Find Usages dialog.

Replace the search string in a file

Press Ctrl+R or select Edit | Find | Replace from the main menu to open the Replace in File window.

In the top field, enter your search string. In the bottom field, enter your replacement string. If you need to preserve the case, click  the Preserve Case icon  located in the replace field.

Replace in file pane

Click  Multi-line  for a multi-line replace. For example, if you want to replace a comma with a comma and a new line, enter a comma in the search field and a comma and the new line in the replace field.

Click Replace to replace items one by one, Replace all to replace all items in your file, and Exclude to omit some items from replacing.

The options that appear in the Replace window, are similar to the Find window and you can refer to the manage the search results section.

Search and replace a target within a project

You can search for a text string within a project, use different scopes to narrow your search process, find occurrences, and exclude certain items from the search.

Find the search string in a project

From the main menu, select Edit | Find | Find in FilesCtrl+Shift+F.

In the search field, type your search string. Alternatively, in the editor, highlight the string you want to find and press Ctrl+Shift+F. IntelliJ IDEA places the highlighted string into the search field.

To see a list of your previous searches, press Alt+Down.

If you need, specify the additional options.

Find in Files

IntelliJ IDEA lists the search strings and the files that contain them. If the search string is found several times on the same line of code, IntelliJ IDEA merges the results in one line.

To do a multi-line search, click the  Multi-line search  icon to enter a new line, and press Ctrl+Alt+Down/ Ctrl+Alt+Up to browse through occurrences.

Check the results in the preview area of the dialog where you can replace the search string or select another string, press Ctrl+Shift+F again and start a new search.

To see the list of occurrences in a separate tool window, click Open in Find Window. Use this window and its options to group the results, preview them, and work with them further.

If you want to see each new search result in a separate tab in the Find tool window, click  Artwork studio icons logcat toolbar settings  on the bottom of the Find in Files dialog and select the Open Results in New Tab checkbox.

Open Results in New Tab

Narrow your search

You can use different options in the Find in Files dialog to adjust your search process.

Select options such asWords( the Words icon ) orMatch case( the Match case icon ) to find the exact word in a project or match the letter case.

With the Regex icon selected, IntelliJ IDEA automatically escapes special regex symbols with backslash \ when you search for a text string that contains them.

Keep in mind that if you copy (Ctrl+C) the string first and then paste (Ctrl+V) it in the search field, the regex symbols will not be taken into account.

Escape regex symbols

For more details on regex, refer to the search with regex documentation.

Click the filter icon to filter your search. For example, you can filter the search to omit comments or search only in comments instead.

Select one of the displayed options such asModuleorDirectoryto limit your search.

Moreover, you can select the Scope option that offers you a list of predefined scopes for your search. For example, you can limit your search only to the open files in your project or you can search in a class hierarchy.

Search in class hierarchy

If you work without tabs, the scope Recently Viewed Files or Recently Changed Files option might become quite useful. You can also create your own custom scope, click the Browse icon ( ellipsis icon ) to open the Scopes dialog.

Search in the specific file types

Use the File Mask option to narrow your search to a specific file type. You can select the existing file type from the list, add a new file type, or add an additional file mask syntax to search for file types with certain patterns.

In the Find in Files dialog, select the File Mask checkbox and from the list of file types, select the one you need.

File mask

IntelliJ IDEA limits its search to the specified type.

If you don't find the file type you need in the list, enter your file type in the File Mask field.

For example, use the following syntax to search only in gradle files: *.gradle.

Other wildcards besides * are supported. You can also specify several file types by separating them with a comma.

Add a new file type

Replace the search string in a project

Press Ctrl+Shift+R to open the Replace in Path dialog.

In the top field, enter your search string. In the bottom field, enter your replacement string.

Replace in path dialog

For example, if you want to replace a variable name with a new name for a large project, use the replace in path instead of rename refactoring since your variable can appear in the config files as well.

Click one of the available Replace commands.

Work with the search results in the Find tool window

In the Find in Files dialog, click Open in Find Window to open the list of the search results in a separate window.

Using icons and context menu in the Find tool window, you can sort entries, exclude directories, navigate to the source code, and so on.

the Find tool window

Check the following popular options:

If you want to exclude a directory from the results, select a directory and from the context menu, selectExclude.

To locate the result of the search in the editor, use theJump to Sourceoption from the context menu.

To return back to theFind in Filesdialog, click the Settings icon on the left toolbar.

To sort the search entries, selectView Options | Sort Members AlphabeticallyinShow Options Menu( the Show Options Menu ).

Find and replace text using regular expressions

When you want to search and replace specific patterns of text, use regular expressions. They can help you in pattern matching, parsing, filtering of results, and so on. Once you learn the regex syntax, you can use it for almost any language.

Regex icon

Press Ctrl+R to open the search and replace pane.

If you need to search and replace in more than one file, press Ctrl+Shift+R. For more detailed information, refer to Search and replace a target within a project.

Enter a search string in the top field and a replace string in the bottom field.

Regex search and replace fields

Click  the Regex icon  to enable regular expressions. If you want to check the synax of regular expressions, hover over  the Regex icon  and click the Show expressions help link.

When you search for a text string that contains special regex symbols, IntelliJ IDEA automatically escapes them with backlash \ in the search field.

Keep in mind that if you copy (Ctrl+C) the string first and then paste (Ctrl+V) it in the search field, the regex symbols will not be taken into account.

Escape regex symbols

However, when you specifically search for metacharacters such as .[{()\^$|?*+, you need to escape them with backslash \, so they can be recognized.

For example, if you need to find ., type \. in the search field.

IntelliJ IDEA can also match a letter case when you enter a range of characters in your search field.

For example, if you want to search for only uppercase characters, type the following in the search field:

\b[A-Z]

Copied!

To search and replace more complicated patterns, use the structural search and replace.

If  the Match Case icon  is unselected in the search field, IntelliJ IDEA searches for both lower and upper cases.

Select  the Match Case button  in the search field to match the case of the specified range.

The result of the Match Case selection

When you browse the occurrences, IntelliJ IDEA displays the replacement hints, so you can view the potential results before clicking the Replace button.

Replacement hints

See RegEx syntax for more details.

Use regex capturing groups and backreferences

You can put the regular expressions inside brackets in order to group them. Each group has a number starting with 1, so you can refer to (backreference) them in your replace pattern. Note that the group 0 refers to the entire regular expression. However, you can refer to the captured group not only by a number $n, but also by a name ${name}.

For example, for the numbered capturing groups, use the following syntax:

Find field

Replace field

(.*?)

Copied!

For the named capturing groups, use the following syntax:

Find field

Replace field

(?.*?)</h2>

Copied!

Find and replace a captured group

Let's consider the following code:

ij category=105 title=Multiline search and replace in the current file/>

ij category=105 title=Improved search and replace in the current file/>

ij category=105 title=Regexp shows replacement preview/>

Copied!

Open the search and replace pane Ctrl+R.

In the search field, enter parentheses () that would indicate a capturing group, for example: \stitle=(.*)?\s*(/>*).

In the replace field, backreference such groups by numbers starting with 1, for example:

$2$1

Copied!

IntelliJ IDEA highlights the found occurrences based on your search specifications and displays hints with the replace string.

Replace with regex result

Switch the character case

You can use regular expressions to change the case of characters that matches some criteria.

Open the search and replace pane Ctrl+R. Make sure that  the Regex icon  is selected in the search field.

In the search field enter the search pattern.

In the replace field, depending on what you want to achieve, enter one of the following syntax:

\l changes a character to lowercase until the next character in the string.

For example, Bar becomes bar.

\u changes a character to uppercase until the next character in the string.

For example, bar becomes Bar.

\L changes characters to lowercase until the end of the literal string \E.

For example, BAR becomes bar.

\U changes characters to uppercase until the end of the literal string \E.

For example, bar becomes BAR.

Switch to the uppercase character example

Search for usages

When you write or edit code, you might come across a code element that you want to change or delete. Before you make the changes, it is a good practice to see where the code element is used and how it affects the application. With the Find Usages actions you can search for the references of your code element throughout the whole codebase.

You can manage the search process, and search only in a single file, extend your search to the whole project, or create a certain search scope. Moreover, you can configure the color of the usages highlighting or disable the automatic highlighting of usages altogether.

Search for usages in a file

In the editor, select a symbol you want to find, IntelliJ IDEA automatically highlights all found usages in the file. If the highlighting of usages is disabled, press Ctrl+Shift+F7 to highlight all usages in the file.

Find usages in file result

From the main menu, select Edit | Find Usages | Find Usages in File Ctrl+F7. IntelliJ IDEA selects the first usage occurrence in the file.

Find usages resultFind usages result

With the Ctrl+F7 you can also highlight the exception name and places where the exception is thrown.

Вы достигли конца предварительного просмотра. , чтобы узнать больше!
Страница 1 из 1

Обзоры

Что люди думают о Learn IntelliJ IDEA - Part 2

0
0 оценки / 0 Обзоры
Ваше мнение?
Рейтинг: 0 из 5 звезд

Отзывы читателей