if (annotationQualifiedName.contentEquals(PROVIDES_CLASS_NAME) || annotationQualifiedName.contentEquals(PRODUCES_CLASS_NAME)) { List<JCExpression> arguments = annotation.getArguments(); if (!arguments.isEmpty()) { JCExpression argument = Iterables.getOnlyElement(arguments);
@Override public void visitAnnotation(JCAnnotation anno) { if (anno.getArguments().isEmpty()) { try { print("@"); printExpr(anno.annotationType); } catch (IOException e) { throw new UncheckedIOException(e); } } else { super.visitAnnotation(anno); } } }.printStat(variableDecl);
@Override public void visitAnnotation(JCAnnotation anno) { if (anno.getArguments().isEmpty()) { try { print("@"); printExpr(anno.annotationType); } catch (IOException e) { // the supertype swallows exceptions too throw new RuntimeException(e); } } else { super.visitAnnotation(anno); } }
Source src = context.source; JCTree.JCAnnotation anno = (JCTree.JCAnnotation) tree; List<JCTree.JCExpression> arguments = anno.getArguments(); Range range = Range.create(src, startPos + 1, endPos); Type type = anno.type; src.annotationMap.put(range.begin.line, annotation); analyzeSimpleExpressions(context, anno.getArguments()); JCTree annotationType = anno.getAnnotationType(); analyzeParsedTree(context, annotationType);
if (annotationQualifiedName.contentEquals(PROVIDES_CLASS_NAME) || annotationQualifiedName.contentEquals(PRODUCES_CLASS_NAME)) { List<JCExpression> arguments = annotation.getArguments(); if (!arguments.isEmpty()) { JCExpression argument = Iterables.getOnlyElement(arguments);
com.sun.tools.javac.util.List<JCTree.JCExpression> args = anno.getArguments(); if( args.isEmpty() )
/** * Searches the annotation list for {@code @Test(expected=...)}. If found, deletes the exception * attribute from the annotation, and returns its value. */ private static JCExpression deleteExpectedException( SuggestedFix.Builder fix, List<JCAnnotation> annotations, VisitorState state) { Type testAnnotation = state.getTypeFromString(JUnitMatchers.JUNIT4_TEST_ANNOTATION); for (JCAnnotation annotationTree : annotations) { if (!ASTHelpers.isSameType(testAnnotation, annotationTree.type, state)) { continue; } com.sun.tools.javac.util.List<JCExpression> arguments = annotationTree.getArguments(); for (JCExpression arg : arguments) { if (!arg.hasTag(Tag.ASSIGN)) { continue; } JCAssign assign = (JCAssign) arg; if (assign.lhs.hasTag(Tag.IDENT) && ((JCIdent) assign.lhs).getName().contentEquals("expected")) { if (arguments.size() == 1) { fix.replace(annotationTree, "@Test"); } else { removeFromList(fix, state, arguments, assign); } return assign.rhs; } } } return null; }
private static String parseModifiers( SourceContext context, @Nullable JCTree.JCModifiers modifiers) throws IOException { if (nonNull(modifiers)) { List<JCTree.JCAnnotation> annotations = modifiers.getAnnotations(); if (nonNull(annotations) && annotations.size() > 0) { for (JCTree.JCAnnotation anno : annotations) { JCTree annotationType = anno.getAnnotationType(); if (nonNull(annotationType)) { analyzeParsedTree(context, annotationType); } List<JCTree.JCExpression> arguments = anno.getArguments(); if (nonNull(arguments)) { for (JCTree.JCExpression jcExpression : arguments) { analyzeParsedTree(context, jcExpression); } } } String mod = modifiers.toString(); int lastIndexOf = mod.lastIndexOf('\n'); return mod.substring(lastIndexOf + 1); } return modifiers.toString(); } return ""; }
@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 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 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 void visitAnnotation(JCAnnotation anno) { if (anno.getArguments().isEmpty()) { try { print("@"); printExpr(anno.annotationType); } catch (IOException e) { // the supertype swallows exceptions too throw new RuntimeException(e); } } else { super.visitAnnotation(anno); } }
/** * Prints an annotation tree. */ @Override public void visitAnnotation(JCAnnotation annotation) { if (!context.hasAnnotationType(annotation.type.tsym, JSweetConfig.ANNOTATION_DECORATOR)) { return; } print("@").print(annotation.getAnnotationType()); if (annotation.getArguments() != null && !annotation.getArguments().isEmpty()) { print("("); isAnnotationScope = true; print(" { "); for (JCExpression e : annotation.getArguments()) { print(e); print(", "); } removeLastChars(2); print(" } "); isAnnotationScope = false; print(")"); } else if (getParentOfParent() instanceof JCClassDecl) { print("()"); } println().printIndent(); }
/** * Searches the annotation list for {@code @Test(expected=...)}. If found, deletes the exception * attribute from the annotation, and returns its value. */ private static JCExpression deleteExpectedException( SuggestedFix.Builder fix, List<JCAnnotation> annotations, VisitorState state) { Type testAnnotation = state.getTypeFromString(JUnitMatchers.JUNIT4_TEST_ANNOTATION); for (JCAnnotation annotationTree : annotations) { if (!ASTHelpers.isSameType(testAnnotation, annotationTree.type, state)) { continue; } com.sun.tools.javac.util.List<JCExpression> arguments = annotationTree.getArguments(); for (JCExpression arg : arguments) { if (!arg.hasTag(Tag.ASSIGN)) { continue; } JCAssign assign = (JCAssign) arg; if (assign.lhs.hasTag(Tag.IDENT) && ((JCIdent) assign.lhs).getName().contentEquals("expected")) { if (arguments.size() == 1) { fix.replace(annotationTree, "@Test"); } else { removeFromList(fix, state, arguments, assign); } return assign.rhs; } } } return null; }