Search in sources :

Example 76 with AnnotationMirror

use of javax.lang.model.element.AnnotationMirror in project graal by oracle.

the class AbstractCodeWriter method visitVariable.

@Override
public Void visitVariable(VariableElement f, Void p) {
    Element parent = f.getEnclosingElement();
    for (AnnotationMirror annotation : f.getAnnotationMirrors()) {
        visitAnnotation(f, annotation);
        write(" ");
    }
    CodeTree init = null;
    if (f instanceof CodeVariableElement) {
        init = ((CodeVariableElement) f).getInit();
    }
    if (parent != null && parent.getKind() == ElementKind.ENUM && f.getModifiers().contains(Modifier.STATIC)) {
        write(f.getSimpleName());
        if (init != null) {
            write("(");
            visitTree(init, p, f);
            write(")");
        }
    } else {
        writeModifiers(f.getModifiers(), true);
        boolean varArgs = false;
        if (parent != null && parent.getKind() == ElementKind.METHOD) {
            ExecutableElement method = (ExecutableElement) parent;
            if (method.isVarArgs() && method.getParameters().indexOf(f) == method.getParameters().size() - 1) {
                varArgs = true;
            }
        }
        TypeMirror varType = f.asType();
        if (varArgs) {
            if (varType.getKind() == TypeKind.ARRAY) {
                varType = ((ArrayType) varType).getComponentType();
            }
            write(useImport(f, varType));
            write("...");
        } else {
            write(useImport(f, varType));
        }
        write(" ");
        write(f.getSimpleName());
        if (init != null) {
            write(" = ");
            visitTree(init, p, f);
        }
    }
    return null;
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) CodeTree(com.oracle.truffle.dsl.processor.java.model.CodeTree) TypeMirror(javax.lang.model.type.TypeMirror) VariableElement(javax.lang.model.element.VariableElement) TypeElement(javax.lang.model.element.TypeElement) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement) CodeExecutableElement(com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement) CodeTypeElement(com.oracle.truffle.dsl.processor.java.model.CodeTypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) TypeParameterElement(javax.lang.model.element.TypeParameterElement) CodeExecutableElement(com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement) ExecutableElement(javax.lang.model.element.ExecutableElement) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)

Example 77 with AnnotationMirror

use of javax.lang.model.element.AnnotationMirror in project graal by oracle.

the class AbstractCodeWriter method visitExecutable.

@Override
public Void visitExecutable(CodeExecutableElement e, Void p) {
    for (AnnotationMirror annotation : e.getAnnotationMirrors()) {
        visitAnnotation(e, annotation);
        writeLn();
    }
    writeModifiers(e.getModifiers(), !e.getEnclosingClass().getModifiers().contains(Modifier.FINAL));
    List<TypeParameterElement> typeParameters = e.getTypeParameters();
    if (!typeParameters.isEmpty()) {
        write("<");
        for (int i = 0; i < typeParameters.size(); i++) {
            TypeParameterElement param = typeParameters.get(i);
            write(param.getSimpleName().toString());
            List<? extends TypeMirror> bounds = param.getBounds();
            if (!bounds.isEmpty()) {
                write(" extends ");
                for (int j = 0; j < bounds.size(); j++) {
                    TypeMirror bound = bounds.get(i);
                    write(useImport(e, bound));
                    if (j < bounds.size() - 1) {
                        write(" ");
                        write(", ");
                    }
                }
            }
            if (i < typeParameters.size() - 1) {
                write(" ");
                write(", ");
            }
        }
        write("> ");
    }
    if (e.getReturnType() != null) {
        write(useImport(e, e.getReturnType()));
        write(" ");
    }
    write(e.getSimpleName());
    write("(");
    for (int i = 0; i < e.getParameters().size(); i++) {
        VariableElement param = e.getParameters().get(i);
        param.accept(this, p);
        if (i < e.getParameters().size() - 1) {
            write(", ");
        }
    }
    write(")");
    List<TypeMirror> throwables = e.getThrownTypes();
    if (throwables.size() > 0) {
        write(" throws ");
        for (int i = 0; i < throwables.size(); i++) {
            write(useImport(e, throwables.get(i)));
            if (i < throwables.size() - 1) {
                write(", ");
            }
        }
    }
    if (e.getModifiers().contains(Modifier.ABSTRACT)) {
        writeLn(";");
    } else if (e.getBodyTree() != null) {
        writeLn(" {");
        indent(1);
        visitTree(e.getBodyTree(), p, e);
        dedent(1);
        writeLn("}");
    } else if (e.getBody() != null) {
        write(" {");
        write(e.getBody());
        writeLn("}");
    } else {
        writeLn(" {");
        writeLn("}");
    }
    writeEmptyLn();
    return null;
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeMirror(javax.lang.model.type.TypeMirror) VariableElement(javax.lang.model.element.VariableElement) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement) TypeParameterElement(javax.lang.model.element.TypeParameterElement)

Example 78 with AnnotationMirror

use of javax.lang.model.element.AnnotationMirror in project graal by oracle.

the class GenerateOverrideVisitor method visitExecutable.

