mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-13 20:15:09 +00:00
More attempts to fix NullPointerExceptions reported on the forums.
http://groups.google.com/group/project-lombok/browse_thread/thread/a8d59daaf7c1ae09
This commit is contained in:
1 parent
5f4c415017
commit
fe945d9198
1 file changed
+16
-2
@@ -41,6 +41,7 @@ import lombok.javac.JavacAST;
|
||||
import lombok.javac.JavacASTAdapter;
|
||||
import lombok.javac.JavacAST.Node;
|
||||
|
||||
import com.sun.source.util.TreePath;
|
||||
import com.sun.source.util.Trees;
|
||||
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
|
||||
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
|
||||
@@ -86,7 +87,10 @@ public class Processor extends AbstractProcessor {
|
||||
|
||||
|
||||
IdentityHashMap<JCCompilationUnit, Void> units = new IdentityHashMap<JCCompilationUnit, Void>();
|
||||
for ( Element element : roundEnv.getRootElements() ) units.put(toUnit(element), null);
|
||||
for ( Element element : roundEnv.getRootElements() ) {
|
||||
JCCompilationUnit unit = toUnit(element);
|
||||
if ( unit != null ) units.put(unit, null);
|
||||
}
|
||||
|
||||
List<JavacAST> asts = new ArrayList<JavacAST>();
|
||||
|
||||
@@ -143,6 +147,16 @@ public class Processor extends AbstractProcessor {
|
||||
}
|
||||
|
||||
private JCCompilationUnit toUnit(Element element) {
|
||||
return (JCCompilationUnit) trees.getPath(element).getCompilationUnit();
|
||||
TreePath path = trees.getPath(element);
|
||||
if ( path != null ) return (JCCompilationUnit) path.getCompilationUnit();
|
||||
else {
|
||||
if ( element == null ) {
|
||||
processingEnv.getMessager().printMessage(Kind.WARNING, "LOMBOK DIAGNOSTIC: no TreePath returned for element, " +
|
||||
"probably because element is null!");
|
||||
}
|
||||
processingEnv.getMessager().printMessage(Kind.WARNING, "LOMBOK DIAGNOSTIC: no TreePath returned for element of type: " +
|
||||
element.getClass() + "with toString: " + element);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user