public class CoreJavaCodeStyleManager extends JavaCodeStyleManager
DO_NOT_ADD_IMPORTS, INCOMPLETE_CODE
Constructor and Description |
---|
CoreJavaCodeStyleManager() |
Modifier and Type | Method and Description |
---|---|
boolean |
addImport(PsiJavaFile file,
PsiClass refClass) |
int |
findEntryIndex(PsiImportStatementBase statement) |
java.util.Collection<PsiImportStatementBase> |
findRedundantImports(PsiJavaFile file) |
java.lang.String |
getPrefixByVariableKind(VariableKind variableKind) |
java.lang.String |
getSuffixByVariableKind(VariableKind variableKind) |
void |
optimizeImports(PsiFile file)
Optimizes imports in the specified Java or JSP file.
|
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.
|
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.
|
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.
|
void |
removeRedundantImports(PsiJavaFile file)
Removes unused import statements from the specified Java file.
|
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.
|
PsiElement |
shortenClassReferences(PsiElement element,
int flags) |
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 |
suggestNames(java.util.Collection<java.lang.String> semanticNames,
VariableKind kind,
PsiType type) |
java.util.Collection<java.lang.String> |
suggestSemanticNames(PsiExpression expression)
This method is not actually tied to Java Code Style.
|
java.lang.String |
suggestUniqueVariableName(java.lang.String baseName,
PsiElement place,
boolean lookForward)
Suggests a unique name for the variable used at the specified location.
|
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 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,
boolean correctKeywords) |
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.
|
getInstance, getVariableKind, hasConflictingOnDemandImport, suggestCompiledParameterName, suggestUniqueVariableName, suggestVariableName
public boolean addImport(PsiJavaFile file, PsiClass refClass)
addImport
in class JavaCodeStyleManager
public PsiElement shortenClassReferences(PsiElement element, int flags) throws IncorrectOperationException
shortenClassReferences
in class JavaCodeStyleManager
IncorrectOperationException
public java.lang.String getPrefixByVariableKind(VariableKind variableKind)
getPrefixByVariableKind
in class JavaCodeStyleManager
public java.lang.String getSuffixByVariableKind(VariableKind variableKind)
getSuffixByVariableKind
in class JavaCodeStyleManager
public int findEntryIndex(PsiImportStatementBase statement)
findEntryIndex
in class JavaCodeStyleManager
public PsiElement shortenClassReferences(PsiElement element) throws IncorrectOperationException
JavaCodeStyleManager
shortenClassReferences
in class JavaCodeStyleManager
element
- the element to shorten references in.IncorrectOperationException
- if the file to shorten references in is read-only.public void shortenClassReferences(PsiElement element, int startOffset, int endOffset) throws IncorrectOperationException
JavaCodeStyleManager
shortenClassReferences
in class JavaCodeStyleManager
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 void optimizeImports(PsiFile file) throws IncorrectOperationException
JavaCodeStyleManager
optimizeImports
in class JavaCodeStyleManager
file
- the file to optimize the imports in.IncorrectOperationException
- if the file is read-only.public PsiImportList prepareOptimizeImportsResult(PsiJavaFile file)
JavaCodeStyleManager
prepareOptimizeImportsResult
in class JavaCodeStyleManager
file
- the file to calculate the import list for.null
when the file has no import list.public SuggestedNameInfo suggestVariableName(VariableKind kind, java.lang.String propertyName, PsiExpression expr, PsiType type, boolean correctKeywords)
suggestVariableName
in class JavaCodeStyleManager
public java.lang.String variableNameToPropertyName(java.lang.String name, VariableKind variableKind)
JavaCodeStyleManager
variableNameToPropertyName
in class JavaCodeStyleManager
name
- the name of the variable.variableKind
- the kind of the variable.public java.lang.String propertyNameToVariableName(java.lang.String propertyName, VariableKind variableKind)
JavaCodeStyleManager
propertyNameToVariableName
in class JavaCodeStyleManager
propertyName
- the base name of the variable.variableKind
- the kind of the variable.public java.lang.String suggestUniqueVariableName(java.lang.String baseName, PsiElement place, boolean lookForward)
JavaCodeStyleManager
suggestUniqueVariableName
in class JavaCodeStyleManager
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 java.lang.String suggestUniqueVariableName(java.lang.String baseName, PsiElement place, java.util.function.Predicate<? super PsiVariable> canBeReused)
JavaCodeStyleManager
suggestUniqueVariableName
in class JavaCodeStyleManager
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 SuggestedNameInfo suggestUniqueVariableName(SuggestedNameInfo baseNameInfo, PsiElement place, boolean ignorePlaceName, boolean lookForward)
JavaCodeStyleManager
suggestUniqueVariableName
in class JavaCodeStyleManager
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 PsiElement qualifyClassReferences(PsiElement element)
JavaCodeStyleManager
qualifyClassReferences
in class JavaCodeStyleManager
element
- the element to replace the references in.public void removeRedundantImports(PsiJavaFile file) throws IncorrectOperationException
JavaCodeStyleManager
removeRedundantImports
in class JavaCodeStyleManager
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 java.util.Collection<PsiImportStatementBase> findRedundantImports(PsiJavaFile file)
findRedundantImports
in class JavaCodeStyleManager
public java.util.Collection<java.lang.String> suggestSemanticNames(PsiExpression expression)
JavaCodeStyleManager
Should be used with JavaCodeStyleManager.suggestNames(Collection, VariableKind, PsiType)
.
suggestSemanticNames
in class JavaCodeStyleManager
public SuggestedNameInfo suggestNames(java.util.Collection<java.lang.String> semanticNames, VariableKind kind, PsiType type)
suggestNames
in class JavaCodeStyleManager