@Override
public Void visitExecutable(CodeExecutableElement e, Void p) {
    if (!e.getModifiers().contains(Modifier.STATIC) && !e.getModifiers().contains(Modifier.PRIVATE)) {
        String name = e.getSimpleName().toString();
        TypeMirror[] params = e.getParameterTypes();
        for (AnnotationMirror mirror : e.getAnnotationMirrors()) {
            if (ElementUtils.typeEquals(overrideType, mirror.getAnnotationType())) {
                // already declared (may happen if method copied from super class)
                return super.visitExecutable(e, p);
            }
        }
        if (isDeclaredMethodInSuperType(e.getEnclosingClass(), name, params)) {
            e.addAnnotationMirror(new CodeAnnotationMirror(overrideType));
        }
    }
    return super.visitExecutable(e, p);
}
Also used : CodeAnnotationMirror(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationMirror) CodeAnnotationMirror(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationMirror) AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeMirror(javax.lang.model.type.TypeMirror)

Example 79 with AnnotationMirror

use of javax.lang.model.element.AnnotationMirror in project graal by oracle.

the class NodeParser method parseNodeData.

private NodeData parseNodeData(TypeElement templateType, List<TypeElement> typeHierarchy) {
    AnnotationMirror typeSystemMirror = findFirstAnnotation(typeHierarchy, TypeSystemReference.class);
    TypeSystemData typeSystem = null;
    if (typeSystemMirror != null) {
        TypeMirror typeSystemType = ElementUtils.getAnnotationValue(TypeMirror.class, typeSystemMirror, "value");
        typeSystem = (TypeSystemData) context.getTemplate(typeSystemType, true);
        if (typeSystem == null) {
            NodeData nodeData = new NodeData(context, templateType);
            nodeData.addError("The used type system '%s' is invalid. Fix errors in the type system first.", ElementUtils.getQualifiedName(typeSystemType));
            return nodeData;
        }
    } else {
        // default dummy type system
        typeSystem = new TypeSystemData(context, templateType, null, true);
    }
    boolean useNodeFactory = findFirstAnnotation(typeHierarchy, GenerateNodeFactory.class) != null;
    return new NodeData(context, templateType, typeSystem, useNodeFactory);
}
Also used : TypeSystemData(com.oracle.truffle.dsl.processor.model.TypeSystemData) AnnotationMirror(javax.lang.model.element.AnnotationMirror) ArrayCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) GenerateNodeFactory(com.oracle.truffle.api.dsl.GenerateNodeFactory) NodeData(com.oracle.truffle.dsl.processor.model.NodeData)

Example 80 with AnnotationMirror

use of javax.lang.model.element.AnnotationMirror in project graal by oracle.

the class TemplateMethodParser method parse.

public final List<E> parse(List<? extends Element> elements) {
    List<ExecutableElement> methods = new ArrayList<>();
    methods.addAll(ElementFilter.methodsIn(elements));
    List<E> parsedMethods = new ArrayList<>();
    boolean valid = true;
    int naturalOrder = 0;
    for (ExecutableElement method : methods) {
        if (!isParsable(method)) {
            continue;
        }
        Class<? extends Annotation> annotationType = getAnnotationType();
        AnnotationMirror mirror = null;
        if (annotationType != null) {
            mirror = ElementUtils.findAnnotationMirror(getContext().getEnvironment(), method, annotationType);
        }
        E parsedMethod = parse(naturalOrder, method, mirror);
        if (method.getModifiers().contains(Modifier.PRIVATE) && parser.isEmitErrors()) {
            parsedMethod.addError("Method annotated with @%s must not be private.", getAnnotationType().getSimpleName());
            parsedMethods.add(parsedMethod);
            valid = false;
            continue;
        }
        if (parsedMethod != null) {
            parsedMethods.add(parsedMethod);
        } else {
            valid = false;
        }
        naturalOrder++;
    }
    Collections.sort(parsedMethods);
    if (!valid && isParseNullOnError()) {
        return null;
    }
    return parsedMethods;
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) ExecutableElement(javax.lang.model.element.ExecutableElement) ArrayList(java.util.ArrayList)

Aggregations

AnnotationMirror (javax.lang.model.element.AnnotationMirror)665 TypeElement (javax.lang.model.element.TypeElement)159 ExecutableElement (javax.lang.model.element.ExecutableElement)112 TypeMirror (javax.lang.model.type.TypeMirror)99 ArrayList (java.util.ArrayList)92 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)90 Element (javax.lang.model.element.Element)87 VariableElement (javax.lang.model.element.VariableElement)79 AnnotationValue (javax.lang.model.element.AnnotationValue)73 DeclaredType (javax.lang.model.type.DeclaredType)58 List (java.util.List)52 CFValue (org.checkerframework.framework.flow.CFValue)52 Map (java.util.Map)46 HashSet (java.util.HashSet)40 JavaExpression (org.checkerframework.dataflow.expression.JavaExpression)39 CFStore (org.checkerframework.framework.flow.CFStore)39 HashMap (java.util.HashMap)37 QualifierHierarchy (org.checkerframework.framework.type.QualifierHierarchy)36 ExpressionTree (com.sun.source.tree.ExpressionTree)30 MethodTree (com.sun.source.tree.MethodTree)29