public abstract class JavaCodeStyleManager
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
DO_NOT_ADD_IMPORTS |
static int |
INCOMPLETE_CODE |
Constructor and Description |
---|
JavaCodeStyleManager() |
Modifier and Type | Method and Description |
---|---|
abstract boolean |
addImport(PsiJavaFile file,
PsiClass refClass) |
abstract int |
findEntryIndex(PsiImportStatementBase statement) |
abstract java.util.Collection<PsiImportStatementBase> |
findRedundantImports(PsiJavaFile file) |
static JavaCodeStyleManager |
getInstance(Project project) |
abstract java.lang.String |
getPrefixByVariableKind(VariableKind variableKind) |
abstract java.lang.String |
getSuffixByVariableKind(VariableKind variableKind) |
VariableKind |
getVariableKind(PsiVariable variable)
Returns the kind of the specified variable (local, parameter, field, static field or static final field).
|
boolean |
hasConflictingOnDemandImport(PsiJavaFile file,
PsiClass psiClass,
java.lang.String referenceName)
Single-static-import
import static classFQN.referenceName; shadows on-demand static imports, like described
JLS 6.4.1
A single-static-import declaration d in a compilation unit c of package p that imports a {member} named n
shadows the declaration of any static {member} named n imported by a static-import-on-demand declaration in c, throughout c. |
abstract void |
optimizeImports(PsiFile file)
Optimizes imports in the specified Java or JSP file.
|
abstract PsiImportList |
prepareOptimizeImportsResult(PsiJavaFile file)
Calculates the import list that would be substituted in the specified Java or JSP
file if an Optimize Imports operation was performed on it.
|
abstract java.lang.String |
propertyNameToVariableName(java.lang.String propertyName,
VariableKind variableKind)
Appends code style defined prefixes and/or suffixes for the specified variable kind
to the specified variable name.
|
abstract PsiElement |
qualifyClassReferences(PsiElement element)
Replaces all references to Java classes in the contents of the specified element,
except for references to classes in the same package or in implicitly imported packages,
with full-qualified references.
|
abstract void |
removeRedundantImports(PsiJavaFile file)
Removes unused import statements from the specified Java file.
|
abstract PsiElement |
shortenClassReferences(PsiElement element)
Replaces fully-qualified class names in the contents of the specified element with
non-qualified names and adds import statements as necessary.
|
abstract PsiElement |
shortenClassReferences(PsiElement element,
int flags) |
abstract void |
shortenClassReferences(PsiElement element,
int startOffset,
int endOffset)
Replaces fully-qualified class names in a part of contents of the specified element with
non-qualified names and adds import statements as necessary.
|
SuggestedNameInfo |
suggestCompiledParameterName(PsiType type)
Generates compiled parameter name for given type.
|
abstract SuggestedNameInfo |
suggestNames(java.util.Collection<java.lang.String> semanticNames,
VariableKind kind,
PsiType type) |
abstract java.util.Collection<java.lang.String> |
suggestSemanticNames(PsiExpression expression)
This method is not actually tied to Java Code Style.
|
abstract java.lang.String |
suggestUniqueVariableName(java.lang.String baseName,
PsiElement place,
boolean lookForward)
Suggests a unique name for the variable used at the specified location.
|
abstract java.lang.String |
suggestUniqueVariableName(java.lang.String baseName,
PsiElement place,
java.util.function.Predicate<? super PsiVariable> canBeReused)
Suggests a unique name for the variable used at the specified location looking forward with possible filtering.
|
SuggestedNameInfo |
suggestUniqueVariableName(SuggestedNameInfo baseNameInfo,
PsiElement place,
boolean lookForward)
Suggests a unique names for the variable used at the specified location.
|
abstract SuggestedNameInfo |
suggestUniqueVariableName(SuggestedNameInfo baseNameInfo,
PsiElement place,
boolean ignorePlaceName,
boolean lookForward)
Suggests a unique name for the variable used at the specified location.
|
SuggestedNameInfo |
suggestVariableName(VariableKind kind,
java.lang.String propertyName,
PsiExpression expr,
PsiType type) |
abstract SuggestedNameInfo |
suggestVariableName(VariableKind kind,
java.lang.String propertyName,
PsiExpression expr,
PsiType type,
boolean correctKeywords) |
abstract java.lang.String |
variableNameToPropertyName(java.lang.String name,
VariableKind variableKind)
Generates a stripped-down name (with no code style defined prefixes or suffixes, usable as
a property name) from the specified name of a variable of the specified kind.
|
public static final int DO_NOT_ADD_IMPORTS
public static final int INCOMPLETE_CODE
public static JavaCodeStyleManager getInstance(Project project)
public abstract boolean addImport(PsiJavaFile file, PsiClass refClass)
public abstract PsiElement shortenClassReferences(PsiElement element, int flags) throws IncorrectOperationException
IncorrectOperationException
public abstract java.lang.String getPrefixByVariableKind(VariableKind variableKind)
public abstract java.lang.String getSuffixByVariableKind(VariableKind variableKind)
public abstract int findEntryIndex(PsiImportStatementBase statement)
public abstract PsiElement shortenClassReferences(PsiElement element) throws IncorrectOperationException
element
- the element to shorten references in.IncorrectOperationException
- if the file to shorten references in is read-only.public abstract void shortenClassReferences(PsiElement element, int startOffset, int endOffset) throws IncorrectOperationException
element
- the element to shorten references in.startOffset
- the start offset in the element of the part where class references are shortened.endOffset
- the end offset in the element of the part where class references are shortened.IncorrectOperationException
- if the file to shorten references in is read-only.public abstract void optimizeImports(PsiFile file) throws IncorrectOperationException
file
- the file to optimize the imports in.IncorrectOperationException
- if the file is read-only.public abstract PsiImportList prepareOptimizeImportsResult(PsiJavaFile file)
file
- the file to calculate the import list for.null
when the file has no import list.public boolean hasConflictingOnDemandImport(PsiJavaFile file, PsiClass psiClass, java.lang.String referenceName)
import static classFQN.referenceName;
shadows on-demand static imports, like described
JLS 6.4.1
A single-static-import declaration d in a compilation unit c of package p that imports a {member} named n
shadows the declaration of any static {member} named n imported by a static-import-on-demand declaration in c, throughout c.public VariableKind getVariableKind(PsiVariable variable)
variable
- the variable to get the kind for.public SuggestedNameInfo suggestVariableName(VariableKind kind, java.lang.String propertyName, PsiExpression expr, PsiType type)
public SuggestedNameInfo suggestCompiledParameterName(PsiType type)
public abstract SuggestedNameInfo suggestVariableName(VariableKind kind, java.lang.String propertyName, PsiExpression expr, PsiType type, boolean correctKeywords)
public abstract java.lang.String variableNameToPropertyName(java.lang.String name, VariableKind variableKind)
name
- the name of the variable.variableKind
- the kind of the variable.public abstract java.lang.String propertyNameToVariableName(java.lang.String propertyName, VariableKind variableKind)
propertyName
- the base name of the variable.variableKind
- the kind of the variable.public abstract java.lang.String suggestUniqueVariableName(java.lang.String baseName, PsiElement place, boolean lookForward)
baseName
- the base name for the variable.place
- the location where the variable will be used.lookForward
- if true, the existing variables are searched in both directions; if false - only backwardpublic SuggestedNameInfo suggestUniqueVariableName(SuggestedNameInfo baseNameInfo, PsiElement place, boolean lookForward)
baseNameInfo
- the base name info for the variable.place
- the location where the variable will be used.lookForward
- if true, the existing variables are searched in both directions; if false - only backwardpublic abstract java.lang.String suggestUniqueVariableName(java.lang.String baseName, PsiElement place, java.util.function.Predicate<? super PsiVariable> canBeReused)
baseName
- the base name info for the variable.place
- the location where the variable will be used.canBeReused
- a predicate which returns true for variables which names still could be reused (e.g. a variable will be deleted
during the ongoing refactoring)public abstract SuggestedNameInfo suggestUniqueVariableName(SuggestedNameInfo baseNameInfo, PsiElement place, boolean ignorePlaceName, boolean lookForward)
baseNameInfo
- the base name info for the variable.place
- the location where the variable will be used.ignorePlaceName
- if true and place is PsiNamedElement, place.getName() would be still treated as unique namelookForward
- if true, the existing variables are searched in both directions; if false - only backwardpublic abstract PsiElement qualifyClassReferences(PsiElement element)
element
- the element to replace the references in.public abstract void removeRedundantImports(PsiJavaFile file) throws IncorrectOperationException
file
- the file to remove the import statements from.IncorrectOperationException
- if the operation fails for some reason (for example, the file is read-only).public abstract java.util.Collection<PsiImportStatementBase> findRedundantImports(PsiJavaFile file)
public abstract java.util.Collection<java.lang.String> suggestSemanticNames(PsiExpression expression)
Should be used with suggestNames(Collection, VariableKind, PsiType)
.
public abstract SuggestedNameInfo suggestNames(java.util.Collection<java.lang.String> semanticNames, VariableKind kind, PsiType type)