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

Completion for unimported types doesn't work #1503

Merged
merged 1 commit into from
Dec 3, 2024

Conversation

snjeza
Copy link
Contributor

@snjeza snjeza commented Oct 23, 2023

Fixes #1502

@stephan-herrmann
Copy link
Contributor

Found this only after commenting in #1502 - still a few answers to my questions there would help the reviewer :)

@akurtakov
Copy link
Contributor

Are @snjeza 's answers on the issue good?

@jukzi
Copy link
Contributor

jukzi commented Dec 5, 2023

@snjeza please resolve conflicts and update the commit message to reflect the change and and contain a reference to the bug

- use MissingTypesGuesser to select all missing types and offer their completion

The related issue: eclipse-jdt#1502
@snjeza
Copy link
Contributor Author

snjeza commented Dec 5, 2023

@jukzi I have updated the PR.

@jukzi
Copy link
Contributor

jukzi commented Dec 5, 2023

LGTM, and it usefull. i tested it. It could be improved, please:

package aaa;

import java.util.ArrayList;

public class X {
	void foo() {
		new ArrayList<>().add(null);
		new HashMap().cl|
		}
}

image
results in not compile-able completion:
new HashMap<K, V>().clear();

it would be better if it completes to diamond operator new HashMap<>().clear(); as K and V are not defined.

@snjeza
Copy link
Contributor Author

snjeza commented Dec 6, 2023

results in not compile-able completion:
new HashMap<K, V>().clear();
it would be better if it completes to diamond operator new HashMap<>().clear(); as K and V are not defined.

This should be resolved in eclipse.jdt.ui - https://github.com/eclipse-jdt/eclipse.jdt.ui/blob/a4c1b5bc5dbb294e8c23b93296effeb1d5c2cae0/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaMethodCompletionProposal.java#L474

@rgrunber
Copy link
Contributor

results in not compile-able completion:
new HashMap<K, V>().clear();
it would be better if it completes to diamond operator new HashMap<>().clear(); as K and V are not defined.

This should be resolved in eclipse.jdt.ui - https://github.com/eclipse-jdt/eclipse.jdt.ui/blob/a4c1b5bc5dbb294e8c23b93296effeb1d5c2cae0/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaMethodCompletionProposal.java#L474

Looks to still be an issue for me with this PR on latest master of jdt.core and latest jdt.ui.

hashmap-clear-generics

@stephan-herrmann
Copy link
Contributor

results in not compile-able completion:
new HashMap<K, V>().clear();
it would be better if it completes to diamond operator new HashMap<>().clear(); as K and V are not defined.

This should be resolved in eclipse.jdt.ui - https://github.com/eclipse-jdt/eclipse.jdt.ui/blob/a4c1b5bc5dbb294e8c23b93296effeb1d5c2cae0/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaMethodCompletionProposal.java#L474

Looks to still be an issue for me with this PR on latest master of jdt.core and latest jdt.ui.

I guess JavaMethodCompletionProposal is good, but perhaps somewhere in the implementation of canUseDiamon() this situation is handled wrongly. In particular InternalExtendedCompletionContext.canUseDiamond(String[], char[][]) from https://bugs.eclipse.org/578969 has a suspicious comment:

// If no LHS or return type expected, then we can safely use diamond

No LHS is actually the situation mentioned by @jukzi , and for this very reason a diamond is illegal.

@datho7561
Copy link
Contributor

Roland sent me to this PR, since I took a look at another PR related to generics. Taking a look at this, it seems like there are two possible ways forward for the completion Stephan mentioned:

  • substitute the erasure of the type variables for the type variables (eg. HashMap<Object, Object> in this case)
  • use the raw type (i.e. HashMap with no diamond operator and no type arguments passed)

However, from my understanding, these fixes to completion seem unrelated to the changes in this PR. Is there anything blocking this PR from being merged?

@stephan-herrmann stephan-herrmann added the content assist Content assist related issues label Sep 15, 2024
@rgrunber rgrunber added this to the 4.35 M1 milestone Nov 29, 2024
@rgrunber rgrunber merged commit 074bbd3 into eclipse-jdt:master Dec 3, 2024
9 checks passed
@rgrunber rgrunber removed this from the 4.35 M1 milestone Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content assist Content assist related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Completion for unimported types doesn't work
6 participants