Skip to content

Commit

Permalink
Fixed token lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
TwoOfTwelve committed Oct 29, 2024
1 parent dfd455a commit 389cb84
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,13 @@ public Void visitNewArray(NewArrayTree node, Void unused) {
scan(node.getDimensions(), null);
boolean hasInit = node.getInitializers() != null && !node.getInitializers().isEmpty();
if (hasInit) {
start = positions.getStartPosition(ast, node.getInitializers().get(0));
start = positions.getStartPosition(ast, node.getInitializers().get(0)) - 1;
addToken(JavaTokenType.J_ARRAY_INIT_BEGIN, start, 1, new CodeSemantics());
}
scan(node.getInitializers(), null);
// super method has annotation processing but we have it disabled anyways
if (hasInit) {
end = positions.getEndPosition(ast, node.getInitializers().getLast()) - 1;
end = positions.getEndPosition(ast, node) - 1;
addToken(JavaTokenType.J_ARRAY_INIT_END, end, 1, new CodeSemantics());
}
return null;
Expand Down Expand Up @@ -490,6 +490,13 @@ public Void visitConditionalExpression(ConditionalExpressionTree node, Void unus
public Void visitMethodInvocation(MethodInvocationTree node, Void unused) {
long start = positions.getStartPosition(ast, node);
long end = positions.getEndPosition(ast, node.getMethodSelect());

String text = node.getMethodSelect().toString();
if (text.contains(".") && !text.contains("\n")) {
int offset = text.length() - text.lastIndexOf('.');
start = end - offset;
}

CodeSemantics codeSemantics = CRITICAL_METHODS.contains(node.getMethodSelect().toString()) ? CodeSemantics.createCritical()
: CodeSemantics.createControl();
addToken(JavaTokenType.J_APPLY, start, end, codeSemantics);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
>class Apply {
> public static void main(String[] args) {
> System.out.println("Test");
$ | J_APPLY 18
$ | J_APPLY 8
> }
>}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
>class Apply {
> public static void main(String[] args) {
> new String("test").length();
$ | J_APPLY 6
$ | J_APPLY 7
> }
>}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
> public static void main(String[] args) {
> File file = new File("test");
> file.getName().length();
$ | J_APPLY 12
$ | J_APPLY 6
$ | J_APPLY 8
$ | J_APPLY 7
> }
>}

0 comments on commit 389cb84

Please sign in to comment.