public class ExtractMethodProcessor extends java.lang.Object implements MatchProvider
Constructor and Description |
---|
ExtractMethodProcessor(Project project,
Editor editor,
PsiElement[] elements,
PsiType forcedReturnType,
java.lang.String refactoringName,
java.lang.String initialMethodName,
java.lang.String helpId) |
public static final Key<java.lang.Boolean> SIGNATURE_CHANGE_ALLOWED
protected final Project myProject
protected final PsiElement[] myElements
protected final java.lang.String myRefactoringName
protected final java.lang.String myInitialMethodName
protected java.lang.String myMethodName
protected PsiType myReturnType
protected PsiTypeParameterList myTypeParameterList
protected VariableData[] myVariableDatum
protected PsiClassType[] myThrownExceptions
protected boolean myStatic
protected PsiClass myTargetClass
protected ControlFlowWrapper myControlFlowWrapper
protected InputVariables myInputVariables
protected PsiVariable[] myOutputVariables
protected PsiVariable myOutputVariable
protected PsiVariable myArtificialOutputVariable
protected boolean myHasExpressionOutput
protected boolean myCanBeStatic
protected boolean myCanBeChainedConstructor
protected boolean myIsChainedConstructor
protected java.util.List<Match> myDuplicates
protected java.lang.String myMethodVisibility
protected boolean myGenerateConditionalExit
protected PsiStatement myFirstExitStatementCopy
protected PsiMethod myExtractedMethod
protected boolean myNullConditionalCheck
protected boolean myNotNullConditionalCheck
protected Nullability myNullability
public ExtractMethodProcessor(Project project, Editor editor, PsiElement[] elements, PsiType forcedReturnType, java.lang.String refactoringName, java.lang.String initialMethodName, java.lang.String helpId)
public void setShowErrorDialogs(boolean showErrorDialogs)
public void setPreviewSupported(boolean previewSupported)
public boolean isPreviewDuplicates()
public void setChainedConstructor(boolean isChainedConstructor)
public boolean prepare() throws PrepareFailedException
PrepareFailedException
public boolean prepare(Pass<ExtractMethodProcessor> pass) throws PrepareFailedException
PrepareFailedException
protected PsiVariable getArtificialOutputVariable()
protected boolean insertNotNullCheckIfPossible()
protected boolean checkOutputVariablesCount()
public boolean showDialog(boolean direct)
protected void apply(AbstractExtractDialog dialog)
protected AbstractExtractDialog createExtractMethodDialog(boolean direct)
public void setDataFromInputVariables()
public PsiExpression[] findOccurrences()
protected java.lang.String[] suggestInitialMethodName()
public boolean isOutputVariable(PsiVariable var)
public boolean showDialog()
public void testRun() throws IncorrectOperationException
IncorrectOperationException
public void testNullability()
public void testPrepare()
public void testTargetClass(PsiClass targetClass)
public void testPrepare(PsiType returnType, boolean makeStatic) throws PrepareFailedException
PrepareFailedException
public void doNotPassParameter(int i)
public void changeParamName(int i, java.lang.String param)
public void doRefactoring() throws IncorrectOperationException
IncorrectOperationException
public void previewRefactoring(java.util.Set<TextRange> textRanges)
protected void initDuplicates(java.util.Set<TextRange> textRanges)
protected int estimateDuplicatesCount()
public void doExtract() throws IncorrectOperationException
IncorrectOperationException
protected PsiExpression expressionToReplace(PsiExpression expression)
protected boolean isNeedToChangeCallContext()
public java.util.List<Match> getDuplicates()
getDuplicates
in interface MatchProvider
public ParametrizedDuplicates getParametrizedDuplicates()
public java.util.List<Match> getAnyDuplicates()
public void prepareSignature(Match match)
MatchProvider
prepareSignature
in interface MatchProvider
match
- match which requires signature to be changed e.g. due to stronger expected type, etcpublic PsiElement processMatch(Match match) throws IncorrectOperationException
processMatch
in interface MatchProvider
IncorrectOperationException
protected PsiMethodCallExpression getMatchMethodCallExpression(PsiElement element)
protected void deleteExtracted() throws IncorrectOperationException
IncorrectOperationException
protected PsiElement addToMethodCallLocation(PsiStatement newStatement) throws IncorrectOperationException
IncorrectOperationException
public PsiClass getTargetClass()
public PsiType getReturnType()
public PsiMethod generateEmptyMethod(java.lang.String methodName, PsiElement context) throws IncorrectOperationException
IncorrectOperationException
protected boolean defineVariablesForUnselectedParameters()
protected PsiMethodCallExpression generateMethodCall(PsiExpression instanceQualifier, boolean generateArgs, PsiElement context)
protected java.util.Set<PsiVariable> getEffectivelyLocalVariables()
protected void declareNecessaryVariablesAfterCall(PsiVariable outputVariable) throws IncorrectOperationException
IncorrectOperationException
public PsiMethodCallExpression getMethodCall()
public void setMethodCall(PsiMethodCallExpression methodCall)
public boolean isDeclaredInside(PsiVariable variable)
public static boolean canBeStatic(PsiClass targetClass, PsiElement place, PsiElement[] elements, java.util.Set<? super PsiField> usedFields)
protected boolean isFoldingApplicable()
protected void chooseAnchor()
protected void showMultipleOutputMessage(PsiType expressionType) throws PrepareFailedException
PrepareFailedException
protected java.lang.String buildMultipleOutputMessageError(PsiType expressionType)
public PsiMethod getExtractedMethod()
public void setMethodName(java.lang.String methodName)
public PsiElement getAnchor()
public java.lang.Boolean hasDuplicates()
hasDuplicates
in interface MatchProvider
public boolean initParametrizedDuplicates(boolean showDialog)
public boolean hasDuplicates(java.util.Set<? extends VirtualFile> files)
protected DuplicatesFinder getExactDuplicatesFinder()
public java.lang.String getConfirmDuplicatePrompt(Match match)
getConfirmDuplicatePrompt
in interface MatchProvider
public UniqueNameGenerator getParameterNameGenerator(PsiElement scopeElement)
public java.lang.String getReplaceDuplicatesTitle(int idx, int size)
getReplaceDuplicatesTitle
in interface MatchProvider
public InputVariables getInputVariables()
public PsiTypeParameterList getTypeParameterList()
public PsiClassType[] getThrownExceptions()
public boolean isStatic()
public boolean isCanBeStatic()
public PsiElement[] getElements()
public Project getProject()
public java.lang.String getMethodName()
public PsiVariable[] getOutputVariables()
public void setMethodVisibility(java.lang.String methodVisibility)