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
.HighlightUtil
;
20 import com
.intellij
.codeInsight
.intention
.IntentionAction
;
21 import com
.intellij
.codeInsight
.CodeInsightUtilBase
;
22 import com
.intellij
.openapi
.diagnostic
.Logger
;
23 import com
.intellij
.openapi
.editor
.Editor
;
24 import com
.intellij
.openapi
.project
.Project
;
25 import com
.intellij
.psi
.*;
26 import com
.intellij
.psi
.util
.PsiUtil
;
27 import com
.intellij
.util
.IncorrectOperationException
;
28 import org
.jetbrains
.annotations
.NotNull
;
30 public class MoveCatchUpFix
implements IntentionAction
{
31 private static final Logger LOG
= Logger
.getInstance("#com.intellij.codeInsight.daemon.impl.quickfix.DeleteCatchFix");
33 private final PsiCatchSection myCatchSection
;
34 private final PsiCatchSection myMoveBeforeSection
;
36 public MoveCatchUpFix(PsiCatchSection catchSection
, PsiCatchSection moveBeforeSection
) {
37 this.myCatchSection
= catchSection
;
38 myMoveBeforeSection
= moveBeforeSection
;
42 public String
getText() {
43 return QuickFixBundle
.message("move.catch.up.text",
44 HighlightUtil
.formatType(myCatchSection
.getCatchType()),
45 HighlightUtil
.formatType(myMoveBeforeSection
.getCatchType()));
49 public String
getFamilyName() {
50 return QuickFixBundle
.message("move.catch.up.family");
53 public boolean isAvailable(@NotNull Project project
, Editor editor
, PsiFile file
) {
55 myCatchSection
!= null
56 && myCatchSection
.isValid()
57 && myCatchSection
.getManager().isInProject(myCatchSection
)
58 && myMoveBeforeSection
!= null
59 && myMoveBeforeSection
.isValid()
60 && myCatchSection
.getCatchType() != null
61 && PsiUtil
.resolveClassInType(myCatchSection
.getCatchType()) != null
62 && myMoveBeforeSection
.getCatchType() != null
63 && PsiUtil
.resolveClassInType(myMoveBeforeSection
.getCatchType()) != null
64 && !myCatchSection
.getManager().areElementsEquivalent(
65 PsiUtil
.resolveClassInType(myCatchSection
.getCatchType()),
66 PsiUtil
.resolveClassInType(myMoveBeforeSection
.getCatchType()))
70 public void invoke(@NotNull Project project
, Editor editor
, PsiFile file
) {
71 if (!CodeInsightUtilBase
.prepareFileForWrite(myCatchSection
.getContainingFile())) return;
73 PsiTryStatement statement
= myCatchSection
.getTryStatement();
74 statement
.addBefore(myCatchSection
, myMoveBeforeSection
);
75 myCatchSection
.delete();
77 catch (IncorrectOperationException e
) {
82 public boolean startInWriteAction() {