Package org.eclipse.jdt.ui.text.folding
Class DefaultJavaFoldingStructureProvider
java.lang.Object
org.eclipse.jdt.ui.text.folding.DefaultJavaFoldingStructureProvider
- All Implemented Interfaces:
IJavaFoldingStructureProvider
,IJavaFoldingStructureProviderExtension
public class DefaultJavaFoldingStructureProvider
extends Object
implements IJavaFoldingStructureProvider, IJavaFoldingStructureProviderExtension
Updates the projection model of a class file or compilation unit.
Clients may instantiate or subclass. Subclasses must make sure to always call the superclass' code when overriding methods that are marked with "subclasses may extend".
- Since:
- 3.0 (internal), 3.2 (API)
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected final class
A context that contains the information needed to compute the folding structure of anICompilationUnit
or anIClassFile
.protected static final class
AProjectionAnnotation
for java code. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected final org.eclipse.jface.text.IRegion
alignRegion
(org.eclipse.jface.text.IRegion region, DefaultJavaFoldingStructureProvider.FoldingStructureComputationContext ctx) Alignsregion
to start and end at a line offset.final void
Collapses all comments.final void
collapseElements
(IJavaElement[] elements) Collapses the given elements.final void
Collapses all members except for top level types.protected void
computeFoldingStructure
(IJavaElement element, DefaultJavaFoldingStructureProvider.FoldingStructureComputationContext ctx) Computes the folding structure for a givenjava element
.protected final org.eclipse.jface.text.IRegion[]
computeProjectionRanges
(ISourceReference reference, DefaultJavaFoldingStructureProvider.FoldingStructureComputationContext ctx) Computes the projection ranges for a givenISourceReference
.protected final org.eclipse.jface.text.Position
createCommentPosition
(org.eclipse.jface.text.IRegion aligned) Creates a comment folding position from analigned
region.protected final org.eclipse.jface.text.Position
createMemberPosition
(org.eclipse.jface.text.IRegion aligned, IMember member) Creates a folding position that remembers its member from analigned
region.final void
expandElements
(IJavaElement[] elements) Expands the given elements.protected void
Called whenever projection is disabled, for example when the provider isuninstalled
, when the viewer issues aprojectionDisabled
message and beforeenabling
the provider.protected void
Called whenever projection is enabled, for example when the viewer issues aprojectionEnabled
message.final void
(Re-)initializes the structure provided by the receiver.void
install
(org.eclipse.ui.texteditor.ITextEditor editor, org.eclipse.jface.text.source.projection.ProjectionViewer viewer) Installs this structure provider on the given editor and viewer.protected final boolean
Returnstrue
if the provider is installed,false
otherwise.void
Uninstalls this structure provider.
-
Constructor Details
-
DefaultJavaFoldingStructureProvider
public DefaultJavaFoldingStructureProvider()Creates a new folding provider. It must beinstalled
on an editor/viewer pair before it can be used, anduninstalled
when not used any longer.The projection state may be reset by calling
initialize()
.
-
-
Method Details
-
install
public void install(org.eclipse.ui.texteditor.ITextEditor editor, org.eclipse.jface.text.source.projection.ProjectionViewer viewer) Installs this structure provider on the given editor and viewer. Implementations should listen to the projection events generated byviewer
and enable / disable generation of projection structure accordingly.Subclasses may extend.
- Specified by:
install
in interfaceIJavaFoldingStructureProvider
- Parameters:
editor
- the editor that this provider works onviewer
- 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 interfaceIJavaFoldingStructureProvider
-
isInstalled
protected final boolean isInstalled()Returnstrue
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 aprojectionEnabled
message. When the provider is already enabled when this method is called, it is firstdisabled
.Subclasses may extend.
-
handleProjectionDisabled
protected void handleProjectionDisabled()Called whenever projection is disabled, for example when the provider isuninstalled
, when the viewer issues aprojectionDisabled
message and beforeenabling
the provider. Implementations must be prepared to handle multiple calls to this method even if the provider is already disabled.Subclasses may extend.
-
initialize
public final void initialize()Description copied from interface:IJavaFoldingStructureProvider
(Re-)initializes the structure provided by the receiver.- Specified by:
initialize
in interfaceIJavaFoldingStructureProvider
-
computeFoldingStructure
protected void computeFoldingStructure(IJavaElement element, DefaultJavaFoldingStructureProvider.FoldingStructureComputationContext ctx) Computes the folding structure for a givenjava element
. Computed projection annotations areadded
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 forctx
- the computation context
-
computeProjectionRanges
protected final org.eclipse.jface.text.IRegion[] computeProjectionRanges(ISourceReference reference, DefaultJavaFoldingStructureProvider.FoldingStructureComputationContext ctx) Computes the projection ranges for a givenISourceReference
. 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 referencectx
- the folding context- Returns:
- the regions to be folded
-
createCommentPosition
protected final org.eclipse.jface.text.Position createCommentPosition(org.eclipse.jface.text.IRegion aligned) Creates a comment folding position from analigned
region.- Parameters:
aligned
- an aligned region- Returns:
- a folding position corresponding to
aligned
-
createMemberPosition
protected final org.eclipse.jface.text.Position createMemberPosition(org.eclipse.jface.text.IRegion aligned, IMember member) Creates a folding position that remembers its member from analigned
region.- Parameters:
aligned
- an aligned regionmember
- the member to remember- Returns:
- a folding position corresponding to
aligned
-
alignRegion
protected final org.eclipse.jface.text.IRegion alignRegion(org.eclipse.jface.text.IRegion region, DefaultJavaFoldingStructureProvider.FoldingStructureComputationContext ctx) Alignsregion
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 ifregion
isnull
itself or does not comprise at least one line delimiter, as a single line cannot be folded.- Parameters:
region
- the region to align, may benull
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)
-
collapseMembers
public final void collapseMembers()Description copied from interface:IJavaFoldingStructureProviderExtension
Collapses all members except for top level types.- Specified by:
collapseMembers
in interfaceIJavaFoldingStructureProviderExtension
-
collapseComments
public final void collapseComments()Description copied from interface:IJavaFoldingStructureProviderExtension
Collapses all comments.- Specified by:
collapseComments
in interfaceIJavaFoldingStructureProviderExtension
-
collapseElements
Description copied from interface:IJavaFoldingStructureProviderExtension
Collapses the given elements.- Specified by:
collapseElements
in interfaceIJavaFoldingStructureProviderExtension
- Parameters:
elements
- the java elements to collapse (the array and its elements must not be modified)
-
expandElements
Description copied from interface:IJavaFoldingStructureProviderExtension
Expands the given elements.- Specified by:
expandElements
in interfaceIJavaFoldingStructureProviderExtension
- Parameters:
elements
- the java elements to expand (the array and its elements must not be modified)
-