Order Scala methods alphabetically (by name) using Intellij IDEA - scala

I wanted to order Scala functions alphabetically, I'm using Intellij IDEA is there is a way to do that ?

Settings > Editor > Code Style > Scala > Arrangement
In Matching Rules click + to add a new rule
If you want to order def without modifiers (which is public by default) in Type click function and in Modifier click public, in Order choose order by name. Then click OK.
After that you can open your file with unordered methods, click Code > Rearrange Code and they will be ordered by name.
PS I used IDEA Community Edition 2019.3

Related

Eclipse key for "go to typed in class"

Is there a key in Eclipse Neon.3 (Java) that allows me to type in a class name and which then takes me to that class, whichever project in my workspace contains it? Specifically, I am not sitting in a source file with a reference to it, but I have a case like someone emails me and says "I have a question about class StoreImportantData" and I want to be able to type that class name in and go to it without thinking about where it might be located. Various "Search" functions will work, but are very clumsy or require temporarily changing my default search settings.
Normally Ctrl+Shift+T is bound to Open Type - should be the default, I'm pretty sure that I've not changed it.
Note: Ctrl+Shift+L list all key bindings, and the preferences
Window -> Preferences -> General -> Keys
lists all commands and bindings. It not only allows changing the binding, but also has a filter field that helps searching a specific functionality..

Eclipse optimize imports to include static members and methods

Long user of eclipse and Java. One issue that i've found with Eclipse, is it seems that there is no easy way to import static members and methods.
Namely, the jUnit fail() method from org.junit.Assert
I create several classes a day, and manually add
import static org.junit.Assert.fail;
to the import statements. This is quite annoying. I absolute LOVE using Ctrl+Shift+O to organize my imports, but it still doesn't find static members and methods.
Also, the import does not show up in eclipse.
Funny thing is, is that i've seen it work previously, but i cant recall the variables.
So to my question:
Does anybody know what I need to do to ensure that this static import is always recognized and can be found using Ctrl+Shift+O?
Thanks #qqilihq.
Note:
The answer that was accepted does not work with the Organize Imports keyboard shortcut that I preferred in eclipse, but does work for the "hover over" suggestion.
You can use Ctrl + Shift + M, for example you want to import verify method from Mockito class then
Mockito.verify() // select verify and press Ctrl + Shift + M
This will import verify static method from Mockito class.
Did you have a look at Preferences > Java > Editor > Content Assist > Favorites? You can define candidates for static imports there. Result:
For less used classes you can lower the value of Preferences > Java > Code Style > Organize Imports > Number of static imports needed for .* but beware that you may get .* for classes that contain generically named methods such as getInstance. This in turn may lead to confusion and/or naming conflicts.
You can add the classes that you statically import from Preferences > Java > Editor > Content Assist > Favorites page in Eclipse. Then, Ctrl+Space shortcut lists all the static members of your favourite classes in the content assist menu.

Automatically Format and Arrange Declarations and Definition in Eclipse [duplicate]

Is there an easy way to sort methods within a class in Eclipse?
select the class, Source > Sort
Members
you can set the order in Java
preferences
via Eclipe forums
Found it on the Eclipse newsgroup:
select the class, Source > Sort
Members

In-place ("Quick-Assist" or something easier) source code modifier?

Eclipse already has very impressive and useful what I call "source code modifiers" (please suggest a better name).
For example, it has "Quick Fix", "Word Completion", "Externalize Strings" and other functions that modify source code via menu (or key-combination).
Now, I am looking to add my own "source code modifier" function: I would like to:
Highlight (select) an arbitrary string.
Right-click on it
Invoke a menu item that would "translate" that string to a different string, using a function that I wrote (preferably in Java). Similar to "Quick Fix" or "Replace With" currently on the default context menu.
Is this possible in Eclipse?
If so, what do I need to do to accomplish this?
The short answer:
The quick assist will have to modify the AST of the Java code. Essentially you will have to replace a org.eclipse.jdt.core.dom.SimpleName node with one that you want.
The long answer:
The org.eclipse.jdt.ui.quickAssistProcessors extension point enables you to contribute your own Java code quick assists.
To create a new extension for the extension point you need to first provide the required extension in the plugin.xml. For example, JDT defines the following processor
<extension
point="org.eclipse.jdt.ui.quickAssistProcessors">
<quickAssistProcessor
name="%defaultQuickAssistProcessor"
class="org.eclipse.jdt.internal.ui.text.correction.QuickAssistProcessor"
id="org.eclipse.jdt.ui.text.correction.QuickAssistProcessor">
</quickAssistProcessor>
</extension>
(For a description of the individual attributes, please refer to the extension point documentation)
Then you need to create the class that implements the org.eclipse.jdt.ui.text.java.IQuickAssistProcessor interface, and modify the AST in this class. (This class is the same as the one you specified while declaring the extension)
Supplying the right IJavaCompletionProposal
JDT provides the following default implementations for correction proposals that can be used to contribute quick fixes and quick assists.
ChangeCorrectionProposal
CUCorrectionProposal
ASTRewriteCorrectionProposal
If you use an ASTRewrite, you should create an ASTRewriteCorrectionProposal.
ASTView Plugin
This is something that will help you visualize the AST of a Java source file http://www.eclipse.org/jdt/ui/astview/index.php
The right name is 'Quick Assist'. You have to write some code to create your Quick Assists.

Creating an interface from a huge class using resharper

I have a very big class with lots of methods, is it possible to build an interface from this class using Resharper?
Yes.
My shortcut is Ctrl + Shift + R to bring up the refactoring options. Doing this on the class name allows you to" Extract Interface..."
Optionally, you can choose from the menu > ReSharper > Refactor > Extract Interface...
Uh, maybe I'm missing something here (I've never used resharper) but you can extract an interface from a class using the standard VS IDE refactoring tools (at least you can in 2008). Right click the class, select 'Refactor' and then 'Extract Interface'. This will bring up a dialog box where you can select which properties to include.