Tabnine Logo
JCTree.getStartPosition
Code IndexAdd Tabnine to your IDE (free)

How to use
getStartPosition
method
in
com.sun.tools.javac.tree.JCTree

Best Java code snippets using com.sun.tools.javac.tree.JCTree.getStartPosition (Showing top 20 results out of 315)

origin: google/error-prone

 /**
  * Returns a start position of given {@code tree}.
  *
  * <p>The only purpose of this method is to avoid doing a hacky casting to {@link JCTree}.
  */
 private static int getStartPosition(Tree tree) {
  return ((JCTree) tree).getStartPosition();
 }
}
origin: google/error-prone

@Override
public int getStartPosition() {
 return position.getStartPosition() + startPositionAdjustment;
}
origin: google/error-prone

 @Override
 public Description report(
   Set<MethodTree> affectedTrees, SuggestedFix fix, VisitorState state, BugChecker checker) {
  return affectedTrees.stream()
    .min(Comparator.comparingInt(t -> ((JCTree) t).getStartPosition()))
    .map(t -> checker.describeMatch(t.getModifiers(), fix))
    .orElse(NO_MATCH);
 }
},
origin: google/error-prone

private void removeLeftOperand(BinaryTree superBinary) {
 fix.replace(
   ((JCTree) superBinary.getLeftOperand()).getStartPosition(),
   ((JCTree) superBinary.getRightOperand()).getStartPosition(),
   "");
}
origin: google/error-prone

 public String getRange(JCCompilationUnit unit) {
  try {
   CharSequence sequence = unit.getSourceFile().getCharContent(true);
   return sequence
     .subSequence(location.getStartPosition(), location.getEndPosition(unit.endPositions))
     .toString();
  } catch (IOException e) {
   throw new RuntimeException(e);
  }
 }
}
origin: google/error-prone

 @Override
 public String getRange(JCCompilationUnit unit) {
  try {
   CharSequence sequence = unit.getSourceFile().getCharContent(true);
   JCTree firstStatement = statements.get(0);
   JCTree lastStatement = Iterables.getLast(statements);
   return sequence
     .subSequence(
       firstStatement.getStartPosition(), lastStatement.getEndPosition(unit.endPositions))
     .toString();
  } catch (IOException e) {
   throw new RuntimeException(e);
  }
 }
}
origin: google/error-prone

private static int getThrowsPosition(MethodTree tree, VisitorState state) {
 for (ErrorProneToken token : state.getTokensForNode(tree)) {
  if (token.kind() == Tokens.TokenKind.THROWS) {
   return ((JCTree) tree).getStartPosition() + token.pos();
  }
 }
 throw new AssertionError();
}
origin: google/error-prone

void advance() {
 ExpressionTree nextArgument = argumentsIterator.next();
 currentArgumentEndPosition = state.getEndPosition(nextArgument) - offset;
 previousArgumentEndPosition = currentArgumentStartPosition;
 currentArgumentStartPosition = ((JCTree) nextArgument).getStartPosition() - offset;
 if (previousCommentedResultBuilder != null) {
  resultBuilder.add(previousCommentedResultBuilder.build());
 }
 previousCommentedResultBuilder = currentCommentedResultBuilder;
 currentCommentedResultBuilder = Commented.<ExpressionTree>builder().setTree(nextArgument);
}
origin: google/error-prone

 @Override
 public Description matchNewClass(NewClassTree tree, VisitorState state) {
  if (!MATCHER.matches(tree, state)) {
   return Description.NO_MATCH;
  }

  ExpressionTree millisArg = Iterables.getOnlyElement(tree.getArguments());
  SuggestedFix fix =
    SuggestedFix.replace(
      ((JCTree) tree).getStartPosition(),
      ((JCTree) millisArg).getStartPosition(),
      state.getSourceForNode(tree.getIdentifier()) + ".millis(");
  return describeMatch(tree, fix);
 }
}
origin: google/error-prone

