public class DefaultJavaFoldingStructureProvider extends Object implements IJavaFoldingStructureProvider, IJavaFoldingStructureProviderExtension
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".
Modifier and Type | Class and Description |
---|---|
protected class |
DefaultJavaFoldingStructureProvider.FoldingStructureComputationContext
A context that contains the information needed to compute the folding structure of an
ICompilationUnit or an IClassFile . |
protected static class |
DefaultJavaFoldingStructureProvider.JavaProjectionAnnotation
A
ProjectionAnnotation for java code. |
Constructor and Description |
---|
DefaultJavaFoldingStructureProvider()
Creates a new folding provider.
|
Modifier and Type | Method and Description |
---|---|
protected IRegion |
alignRegion(IRegion region,
DefaultJavaFoldingStructureProvider.FoldingStructureComputationContext ctx)
Aligns
region to start and end at a line offset. |
void |
collapseComments()
Collapses all comments.
|
void |
collapseElements(IJavaElement[] elements)
Collapses the given elements.
|
void |
collapseMembers()
Collapses all members except for top level types.
|
protected void |
computeFoldingStructure(IJavaElement element,
DefaultJavaFoldingStructureProvider.FoldingStructureComputationContext ctx)
Computes the folding structure for a given
java element . |
protected IRegion[] |
computeProjectionRanges(ISourceReference reference,
DefaultJavaFoldingStructureProvider.FoldingStructureComputationContext ctx)
Computes the projection ranges for a given
ISourceReference . |
protected Position |
createCommentPosition(IRegion aligned)
Creates a comment folding position from an
aligned
region. |
protected Position |
createMemberPosition(IRegion aligned,
IMember member)
Creates a folding position that remembers its member from an
aligned
region. |
void |
expandElements(IJavaElement[] elements)
Expands the given elements.
|
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. |
protected void |
handleProjectionEnabled()
Called whenever projection is enabled, for example when the viewer issues a
projectionEnabled message. |
void |
initialize()
(Re-)initializes the structure provided by the receiver.
|
void |
install(ITextEditor editor,
ProjectionViewer viewer)
Installs this structure provider on the given editor and viewer.
|
protected boolean |
isInstalled()
Returns
true if the provider is installed, false otherwise. |
void |
uninstall()
Uninstalls this structure provider.
|
public DefaultJavaFoldingStructureProvider()
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()
.
public void install(ITextEditor editor, ProjectionViewer viewer)
viewer
and enable / disable generation of projection
structure accordingly.
Subclasses may extend.
install
in interface IJavaFoldingStructureProvider
editor
- the editor that this provider works onviewer
- the projection viewer that displays the annotations created
by this structure providerpublic void uninstall()
Subclasses may extend.
uninstall
in interface IJavaFoldingStructureProvider
protected final boolean isInstalled()
true
if the provider is installed, false
otherwise.true
if the provider is installed, false
otherwiseprotected void handleProjectionEnabled()
projectionEnabled
message. When the provider
is already enabled when this method is called, it is first
disabled
.
Subclasses may extend.
protected void handleProjectionDisabled()
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.
public final void initialize()
IJavaFoldingStructureProvider
initialize
in interface IJavaFoldingStructureProvider
protected void computeFoldingStructure(IJavaElement element, DefaultJavaFoldingStructureProvider.FoldingStructureComputationContext ctx)
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:
element
- the java element to compute the folding structure forctx
- the computation contextprotected final IRegion[] computeProjectionRanges(ISourceReference reference, DefaultJavaFoldingStructureProvider.FoldingStructureComputationContext ctx)
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.
reference
- a java element that is a source referencectx
- the folding contextprotected final Position createCommentPosition(IRegion aligned)
aligned
region.aligned
- an aligned regionaligned
protected final Position createMemberPosition(IRegion aligned, IMember member)
aligned
region.aligned
- an aligned regionmember
- the member to rememberaligned
protected final IRegion alignRegion(IRegion region, DefaultJavaFoldingStructureProvider.FoldingStructureComputationContext ctx)
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.region
- the region to align, may be null
ctx
- the folding contextregion
that is aligned with line
offsets, null
if the region is too small to be foldable (e.g. covers
only one line)public final void collapseMembers()
IJavaFoldingStructureProviderExtension
collapseMembers
in interface IJavaFoldingStructureProviderExtension
public final void collapseComments()
IJavaFoldingStructureProviderExtension
collapseComments
in interface IJavaFoldingStructureProviderExtension
public final void collapseElements(IJavaElement[] elements)
IJavaFoldingStructureProviderExtension
collapseElements
in interface IJavaFoldingStructureProviderExtension
elements
- the java elements to collapse (the array and its elements must not be
modified)public final void expandElements(IJavaElement[] elements)
IJavaFoldingStructureProviderExtension
expandElements
in interface IJavaFoldingStructureProviderExtension
elements
- the java elements to expand (the array and its elements must not be modified)
Copyright (c) 2000, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.