Class RemovedGroup
- java.lang.Object
-
- com.github.javaparser.printer.lexicalpreservation.RemovedGroup
-
- All Implemented Interfaces:
java.lang.Iterable<Removed>
final class RemovedGroup extends java.lang.Object implements java.lang.Iterable<Removed>
This class represents a group ofRemoved
elements. TheRemoved
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 containingRemoved
elements.- See Also:
Iterable
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Integer
firstElementIndex
private java.util.function.Function<TokenRange,java.lang.Boolean>
hasOnlyWhitespaceBehindFunction
private java.util.function.Function<TokenRange,java.lang.Boolean>
hasOnlyWhitespaceInFrontFunction
private java.util.function.Function<JavaToken,java.lang.Boolean>
hasOnlyWhitespaceJavaTokenBehindFunction
private java.util.function.Function<JavaToken,java.lang.Boolean>
hasOnlyWhitespaceJavaTokenInFrontFunction
private boolean
isProcessed
private java.util.List<Removed>
removedList
-
Constructor Summary
Constructors Modifier Constructor Description private
RemovedGroup(java.lang.Integer firstElementIndex, java.util.List<Removed> removedList)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) Removed
getFirstElement()
Returns the first element of this RemovedGroup(package private) java.util.Optional<java.lang.Integer>
getIndentation()
Returns the indentation in front of this RemovedGroup if possible.private java.util.List<java.lang.Integer>
getIndicesBeingRemoved()
(package private) Removed
getLastElement()
Returns the last element of this RemovedGroup(package private) java.lang.Integer
getLastElementIndex()
Returns the difference index of the last element being removed with this RemovedGroupprivate boolean
hasOnlyWhitespace(Removed startElement, java.util.function.Function<TokenRange,java.lang.Boolean> hasOnlyWhitespaceFunction)
private boolean
hasOnlyWhiteSpaceForTokenFunction(JavaToken token, java.util.function.Function<JavaToken,java.util.Optional<JavaToken>> tokenFunction)
(package private) 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.(package private) boolean
isProcessed()
Returns whether the RemovedGroup was already processed and should not be processed againjava.util.Iterator<Removed>
iterator()
static RemovedGroup
of(java.lang.Integer firstElementIndex, java.util.List<Removed> removedList)
Factory method to create a RemovedGroup which consists of consecutive Removed elements(package private) void
processed()
Marks the RemovedGroup as processed which indicates that it should not be processed again
-
-
-
Field Detail
-
firstElementIndex
private final java.lang.Integer firstElementIndex
-
removedList
private final java.util.List<Removed> removedList
-
isProcessed
private boolean isProcessed
-
hasOnlyWhitespaceJavaTokenInFrontFunction
private final java.util.function.Function<JavaToken,java.lang.Boolean> hasOnlyWhitespaceJavaTokenInFrontFunction
-
hasOnlyWhitespaceJavaTokenBehindFunction
private final java.util.function.Function<JavaToken,java.lang.Boolean> hasOnlyWhitespaceJavaTokenBehindFunction
-
hasOnlyWhitespaceInFrontFunction
private final java.util.function.Function<TokenRange,java.lang.Boolean> hasOnlyWhitespaceInFrontFunction
-
hasOnlyWhitespaceBehindFunction
private final java.util.function.Function<TokenRange,java.lang.Boolean> hasOnlyWhitespaceBehindFunction
-
-
Constructor Detail
-
RemovedGroup
private RemovedGroup(java.lang.Integer firstElementIndex, java.util.List<Removed> removedList)
-
-
Method Detail
-
of
public static RemovedGroup of(java.lang.Integer firstElementIndex, java.util.List<Removed> removedList)
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:
java.lang.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
private java.util.List<java.lang.Integer> getIndicesBeingRemoved()
-
getLastElementIndex
final java.lang.Integer getLastElementIndex()
Returns the difference index of the last element being removed with this RemovedGroup- Returns:
- the last difference incex of this RemovedGroup
-
getFirstElement
final Removed getFirstElement()
Returns the first element of this RemovedGroup- Returns:
- the first element of this RemovedGroup
-
getLastElement
final Removed getLastElement()
Returns the last element of this RemovedGroup- Returns:
- 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, java.util.function.Function<TokenRange,java.lang.Boolean> hasOnlyWhitespaceFunction)
-
hasOnlyWhiteSpaceForTokenFunction
private boolean hasOnlyWhiteSpaceForTokenFunction(JavaToken token, java.util.function.Function<JavaToken,java.util.Optional<JavaToken>> tokenFunction)
-
getIndentation
final java.util.Optional<java.lang.Integer> getIndentation()
Returns the indentation in front of this RemovedGroup if possible. If there is something else than whitespace in front, Optional.empty() is returned.- Returns:
- the indentation in front of this RemovedGroup or Optional.empty()
-
-