update copyright
[fedora-idea.git] / xml / impl / src / com / intellij / codeInspection / htmlInspections / RemoveAttributeIntentionAction.java
blob33793cbf9235ebd37f244428f9e90b3b1fe038b7
1 /*
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;
30 /**
31 * @author spleaner
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;
42 @NotNull
43 public String getName() {
44 return XmlErrorMessages.message("remove.attribute.quickfix.text", myLocalName);
47 @NotNull
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())) {
54 return;
57 PsiElement next = findNextAttribute(myAttribute);
58 new WriteCommandAction(project) {
59 protected void run(final Result result) throws Throwable {
60 myAttribute.delete();
62 }.execute();
64 //if (next != null) {
65 // editor.getCaretModel().moveToOffset(next.getTextRange().getStartOffset());
66 //}
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();
75 return null;