Top Description Inners Fields Constructors Methods
com.github.javaparser.printer.lexicalpreservation

public Class Difference

extends Object
Class Inheritance
Static Imports
com.github.javaparser.GeneratedJavaParserConstants.*

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 and Inner Type Summary

Modifier and TypeClass and Description
private static enum

Field Summary

Modifier and TypeField and Description
private boolean
private final List<DifferenceElement>
private int
private final List<TokenTextElement>
private final Node
private final NodeText
private final List<TextElement>
private int
public static final int

Constructor Summary

AccessConstructor and Description
pack-priv
Difference(List<DifferenceElement> diffElements, NodeText nodeText, Node node)

Method Summary

Modifier and TypeMethod and Description
private int
adjustIndentation(List<TokenTextElement> indentation, NodeText nodeText, int nodeTextIndex, boolean followedByUnindent)

pack-priv 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).

private void
private void
applyKeptDiffElement(Kept kept, TextElement originalElement, boolean originalElementIsChild, boolean originalElementIsToken)

private boolean
private boolean
private void
applyRemovedDiffElement(RemovedGroup removedGroup, Removed removed, TextElement originalElement, boolean originalElementIsChild, boolean originalElementIsToken)

private void
cleanTheLineOfLeftOverSpace(RemovedGroup removedGroup, Removed removed)

Cleans the line of left over space if there is unnecessary indentation and the element will not be replaced

private Map<Removed, RemovedGroup>

Returns:

Map with all Removed elements as keys to their corresponding RemovedGroup
combineRemovedElementsToRemovedGroups
()

Maps all Removed elements as keys to their corresponding RemovedGroup.

private int
considerEnforcingIndentation(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 boolean
private void
private List<Integer>
findIndexOfCorrespondingNodeTextElement(List<CsmElement> elements, NodeText nodeText, int startIndex, Node node)

private Map<Integer, Integer>
getCorrespondanceBetweenNextOrderAndPreviousOrder(CsmMix elementsFromPreviousOrder, CsmMix elementsFromNextOrder)

private int
getIndexToNextTokenElement(TokenTextElement element, int nestedDiamondOperator)

private Map<Integer, List<Removed>>
private List<TextElement>
private boolean
isAfterLBrace(NodeText nodeText, int nodeTextIndex)

private boolean
private boolean
isAReplacement(int diffIndex)

private boolean
isCorrespondingElement(TextElement textElement, CsmElement csmElement, Node node)

private boolean
private boolean
isFollowedByUnindent(List<DifferenceElement> diffElements, int diffIndex)

private boolean
private boolean
isReplaced(int diffIndex)

private boolean
nextIsRightBrace(int index)

private boolean
private List<TextElement>
private int
rewindSpace(int index)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
private boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

addedIndentationback to summary
private boolean addedIndentation
diffElementsback to summary
private final List<DifferenceElement> diffElements
diffIndexback to summary
private int diffIndex
indentationback to summary
private final List<TokenTextElement> indentation
nodeback to summary
private final Node node
nodeTextback to summary
private final NodeText nodeText
originalElementsback to summary
private final List<TextElement> originalElements
originalIndexback to summary
private int originalIndex
STANDARD_INDENTATION_SIZEback to summary
public static final int STANDARD_INDENTATION_SIZE

Constructor Detail

Differenceback to summary
pack-priv Difference(List<DifferenceElement> diffElements, NodeText nodeText, Node node)

Method Detail

adjustIndentationback to summary
private int adjustIndentation(List<TokenTextElement> indentation, NodeText nodeText, int nodeTextIndex, boolean followedByUnindent)
applyback to summary
pack-priv 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).

applyAddedDiffElementback to summary
private void applyAddedDiffElement(Added added)
applyKeptDiffElementback to summary
private void applyKeptDiffElement(Kept kept, TextElement originalElement, boolean originalElementIsChild, boolean originalElementIsToken)
applyLeftOverDiffElementsback to summary
private boolean applyLeftOverDiffElements()
applyLeftOverOriginalElementsback to summary
private boolean applyLeftOverOriginalElements()
applyRemovedDiffElementback to summary
private void applyRemovedDiffElement(RemovedGroup removedGroup, Removed removed, TextElement originalElement, boolean originalElementIsChild, boolean originalElementIsToken)
cleanTheLineOfLeftOverSpaceback to summary
private void cleanTheLineOfLeftOverSpace(RemovedGroup removedGroup, Removed removed)

