Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ is it possible to add @Overrrides to all methods of a particular interface?

I have created an interface, with about 30 methods and implemented in 30 classes.

I want to add @Override to each of the implementations, but i would like not to do it by hand.

How can IntelliJ help me?

interface looks like this:

public interface PreviewObjectTests {     void testGetName();     void testGetType();     //... 30 similar methods } 

implementation code:

public class PreviewObjectAccountTest implements PreviewObjectTests {      //I want to add @Override here!     @Test public void testGetName() {         assertThat(...);     }      //I want to add @Override here!     @Test public void testGetType() {         assertThat(...);     }      //...30 similar methods   } 
like image 987
Jesper Rønn-Jensen Avatar asked Jan 27 '12 09:01

Jesper Rønn-Jensen


People also ask

How do I add unimplemented methods in IntelliJ?

You can also right-click anywhere in the class file, then click Generate Alt+Insert , and select Implement methods. In the dialog that opens, select the methods to implement. If necessary, select the Copy JavaDoc checkbox to insert JavaDoc comments for the implemented methods . Click OK.

Which of the following can be inserted to override the superclass method?

Override a method of a superclass On the Code menu, click Override methods Ctrl+O . Alternatively, you can right-click anywhere in the class file, then click Generate Alt+Insert , and select Override methods.

How do I know override method?

Position the cursor on the name of the method you're interested in. You can be in any class on the class hierarchy, not necessarily the parent interface/class. Press Ctrl+T. A popup will appear with all classes that inherit/override this method.

How does IntelliJ calculate implementation?

To navigate to the implementation, press Ctrl+Alt+B .

How do I implement a method in IntelliJ?

IntelliJ IDEA creates stubs for implemented methods, with the default return values for the primitive types, and null values for the objects. From the main menu, select Code | Implement methods or press Ctrl+I. You can also right-click anywhere in the class file, then click Generate Alt+Insert, and select Implement methods.

How to limit the number of classes that IntelliJ IDEA has imported?

When the number of classes that IntelliJ IDEA has imported from the same package reaches the limit ( 5 by default), the IDE modifies the statements in order to import the entire package instead of importing several single classes from this package: In the Settings/Preferences dialog Ctrl+Alt+S, select Editor | Code Style | Java | Imports.

How to use find actions in IntelliJ IDEA?

Use Find Actions to modify your IntelliJ IDEA interface. Take a look around a standard Gradle project to understand it better. You can start typing into a dialog box to search, even if there's not a textual search box available.

How do I change the default import in IntelliJ IDEA?

IntelliJ IDEA suggests to import single classes by default. You can change the settings to import entire packages instead. In the Settings/Preferences dialog (Ctrl+Alt+S), select . Clear the Use single class import checkbox, and apply the changes.


2 Answers

Easily done with Alt+Enter intention, then press Right arrow for the sub-menu:

Fix all

like image 127
CrazyCoder Avatar answered Sep 28 '22 11:09

CrazyCoder


For IntelliJ:

  1. Check if you have "Missing @Override annotation" checked inside Preferences -> Project Settings -> Inspections -> Inheritance issues.
  2. Use Analyze -> Inspect Code
  3. Find Inheritance issues -> Missing @Override annotation inside "Results for Inspection Profile" window.
  4. Apply fix "Add @Override annotation" Apply fix "Add @Override annotation"
like image 32
user1991776 Avatar answered Sep 28 '22 10:09

user1991776