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

improve how method and variable positions names are resolved #597

Merged

Conversation

gayanper
Copy link

Fixes #592

@gayanper gayanper changed the base branch from master to dom-with-javac July 15, 2024 17:41
@gayanper gayanper changed the title Fix name positions improve how method and variable positions names are resoved Jul 15, 2024
@gayanper gayanper changed the title improve how method and variable positions names are resoved improve how method and variable positions names are resolved Jul 15, 2024
@gayanper
Copy link
Author

@mickaelistria @datho7561 A small but skeptical fix which I really need your eyes on.

@mickaelistria
Copy link

Seems to add 76 failures.

@gayanper
Copy link
Author

@mickaelistria is there a easy way to see the diff of failing tests with this PR ?

I think i have to refine the fix.

@gayanper
Copy link
Author

I refined the fix, @mickaelistria please have a look at. I also see that now failed method delta is -80ish.

Comment on lines 943 to 957
// int endPos = javac.getEndPosition(this.javacCompilationUnit.endPositions);
// if( !simpleName.toString().equals(FAKE_IDENTIFIER)) {
// char theChar = this.rawText.charAt(endPos);
// char soughtLastChar = simpleName.toString().charAt(simpleName.toString().length() - 1);
// while (endPos > res.getStartPosition() && theChar != soughtLastChar) {
// theChar = this.rawText.charAt(--endPos);
// }
// endPos++;
// int length = simpleName.toString().length();
// if( endPos != -1 && endPos - length > 0) {
// simpleName.setSourceRange(endPos - length, length);
// }
// }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please just remove

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove it once all tests passes as the final step, Until I will keep this review open as a reminder.

@mickaelistria
Copy link

Looks like it still adds 35 failures compared to https://ci.eclipse.org/ls/job/jdt-core-incubator/job/dom-with-javac/

@datho7561
Copy link

I'm getting IllegalArgumentException thrown in the conversion process:

