Class SourceFragmentContextList

All Implemented Interfaces:

public class SourceFragmentContextList extends Object
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 Details

    • mutableTokenWriter

      protected final MutableTokenWriter mutableTokenWriter
    • childFragments

      protected final List<SourceFragment> childFragments
    • changeResolver

      protected final ChangeResolver changeResolver
    • childFragmentIdx

      protected int childFragmentIdx
    • separatorActions

      protected final List<Runnable> separatorActions
  • Constructor Details

    • SourceFragmentContextList

      public SourceFragmentContextList(MutableTokenWriter mutableTokenWriter, CtElement element, List<SourceFragment> fragments, ChangeResolver changeResolver)
      mutableTokenWriter - MutableTokenWriter, which is used for printing
      element - the CtElement whose list attribute is handled
      fragments - the List of fragments, which represents whole list of elements. E.g. body of method or all type members of type
      changeResolver - ChangeResolver, which can be used to detect changes of list items
  • Method Details

    • findIFragmentIndexCorrespondingToEvent

      protected int findIFragmentIndexCorrespondingToEvent(PrinterEvent event)
      Looks for the child token which fits to PrinterEvent `event`
      event - PrinterEvent whose token it searches for
      index of first token which fits to PrinterEvent or -1 if not found
    • knowsHowToPrint

      public boolean knowsHowToPrint(PrinterEvent event)
      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

      protected ModificationStatus isFragmentModified(SourceFragment fragment)
      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

      protected String getSuffixSpace()
      the suffix whitespaces at the end of collection of elements
    • onFinished

      public void onFinished()
      Description copied from interface: SourceFragmentPrinter
      Called when printing using this context is going to finish
      Specified by:
      onFinished in interface SourceFragmentPrinter
    • print

      public void print(PrinterEvent event)
      Description copied from interface: SourceFragmentPrinter
      Called when DefaultJavaPrettyPrinter starts an operation
      Specified by:
      print in interface SourceFragmentPrinter
      event - the DefaultJavaPrettyPrinter event
    • update

      public int update(PrinterEvent event)
      Description copied from interface: SourceFragmentPrinter
      Update 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:
      update in interface SourceFragmentPrinter
    • printSpaces

      protected void printSpaces(int fromIndex, int fragmentIndex)
      Prints spaces before fragment with index `fragmentIndex`
      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`
      fromIndex - index of first processed fragment
      toIndex - index of first not processed fragment.
    • setChildFragmentIdx

      protected void setChildFragmentIdx(int idx)
      Remembers index of last processed fragment
      idx - index of last processed fragment
    • hasNextChildToken

      protected boolean hasNextChildToken()
      true if there is more child tokens to be processed. false if all tokens were processed
    • findIndexOfNextChildTokenByValue

      protected int findIndexOfNextChildTokenByValue(String token)
      looks for next child token which contains exactly same token
      token - String of searched token
      index of first same token or -1 if not found
    • findIndexOfNextChildTokenByType

      protected int findIndexOfNextChildTokenByType(TokenType type)
      looks for next child token which contains expected token type
      type - TokenType of search token
      index of token with same type or -1 if not found
    • findIndexOfNextChildTokenOfRole

      protected int findIndexOfNextChildTokenOfRole(int start, CtRole role)
      looks for next child token which has role `role`
      role - CtRole of searched token
      index of first token with same role or -1 if not found
    • findIndexOfNextChildTokenOfElement

      protected int findIndexOfNextChildTokenOfElement(SourcePositionHolder element)
      looks for next child token, which has element `element
      element - element of searched token
      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: SourceFragmentPrinter
      called when pushed on the stack
      Specified by:
      onPush in interface SourceFragmentPrinter