use of com.google.devtools.j2objc.ast.MemberValuePair in project j2objc by google.
the class TreeConverter method convertAnnotation.
private TreeNode convertAnnotation(JCTree.JCAnnotation node) {
List<JCTree.JCExpression> args = node.getArguments();
String annotationName = node.getAnnotationType().toString();
boolean isPropertyAnnotation = annotationName.equals(Property.class.getSimpleName()) || annotationName.equals(Property.class.getName());
Annotation newNode;
if (isPropertyAnnotation) {
newNode = new PropertyAnnotation().setAnnotationMirror(node.attribute);
if (!args.isEmpty()) {
for (String attr : ElementUtil.parsePropertyAttribute(node.attribute)) {
((PropertyAnnotation) newNode).addAttribute(attr);
}
}
} else if (args.isEmpty()) {
newNode = new MarkerAnnotation().setAnnotationMirror(node.attribute);
} else if (args.size() == 1) {
JCTree.JCAssign assign = (JCTree.JCAssign) args.get(0);
newNode = new SingleMemberAnnotation().setValue((Expression) convert(assign.rhs));
} else {
NormalAnnotation normalAnn = new NormalAnnotation();
for (JCTree.JCExpression obj : node.getArguments()) {
JCTree.JCAssign assign = (JCTree.JCAssign) obj;
Symbol sym = ((JCTree.JCIdent) assign.lhs).sym;
MemberValuePair memberPair = new MemberValuePair().setName(convertSimpleName(sym, sym.asType(), getPosition(assign.lhs))).setValue((Expression) convert(assign.rhs));
normalAnn.addValue(memberPair);
}
newNode = normalAnn;
}
return newNode.setAnnotationMirror(node.attribute).setTypeName((Name) convert(node.getAnnotationType()));
}
Aggregations