use of com.sun.tools.javac.code.Attribute in project bazel by bazelbuild.
the class TypeAnnotationUtils method createCompoundFromAnnotationMirror.
/**
* Returns a newly created Attribute.Compound corresponding to an
* argument AnnotationMirror.
*
* @param am an AnnotationMirror, which may be part of an AST or an internally
* created subclass.
* @return a new Attribute.Compound corresponding to the AnnotationMirror
*/
public static Attribute.Compound createCompoundFromAnnotationMirror(ProcessingEnvironment env, AnnotationMirror am) {
// Create a new Attribute to match the AnnotationMirror.
List<Pair<Symbol.MethodSymbol, Attribute>> values = List.nil();
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : am.getElementValues().entrySet()) {
Attribute attribute = attributeFromAnnotationValue(env, entry.getKey(), entry.getValue());
values = values.append(new Pair<>((Symbol.MethodSymbol) entry.getKey(), attribute));
}
return new Attribute.Compound((Type.ClassType) am.getAnnotationType(), values);
}
use of com.sun.tools.javac.code.Attribute in project bazel by bazelbuild.
the class TypeAnnotationUtils method createTypeCompoundFromAnnotationMirror.
/**
* Returns a newly created Attribute.TypeCompound corresponding to an
* argument AnnotationMirror.
*
* @param am an AnnotationMirror, which may be part of an AST or an internally
* created subclass.
* @param tapos the type annotation position to use.
* @return a new Attribute.TypeCompound corresponding to the AnnotationMirror
*/
public static Attribute.TypeCompound createTypeCompoundFromAnnotationMirror(ProcessingEnvironment env, AnnotationMirror am, TypeAnnotationPosition tapos) {
// Create a new Attribute to match the AnnotationMirror.
List<Pair<Symbol.MethodSymbol, Attribute>> values = List.nil();
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : am.getElementValues().entrySet()) {
Attribute attribute = attributeFromAnnotationValue(env, entry.getKey(), entry.getValue());
values = values.append(new Pair<>((Symbol.MethodSymbol) entry.getKey(), attribute));
}
return new Attribute.TypeCompound((Type.ClassType) am.getAnnotationType(), values, tapos);
}
use of com.sun.tools.javac.code.Attribute in project ceylon-compiler by ceylon.
the class JavacAnnotation method attributeToRefl.
private Object attributeToRefl(Attribute attr) {
if (attr == null)
return null;
if (attr instanceof Attribute.Constant)
return attr.getValue();
if (attr instanceof Attribute.Array) {
Attribute[] values = ((Attribute.Array) attr).values;
List<Object> list = new ArrayList<Object>(values.length);
for (Attribute elem : values) {
list.add(attributeToRefl(elem));
}
return list;
}
if (attr instanceof Attribute.Compound)
return new JavacAnnotation((Compound) attr);
if (attr instanceof Attribute.Enum)
return ((Attribute.Enum) attr).getValue().name.toString();
if (attr instanceof Attribute.Class)
return new JavacType(((Attribute.Class) attr).getValue());
// FIXME: turn into error
throw new RuntimeException("Unknown attribute type: " + attr);
}
use of com.sun.tools.javac.code.Attribute in project ceylon-compiler by ceylon.
the class JavacAnnotation method getValue.
@Override
public Object getValue(String fieldName) {
Object result = attributes.get(fieldName);
if (result == null) {
Attribute attr = member(fieldName);
result = attributeToRefl(attr);
attributes.put(fieldName, result);
}
return result;
}
use of com.sun.tools.javac.code.Attribute in project ceylon-compiler by ceylon.
the class AnnotationMirrorImpl method toString.
/**
* Returns a string representation of this annotation.
* String is of one of the forms:
* @com.example.foo(name1=val1, name2=val2)
* @com.example.foo(val)
* @com.example.foo
* Omit parens for marker annotations, and omit "value=" when allowed.
*/
public String toString() {
StringBuilder sb = new StringBuilder("@");
Constants.Formatter fmtr = Constants.getFormatter(sb);
fmtr.append(anno.type.tsym);
int len = anno.values.length();
if (len > 0) {
// omit parens for marker annotations
sb.append('(');
boolean first = true;
for (Pair<MethodSymbol, Attribute> val : anno.values) {
if (!first) {
sb.append(", ");
}
first = false;
Name name = val.fst.name;
if (len > 1 || name != env.names.value) {
fmtr.append(name);
sb.append('=');
}
sb.append(new AnnotationValueImpl(env, val.snd, this));
}
sb.append(')');
}
return fmtr.toString();
}
Aggregations