protected final void printCastMethodInvocation(InvocationElement invocation) { boolean needsParens = getPrinter().getParent() instanceof JCMethodInvocation; if (needsParens) { // async needs no parens to work JCMethodInvocation parentInvocation = (JCMethodInvocation) getPrinter().getParent(); if (parentInvocation.meth instanceof JCIdent) { needsParens = !((JCIdent) parentInvocation.meth).getName().toString().equals("async"); } } if (needsParens) { print("("); } print(invocation.getArgument(0)); if (needsParens) { print(")"); } }
String nm = ident.getName().toString(); String identClazz = src.getImportedClassFQCN(nm, null);
Symbol owner = sym.owner; Type type = sym.asType(); String name = ident.getName().toString();
String s = ident.getName().toString(); Symbol sym = ident.sym; if (nonNull(sym)) { String nm = ident.getName().toString(); String clazz = src.getImportedClassFQCN(nm, null); if (nonNull(clazz)) { if (expression instanceof JCTree.JCIdent) { JCTree.JCIdent ident = (JCTree.JCIdent) expression; String nm = ident.getName().toString(); String clazz = src.getImportedClassFQCN(nm, null); if (nonNull(clazz)) {
Identifier id = new Identifier(); if (sel instanceof JCIdent) { String name = ((JCIdent) sel).getName().toString(); if ("this".equals(name)) { AlternateConstructorInvocation aci = new AlternateConstructorInvocation();
Identifier id = new Identifier(); if (sel instanceof JCIdent) { String name = ((JCIdent) sel).getName().toString(); if ("this".equals(name)) { AlternateConstructorInvocation aci = new AlternateConstructorInvocation();
Identifier id = new Identifier(); if (sel instanceof JCIdent) { String name = ((JCIdent) sel).getName().toString(); if ("this".equals(name)) { AlternateConstructorInvocation aci = new AlternateConstructorInvocation();
/** * 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; }
@Override public void visitIdent(JCIdent node) { String name = node.getName().toString(); if ("this".equals(name)) { This t = new This(); set(node, t); setConversionPositionInfo(t, "this", getPosition(node)); return; } if ("super".equals(name)) { Super s = new Super(); set(node, s); setConversionPositionInfo(s, "super", getPosition(node)); return; } Identifier id = setPos(node, new Identifier().astValue(name)); if (hasFlag(FlagKey.TYPE_REFERENCE)) { TypeReferencePart part = setPos(node, new TypeReferencePart().astIdentifier(id)); set(node, new TypeReference().astParts().addToEnd(part)); return; } set(node, new VariableReference().astIdentifier(id)); }
@Override public void visitIdent(JCIdent node) { String name = node.getName().toString(); if ("this".equals(name)) { This t = new This(); set(node, t); setConversionPositionInfo(t, "this", getPosition(node)); return; } if ("super".equals(name)) { Super s = new Super(); set(node, s); setConversionPositionInfo(s, "super", getPosition(node)); return; } Identifier id = setPos(node, new Identifier().astValue(name)); if (hasFlag(FlagKey.TYPE_REFERENCE)) { TypeReferencePart part = setPos(node, new TypeReferencePart().astIdentifier(id)); set(node, new TypeReference().astParts().addToEnd(part)); return; } set(node, new VariableReference().astIdentifier(id)); }
@Override public void visitIdent(JCIdent node) { String name = node.getName().toString(); if ("this".equals(name)) { This t = new This(); set(node, t); setConversionPositionInfo(t, "this", getPosition(node)); return; } if ("super".equals(name)) { Super s = new Super(); set(node, s); setConversionPositionInfo(s, "super", getPosition(node)); return; } Identifier id = setPos(node, new Identifier().astValue(name)); if (hasFlag(FlagKey.TYPE_REFERENCE)) { TypeReferencePart part = setPos(node, new TypeReferencePart().astIdentifier(id)); set(node, new TypeReference().astParts().addToEnd(part)); return; } set(node, new VariableReference().astIdentifier(id)); }
@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); } }
/** * 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; }