Cleans the line of left over space if there is unnecessary indentation and the element will not be replaced

combineRemovedElementsToRemovedGroupsback to summary
private Map<Removed, RemovedGroup> 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<Removed, RemovedGroup>

Map with all Removed elements as keys to their corresponding RemovedGroup

considerEnforcingIndentationback to summary
private int considerEnforcingIndentation(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.

doWeHaveLeftBraceFollowedBySpaceback to summary
private boolean doWeHaveLeftBraceFollowedBySpace(int index)
extractReshuffledDiffElementsback to summary
private void extractReshuffledDiffElements(List<DifferenceElement> diffElements)
findIndexOfCorrespondingNodeTextElementback to summary
private List<Integer> findIndexOfCorrespondingNodeTextElement(List<CsmElement> elements, NodeText nodeText, int startIndex, Node node)
getCorrespondanceBetweenNextOrderAndPreviousOrderback to summary
private Map<Integer, Integer> getCorrespondanceBetweenNextOrderAndPreviousOrder(CsmMix elementsFromPreviousOrder, CsmMix elementsFromNextOrder)
getIndexToNextTokenElementback to summary
private int getIndexToNextTokenElement(TokenTextElement element, int nestedDiamondOperator)
groupConsecutiveRemovedElementsback to summary
private Map<Integer, List<Removed>> groupConsecutiveRemovedElements()
indentationBlockback to summary
private List<TextElement> indentationBlock()
isAfterLBraceback to summary
private boolean isAfterLBrace(NodeText nodeText, int nodeTextIndex)
isAlmostCorrespondingElementback to summary
private boolean isAlmostCorrespondingElement(TextElement textElement, CsmElement csmElement, Node node)
isAReplacementback to summary
private boolean isAReplacement(int diffIndex)
isCorrespondingElementback to summary
private boolean isCorrespondingElement(TextElement textElement, CsmElement csmElement, Node node)
isDiamondOperatorback to summary
private boolean isDiamondOperator(JavaToken.Kind kind)
isFollowedByUnindentback to summary
private boolean isFollowedByUnindent(List<DifferenceElement> diffElements, int diffIndex)
isNodeWithTypeArgumentsback to summary
private boolean isNodeWithTypeArguments(DifferenceElement element)
isReplacedback to summary
private boolean isReplaced(int diffIndex)
nextIsRightBraceback to summary
private boolean nextIsRightBrace(int index)
openBraceWasOnSameLineback to summary
private boolean openBraceWasOnSameLine()
processIndentationback to summary
private List<TextElement> processIndentation(List<TokenTextElement> indentation, List<TextElement> prevElements)
rewindSpaceback to summary
private int rewindSpace(int index)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
wasSpaceBetweenBracesback to summary
private boolean wasSpaceBetweenBraces()
com.github.javaparser.printer.lexicalpreservation back to summary

private final Enum Difference.MatchClassification

extends Enum<Difference.MatchClassification>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final Difference.MatchClassification
public static final Difference.MatchClassification
public static final Difference.MatchClassification
public static final Difference.MatchClassification
private final int
public static final Difference.MatchClassification

Constructor Summary

AccessConstructor and Description
private
MatchClassification(int priority)

Method Summary

Modifier and TypeMethod and Description
pack-priv int
public static Difference.MatchClassification
public static Difference.MatchClassification[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ALLback to summary
public static final Difference.MatchClassification ALL
ALMOSTback to summary
public static final Difference.MatchClassification ALMOST
NEXT_AND_SAMEback to summary
public static final Difference.MatchClassification NEXT_AND_SAME
PREVIOUS_AND_SAMEback to summary
public static final Difference.MatchClassification PREVIOUS_AND_SAME
priorityback to summary
private final int priority
SAME_ONLYback to summary
public static final Difference.MatchClassification SAME_ONLY

Constructor Detail

MatchClassificationback to summary
private MatchClassification(int priority)

Method Detail

getPriorityback to summary
pack-priv int getPriority()
valueOfback to summary
public static Difference.MatchClassification valueOf(String name)
valuesback to summary
public static Difference.MatchClassification[] values()