Methods added via PsiAugmentProvider do not infer references to the containing class' type variable .

Methods added via PsiAugmentProvider do not infer references to the containing class' type variable .

For example, I am using PsiAugmentProvider to add the following methods to java.util.List:

public void foo( java.util.functions.Predicate<E> param )
public void bar( abc.MyClass<E> param )

I am using standard LightMethodBuilder and PsiElementFactory.createMethodFromText() to add both methods.  Everything works fine except type inference on the second one.  For example, if I use code completion for the following:

List<String> list = blah;
list.<ctrl-space>

IJ includes both methods in the popup:

foo( Predicate<String> )  // correctly inferred String
bar( MyClass<E> ) // failed to infer String

But fails to infer E as String in the second one.  MyClass is a simple class:  public class MyClass<T> { ... }  not sure why it can't infer the type correctly.  This behavior is consistent -- if the parameter type is not a standard Java runtime class, it is not inferred.  In this case MyClass comes from a dependency jar file.

0
2 comments

Hi Scott,

What is the context you pass for method created?

Thanks,

Anna

0

Hi Anna.

First I create a PsiMethod via PsiElementFactory:

PsiMethod method = elementFactory.createMethodFromText( methodText, psiClass );

Where psiClass is passed into my implementation of PsiAugmentProvider#getAugments(), which in this case is java.util.List.

Then I create my subclass of LightMethodBuilder:

MyLightMethodBuilder method = myPsiElemFactory.createLightMethod( psiClass.getManager(), methodName )
.withContainingClass( psiClass );
...

The odd part of this is that standard Java generic classes such as Collection and Predicate are correctly inferred, but classes from other jar files and classes local to the project fail to be inferred.

0

Please sign in to leave a comment.