Search in sources :

Example 1 with JCodeModel

use of com.helger.jcodemodel.JCodeModel in project androidannotations by androidannotations.

the class APTCodeModelHelper method createDelegatingAnonymousRunnableClass.

public JDefinedClass createDelegatingAnonymousRunnableClass(JBlock previousBody) {
    JCodeModel codeModel = environment.getCodeModel();
    JDefinedClass anonymousRunnableClass = codeModel.anonymousClass(Runnable.class);
    JMethod runMethod = anonymousRunnableClass.method(JMod.PUBLIC, codeModel.VOID, "run");
    runMethod.annotate(Override.class);
    runMethod.body().add(previousBody);
    return anonymousRunnableClass;
}
Also used : JDefinedClass(com.helger.jcodemodel.JDefinedClass) JMethod(com.helger.jcodemodel.JMethod) JCodeModel(com.helger.jcodemodel.JCodeModel)

Example 2 with JCodeModel

use of com.helger.jcodemodel.JCodeModel in project adt4j by sviperll.

the class GenerateValueClassForVisitorProcessor method finishProcessing.

private void finishProcessing() {
    Set<TypeElement> elements = new HashSet<>();
    for (String path : remainingElements) {
        TypeElement typeElement = processingEnv.getElementUtils().getTypeElement(path);
        if (typeElement == null)
            processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Unable to find type " + path);
        else
            elements.add(typeElement);
    }
    ElementProcessor elementProcessor = new ElementProcessor(elements, new JCodeModel());
    elementProcessor.generateClasses();
    elementProcessor.writeGeneratedCode();
    for (Entry<String, List<String>> errors : errorMap.entrySet()) {
        TypeElement typeElement = processingEnv.getElementUtils().getTypeElement(errors.getKey());
        for (String error : errors.getValue()) {
            processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, error, typeElement);
        }
    }
}
Also used : TypeElement(javax.lang.model.element.TypeElement) ArrayList(java.util.ArrayList) List(java.util.List) JCodeModel(com.helger.jcodemodel.JCodeModel) HashSet(java.util.HashSet)

Example 3 with JCodeModel

use of com.helger.jcodemodel.JCodeModel in project adt4j by sviperll.

the class GenerateValueClassForVisitorProcessor method processRound.

private void processRound(RoundEnvironment roundEnv) {
    Set<TypeElement> elements = new HashSet<>();
    for (Element element : roundEnv.getElementsAnnotatedWith(GenerateValueClassForVisitor.class)) {
        elements.add((TypeElement) element);
    }
    for (Element element : roundEnv.getElementsAnnotatedWith(WrapsGeneratedValueClass.class)) {
        elements.add((TypeElement) element);
    }
    Set<String> elementsFromPreviousRound = new HashSet<>(remainingElements);
    remainingElements.clear();
    for (String path : elementsFromPreviousRound) {
        TypeElement typeElement = processingEnv.getElementUtils().getTypeElement(path);
        if (typeElement == null)
            remainingElements.add(path);
        else
            elements.add(typeElement);
    }
    ElementProcessor elementProcessor = new ElementProcessor(elements, new JCodeModel());
    elementProcessor.generateClassesWithoutErrors();
    elementProcessor.writeGeneratedCode();
}
Also used : TypeElement(javax.lang.model.element.TypeElement) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) JCodeModel(com.helger.jcodemodel.JCodeModel) HashSet(java.util.HashSet)

Aggregations

JCodeModel (com.helger.jcodemodel.JCodeModel)3 HashSet (java.util.HashSet)2 TypeElement (javax.lang.model.element.TypeElement)2 JDefinedClass (com.helger.jcodemodel.JDefinedClass)1 JMethod (com.helger.jcodemodel.JMethod)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Element (javax.lang.model.element.Element)1