Search in sources :

Example 96 with Elements

use of javax.lang.model.util.Elements in project blue by kunstmusik.

the class ProjectPluginEditorItemProcessor method handleProcess.

@Override
protected boolean handleProcess(Set<? extends TypeElement> set, RoundEnvironment env) throws LayerGenerationException {
    Elements elements = processingEnv.getElementUtils();
    for (Element e : env.getElementsAnnotatedWith(ProjectPluginEditorItem.class)) {
        TypeElement clazz = (TypeElement) e;
        String teName = elements.getBinaryName(clazz).toString();
        ProjectPluginEditorItem ppePlugin = clazz.getAnnotation(ProjectPluginEditorItem.class);
        File f = layer(e).file("blue/project/plugins/editors/" + teName.replace('.', '-') + ".instance").intvalue("position", ppePlugin.position()).bundlevalue("displayName", ppePlugin.displayName());
        f.write();
    }
    return true;
}
Also used : TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) Elements(javax.lang.model.util.Elements) File(org.openide.filesystems.annotations.LayerBuilder.File) ProjectPluginEditorItem(blue.plugin.ProjectPluginEditorItem)

Example 97 with Elements

use of javax.lang.model.util.Elements in project blue by kunstmusik.

the class SoundObjectPluginProcessor method handleProcess.

@Override
protected boolean handleProcess(Set<? extends TypeElement> set, RoundEnvironment env) throws LayerGenerationException {
    Elements elements = processingEnv.getElementUtils();
    for (Element e : env.getElementsAnnotatedWith(SoundObjectPlugin.class)) {
        TypeElement clazz = (TypeElement) e;
        SoundObjectPlugin sObjPlugin = clazz.getAnnotation(SoundObjectPlugin.class);
        String teName = elements.getBinaryName(clazz).toString();
        File f = layer(e).file("blue/score/soundObjects/" + teName.replace('.', '-') + ".instance").intvalue("position", sObjPlugin.position()).bundlevalue("displayName", sObjPlugin.displayName()).boolvalue("live", sObjPlugin.live());
        f.write();
    }
    return true;
}
Also used : TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) Elements(javax.lang.model.util.Elements) File(org.openide.filesystems.annotations.LayerBuilder.File) SoundObjectPlugin(blue.plugin.SoundObjectPlugin)

Example 98 with Elements

use of javax.lang.model.util.Elements in project blue by kunstmusik.

the class ProjectPluginItemProcessor method handleProcess.

@Override
protected boolean handleProcess(Set<? extends TypeElement> set, RoundEnvironment env) throws LayerGenerationException {
    Elements elements = processingEnv.getElementUtils();
    for (Element e : env.getElementsAnnotatedWith(ProjectPluginItem.class)) {
        TypeElement clazz = (TypeElement) e;
        String teName = elements.getBinaryName(clazz).toString();
        ProjectPluginItem ppePlugin = clazz.getAnnotation(ProjectPluginItem.class);
        File f = layer(e).file("blue/project/plugins/" + teName.replace('.', '-') + ".instance").intvalue("position", ppePlugin.position());
        f.write();
    }
    return true;
}
Also used : TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) Elements(javax.lang.model.util.Elements) ProjectPluginItem(blue.plugin.ProjectPluginItem) File(org.openide.filesystems.annotations.LayerBuilder.File)

Example 99 with Elements

use of javax.lang.model.util.Elements in project kripton by xcesco.

the class BindTypeBuilder method generate.

/**
 * @return typeName of generated class
 *
 * @throws IOException
 */
