how to complete with the class's FQN?

hi all
in my plugin, i have a PsiReference implementation class which works fine except in getVarients i return PsiClass array ,when i press ctrl-space it shows the popup of class names(short name) and when i choose one it insert that short name BUT i need it to insert the fully qualified name eg. org.apache.ant.Task not just Task
any help please
is the solution in using candidateInfo instead,if so how can i get(Efficiently) an array of candidateInfo of all classes of the project PLUS dependencies
thanks a lot

6 comments

The obvious solution is to return plain Strings with the FQN instead of PsiClasses.

0

i think it will be overkill(performance wise) to loop over all classes in jdk plus dependencies and get all the FQN as string ,then build the array and return it
is there an already cached version of that to improve the performance(ok i know that i can cache it myself but i donot want to waste memory )
is there a way to intercept between getVarient and the actual completion to get the selected psiClass and insert the FQN
(i know that completionData and lookupItem may be usefull but donot know how to organise the work between them and the PsiReference)
ANY HELP please
thanks
joe

0

If you can return an array of PsiClasses, making an array of their FQNs shouldn't be a problem. Sounds like a case of premature optimization to me.

0

actually i donot get the PsiClasses myself, i get them from the idea openApi SearchHelper which give me all the PsiClasses registered or available to the IDE

0

ok ,i tried your advice and built an array of string of the fqn but when i return it i got this exception

