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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

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.

Completion for unimported types doesn't work
5 participants