visitXmlAttribute question
I'm just getting my feet wet with plugin development so please excuse me for silly questions :)
I have a really simple LocalInspectionTool that checks for invalid xml attributes. I do something like this:
public void visitXmlAttribute(XmlAttribute attribute)
{
if (attribute.getName().equals("foo"))
{
if (attribute.getValue().equals("bar"))
{
problemsHolder.registerProblem(
attribute,
"invalid.attribute.test"
);
}
}
}
When I create a html file and add a foo=bar attribute to a tag it is correctly marked with "invalid.attribute.test". Cool. But it is marked 5 times :) I don't understand where the duplicate warnings come from.
S.
Please sign in to leave a comment.
Hello Stefan,
SA> I'm just getting my feet wet with plugin development so please
SA> excuse me for silly questions :)
SA>
SA> I have a really simple LocalInspectionTool that checks for invalid
SA> xml attributes. I do something like this:
SA>
SA> public void visitXmlAttribute(XmlAttribute attribute)
SA> {
SA> if (attribute.getName().equals("foo"))
SA> {
SA> if (attribute.getValue().equals("bar"))
SA> {
SA> problemsHolder.registerProblem(
SA> attribute,
SA> "invalid.attribute.test"
SA> );
SA> }
SA> }
SA> }
SA> When I create a html file and add a foo=bar attribute to a tag it is
SA> correctly marked with "invalid.attribute.test". Cool. But it is
SA> marked 5 times :) I don't understand where the duplicate warnings
SA> come from.
The visitor returned from the inspection tool must not be inherited from
PsiRecursiveElementVisitor.
--
Dmitry Jemerov
Software Developer
http://www.jetbrains.com/
"Develop with Pleasure!"
Ok I now inherit from PsiElementVisitor and simply provide an empty visitReferenceExpression(). That seems to work much better!
Two additional questions:
ProblemHighlightType only defines a few simple error classes and none really apply to the kind of error that I am finding in the xml. I used GENERIC_ERROR_OR_WARNING in my code but that results in a yellow highlight and not a red error, which is really should be. How do I do the latter?
I'm working on plugin to support a html based template language. The template language adds some additional attributes in their own namespace to html. For example < a href="#" my:id="foo" >Foo< /a >. IDEA correctly marks the my:id as 'Attribute my:id' is not allowed here. Is there a way to override that or remove the error?
S.
Hello Stefan,
SA> Ok I now inherit from PsiElementVisitor and simply provide an empty
SA> visitReferenceExpression(). That seems to work much better!
SA>
SA> Two additional questions:
SA>
SA> ProblemHighlightType only defines a few simple error classes and
SA> none really apply to the kind of error that I am finding in the xml.
SA> I used GENERIC_ERROR_OR_WARNING in my code but that results in a
SA> yellow highlight and not a red error, which is really should be. How
SA> do I do the latter?
Return HighlightDisplayLevel.ERROR from LocalInspectionTool.getDefaultLevel().
--
Dmitry Jemerov
Software Developer
http://www.jetbrains.com/
"Develop with Pleasure!"