java.lang.Throwable
at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:78)
at com.intellij.codeInsight.lookup.LookupItemUtil.objectToLookupItem(LookupItemUtil.java:157)
at com.intellij.codeInsight.completion.CompletionVariant.a(CompletionVariant.java:74)
at com.intellij.codeInsight.completion.CompletionVariant.addReferenceCompletions(CompletionVariant.java:80)
at com.intellij.codeInsight.completion.CompletionVariant.addReferenceCompletions(CompletionVariant.java:184)
at com.intellij.codeInsight.completion.CompletionData.completeReference(CompletionData.java:14)
at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.a(CodeCompletionHandlerBase.java:184)
at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.getLookupData(CodeCompletionHandlerBase.java:32)
at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.invoke(CodeCompletionHandlerBase.java:76)
at com.intellij.codeInsight.actions.BaseCodeInsightAction$1$1.run(BaseCodeInsightAction.java)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:370)
at com.intellij.codeInsight.actions.BaseCodeInsightAction$1.run(BaseCodeInsightAction.java:2)
at com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:102)
at com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:66)
at com.intellij.codeInsight.actions.BaseCodeInsightAction.actionPerformedImpl(BaseCodeInsightAction.java:5)
at com.intellij.codeInsight.completion.actions.CodeCompletionAction.actionPerformedImpl(CodeCompletionAction.java:4)
at com.intellij.codeInsight.actions.BaseCodeInsightAction.actionPerformed(BaseCodeInsightAction.java:24)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.a(IdeKeyEventDispatcher.java:33)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.b(IdeKeyEventDispatcher.java:176)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:77)
at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:6)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:25)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
ERROR - eInsight.lookup.LookupItemUtil - Assertion failed: Null string for object: null of class null
ERROR - eInsight.lookup.LookupItemUtil - IntelliJ IDEA 5.1 Build #4155
ERROR - eInsight.lookup.LookupItemUtil - JDK: 1.5.0_06
ERROR - eInsight.lookup.LookupItemUtil - VM: Java HotSpot(TM) Client VM
ERROR - eInsight.lookup.LookupItemUtil - Vendor: Sun Microsystems Inc.
ERROR - eInsight.lookup.LookupItemUtil - OS: Windows 2000
ERROR - eInsight.lookup.LookupItemUtil - Last Action: CodeCompletion
ERROR - eInsight.lookup.LookupItemUtil - Current Command: Basic
ERROR - eInsight.lookup.LookupItemUtil - Assertion failed: Null string for object: null of class null
java.lang.Throwable
at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:78)
at com.intellij.codeInsight.lookup.LookupItemUtil.objectToLookupItem(LookupItemUtil.java:157)
at com.intellij.codeInsight.completion.CompletionVariant.a(CompletionVariant.java:74)
at com.intellij.codeInsight.completion.CompletionVariant.addReferenceCompletions(CompletionVariant.java:80)
at com.intellij.codeInsight.completion.CompletionVariant.addReferenceCompletions(CompletionVariant.java:184)
at com.intellij.codeInsight.completion.CompletionData.completeReference(CompletionData.java:14)
at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.a(CodeCompletionHandlerBase.java:184)
at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.getLookupData(CodeCompletionHandlerBase.java:32)
at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.invoke(CodeCompletionHandlerBase.java:76)
at com.intellij.codeInsight.actions.BaseCodeInsightAction$1$1.run(BaseCodeInsightAction.java)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:370)
at com.intellij.codeInsight.actions.BaseCodeInsightAction$1.run(BaseCodeInsightAction.java:2)
at com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:102)
at com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:66)
at com.intellij.codeInsight.actions.BaseCodeInsightAction.actionPerformedImpl(BaseCodeInsightAction.java:5)
at com.intellij.codeInsight.completion.actions.CodeCompletionAction.actionPerformedImpl(CodeCompletionAction.java:4)
at com.intellij.codeInsight.actions.BaseCodeInsightAction.actionPerformed(BaseCodeInsightAction.java:24)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.a(IdeKeyEventDispatcher.java:33)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.b(IdeKeyEventDispatcher.java:176)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:77)
at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:6)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:25)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
java.lang.NullPointerException
at org.apache.oro.text.regex.Perl5Matcher.matches(Unknown Source)
at com.intellij.codeInsight.completion.CompletionVariant.a(CompletionVariant.java:93)
at com.intellij.codeInsight.completion.CompletionVariant.addReferenceCompletions(CompletionVariant.java:80)
at com.intellij.codeInsight.completion.CompletionVariant.addReferenceCompletions(CompletionVariant.java:184)
at com.intellij.codeInsight.completion.CompletionData.completeReference(CompletionData.java:14)
at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.a(CodeCompletionHandlerBase.java:184)
at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.getLookupData(CodeCompletionHandlerBase.java:32)
at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.invoke(CodeCompletionHandlerBase.java:76)
at com.intellij.codeInsight.actions.BaseCodeInsightAction$1$1.run(BaseCodeInsightAction.java)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:370)
at com.intellij.codeInsight.actions.BaseCodeInsightAction$1.run(BaseCodeInsightAction.java:2)
at com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:102)
at com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:66)
at com.intellij.codeInsight.actions.BaseCodeInsightAction.actionPerformedImpl(BaseCodeInsightAction.java:5)
at com.intellij.codeInsight.completion.actions.CodeCompletionAction.actionPerformedImpl(CodeCompletionAction.java:4)
at com.intellij.codeInsight.actions.BaseCodeInsightAction.actionPerformed(BaseCodeInsightAction.java:24)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.a(IdeKeyEventDispatcher.java:33)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.b(IdeKeyEventDispatcher.java:176)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:77)
at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:6)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:25)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
ERROR - mand.impl.CommandProcessorImpl -
ERROR - mand.impl.CommandProcessorImpl - IntelliJ IDEA 5.1 Build #4155
ERROR - mand.impl.CommandProcessorImpl - JDK: 1.5.0_06
ERROR - mand.impl.CommandProcessorImpl - VM: Java HotSpot(TM) Client VM
ERROR - mand.impl.CommandProcessorImpl - Vendor: Sun Microsystems Inc.
ERROR - mand.impl.CommandProcessorImpl - OS: Windows 2000
ERROR - mand.impl.CommandProcessorImpl - Last Action: CodeCompletion
ERROR - mand.impl.CommandProcessorImpl - Current Command: Basic
ERROR - mand.impl.CommandProcessorImpl -
java.lang.NullPointerException
at org.apache.oro.text.regex.Perl5Matcher.matches(Unknown Source)
at com.intellij.codeInsight.completion.CompletionVariant.a(CompletionVariant.java:93)
at com.intellij.codeInsight.completion.CompletionVariant.addReferenceCompletions(CompletionVariant.java:80)
at com.intellij.codeInsight.completion.CompletionVariant.addReferenceCompletions(CompletionVariant.java:184)
at com.intellij.codeInsight.completion.CompletionData.completeReference(CompletionData.java:14)
at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.a(CodeCompletionHandlerBase.java:184)
at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.getLookupData(CodeCompletionHandlerBase.java:32)
at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.invoke(CodeCompletionHandlerBase.java:76)
at com.intellij.codeInsight.actions.BaseCodeInsightAction$1$1.run(BaseCodeInsightAction.java)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:370)
at com.intellij.codeInsight.actions.BaseCodeInsightAction$1.run(BaseCodeInsightAction.java:2)
at com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:102)
at com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:66)
at com.intellij.codeInsight.actions.BaseCodeInsightAction.actionPerformedImpl(BaseCodeInsightAction.java:5)
at com.intellij.codeInsight.completion.actions.CodeCompletionAction.actionPerformedImpl(CodeCompletionAction.java:4)
at com.intellij.codeInsight.actions.BaseCodeInsightAction.actionPerformed(BaseCodeInsightAction.java:24)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.a(IdeKeyEventDispatcher.java:33)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.b(IdeKeyEventDispatcher.java:176)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:77)
at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:6)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:25)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

why,is it because it is very long or what
joe

0

The exception says "Assertion failed: Null string for object: null of class null". I guess you included null-values in your FQN array - which is because of anonymous classes that return null from getQualifiedName() - says the javadoc of PsiClass.

0

Please sign in to leave a comment.