Trying to see if a property is set in the .properties files
Hi!
I'd like to make an inspection to see if a string following a specific
pattern is a key in the project .properties files.
(for example if you have someMethod("project.str1"), and there is no
project.str1=foo in any .properties files, this inspection would notify
a problem.
How can I see if a string is a key in the project .properties files?
I saw there's a PropertiesComponent and it has a
isValueSet(java.lang.String name) method. Is it related to my problem,
or something completely unrelated?
Thanks!
BoD
请先登录再写评论。
No, it is completely unrelated.
--
regards,
Alexey Kudravtsev
Software Developer
JetBrains, Inc, http://www.jetbrains.com
"Develop with pleasure!"
P.S. OK, you can test whether some string literal resolves to some property
e.g. this way:
resolved = literalExpression.findReferenceAt(0).resolve();
return resolved instanceof com.intellij.lang.properties.Property;
"BoD" <BoD@JRAF.org> wrote in message news:dfscie$2pf$1@is.intellij.net...
>
>
>
>
>
> resolved = literalExpression.findReferenceAt(0).resolve();
> return resolved instanceof com.intellij.lang.properties.Property;
Thanks!
However 1/ can I test if a property is set without it being an
expression. For example my expression is "FOO" but I want to see if
"FOO"+"_REQUEST" is set.
2/ I can seem to find the com.intellij.lang.properties package anywhere ?
BoD
Alexey Kudravtsev (JetBrains) wrote:
3/ expression.findReferenceAt(0) always returns null even when the
String is indeed a key in a property file (middle-click does work and
goes to the declaration in the file)
BoD
BoD wrote:
>> No, it is completely unrelated.
Sorry, it meant to be PsiReference ref =
literalExpression.findReferenceAt(1);, since the first element in the string
literal is open quote.
Further, there should be these magical lines:
boolean resolvesToProperty(PsiReference ref) {
if (ref instance com.intellij.psi.PsiPolyVariantReference) {
for (PsiReference variantRef:
((PsiPolyVariantReference)ref).multiResolve(false)) {
if (resolvesToProperty(variantRef)) return true;
}
}
return ref.resolve() instanceof Property;
}
As to whether "FOO"+"_REQUEST" expression resolves to the property, there is
public static Collection findPropertiesByKey(Project project, final String key) in the com.intellij.lang.properties.PropertiesUtil class although it is not OpenAPI yet. -- regards, -- Alexey Kudravtsev Software Developer JetBrains, Inc, http://www.jetbrains.com "Develop with pleasure!" "BoD" ]]> wrote in message news:dfsgo9$l8s$1@is.intellij.net...
>
>
>
>
>> > resolved = literalExpression.findReferenceAt(0).resolve();
>> > return resolved instanceof com.intellij.lang.properties.Property;
>>
>> Thanks!
>>
>> However 1/ can I test if a property is set without it being an
>> expression. For example my expression is "FOO" but I want to see if
>> "FOO"+"_REQUEST" is set.
>> 2/ I can seem to find the com.intellij.lang.properties package anywhere ?
>>
>> BoD
>>
>>
>>
>> Alexey Kudravtsev (JetBrains) wrote:
>>
>>> No, it is completely unrelated.
Thank you very much I used the findPropertiesByKey way, and it works well.
I think I'm gonna release this inspection since I believe it could be
usefull.
BoD
Alexey Kudravtsev (JetBrains) wrote: