public final class VariableNaming
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
VariableNaming.IntroduceVariableScopeStatus
Enum to describe possible return values for method
canIntroduceVariableInScope(SourceElement, String). |
static class |
VariableNaming.VariableType
Enum of the various variable types that names can be generated for.
|
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
canIntroduceField(SourceElement sourceElement,
java.lang.String fieldName)
Verifies if a field can be introduced in the class that contains the
SourceElement. |
static boolean |
canIntroduceVariable(SourceElement scopeElement,
java.lang.String variableName)
Checks if a local variable (or method parameter or lambda parameter or catch parameter)
with the
variableName name can be introduced within the scope of scopeElement . |
static VariableNaming.IntroduceVariableScopeStatus |
canIntroduceVariableInScope(SourceElement scopeElement,
java.lang.String variableName)
Checks if a variable (or method parameter or lambda parameter or catch parameter)
with the
variableName name can be introduced within the scope of scopeElement. |
static void |
fillWithMembers(SourceElement element,
java.util.HashSet<java.lang.String> existingNames)
Fills the set with the names of existing field declarations visible from the sourceElement.
|
static void |
fillWithParentVariableDeclaration(SourceElement sourceElement,
java.util.HashSet<java.lang.String> existingNames)
Fills the set with the names of variables in all the parent
scopes of the sourceElement.
|
static java.lang.String |
format(VariableNaming.VariableType variableType,
java.lang.String name)
Format the given name for the code style of the given variableType.
|
static boolean |
hasShadowedFieldUses(SourceElement sourceVariable,
java.lang.String newVariableName)
Checks if the new name of a formal parameter or local variable
would shadow a field that has uses within the paramater's or local
variable's surrounding scope or any scope contained in that
surrounding scope.
|
static boolean |
isFieldShadowing(SourceElement element,
java.lang.String newVariableName)
Deprecated.
Use hasFieldShadowing(SourceElement, String) instead
|
static java.util.List<java.lang.String> |
suggestNames(SourceElement sourceElement,
java.lang.String typeName,
VariableNaming.VariableType variableType,
java.lang.String currentName)
Suggest names for the given source element.
|
static java.util.List<java.lang.String> |
suggestNamesFromCamelWord(java.lang.String shortName,
VariableNaming.VariableType variableType)
Suggest names based on the given word (in camel case).
|
public static java.lang.String format(VariableNaming.VariableType variableType, java.lang.String name)
variableType - A variableTypename - A namepublic static boolean canIntroduceVariable(SourceElement scopeElement, java.lang.String variableName)
variableName name can be introduced within the scope of scopeElement .
This method checks also for shadowed fields. If you want to allow field shadowing,
use canIntroduceVariableInScope(SourceElement,String) instead.scopeElement - The element whose scope should be checked, this is the scope
where the variable will be introduced.variableName - The name of the newly introduced variable.variableName does not already represent a variable within
the scope of scopeElement and the variable does not shadow a field.public static VariableNaming.IntroduceVariableScopeStatus canIntroduceVariableInScope(SourceElement scopeElement, java.lang.String variableName)
variableName name can be introduced within the scope of scopeElement.scopeElement - The element whose scope should be checked, this is the scope
where the variable will be introduced.variableName - The name of the newly introduced variable.public static java.util.List<java.lang.String> suggestNamesFromCamelWord(java.lang.String shortName,
VariableNaming.VariableType variableType)
shortName - A name which is assumed to be in camel casevariableType - If not null, a VariableType to use for formattingpublic static java.util.List<java.lang.String> suggestNames(SourceElement sourceElement, java.lang.String typeName, VariableNaming.VariableType variableType, java.lang.String currentName)
sourceElement - get suggestions for this elementtypeName - optional type name to get more suggestions forvariableType - If not null, a VariableType to use for formattingcurrentName - do not modify suggestions (e.g. add a" _2") if they clash with this namepublic static void fillWithMembers(SourceElement element, java.util.HashSet<java.lang.String> existingNames)
element - A SourceElementexistingNames - A HashSet for the names foundpublic static void fillWithParentVariableDeclaration(SourceElement sourceElement, java.util.HashSet<java.lang.String> existingNames)
sourceElement - A SourceElementexistingNames - A Set to fill with variable namespublic static java.lang.String canIntroduceField(SourceElement sourceElement, java.lang.String fieldName)
SourceElement.
It will verify that the field name is a valid field identifier, that it does not already exist, that
there is an enclosing class scope for the SourceElement and that it does
not override a variable in the enclosing class scope.sourceElement - A SourceElement with an enclosing class scopefieldName - The name of the new fieldpublic static boolean hasShadowedFieldUses(SourceElement sourceVariable, java.lang.String newVariableName)
Checks if the new name of a formal parameter or local variable would shadow a field that has uses within the paramater's or local variable's surrounding scope or any scope contained in that surrounding scope. Introduction of such a name that shadows a field could require qualifying the existing uses of the field.
Note that this checks for uses of a shadowed field. Use CanIntroduceVariableInScope to find if a variable name would shadow a field.
sourceVariable - A formal parameter or local variablenewVariableName - The new variable namenewVariableName would shadow a
field with usespublic static boolean isFieldShadowing(SourceElement element, java.lang.String newVariableName)