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
.codeInsight
.CodeInsightUtilBase
;
20 import com
.intellij
.codeInsight
.daemon
.XmlErrorMessages
;
21 import com
.intellij
.codeInspection
.LocalQuickFix
;
22 import com
.intellij
.codeInspection
.ProblemDescriptor
;
23 import com
.intellij
.openapi
.application
.Result
;
24 import com
.intellij
.openapi
.command
.WriteCommandAction
;
25 import com
.intellij
.openapi
.project
.Project
;
26 import com
.intellij
.psi
.PsiElement
;
27 import com
.intellij
.psi
.xml
.XmlAttribute
;
28 import org
.jetbrains
.annotations
.NotNull
;
33 public class RemoveAttributeIntentionAction
implements LocalQuickFix
{
34 private final String myLocalName
;
35 private final XmlAttribute myAttribute
;
37 public RemoveAttributeIntentionAction(final String localName
, final XmlAttribute attribute
) {
38 myLocalName
= localName
;
39 myAttribute
= attribute
;
43 public String
getName() {
44 return XmlErrorMessages
.message("remove.attribute.quickfix.text", myLocalName
);
48 public String
getFamilyName() {
49 return XmlErrorMessages
.message("remove.attribute.quickfix.family");
52 public void applyFix(@NotNull final Project project
, @NotNull final ProblemDescriptor descriptor
) {
53 if (!CodeInsightUtilBase
.prepareFileForWrite(myAttribute
.getContainingFile())) {
57 PsiElement next
= findNextAttribute(myAttribute
);
58 new WriteCommandAction(project
) {
59 protected void run(final Result result
) throws Throwable
{
65 // editor.getCaretModel().moveToOffset(next.getTextRange().getStartOffset());
69 private static PsiElement
findNextAttribute(final XmlAttribute attribute
) {
70 PsiElement nextSibling
= attribute
.getNextSibling();
71 while (nextSibling
!= null) {
72 if (nextSibling
instanceof XmlAttribute
) return nextSibling
;
73 nextSibling
= nextSibling
.getNextSibling();