Type placeholder?

Is there an extension to implement that provides the ability to process local variable declaration Psi and change the variable's underlying type reference, but without changing the text in the document? 

For example, let's say we have a special type that serves as a placeholder:

package placeholder;
public interface Thing {}

Then we have the following code:

import placeholder.Thing;
import java.util.*;

class Foo {
void blah() {
Thing map = new HashMap<String,Foo>();

I want to change the underlying type of Thing for the local variable to Map<String,Foo>, but I want to keep the "Thing" text in place -- no visible changes in the source.  Note Thing may be used in other variable declarations having different types; different occurrences of Thing can resolve to different types.

Perhaps what I'm really after is a way to hook into the Psi parser so that I can re-resolve Thing after the declaration?  Thing's type depends on the right hand side expression.

Anyway, any help here would be appreciated.


1 comment

Hi Scott,

as far as I understood the similar thing is done for Lombok's 'var'. The corresponding extension is com.intellij.psi.augment.PsiAugmentProvider#inferType.



Please sign in to leave a comment.