Search in sources :

Example 66 with TypeMirror

use of javax.lang.model.type.TypeMirror in project j2objc by google.

the class TreeConverter method needsImplicitSuperCall.

private static boolean needsImplicitSuperCall(MethodDeclaration node) {
    ExecutableElement method = node.getExecutableElement();
    if (!ElementUtil.isConstructor(method)) {
        return false;
    }
    TypeMirror superType = ElementUtil.getDeclaringClass(method).getSuperclass();
    if (TypeUtil.isNone(superType)) {
        // java.lang.Object supertype is null.
        return false;
    }
    List<Statement> stmts = node.getBody().getStatements();
    if (stmts.isEmpty()) {
        return true;
    }
    Statement firstStmt = stmts.get(0);
    return !(firstStmt instanceof SuperConstructorInvocation || firstStmt instanceof ConstructorInvocation);
}
Also used : ConstructorInvocation(com.google.devtools.j2objc.ast.ConstructorInvocation) SuperConstructorInvocation(com.google.devtools.j2objc.ast.SuperConstructorInvocation) TypeMirror(javax.lang.model.type.TypeMirror) ExpressionStatement(com.google.devtools.j2objc.ast.ExpressionStatement) ForStatement(com.google.devtools.j2objc.ast.ForStatement) EnhancedForStatement(com.google.devtools.j2objc.ast.EnhancedForStatement) BreakStatement(com.google.devtools.j2objc.ast.BreakStatement) ContinueStatement(com.google.devtools.j2objc.ast.ContinueStatement) AssertStatement(com.google.devtools.j2objc.ast.AssertStatement) DoStatement(com.google.devtools.j2objc.ast.DoStatement) LabeledStatement(com.google.devtools.j2objc.ast.LabeledStatement) VariableDeclarationStatement(com.google.devtools.j2objc.ast.VariableDeclarationStatement) WhileStatement(com.google.devtools.j2objc.ast.WhileStatement) Statement(com.google.devtools.j2objc.ast.Statement) EmptyStatement(com.google.devtools.j2objc.ast.EmptyStatement) SwitchStatement(com.google.devtools.j2objc.ast.SwitchStatement) ThrowStatement(com.google.devtools.j2objc.ast.ThrowStatement) SynchronizedStatement(com.google.devtools.j2objc.ast.SynchronizedStatement) TryStatement(com.google.devtools.j2objc.ast.TryStatement) IfStatement(com.google.devtools.j2objc.ast.IfStatement) TypeDeclarationStatement(com.google.devtools.j2objc.ast.TypeDeclarationStatement) ReturnStatement(com.google.devtools.j2objc.ast.ReturnStatement) ExecutableElement(javax.lang.model.element.ExecutableElement) SuperConstructorInvocation(com.google.devtools.j2objc.ast.SuperConstructorInvocation)

Example 67 with TypeMirror

use of javax.lang.model.type.TypeMirror in project j2objc by google.

the class JdtIntersectionType method fromJdtIntersection.

static JdtIntersectionType fromJdtIntersection(ITypeBinding t) {
    List<TypeMirror> bounds = new ArrayList<>();
    ITypeBinding superclass = t.getSuperclass();
    if (superclass != null) {
        bounds.add(BindingConverter.getType(superclass));
    }
    for (ITypeBinding intrface : t.getInterfaces()) {
        bounds.add(BindingConverter.getType(intrface));
    }
    return new JdtIntersectionType(t, bounds);
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) ArrayList(java.util.ArrayList)

Example 68 with TypeMirror

use of javax.lang.model.type.TypeMirror in project j2objc by google.

the class TreeConverter method convertIntersectionType.

private static TreeNode convertIntersectionType(org.eclipse.jdt.core.dom.IntersectionType node) {
    TypeMirror type = BindingConverter.getType(node.resolveBinding());
    IntersectionType newNode = new IntersectionType(type);
    for (Object x : node.types()) {
        newNode.addType((Type) convert(x));
    }
    return newNode;
}
Also used : IntersectionType(com.google.devtools.j2objc.ast.IntersectionType) TypeMirror(javax.lang.model.type.TypeMirror)

Example 69 with TypeMirror

use of javax.lang.model.type.TypeMirror in project error-prone by google.

the class RequiredAnnotationProcessor method validateElement.

