/** * Finds the method declaration within the given type, for the given invocation. */ public static MethodSymbol findMethodDeclarationInType(Types types, TypeSymbol typeSymbol, JCMethodInvocation invocation) { String meth = invocation.meth.toString(); String methName = meth.substring(meth.lastIndexOf('.') + 1); return findMethodDeclarationInType(types, typeSymbol, methName, (MethodType) invocation.meth.type); }
@Override protected Choice<Unifier> defaultAction(Tree target, Unifier unifier) { JCExpression expr = (JCExpression) target; Type targetType = expr.type; if (targetType == null) { return Choice.none(); } @Nullable TypeWithExpression boundType = unifier.getBinding(key()); if (boundType == null) { unifier.putBinding( key(), expr.accept(QUALIFIED_FROM_PACKAGE, null) ? TypeWithExpression.create( targetType) /* use the ImportPolicy to refer to this type */ : TypeWithExpression.create(targetType, expr)); return Choice.of(unifier); } else if (unifier.types().isSameType(targetType, boundType.type())) { return Choice.of(unifier); } return Choice.none(); } }
.replace( ((JCTree) tree).getStartPosition(), arg.getStartPosition(), maybeCast(state, type, argType)) .replace(state.getEndPosition(arg), state.getEndPosition(tree), "") .replace(parent.getStartPosition(), arg.getStartPosition(), "String.valueOf(") .replace(state.getEndPosition(arg), state.getEndPosition(parent), ")") .build(); parent.getStartPosition(), arg.getStartPosition(), replacement + optionalCast) .replace(state.getEndPosition(arg), state.getEndPosition(parent), optionalSuffix + ")") .build(); .replace( compareTo.getStartPosition(), arg.getStartPosition(), String.format("%s.compare(%s", typeName, optionalCast)) .replace( /* endPos= */ rhs.getStartPosition(), String.format("%s, ", optionalSuffix)) .replace(state.getEndPosition(rhs), state.getEndPosition(compareTo), ")") .replace(((JCTree) tree).getStartPosition(), arg.getStartPosition(), prefixToArg) .postfixWith(arg, suffix) .build();
int endPosType = baseType.getEndPosition(endPosTable); if (endPosType != -1 && startPosFirst != -1 && endPosType > startPosFirst) { baseType = ((JCArrayTypeTree) baseType).elemtype;
int endPosType = baseType.getEndPosition(endPosTable); if (endPosType != -1 && startPosFirst != -1 && endPosType > startPosFirst) { baseType = ((JCArrayTypeTree) baseType).elemtype;
int endPosType = baseType.getEndPosition(endPosTable); if (endPosType != -1 && startPosFirst != -1 && endPosType > startPosFirst) { baseType = ((JCArrayTypeTree) baseType).elemtype;
if (!arguments.isEmpty()) { JCExpression argument = Iterables.getOnlyElement(arguments); checkState(argument.getKind().equals(ASSIGNMENT)); JCAssign assignment = (JCAssign) argument; checkState(getSymbol(assignment.getVariable()).getSimpleName().contentEquals("type"));
String name = identifier.toString(); int start = identifier.getStartPosition(); int end = identifier.getEndPosition(endPosTable); Range nameRange = Range.create(src, start, end);
if ((tree.mods.flags & VARARGS) != 0) { if (Kind.ARRAY_TYPE == tree.vartype.getKind()) { printExpr(((JCArrayTypeTree) tree.vartype).elemtype); } else {
if (target.getKind() == Kind.CONDITIONAL_EXPRESSION) { JCConditional cond = (JCConditional) target; Type trueTy = cond.truepart.type;
startPos = packageTree != null ? packageTree.getEndPosition(endPositions) + 2 // +2 for semicolon and newline : 0; endPos = startPos;
JCExpression curr = tree; while (true) { if (curr.hasTag(JCTree.Tag.PLUS)) { JCBinary op = (JCBinary)curr; needsFolding |= foldIfNeeded(op.rhs, litBuf, opStack, false); JCExpression res = ops.head; for (JCExpression op : ops.tail) { res = F.at(op.getStartPosition()).Binary(optag(TokenKind.PLUS), res, op); storeEnd(res, getEndPos(op));
protected int diffApply(JCMethodInvocation oldT, JCMethodInvocation newT, int[] bounds) { int localPointer = bounds[0]; int[] methBounds = getBounds(oldT.meth); if (Kind.MEMBER_SELECT == oldT.meth.getKind() && oldT.meth.getKind() == newT.meth.getKind()) { localPointer = diffSelect((JCFieldAccess) oldT.meth, (JCFieldAccess) newT.meth, methBounds, oldT.typeargs, newT.typeargs); } else if (oldT.typeargs.isEmpty() && newT.typeargs.isEmpty()) {
JCExpression memberReferenceSuffix(int pos1, JCExpression t) { checkMethodReferences(); mode = EXPR; List<JCExpression> typeArgs = null; if (token.kind == LT) { typeArgs = typeArguments(false); } Name refName; ReferenceMode refMode; if (token.kind == NEW) { refMode = ReferenceMode.NEW; refName = names.init; nextToken(); } else { refMode = ReferenceMode.INVOKE; refName = ident(); } return toP(F.at(t.getStartPosition()).Reference(refMode, refName, t, typeArgs)); }
public static JCTree.JCExpression parseString(String guardedByString, Context context) { JavacParser parser = ParserFactory.instance(context) .newParser( guardedByString, /* keepDocComments= */ false, /* keepEndPos= */ true, /* keepLineMap= */ false); JCTree.JCExpression exp; try { exp = parser.parseExpression(); } catch (Throwable e) { throw new IllegalGuardedBy(e.getMessage()); } int len = (parser.getEndPos(exp) - exp.getStartPosition()); if (len != guardedByString.length()) { throw new IllegalGuardedBy("Didn't parse entire string."); } return exp; }
JCExpression memberReferenceSuffix(int pos1, JCExpression t) { checkMethodReferences(); mode = EXPR; List<JCExpression> typeArgs = null; if (token.kind == LT) { typeArgs = typeArguments(false); } Name refName; ReferenceMode refMode; if (token.kind == NEW) { refMode = ReferenceMode.NEW; refName = names.init; nextToken(); } else { refMode = ReferenceMode.INVOKE; refName = ident(); } return toP(F.at(t.getStartPosition()).Reference(refMode, refName, t, typeArgs)); }
private boolean isSynthetic(JCTree tree) { if (tree.getKind() == Kind.METHOD) { //filter synthetic constructors return (((JCMethodDecl)tree).mods.flags & Flags.GENERATEDCONSTR) != 0L; } //filter synthetic superconstructor calls if (tree.getKind() == Kind.EXPRESSION_STATEMENT && diffContext.origUnit != null) { JCExpressionStatement est = (JCExpressionStatement) tree; if (est.expr.getKind() == Kind.METHOD_INVOCATION) { JCMethodInvocation mit = (JCMethodInvocation) est.getExpression(); if (mit.meth.getKind() == Kind.IDENTIFIER) { JCIdent it = (JCIdent) mit.getMethodSelect(); return it.name == names._super && diffContext.syntheticTrees.contains(tree); } } } return false; }
/** CatchClause = CATCH "(" FormalParameter ")" Block * TODO: the "FormalParameter" is not correct, it uses the special "catchTypes" rule below. */ protected JCCatch catchClause() { int pos = token.pos; accept(CATCH); accept(LPAREN); JCModifiers mods = optFinal(Flags.PARAMETER); List<JCExpression> catchTypes = catchTypes(); JCExpression paramType = catchTypes.size() > 1 ? toP(F.at(catchTypes.head.getStartPosition()).TypeUnion(catchTypes)) : catchTypes.head; JCVariableDecl formal = variableDeclaratorId(mods, paramType); accept(RPAREN); JCBlock body = block(); return F.at(pos).Catch(formal, body); }
/** CatchClause = CATCH "(" FormalParameter ")" Block * TODO: the "FormalParameter" is not correct, it uses the special "catchTypes" rule below. */ protected JCCatch catchClause() { int pos = token.pos; accept(CATCH); accept(LPAREN); JCModifiers mods = optFinal(Flags.PARAMETER); List<JCExpression> catchTypes = catchTypes(); JCExpression paramType = catchTypes.size() > 1 ? toP(F.at(catchTypes.head.getStartPosition()).TypeUnion(catchTypes)) : catchTypes.head; JCVariableDecl formal = variableDeclaratorId(mods, paramType); accept(RPAREN); JCBlock body = block(); return F.at(pos).Catch(formal, body); }