public class RefactoringUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
RefactoringUtil.ConditionCache<T> |
static interface |
RefactoringUtil.Graph<T> |
static interface |
RefactoringUtil.ImplicitConstructorUsageVisitor |
static class |
RefactoringUtil.IsDescendantOf |
Modifier and Type | Field and Description |
---|---|
static int |
EXPR_COPY_PROHIBITED |
static int |
EXPR_COPY_SAFE |
static int |
EXPR_COPY_UNSAFE |
Modifier and Type | Method and Description |
---|---|
static boolean |
canBeDeclaredFinal(PsiVariable variable) |
static boolean |
canCreateInSourceRoot(java.lang.String sourceRootPackage,
java.lang.String targetQName) |
static java.lang.String |
checkEnumConstantInSwitchLabel(PsiExpression expr) |
static java.util.List<PsiVariable> |
collectReferencedVariables(PsiElement scope) |
static void |
collectTypeParameters(java.util.Set<? super PsiTypeParameter> used,
PsiElement element) |
static void |
collectTypeParameters(java.util.Set<? super PsiTypeParameter> used,
PsiElement element,
Condition<? super PsiTypeParameter> filter) |
static PsiExpression |
convertInitializerToNormalExpression(PsiExpression expression,
PsiType forcedReturnType) |
static PsiExpression |
createNewExpressionFromArrayInitializer(PsiArrayInitializerExpression initializer,
PsiType forcedType) |
static PsiDirectory |
createPackageDirectoryInSourceRoot(PackageWrapper aPackage,
VirtualFile sourceRoot) |
static java.lang.String |
createTempVar(PsiExpression expr,
PsiElement context,
boolean declareFinal) |
static PsiTypeParameterList |
createTypeParameterListWithUsedTypeParameters(PsiElement... elements) |
static PsiTypeParameterList |
createTypeParameterListWithUsedTypeParameters(PsiTypeParameterList fromList,
Condition<? super PsiTypeParameter> filter,
PsiElement... elements) |
static PsiTypeParameterList |
createTypeParameterListWithUsedTypeParameters(PsiTypeParameterList fromList,
PsiElement... elements) |
static <T extends PsiExpression> |
ensureCodeBlock(T expression)
Ensures that given call is surrounded by
PsiCodeBlock (that is, it has a parent statement
which is located inside the code block). |
static boolean |
equivalentTypes(PsiType t1,
PsiType t2,
PsiManager manager) |
static PsiCodeBlock |
expandExpressionLambdaToCodeBlock(PsiLambdaExpression lambdaExpression) |
static PsiDirectory |
findPackageDirectoryInSourceRoot(PackageWrapper aPackage,
VirtualFile sourceRoot) |
static PsiJavaCodeReferenceElement |
findReferenceToClass(PsiReferenceList refList,
PsiClass aClass) |
static void |
fixJavadocsForParams(PsiMethod method,
PsiDocComment docComment,
java.util.Set<? extends PsiParameter> newParameters,
Condition<? super Pair<PsiParameter,java.lang.String>> eqCondition,
Condition<? super java.lang.String> matchedToOldParam) |
static void |
fixJavadocsForParams(PsiMethod method,
java.util.Set<? extends PsiParameter> newParameters) |
static void |
fixJavadocsForParams(PsiMethod method,
java.util.Set<? extends PsiParameter> newParameters,
Condition<? super Pair<PsiParameter,java.lang.String>> eqCondition) |
static void |
fixJavadocsForParams(PsiMethod method,
java.util.Set<? extends PsiParameter> newParameters,
Condition<? super Pair<PsiParameter,java.lang.String>> eqCondition,
Condition<? super java.lang.String> matchedToOldParam) |
static PsiElement |
getAnchorElementForMultipleExpressions(PsiExpression [] occurrences,
PsiElement scope) |
static PsiExpressionList |
getArgumentListByMethodReference(PsiElement ref) |
static PsiCall |
getCallExpressionByMethodReference(PsiElement ref) |
static PsiMethod |
getChainedConstructor(PsiMethod constructor) |
static PsiCall |
getEnclosingConstructorCall(PsiJavaCodeReferenceElement ref) |
static PsiMethod |
getEnclosingMethod(PsiElement element) |
static PsiElement |
getLoopForLoopCondition(PsiExpression expression) |
static java.lang.String |
getNewInnerClassName(PsiClass aClass,
java.lang.String oldInnerClassName,
java.lang.String newName) |
static PsiElement |
getParentExpressionAnchorElement(PsiElement place) |
static PsiElement |
getParentStatement(PsiElement place,
boolean skipScopingStatements) |
static PsiClass |
getThisResolveClass(PsiReferenceExpression place) |
static PsiType |
getTypeByExpression(PsiExpression expr) |
static PsiType |
getTypeByExpressionWithExpectedType(PsiExpression expr) |
static PsiElement |
getVariableScope(PsiLocalVariable localVar) |
static boolean |
hasOnDemandStaticImport(PsiElement element,
PsiClass aClass) |
static java.util.List<RangeHighlighter> |
highlightAllOccurrences(Project project,
PsiElement[] occurrences,
Editor editor) |
static boolean |
inImportStatement(PsiReference ref,
PsiElement element) |
static boolean |
isAssignmentLHS(PsiElement element) |
static boolean |
isExpressionAnchorElement(PsiElement element) |
static boolean |
isInMovedElement(PsiElement element,
java.util.Set<? extends PsiMember> membersToMove) |
static boolean |
isInsideAnonymousOrLocal(PsiElement element,
PsiElement upTo) |
static boolean |
isInStaticContext(PsiElement element,
PsiClass aClass) |
static boolean |
isLoopOrIf(PsiElement element) |
static boolean |
isMethodUsage(PsiElement element) |
static boolean |
isModifiedInScope(PsiVariable variable,
PsiElement scope) |
static boolean |
isResolvableType(PsiType type)
Deprecated.
|
static boolean |
isSourceRoot(PsiDirectory directory) |
static void |
makeMethodAbstract(PsiClass targetClass,
PsiMethod method) |
static void |
makeMethodDefault(PsiMethod method) |
static PsiExpression |
outermostParenthesizedExpression(PsiExpression expression) |
static PsiStatement |
putStatementInLoopBody(PsiStatement declaration,
PsiElement container,
PsiElement finalAnchorStatement) |
static PsiStatement |
putStatementInLoopBody(PsiStatement declaration,
PsiElement container,
PsiElement finalAnchorStatement,
boolean replaceBody) |
static java.lang.String |
qNameToCreateInSourceRoot(PackageWrapper aPackage,
VirtualFile sourceRoot) |
static PsiJavaCodeReferenceElement |
removeFromReferenceList(PsiReferenceList refList,
PsiClass aClass)
removes a reference to the specified class from the reference list given
|
static void |
renameConflictingTypeParameters(PsiMember memberCopy,
PsiClass targetClass) |
static void |
renameVariableReferences(PsiVariable variable,
java.lang.String newName,
SearchScope scope) |
static void |
renameVariableReferences(PsiVariable variable,
java.lang.String newName,
SearchScope scope,
boolean ignoreAccessScope) |
static PsiElement |
replaceElementsWithMap(PsiElement replaceIn,
java.util.Map<PsiElement,PsiElement> elementsToReplace) |
static void |
replaceMovedMemberTypeParameters(PsiElement member,
java.lang.Iterable<? extends PsiTypeParameter> parametersIterable,
PsiSubstitutor substitutor,
PsiElementFactory factory) |
static PsiElement |
replaceOccurenceWithFieldRef(PsiExpression occurrence,
PsiField newField,
PsiClass destinationClass) |
static java.lang.String |
suggestNewOverriderName(java.lang.String oldOverriderName,
java.lang.String oldBaseName,
java.lang.String newBaseName) |
static java.lang.String |
suggestUniqueVariableName(java.lang.String baseName,
PsiElement place,
PsiField fieldToReplace) |
static <T> java.util.Set<T> |
transitiveClosure(RefactoringUtil.Graph<T> graph,
Condition<? super T> initialRelation)
Returns subset of
graph.getVertices() that is a transitive closure (by graph.getTargets() |
static PsiExpression |
unparenthesizeExpression(PsiExpression expression) |
static int |
verifySafeCopyExpression(PsiElement expr) |
static void |
visitImplicitSuperConstructorUsages(PsiClass subClass,
RefactoringUtil.ImplicitConstructorUsageVisitor implicitConstructorUsageVistor,
PsiClass superClass) |
public static final int EXPR_COPY_SAFE
public static final int EXPR_COPY_UNSAFE
public static final int EXPR_COPY_PROHIBITED
public static boolean isSourceRoot(PsiDirectory directory)
public static boolean isInStaticContext(PsiElement element, PsiClass aClass)
@Deprecated public static boolean isResolvableType(PsiType type)
PsiTypesUtil.hasUnresolvedComponents(PsiType)
public static PsiElement replaceOccurenceWithFieldRef(PsiExpression occurrence, PsiField newField, PsiClass destinationClass) throws IncorrectOperationException
IncorrectOperationException
public static java.lang.String suggestUniqueVariableName(java.lang.String baseName, PsiElement place, PsiField fieldToReplace)
public static java.lang.String suggestNewOverriderName(java.lang.String oldOverriderName, java.lang.String oldBaseName, java.lang.String newBaseName)
public static boolean hasOnDemandStaticImport(PsiElement element, PsiClass aClass)
public static PsiElement replaceElementsWithMap(PsiElement replaceIn, java.util.Map<PsiElement,PsiElement> elementsToReplace) throws IncorrectOperationException
IncorrectOperationException
public static PsiElement getVariableScope(PsiLocalVariable localVar)
public static PsiElement getParentStatement(PsiElement place, boolean skipScopingStatements)
public static PsiElement getParentExpressionAnchorElement(PsiElement place)
public static boolean isExpressionAnchorElement(PsiElement element)
public static PsiElement getLoopForLoopCondition(PsiExpression expression)
expression
- public static PsiClass getThisResolveClass(PsiReferenceExpression place)
public static PsiCall getEnclosingConstructorCall(PsiJavaCodeReferenceElement ref)
public static PsiMethod getEnclosingMethod(PsiElement element)
public static void renameVariableReferences(PsiVariable variable, java.lang.String newName, SearchScope scope) throws IncorrectOperationException
IncorrectOperationException
public static void renameVariableReferences(PsiVariable variable, java.lang.String newName, SearchScope scope, boolean ignoreAccessScope) throws IncorrectOperationException
IncorrectOperationException
public static boolean canBeDeclaredFinal(PsiVariable variable)
public static PsiJavaCodeReferenceElement removeFromReferenceList(PsiReferenceList refList, PsiClass aClass) throws IncorrectOperationException
IncorrectOperationException
public static PsiJavaCodeReferenceElement findReferenceToClass(PsiReferenceList refList, PsiClass aClass)
public static PsiType getTypeByExpressionWithExpectedType(PsiExpression expr)
public static PsiType getTypeByExpression(PsiExpression expr)
public static boolean isAssignmentLHS(PsiElement element)
public static PsiElement getAnchorElementForMultipleExpressions(PsiExpression [] occurrences, PsiElement scope)
public static boolean isMethodUsage(PsiElement element)
public static PsiExpressionList getArgumentListByMethodReference(PsiElement ref)
public static PsiCall getCallExpressionByMethodReference(PsiElement ref)
public static java.util.List<RangeHighlighter> highlightAllOccurrences(Project project, PsiElement[] occurrences, Editor editor)
public static java.lang.String createTempVar(PsiExpression expr, PsiElement context, boolean declareFinal) throws IncorrectOperationException
IncorrectOperationException
public static int verifySafeCopyExpression(PsiElement expr)
public static PsiExpression convertInitializerToNormalExpression(PsiExpression expression, PsiType forcedReturnType) throws IncorrectOperationException
IncorrectOperationException
public static PsiExpression createNewExpressionFromArrayInitializer(PsiArrayInitializerExpression initializer, PsiType forcedType) throws IncorrectOperationException
IncorrectOperationException
public static void makeMethodAbstract(PsiClass targetClass, PsiMethod method) throws IncorrectOperationException
IncorrectOperationException
public static void makeMethodDefault(PsiMethod method) throws IncorrectOperationException
IncorrectOperationException
public static boolean isInsideAnonymousOrLocal(PsiElement element, PsiElement upTo)
public static PsiExpression unparenthesizeExpression(PsiExpression expression)
public static PsiExpression outermostParenthesizedExpression(PsiExpression expression)
public static java.lang.String getNewInnerClassName(PsiClass aClass, java.lang.String oldInnerClassName, java.lang.String newName)
public static void visitImplicitSuperConstructorUsages(PsiClass subClass, RefactoringUtil.ImplicitConstructorUsageVisitor implicitConstructorUsageVistor, PsiClass superClass)
public static void replaceMovedMemberTypeParameters(PsiElement member, java.lang.Iterable<? extends PsiTypeParameter> parametersIterable, PsiSubstitutor substitutor, PsiElementFactory factory)
public static void renameConflictingTypeParameters(PsiMember memberCopy, PsiClass targetClass)
public static boolean isInMovedElement(PsiElement element, java.util.Set<? extends PsiMember> membersToMove)
public static boolean inImportStatement(PsiReference ref, PsiElement element)
public static PsiStatement putStatementInLoopBody(PsiStatement declaration, PsiElement container, PsiElement finalAnchorStatement) throws IncorrectOperationException
IncorrectOperationException
public static PsiStatement putStatementInLoopBody(PsiStatement declaration, PsiElement container, PsiElement finalAnchorStatement, boolean replaceBody) throws IncorrectOperationException
IncorrectOperationException
public static boolean isLoopOrIf(PsiElement element)
public static PsiCodeBlock expandExpressionLambdaToCodeBlock(PsiLambdaExpression lambdaExpression)
public static <T extends PsiExpression> T ensureCodeBlock(T expression)
PsiCodeBlock
(that is, it has a parent statement
which is located inside the code block). If not, tries to create a code block.
Note that the expression is not necessarily a child of PsiExpressionStatement
; it could be a subexpression,
PsiIfStatement
, etc.
This method works if ControlFlowUtils.canExtractStatement(PsiExpression)
returns true on the same expression.
expression
- an expression which should be located inside the code blocknull
if the expression cannot be surrounded with code block.public static java.lang.String checkEnumConstantInSwitchLabel(PsiExpression expr)
public static <T> java.util.Set<T> transitiveClosure(RefactoringUtil.Graph<T> graph, Condition<? super T> initialRelation)
graph.getVertices()
that is a transitive closure (by graph.getTargets())
of the following property: initialRelation.value() of vertex or graph.getTargets(vertex)
is true.
Note that graph.getTargets()
is not neccesrily a subset of graph.getVertex()
graph
- initialRelation
- public static boolean equivalentTypes(PsiType t1, PsiType t2, PsiManager manager)
public static java.util.List<PsiVariable> collectReferencedVariables(PsiElement scope)
public static boolean isModifiedInScope(PsiVariable variable, PsiElement scope)
public static void fixJavadocsForParams(PsiMethod method, java.util.Set<? extends PsiParameter> newParameters) throws IncorrectOperationException
IncorrectOperationException
public static void fixJavadocsForParams(PsiMethod method, java.util.Set<? extends PsiParameter> newParameters, Condition<? super Pair<PsiParameter,java.lang.String>> eqCondition) throws IncorrectOperationException
IncorrectOperationException
public static void fixJavadocsForParams(PsiMethod method, java.util.Set<? extends PsiParameter> newParameters, Condition<? super Pair<PsiParameter,java.lang.String>> eqCondition, Condition<? super java.lang.String> matchedToOldParam) throws IncorrectOperationException
IncorrectOperationException
public static void fixJavadocsForParams(PsiMethod method, PsiDocComment docComment, java.util.Set<? extends PsiParameter> newParameters, Condition<? super Pair<PsiParameter,java.lang.String>> eqCondition, Condition<? super java.lang.String> matchedToOldParam) throws IncorrectOperationException
IncorrectOperationException
public static PsiDirectory createPackageDirectoryInSourceRoot(PackageWrapper aPackage, VirtualFile sourceRoot) throws IncorrectOperationException
IncorrectOperationException
public static java.lang.String qNameToCreateInSourceRoot(PackageWrapper aPackage, VirtualFile sourceRoot) throws IncorrectOperationException
IncorrectOperationException
public static boolean canCreateInSourceRoot(java.lang.String sourceRootPackage, java.lang.String targetQName)
public static PsiDirectory findPackageDirectoryInSourceRoot(PackageWrapper aPackage, VirtualFile sourceRoot)
public static PsiTypeParameterList createTypeParameterListWithUsedTypeParameters(PsiElement... elements)
public static PsiTypeParameterList createTypeParameterListWithUsedTypeParameters(PsiTypeParameterList fromList, PsiElement... elements)
public static PsiTypeParameterList createTypeParameterListWithUsedTypeParameters(PsiTypeParameterList fromList, Condition<? super PsiTypeParameter> filter, PsiElement... elements)
public static void collectTypeParameters(java.util.Set<? super PsiTypeParameter> used, PsiElement element)
public static void collectTypeParameters(java.util.Set<? super PsiTypeParameter> used, PsiElement element, Condition<? super PsiTypeParameter> filter)