public static String generate(Filer filer, BindEntity item) throws IOException {
    Elements elementUtils = BaseProcessor.elementUtils;
    String beanClassName = item.getSimpleName().toString();
    boolean needSuffix = true;
    if (beanClassName.endsWith(SUFFIX)) {
        needSuffix = false;
    }
    String className = PREFIX + beanClassName + (needSuffix ? SUFFIX : "");
    PackageElement pkg = elementUtils.getPackageOf(item.getElement());
    String packageName = pkg.isUnnamed() ? "" : pkg.getQualifiedName().toString();
    AnnotationProcessorUtilis.infoOnGeneratedClasses(BindType.class, packageName, className);
    // @formatter:off
    TypeSpec.Builder builder = TypeSpec.classBuilder(className).addAnnotation(AnnotationSpec.builder(BindMap.class).addMember("value", "$T.class", typeName(item.getElement().asType())).build()).addModifiers(Modifier.PUBLIC).superclass(TypeUtility.parameterizedTypeName(className(AbstractMapper.class), typeName(item.getElement().asType())));
    BindTypeContext context = new BindTypeContext(builder, TypeUtility.typeName(packageName, className), Modifier.PRIVATE);
    // @formatter:on
    builder.addJavadoc("This class is binder map for $T\n\n", item.getElement());
    JavadocUtility.generateJavadocGeneratedBy(builder);
    builder.addJavadoc("@see $T\n", item.getElement());
    // order item by order, property typeName
    Collections.sort(item.getCollection(), new Comparator<BindProperty>() {

        @Override
        public int compare(BindProperty lhs, BindProperty rhs) {
            int c1 = lhs.order - rhs.order;
            if (c1 != 0)
                return c1;
            return lhs.getName().compareTo(rhs.getName());
        }
    });
    // generate serializeOnJackson
    generateSerializeOnJackson(context, item);
    // generate serializeOnJacksonAsString
    generateSerializeOnJacksonAsString(context, item);
    // order item by type (attribute, element, value), order, xmlName
    Collections.sort(item.getCollection(), new Comparator<BindProperty>() {

        @Override
        public int compare(BindProperty lhs, BindProperty rhs) {
            int c1 = lhs.xmlInfo.xmlType.ordinal() - rhs.xmlInfo.xmlType.ordinal();
            if (c1 != 0)
                return c1;
            c1 = lhs.order - rhs.order;
            if (c1 != 0)
                return c1;
            return lhs.label.compareTo(rhs.label);
        }
    });
    // generate serializeOnXml
    generateSerializeOnXml(context, item);
    // generate parseOnJackson
    generateParseOnJackson(context, item);
    // generate parseOnJacksonAsString
    generateParseOnJacksonAsString(context, item);
    // generate parseOnXml
    generateParseOnXml(context, item);
    TypeSpec typeSpec = builder.build();
    JavaWriterHelper.writeJava2File(filer, packageName, typeSpec);
    return className;
}
Also used : PackageElement(javax.lang.model.element.PackageElement) BindMap(com.abubusoft.kripton.annotation.BindMap) Elements(javax.lang.model.util.Elements) BindProperty(com.abubusoft.kripton.processor.bind.model.BindProperty) TypeSpec(com.squareup.javapoet.TypeSpec)

Example 100 with Elements

use of javax.lang.model.util.Elements in project kripton by xcesco.

the class AnnotationUtility method extractAsInt.

public static int extractAsInt(Element item, Class<? extends Annotation> annotationClass, AnnotationAttributeType attributeName) {
    final Elements elementUtils = BaseProcessor.elementUtils;
    final One<Integer> result = new One<Integer>();
    result.value0 = 0;
    extractString(elementUtils, item, annotationClass, attributeName, new OnAttributeFoundListener() {

        @Override
        public void onFound(String value) {
            result.value0 = Integer.parseInt(value);
        }
    });
    return result.value0;
}
Also used : One(com.abubusoft.kripton.common.One) Elements(javax.lang.model.util.Elements)

Aggregations

Elements (javax.lang.model.util.Elements)146 TypeElement (javax.lang.model.element.TypeElement)90 TypeMirror (javax.lang.model.type.TypeMirror)52 Element (javax.lang.model.element.Element)46 Types (javax.lang.model.util.Types)40 VariableElement (javax.lang.model.element.VariableElement)35 ExecutableElement (javax.lang.model.element.ExecutableElement)32 Map (java.util.Map)18 ArrayList (java.util.ArrayList)17 SupportedAnnotationTypes (javax.annotation.processing.SupportedAnnotationTypes)17 PackageElement (javax.lang.model.element.PackageElement)17 LinkedHashSet (java.util.LinkedHashSet)15 AnnotationMirror (javax.lang.model.element.AnnotationMirror)15 Test (org.junit.Test)15 List (java.util.List)14 XmlElements (javax.xml.bind.annotation.XmlElements)14 Metadata (org.apache.camel.spi.Metadata)14 Set (java.util.Set)12 DeclaredType (javax.lang.model.type.DeclaredType)12 AnnotationProcessorHelper.findTypeElement (org.apache.camel.tools.apt.AnnotationProcessorHelper.findTypeElement)12