private static String getMessageOrFormat(MethodInvocationTree tree, VisitorState state) {
 if (tree.getArguments().size() > 1) {
  return "String.format("
    + state
      .getSourceCode()
      .subSequence(
        ((JCTree) tree.getArguments().get(0)).getStartPosition(),
        state.getEndPosition(Iterables.getLast(tree.getArguments())))
    + ")";
 }
 return state.getSourceForNode(getOnlyElement(tree.getArguments()));
}
origin: google/error-prone

private static SuggestedFix appendArgument(
  NewClassTree constructor, String exception, VisitorState state, List<Type> types) {
 if (types.isEmpty()) {
  // Skip past the opening '(' of the constructor.
  String source = state.getSourceForNode(constructor);
  int startPosition = ((JCTree) constructor).getStartPosition();
  int pos =
    source.indexOf('(', state.getEndPosition(constructor.getIdentifier()) - startPosition)
      + startPosition
      + 1;
  return SuggestedFix.replace(pos, pos, exception);
 }
 return SuggestedFix.postfixWith(
   getLast(constructor.getArguments()), String.format(", %s", exception));
}
origin: google/error-prone

 private static int caseEndPosition(VisitorState state, JCTree.JCCase caseTree) {
  // if the statement group is a single block statement, handle fall through comments at the
  // end of the block
  if (caseTree.stats.size() == 1) {
   JCTree.JCStatement only = getOnlyElement(caseTree.stats);
   if (only.hasTag(JCTree.Tag.BLOCK)) {
    BlockTree blockTree = (BlockTree) only;
    return blockTree.getStatements().isEmpty()
      ? ((JCTree) blockTree).getStartPosition()
      : state.getEndPosition(getLast(blockTree.getStatements()));
   }
  }
  return state.getEndPosition(caseTree);
 }
}
origin: google/error-prone

 @Override
 public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
  if (!MATCHER.matches(tree, state)) {
   return Description.NO_MATCH;
  }

  SuggestedFix.Builder builder = SuggestedFix.builder();
  String replacement =
    SuggestedFixes.qualifyType(state, builder, "org.joda.time.Duration") + ".millis(";
  ExpressionTree millisArg = Iterables.getOnlyElement(tree.getArguments());

  builder.replace(
    ((JCTree) tree).getStartPosition(),
    ((JCTree) millisArg).getStartPosition(),
    replacement);
  return describeMatch(tree, builder.build());
 }
}
origin: google/error-prone

 @Override
 public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
  if (!MATCHER.matches(tree, state)) {
   return Description.NO_MATCH;
  }

  SuggestedFix.Builder builder = SuggestedFix.builder();
  String replacement =
    "new " + SuggestedFixes.qualifyType(state, builder, "org.joda.time.Instant") + "(";
  ExpressionTree millisArg = Iterables.getOnlyElement(tree.getArguments());

  builder.replace(
    ((JCTree) tree).getStartPosition(),
    ((JCTree) millisArg).getStartPosition(),
    replacement);
  return describeMatch(tree, builder.build());
 }
}
origin: google/error-prone

 @Override
 SuggestedFix fix(Fixer fixer, ExpressionTree tree, VisitorState state) {
  MethodInvocationTree methodInvocationTree = (MethodInvocationTree) tree;
  return fixer
    .getHazzer(/* negated= */ false, state)
    .map(
      r -> {
       int startPos = ((JCTree) methodInvocationTree).getStartPosition();
       return SuggestedFix.builder()
         .replace(getLast(methodInvocationTree.getArguments()), r)
         .replace(startPos, startPos + "assertNotNull".length(), "assertTrue")
         .build();
      })
    .orElse(SuggestedFix.builder().build());
 }
},
origin: google/error-prone

 private static SuggestedFix fixClass(ClassTree classTree, VisitorState state) {
  int startPos = ((JCTree) classTree).getStartPosition();
  int endPos = ((JCTree) classTree.getMembers().get(0)).getStartPosition();
  ImmutableList<ErrorProneToken> tokens =
    ErrorProneTokens.getTokens(
      state.getSourceCode().subSequence(startPos, endPos).toString(), state.context);
  String modifiers =
    getSymbol(classTree).owner.enclClass() == null ? "final class" : "static final class";
  SuggestedFix.Builder fix = SuggestedFix.builder();
  for (ErrorProneToken token : tokens) {
   if (token.kind() == TokenKind.INTERFACE) {
    fix.replace(startPos + token.pos(), startPos + token.endPos(), modifiers);
   }
  }
  return fix.build();
 }
}
origin: google/error-prone

