Class ElementSourceFragment

    • Method Detail

      • getStart

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

        public int getEnd()
        Returns:
        offset of character after this fragment
      • getSourceCode

        public String getSourceCode​(int start,
                                    int end)
        Parameters:
        start - start offset relative to compilation unit
        end - end offset (after last character) relative to compilation unit
        Returns:
        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
        Parameters:
        element - the root element of the tree
      • 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.
        Parameters:
        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
        Returns:
        ElementSourceFragment which represents the root of the CtElement whose sources are in interval [start, end]
      • 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.
        Returns:
        list of child fragments of this ElementSourceFragment.
      • getRoleInParent

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

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