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;
}
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;
}
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);
}
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);
}
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;
}
Aggregations