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
.util
.xml
.highlighting
;
19 import com
.intellij
.codeInspection
.LocalQuickFix
;
20 import com
.intellij
.codeInspection
.ProblemDescriptor
;
21 import com
.intellij
.openapi
.project
.Project
;
22 import com
.intellij
.psi
.xml
.XmlTag
;
23 import com
.intellij
.psi
.xml
.XmlAttribute
;
24 import com
.intellij
.util
.xml
.DomBundle
;
25 import com
.intellij
.util
.xml
.DomElement
;
26 import com
.intellij
.util
.xml
.DomManager
;
27 import org
.jetbrains
.annotations
.NotNull
;
30 * @author Dmitry Avdeev
32 public class RemoveDomElementQuickFix
implements LocalQuickFix
{
34 private final boolean myIsTag
;
35 private final String myName
;
37 public RemoveDomElementQuickFix(@NotNull DomElement element
) {
38 myIsTag
= element
.getXmlElement() instanceof XmlTag
;
39 myName
= element
.getXmlElementName();
43 public String
getName() {
45 DomBundle
.message("remove.element.fix.name", myName
) :
46 DomBundle
.message("remove.attribute.fix.name", myName
);
50 public String
getFamilyName() {
51 return DomBundle
.message("quick.fixes.family");
54 public void applyFix(@NotNull Project project
, @NotNull ProblemDescriptor descriptor
) {
56 final XmlTag tag
= (XmlTag
)descriptor
.getPsiElement();
57 final XmlTag parentTag
= tag
.getParentTag();
58 final DomElement domElement
= DomManager
.getDomManager(project
).getDomElement(tag
);
59 assert domElement
!= null;
60 domElement
.undefine();
61 if (parentTag
!= null && parentTag
.isValid()) {
62 parentTag
.collapseIfEmpty();
65 final DomElement domElement
= DomManager
.getDomManager(project
).getDomElement((XmlAttribute
)descriptor
.getPsiElement());
66 assert domElement
!= null;
67 domElement
.undefine();