ervandew/eclim — pull request #194 by AlexJF (2013-02-13 16:27:41+00:00)
Title: Fixed :JavaImpl inside anonymous inner classes.

Example:
package P;

public interface A {
public void someMethod();
}

public class B {
private static A objA = new A() {

}
}

Result: NullPointerException

Reason: findType doesn't work with anonymous classes returning null.

Solutions:
1. - Search the whole type tree for a type that matches the FQN of the
anonymous class. Upon finding it, we have found our type. Besides being
the simplest implementation, it also works (or should work) with nested
anonymous classes. However, there may be some performance issues since
we are scanning all children of the main type (B).

2. - Save the offset used during the first call to obtain the type again
(instead of saving the FQN of the type we are adding the methods to).
I'm not sure how heavy the finding of a type via an offset is but this
could be a good option. However, once we have added newlines to the
document without closing the :JavaImpl result window, the offset would
be invalidated.

3. - When returning the FQN of the type before showing the option window,
add a special case for anonymous classes and include their whole
hierarchy. In the case above this would be P.B.objA. Once we have access
to objA we can get the anonymous class by calling:
objAType.getType("", occurrenceNumber)
where occurrenceNumber corresponds to the number after the $ on the FQN
of the anonymous class (1 in the example).
Handling nested anonymous classes would require significant parsing on
our part though.

Those were the only options I could think of after some debugging and javadoc
searching. There should really be a better way to obtain types of anonymous
classes. By the way also tried using the findType of TypeUtils but it was unable
to get the type of the anonymous class as well.