!ENTRY org.eclipse.jdt.core 4 0 2024-07-17 09:56:29.397
!MESSAGE IllegalArgumentException
!STACK 0
java.lang.IllegalArgumentException
	at org.eclipse.jdt.core.dom.ASTNode.setSourceRange(ASTNode.java:3480)
	at org.eclipse.jdt.core.dom.JavacConverter.nameSettings(JavacConverter.java:398)
	at org.eclipse.jdt.core.dom.JavacConverter.convertMethodDecl(JavacConverter.java:807)
	at org.eclipse.jdt.core.dom.JavacConverter.convertBodyDeclaration(JavacConverter.java:689)
	at org.eclipse.jdt.core.dom.JavacConverter.convertClassDecl(JavacConverter.java:549)
	at org.eclipse.jdt.core.dom.JavacConverter.convertClassDecl(JavacConverter.java:478)
	at org.eclipse.jdt.core.dom.JavacConverter.convertBodyDeclaration(JavacConverter.java:692)
	at org.eclipse.jdt.core.dom.JavacConverter.lambda$3(JavacConverter.java:177)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:215)
	at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
	at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1939)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:570)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:560)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:636)
	at org.eclipse.jdt.core.dom.JavacConverter.populateCompilationUnit(JavacConverter.java:179)
	at org.eclipse.jdt.core.dom.JavacCompilationUnitResolver.parse(JavacCompilationUnitResolver.java:533)
	at org.eclipse.jdt.core.dom.JavacCompilationUnitResolver.toCompilationUnit(JavacCompilationUnitResolver.java:427)
	at org.eclipse.jdt.core.dom.ASTParser.internalCreateASTCached(ASTParser.java:1263)
	at org.eclipse.jdt.core.dom.ASTParser.lambda$0(ASTParser.java:1142)
	at org.eclipse.jdt.internal.core.JavaModelManager.cacheZipFiles(JavaModelManager.java:5762)
	at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:1142)
	at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:882)
	at org.eclipse.jdt.internal.core.CompilationUnit.buildStructure(CompilationUnit.java:218)
	at org.eclipse.jdt.internal.core.Openable.generateInfos(Openable.java:245)
	at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed(JavaElement.java:585)
	at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:308)
	at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:294)
	at org.eclipse.jdt.internal.core.CompilationUnit.getCompilationUnitElementInfo(CompilationUnit.java:1652)
	at org.eclipse.jdt.internal.core.CompilationUnit.getCustomOptions(CompilationUnit.java:1630)
	at org.eclipse.jdt.core.ICompilationUnit.getOptions(ICompilationUnit.java:607)
	at org.eclipse.jdt.core.dom.ASTParser.setSource(ASTParser.java:626)
	at org.eclipse.jdt.core.tests.dom.ConverterTestSetup.runConversion(ConverterTestSetup.java:423)
	at org.eclipse.jdt.core.tests.dom.ConverterTestSetup.runConversion(ConverterTestSetup.java:413)
	at org.eclipse.jdt.core.tests.dom.ConverterTestSetup.runConversion(ConverterTestSetup.java:409)
	at org.eclipse.jdt.core.tests.dom.ConverterTestSetup.runConversion(ConverterTestSetup.java:389)
	at org.eclipse.jdt.core.tests.dom.ASTConverterTest.test0152(ASTConverterTest.java:3431)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at junit.framework.TestCase.runTest(TestCase.java:177)
	at org.eclipse.jdt.core.tests.junit.extension.TestCase.runTest(TestCase.java:972)
	at junit.framework.TestCase.runBare(TestCase.java:142)
	at junit.framework.TestResult$1.protect(TestResult.java:122)
	at junit.framework.TestResult.runProtected(TestResult.java:142)
	at junit.framework.TestResult.run(TestResult.java:125)
	at junit.framework.TestCase.run(TestCase.java:130)
	at junit.framework.TestSuite.runTest(TestSuite.java:241)
	at org.eclipse.jdt.core.tests.model.SuiteOfTestCases$Suite.runTest(SuiteOfTestCases.java:116)
	at junit.framework.TestSuite.run(TestSuite.java:236)
	at org.eclipse.jdt.core.tests.model.SuiteOfTestCases$Suite.superRun(SuiteOfTestCases.java:99)
	at org.eclipse.jdt.core.tests.model.SuiteOfTestCases$Suite$1.protect(SuiteOfTestCases.java:87)
	at junit.framework.TestResult.runProtected(TestResult.java:142)
	at org.eclipse.jdt.core.tests.model.SuiteOfTestCases$Suite.run(SuiteOfTestCases.java:96)
	at junit.framework.TestSuite.runTest(TestSuite.java:241)
	at junit.framework.TestSuite.run(TestSuite.java:236)
	at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:90)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:93)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:530)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:758)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:453)
	at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:83)
	at org.eclipse.pde.internal.junit.runtime.CoreTestApplication.start(CoreTestApplication.java:28)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:208)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:143)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:109)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:439)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:271)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:668)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:605)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1481)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1454)

The cause appears to be that the length of the name is non-zero, but the starting position is < 0.

@datho7561
Copy link

I suggest setting a break point on the two IllegalArgumentException throws in ASTNode.setSourceRange and then debug the RunConverterTestsJavac test suite (let me know if you need help settings this up). It should help uncover a few things.

For instance, for constructors, the selector is <init>. The length of the selector is used to set the length of the node name, which in this case means the wrong length is being set.

@gayanper
Copy link
Author

@datho7561 @mickaelistria How do you run the tests locally for debugging, For example I tried to run a failing ASTConverter test in org.eclipse.jdt.core.tests.model but I get bunch of errors that I don't see in CI. basically regardless which branch I'm in they fail.

@datho7561
Copy link

Here's the config I use along with descriptions of the important parts

image

