Search in sources :

Example 91 with Elements

use of javax.lang.model.util.Elements in project checker-framework by typetools.

the class DefaultTypeHierarchy method castedAsSuper.

/**
 * Calls asSuper and casts the result to the same type as the input supertype
 *
 * @param subtype subtype to be transformed to supertype
 * @param supertype supertype that subtype is transformed to
 * @param <T> the type of supertype and return type
 * @return subtype as an instance of supertype
 */
@SuppressWarnings("unchecked")
public static <T extends AnnotatedTypeMirror> T castedAsSuper(final AnnotatedTypeMirror subtype, final T supertype) {
    final Types types = subtype.atypeFactory.getProcessingEnv().getTypeUtils();
    final Elements elements = subtype.atypeFactory.getProcessingEnv().getElementUtils();
    if (subtype.getKind() == TypeKind.NULL) {
        // Make a copy of the supertype so that if supertype is a composite type, the
        // returned type will be fully annotated.  (For example, if sub is @C null and super is
        // @A List<@B String>, then the returned type is @C List<@B String>.)
        T copy = (T) supertype.deepCopy();
        copy.replaceAnnotations(subtype.getAnnotations());
        return copy;
    }
    final T asSuperType = AnnotatedTypes.asSuper(subtype.atypeFactory, subtype, supertype);
    fixUpRawTypes(subtype, asSuperType, supertype, types);
    // @1 Enum<@2 E>
    if (asSuperType != null && isEnum(asSuperType) && isDeclarationOfJavaLangEnum(types, elements, supertype)) {
        final AnnotatedDeclaredType resultAtd = ((AnnotatedDeclaredType) supertype).deepCopy();
        resultAtd.clearAnnotations();
        resultAtd.addAnnotations(asSuperType.getAnnotations());
        final AnnotatedDeclaredType asSuperAdt = (AnnotatedDeclaredType) asSuperType;
        if (resultAtd.getTypeArguments().size() > 0 && asSuperAdt.getTypeArguments().size() > 0) {
            final AnnotatedTypeMirror sourceTypeArg = asSuperAdt.getTypeArguments().get(0);
            final AnnotatedTypeMirror resultTypeArg = resultAtd.getTypeArguments().get(0);
            resultTypeArg.clearAnnotations();
            resultTypeArg.addAnnotations(sourceTypeArg.getAnnotations());
            return (T) resultAtd;
        }
    }
    return asSuperType;
}
Also used : Types(javax.lang.model.util.Types) AnnotatedTypes(org.checkerframework.framework.util.AnnotatedTypes) AnnotatedDeclaredType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType) Elements(javax.lang.model.util.Elements)

Example 92 with Elements

use of javax.lang.model.util.Elements in project checker-framework by typetools.

the class LubGlbChecker method initChecker.

@Override
public void initChecker() {
    super.initChecker();
    Elements elements = processingEnv.getElementUtils();
    A = AnnotationBuilder.fromClass(elements, A.class);
    B = AnnotationBuilder.fromClass(elements, B.class);
    C = AnnotationBuilder.fromClass(elements, C.class);
    D = AnnotationBuilder.fromClass(elements, D.class);
    E = AnnotationBuilder.fromClass(elements, E.class);
    F = AnnotationBuilder.fromClass(elements, F.class);
    POLY = AnnotationBuilder.fromClass(elements, Poly.class);
    QualifierHierarchy qh = ((BaseTypeVisitor<?>) visitor).getTypeFactory().getQualifierHierarchy();
    // System.out.println("LUB of D and E: " + qh.leastUpperBound(D, E));
    assert AnnotationUtils.areSame(qh.leastUpperBound(D, E), C) : "LUB of D and E is not C!";
    // System.out.println("LUB of E and D: " + qh.leastUpperBound(E, D));
    assert AnnotationUtils.areSame(qh.leastUpperBound(E, D), C) : "LUB of E and D is not C!";
    // System.out.println("GLB of B and C: " + qh.greatestLowerBound(B, C));
    assert AnnotationUtils.areSame(qh.greatestLowerBound(B, C), D) : "GLB of B and C is not D!";
    // System.out.println("GLB of C and B: " + qh.greatestLowerBound(C, B));
    assert AnnotationUtils.areSame(qh.greatestLowerBound(C, B), D) : "GLB of C and B is not D!";
    assert AnnotationUtils.areSame(qh.greatestLowerBound(POLY, B), F) : "GLB of POLY and B is not F!";
    assert AnnotationUtils.areSame(qh.greatestLowerBound(POLY, F), F) : "GLB of POLY and F is not F!";
    assert AnnotationUtils.areSame(qh.greatestLowerBound(POLY, A), POLY) : "GLB of POLY and A is not POLY!";
    assert AnnotationUtils.areSame(qh.leastUpperBound(POLY, B), A) : "LUB of POLY and B is not A!";
    assert AnnotationUtils.areSame(qh.leastUpperBound(POLY, F), POLY) : "LUB of POLY and F is not POLY!";
    assert AnnotationUtils.areSame(qh.leastUpperBound(POLY, A), A) : "LUB of POLY and A is not A!";
}
Also used : A(lubglb.quals.A) B(lubglb.quals.B) C(lubglb.quals.C) D(lubglb.quals.D) E(lubglb.quals.E) F(lubglb.quals.F) QualifierHierarchy(org.checkerframework.framework.type.QualifierHierarchy) Poly(lubglb.quals.Poly) Elements(javax.lang.model.util.Elements)

