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

Use JLS23 as latest compliance level in AST #465

Open
wants to merge 724 commits into
base: dom-with-javac
Choose a base branch
from

Conversation

gayanper
Copy link

@gayanper gayanper commented Jun 9, 2024

Currently JavaCore returns the latest supported java version as Java 23, But the AST validation is restricted to Java 22, this cause the issue with vscode java debugger, which sends the compliancy level as 23 when evaluating debug breakpoints to be registered.

@gayanper
Copy link
Author

gayanper commented Jun 9, 2024

@mickaelistria another small fix to make javac usable with debugging in vscode.

@mickaelistria
Copy link

This seems to cause ~60 new test failures: https://ci.eclipse.org/ls/job/jdt-core-incubator/job/PR-465/1/
The issue is that when we set the "latest" then many other bits of JDT expect that ECJ can support this latest too, which is not the case yet.This seems to cause ~60 new test failures: https://ci.eclipse.org/ls/job/jdt-core-incubator/job/PR-465/1/
The issue is that when we set the "latest" then many other bits of JDT expect that ECJ can support this latest too, which is not the case yet. So far, the approach of declaring the new versions but not listing them as "latest" has been the best working one. Do you know where in your use-case is JLS_Latest being used?

@gayanper
Copy link
Author

If we check the code here https://github.com/microsoft/java-debug/blob/83403a458e0d01fba5a3871fea81af742460bdf0/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JdtSourceLookUpProvider.java#L103

as we can see it reads the latest java version from JavaCore.latestSupportedJavaVersion() which has the following implementation in our incubator

	public static String latestSupportedJavaVersion() {
		return allVersions.get(allVersions.size() - 1);
	}

allVersions has VERSION_23 as the last element.

@gayanper
Copy link
Author

@mickaelistria How should we handle this ?

@mickaelistria
Copy link

I'm curious about "AST validation is restricted to Java 22", can you please elaborate how we can see this? I think AST validation should be working for any known AST version, independently of what's the one marked as latest.

@gayanper
Copy link
Author

I'm curious about "AST validation is restricted to Java 22", can you please elaborate how we can see this? I think AST validation should be working for any known AST version, independently of what's the one marked as latest.

The problem happens in https://github.com/gayanper/eclipse.jdt.core/blob/81b72d0d5ee1283ae61f543bb64d6e966fd35e22/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AST.java#L1181

Since the constant at https://github.com/gayanper/eclipse.jdt.core/blob/81b72d0d5ee1283ae61f543bb64d6e966fd35e22/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AST.java#L546 is not pointing to the latest version provided by avaCore.latestSupportedJavaVersion() method.

@testforstephen
Copy link

I previously encountered this issue as well while using the VS Code Java Debugger to debug applications that were switched to Javac. It happens when my session enables breakpoints in some Java files. The reason is that Java Debugger needs to invoke the DOM ASTParser (e.g., ASTParser.newParser(this.latestASTLevel)) to parse the target file and identify the breakpoint context. The debugger always uses the highest AST level supported by JavaCore.latestSupportedJavaVersion() to parse the file. Since the JDT Core updated the latest version to 23, but the Javac parser does not and just supports version 22, resulting in an unsupported AST version error.

To prevent this issue from occurring in the future, we need a flag to determine the actual highest AST version supported by the underlying parser.

@gayanper
Copy link
Author

@testforstephen @mickaelistria What if we use the above flag in the JavaCore.latestSupportedJavaVersion() so that we can override it for javac builds ?

@testforstephen
Copy link

Introducing a system property will delegate the maintenance responsibility to the integration client, that looks a bit heavy to me. Instead, the supported java versions should be a capability of the ASTParser. The ASTParser should include a new method getSupportedHighestJavaVersion() to tell the consumer the highest Java version it supports.

Additionally, we have added an extension point compilationUnitResolver to enable the DOM ASTParser to support alternative parser. I am thinking whether it would be beneficial to extend this extension point to specify the supported Java versions.

@mickaelistria
Copy link

The AST class has some symbols that can probably be changed and used for that case.
We recently had a discussion on another issue with @iloveeclipse , there are multiple possible meanings for "support", and multiple place where versions are set/used. With the current approaches to use alternative parsers, we will have to establish new practices regarding updating those versions as the current ECJ-driven workflow don't fit for Javac.

@gayanper
Copy link
Author

@mickaelistria @testforstephen changes to jdt.core for supporting javac support will get approved ? Since the current way of jdt working is tailored to ECJ and it works fine. And if we are suggesting a new change that benefit the javac support which is not yet in jdt.core main line, I'm thinking if it will be a hard sell.

@mickaelistria
Copy link

changes to jdt.core for supporting javac support will get approved ?

The API change and extension points to allow plugging an alternative parser/compiler are already merged in. The particular Javac extension is not planned to be contributed to JDT at the moment. I would be great to contribute it later, but this is not yet a priority to us and to other JDT contributors, so let's wait a bit.
Some of the remaining changes have been only 2 days ago: eclipse-jdt#2699, eclipse-jdt#2700 , eclipse-jdt#2701 and a couple more changes still have to completed and contributed.

datho7561 and others added 25 commits September 7, 2024 21:04
eg.

```java
public class Superclass {
  public Superclass(int i) {
  }
}
```

```java
public class Subclass extends Superclass {
}
```

An error is issued; this PR ensures that the range covers the text `Subclass`,
which fixes the quickfix to add a constructor when it's invoked from the
beginning of the line.

Signed-off-by: David Thompson <[email protected]>
Do not use the original (recovered) type if it's also erroneous,
instead use the type stub.

Should fix a few tests, probably 4ish.

Signed-off-by: David Thompson <[email protected]>
- `ModifierCorrectionsQuickFixTest.testAddPermitsToDirectSuperClass`
- `ModifierCorrectionsQuickFixTest.testAddSealedAsDirectSuperClass`
- `ModifierCorrectionsQuickFixTest.testAddSealedMissingClassModifierProposal`
- Fix id for "cannot inherit final" for anonymous classes

Signed-off-by: David Thompson <[email protected]>
- Also fix a mostly unrelated classcast exception

Signed-off-by: David Thompson <[email protected]>
…-jdt#597)

fix: eclipse-jdt#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.

7 participants