Expression input field with code completion
We want to show a dialog where the user can enter an expression resulting in
a certain type. We can specify the source file location defining the scope,
so local variables of the method, method parameters or fields should be found.
Thanks in advance,
Tom
Please sign in to leave a comment.
Hello Tom,
Use PsiElementFactory.createExpressionCodeFragment() to create a PsiCodeFragment
instance, then use EditorTextField and call editorTextField.setDocument(PsiDocumentManager.getInstance(project).getDocument(codeFragment))
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Thank you, Dmitry. Where can I define the type the expression should have?
Tom
Hello Tom,
Third parameter to createExpressionCodeFragment().
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
More questions:
createExpressionCodeFragment has 4 parameters:
String ... what should I pass?
PsiElement ... the "location" defining the scope?
PsiType ... javaParserFacade.createTypeFromText(className, element); ?
boolean ... what should I pass?
How do I obtain such a class? Ctrl+N does not show me such a class.
Tom
Hello Tom,
>> Use PsiElementFactory.createExpressionCodeFragment() to create a
>> PsiCodeFragment instance
>>
PsiElementFactory is actually one of the few classes in our API that has
complete JavaDoc. And yet you're asking questions for which the answers can
be found in JavaDoc.
The default text of the expression. An empty string is a valid Java expressoin,
so it will do.
The context for resolving references from the code fragment.
If you have a PsiClass, you should better use PsiElementFactory.createType(PsiClass).
true
>> then use EditorTextField
>>
Add idea.jar to the classpath of the IDEA SDK.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Unfortunately, I can't find the JavaDoc in my IDEA installation directory
and IDEA did not found it either when creating the IDEA-SDK.
>> String ... what should I pass?
>> PsiElement ... the "location" defining the scope?
>> PsiType ... javaParserFacade.createTypeFromText(className, element); ?
>> boolean ... what should I pass?
>>> then use EditorTextField
>>>
>> How do I obtain such a class? Ctrl+N does not show me such a class.
Thank you. Now it compiles. But when I press Ctrl-Space in the generated
input field, I'm getting following exception:
Tom
Hello Tom,
>> PsiElementFactory is actually one of the few classes in our API that
>> has complete JavaDoc. And yet you're asking questions for which the
>> answers can be found in JavaDoc.
>>
Please download the Plugin Development Kit:
http://www.jetbrains.com/idea/download/index.html#kit
>>>> then use EditorTextField
>>>>
>>> How do I obtain such a class? Ctrl+N does not show me such a class.
>>>
>> Add idea.jar to the classpath of the IDEA SDK.
>>
>> java.lang.NullPointerException
>>
>> at
>> com.intellij.codeInsight.lookup.LookupManager.getInstance(LookupManag
>> er.java:2)
You didn't pass a Project to the EditorTextField constructor.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
On Fri, 14 Nov 2008 13:27:50 +0000, Dmitry Jemerov wrote:
Hi Dmitry,
the irony of your first sentence surely cannot be lost on you? I'm one
of the first to lose patience when asked questions that a little research
by the questioner would have answered, but it seems not a little churlish
of you to respond like this while, by your own admission, most of the
OpenAPI remains undocumented.
Sadly, expecting to find helpful OpenAPI JavaDoc really is a triumph of
hope over experience. IMHO you shouldn't be surprised when someone's
first thought is to post to a newsgroup rather than to launch their web
browser.
http://www.jetbrains.net/jira/browse/IDEA-20395 adds insult to injury :)
I've (seriously) wondered on several occasions if the lack of API
documentation is a deliberate ploy to filter out those who're not truly
motivated to write plug-ins. The barrier to entry really is much higher
than it should be.
I'm sorry to be critical, particularly since your newsgroup posts are
generally very helpful and appreciated because of that.
--
Mark Scott
mark@codebrewer.com
Hello Mark,
I had to look up "churlish" in the dictionary. :)
Yes, of course, I understand the irony, and in general I'm OK with people
asking simple questions (they're easier for me to answer because I don't
need to do much research). I tried a number of times to start efforts to
improve quality of our API documentation, but given that I have to divide
my time between lots of different projects and tasks, I only managed to produce
several incomplete documents.
Hopefully the company will be able to allocate more resources to API documentation
during version 9 development. However, unfortunately I can't give any definite
promise on that.
>> PsiElementFactory is actually one of the few classes in our API that
>> has complete JavaDoc. And yet you're asking questions for which the
>> answers can be found in JavaDoc.
>>
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
On Fri, 14 Nov 2008 16:14:45 +0000, Dmitry Jemerov wrote:
Hi Dmitry,
Oh well, I'm glad your English vocabulary is improving even if the
OpenAPI doc isn't ;)
I understand that adding API documentation won't directly increase sales
so I'm sure that commercial considerations mean time spent on such a
project won't be considered worthwhile. However, in the longer term, an
increasing number of high-quality, useful plug-ins can only be helpful.
But I guess I'm preaching to the converted...
--
Mark Scott
mark@codebrewer.com
Thank you. Now it compiles, runs without an exception, but still does not
work - just shows a spinning wheel without showing results. Everything
worked perfect with IDEA 7, your massive changes to the OpenAPI cost a lot
of effort.
Tom
Attachment(s):
codecompletion.png
Dmitry, do you have more ideas related with this problem?
Tom
Hello Tom,
I'm afraid not. I would need to run your code under the debugger in order
to investigate why exactly the completion list isn't getting filled.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Hi Dmitry,
Did you receive my code from 24th November?
Tom
Hello Tom,
Yes, but unfortunately I haven't had a chance to look at it yet.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"