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

Fix addStaticImportFavoriteProposals for generic types #1507

Merged
merged 1 commit into from
Jul 17, 2024

Conversation

estepper
Copy link
Contributor

@estepper estepper commented Jul 12, 2024

When you add a static method to a generic type and add it to the list of content assist favorites you can't use Quick Fix to add the required static import.

Let's say you have a helper class as follows:

package content_assist_test;

public class EikesHelper<T>
{
   public static void help()
   {
   }
}

Then you configure that static method as a content assist favorite: content_assist_test.EikesHelper.test

Then you write a class to test it:

public class EikesTest
{
   public static void test()
   {
      help();
   }
}

The call to the help() method is marked as a compiler error. When you open the Quick Fix menu it looks as follows:

image001

When you execute the Quick Fix a wrong import statement is inserted.

The problem is caused by a small bug in org.eclipse.jdt.internal.ui.text.correction.UnresolvedElementsBaseSubProcessor.addStaticImportFavoriteProposals(). In line 1497 it computes the qualifiedTypeName from the fully qualified method name curr. As curr contains the string "<T>", the Signature.getQualifier() method behaves wrongly and cuts off too much.

My fix is to strip off the generic part of the type name with the help of Signature.getTypeErasure() before Signature.getQualifier() is called. The result looks like so, now:

image002

@jjohnstn jjohnstn merged commit d23a721 into eclipse-jdt:master Jul 17, 2024
9 checks passed
@jjohnstn
Copy link
Contributor

Thanks @estepper

@estepper
Copy link
Contributor Author

Thanks for the prompt reaction!

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.

2 participants