SuggestedFix buildCommentArgumentsFix(InvocationInfo info) {
 SuggestedFix.Builder commentArgumentsFixBuilder = SuggestedFix.builder();
 for (ParameterPair change : changedPairs()) {
  int index = change.formal().index();
  ExpressionTree actual = info.actualParameters().get(index);
  int startPosition = ((JCTree) actual).getStartPosition();
  String formal = info.formalParameters().get(index).getSimpleName().toString();
  commentArgumentsFixBuilder.replace(
    startPosition, startPosition, NamedParameterComment.toCommentText(formal));
 }
 return commentArgumentsFixBuilder.build();
}
origin: google/error-prone

 @Override
 public Description matchParenthesized(ParenthesizedTree tree, VisitorState state) {
  ExpressionTree expression = tree.getExpression();
  if (state.getPath().getParentPath().getLeaf() instanceof StatementTree) {
   return NO_MATCH;
  }
  if (ASTHelpers.requiresParentheses(expression, state)) {
   return NO_MATCH;
  }
  return describeMatch(
    tree,
    SuggestedFix.builder()
      .replace(
        ((JCTree) tree).getStartPosition(), ((JCTree) expression).getStartPosition(), "")
      .replace(state.getEndPosition(expression), state.getEndPosition(tree), "")
      .build());
 }
}
origin: google/error-prone

 @Override
 public Void visitBinary(BinaryTree tree, SuggestedFix.Builder p) {
  if (tree.getKind() == Kind.AND || tree.getKind() == Kind.OR) {
   p.replace(
     /* startPos= */ state.getEndPosition(tree.getLeftOperand()),
     /* endPos= */ ((JCTree) tree.getRightOperand()).getStartPosition(),
     tree.getKind() == Tree.Kind.AND ? " && " : " || ");
  }
  return super.visitBinary(tree, p);
 }
}
origin: google/error-prone

 private Description checkCondition(ExpressionTree condition, VisitorState state) {
  if (!(condition instanceof AssignmentTree)) {
   return NO_MATCH;
  }
  AssignmentTree assign = (AssignmentTree) condition;
  return buildDescription(condition)
    .addFix(
      SuggestedFix.builder().prefixWith(condition, "(").postfixWith(condition, ")").build())
    .addFix(
      SuggestedFix.replace(
        /*startPos=*/ state.getEndPosition(assign.getVariable()),
        /*endPos=*/ ((JCTree) assign.getExpression()).getStartPosition(),
        " == "))
    .build();
 }
}
com.sun.tools.javac.treeJCTreegetStartPosition

Popular methods of JCTree

  • accept
    Visit this tree with a given visitor.
  • toString
    Convert a tree to a pretty-printed string.
  • getKind
  • getTag
  • pos
    Get a default position for this tree node.
  • getEndPosition
  • hasTag
  • setPos
    Set position field and return this tree.
  • setType
    Set type field and return this tree.
  • getPreferredPosition

Popular in Java

  • Creating JSON documents from java classes using gson
  • scheduleAtFixedRate (Timer)
  • requestLocationUpdates (LocationManager)
  • setRequestProperty (URLConnection)
  • BufferedInputStream (java.io)
    A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the i
  • URL (java.net)
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • ResourceBundle (java.util)
    ResourceBundle is an abstract class which is the superclass of classes which provide Locale-specifi
  • Timer (java.util)
    Timers schedule one-shot or recurring TimerTask for execution. Prefer java.util.concurrent.Scheduled
  • Options (org.apache.commons.cli)
    Main entry-point into the library. Options represents a collection of Option objects, which describ
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now