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.
16 package com
.intellij
.codeInsight
.daemon
.impl
.quickfix
;
18 import com
.intellij
.codeInsight
.daemon
.QuickFixBundle
;
19 import com
.intellij
.codeInsight
.daemon
.impl
.analysis
.HighlightMessageUtil
;
20 import com
.intellij
.codeInsight
.intention
.IntentionAction
;
21 import com
.intellij
.codeInsight
.CodeInsightUtilBase
;
22 import com
.intellij
.openapi
.editor
.Editor
;
23 import com
.intellij
.openapi
.project
.Project
;
24 import com
.intellij
.psi
.PsiElement
;
25 import com
.intellij
.psi
.PsiFile
;
26 import com
.intellij
.psi
.PsiSubstitutor
;
27 import com
.intellij
.refactoring
.safeDelete
.SafeDeleteHandler
;
28 import com
.intellij
.util
.IncorrectOperationException
;
29 import org
.jetbrains
.annotations
.NotNull
;
31 public class SafeDeleteFix
implements IntentionAction
{
32 private final PsiElement myElement
;
34 public SafeDeleteFix(PsiElement element
) {
39 public String
getText() {
40 return QuickFixBundle
.message("safe.delete.text",
41 HighlightMessageUtil
.getSymbolName(myElement
, PsiSubstitutor
.EMPTY
));
45 public String
getFamilyName() {
46 return QuickFixBundle
.message("safe.delete.family");
49 public boolean isAvailable(@NotNull Project project
, Editor editor
, PsiFile file
) {
50 return myElement
.isValid() && myElement
.getManager().isInProject(myElement
);
53 public void invoke(@NotNull Project project
, Editor editor
, PsiFile file
) throws IncorrectOperationException
{
54 if (!CodeInsightUtilBase
.prepareFileForWrite(myElement
.getContainingFile())) return;
55 SafeDeleteHandler
.invoke(project
, new PsiElement
[]{myElement
}, false);
58 public boolean startInWriteAction() {