Class RemovedGroup
java.lang.Object
com.github.javaparser.printer.lexicalpreservation.RemovedGroup
This class represents a group of
Removed
elements.
The Removed
elements are ideally consecutive for the methods in this class to work correctly.
This class consists of methods that calculate information to better handle the difference application for the
containing Removed
elements.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Integer
private final Function
<TokenRange, Boolean> private final Function
<TokenRange, Boolean> private boolean
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
RemovedGroup
(Integer firstElementIndex, List<Removed> removedList) -
Method Summary
Modifier and TypeMethodDescription(package private) final Removed
Returns the first element of this RemovedGroupReturns the indentation in front of this RemovedGroup if possible.(package private) final Removed
Returns the last element of this RemovedGroup(package private) final Integer
Returns the difference index of the last element being removed with this RemovedGroupprivate boolean
hasOnlyWhitespace
(Removed startElement, Function<TokenRange, Boolean> hasOnlyWhitespaceFunction) private boolean
hasOnlyWhiteSpaceForTokenFunction
(JavaToken token, Function<JavaToken, Optional<JavaToken>> tokenFunction) (package private) final boolean
Returns true if the RemovedGroup equates to a complete line This is the case if there are only spaces and tabs left on the line besides the Removed elements.(package private) final boolean
isLastElement
(Removed element) Returns true if the specified element is the last element of this RemovedGroup(package private) final boolean
Returns whether the RemovedGroup was already processed and should not be processed againiterator()
static RemovedGroup
Factory method to create a RemovedGroup which consists of consecutive Removed elements(package private) final void
Marks the RemovedGroup as processed which indicates that it should not be processed againMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
firstElementIndex
-
removedList
-
isProcessed
private boolean isProcessed -
hasOnlyWhitespaceJavaTokenInFrontFunction
-
hasOnlyWhitespaceJavaTokenBehindFunction
-
hasOnlyWhitespaceInFrontFunction
-
hasOnlyWhitespaceBehindFunction
-
-
Constructor Details
-
RemovedGroup
-
-
Method Details
-
of
Factory method to create a RemovedGroup which consists of consecutive Removed elements- Parameters:
firstElementIndex
- the difference index at which the RemovedGroup startsremovedList
- list of the consecutive Removed elements- Returns:
- a RemovedGroup object
- Throws:
IllegalArgumentException
- if the firstElementIndex is null or the removedList is empty or null
-
processed
final void processed()Marks the RemovedGroup as processed which indicates that it should not be processed again -
isProcessed
final boolean isProcessed()Returns whether the RemovedGroup was already processed and should not be processed again- Returns:
- wheter the RemovedGroup was already processed
-
getIndicesBeingRemoved
-
getLastElementIndex
Returns the difference index of the last element being removed with this RemovedGroup- Returns:
- the last difference incex of this RemovedGroup
-
getFirstElement
Returns the first element of this RemovedGroup- Returns:
- the first element of this RemovedGroup
-
getLastElement
Returns the last element of this RemovedGroup- Returns:
- the last element of this RemovedGroup
-
isLastElement
Returns true if the specified element is the last element of this RemovedGroup -
isACompleteLine
final boolean isACompleteLine()Returns true if the RemovedGroup equates to a complete line This is the case if there are only spaces and tabs left on the line besides the Removed elements.
Example:" [Removed] [EOL]" -> this would be a complete line, regardless of spaces or tabs before or after the [Removed] element " [Removed] void [EOL]" -> this would not be a complete line because of the "void" " public [Removed] [EOL]" -> this would not be a complete line because of the "public"
- Returns:
- true if the RemovedGroup equates to a complete line
-
hasOnlyWhitespace
private boolean hasOnlyWhitespace(Removed startElement, Function<TokenRange, Boolean> hasOnlyWhitespaceFunction) -
hasOnlyWhiteSpaceForTokenFunction
-
getIndentation
Returns the indentation in front of this RemovedGroup if possible. Sometimes the first deleted element may be a line break because theConcreteSyntaxModel
generates a line break before the members (for example FieldDeclaration). In this case a remove operation on the member will generate the deletion of the first line break. It is therefore necessary to avoid taking this element into account so we're looking for the first element that isn't a line break.. For example class Foo { int x; } If there is something else than whitespace in front this element, Optional.empty() is returned.- Returns:
- the indentation in front of this RemovedGroup or Optional.empty()
-
iterator
-