Create test classesĬontext Actions make the process of creating tests easy and quick. If you want to learn more about language injections, we have an entire blog post dedicated to this feature.
After, pick the necessary language from the list and get code completion, inspections, highlighting, and even a dedicated editor for the injected code. Type the code that you want to embed, press Alt+Enter and select Inject language or reference. For example, these can be fragments of HTML code in Java, regular expressions, or SQL queries. Sometimes, you need to work on small elements of code in other languages embedded in your project. If there are several options, pressing Alt+Enter opens a list of options from which you can pick the most suitable one. If the suggested fix works for you, press Alt+Enter, and the IDE will add the import statement for you. IntelliJ IDEA has a faster solution: it shows you the most suitable import statement in a popup right in the editor. Normally, you’d have to go up to the beginning of the file and add the missing statement manually. Pasting code from elsewhere? If the inserted code block has a class or a method that has not yet been imported, you’ll see an error.
The IDE will download and install it for you. To quickly fix that, press Alt+Enter and select the necessary library from the list. If you’re using a piece of code from a library that has not yet been added to your project, it will be highlighted in red as an error.
Learn more about how to deal with code problems from this blog post. There, you can deal with each problem, from errors to typos, by pressing Alt+Enter without having to jump between the tool window and the editor. Click the widget to open the list of problems in the Problems tool window. If you’re not sure how a certain fix is going to change your code, you can open the preview by pressing Alt+Space on macOS or Ctrl+Shift+I on Windows and Linux on a suggestion in the list.īy the way, if the widget in the top-right corner tells you that there are problems in your current file, don’t scroll down and look for them. Pressing this shortcut on a highlighted code element in the editor opens a list of possible fixes from which you can select the one that works best. The most powerful tool in IntelliJ IDEA that operates by means of Alt+Enter is code inspections. Whenever you see a yellow or red light bulb icon in the editor, press Alt+Enter, because IntelliJ IDEA has tips to offer. In reality, they incorporate a vast amount of quick-fixes and suggestions that can correct and improve your code, add code elements, upload missing components, create classes and methods, and do many other amazing things. In a nutshell, context actions help you fix problems and improve your code. They differ depending on your current context and the code that you’re working with. Today, let’s dive deeper into Context Actions.Ĭontext Actions become available to you in the editor as you type. In one of the previous IntelliJ IDEA: how2pro blog posts, we talked about the Search Everywhere feature and how you can use it to search for code elements and even disable and enable IDE actions or assign shortcuts.
IntelliJ IDEA has two shortcuts that can get you out of almost any kind of trouble: Shift+Shift to run Search Everywhere and Alt+Enter to invoke Context Actions. Imagine that you have the entire IntelliJ IDEA interface at the tips of your fingers.