Class Difference
java.lang.Object
com.github.javaparser.printer.lexicalpreservation.Difference
A Difference should give me a sequence of elements I should find (to indicate the context) followed by a list of elements
to remove or to add and follow by another sequence of elements.
I should later be able to apply such difference to a nodeText.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classprivate class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate final List<DifferenceElement> private intprivate final List<TextElement> private final Nodeprivate final NodeTextprivate final List<TextElement> private intstatic final int -
Constructor Summary
ConstructorsConstructorDescriptionDifference(List<DifferenceElement> diffElements, NodeText nodeText, Node node) -
Method Summary
Modifier and TypeMethodDescriptionprivate intadjustIndentation(List<TextElement> indentation, NodeText nodeText, int nodeTextIndex, boolean followedByUnindent) (package private) voidapply()Node that we have calculate the Difference we can apply to a concrete NodeText, modifying it according to the difference (adding and removing the elements provided).private voidapplyAddedDiffElement(Added added) private voidapplyKeptDiffElement(Kept kept, TextElement originalElement, boolean originalElementIsChild, boolean originalElementIsToken) private booleanprivate booleanprivate voidapplyRemovedDiffElement(RemovedGroup removedGroup, Removed removed, TextElement originalElement, boolean originalElementIsChild, boolean originalElementIsToken) private voidcleanTheLineOfLeftOverSpace(RemovedGroup removedGroup, Removed removed) Cleans the line of left over space if there is unnecessary indentation and the element will not be replacedprivate Map<Removed, RemovedGroup> Maps all Removed elements as keys to their corresponding RemovedGroup.(package private) intconsiderEnforcingIndentation(NodeText nodeText, int nodeTextIndex) If we are at the beginning of a line, with just spaces or tabs before/after the position of the deleted element we should force the space to be the same as the current indentation.private intconsiderIndentation(NodeText nodeText, int nodeTextIndex, int numberOfCharactersToPreserve) private intconsiderRemovingIndentation(NodeText nodeText, int nodeTextIndex) defineEnforcingIndentationContext(NodeText nodeText, int startIndex) Starting atnodeTextIndexthis method tries to determine how many contiguous spaces there are between the previous end of line and the next non whitespace (or tab) characterprivate intgetArrayLevel(DifferenceElement element) private intgetIndexToNextTokenElement(TokenTextElement element, int nestedDiamondOperator) private intgetIndexToNextTokenElement(TokenTextElement element, DifferenceElement kept) private intgetIndexToNextTokenElementInArrayType(TokenTextElement element, int arrayLevel) private List<TextElement> private booleanisAfterLBrace(NodeText nodeText, int nodeTextIndex) private booleanisAReplacement(int diffIndex) private booleanisArrayType(DifferenceElement element) private booleanisBracket(JavaToken.Kind kind) private booleanprivate booleanisEnforcingIndentationActivable(RemovedGroup removedGroup) private booleanisFollowedByComment(int fromIndex, List<TextElement> elements) private booleanisFollowedByUnindent(List<DifferenceElement> diffElements, int diffIndex) private booleanisLastElement(List<?> list, int index) private booleanisNodeWithTypeArguments(DifferenceElement element) private booleanisRemovingIndentationActivable(RemovedGroup removedGroup) private booleanisReplaced(int diffIndex) private booleanisSpaceOrTabElement(NodeText nodeText, int i) private booleanprivate booleanisValidIndex(int index, List<?> elements) (package private) intlastIndexOfEol(List<TextElement> source) (package private) intlastIndexOfEolWithoutGPT(List<TextElement> source) private DifferenceElementnextDiffElement(List<DifferenceElement> list, int index) private booleannextIsRightBrace(int index) private intposOfNextComment(int fromIndex, List<TextElement> elements) (package private) List<TextElement> processIndentation(List<TextElement> indentation, List<TextElement> prevElements) private voidremoveElements(int fromIndex, int toIndex, List<TextElement> elements) private intremoveExtraCharacters(NodeText nodeText, int nodeTextIndex, int extraCharacters) Remove excess white space after deleting element.(package private) List<TextElement> takeWhile(List<TextElement> prevElements, Predicate<TextElement> predicate) toString()
-
Field Details
-
STANDARD_INDENTATION_SIZE
public static final int STANDARD_INDENTATION_SIZE- See Also:
-
nodeText
-
node
-
diffElements
-
originalElements
-
originalIndex
private int originalIndex -
diffIndex
private int diffIndex -
indentation
-
addedIndentation
private boolean addedIndentation
-
-
Constructor Details
-
Difference
Difference(List<DifferenceElement> diffElements, NodeText nodeText, Node node)
-
-
Method Details
-
processIndentation
-
takeWhile
-
lastIndexOfEol
-
posOfNextComment
-
isFollowedByComment
-
removeElements
-
isValidIndex
-
lastIndexOfEolWithoutGPT
-
indentationBlock
-
isAfterLBrace
-
considerEnforcingIndentation
If we are at the beginning of a line, with just spaces or tabs before/after the position of the deleted element we should force the space to be the same as the current indentation. This method handles the following case if we remove the modifierpublic([ ] is an indent character)[ ][ ]public[ ][ ][ ]void[ ]m{} <-1--> <---2---> 1/ current indentation 2/ these whitespaces must be removedshould produce[ ][ ]void[ ]m{} -
considerRemovingIndentation
-
considerIndentation
private int considerIndentation(NodeText nodeText, int nodeTextIndex, int numberOfCharactersToPreserve) -
isEnforcingIndentationActivable
-
isRemovingIndentationActivable
-
isLastElement
-
nextDiffElement
-
removeExtraCharacters
Remove excess white space after deleting element.- Parameters:
nodeText- Contains a list of elements to analyzenodeTextIndex- Starting position in the input list- Returns:
- The current position in the list of the elements
-
defineEnforcingIndentationContext
private Difference.EnforcingIndentationContext defineEnforcingIndentationContext(NodeText nodeText, int startIndex) Starting atnodeTextIndexthis method tries to determine how many contiguous spaces there are between the previous end of line and the next non whitespace (or tab) character- Parameters:
nodeText- List of elements to analyzenodeTextIndex- Starting position in the input list- Returns:
- EnforcingIndentationContext Data structure that hold the starting position of the first whitespace char and The number of consecutive whitespace (or tab) characters
-
isSpaceOrTabElement
-
apply
void apply()Node that we have calculate the Difference we can apply to a concrete NodeText, modifying it according to the difference (adding and removing the elements provided). -
applyLeftOverOriginalElements
private boolean applyLeftOverOriginalElements() -
applyLeftOverDiffElements
private boolean applyLeftOverDiffElements() -
combineRemovedElementsToRemovedGroups
Maps all Removed elements as keys to their corresponding RemovedGroup. A RemovedGroup contains all consecutive Removed elements.
Example:Elements: Kept|Removed1|Removed2|Kept|Removed3|Added|Removed4 Groups: invalid input: '<'----Group1----> Group2 Group3 Keys: Removed1+Removed2 Removed3 Removed4- Returns:
- Map with all Removed elements as keys to their corresponding RemovedGroup
-
groupConsecutiveRemovedElements
-
applyRemovedDiffElement
private void applyRemovedDiffElement(RemovedGroup removedGroup, Removed removed, TextElement originalElement, boolean originalElementIsChild, boolean originalElementIsToken) -
cleanTheLineOfLeftOverSpace
Cleans the line of left over space if there is unnecessary indentation and the element will not be replaced -
applyKeptDiffElement
private void applyKeptDiffElement(Kept kept, TextElement originalElement, boolean originalElementIsChild, boolean originalElementIsToken) -
getArrayLevel
-
isArrayType
-
isTypeWithFullyQualifiedName
-
isNodeWithTypeArguments
-
getIndexToNextTokenElement
-
getIndexToNextTokenElement
-
getIndexToNextTokenElementInArrayType
-
isDiamondOperator
-
isBracket
-
nextIsRightBrace
private boolean nextIsRightBrace(int index) -
applyAddedDiffElement
-
isFollowedByUnindent
-
adjustIndentation
private int adjustIndentation(List<TextElement> indentation, NodeText nodeText, int nodeTextIndex, boolean followedByUnindent) -
isAReplacement
private boolean isAReplacement(int diffIndex) -
isReplaced
private boolean isReplaced(int diffIndex) -
toString
-