public abstract class CLikeLanguageFeatureParserBase extends java.lang.Object implements ILanguageFeatureParser
Modifier and Type | Field and Description |
---|---|
static java.util.EnumSet<ETokenType> |
CONDITIONAL_OPERATOR_TYPES
Conditional operator types.
|
protected ETokenType |
packageSeparator
The token type to separate packages/namespaces/scopes.
|
protected java.lang.String |
packageSeparatorText
The text of the package separator token.
|
static java.util.EnumSet<ETokenType> |
POINTER_TYPES
Token types that are used to declare a pointer or reference (C++).
|
protected java.util.EnumSet<ETokenType> |
primitiveTypeTokens
All token types that can be used to declare a primitive type.
|
protected static java.lang.String[] |
TYPE_MODIFICATIONS
All strings that modify a type name.
|
protected java.util.EnumSet<ETokenType> |
typeTokens
All token types that can be used to declare a type.
|
protected CLikeVariableUseExtractor |
useExtractor
The variable use extractor to find uses of names (e.g.
|
protected java.util.EnumSet<ETokenType> |
validIdentifiers
All token types that can be used as valid identifiers.
|
protected ETokenType |
variableSplitType
The type of variable split of splitVariableTokens method
|
Modifier | Constructor and Description |
---|---|
protected |
CLikeLanguageFeatureParserBase(ELanguage language,
java.util.EnumSet<ETokenType> validIdentifiers,
java.util.EnumSet<ETokenType> primitiveTypeTokens,
java.util.EnumSet<ETokenType> additionalTypeTokens,
ETokenType packageSeparator,
java.lang.String packageSeparatorText,
CLikeVariableUseExtractor useExtractor)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected int |
collectTokenFromTypePart(java.util.List<IToken> tokens,
int endIndex,
TypeNameTokenCollection typeName)
Collects a type name token from a part of a type name within a variable
declaration.
|
protected int |
collectTokensFromModifiers(java.util.List<IToken> tokens,
int endIndex,
java.util.List<IToken> modifierTokens)
Collects modifier tokens from modifier specifications in front of the type
name within a variable declaration.
|
protected int |
collectTokensFromPointers(java.util.List<IToken> tokens,
int endIndex,
java.util.List<IToken> modifierTokens,
TypeNameTokenCollection typeName)
Collects modifier tokens from pointer or reference declarations (mainly const
in C++).
|
protected int |
collectTokensFromPrimitiveType(java.util.List<IToken> tokens,
int endIndex,
TypeNameTokenCollection typeName)
Collects type name tokens from a primitive type within a variable
declaration.
|
protected int |
collectTokensFromType(java.util.List<IToken> tokens,
int endIndex,
TypeNameTokenCollection typeName)
Collects type name tokens from a type name within a variable declaration.
|
protected int |
collectTokensFromTypeAndModifications(java.util.List<IToken> tokens,
int endIndex,
java.util.List<IToken> modifierTokens,
TypeNameTokenCollection typeName)
Collects modifier and type tokens from type modifications like pointer or
reference declarations and from the type type name tokens itself.
|
java.util.List<IToken> |
extractConditionTokens(ShallowEntity statement)
Extracts all tokens that are part of a condition from a statement.
|
protected java.util.List<IToken> |
extractParameterTokens(java.util.List<IToken> tokensAfterMethodName)
Returns a list of parameter tokens for the given tokens after the method
name.
|
protected java.util.List<IToken> |
filterGenericTokens(java.util.List<IToken> genericTokens)
Filters the generic tokens before converting them to their token texts.
|
java.lang.String |
getBaseTypeName(java.lang.String typeName)
Returns the base name of the given type name.
|
java.util.List<java.lang.String> |
getGenericNamesForMethod(ShallowEntity method)
Returns a list of all generic names for the given method.
|
java.util.List<java.lang.String> |
getGenericNamesForType(ShallowEntity type)
Returns a list of all generic names for the given type.
|
java.util.List<java.lang.String> |
getGenericTypeNames(java.util.List<IToken> tokens)
Extracts type names that are used in generics from the given tokens.
|
java.util.List<java.lang.String> |
getImportedNames(java.util.List<ShallowEntity> importEntities)
Returns a list of names that are imported by the given "import" entities.
|
abstract java.lang.String |
getImportName(ShallowEntity entity)
Returns the imported name of the given import shallow entity.
|
ELanguage |
getLanguage()
Returns that language the feature parsers are implemented for.
|
protected int |
getMethodOpeningParenthesisIndex(java.util.List<IToken> methodTokens)
Returns the index of the opening parenthesis of a method from the given
tokens.
|
Pair<java.util.List<IToken>,java.lang.String> |
getModifiersAndTypeFromTokens(java.util.List<IToken> tokens)
Extracts a list of modifiers and a type name from the given token list.
|
java.util.List<IToken> |
getParameterTokens(ShallowEntity method)
Returns a list of parameter tokens for the given method.
|
java.util.List<java.util.Optional<java.lang.String>> |
getParameterTypeNames(ShallowEntity method)
Returns all parameter type names of the given method.
|
java.lang.String |
getPlainTypeName(java.lang.String typeName)
Removes all pointer, array and reference declarations from the given
typename.
|
java.lang.String |
getReturnType(ShallowEntity method)
Returns the type name of the return type of the given method.
|
java.util.List<java.util.List<IToken>> |
getSplitParameterTokens(ShallowEntity method)
Returns a list of lists of tokens that represent the parameters of the given
method.
|
java.lang.String |
getTypeNameFromCatchTokens(java.util.List<IToken> catchTokens)
Returns the type name of an exception within a catch statement or null if
none is found.
|
protected int |
getTypeNameStartIndex(java.util.List<IToken> tokens,
int lastTypeTokenIndex)
Return the start index of the type name that ends at the given index within
the given token list.
|
IToken |
getVariableNameFromCatchTokens(java.util.List<IToken> catchTokens)
Returns the variable name of an exception within a catch statement or null if
the exception is not named.
|
IToken |
getVariableNameFromTokens(java.util.List<IToken> tokens)
Returns the variable name token from the given token list or
null if none is found. |
java.util.List<IToken> |
getVariableNamesFromTokens(java.util.List<IToken> variableTokens)
Returns all variable name tokens from the given variable tokens.
|
java.util.List<java.lang.Integer> |
getVariableReadsFromTokens(java.util.List<IToken> tokens,
java.lang.String variableName,
boolean isField,
boolean isShadowed)
Returns all token indices from the given tokens that read the value of the
variable with the given name.
|
java.util.List<IToken> |
getVariableTokensFromForLikeTokens(java.util.List<IToken> forLikeTokens,
ETokenType endToken)
Returns all variable declaration tokens within a for-like statement.
|
java.lang.String |
getVariableTypeFromTokens(java.util.List<IToken> tokens)
Returns the type name of a variable from the declaring tokens.
|
java.util.List<java.lang.Integer> |
getVariableUsesFromTokens(java.util.List<IToken> tokens,
java.lang.String variableName,
boolean isField,
boolean isShadowed)
Returns all token indices from the given tokens that are uses of the variable
with the given name.
|
java.util.List<java.lang.Integer> |
getVariableWritesFromTokens(java.util.List<IToken> tokens,
java.lang.String variableName,
boolean isField,
boolean isShadowed)
Returns all token indices from the given tokens that change the value of the
variable with the given name.
|
boolean |
hasOnlyStaticMembers(ShallowEntity clazz)
Returns whether the given entity only has static members.
|
boolean |
hasVariableLengthArgumentList(java.util.List<IToken> tokens)
Returns whether the given tokens represent a variable length argument.
|
boolean |
hasVoidReturnType(ShallowEntity method)
Returns whether the given method has a void return type.
|
abstract boolean |
isImport(ShallowEntity entity)
Returns whether the given entity is an import.
|
boolean |
isPrimitiveTypeToken(IToken token)
Returns whether the given token is a primitive type token.
|
boolean |
isStatic(ShallowEntity entity)
Returns whether the given entity is static.
|
boolean |
isTypeToken(IToken token)
Returns whether the given token is a type token.
|
boolean |
isVariableDeclaration(java.util.List<IToken> variableTokens)
Returns whether the given tokens are a variable declaration.
|
boolean |
matchesFullQualifiedTypeName(java.lang.String typeName,
java.util.Collection<java.lang.String> importedNamespaces,
java.lang.String fullQualifiedTypeName)
Returns whether the given type name matches the given full qualified type
name considering the given imported namespaces.
|
protected int |
reverseSkipToType(java.util.List<IToken> tokens)
Skips from the end of the given token list (that represents a variable
definition) to the token after the last token that specifies the variables
type.
|
int |
skipGeneric(java.util.List<IToken> tokens,
int startIndex)
Skips a generic or template declaration in the given token list that begins
at the given start index.
|
int |
skipGenericReverse(java.util.List<IToken> tokens,
int startIndex)
Skips a generic parameter (nested < and >) in reverse direction and
returns the index of the first opening < token.
|
java.util.List<java.util.List<IToken>> |
splitVariableTokens(java.util.List<IToken> variableTokens)
Splits the given variable declaration tokens at commas regarding nesting
between parenthesis, brackets, braces and angle brackets.
|
public static final java.util.EnumSet<ETokenType> CONDITIONAL_OPERATOR_TYPES
public static final java.util.EnumSet<ETokenType> POINTER_TYPES
protected static final java.lang.String[] TYPE_MODIFICATIONS
protected final java.util.EnumSet<ETokenType> validIdentifiers
protected final java.util.EnumSet<ETokenType> primitiveTypeTokens
protected final java.util.EnumSet<ETokenType> typeTokens
protected final CLikeVariableUseExtractor useExtractor
protected final ETokenType packageSeparator
protected final java.lang.String packageSeparatorText
protected ETokenType variableSplitType
protected CLikeLanguageFeatureParserBase(ELanguage language, java.util.EnumSet<ETokenType> validIdentifiers, java.util.EnumSet<ETokenType> primitiveTypeTokens, java.util.EnumSet<ETokenType> additionalTypeTokens, ETokenType packageSeparator, java.lang.String packageSeparatorText, CLikeVariableUseExtractor useExtractor)
language
- the concrete language of this parservalidIdentifiers
- all token types that can be used as identifiersprimitiveTypeTokens
- all token types that can be part of a primitive typeadditionalTypeTokens
- token types besides primitive ones that can be used to specify a
typepackageSeparator
- the token that is used to separate packages/scopes/namespacespackageSeparatorText
- the string representation of the package separatorpublic boolean isVariableDeclaration(java.util.List<IToken> variableTokens)
public boolean matchesFullQualifiedTypeName(java.lang.String typeName, java.util.Collection<java.lang.String> importedNamespaces, java.lang.String fullQualifiedTypeName)
public java.util.List<IToken> extractConditionTokens(ShallowEntity statement)
public boolean isStatic(ShallowEntity entity)
public boolean hasOnlyStaticMembers(ShallowEntity clazz)
false
is returned.public java.util.List<java.lang.String> getGenericNamesForType(ShallowEntity type)
public java.util.List<java.lang.String> getGenericNamesForMethod(ShallowEntity method)
protected java.util.List<IToken> filterGenericTokens(java.util.List<IToken> genericTokens)
public boolean hasVoidReturnType(ShallowEntity method)
public java.lang.String getReturnType(ShallowEntity method)
protected int getMethodOpeningParenthesisIndex(java.util.List<IToken> methodTokens)
public java.util.List<IToken> getParameterTokens(ShallowEntity method)
protected java.util.List<IToken> extractParameterTokens(java.util.List<IToken> tokensAfterMethodName)
public Pair<java.util.List<IToken>,java.lang.String> getModifiersAndTypeFromTokens(java.util.List<IToken> tokens)
protected int collectTokensFromTypeAndModifications(java.util.List<IToken> tokens, int endIndex, java.util.List<IToken> modifierTokens, TypeNameTokenCollection typeName)
protected int collectTokensFromPointers(java.util.List<IToken> tokens, int endIndex, java.util.List<IToken> modifierTokens, TypeNameTokenCollection typeName)
protected int collectTokensFromType(java.util.List<IToken> tokens, int endIndex, TypeNameTokenCollection typeName)
protected int collectTokensFromPrimitiveType(java.util.List<IToken> tokens, int endIndex, TypeNameTokenCollection typeName)
primitiveTypeTokens
like "unsigned long long" in C++.protected int collectTokenFromTypePart(java.util.List<IToken> tokens, int endIndex, TypeNameTokenCollection typeName)
protected int collectTokensFromModifiers(java.util.List<IToken> tokens, int endIndex, java.util.List<IToken> modifierTokens)
public boolean isTypeToken(IToken token)
public boolean isPrimitiveTypeToken(IToken token)
protected int reverseSkipToType(java.util.List<IToken> tokens)
public int skipGeneric(java.util.List<IToken> tokens, int startIndex)
ETokenType.LT
. The index of the matching closing token is returned.public int skipGenericReverse(java.util.List<IToken> tokens, int startIndex)
ETokenType.GT
. The index of the matching
opening token is returned.public java.util.List<java.util.List<IToken>> getSplitParameterTokens(ShallowEntity method)
public java.util.List<java.util.Optional<java.lang.String>> getParameterTypeNames(ShallowEntity method)
protected int getTypeNameStartIndex(java.util.List<IToken> tokens, int lastTypeTokenIndex)
public java.util.List<java.lang.String> getGenericTypeNames(java.util.List<IToken> tokens)
public java.util.List<java.util.List<IToken>> splitVariableTokens(java.util.List<IToken> variableTokens)
public java.util.List<IToken> getVariableNamesFromTokens(java.util.List<IToken> variableTokens)
public IToken getVariableNameFromTokens(java.util.List<IToken> tokens)
null
if none is found. The list of tokens must have the pattern
of a variable declaration.public java.lang.String getVariableTypeFromTokens(java.util.List<IToken> tokens)
public IToken getVariableNameFromCatchTokens(java.util.List<IToken> catchTokens)
public java.lang.String getTypeNameFromCatchTokens(java.util.List<IToken> catchTokens)
public java.util.List<IToken> getVariableTokensFromForLikeTokens(java.util.List<IToken> forLikeTokens, ETokenType endToken)
public java.util.List<java.lang.Integer> getVariableUsesFromTokens(java.util.List<IToken> tokens, java.lang.String variableName, boolean isField, boolean isShadowed)
validIdentifiers
. Those
token types are set from the subclass for a concrete language. Internally a
CLikeVariableUseExtractor
is used.isField
- if the variable is a fieldisShadowed
- if the variable is a field and shadowed by another local variablepublic java.util.List<java.lang.Integer> getVariableReadsFromTokens(java.util.List<IToken> tokens, java.lang.String variableName, boolean isField, boolean isShadowed)
isField
- if the variable is a fieldisShadowed
- if the variable is a field and shadowed by another local variablepublic java.util.List<java.lang.Integer> getVariableWritesFromTokens(java.util.List<IToken> tokens, java.lang.String variableName, boolean isField, boolean isShadowed)
isField
- if the variable is a fieldisShadowed
- if the variable is a field and shadowed by another local variablepublic abstract boolean isImport(ShallowEntity entity)
public abstract java.lang.String getImportName(ShallowEntity entity)
public boolean hasVariableLengthArgumentList(java.util.List<IToken> tokens)
public java.util.List<java.lang.String> getImportedNames(java.util.List<ShallowEntity> importEntities)
public java.lang.String getPlainTypeName(java.lang.String typeName)
public java.lang.String getBaseTypeName(java.lang.String typeName)
public ELanguage getLanguage()
getLanguage
in interface ILanguageFeatureParser