Skip to content

Commit 7171ef7

Browse files
committed
fix - Method parsing error
1 parent eac027f commit 7171ef7

File tree

13 files changed

+131
-139
lines changed

13 files changed

+131
-139
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ jobs:
2121
sudo /usr/bin/Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
2222
sleep 3
2323
24-
- name: Set up JDK 17
24+
- name: Set up JDK 21
2525
uses: actions/setup-java@v1
2626
with:
27-
java-version: '17'
27+
java-version: '21'
2828

2929
- name: Setup Node.js environment
3030
uses: actions/setup-node@v2
@@ -57,10 +57,10 @@ jobs:
5757
steps:
5858
- uses: actions/checkout@v2
5959

60-
- name: Set up JDK 17
60+
- name: Set up JDK 21
6161
uses: actions/setup-java@v1
6262
with:
63-
java-version: '17'
63+
java-version: '21'
6464

6565
- name: Setup Node.js environment
6666
uses: actions/setup-node@v2
@@ -93,10 +93,10 @@ jobs:
9393
steps:
9494
- uses: actions/checkout@v2
9595

96-
- name: Set up JDK 17
96+
- name: Set up JDK 21
9797
uses: actions/setup-java@v1
9898
with:
99-
java-version: '17'
99+
java-version: '21'
100100

101101
- name: Setup Node.js environment
102102
uses: actions/setup-node@v2

java-extension/com.microsoft.java.test.plugin.test/projects/coverage-test/.classpath

Lines changed: 0 additions & 57 deletions
This file was deleted.

