autocompletion getVariants returning PsiElement[]

hi,

i am a bit confused by the documention. http://grepcode.com/file/repository.grepcode.com/java/ext/com.jetbrains/intellij-idea/10.0/com/intellij/psi/PsiReference.java#PsiReference.getVariants%28%29 mention me that i can return String[] and PsiElement[].
if i just return a string everything is fine, if i return a PsiElement i get an exception.

java.lang.IllegalArgumentException: Argument 1 for @NotNull parameter of com/intellij/codeInsight/lookup/LookupItem.<init> must not be null
     at com.intellij.codeInsight.lookup.LookupItem.<init>(LookupItem.java)
     at com.intellij.codeInsight.completion.CompletionData.objectToLookupItem(CompletionData.java:257)
     at com.intellij.codeInsight.completion.CompletionData.addLookupItem(CompletionData.java:272)
     at com.intellij.codeInsight.completion.CompletionData.completeReference(CompletionData.java:320)
     at com.intellij.codeInsight.completion.CompletionVariant.addReferenceCompletions(CompletionVariant.java:181)
     at com.intellij.codeInsight.completion.CompletionData.completeReference(CompletionData.java:112)
     at com.intellij.codeInsight.completion.LegacyCompletionContributor$2.consume(LegacyCompletionContributor.java:80)



i got the PsiElement from another file:

PsiFile[] filesByName = FilenameIndex.getFilesByName(this.project, "foo.php.blubb.php", ProjectScope.getProjectScope(this.project));         PsiFile file = filesByName[0];         PsiElement[] psiElements = new PsiElement[1];         TagPsiFinder visitor = new TagPsiFinder(psiElements) {             @Override             public void visitElement(PsiElement element) {                  super.visitElement(element);                  if(element instanceof LeafPsiElement && ((LeafPsiElement) element).getElementType().toString() == "variable" )                      this.list[0] = element;             }         };         file.accept(visitor);         return psiElements; // instance is returned, verified in the debugger.



thanks for any hint :)
3 comments
Comment actions Permalink

Hello,

IDEA should be able to get a string representing the returned PsiElement. Usually this is ensured by implementing PsiNamedElement interface in your
PsiElement.

--
Nikolay Chashnikov
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

0
Comment actions Permalink

so normal times this should work fine?

is it ok, that i fetch any PsiElement from a different File? May it cant resolve the Element or something like this?

0
Comment actions Permalink

The exception means that IDEA cannot get a name of the PsiElement. The idea.log file should contain more detailed description of the problem.

--
Nikolay Chashnikov
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

0

Please sign in to leave a comment.