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; }
SuggestedFix.replace( tree.getStartPosition(), ((JCAssignOp) tree).getExpression().getStartPosition(), ""); fix.merge(replacement); encounteredSideEffects = true; fix.replace( tree.getStartPosition(), ((JCAssign) tree).getExpression().getStartPosition(), ""); removeSideEffectsFix.replace(statement, ""); continue;
.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();
posHint = oldT.restype != null ? oldT.restype.getStartPosition() : oldT.getStartPosition(); } else { posHint = oldT.typarams.iterator().next().getStartPosition(); posHint = oldT.thrown.iterator().next().getStartPosition();
insertHint = oldT.implementing.iterator().next().getStartPosition();
.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();
SuggestedFix.replace( tree.getStartPosition(), ((JCAssignOp) tree).getExpression().getStartPosition(), ""); fix.merge(replacement); SuggestedFix.replace( tree.getStartPosition(), ((JCAssign) tree).getExpression().getStartPosition(), ""); fix.merge(replacement);
JCExpression newTPid = newT != null ? newT.pid : null; if (oldTPid != null) { tokenSequence.move(oldTPid.getStartPosition()); moveToSrcRelevant(tokenSequence, Direction.BACKWARD); packageKeywordStart = tokenSequence.offset();
String name = identifier.toString(); int start = identifier.getStartPosition(); int end = identifier.getEndPosition(endPosTable); Range nameRange = Range.create(src, start, end);
JCExpression res = ops.head; for (JCExpression op : ops.tail) { res = F.at(op.getStartPosition()).Binary(optag(TokenKind.PLUS), res, op); storeEnd(res, getEndPos(op));
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)); }
/** 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); }
@Override protected String formatArgument(JCDiagnostic diag, Object arg, Locale l) { String s; if (arg instanceof Formattable) { s = arg.toString(); } else if (arg instanceof JCExpression) { JCExpression tree = (JCExpression)arg; s = "@" + tree.getStartPosition(); } else if (arg instanceof BaseFileObject) { s = ((BaseFileObject) arg).getShortName(); } else { s = super.formatArgument(diag, arg, null); } return (arg instanceof JCDiagnostic) ? "(" + s + ")" : s; }
@Override protected String formatArgument(JCDiagnostic diag, Object arg, Locale l) { String s; if (arg instanceof Formattable) { s = arg.toString(); } else if (arg instanceof JCExpression) { JCExpression tree = (JCExpression)arg; s = "@" + tree.getStartPosition(); } else if (arg instanceof BaseFileObject) { s = ((BaseFileObject) arg).getShortName(); } else { s = super.formatArgument(diag, arg, null); } return (arg instanceof JCDiagnostic) ? "(" + s + ")" : s; }
private void replaceFieldSelected(JCFieldAccess fieldAccess, JCMethodInvocation newShadowOfCall, VisitorState state) { int priorStartPosition = fieldAccess.selected.getStartPosition(); int priorEndPosition = getEndPosition(state, fieldAccess.selected); fieldAccess.selected = newShadowOfCall; newShadowOfCall.pos = priorStartPosition; if (newShadowOfCall.meth instanceof JCIdent) { ((JCIdent) newShadowOfCall.meth).pos = priorStartPosition; } setEndPosition(state, newShadowOfCall, priorEndPosition); }