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 Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate final List<DifferenceElement>private intprivate final List<TokenTextElement>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<TokenTextElement> 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.private intconsiderEnforcingIndentation(NodeText nodeText, int nodeTextIndex) If we are at the beginning of a line, with just spaces or tabs before us we should force the space to be the same as the indentation.private booleandoWeHaveLeftBraceFollowedBySpace(int index) private voidextractReshuffledDiffElements(List<DifferenceElement> diffElements) findIndexOfCorrespondingNodeTextElement(List<CsmElement> elements, NodeText nodeText, int startIndex, Node node) private intgetArrayLevel(DifferenceElement element) getCorrespondanceBetweenNextOrderAndPreviousOrder(CsmMix elementsFromPreviousOrder, CsmMix elementsFromNextOrder) 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 booleanisAlmostCorrespondingElement(TextElement textElement, CsmElement csmElement, Node node) private booleanisAReplacement(int diffIndex) private booleanisArrayType(DifferenceElement element) private booleanisBracket(JavaToken.Kind kind) private booleanisCorrespondingElement(TextElement textElement, CsmElement csmElement, Node node) private booleanprivate booleanisFollowedByUnindent(List<DifferenceElement> diffElements, int diffIndex) private booleanisNodeWithTypeArguments(DifferenceElement element) private booleanisReplaced(int diffIndex) private boolean(package private) intlastIndexOfEol(List<TextElement> source) private booleannextIsRightBrace(int index) private booleanprivate List<TextElement>processIndentation(List<TokenTextElement> indentation, List<TextElement> prevElements) private intrewindSpace(int index) private StringtokenDescription(int kind) toString()private boolean
-
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
private List<TextElement> processIndentation(List<TokenTextElement> indentation, List<TextElement> prevElements) -
lastIndexOfEol
-
indentationBlock
-
isAfterLBrace
-
considerEnforcingIndentation
If we are at the beginning of a line, with just spaces or tabs before us we should force the space to be the same as the indentation. -
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() -
extractReshuffledDiffElements
-
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: <----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
-
openBraceWasOnSameLine
private boolean openBraceWasOnSameLine() -
wasSpaceBetweenBraces
private boolean wasSpaceBetweenBraces() -
doWeHaveLeftBraceFollowedBySpace
private boolean doWeHaveLeftBraceFollowedBySpace(int index) -
rewindSpace
private int rewindSpace(int index) -
nextIsRightBrace
private boolean nextIsRightBrace(int index) -
applyAddedDiffElement
-
tokenDescription
-
getCorrespondanceBetweenNextOrderAndPreviousOrder
-
isFollowedByUnindent
-
findIndexOfCorrespondingNodeTextElement
-
isCorrespondingElement
-
isAlmostCorrespondingElement
private boolean isAlmostCorrespondingElement(TextElement textElement, CsmElement csmElement, Node node) -
adjustIndentation
private int adjustIndentation(List<TokenTextElement> indentation, NodeText nodeText, int nodeTextIndex, boolean followedByUnindent) -
isAReplacement
private boolean isAReplacement(int diffIndex) -
isReplaced
private boolean isReplaced(int diffIndex) -
toString
-