private void validateElement(final Element element) {
    TypeMirror requiredAnnotationTypeMirror = processingEnv.getElementUtils().getTypeElement(RequiredAnnotation.class.getName()).asType();
    for (final AnnotationMirror annotation : processingEnv.getElementUtils().getAllAnnotationMirrors(element)) {
        AnnotationMirror requiredAnnotationMirror = getAnnotationMirror(annotation.getAnnotationType().asElement(), requiredAnnotationTypeMirror);
        if (requiredAnnotationMirror == null) {
            continue;
        }
        AnnotationValue value = getAnnotationValue(requiredAnnotationMirror, "value");
        if (value == null) {
            continue;
        }
        new SimpleAnnotationValueVisitor7<Void, Void>() {

            @Override
            public Void visitType(TypeMirror t, Void p) {
                if (getAnnotationMirror(element, t) == null) {
                    printError(element, annotation, "Annotation %s on %s also requires %s", annotation, element, t);
                }
                return null;
            }

            @Override
            public Void visitArray(List<? extends AnnotationValue> vals, Void p) {
                for (AnnotationValue val : vals) {
                    visit(val);
                }
                return null;
            }
        }.visit(value);
    }
    validateElements(element.getEnclosedElements());
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeMirror(javax.lang.model.type.TypeMirror) AnnotationValue(javax.lang.model.element.AnnotationValue)

Example 70 with TypeMirror

use of javax.lang.model.type.TypeMirror in project camel by apache.

the class CoreEipAnnotationProcessor method findClassProperties.

protected void findClassProperties(ProcessingEnvironment processingEnv, PrintWriter writer, RoundEnvironment roundEnv, Set<EipOption> eipOptions, TypeElement originalClassType, TypeElement classElement, String prefix, String modelName) {
    while (true) {
        List<VariableElement> fieldElements = ElementFilter.fieldsIn(classElement.getEnclosedElements());
        for (VariableElement fieldElement : fieldElements) {
            String fieldName = fieldElement.getSimpleName().toString();
            XmlAttribute attribute = fieldElement.getAnnotation(XmlAttribute.class);
            if (attribute != null) {
                boolean skip = processAttribute(processingEnv, roundEnv, originalClassType, classElement, fieldElement, fieldName, attribute, eipOptions, prefix, modelName);
                if (skip) {
                    continue;
                }
            }
            XmlValue value = fieldElement.getAnnotation(XmlValue.class);
            if (value != null) {
                processValue(processingEnv, roundEnv, originalClassType, classElement, fieldElement, fieldName, value, eipOptions, prefix, modelName);
            }
            XmlElements elements = fieldElement.getAnnotation(XmlElements.class);
            if (elements != null) {
                processElements(processingEnv, roundEnv, classElement, elements, fieldElement, eipOptions, prefix);
            }
            XmlElement element = fieldElement.getAnnotation(XmlElement.class);
            if (element != null) {
                processElement(processingEnv, roundEnv, classElement, element, fieldElement, eipOptions, prefix);
            }
            // special for eips which has outputs or requires an expressions
            XmlElementRef elementRef = fieldElement.getAnnotation(XmlElementRef.class);
            if (elementRef != null) {
                // special for routes
                processRoutes(roundEnv, originalClassType, elementRef, fieldElement, fieldName, eipOptions, prefix);
                // special for outputs
                processOutputs(processingEnv, roundEnv, originalClassType, elementRef, fieldElement, fieldName, eipOptions, prefix);
                // special for when clauses (choice eip)
                processRefWhenClauses(processingEnv, roundEnv, originalClassType, elementRef, fieldElement, fieldName, eipOptions, prefix);
                // special for rests (rest-dsl)
                processRests(roundEnv, originalClassType, elementRef, fieldElement, fieldName, eipOptions, prefix);
                // special for verbs (rest-dsl)
                processVerbs(processingEnv, roundEnv, originalClassType, elementRef, fieldElement, fieldName, eipOptions, prefix);
                // special for expression
                processRefExpression(processingEnv, roundEnv, originalClassType, classElement, elementRef, fieldElement, fieldName, eipOptions, prefix);
            }
        }
        // special when we process these nodes as they do not use JAXB annotations on fields, but on methods
        if ("OptionalIdentifiedDefinition".equals(classElement.getSimpleName().toString())) {
            processIdentified(processingEnv, roundEnv, originalClassType, classElement, eipOptions, prefix);
        } else if ("RouteDefinition".equals(classElement.getSimpleName().toString())) {
            processRoute(processingEnv, roundEnv, originalClassType, classElement, eipOptions, prefix);
        }
        // check super classes which may also have fields
        TypeElement baseTypeElement = null;
        TypeMirror superclass = classElement.getSuperclass();
        if (superclass != null) {
            String superClassName = canonicalClassName(superclass.toString());
            baseTypeElement = findTypeElement(processingEnv, roundEnv, superClassName);
        }
        if (baseTypeElement != null) {
            classElement = baseTypeElement;
        } else {
            break;
        }
    }
}
Also used : XmlElementRef(javax.xml.bind.annotation.XmlElementRef) XmlElements(javax.xml.bind.annotation.XmlElements) XmlAttribute(javax.xml.bind.annotation.XmlAttribute) TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) AnnotationProcessorHelper.findTypeElement(org.apache.camel.tools.apt.AnnotationProcessorHelper.findTypeElement) XmlValue(javax.xml.bind.annotation.XmlValue) XmlElement(javax.xml.bind.annotation.XmlElement) VariableElement(javax.lang.model.element.VariableElement)

Aggregations

TypeMirror (javax.lang.model.type.TypeMirror)1086 TypeElement (javax.lang.model.element.TypeElement)419 ExecutableElement (javax.lang.model.element.ExecutableElement)259 VariableElement (javax.lang.model.element.VariableElement)237 Element (javax.lang.model.element.Element)196 DeclaredType (javax.lang.model.type.DeclaredType)177 ArrayList (java.util.ArrayList)154 Test (org.junit.Test)152 AnnotationMirror (javax.lang.model.element.AnnotationMirror)75 Types (javax.lang.model.util.Types)70 List (java.util.List)66 Elements (javax.lang.model.util.Elements)60 HashSet (java.util.HashSet)53 ArrayCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror)50 Map (java.util.Map)49 ExecutableType (javax.lang.model.type.ExecutableType)45 MethodSpec (com.squareup.javapoet.MethodSpec)44 PackageElement (javax.lang.model.element.PackageElement)41 ArrayType (javax.lang.model.type.ArrayType)41 Expression (com.google.devtools.j2objc.ast.Expression)39