Dynamically add new properties to .properties files
I have tried to add a new property to a .properties file, but I get stuck when trying to create a new Property using the PropertyImpl contructor. It takes in a ASTNode, and from the PsiViewer I can see that it's an "Element(Properties:PROPERTY)". However, I didn't see any ASTNode's that directly correspond to a "Property" like many of the other available options.
What I have tried is (applying this in a quick fix):
If this is not the right direction to take, is there a factory for doing something along these lines? I didn't see the ability to do such using the PsiElementFactory.
Please sign in to leave a comment.
You probably use PropertiesElementFactory. I found this with
ctrlaltshiftn "createProperty". CtrlAltShiftN is the #1 best way
to find something in IDEA plugin API.
Mike McCullough wrote:
Hi,
I tried using PropertiesElementFactory but I couldn't find it.
Is it part of the Open API 5.0?
Thanks,
Roy
Hello Roy,
RN> I tried using PropertiesElementFactory but I couldn't find it. Is it
RN> part of the Open API 5.0?
The class is in idea.jar. In 5.0 it was not officially documented, and in
6.0 it's considered "Extended API" (API is supported, but no source code
is provided).
--
Dmitry Jemerov
Software Developer
http://www.jetbrains.com/
"Develop with Pleasure!"
Thanks for the prompt reply Dmitry,
My problem was that idea.jar wasn't in my classpath for some reason.
Is there any way to determine the location of the new property in the file?
addAfter() doesn't work here and I have to use addProperty() instead.
Thanks again,
Roy
Hello Roy,
RN> Is there any way to determine the location of the new property in
RN> the file? addAfter() doesn't work here and I have to use
RN> addProperty() instead.
Looks like it's not currently possible. Please file a JIRA request to add
this to the API.
--
Dmitry Jemerov
Software Developer
http://www.jetbrains.com/
"Develop with Pleasure!"