in javac-ast-extension/src/org/jetbrains/jps/javac/ast/JavacReferenceCollectorListener.java [335:354]
private static Element getElementIfJdkUnder8(Tree tree) {
if (tree == null || tree instanceof PrimitiveTypeTree || tree instanceof ArrayTypeTree) return null;
if (tree instanceof ParameterizedTypeTree) {
return getElementIfJdkUnder8(((ParameterizedTypeTree)tree).getType());
}
Field symField;
try {
//should be the same to com.sun.tools.javac.tree.TreeInfo.symbolForImpl() since com.sun.source.util.Trees.getElement() works improperly under jdk 6-7
symField = tree.getClass().getField(tree instanceof NewClassTree ? "constructor" : "sym");
}
catch (NoSuchFieldException e) {
throw new RuntimeException(tree.getClass().getName());
}
try {
return (Element) symField.get(tree);
}
catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}