Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added java token position tests from J_APPLY to J_ASSIGN #1962

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -0,0 +1,6 @@
>class Apply {
> public static void main(String[] args) {
> System.out.println("Test");
$ | J_APPLY 8
> }
>}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
>class Apply {
> public static void main(String[] args) {
> new String("test").length();
$ | J_APPLY 7
> }
>}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
>import java.io.File;
>
>class Apply {
> public static void main(String[] args) {
> File file = new File("test");
> file.getName().length();
$ | J_APPLY 8
$ | J_APPLY 7
> }
>}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
>class Apply {
> public static void main(String[] args) {
> int[] data = new int[]{1,2,3,4};
$ | J_ARRAY_INIT_BEGIN 1
$ | J_ARRAY_INIT_END 1
> }
>}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
>@SuppressWarnings({"Test1", "Test2"})
$ | J_ARRAY_INIT_BEGIN 1
$ | J_ARRAY_INIT_END 1
>class Apply {
> public static void main(String[] args) {
> }
>}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
>class Apply {
> public static void main(String[] args) {
> assert true;
$ | J_ASSERT 6
> }
>}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
>class Apply {
> public static void main(String[] args) {
> assert args.length == 0;
$ | J_ASSERT 6
> }
>}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
>class Apply {
> public static void main(String[] args) {
> int i = 1;
$ | J_ASSIGN 3
> }
>}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
>class Apply {
> public static void main(String[] args) {
> int i = 1;
> i = 2;
$ | J_ASSIGN 3
> }
>}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
>class Apply {
> public static void main(String[] args) {
> int i = 1;
> i = (int) Math.random();
$ | J_ASSIGN 3
> }
>}
Loading