Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I hide all java.lang.Object methods from code completion?

i want to create some simple wrapper classes for an existing class library. To make the syntax nice to read AND nice to guess (via code completion) i'd like to remove the methods of java.lang.Object.

The problem is that all non-atomic things in java inherit from Object and thus have these methods. I already tried to create the wrapper syntax via enums and interfaces, without success; because enums and interfaces are also java.lang.Objects.

java.lang.Object has nine methods that i don't want to see in the code completion of my interfaces. Here's what i want to remove (red) and what i want to keep (green):

alt text http://ju.venile.de/upload/java-lang-object-methods.png

Here is some example code for creating nice wrappers around existing classes (Builder pattern):

public interface IMySyntax{
  public IMySyntax myMethod1();
  public IMySyntax myMethod2();
}

public class MyBuilder implements IMySyntax{
  public static IMySyntax build(){ return (IMySyntax) new MyBuilder() }
  public IMySyntax myMethod1(){ /* do something */ return (IMySyntax) this }
  public IMySyntax myMethod2(){ /* do something */ return (IMySyntax) this }     
}

Usage of the new wrapper code should look like this:

MyBuilder.build()
         .myMethod1()
         .myMethod2();

Casting all this statements of the builder to an interface will reduce the method visibility, e.g. if the builder implements more that one interface. All java.lang.Object methods will stay, unfortunately.

If this method hiding was possible in Java (maybe using Annotations?), i could create a nice library that is IDE agnostic (nice code completion everywhere). If not, than maybe there's a trick for at least the Eclipse IDE (maybe a plugin?) that can provide java.lang.Object method hiding.

like image 555
Juve Avatar asked Feb 23 '09 19:02

Juve


1 Answers

For Eclipse 3.4 at least you can do the following:

1) Go to Preferences -> Java -> Appearance -> Type Filters 2) Click Add, and enter java.lang.Object

Now in code assist, the methods inherited directly from java.lang.Object will dissapear

like image 68
Il-Bhima Avatar answered Sep 20 '22 06:09

Il-Bhima