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

Issues with classes starting with $ #670

Open
snjeza opened this issue Jan 30, 2023 · 4 comments · May be fixed by #671
Open

Issues with classes starting with $ #670

snjeza opened this issue Jan 30, 2023 · 4 comments · May be fixed by #671

Comments

@snjeza
Copy link
Contributor

snjeza commented Jan 30, 2023

Related issues

Steps to reproduce:

  • create the $EnumUtils.java class
package org.sample;
public class $EnumUtils {
	public void test() {
	}
}
  • create the Main.java class
package org.sample.main;
public class Main {
	public static void main(String[] args) {
		$EnumUtils foo = new $EnumUtils();
	}
}
  • try CA, Organize Import, Search, Open Type
@szarnekow
Copy link
Contributor

Any chance we can find a holistic solution that also supports the following cases for top-level types?

  • MyClass$
  • MyClass$$$Generated

It would also be interesting to check if these naming patterns can be supported for nested classes, too.

@snjeza
Copy link
Contributor Author

snjeza commented Feb 1, 2023

Any chance we can find a holistic solution that also supports the following cases for top-level types?
MyClass$
MyClass$$$Generated

I have solved them.

It would also be interesting to check if these naming patterns can be supported for nested classes, too.

It should already work.

@stephan-herrmann
Copy link
Contributor

I haven't looked at the details but this issue reminds me of previous bugs, where the bottom line was: for binary types the problem does not have a valid solution (e.g., requesting a '.' separated signature from "MyClass$$$Generated" has 4 valid solutions - no way the implementation can know, which one is "correct").

Hence my question: can you @snjeza explain your strategy in plain words?

Given that class Signature is API, any changes here will affect clients, some of which may have their own heuristics in place, which could possibly break even by changes that are "morally correct".

@snjeza
Copy link
Contributor Author

snjeza commented Feb 2, 2023

Hence my question: can you @snjeza explain your strategy in plain words?

  • $ becomes $; it certainly isn't anonymous or nested; the current JDK resolves it as <ClassName>.
  • $ becomes $<ClassName}; it certainly isn't anonymous or nested; the current JDK resolves it as .<ClassName>
  • MyClass$$$Generated/MyClass$$Generated becomes MyClass$$$Generated/MyClass$$Generated; I agree that it's ambiguous; current JDK resolves it as MyClass...Generated/MyClass..Generated.

I can remove the solution for MyClass$$$Generated or create a minimal PR to fix the issue described at redhat-developer/vscode-java#2219 as follows:

diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryType.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryType.java
index 6215244b44..0b05d3bf4d 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryType.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryType.java
@@ -268,7 +268,7 @@ public IType getDeclaringType() {
                                lastDollar = i;
                        }
                }
-               if (lastDollar == -1) {
+               if (lastDollar <= 0) {
                        return null;
                } else {
                        String enclosingName = classFileName.substring(0, lastDollar);

@stephan-herrmann @szarnekow @rgrunber Could you, please, advice?

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 a pull request may close this issue.

3 participants