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
.refactoring
.openapi
.impl
;
18 import com
.intellij
.openapi
.diagnostic
.Logger
;
19 import com
.intellij
.openapi
.project
.Project
;
20 import com
.intellij
.openapi
.vfs
.VirtualFile
;
21 import com
.intellij
.psi
.*;
22 import com
.intellij
.refactoring
.*;
23 import com
.intellij
.refactoring
.move
.moveClassesOrPackages
.AutocreatingSingleSourceRootMoveDestination
;
24 import com
.intellij
.refactoring
.move
.moveClassesOrPackages
.MultipleRootsMoveDestination
;
25 import com
.intellij
.refactoring
.move
.moveInner
.MoveInnerImpl
;
26 import org
.jetbrains
.annotations
.NotNull
;
31 public class JavaRefactoringFactoryImpl
extends JavaRefactoringFactory
{
32 private static final Logger LOG
= Logger
.getInstance("#com.intellij.refactoring.openapi.impl.JavaRefactoringFactoryImpl");
33 private final Project myProject
;
35 public JavaRefactoringFactoryImpl(Project project
) {
39 public JavaRenameRefactoring
createRename(PsiElement element
, String newName
) {
40 return new JavaRenameRefactoringImpl(myProject
, element
, newName
, true, true);
43 public MoveInnerRefactoring
createMoveInner(PsiClass innerClass
, String newName
, boolean passOuterClass
, String parameterName
) {
44 final PsiElement targetContainer
= MoveInnerImpl
.getTargetContainer(innerClass
, false);
45 if (targetContainer
== null) return null;
46 return new MoveInnerRefactoringImpl(myProject
, innerClass
, newName
, passOuterClass
, parameterName
, targetContainer
);
49 public MoveDestination
createSourceFolderPreservingMoveDestination(@NotNull String targetPackage
) {
50 return new MultipleRootsMoveDestination(createPackageWrapper(targetPackage
));
53 private PackageWrapper
createPackageWrapper(@NotNull String targetPackage
) {
54 return new PackageWrapper(PsiManager
.getInstance(myProject
), targetPackage
);
57 public MoveDestination
createSourceRootMoveDestination(@NotNull String targetPackageQualifiedName
, @NotNull VirtualFile sourceRoot
) {
58 final PsiDirectory directory
= PsiManager
.getInstance(myProject
).findDirectory(sourceRoot
);
59 LOG
.assertTrue(directory
!= null && JavaDirectoryService
.getInstance().isSourceRoot(directory
), "Should pass source root");
60 return new AutocreatingSingleSourceRootMoveDestination(createPackageWrapper(targetPackageQualifiedName
),
65 public MoveClassesOrPackagesRefactoring
createMoveClassesOrPackages(PsiElement
[] elements
, MoveDestination moveDestination
) {
66 return new MoveClassesOrPackagesRefactoringImpl(myProject
, elements
, moveDestination
);
69 public MoveMembersRefactoring
createMoveMembers(final PsiMember
[] elements
,
70 final String targetClassQualifiedName
,
71 final String newVisibility
) {
72 return createMoveMembers(elements
, targetClassQualifiedName
, newVisibility
, false);
75 public MoveMembersRefactoring
createMoveMembers(final PsiMember
[] elements
,
76 final String targetClassQualifiedName
,
77 final String newVisibility
,
78 final boolean makeEnumConstants
) {
79 return new MoveMembersRefactoringImpl(myProject
, elements
, targetClassQualifiedName
, newVisibility
, makeEnumConstants
);
82 public MakeStaticRefactoring
<PsiMethod
> createMakeMethodStatic(PsiMethod method
,
83 boolean replaceUsages
,
84 String classParameterName
,
87 return new MakeMethodStaticRefactoringImpl(myProject
, method
, replaceUsages
, classParameterName
, fields
, names
);
90 public MakeStaticRefactoring
<PsiClass
> createMakeClassStatic(PsiClass aClass
,
91 boolean replaceUsages
,
92 String classParameterName
,
95 return new MakeClassStaticRefactoringImpl(myProject
, aClass
, replaceUsages
, classParameterName
, fields
, names
);
98 public ConvertToInstanceMethodRefactoring
createConvertToInstanceMethod(PsiMethod method
,
99 PsiParameter targetParameter
) {
100 return new ConvertToInstanceMethodRefactoringImpl(myProject
, method
, targetParameter
);
103 public SafeDeleteRefactoring
createSafeDelete(PsiElement
[] elements
) {
104 return new SafeDeleteRefactoringImpl(myProject
, elements
);
107 public TurnRefsToSuperRefactoring
createTurnRefsToSuper(PsiClass aClass
,
109 boolean replaceInstanceOf
) {
110 return new TurnRefsToSuperRefactoringImpl(myProject
, aClass
, aSuper
, replaceInstanceOf
);
113 public ReplaceConstructorWithFactoryRefactoring
createReplaceConstructorWithFactory(PsiMethod method
,
114 PsiClass targetClass
,
115 String factoryName
) {
116 return new ReplaceConstructorWithFactoryRefactoringImpl(myProject
, method
, targetClass
, factoryName
);
119 public ReplaceConstructorWithFactoryRefactoring
createReplaceConstructorWithFactory(PsiClass originalClass
,
120 PsiClass targetClass
,
121 String factoryName
) {
122 return new ReplaceConstructorWithFactoryRefactoringImpl(myProject
, originalClass
, targetClass
, factoryName
);
125 public TypeCookRefactoring
createTypeCook(PsiElement
[] elements
,
126 boolean dropObsoleteCasts
,
127 boolean leaveObjectsRaw
,
128 boolean preserveRawArrays
,
131 boolean cookToWildcards
) {
132 return new TypeCookRefactoringImpl(myProject
, elements
, dropObsoleteCasts
, leaveObjectsRaw
, preserveRawArrays
, exhaustive
, cookObjects
, cookToWildcards
);
135 public IntroduceParameterRefactoring
createIntroduceParameterRefactoring(PsiMethod methodToReplaceIn
,
136 PsiMethod methodToSearchFor
,
137 String parameterName
, PsiExpression parameterInitializer
,
138 PsiLocalVariable localVariable
,
139 boolean removeLocalVariable
, boolean declareFinal
) {
140 return new IntroduceParameterRefactoringImpl(myProject
, methodToReplaceIn
, methodToSearchFor
, parameterName
, parameterInitializer
,
141 localVariable
, removeLocalVariable
, declareFinal
);
144 public IntroduceParameterRefactoring
createIntroduceParameterRefactoring(PsiMethod methodToReplaceIn
,
145 PsiMethod methodToSearchFor
,
146 String parameterName
, PsiExpression parameterInitializer
,
147 PsiExpression expressionToSearchFor
,
148 boolean declareFinal
, final boolean replaceAllOccurences
) {
149 return new IntroduceParameterRefactoringImpl(myProject
, methodToReplaceIn
, methodToSearchFor
, parameterName
, parameterInitializer
,
150 expressionToSearchFor
, declareFinal
, replaceAllOccurences
);