public class ShallowParsingUtils extends java.lang.Object
ShallowEntitys.| Constructor and Description |
|---|
ShallowParsingUtils() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
containsLoopReferenceWithoutLoop(java.util.List<ShallowEntity> block)
Checks if
continue or break are contained in a
for or while loop in the given block. |
static java.util.List<IToken> |
extractParameterNameTokens(ShallowEntity entity)
Returns the tokens of a method entity that correspond to parameter names.
|
static java.util.List<IToken> |
extractVariableNameTokens(java.util.List<IToken> tokens)
Returns the tokens corresponding to variable names.
|
static java.util.List<IToken> |
extractVariablesDeclaredInFor(ShallowEntity entity)
Returns the list of tokens corresponding to the names of variables newly
declared within a for loop.
|
static java.util.List<java.lang.String> |
getClassAttributes(java.util.List<ShallowEntity> classEntities)
Extracts from a given token (that represents a file) all the attributes
(variables) that are declared directly in a type (class) and not within a
method etc.
|
static java.util.List<ShallowEntity> |
getClassEntities(java.util.List<ShallowEntity> shallowEntities,
int startLine,
int endLine)
Obtain all classes (including anonymous classes) that contain directly or
indirectly the method corresponding to the given line numbers.
|
static java.util.List<ShallowEntity> |
getCompleteStatement(ShallowEntity shallowEntity)
Returns for a given entity that contains an
if or
try block a list of ShallowEntities that
represents the corresponding else if or catch and
else or finally block. |
static ShallowEntity |
getFirstEntityAfter(ShallowEntity candidate)
Returns the entity which is directly after the given
ShallowEntity. |
static ELanguage |
getLanguage(ShallowEntity entity)
Determines the language of the given entity or
null if it cannot
be determined |
static ShallowEntity |
getLastEntityBefore(ShallowEntity candidate)
Returns the entity which is directly before the given
ShallowEntity. |
static java.util.Optional<ShallowEntity> |
getMethod(java.util.List<ShallowEntity> shallowEntities,
LineBasedRegion region)
Get a method by its region.
|
static java.util.Optional<ShallowEntity> |
getMethod(java.util.List<ShallowEntity> shallowEntities,
OffsetBasedRegion region)
Get a method by its region.
|
static java.util.Optional<ShallowEntity> |
getMethod(java.util.List<ShallowEntity> shallowEntities,
java.util.function.Predicate<ShallowEntity> filter)
Get a method using a predicate.
|
static java.util.List<ShallowEntity> |
getMethods(java.util.List<ShallowEntity> shallowEntities)
Obtain all methods.
|
static int |
getNestingArea(java.util.List<ShallowEntity> shallowEntities)
Returns the nesting area of a list of
ShallowEntities. |
static int |
getNestingDepth(java.util.List<ShallowEntity> block)
Returns the maximal nesting depth of the given block.
|
static int |
getNestingDepth(ShallowEntity shallowEntity)
Returns the maximal nesting depth of the given entity.
|
static int |
getNumberOfBlankLinesOrCommentsAfter(ShallowEntity candidate)
Returns the number of blank or commented lines after the given
ShallowEntity. |
static int |
getNumberOfBlankLinesOrCommentsBefore(ShallowEntity candidate)
Returns the number of blank or commented lines before the given
ShallowEntity. |
static java.util.List<java.lang.String> |
getReturnParameters(java.util.List<ShallowEntity> block)
Returns a list of variable names (identifiers) that must be returned from the
specified block if it is extracted into a new method
|
static java.util.List<ShallowEntity> |
getStatements(ShallowEntity entity)
Returns all statements in the given entity
|
static boolean |
isCppConstructor(ELanguage language,
ShallowEntity entity)
Checks whether the given method is a C++ constructor.
|
static boolean |
isGlobalVariable(ShallowEntity entity)
Returns whether the entity is a global variable.
|
static boolean |
isLambdaMethod(ShallowEntity entity) |
static boolean |
isLocalVariable(ShallowEntity entity)
Returns whether the entity is a local variable.
|
static boolean |
isLoop(ShallowEntity entity)
Checks if the entity is a loop (for, foreach, while).
|
static boolean |
isSubpartOfBranchingStatement(ShallowEntity entity)
Checks if the given entity is part of a branching statement but not the first
option of the branches.
|
static java.util.List<ShallowEntity> |
listNestedStatements(java.util.Collection<ShallowEntity> entities)
Lists all nested statements (i.e.
|
static java.util.List<ShallowEntity> |
listPrimitiveStatements(java.util.Collection<ShallowEntity> entities)
Lists all primitive statements (i.e.
|
public ShallowParsingUtils()
public static java.util.List<ShallowEntity> listPrimitiveStatements(java.util.Collection<ShallowEntity> entities)
public static java.util.List<ShallowEntity> listNestedStatements(java.util.Collection<ShallowEntity> entities)
public static java.util.List<IToken> extractParameterNameTokens(ShallowEntity entity)
public static java.util.List<IToken> extractVariableNameTokens(java.util.List<IToken> tokens)
public static java.util.List<IToken> extractVariablesDeclaredInFor(ShallowEntity entity)
public static boolean isLocalVariable(ShallowEntity entity)
public static boolean isGlobalVariable(ShallowEntity entity)
public static boolean containsLoopReferenceWithoutLoop(java.util.List<ShallowEntity> block)
continue or break are contained in a
for or while loop in the given block. If there is
continue, break or return; in a code
segment, it can not be extracted. (Note: return sth; may be
extractable.)block - the ShallowEntities that will be checked.true if there is continue or
breakpublic static java.util.List<ShallowEntity> getCompleteStatement(ShallowEntity shallowEntity)
if or
try block a list of ShallowEntities that
represents the corresponding else if or catch and
else or finally block. That means that the complete
statement is determined and returned.shallowEntity - the entity that contains an if or try
blockShallowEntities that contains the
corresponding block with all else if or
catch and else or finally
entities belonging to the given shallowEntitypublic static ShallowEntity getFirstEntityAfter(ShallowEntity candidate)
ShallowEntity.candidate - the last entity of the candidateShallowEntity. If there is no such entity, null
will be returned.public static ShallowEntity getLastEntityBefore(ShallowEntity candidate)
ShallowEntity.candidate - the first entity of the candidateShallowEntity. If there is no such entity, null
will be returned.public static int getNestingArea(java.util.List<ShallowEntity> shallowEntities)
ShallowEntities.
The nesting area is the sum of the nesting depth of all ShallowEntities.shallowEntities - the ShallowEntities.public static int getNestingDepth(java.util.List<ShallowEntity> block)
block - the ShallowEntities that are taken into
account for the maximal nesting depth.public static int getNestingDepth(ShallowEntity shallowEntity)
shallowEntity - the ShallowEntity.public static int getNumberOfBlankLinesOrCommentsAfter(ShallowEntity candidate)
ShallowEntity.candidate - if a refactoring candidate should be considered, take its last
ShallowEntity.public static int getNumberOfBlankLinesOrCommentsBefore(ShallowEntity candidate)
ShallowEntity.candidate - if a refactoring candidate should be considered, take its first
ShallowEntity.public static java.util.List<java.lang.String> getReturnParameters(java.util.List<ShallowEntity> block)
block - ShallowEntities that might be extractedpublic static java.util.List<ShallowEntity> getStatements(ShallowEntity entity)
public static java.util.List<ShallowEntity> getClassEntities(java.util.List<ShallowEntity> shallowEntities, int startLine, int endLine)
shallowEntities - the ShallowEntities that represent the file
in which the finding was foundstartLine - the start line of the code area that must be covered by the
classesendLine - the end line of the code area that must be covered by the classesShallowEntity with type
TYPE.public static java.util.List<ShallowEntity> getMethods(java.util.List<ShallowEntity> shallowEntities)
shallowEntities - the ShallowEntities that represent the file
in which the finding was foundEShallowEntityType.METHODpublic static java.util.Optional<ShallowEntity> getMethod(java.util.List<ShallowEntity> shallowEntities, OffsetBasedRegion region)
shallowEntities - the ShallowEntities that represent the file
in which the finding was foundregion - of the methodpublic static java.util.Optional<ShallowEntity> getMethod(java.util.List<ShallowEntity> shallowEntities, LineBasedRegion region)
shallowEntities - the ShallowEntities that represent the file
in which the finding was foundregion - of the methodpublic static java.util.Optional<ShallowEntity> getMethod(java.util.List<ShallowEntity> shallowEntities, java.util.function.Predicate<ShallowEntity> filter)
shallowEntities - the ShallowEntities that represent the file
in which the finding was foundfilter - to filter a methodpublic static java.util.List<java.lang.String> getClassAttributes(java.util.List<ShallowEntity> classEntities)
classEntities - the ShallowEntity of the class that contains the method
for which suggestions are to be generatedpublic static boolean isLoop(ShallowEntity entity)
public static boolean isSubpartOfBranchingStatement(ShallowEntity entity)
subtype ELSE IF, ELSE, CATCH,
FINALLY, CASE, DEFAULT, USING, DO will return true but
for other subtypes (including IF, SWITCH, TRY) return
false.public static boolean isCppConstructor(ELanguage language, ShallowEntity entity)
public static boolean isLambdaMethod(ShallowEntity entity)
public static ELanguage getLanguage(ShallowEntity entity)
null if it cannot
be determined