private static Object lookupBinaryType(Object binding) throws Exception { Object lookupEnvironment = field(binding, "environment"); Object compoundClassName = field(binding, "compoundName"); Object nameEnvironment = field(lookupEnvironment, "nameEnvironment"); Object nameEnvironmentAnswer = method(nameEnvironment, "findType", new Class[]{char[][].class}, compoundClassName); Object binaryType = method(nameEnvironmentAnswer, "getBinaryType", new Class[0]); return binaryType; }
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); }
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() + "."); } }
private List<Element> loadMembers(TypeElement templateType) { List<Element> members = new ArrayList<>(CompilerFactory.getCompiler(templateType).getAllMembersInDeclarationOrder(context.getEnvironment(), templateType)); return members; }
private static List<Object> findSourceTypeOrder(Object binding) throws Exception { Object referenceContext = field(field(binding, "scope"), "referenceContext"); TreeMap<Integer, Object> orderedBindings = new TreeMap<>(); collectSourceOrder(orderedBindings, referenceContext, "methods"); collectSourceOrder(orderedBindings, referenceContext, "fields"); collectSourceOrder(orderedBindings, referenceContext, "memberTypes"); return new ArrayList<>(orderedBindings.values()); }
@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); } }
@Override protected void writeHeader() { if (env == null) { return; } String comment = CompilerFactory.getCompiler(originalElement).getHeaderComment(env, originalElement); if (comment != null) { writeLn(comment); } writeLn("// CheckStyle: start generated"); }
@Override public List<? extends Element> getAllMembersInDeclarationOrder(ProcessingEnvironment environment, TypeElement type) { return sortBySourceOrder(newElementList(environment.getElementUtils().getAllMembers(type))); }
private static void collectSourceOrder(TreeMap<Integer, Object> orderedBindings, Object referenceContext, String fieldName) throws Exception { Object[] declarations = (Object[]) field(referenceContext, fieldName); if (declarations != null) { for (int i = 0; i < declarations.length; i++) { Integer declarationSourceStart = (Integer) field(declarations[i], "declarationSourceStart"); orderedBindings.put(declarationSourceStart, field(declarations[i], "binding")); } } } }
public List<? extends Element> getEnclosedElementsInDeclarationOrder(TypeElement type) { return sortBySourceOrder(new ArrayList<>(type.getEnclosedElements())); }
@Override public String getHeaderComment(ProcessingEnvironment env, Element type) { try { char[] source = getSource(type); if (source == null) { return null; } return parseHeader(new String(source)); } catch (Exception e) { return ElementUtils.printException(e); } }
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() + "."); } }
private static Object lookupBinaryType(Object binding) throws Exception { Object lookupEnvironment = field(binding, "environment"); Object compoundClassName = field(binding, "compoundName"); Object nameEnvironment = field(lookupEnvironment, "nameEnvironment"); Object nameEnvironmentAnswer = method(nameEnvironment, "findType", new Class<?>[]{char[][].class}, compoundClassName); Object binaryType = method(nameEnvironmentAnswer, "getBinaryType", new Class<?>[0]); return binaryType; }
private List<Element> loadMembers(TypeElement templateType) { return newElementList(CompilerFactory.getCompiler(templateType).getAllMembersInDeclarationOrder(context.getEnvironment(), templateType)); }
private static List<Object> findSourceTypeOrder(Object binding) throws Exception { Object referenceContext = field(field(binding, "scope"), "referenceContext"); TreeMap<Integer, Object> orderedBindings = new TreeMap<>(); collectSourceOrder(orderedBindings, referenceContext, "methods"); collectSourceOrder(orderedBindings, referenceContext, "fields"); collectSourceOrder(orderedBindings, referenceContext, "memberTypes"); return new ArrayList<>(orderedBindings.values()); }
private static void collectSourceOrder(TreeMap<Integer, Object> orderedBindings, Object referenceContext, String fieldName) throws Exception { Object[] declarations = (Object[]) field(referenceContext, fieldName); if (declarations != null) { for (int i = 0; i < declarations.length; i++) { Integer declarationSourceStart = (Integer) field(declarations[i], "declarationSourceStart"); orderedBindings.put(declarationSourceStart, field(declarations[i], "binding")); } } }
public List<? extends Element> getAllMembersInDeclarationOrder(ProcessingEnvironment environment, TypeElement type) { return sortBySourceOrder(new ArrayList<>(environment.getElementUtils().getAllMembers(type))); }