Example 93 with Elements

use of javax.lang.model.util.Elements in project SpongeAPI by SpongePowered.

the class ListenerProcessor method isTypeSubclass.

private boolean isTypeSubclass(Element typedElement, String subclass) {
    Elements elements = this.processingEnv.getElementUtils();
    Types types = this.processingEnv.getTypeUtils();
    TypeMirror event = types.getDeclaredType(elements.getTypeElement(subclass));
    return types.isAssignable(typedElement.asType(), event);
}
Also used : Types(javax.lang.model.util.Types) SupportedAnnotationTypes(javax.annotation.processing.SupportedAnnotationTypes) TypeMirror(javax.lang.model.type.TypeMirror) Elements(javax.lang.model.util.Elements)

Example 94 with Elements

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

the class BarRendererPluginProcessor method handleProcess.

@Override
protected boolean handleProcess(Set<? extends TypeElement> set, RoundEnvironment env) throws LayerGenerationException {
    Elements elements = processingEnv.getElementUtils();
    for (Element e : env.getElementsAnnotatedWith(BarRendererPlugin.class)) {
        TypeElement clazz = (TypeElement) e;
        String teName = elements.getBinaryName(clazz).toString();
        BarRendererPlugin barRendererPlugin = clazz.getAnnotation(BarRendererPlugin.class);
        File f = layer(e).file("blue/score/barRenderers/" + teName.replace('.', '-') + ".instance");
        TypeMirror tm = null;
        try {
            barRendererPlugin.scoreObjectType();
        } catch (MirroredTypeException mte) {
            tm = mte.getTypeMirror();
        }
        f.stringvalue("scoreObjectType", tm.toString());
        f.write();
    }
    return true;
}
Also used : BarRendererPlugin(blue.plugin.BarRendererPlugin) MirroredTypeException(javax.lang.model.type.MirroredTypeException) TypeMirror(javax.lang.model.type.TypeMirror) 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)

Example 95 with Elements

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

the class InstrumentPluginProcessor method handleProcess.

@Override
protected boolean handleProcess(Set<? extends TypeElement> set, RoundEnvironment env) throws LayerGenerationException {
    Elements elements = processingEnv.getElementUtils();
    for (Element e : env.getElementsAnnotatedWith(InstrumentPlugin.class)) {
        TypeElement clazz = (TypeElement) e;
        InstrumentPlugin noteProcessorPlugin = clazz.getAnnotation(InstrumentPlugin.class);
        String teName = elements.getBinaryName(clazz).toString();
        File f = layer(e).file("blue/instruments/" + teName.replace('.', '-') + ".instance").intvalue("position", noteProcessorPlugin.position()).bundlevalue("displayName", noteProcessorPlugin.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) InstrumentPlugin(blue.plugin.InstrumentPlugin) File(org.openide.filesystems.annotations.LayerBuilder.File)

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