@Override public boolean visitAnnotation(Annotation node) { int start = node.getPosition().getStart(); int end = node.getPosition().getEnd(); // Newer javacs //int end = node.astAnnotationTypeReference().getPosition().getEnd(); // Older javacs return set(node, setPos(start, end, treeMaker.Annotation(toTree(node.astAnnotationTypeReference()), toList(JCExpression.class, node.astElements())))); }
public Node createAnnotationFromElements(Node head, List<Node> tail) { Annotation result = new Annotation(); if (head != null) result.rawElements().addToEnd(head); if (tail != null) for (Node n : tail) if (n != null) result.rawElements().addToEnd(n); return posify(result); }
public Node createAnnotation(Node type, Node annotation) { if (annotation instanceof Annotation) { return posify(((Annotation)annotation).rawAnnotationTypeReference(type)); } return posify(new Annotation().rawAnnotationTypeReference(type)); }
private lombok.ast.Annotation createAnnotation(Annotation node) { lombok.ast.Annotation annotation = new lombok.ast.Annotation(); annotation.astAnnotationTypeReference((lombok.ast.TypeReference) toTree(node.type)); return annotation; }
@Override public void visitNormalAnnotation(NormalAnnotation node) { lombok.ast.Annotation annot = createAnnotation(node); fillList(node.memberValuePairs, annot.rawElements()); annot.setPosition(toPosition(node.sourceStart, node.declarationSourceEnd)); setConversionStructInfo(annot, "isNormalAnnotation"); set(node, annot); }
@Override public boolean visitAnnotation(lombok.ast.Annotation node) { //TODO add test where the value is the result of string concatenation TypeReference type = (TypeReference) toTree(node.astAnnotationTypeReference()); boolean isEcjNormal = Position.UNPLACED == getConversionPositionInfo(node, "isNormalAnnotation"); if (node.astElements().isEmpty() && countStructure(node, "(") == 0 && !isEcjNormal) { MarkerAnnotation ann = new MarkerAnnotation(type, start(node)); ann.declarationSourceEnd = end(node); return set(node, ann); } MemberValuePair[] values = toArray(MemberValuePair.class, node.astElements()); if (values != null && (values.length == 1 && values[0].name == null)) { SingleMemberAnnotation ann = new SingleMemberAnnotation(type, start(node)); ann.declarationSourceEnd = end(node); ann.memberValue = values[0].value; return set(node, ann); } NormalAnnotation ann = new NormalAnnotation(type, start(node)); ann.declarationSourceEnd = end(node); ann.memberValuePairs = values; return set(node, ann); }
@Override public void visitAnnotation(JCAnnotation node) { Annotation a = new Annotation(); a.rawAnnotationTypeReference(toTree(node.getAnnotationType(), FlagKey.TYPE_REFERENCE)); for (JCExpression elem : node.getArguments()) { AnnotationElement e = new AnnotationElement(); if (elem instanceof JCAssign) { JCExpression rawName = ((JCAssign) elem).getVariable(); if (rawName instanceof JCIdent) e.astName(setPos(rawName, new Identifier().astValue(((JCIdent)rawName).getName().toString()))); elem = ((JCAssign) elem).getExpression(); } e.rawValue(toTree(elem)); a.astElements().addToEnd(e); } set(node, a); } }
@Override public boolean visitAnnotation(Annotation node) { String type = node.astAnnotationTypeReference().getTypeName(); if (SUPPRESS_LINT.equals(type) || FQCN_SUPPRESS_LINT.equals(type)) { Node parent = node.getParent(); if (parent instanceof Modifiers) { parent = parent.getParent(); if (parent instanceof VariableDefinition) { for (AnnotationElement element : node.astElements()) { AnnotationValue valueNode = element.astValue(); if (valueNode == null) {
@Override public void visitSingleMemberAnnotation(SingleMemberAnnotation node) { lombok.ast.Annotation annot = createAnnotation(node); lombok.ast.AnnotationElement element = new lombok.ast.AnnotationElement(); element.astValue((lombok.ast.AnnotationValue) toTree(node.memberValue)); annot.astElements().addToEnd(element); annot.setPosition(toPosition(node.sourceStart, node.declarationSourceEnd)); set(node, annot); }
@CopyMethod static List<Node> getValues(Annotation self, String key) { for (AnnotationElement elem : self.astElements()) { if (key == null && elem.astName() == null) return elem.getValues(); if (key != null && elem.astName() != null && elem.astName().astValue().equals(key)) return elem.getValues(); } return ImmutableList.of(); } }
@Override public boolean visitAnnotation(Annotation node) { formatter.buildBlock(node); formatter.append("@"); visit(node.rawAnnotationTypeReference()); visitAll(node.rawElements(), ", ", "(", ")"); formatter.closeBlock(); return true; }
@CopyMethod static String getDescription(Annotation self) { try { return self.astAnnotationTypeReference().getDescription(); } catch (NullPointerException e) { return null; } }
@Override public void visitMarkerAnnotation(MarkerAnnotation node) { lombok.ast.Annotation annot = createAnnotation(node); annot.setPosition(toPosition(node.sourceStart, node.declarationSourceEnd)); set(node, annot); }
int modStart = node.astAnnotations().first().getPosition().getStart(); int modEnd = node.astAnnotations().last().getPosition().getEnd(); setPos(modStart, modEnd, mods);
@Override public boolean visitAnnotation(lombok.ast.Annotation node) { //TODO add test where the value is the result of string concatenation TypeReference type = (TypeReference) toTree(node.astAnnotationTypeReference()); boolean isEcjNormal = Position.UNPLACED == getConversionPositionInfo(node, "isNormalAnnotation"); if (node.astElements().isEmpty() && countStructure(node, "(") == 0 && !isEcjNormal) { MarkerAnnotation ann = new MarkerAnnotation(type, start(node)); ann.declarationSourceEnd = end(node); return set(node, ann); } MemberValuePair[] values = toArray(MemberValuePair.class, node.astElements()); if (values != null && (values.length == 1 && values[0].name == null)) { SingleMemberAnnotation ann = new SingleMemberAnnotation(type, start(node)); ann.declarationSourceEnd = end(node); ann.memberValue = values[0].value; return set(node, ann); } NormalAnnotation ann = new NormalAnnotation(type, start(node)); ann.declarationSourceEnd = end(node); ann.memberValuePairs = values; return set(node, ann); }
@Override public void visitAnnotation(JCAnnotation node) { Annotation a = new Annotation(); a.rawAnnotationTypeReference(toTree(node.getAnnotationType(), FlagKey.TYPE_REFERENCE)); for (JCExpression elem : node.getArguments()) { AnnotationElement e = new AnnotationElement(); if (elem instanceof JCAssign) { JCExpression rawName = ((JCAssign) elem).getVariable(); if (rawName instanceof JCIdent) e.astName(setPos(rawName, new Identifier().astValue(((JCIdent)rawName).getName().toString()))); elem = ((JCAssign) elem).getExpression(); } e.rawValue(toTree(elem)); a.astElements().addToEnd(e); } set(node, a); } }
private lombok.ast.Annotation createAnnotation(Annotation node) { lombok.ast.Annotation annotation = new lombok.ast.Annotation(); annotation.astAnnotationTypeReference((lombok.ast.TypeReference) toTree(node.type)); return annotation; }
@Override public void visitSingleMemberAnnotation(SingleMemberAnnotation node) { lombok.ast.Annotation annot = createAnnotation(node); lombok.ast.AnnotationElement element = new lombok.ast.AnnotationElement(); element.astValue((lombok.ast.AnnotationValue) toTree(node.memberValue)); annot.astElements().addToEnd(element); annot.setPosition(toPosition(node.sourceStart, node.declarationSourceEnd)); set(node, annot); }
@CopyMethod static List<Node> getValues(Annotation self, String key) { for (AnnotationElement elem : self.astElements()) { if (key == null && elem.astName() == null) return elem.getValues(); if (key != null && elem.astName() != null && elem.astName().astValue().equals(key)) return elem.getValues(); } return ImmutableList.of(); } }
@Override public boolean visitAnnotation(Annotation node) { formatter.buildBlock(node); formatter.append("@"); visit(node.rawAnnotationTypeReference()); visitAll(node.rawElements(), ", ", "(", ")"); formatter.closeBlock(); return true; }