Class ElementSourceFragment

All Implemented Interfaces:

public class ElementSourceFragment extends Object implements SourceFragment
Represents a part of source code of an CtElement It is connected into a tree of ElementSourceFragments. Use SourcePositionHolder.getOriginalSourceFragment() to get it.
  • Field Details

  • Constructor Details

  • Method Details

    • getStart

      public int getStart()
      offset of first character which belongs to this fragment
    • getEnd

      public int getEnd()
      offset of character after this fragment
    • getSourcePosition

      public SourcePosition getSourcePosition()
      SourcePosition of this fragment
    • toString

      public String toString()
      toString in class Object
    • getSourceCode

      public String getSourceCode()
      Specified by:
      getSourceCode in interface SourceFragment
      origin source code of this fragment
    • getSourceCode

      public String getSourceCode(int start, int end)
      start - start offset relative to compilation unit
      end - end offset (after last character) relative to compilation unit
      source code of this Fragment between start/end offsets
    • createSourceFragmentsFrom

      public static ElementSourceFragment createSourceFragmentsFrom(CtElement element)
      Builds a tree of source fragments for `element` and all its children, based on the source positions of each element
      element - the root element of the tree
    • add

      adds `other` ElementSourceFragment into tree of ElementSourceFragments represented by this root element
      other - to be added ElementSourceFragment
      new root of the tree of the ElementSourceFragments. It can be be this or `other`
    • getNextSibling

      public ElementSourceFragment getNextSibling()
      ElementSourceFragment which belongs to the same parent and is next in the sources
    • getFirstChild

      public ElementSourceFragment getFirstChild()
      ElementSourceFragment, which is first child of this fragment
    • getSourceFragmentOf

      public ElementSourceFragment getSourceFragmentOf(SourcePositionHolder element, int start, int end)
      Searches the tree of fragments for the ElementSourceFragment with expected `element`, which contains `start` and `end` source interval. It searches in siblings and children of this ElementSourceFragment recursively.
      element - the SourcePositionHolder of fragment it is looking for or null for any element
      start - the start offset of searched fragment
      end - the offset of next character after the end of searched fragment
      ElementSourceFragment which represents the root of the CtElement whose sources are in interval [start, end]
    • getElement

      public SourcePositionHolder getElement()
      CtElement whose source code is contained in this fragment. May be null
    • getChildrenFragments

      public List<SourceFragment> getChildrenFragments()
      Note: the List of children is flat. The child fragments of collections (parameters, type members, ...) are next to each other.
      list of child fragments of this ElementSourceFragment.
    • getGroupedChildrenFragments

      public List<SourceFragment> getGroupedChildrenFragments()
      Detects all child fragments of this ElementSourceFragment. Note: the List of children contains one CollectionSourceFragment for each collection of fragments (parameters, type members, ...). Note: the CollectionSourceFragment may contain a mix of fragments of different roles, when they overlap. For example this code contains mix of annotations and modifiers public @Test static @Ignored void method()
      list of child fragments of this ElementSourceFragment where fragments, which belongs to the same collection are grouped into CollectionSourceFragment
    • getRoleInParent

      public CtRole getRoleInParent()
      role of the element of this fragment in scope of it's parent
    • getContainerKindInParent

      public ContainerKind getContainerKindInParent()
      the ContainerKind of the attribute which holds the element of this fragment in it's parent