private static CharSequence getContent(Object treeAndTopLevel) throws Exception { /* * CharSequence content = treeAndTopLevel.snd.getSourceFile().getCharContent(true); */ return (CharSequence) method(method(field(treeAndTopLevel, "snd"), "getSourceFile"), "getCharContent", getCharContentSignature, true); }
public static Compiler getCompiler(Element currentElement) { if (JavaCCompiler.isValidElement(currentElement)) { if (javac == null) { javac = new JavaCCompiler(); } return javac; } else if (JDTCompiler.isValidElement(currentElement)) { if (jdt == null) { jdt = new JDTCompiler(); } return jdt; } else { throw new UnsupportedOperationException("Unsupported compiler for element " + currentElement.getClass().getName() + "."); } }
@Override public String getMethodBody(ProcessingEnvironment env, ExecutableElement method) { try { /* * if (false) { Pair<JCTree, JCCompilationUnit> treeAndTopLevel = ((JavacElements) * env.getElementUtils()).getTreeAndTopLevel(method, null, null); JCBlock block = * ((JCMethodDecl) treeAndTopLevel.fst).getBody(); int startPos = block.pos; int endPos * = block.endpos; String methodBody = * treeAndTopLevel.snd.getSourceFile().getCharContent(true).subSequence(startPos + 1, * endPos).toString(); return methodBody; } */ Object treeAndTopLevel = getTreeAndTopLevel(env, method); Object block = method(field(treeAndTopLevel, "fst"), "getBody"); int startPos = (int) field(block, "pos"); int endPos = (int) field(block, "endpos"); return getContent(treeAndTopLevel).subSequence(startPos + 1, endPos).toString(); } catch (Exception e) { return ElementUtils.printException(e); } }
@Override public String getHeaderComment(ProcessingEnvironment env, Element type) { try { String content = getContent(getTreeAndTopLevel(env, type)).toString(); return parseHeader(content); } catch (Exception e) { return ElementUtils.printException(e); } }
private static Object getTreeAndTopLevel(ProcessingEnvironment env, Element element) throws Exception { /* * Pair<JCTree, JCCompilationUnit> treeAndTopLevel = ((JavacElements) * env.getElementUtils()).getTreeAndTopLevel(method, null, null); */ return method(method(env, "getElementUtils"), "getTreeAndTopLevel", getTreeAndTopLevelSignature, element, null, null); }
public static Compiler getCompiler(Element currentElement) { if (JavaCCompiler.isValidElement(currentElement)) { if (javac == null) { javac = new JavaCCompiler(); } return javac; } else if (JDTCompiler.isValidElement(currentElement)) { if (jdt == null) { jdt = new JDTCompiler(); } return jdt; } else { throw new UnsupportedOperationException("Unsupported compiler for element " + currentElement.getClass().getName() + "."); } }