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
.QuickFixActionRegistrar
;
19 import com
.intellij
.codeInsight
.daemon
.impl
.analysis
.HighlightMethodUtil
;
20 import com
.intellij
.codeInsight
.quickfix
.UnresolvedReferenceQuickFixProvider
;
21 import com
.intellij
.openapi
.util
.TextRange
;
22 import com
.intellij
.psi
.*;
23 import com
.intellij
.psi
.util
.PsiTreeUtil
;
24 import com
.intellij
.psi
.util
.PsiUtil
;
26 public class DefaultQuickFixProvider
implements UnresolvedReferenceQuickFixProvider
{
27 public void registerFixes(PsiJavaCodeReferenceElement ref
, QuickFixActionRegistrar registrar
) {
28 registrar
.register(new ImportClassFix(ref
));
29 registrar
.register(SetupJDKFix
.getInstnace());
30 OrderEntryFix
.registerFixes(registrar
, ref
);
31 MoveClassToModuleFix
.registerFixes(registrar
, ref
);
33 if (ref
instanceof PsiReferenceExpression
) {
34 TextRange fixRange
= HighlightMethodUtil
.getFixRange(ref
);
35 PsiReferenceExpression refExpr
= (PsiReferenceExpression
)ref
;
37 registrar
.register(fixRange
, new CreateEnumConstantFromUsageFix(refExpr
), null);
38 registrar
.register(fixRange
, new CreateConstantFieldFromUsageFix(refExpr
), null);
39 registrar
.register(fixRange
, new CreateFieldFromUsageFix(refExpr
), null);
40 registrar
.register(new RenameWrongRefFix(refExpr
));
42 if (!ref
.isQualified()) {
43 registrar
.register(fixRange
, new BringVariableIntoScopeFix(refExpr
), null);
44 registrar
.register(fixRange
, new CreateLocalFromUsageFix(refExpr
), null);
45 registrar
.register(fixRange
, new CreateParameterFromUsageFix(refExpr
), null);
49 registrar
.register(new CreateClassFromUsageFix(ref
, CreateClassKind
.INTERFACE
));
50 if (PsiUtil
.isLanguageLevel5OrHigher(ref
)) {
51 registrar
.register(new CreateClassFromUsageFix(ref
, CreateClassKind
.ENUM
));
53 PsiElement parent
= PsiTreeUtil
.getParentOfType(ref
, PsiNewExpression
.class, PsiMethod
.class);
54 if (parent
instanceof PsiNewExpression
&& !(ref
.getParent() instanceof PsiTypeElement
)) {
55 registrar
.register(new CreateClassFromNewFix((PsiNewExpression
)parent
));
56 registrar
.register(new CreateInnerClassFromNewFix((PsiNewExpression
)parent
));
59 registrar
.register(new CreateClassFromUsageFix(ref
, CreateClassKind
.CLASS
));
60 registrar
.register(new CreateInnerClassFromUsageFix(ref
, CreateClassKind
.CLASS
));