Class DefaultJavaFoldingStructureProvider

    • Constructor Detail

      • DefaultJavaFoldingStructureProvider

        public DefaultJavaFoldingStructureProvider()
        Creates a new folding provider. It must be installed on an editor/viewer pair before it can be used, and uninstalled when not used any longer.

        The projection state may be reset by calling initialize().

    • Method Detail

      • install

        public void install​(ITextEditor editor,
                            ProjectionViewer viewer)
        Installs this structure provider on the given editor and viewer. Implementations should listen to the projection events generated by viewer and enable / disable generation of projection structure accordingly.

        Subclasses may extend.

        Specified by:
        install in interface IJavaFoldingStructureProvider
        Parameters:
        editor - the editor that this provider works on
        viewer - the projection viewer that displays the annotations created by this structure provider
      • uninstall

        public void uninstall()
        Uninstalls this structure provider. Any references to editors or viewers should be cleared.

        Subclasses may extend.

        Specified by:
        uninstall in interface IJavaFoldingStructureProvider
      • isInstalled

        protected final boolean isInstalled()
        Returns true if the provider is installed, false otherwise.
        Returns:
        true if the provider is installed, false otherwise
      • handleProjectionEnabled

        protected void handleProjectionEnabled()
        Called whenever projection is enabled, for example when the viewer issues a projectionEnabled message. When the provider is already enabled when this method is called, it is first disabled.

        Subclasses may extend.

      • handleProjectionDisabled

        protected void handleProjectionDisabled()
        Called whenever projection is disabled, for example when the provider is uninstalled, when the viewer issues a projectionDisabled message and before enabling the provider. Implementations must be prepared to handle multiple calls to this method even if the provider is already disabled.

        Subclasses may extend.

      • computeFoldingStructure

        protected void computeFoldingStructure​(IJavaElement element,
                                               DefaultJavaFoldingStructureProvider.FoldingStructureComputationContext ctx)
        Computes the folding structure for a given java element. Computed projection annotations are added to the computation context.

        Subclasses may extend or replace. The default implementation creates projection annotations for the following elements:

        • true members (not for top-level types)
        • the javadoc comments of any member
        • header comments (javadoc or multi-line comments appearing before the first type's javadoc or before the package or import declarations).

        Parameters:
        element - the java element to compute the folding structure for
        ctx - the computation context
      • computeProjectionRanges

        protected final IRegion[] computeProjectionRanges​(ISourceReference reference,
                                                          DefaultJavaFoldingStructureProvider.FoldingStructureComputationContext ctx)
        Computes the projection ranges for a given ISourceReference. More than one range or none at all may be returned. If there are no foldable regions, an empty array is returned.

        The last region in the returned array (if not empty) describes the region for the java element that implements the source reference. Any preceding regions describe javadoc comments of that java element.

        Parameters:
        reference - a java element that is a source reference
        ctx - the folding context
        Returns:
        the regions to be folded
      • createCommentPosition

        protected final Position createCommentPosition​(IRegion aligned)
        Creates a comment folding position from an aligned region.
        Parameters:
        aligned - an aligned region
        Returns:
        a folding position corresponding to aligned
      • createMemberPosition

        protected final Position createMemberPosition​(IRegion aligned,
                                                      IMember member)
        Creates a folding position that remembers its member from an aligned region.
        Parameters:
        aligned - an aligned region
        member - the member to remember
        Returns:
        a folding position corresponding to aligned
      • alignRegion

        protected final IRegion alignRegion​(IRegion region,
                                            DefaultJavaFoldingStructureProvider.FoldingStructureComputationContext ctx)
        Aligns region to start and end at a line offset. The region's start is decreased to the next line offset, and the end offset increased to the next line start or the end of the document. null is returned if region is null itself or does not comprise at least one line delimiter, as a single line cannot be folded.
        Parameters:
        region - the region to align, may be null
        ctx - the folding context
        Returns:
        a region equal or greater than region that is aligned with line offsets, null if the region is too small to be foldable (e.g. covers only one line)