Package spoon.support.sniper.internal
Class SourceFragmentContextList
java.lang.Object
spoon.support.sniper.internal.SourceFragmentContextList
- All Implemented Interfaces:
SourceFragmentPrinter
Handles printing of changes of the ordered list of elements.
E.g. list of type members of type
Such lists must be printed in same order like they are in defined in Spoon model.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ChangeResolverprotected intprotected List<SourceFragment>protected MutableTokenWriter -
Constructor Summary
ConstructorsConstructorDescriptionSourceFragmentContextList(MutableTokenWriter mutableTokenWriter, CtElement element, List<SourceFragment> fragments, ChangeResolver changeResolver) -
Method Summary
Modifier and TypeMethodDescriptionprotected intLooks for the child token which fits toPrinterEvent`event`protected intlooks for next child token which contains expected token typeprotected intlooks for next child token which contains exactly same tokenprotected intlooks for next child token, which has element `elementprotected intfindIndexOfNextChildTokenOfRole(int start, CtRole role)looks for next child token which has role `role`protected Stringprotected booleanprotected ModificationStatusisFragmentModified(SourceFragment fragment)booleanknowsHowToPrint(PrinterEvent event)voidCalled when printing using this context is going to finishvoidonPush()called when pushed on the stackvoidprint(PrinterEvent event)Called whenDefaultJavaPrettyPrinterstarts an operationprotected voidprintOriginSpacesUntilFragmentIndex(int fromIndex, int toIndex)Prints origin whitespaces including comments which prefixes the fragment on index `index`, starting with fragment on `fromIndex`protected voidprintSpaces(int fromIndex, int fragmentIndex)Prints spaces before fragment with index `fragmentIndex`protected voidprint all tokens, which represents white spaces and then forget them, so we can collect next white spacesprotected voidsetChildFragmentIdx(int idx)Remembers index of last processed fragmentintupdate(PrinterEvent event)Update the internal state of this printer for this event but does not print anything.
-
Field Details
-
mutableTokenWriter
-
childFragments
-
changeResolver
-
childFragmentIdx
protected int childFragmentIdx -
separatorActions
-
-
Constructor Details
-
SourceFragmentContextList
public SourceFragmentContextList(MutableTokenWriter mutableTokenWriter, CtElement element, List<SourceFragment> fragments, ChangeResolver changeResolver)- Parameters:
mutableTokenWriter-MutableTokenWriter, which is used for printingelement- theCtElementwhose list attribute is handledfragments- the List of fragments, which represents whole list of elements. E.g. body of method or all type members of typechangeResolver-ChangeResolver, which can be used to detect changes of list items
-
-
Method Details
-
findIFragmentIndexCorrespondingToEvent
Looks for the child token which fits toPrinterEvent`event`- Parameters:
event-PrinterEventwhose token it searches for- Returns:
- index of first token which fits to
PrinterEventor -1 if not found
-
knowsHowToPrint
- Returns:
- true if this printer is able to handle this event
That is that we can safely call
SourceFragmentPrinter.print(PrinterEvent)after having called this one.
-
isFragmentModified
- Returns:
- true if at least part of `fragment` is modified. false if whole `fragment` is not modified. ModificationStatus.UNKNOWN if it is not possible to detect it here. Then it will be detected later.
-
getSuffixSpace
- Returns:
- the suffix whitespaces at the end of collection of elements
-
onFinished
public void onFinished()Description copied from interface:SourceFragmentPrinterCalled when printing using this context is going to finish- Specified by:
onFinishedin interfaceSourceFragmentPrinter
-
print
Description copied from interface:SourceFragmentPrinterCalled whenDefaultJavaPrettyPrinterstarts an operation- Specified by:
printin interfaceSourceFragmentPrinter- Parameters:
event- theDefaultJavaPrettyPrinterevent
-
update
Description copied from interface:SourceFragmentPrinterUpdate the internal state of this printer for this event but does not print anything. Returns the index of the fragment corresponding to this event.- Specified by:
updatein interfaceSourceFragmentPrinter
-
printSpaces
protected void printSpaces(int fromIndex, int fragmentIndex)Prints spaces before fragment with index `fragmentIndex`- Parameters:
fragmentIndex- index of fragment whose prefix spaces has to be printed or -1 if origin source fragment was not found
-
printOriginSpacesUntilFragmentIndex
protected void printOriginSpacesUntilFragmentIndex(int fromIndex, int toIndex)Prints origin whitespaces including comments which prefixes the fragment on index `index`, starting with fragment on `fromIndex`- Parameters:
fromIndex- index of first processed fragmenttoIndex- index of first not processed fragment.
-
setChildFragmentIdx
protected void setChildFragmentIdx(int idx)Remembers index of last processed fragment- Parameters:
idx- index of last processed fragment
-
hasNextChildToken
protected boolean hasNextChildToken()- Returns:
- true if there is more child tokens to be processed. false if all tokens were processed
-
findIndexOfNextChildTokenByValue
looks for next child token which contains exactly same token- Parameters:
token- String of searched token- Returns:
- index of first same token or -1 if not found
-
findIndexOfNextChildTokenByType
looks for next child token which contains expected token type- Parameters:
type-TokenTypeof search token- Returns:
- index of token with same type or -1 if not found
-
findIndexOfNextChildTokenOfRole
looks for next child token which has role `role`- Parameters:
role-CtRoleof searched token- Returns:
- index of first token with same role or -1 if not found
-
findIndexOfNextChildTokenOfElement
looks for next child token, which has element `element- Parameters:
element- element of searched token- Returns:
- index of first token with same element or -1 if not found
-
printStandardSpaces
protected void printStandardSpaces()print all tokens, which represents white spaces and then forget them, so we can collect next white spaces -
onPush
public void onPush()Description copied from interface:SourceFragmentPrintercalled when pushed on the stack- Specified by:
onPushin interfaceSourceFragmentPrinter
-