This Question is Answered

1 "correct" answer available (4 pts) 2 "helpful" answers available (2 pts)
5 Replies Last post: Sep 25, 2006 6:58 PM by Dmitry Jemerov  
Mike McCullough Newbie 21 posts since
Nov 4, 2004
Currently Being Moderated

May 4, 2006 12:01 AM

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):

 


public final void applyFix(Project project, ProblemDescriptor descriptor) {
    ASTNode node = new DummyHolderElement(); // Didn't see one for a property
    try {
        PropertyImpl property = new PropertyImpl(node);
        property.setName("Check");
        property.setValue("1-2");
        propertiesFile.addProperty(property);
    } catch (IncorrectOperationException exception) {
        exception.printStackTrace();
}

     

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.

Guest
Currently Being Moderated
May 4, 2006 1:20 AM in response to: Mike McCullough
Re: Dynamically add new properties to .properties files

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:

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):

 


> public final void applyFix(Project project, ProblemDescriptor descriptor) {
>     ASTNode node = new DummyHolderElement(); // Didn't see one for a property
>     try {
>         PropertyImpl property = new PropertyImpl(node);
>         property.setName("Check");
>         property.setValue("1-2");
>         propertiesFile.addProperty(property);
>     } catch (IncorrectOperationException exception) {
>         exception.printStackTrace();
> }

     

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.

 

Roy Navon Newbie 2 posts since
Sep 25, 2006
Currently Being Moderated
Sep 25, 2006 5:32 PM in response to: Keith Lea
Re: Dynamically add new properties to .properties files

Hi,

 

I tried using PropertiesElementFactory but I couldn't find it.

Is it part of the Open API 5.0?

 

Thanks,

Roy

Guest
Currently Being Moderated
Sep 25, 2006 5:35 PM in response to: Roy Navon
Re: Dynamically add new properties to .properties files

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!"

 

 

 

Roy Navon Newbie 2 posts since
Sep 25, 2006
Currently Being Moderated
Sep 25, 2006 6:36 PM in response to: Dmitry Jemerov
Re: Dynamically add new properties to .properties files

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

Guest
Currently Being Moderated
Sep 25, 2006 6:58 PM in response to: Roy Navon
Re: Dynamically add new properties to .properties files

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!"

 

 

 

More Like This

  • Retrieving data ...