I run the RunConverterTestsJavac test suite. (You can use JUnit 4 instead of JUnit 3, that doesn't seem to matter)

image

The runtime JRE must be Java 23. The Temurin build of Java 23 is not yet available (Java 23 is due in September I think), so I'm using the java.com early access build.

image

In the VM arguments, you must pass all the flags needed to enable the javac bits. The list of arguments is available in the pom.xml for the javac.tests project

We should probably document this somewhere.

@gayanper
Copy link
Author

@datho7561 thanks a lot for the details, I thought I might have to use the Eclipse IDE to run the tests, but I can get It working in VSCode as well, even individuals tests using PDE plugin. What was missing is the java module entries which I totally forgot about.

@mickaelistria mickaelistria merged commit ce7aa6c into eclipse-jdtls:dom-with-javac Jul 19, 2024
2 of 3 checks passed
akurtakov pushed a commit that referenced this pull request Jul 19, 2024
fix: #592

* Use simple name length instead of javac node length.
* consider the fake name and error names when calculating length.
* skip error and fake identifier nodes from position update.
* improve fix how position is calculated
mickaelistria pushed a commit that referenced this pull request Jul 25, 2024
fix: #592

* Use simple name length instead of javac node length.
* consider the fake name and error names when calculating length.
* skip error and fake identifier nodes from position update.
* improve fix how position is calculated
mickaelistria pushed a commit that referenced this pull request Jul 25, 2024
fix: #592

* Use simple name length instead of javac node length.
* consider the fake name and error names when calculating length.
* skip error and fake identifier nodes from position update.
* improve fix how position is calculated
akurtakov pushed a commit that referenced this pull request Jul 29, 2024
fix: #592

* Use simple name length instead of javac node length.
* consider the fake name and error names when calculating length.
* skip error and fake identifier nodes from position update.
* improve fix how position is calculated
akurtakov pushed a commit that referenced this pull request Aug 16, 2024
fix: #592

* Use simple name length instead of javac node length.
* consider the fake name and error names when calculating length.
* skip error and fake identifier nodes from position update.
* improve fix how position is calculated
mickaelistria pushed a commit that referenced this pull request Sep 5, 2024
fix: #592

* Use simple name length instead of javac node length.
* consider the fake name and error names when calculating length.
* skip error and fake identifier nodes from position update.
* improve fix how position is calculated
mickaelistria pushed a commit that referenced this pull request Sep 10, 2024
fix: #592

* Use simple name length instead of javac node length.
* consider the fake name and error names when calculating length.
* skip error and fake identifier nodes from position update.
* improve fix how position is calculated
mickaelistria pushed a commit that referenced this pull request Sep 18, 2024
fix: #592

* Use simple name length instead of javac node length.
* consider the fake name and error names when calculating length.
* skip error and fake identifier nodes from position update.
* improve fix how position is calculated
mickaelistria pushed a commit that referenced this pull request Sep 24, 2024
fix: #592

* Use simple name length instead of javac node length.
* consider the fake name and error names when calculating length.
* skip error and fake identifier nodes from position update.
* improve fix how position is calculated
mickaelistria pushed a commit that referenced this pull request Sep 25, 2024
fix: #592

* Use simple name length instead of javac node length.
* consider the fake name and error names when calculating length.
* skip error and fake identifier nodes from position update.
* improve fix how position is calculated
mickaelistria pushed a commit that referenced this pull request Oct 15, 2024
fix: #592

* Use simple name length instead of javac node length.
* consider the fake name and error names when calculating length.
* skip error and fake identifier nodes from position update.
* improve fix how position is calculated
rgrunber pushed a commit that referenced this pull request Oct 18, 2024
fix: #592

* Use simple name length instead of javac node length.
* consider the fake name and error names when calculating length.
* skip error and fake identifier nodes from position update.
* improve fix how position is calculated
mickaelistria pushed a commit that referenced this pull request Oct 23, 2024
fix: #592

* Use simple name length instead of javac node length.
* consider the fake name and error names when calculating length.
* skip error and fake identifier nodes from position update.
* improve fix how position is calculated
mickaelistria pushed a commit that referenced this pull request Nov 12, 2024
fix: #592

* Use simple name length instead of javac node length.
* consider the fake name and error names when calculating length.
* skip error and fake identifier nodes from position update.
* improve fix how position is calculated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[javac][format] formatting issue when using a similar names in annotation parameters and method name
3 participants