2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com
.intellij
.codeInspection
.htmlInspections
;
19 import com
.intellij
.codeInspection
.ProblemsHolder
;
20 import com
.intellij
.codeInspection
.ProblemHighlightType
;
21 import com
.intellij
.lang
.ASTNode
;
22 import com
.intellij
.openapi
.diagnostic
.Logger
;
23 import com
.intellij
.psi
.PsiElement
;
24 import com
.intellij
.psi
.html
.HtmlTag
;
25 import com
.intellij
.psi
.xml
.XmlAttribute
;
26 import com
.intellij
.psi
.xml
.XmlChildRole
;
27 import com
.intellij
.psi
.xml
.XmlTag
;
28 import com
.intellij
.xml
.XmlAttributeDescriptor
;
29 import com
.intellij
.xml
.XmlBundle
;
30 import com
.intellij
.xml
.XmlElementDescriptor
;
31 import com
.intellij
.xml
.impl
.schema
.AnyXmlElementDescriptor
;
32 import com
.intellij
.xml
.util
.XmlUtil
;
33 import com
.intellij
.codeInsight
.daemon
.XmlErrorMessages
;
34 import org
.jetbrains
.annotations
.Nls
;
35 import org
.jetbrains
.annotations
.NonNls
;
36 import org
.jetbrains
.annotations
.NotNull
;
41 public class HtmlUnknownAttributeInspection
extends HtmlUnknownTagInspection
{
42 private static final Logger LOG
= Logger
.getInstance("#com.intellij.codeInspection.htmlInspections.HtmlUnknownAttributeInspection");
43 @NonNls public static final String ATTRIBUTE_SHORT_NAME
= "HtmlUnknownAttribute";
45 public HtmlUnknownAttributeInspection() {
51 public String
getDisplayName() {
52 return XmlBundle
.message("html.inspections.unknown.attribute");
57 public String
getShortName() {
58 return ATTRIBUTE_SHORT_NAME
;
61 protected String
getCheckboxTitle() {
62 return XmlBundle
.message("html.inspections.unknown.tag.attribute.checkbox.title");
65 protected String
getPanelTitle() {
66 return XmlBundle
.message("html.inspections.unknown.tag.attribute.title");
70 protected Logger
getLogger() {
74 protected void checkTag(@NotNull final XmlTag tag
, @NotNull final ProblemsHolder holder
, final boolean isOnTheFly
) {
75 // does nothing! this method should be overriden empty!
78 protected void checkAttribute(@NotNull final XmlAttribute attribute
, @NotNull final ProblemsHolder holder
, final boolean isOnTheFly
) {
79 final XmlTag tag
= attribute
.getParent();
81 if (tag
instanceof HtmlTag
) {
82 XmlElementDescriptor elementDescriptor
= tag
.getDescriptor();
83 if (elementDescriptor
== null || elementDescriptor
instanceof AnyXmlElementDescriptor
) {
87 XmlAttributeDescriptor attributeDescriptor
= elementDescriptor
.getAttributeDescriptor(attribute
);
89 final String name
= attribute
.getName();
91 if (attributeDescriptor
== null) {
92 if (!XmlUtil
.attributeFromTemplateFramework(name
, tag
) && (!isCustomValuesEnabled() || !isCustomValue(name
))) {
93 final ASTNode node
= attribute
.getNode();
95 final PsiElement nameElement
= XmlChildRole
.ATTRIBUTE_NAME_FINDER
.findChild(node
).getPsi();
97 holder
.registerProblem(nameElement
, XmlErrorMessages
.message("attribute.is.not.allowed.here", name
),
98 ProblemHighlightType
.GENERIC_ERROR_OR_WARNING
,
99 new AddCustomTagOrAttributeIntentionAction(getShortName(), name
, XmlEntitiesInspection
.UNKNOWN_ATTRIBUTE
),
100 new RemoveAttributeIntentionAction(name
, attribute
));