java-extension/com.microsoft.java.test.plugin.test/projects/coverage-test/.project

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>java.test.runner</groupId>
8+
<artifactId>junit5</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<name>junit5</name>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<maven.compiler.source>21</maven.compiler.source>
16+
<maven.compiler.target>21</maven.compiler.target>
17+
</properties>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.junit.jupiter</groupId>
22+
<artifactId>junit-jupiter</artifactId>
23+
<version>5.10.3</version>
24+
<scope>test</scope>
25+
</dependency>
26+
</dependencies>
27+
28+
</project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package junit;
2+
3+
public class App {
4+
public String getGreeting() {
5+
return "Hello world.";
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package junit5;
2+
3+
import org.junit.jupiter.params.ParameterizedTest;
4+
import org.junit.jupiter.params.provider.CsvSource;
5+
6+
class TestParameterizedWithStrangeComments {
7+
//FORMER_TEST_PARAMS
8+
//@CsvSource(
9+
// {",must not be null",
10+
// "0L,size must be between 1 and 999999999"})
11+
//@ParameterizedTest
12+
13+
/**
14+
* [RequestContext.sessionId]
15+
* Tests all invalid scenarios for requestContext.logonId.
16+
*/
17+
@CsvSource(delimiter = '|', textBlock = """
18+
-1 | size must be between 1 and 999999999
19+
""")
20+
@ParameterizedTest
21+
void whenInvalidReqCtxSessionId(Long __INPUT, String __EXPECTED) throws Exception {
22+
assert(true);
23+
}
24+
}

java-extension/com.microsoft.java.test.plugin.test/src/com/microsoft/java/test/plugin/coverage/CoverageHandlerTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@
1616
import com.microsoft.java.test.plugin.coverage.model.MethodCoverage;
1717
import com.microsoft.java.test.plugin.coverage.model.SourceFileCoverage;
1818

19-
import org.eclipse.core.resources.IProject;
2019
import org.eclipse.core.runtime.NullProgressMonitor;
2120
import org.eclipse.jdt.core.IJavaProject;
22-
import org.eclipse.jdt.core.JavaCore;
2321
import org.eclipse.jdt.ls.core.internal.ProjectUtils;
24-
import org.eclipse.jdt.ls.core.internal.managers.ProjectsManager;
2522
import org.junit.Test;
2623

27-
import java.io.File;
2824
import java.util.Collections;
2925
import java.util.List;
3026

@@ -36,7 +32,7 @@ public class CoverageHandlerTest extends AbstractProjectsManagerBasedTest {
3632
public void testGetCoverageDetail() throws Exception {
3733
importProjects(Collections.singleton("coverage-test"));
3834
final IJavaProject javaProject = ProjectUtils.getJavaProject("coverage-test");
39-
final String basePath = new File("projects/coverage-test").getAbsolutePath();
35+
final String basePath = javaProject.getProject().getLocation().toFile().getAbsolutePath();
4036
final CoverageHandler coverageHandler = new CoverageHandler(javaProject, basePath);
4137
final List<SourceFileCoverage> coverageDetail = coverageHandler.getCoverageDetail(new NullProgressMonitor());
4238
for (final SourceFileCoverage fileCoverage : coverageDetail) {

java-extension/com.microsoft.java.test.plugin.test/src/com/microsoft/java/test/plugin/launchers/JUnitLaunchConfigurationDelegateTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import static org.junit.Assert.assertTrue;
1616

1717
import java.util.Arrays;
18+
import java.util.Collections;
1819
import java.util.List;
1920

2021
import org.eclipse.core.resources.IProject;
@@ -39,4 +40,13 @@ public void testWorkingDirectoryForTestNgUnmanagedFolder() throws Exception {
3940
assertEquals(0, response.getStatus());
4041
assertTrue(response.getBody().workingDirectory.endsWith("simple"));
4142
}
43+
44+
@Test
45+
public void testAstParsingWithComplexComment() throws Exception {
46+
importProjects(Collections.singleton("junit5"));
47+
List<Object> arguments = Arrays.asList("{\"projectName\":\"junit5\",\"testLevel\":6,\"testKind\":0,\"testNames\":[\"=junit5/src\\\\/test\\\\/java=/optional=/true=/=/maven.pomderived=/true=/=/test=/true=/<junit5{TestParameterizedWithStrangeComments.java[TestParameterizedWithStrangeComments~whenInvalidReqCtxSessionId~QLong;~QString;\"]}");
48+
49+
Response<JUnitLaunchArguments> response = JUnitLaunchUtils.resolveLaunchArgument(arguments, new NullProgressMonitor());
50+
assertEquals(0, response.getStatus());
51+
}
4252
}

java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/launchers/JUnitLaunchConfigurationDelegate.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@
3131
import org.eclipse.jdt.core.IJavaProject;
3232
import org.eclipse.jdt.core.IMethod;
3333
import org.eclipse.jdt.core.JavaCore;
34-
import org.eclipse.jdt.core.dom.ASTNode;
3534
import org.eclipse.jdt.core.dom.CompilationUnit;
3635
import org.eclipse.jdt.core.dom.ITypeBinding;
3736
import org.eclipse.jdt.core.dom.MethodDeclaration;
38-
import org.eclipse.jdt.core.dom.NodeFinder;
3937
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
38+
import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil;
4039
import org.eclipse.jdt.launching.VMRunnerConfiguration;
4140

4241
import java.io.BufferedWriter;
@@ -91,6 +90,7 @@ public Response<JUnitLaunchArguments> getJUnitLaunchArguments(ILaunchConfigurati
9190
return new Response<>(launchArguments, null);
9291
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException |
9392
InvocationTargetException | CoreException e) {
93+
e.printStackTrace();
9494
JUnitPlugin.logException("failed to resolve the classpath.", e);
9595
final String msg = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();
9696
return new Response<>(null, msg);
@@ -156,20 +156,14 @@ private void addTestItemArgs(List<String> arguments) throws CoreException {
156156
}
157157
final CompilationUnit root = (CompilationUnit) TestSearchUtils.parseToAst(unit,
158158
false /*fromCache*/, new NullProgressMonitor());
159-
final String key = method.getKey();
160-
ASTNode methodDeclaration = root.findDeclaringNode(key);
159+
final MethodDeclaration methodDeclaration = ASTNodeSearchUtil.getMethodDeclarationNode(method, root);
161160
if (methodDeclaration == null) {
162-
// fallback to find it according to source range
163-
methodDeclaration = NodeFinder.perform(root, method.getSourceRange().getOffset(),
164-
method.getSourceRange().getLength(), unit);
165-
}
166-
if (!(methodDeclaration instanceof MethodDeclaration)) {
167161
throw new CoreException(new Status(IStatus.ERROR, JUnitPlugin.PLUGIN_ID, IStatus.ERROR,
168162
"Cannot get method declaration of method" + method.getElementName(), null)); //$NON-NLS-1$
169163
}
170164

171165
final List<String> parameters = new LinkedList<>();
172-
for (final Object obj : ((MethodDeclaration) methodDeclaration).parameters()) {
166+
for (final Object obj : methodDeclaration.parameters()) {
173167
if (obj instanceof SingleVariableDeclaration) {
174168
final ITypeBinding paramTypeBinding = ((SingleVariableDeclaration) obj)
175169
.getType().resolveBinding();

java-extension/com.microsoft.java.test.target/com.microsoft.java.test.tp.target

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,19 @@
2323
<unit id="org.eclipse.sdk.feature.group" version="0.0.0"/>
2424
<unit id="org.mockito.mockito-core" version="0.0.0"/>
2525
<unit id="org.apache.commons.commons-io" version="0.0.0"/>
26-
<repository location="https://download.eclipse.org/eclipse/updates/4.28/R-4.28-202306050440/"/>
26+
<repository location="https://download.eclipse.org/eclipse/updates/4.33-I-builds/I20240728-1800/"/>
2727
</location>
2828
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
2929
<unit id="org.eclipse.xtext.xbase.lib" version="0.0.0"/>
30-
<repository location="https://download.eclipse.org/releases/2023-03/"/>
30+
<repository location="https://download.eclipse.org/releases/2024-03/"/>
3131
</location>
3232
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
33-
<repository location="https://download.eclipse.org/lsp4j/updates/releases/0.21.1/"/>
33+
<repository location="https://download.eclipse.org/lsp4j/updates/releases/0.23.1/"/>
3434
<unit id="org.eclipse.lsp4j.sdk.feature.group" version="0.0.0"/>
3535
</location>
3636
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
3737
<unit id="org.eclipse.jdt.ls.core" version="0.0.0"/>
38-
<!-- Latest JDT.LS requires JUnit 5.10+, which will break test execution <= 5.9.3
39-
See: https://github.com/microsoft/vscode-java-test/pull/1608#issue-1904190398 -->
40-
<repository location="https://download.eclipse.org/jdtls/snapshots/repository/1.30.0.202310302327/"/>
41-
</location>
42-
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
43-
<unit id="org.apache.commons.lang3" version="3.1.0.v201403281430"/>
44-
<repository location="https://download.eclipse.org/tools/orbit/R-builds/R20200529191137/repository/"/>
38+
<repository location="https://download.eclipse.org/jdtls/snapshots/repository/latest/"/>
4539
</location>
4640
<location includeDependencyDepth="infinite" includeDependencyScopes="compile" includeSource="true" missingManifest="generate" type="Maven">
4741
<dependencies>
@@ -50,6 +44,12 @@
5044
<artifactId>org.jacoco.core</artifactId>
5145
<version>0.8.12</version>
5246
</dependency>
47+
<dependency>
48+
<groupId>org.apache.commons</groupId>
49+
<artifactId>commons-lang3</artifactId>
50+
<version>3.14.0</version>
51+
<type>jar</type>
52+
</dependency>
5353
</dependencies>
5454
</location>
5555
</locations>

0 commit comments

Comments
 (0)