public void visitAssign(JCAssign tree) { tree.lhs = translate(tree.lhs, tree); tree.rhs = translate(tree.rhs, tree.lhs.type); // If translated left hand side is an Apply, we are // seeing an access method invocation. In this case, append // right hand side as last argument of the access method. if (tree.lhs.hasTag(APPLY)) { JCMethodInvocation app = (JCMethodInvocation)tree.lhs; app.args = List.of(tree.rhs).prependList(app.args); result = app; } else { result = tree; } }
public void visitAssign(JCAssign tree) { tree.lhs = translate(tree.lhs, tree); tree.rhs = translate(tree.rhs, tree.lhs.type); // If translated left hand side is an Apply, we are // seeing an access method invocation. In this case, append // right hand side as last argument of the access method. if (tree.lhs.hasTag(APPLY)) { JCMethodInvocation app = (JCMethodInvocation)tree.lhs; app.args = List.of(tree.rhs).prependList(app.args); result = app; } else { result = tree; } }
public static boolean isMultiCatch(JCCatch catchClause) { return catchClause.param.vartype.hasTag(TYPEUNION); }
public void visitNewClass(JCNewClass tree) { if (tree.clazz.hasTag(ANNOTATED_TYPE)) { checkForDeclarationAnnotations(((JCAnnotatedType) tree.clazz).annotations, tree.clazz.type.tsym); } if (tree.def != null) { checkForDeclarationAnnotations(tree.def.mods.annotations, tree.clazz.type.tsym); } if (tree.clazz.type != null) { validateAnnotatedType(tree.clazz, tree.clazz.type); } super.visitNewClass(tree); } public void visitNewArray(JCNewArray tree) {
/** If tree refers to a superclass constructor call, * add all free variables of the superclass. */ public void visitApply(JCMethodInvocation tree) { if (TreeInfo.name(tree.meth) == names._super) { Symbol constructor = TreeInfo.symbol(tree.meth); ClassSymbol c = (ClassSymbol)constructor.owner; if (c.hasOuterInstance() && !tree.meth.hasTag(SELECT) && outerThisStack.head != null) visitSymbol(outerThisStack.head); } super.visitApply(tree); } }
public void visitNewClass(JCNewClass tree) { if (tree.clazz != null && tree.clazz.type != null) { if (tree.clazz.hasTag(ANNOTATED_TYPE)) { checkForDeclarationAnnotations(((JCAnnotatedType) tree.clazz).annotations, tree.clazz.type.tsym); } if (tree.def != null) { checkForDeclarationAnnotations(tree.def.mods.annotations, tree.clazz.type.tsym); } validateAnnotatedType(tree.clazz, tree.clazz.type); } super.visitNewClass(tree); } public void visitNewArray(JCNewArray tree) {
protected JCVariableDecl(JCModifiers mods, JCExpression nameexpr, JCExpression vartype) { this(mods, null, vartype, null, null); this.nameexpr = nameexpr; if (nameexpr.hasTag(Tag.IDENT)) { this.name = ((JCIdent)nameexpr).name; } else { // Only other option is qualified name x.y.this; this.name = ((JCFieldAccess)nameexpr).name; } }
public void visitNewArray(JCNewArray tree) { if (tree.elemtype != null && tree.elemtype.type != null) { if (tree.elemtype.hasTag(ANNOTATED_TYPE)) { checkForDeclarationAnnotations(((JCAnnotatedType) tree.elemtype).annotations, tree.elemtype.type.tsym); } validateAnnotatedType(tree.elemtype, tree.elemtype.type); } super.visitNewArray(tree); } public void visitClassDef(JCClassDecl tree) {
/** Skip parens and return the enclosed expression */ public static JCExpression skipParens(JCExpression tree) { while (tree.hasTag(PARENS)) { tree = ((JCParens) tree).expr; } return tree; }
private Type dummyMethodType(JCMethodDecl md) { Type restype = syms.unknownType; if (md != null && md.restype.hasTag(TYPEIDENT)) { JCPrimitiveTypeTree prim = (JCPrimitiveTypeTree)md.restype; if (prim.typetag == VOID) restype = syms.voidType; } return new MethodType(List.<Type>nil(), restype, List.<Type>nil(), syms.methodClass); } private Type dummyMethodType() {
/** If the expression is a method call, return the method name, null * otherwise. */ public static Name calledMethodName(JCTree tree) { if (tree.hasTag(EXEC)) { JCExpressionStatement exec = (JCExpressionStatement)tree; if (exec.expr.hasTag(APPLY)) { Name mname = TreeInfo.name(((JCMethodInvocation) exec.expr).meth); return mname; } } return null; }
private boolean isIdentOrThisDotIdent(JCTree lhs) { if (lhs.hasTag(IDENT)) return true; if (!lhs.hasTag(SELECT)) return false; JCFieldAccess fa = (JCFieldAccess)lhs; return fa.selected.hasTag(IDENT) && ((JCIdent)fa.selected).name == names._this; }
private boolean is292targetTypeCast(JCTypeCast tree) { boolean is292targetTypeCast = false; JCExpression expr = TreeInfo.skipParens(tree.expr); if (expr.hasTag(APPLY)) { JCMethodInvocation apply = (JCMethodInvocation)expr; Symbol sym = TreeInfo.symbol(apply.meth); is292targetTypeCast = sym != null && sym.kind == MTH && (sym.flags() & HYPOTHETICAL) != 0; } return is292targetTypeCast; }
public void visitNewArray(JCNewArray tree) { if (tree.elemtype != null && tree.elemtype.type != null) { if (tree.elemtype.hasTag(ANNOTATED_TYPE)) { checkForDeclarationAnnotations(((JCAnnotatedType) tree.elemtype).annotations, tree.elemtype.type.tsym); } validateAnnotatedType(tree.elemtype, tree.elemtype.type); } super.visitNewArray(tree); } public void visitClassDef(JCClassDecl tree) {
/** Skip parens and return the enclosed expression */ public static JCExpression skipParens(JCExpression tree) { while (tree.hasTag(PARENS)) { tree = ((JCParens) tree).expr; } return tree; }
/** If the expression is a method call, return the method name, null * otherwise. */ public static Name calledMethodName(JCTree tree) { if (tree.hasTag(EXEC)) { JCExpressionStatement exec = (JCExpressionStatement)tree; if (exec.expr.hasTag(APPLY)) { Name mname = TreeInfo.name(((JCMethodInvocation) exec.expr).meth); return mname; } } return null; }
protected JCVariableDecl(JCModifiers mods, JCExpression nameexpr, JCExpression vartype) { this(mods, null, vartype, null, null); this.nameexpr = nameexpr; if (nameexpr.hasTag(Tag.IDENT)) { this.name = ((JCIdent)nameexpr).name; } else { // Only other option is qualified name x.y.this; this.name = ((JCFieldAccess)nameexpr).name; } }
public void visitSelect(JCFieldAccess tree) { super.visitSelect(tree); if (enforceThisDotInit && tree.selected.hasTag(IDENT) && ((JCIdent)tree.selected).name == names._this && tree.sym.kind == VAR) { checkInit(tree.pos(), (VarSymbol)tree.sym); } }
private boolean is292targetTypeCast(JCTypeCast tree) { boolean is292targetTypeCast = false; JCExpression expr = TreeInfo.skipParens(tree.expr); if (expr.hasTag(APPLY)) { JCMethodInvocation apply = (JCMethodInvocation)expr; Symbol sym = TreeInfo.symbol(apply.meth); is292targetTypeCast = sym != null && sym.kind == MTH && (sym.flags() & HYPOTHETICAL) != 0; } return is292targetTypeCast; }
/** * 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; }