Explaining to idea that variable is used

Hi

we're using some custom annotations in our project for dependency injections, like

@In private Something smth;

Idea gives me a warning "private field smth is never assigned". How do I write a plugin that will add some meta-info to internal idea structures for it tto underfstand that the variable is assigned?

Thanks.

2 comments
Comment actions Permalink

Hi,

You should implement ImplicitUsageProvider.

for instance,

public class MyImplicitUsageProvider implements ImplicitUsageProvider {
private static final @NonNls List RUSED_SYMBOL_ANNOTATIONS = Arrays.asList("com.foo.Out"); private static final @NonNls List]]> WUSED_SYMBOL_ANNOTATIONS =
Arrays.asList("com.foo.In");

public boolean isImplicitUsage(PsiElement element) {
return element instanceof PsiModifierListOwner &&
(AnnotationUtil.isAnnotated((PsiModifierListOwner)element, RUSED_SYMBOL_ANNOTATIONS)

AnnotationUtil.isAnnotated((PsiModifierListOwner)element, WUSED_SYMBOL_ANNOTATIONS));
}

public boolean isImplicitRead(final PsiElement element) {
return element instanceof PsiModifierListOwner && AnnotationUtil.isAnnotated((PsiModifierListOwner)element,
RUSED_SYMBOL_ANNOTATIONS);
}

public boolean isImplicitWrite(final PsiElement element) {
return element instanceof PsiModifierListOwner && AnnotationUtil.isAnnotated((PsiModifierListOwner)element,
WUSED_SYMBOL_ANNOTATIONS);
}
}

Hi

we're using some custom annotations in our project for dependency
injections, like

@In private Something smth;

Idea gives me a warning "private field smth is never assigned". How do
I write a plugin that will add some meta-info to internal idea
structures for it tto underfstand that the variable is assigned?

Thanks.



0
Comment actions Permalink

Wow, thanks, I will definitely try that out. But I'm a bit confused yet: there is no such interface in open api: http://www.jetbrains.com/idea/openapi/5.0/index.html (and I don't have my dev env at hand atm)

0

Please sign in to leave a comment.