Creating an interface from a huge class using resharper - interface

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.

Related

Order Scala methods alphabetically (by name) using Intellij IDEA

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

Eclipse: What is a better way to find the implementation of a virtual function?

Eclipse: What is a better way to find the implementation of a virtual function?
I am now using "Search" to look at every places that have the virtual function name. Apparently it is a very ineffective way.
[Update 1]: Specifically I am reading the code of the liveMedia of live555. I import it as C++ code in Eclipse.
I assume you mean abstract functions.
Right-click on the function and select 'Declarations'.
select function or method and press F3 you will reach at method creation.....
You can see this on the Type hierarchy which can be opened by:
double click on method name
Ctrl + T
or by right clicking on the method name and navigating in the menu.
This opens a class tree showing only classes that implement the method, and if you click on a class it jumps to the implementation for that class.
You have to be in the .hpp file annoyingly to open the Type hierarchy, if you are on the .cpp you have to first jump to the .hpp with Ctrl + Click on the method name.
Related question: Eclipse shortcut to find all children class that override a method
Tested in Eclipse 2020-03 (4.15.0) with this test project.

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.

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.

Keyboard shortcut to switch between test and class in eclipse?

Lets say you create a class Foo and a test FooTest ( standard JUnit test )
I want a keyboard shortcut to help quickly switch between the test and the class.
If that is not possible, something like TextMate's "Run focussed test" (Command + Shift + R) might be of great help.
You can also use moreunit. I just installed it and it works fine, allowing to switch between source class and test class and also to run test class being in source class editor.
There isn't a built in one, but there's a plug-in called "Switcher" which will allow you to do that, here