Class BslOutlineElementUtil


  • public final class BslOutlineElementUtil
    extends Object
    Commons methods for working with Bsl outline elements
    • Method Detail

      • createDeleteChanges

        public static void createDeleteChanges​(IBslConstruct element,
                                               org.eclipse.handly.snapshot.NonExpiringSnapshot snapshot,
                                               int elementOffset,
                                               int elementLength,
                                               String formatStringElement,
                                               org.eclipse.text.edits.MultiTextEdit multiEdit)
                                        throws org.eclipse.core.runtime.CoreException
        Creates change corresponding to the element of Bsl outline
        Parameters:
        element - IBslConstruct deleting element of Bsl outline, can't be null
        snapshot - actual NonExpiringSnapshot for outline's editor, can't be null
        elementOffset - offset of deleting elements
        elementLength - length of content of deleting elements
        formatStringElement - actual formatting string for deleting elements, can't be null
        multiEdit - MultiTextEdit for accumulate creating changes, can't be null
        Throws:
        org.eclipse.core.runtime.CoreException - can be throw from method #getOffsetLowerNeighbourElement()
      • getFormatString

        public static String getFormatString​(String contents,
                                             int offset,
                                             org.eclipse.handly.model.IElement element)
                                      throws org.eclipse.core.runtime.CoreException
        Gets formating string for element of bsl outline
        Parameters:
        contents - string content of element of bsl outline, can't be null
        offset - offset of element of bsl outline, can't be null
        element - actual element of bsl outline, can't be null
        Returns:
        formating string for element of bsl outline, never null
        Throws:
        org.eclipse.core.runtime.CoreException
      • getLowerNeighbor

        public static Object getLowerNeighbor​(Object target)
                                       throws org.eclipse.core.runtime.CoreException
        Gets the nearest lower neighbor of bsl outline element
        Parameters:
        target - bsl outline element
        Returns:
        the nearest lower neighbor of bsl outline element or null if target is not bsl outline element, or there is no lower neighbor
        Throws:
        org.eclipse.core.runtime.CoreException - can be throw from method IElement#getChildren()
      • getUpperNeighbor

        public static Object getUpperNeighbor​(Object target)
                                       throws org.eclipse.core.runtime.CoreException
        Gets the nearest upper neighbor of bsl outline element
        Parameters:
        target - bsl outline element
        Returns:
        the nearest upper neighbor of bsl outline element or null if target is not bsl outline element, or there is no upper neighbor
        Throws:
        org.eclipse.core.runtime.CoreException - can be throw from method IElement#getChildren()
      • isContainsType

        public static boolean isContainsType​(Object target,
                                             Class<?> clazz)
                                      throws org.eclipse.core.runtime.CoreException
        Checks that class of target in instance of clazz
        Parameters:
        target - checking elements, can be null
        clazz - expected type, can't be null
        Returns:
        true if class of target in instance of clazz or if target instanceof IElement and there is child instanceof clazz, false otherwise or if target is null
        Throws:
        org.eclipse.core.runtime.CoreException - can be throw from method IElement#getChildren()
      • hasElementByType

        public static boolean hasElementByType​(List<?> elements,
                                               Class<?> clazz,
                                               boolean checkChildren)
                                        throws org.eclipse.core.runtime.CoreException
        Checks that elements contains elements of type clazz
        Parameters:
        elements - checking elements, can't be null
        clazz - checking type, , can't be null
        checkChildren - true if need to check and children of each element of elements, false otherwise
        Returns:
        true if elements contains elements of type clazz, false otherwise or if list of elements is empty
        Throws:
        org.eclipse.core.runtime.CoreException - CoreException can be throw from method #isContainsType()
      • getTargetOffset

        public static int getTargetOffset​(IBslConstruct target,
                                          com._1c.g5.v8.dt.internal.bsl.ui.dnd.BslViewerDropAdapter.DropLocation location,
                                          org.eclipse.handly.ui.outline.ICommonOutlinePage outlinePage)
                                   throws org.eclipse.core.runtime.CoreException
        Gets actual offset for moving by target element
        Parameters:
        target - moving element of bsl outline, cannot be null
        location - actual BslViewerDropAdapter.DropLocation, cannot be null
        outlinePage - actual outline page, cannot be null
        Returns:
        offset for moving by target element
        Throws:
        org.eclipse.core.runtime.CoreException
      • getFormatTargetString

        public static String getFormatTargetString​(IBslConstruct target,
                                                   org.eclipse.handly.snapshot.NonExpiringSnapshot snapshot,
                                                   com._1c.g5.v8.dt.internal.bsl.ui.dnd.BslViewerDropAdapter.DropLocation location,
                                                   String indent)
                                            throws org.eclipse.core.runtime.CoreException
        Gets format string for target element of bsl outline
        Parameters:
        target - bsl outline element, can't be null
        snapshot - actual NonExpiringSnapshot for outline's editor, can't be null
        location - actual BslViewerDropAdapter.DropLocation
        indent - actual indent of text editor, can't be null
        Returns:
        format string for target element, never null
        Throws:
        org.eclipse.core.runtime.CoreException
      • createInsertChanges

        public static void createInsertChanges​(String content,
                                               int targetOffset,
                                               org.eclipse.text.edits.MultiTextEdit multiEdit)
      • formatContent

        public static String formatContent​(String content,
                                           String formatStringTarget,
                                           String formatStringElement)
        Formats content of moving element corresponding for format in target element
        Parameters:
        content - formatting content, can't be null
        formatStringTarget - format of target bsl outline element, can't be null
        formatStringElement - format of element of bsl outline which content is being formatted, can't be null
        Returns:
        formatted content of moving element corresponding for format in target element, never null
      • allElementsHasTheSameParent

        public static boolean allElementsHasTheSameParent​(List<?> elements)
        Checks that all elements of elements have the same parent
        Parameters:
        elements - checking elements, can't be null
        Returns:
        true if all elements of elements have the same parent, false otherwise
      • isNestedElementsOfSelected

        public static boolean isNestedElementsOfSelected​(Object target,
                                                         List<?> elements)
                                                  throws org.eclipse.core.runtime.CoreException
        Checks that target is parent element for one element from elements
        Parameters:
        target - bsl outline element, can't be null
        elements - checking elements, can't be null
        Returns:
        true if target is parent element for one element from elements, false otherwise
        Throws:
        org.eclipse.core.runtime.CoreException
      • computeElementLengthWithComment

        public static int computeElementLengthWithComment​(org.eclipse.handly.ui.outline.ICommonOutlinePage outlinePage,
                                                          int elementOffset,
                                                          int elementLength)
        Compute full length of the outline element. Full length is sum of original element length and length of the comment node with leader whitespace at the same line that end of the outline element
        Parameters:
        outlinePage - actual outline page, cannot be null
        elementOffset - actual offset of the outline element
        elementLength - actual length of the outline element
        Returns:
        full length of the outline element