public final class PsiUtil extends PsiUtilCore
Modifier and Type | Class and Description |
---|---|
static interface |
PsiUtil.AccessLevel |
static interface |
PsiUtil.ApplicabilityChecker |
PsiUtilCore.NullPsiElement
Modifier and Type | Field and Description |
---|---|
static int |
ACCESS_LEVEL_PACKAGE_LOCAL |
static int |
ACCESS_LEVEL_PRIVATE |
static int |
ACCESS_LEVEL_PROTECTED |
static int |
ACCESS_LEVEL_PUBLIC |
static java.util.Comparator<PsiElement> |
BY_POSITION |
static Key<LanguageLevel> |
FILE_LANGUAGE_LEVEL_KEY |
static Key<java.lang.Boolean> |
VALID_VOID_TYPE_IN_CODE_FRAGMENT |
NULL_PSI_ELEMENT, NULL_PSI_FILE
Modifier and Type | Method and Description |
---|---|
static void |
addException(PsiMethod method,
PsiClass exceptionClass) |
static void |
addException(PsiMethod method,
java.lang.String exceptionFQName) |
static PsiElement |
addModuleStatement(PsiJavaModule module,
java.lang.String text) |
static boolean |
allMethodsHaveSameSignature(PsiMethod [] methods) |
static boolean |
canBeOverridden(PsiMethod method) |
static PsiType |
captureToplevelWildcards(PsiType type,
PsiElement context)
Applies capture conversion to the type in context
|
static void |
checkIsIdentifier(PsiManager manager,
java.lang.String text) |
static boolean |
checkName(PsiElement element,
java.lang.String name,
PsiElement context) |
static PsiType |
convertAnonymousToBaseType(PsiType type) |
static PsiExpression |
deparenthesizeExpression(PsiExpression expression) |
static void |
ensureValidType(PsiType type) |
static void |
ensureValidType(PsiType type,
java.lang.String customMessage) |
static boolean |
equalOnEquivalentClasses(PsiClassType thisClassType,
PsiClass aClass,
PsiClassType otherClassType,
PsiClass bClass)
Compares types with respect to type parameter bounds: e.g.
|
static PsiType |
extractIterableTypeParameter(PsiType psiType,
boolean eraseTypeParameter) |
static PsiMember |
findEnclosingConstructorOrInitializer(PsiElement expression) |
static PsiElement |
findModifierInList(PsiModifierList modifierList,
java.lang.String modifier) |
static PsiReturnStatement [] |
findReturnStatements(PsiCodeBlock body) |
static PsiReturnStatement [] |
findReturnStatements(PsiMethod method) |
static int |
getAccessLevel(PsiModifierList modifierList) |
static java.lang.String |
getAccessModifier(int accessLevel) |
static JavaResolveResult |
getAccessObjectClass(PsiExpression expression) |
static int |
getApplicabilityLevel(PsiMethod method,
PsiSubstitutor substitutorForMethod,
PsiExpressionList argList) |
static int |
getApplicabilityLevel(PsiMethod method,
PsiSubstitutor substitutorForMethod,
PsiType [] args,
LanguageLevel languageLevel) |
static int |
getApplicabilityLevel(PsiMethod method,
PsiSubstitutor substitutorForMethod,
PsiType [] args,
LanguageLevel languageLevel,
boolean allowUncheckedConversion,
boolean checkVarargs,
PsiUtil.ApplicabilityChecker function) |
static PsiElement |
getElementInclusiveRange(PsiElement scope,
TextRange range) |
static PsiElement |
getEnclosingStatement(PsiElement element) |
static PsiModifierListOwner |
getEnclosingStaticElement(PsiElement place,
PsiClass aClass) |
static VirtualFile |
getJarFile(PsiElement candidate) |
static LanguageLevel |
getLanguageLevel(Project project) |
static LanguageLevel |
getLanguageLevel(PsiElement element) |
static java.lang.String |
getMaximumModifierForMember(PsiClass aClass,
boolean allowPublicAbstract) |
static java.lang.String |
getMemberQualifiedName(PsiMember member) |
static java.lang.String |
getPackageName(PsiClass aClass) |
static java.util.List<PsiTypeElement> |
getParameterTypeElements(PsiParameter parameter) |
static PsiMethod [] |
getResourceCloserMethodsForType(PsiClassType resourceType) |
static java.util.List<PsiExpression> |
getSwitchResultExpressions(PsiSwitchExpression switchExpression) |
static PsiClass |
getTopLevelClass(PsiElement element) |
static PsiElement |
getTopLevelEnclosingCodeBlock(PsiElement element,
PsiElement scope) |
static PsiType |
getTypeByPsiElement(PsiElement element) |
static PsiElement |
getVariableCodeBlock(PsiVariable variable,
PsiElement context) |
static boolean |
hasDefaultConstructor(PsiClass clazz) |
static boolean |
hasDefaultConstructor(PsiClass clazz,
boolean allowProtected) |
static boolean |
hasDefaultConstructor(PsiClass clazz,
boolean allowProtected,
boolean allowPrivateAndPackagePrivate) |
static boolean |
isAbstractClass(PsiClass clazz) |
static boolean |
isAccessedForReading(PsiExpression expr) |
static boolean |
isAccessedForWriting(PsiExpression expr) |
static boolean |
isAccessible(Project project,
PsiMember member,
PsiElement place,
PsiClass accessObjectClass)
Checks that a *resolved* to
member reference at place is accessible: it's visible by visibility rules as well as
by module (java) rules. |
static boolean |
isAccessible(PsiMember member,
PsiElement place,
PsiClass accessObjectClass) |
static boolean |
isAccessibleFromPackage(PsiModifierListOwner element,
PsiPackage aPackage) |
static boolean |
isAnnotationMethod(PsiElement element) |
static boolean |
isApplicable(PsiMethod method,
PsiSubstitutor substitutorForMethod,
PsiExpression [] argList) |
static boolean |
isApplicable(PsiMethod method,
PsiSubstitutor substitutorForMethod,
PsiExpressionList argList) |
static boolean |
isArrayClass(PsiElement psiClass) |
static boolean |
isCatchParameter(PsiElement element) |
static boolean |
isCompileTimeConstant(PsiVariable field)
JLS 15.28
|
static boolean |
isCondition(PsiElement expr,
PsiElement parent) |
static boolean |
isConstantExpression(PsiExpression expression) |
static boolean |
isElseBlock(PsiElement element) |
static boolean |
isFromDefaultPackage(PsiClass aClass) |
static boolean |
isFromDefaultPackage(PsiElement element) |
static boolean |
isIgnoredName(java.lang.String name) |
static boolean |
isIncrementDecrementOperation(PsiElement element) |
static boolean |
isInnerClass(PsiClass aClass)
Checks whether given class is inner (as opposed to nested)
|
static boolean |
isInsideJavadocComment(PsiElement element) |
static boolean |
isInstantiatable(PsiClass clazz) |
static boolean |
isJavaToken(PsiElement element,
IElementType type) |
static boolean |
isJavaToken(PsiElement element,
TokenSet types) |
static boolean |
isJvmLocalVariable(PsiElement variable) |
static boolean |
isLanguageLevel10OrHigher(PsiElement element) |
static boolean |
isLanguageLevel11OrHigher(PsiElement element) |
static boolean |
isLanguageLevel5OrHigher(PsiElement element) |
static boolean |
isLanguageLevel6OrHigher(PsiElement element) |
static boolean |
isLanguageLevel7OrHigher(PsiElement element) |
static boolean |
isLanguageLevel8OrHigher(PsiElement element) |
static boolean |
isLanguageLevel9OrHigher(PsiElement element) |
static boolean |
isLocalClass(PsiClass psiClass) |
static boolean |
isLocalOrAnonymousClass(PsiClass psiClass) |
static boolean |
isMemberAccessibleAt(PsiMember member,
PsiElement place)
Checks that reference on
member inserted at place will be resolved and accessible |
static boolean |
isModuleFile(PsiFile file) |
static boolean |
isOnAssignmentLeftHand(PsiExpression expr) |
static boolean |
isPackageEmpty(PsiDirectory [] directories,
java.lang.String packageName) |
static boolean |
isRawSubstitutor(PsiTypeParameterListOwner owner,
PsiSubstitutor substitutor) |
static boolean |
isStatement(PsiElement element) |
static boolean |
isTryBlock(PsiElement element) |
static boolean |
isVariableNameUnique(java.lang.String name,
PsiElement place) |
static PsiElement [] |
mapElements(ResolveResult [] candidates) |
static PsiModifierListOwner |
preferCompiledElement(PsiModifierListOwner element) |
static void |
removeException(PsiMethod method,
java.lang.String exceptionClass) |
static PsiClass |
resolveClassInClassTypeOnly(PsiType type) |
static PsiClass |
resolveClassInType(PsiType type) |
static PsiClassType.ClassResolveResult |
resolveGenericsClassInType(PsiType type) |
static void |
setModifierProperty(PsiModifierListOwner owner,
java.lang.String property,
boolean value) |
static PsiExpression |
skipParenthesizedExprDown(PsiExpression expression) |
static PsiElement |
skipParenthesizedExprUp(PsiElement parent) |
static PsiType |
substituteTypeParameter(PsiType psiType,
PsiClass superClass,
int typeParamIndex,
boolean eraseTypeParameter) |
static PsiType |
substituteTypeParameter(PsiType psiType,
java.lang.String superClass,
int typeParamIndex,
boolean eraseTypeParameter) |
static java.lang.Iterable<PsiTypeParameter> |
typeParametersIterable(PsiTypeParameterListOwner owner) |
static java.util.Iterator<PsiTypeParameter> |
typeParametersIterator(PsiTypeParameterListOwner owner) |
compareElementsByPosition, ensureValid, findFileSystemItem, findLanguageFromElement, getDialect, getElementAtOffset, getElementType, getElementType, getLanguageAtOffset, getName, getNotAnyLanguage, getOriginalElement, getProjectInReadAction, getPsiFile, getQualifiedNameAfterRename, getTemplateLanguageFile, getVirtualFile, hasErrorElementChild, narrowLanguage, toPsiElementArray, toPsiFileArray, toPsiFiles
public static final int ACCESS_LEVEL_PUBLIC
public static final int ACCESS_LEVEL_PROTECTED
public static final int ACCESS_LEVEL_PACKAGE_LOCAL
public static final int ACCESS_LEVEL_PRIVATE
public static final Key<java.lang.Boolean> VALID_VOID_TYPE_IN_CODE_FRAGMENT
public static final Key<LanguageLevel> FILE_LANGUAGE_LEVEL_KEY
public static final java.util.Comparator<PsiElement> BY_POSITION
public static boolean isOnAssignmentLeftHand(PsiExpression expr)
public static boolean isAccessibleFromPackage(PsiModifierListOwner element, PsiPackage aPackage)
public static boolean isAccessedForWriting(PsiExpression expr)
public static boolean isAccessedForReading(PsiExpression expr)
public static boolean isAccessible(PsiMember member, PsiElement place, PsiClass accessObjectClass)
public static boolean isAccessible(Project project, PsiMember member, PsiElement place, PsiClass accessObjectClass)
member
reference at place
is accessible: it's visible by visibility rules as well as
by module (java) rules.
NOTE:
If there is no module (IDEA's) dependency from module withplace
on a module with member
,
then reference won't be resolved and this method will return true
.
Please use isMemberAccessibleAt(PsiMember, PsiElement)
to catch these cases as wellpublic static boolean isMemberAccessibleAt(PsiMember member, PsiElement place)
member
inserted at place
will be resolved and accessiblepublic static JavaResolveResult getAccessObjectClass(PsiExpression expression)
public static boolean isConstantExpression(PsiExpression expression)
public static void addException(PsiMethod method, java.lang.String exceptionFQName) throws IncorrectOperationException
IncorrectOperationException
public static void addException(PsiMethod method, PsiClass exceptionClass) throws IncorrectOperationException
IncorrectOperationException
public static void removeException(PsiMethod method, java.lang.String exceptionClass) throws IncorrectOperationException
IncorrectOperationException
public static boolean isVariableNameUnique(java.lang.String name, PsiElement place)
public static PsiElement getTopLevelEnclosingCodeBlock(PsiElement element, PsiElement scope)
public static boolean isLocalOrAnonymousClass(PsiClass psiClass)
public static boolean isLocalClass(PsiClass psiClass)
public static boolean isAbstractClass(PsiClass clazz)
public static PsiElement getVariableCodeBlock(PsiVariable variable, PsiElement context)
public static boolean isIncrementDecrementOperation(PsiElement element)
public static java.util.List<PsiExpression> getSwitchResultExpressions(PsiSwitchExpression switchExpression)
public static int getAccessLevel(PsiModifierList modifierList)
public static java.lang.String getAccessModifier(int accessLevel)
for JVM language analogue.
public static boolean isStatement(PsiElement element)
public static PsiElement getEnclosingStatement(PsiElement element)
public static PsiElement getElementInclusiveRange(PsiElement scope, TextRange range)
public static PsiClassType.ClassResolveResult resolveGenericsClassInType(PsiType type)
public static boolean isApplicable(PsiMethod method, PsiSubstitutor substitutorForMethod, PsiExpressionList argList)
public static boolean isApplicable(PsiMethod method, PsiSubstitutor substitutorForMethod, PsiExpression [] argList)
public static int getApplicabilityLevel(PsiMethod method, PsiSubstitutor substitutorForMethod, PsiExpressionList argList)
public static int getApplicabilityLevel(PsiMethod method, PsiSubstitutor substitutorForMethod, PsiType [] args, LanguageLevel languageLevel)
public static int getApplicabilityLevel(PsiMethod method, PsiSubstitutor substitutorForMethod, PsiType [] args, LanguageLevel languageLevel, boolean allowUncheckedConversion, boolean checkVarargs, PsiUtil.ApplicabilityChecker function)
public static boolean equalOnEquivalentClasses(PsiClassType thisClassType, PsiClass aClass, PsiClassType otherClassType, PsiClass bClass)
class Foo<T extends Number>{}
types Foo<?> and Foo<? extends Number>
would be equivalentpublic static boolean isCompileTimeConstant(PsiVariable field)
public static boolean allMethodsHaveSameSignature(PsiMethod [] methods)
public static PsiExpression deparenthesizeExpression(PsiExpression expression)
public static boolean isInnerClass(PsiClass aClass)
public static PsiElement findModifierInList(PsiModifierList modifierList, java.lang.String modifier)
public static PsiClass getTopLevelClass(PsiElement element)
public static java.lang.String getPackageName(PsiClass aClass)
public static PsiModifierListOwner getEnclosingStaticElement(PsiElement place, PsiClass aClass)
place
- place to start traversalaClass
- level to stop traversalpublic static PsiType getTypeByPsiElement(PsiElement element)
public static PsiType captureToplevelWildcards(PsiType type, PsiElement context)
public static boolean isInsideJavadocComment(PsiElement element)
public static java.util.List<PsiTypeElement> getParameterTypeElements(PsiParameter parameter)
public static void checkIsIdentifier(PsiManager manager, java.lang.String text) throws IncorrectOperationException
IncorrectOperationException
public static VirtualFile getJarFile(PsiElement candidate)
public static boolean isAnnotationMethod(PsiElement element)
public static java.lang.String getMaximumModifierForMember(PsiClass aClass, boolean allowPublicAbstract)
public static java.util.Iterator<PsiTypeParameter> typeParametersIterator(PsiTypeParameterListOwner owner)
public static java.lang.Iterable<PsiTypeParameter> typeParametersIterable(PsiTypeParameterListOwner owner)
public static boolean canBeOverridden(PsiMethod method)
public static PsiElement [] mapElements(ResolveResult [] candidates)
public static PsiMember findEnclosingConstructorOrInitializer(PsiElement expression)
public static boolean checkName(PsiElement element, java.lang.String name, PsiElement context)
public static boolean isRawSubstitutor(PsiTypeParameterListOwner owner, PsiSubstitutor substitutor)
public static boolean isLanguageLevel5OrHigher(PsiElement element)
public static boolean isLanguageLevel6OrHigher(PsiElement element)
public static boolean isLanguageLevel7OrHigher(PsiElement element)
public static boolean isLanguageLevel8OrHigher(PsiElement element)
public static boolean isLanguageLevel9OrHigher(PsiElement element)
public static boolean isLanguageLevel10OrHigher(PsiElement element)
public static boolean isLanguageLevel11OrHigher(PsiElement element)
public static LanguageLevel getLanguageLevel(PsiElement element)
public static LanguageLevel getLanguageLevel(Project project)
public static boolean isInstantiatable(PsiClass clazz)
public static boolean hasDefaultConstructor(PsiClass clazz)
public static boolean hasDefaultConstructor(PsiClass clazz, boolean allowProtected)
public static boolean hasDefaultConstructor(PsiClass clazz, boolean allowProtected, boolean allowPrivateAndPackagePrivate)
public static PsiType extractIterableTypeParameter(PsiType psiType, boolean eraseTypeParameter)
public static PsiType substituteTypeParameter(PsiType psiType, java.lang.String superClass, int typeParamIndex, boolean eraseTypeParameter)
public static PsiType substituteTypeParameter(PsiType psiType, PsiClass superClass, int typeParamIndex, boolean eraseTypeParameter)
public static void setModifierProperty(PsiModifierListOwner owner, java.lang.String property, boolean value)
public static boolean isTryBlock(PsiElement element)
public static boolean isElseBlock(PsiElement element)
public static boolean isJavaToken(PsiElement element, IElementType type)
public static boolean isJavaToken(PsiElement element, TokenSet types)
public static boolean isCatchParameter(PsiElement element)
public static boolean isIgnoredName(java.lang.String name)
public static PsiMethod [] getResourceCloserMethodsForType(PsiClassType resourceType)
public static PsiExpression skipParenthesizedExprDown(PsiExpression expression)
public static PsiElement skipParenthesizedExprUp(PsiElement parent)
public static void ensureValidType(PsiType type)
public static void ensureValidType(PsiType type, java.lang.String customMessage)
public static java.lang.String getMemberQualifiedName(PsiMember member)
public static boolean isFromDefaultPackage(PsiClass aClass)
public static boolean isFromDefaultPackage(PsiElement element)
public static boolean isCondition(PsiElement expr, PsiElement parent)
public static PsiReturnStatement [] findReturnStatements(PsiMethod method)
public static PsiReturnStatement [] findReturnStatements(PsiCodeBlock body)
public static boolean isModuleFile(PsiFile file)
public static boolean isPackageEmpty(PsiDirectory [] directories, java.lang.String packageName)
public static PsiModifierListOwner preferCompiledElement(PsiModifierListOwner element)
public static PsiElement addModuleStatement(PsiJavaModule module, java.lang.String text)
public static boolean isArrayClass(PsiElement psiClass)
public static boolean isJvmLocalVariable(PsiElement variable)
variable
- variable to test