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
Nested ClassesModifier and TypeClassDescriptionprotected final classA context that contains the information needed to compute the folding structure of anICompilationUnitor anIClassFile.protected static final classAProjectionAnnotationfor java code. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final org.eclipse.jface.text.IRegionalignRegion(org.eclipse.jface.text.IRegion region, DefaultJavaFoldingStructureProvider.FoldingStructureComputationContext ctx) Alignsregionto start and end at a line offset.final voidCollapses all comments.final voidcollapseElements(IJavaElement[] elements) Collapses the given elements.final voidCollapses all members except for top level types.protected voidcomputeFoldingStructure(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 org.eclipse.jface.text.PositioncreateCommentPosition(org.eclipse.jface.text.IRegion aligned) Creates a comment folding position from analignedregion.protected final org.eclipse.jface.text.PositioncreateMemberPosition(org.eclipse.jface.text.IRegion aligned, IMember member) Creates a folding position that remembers its member from analignedregion.final voidexpandElements(IJavaElement[] elements) Expands the given elements.protected voidCalled whenever projection is disabled, for example when the provider isuninstalled, when the viewer issues aprojectionDisabledmessage and beforeenablingthe provider.protected voidCalled whenever projection is enabled, for example when the viewer issues aprojectionEnabledmessage.final void(Re-)initializes the structure provided by the receiver.voidinstall(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 booleanReturnstrueif the provider is installed,falseotherwise.voidUninstalls this structure provider.
-
Constructor Details
-
DefaultJavaFoldingStructureProvider
public DefaultJavaFoldingStructureProvider()Creates a new folding provider. It must beinstalledon an editor/viewer pair before it can be used, anduninstalledwhen 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 byviewerand enable / disable generation of projection structure accordingly.Subclasses may extend.
- Specified by:
installin 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:
uninstallin interfaceIJavaFoldingStructureProvider
-
isInstalled
protected final boolean isInstalled()Returnstrueif the provider is installed,falseotherwise.- Returns:
trueif the provider is installed,falseotherwise
-
handleProjectionEnabled
protected void handleProjectionEnabled()Called whenever projection is enabled, for example when the viewer issues aprojectionEnabledmessage. 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 aprojectionDisabledmessage and beforeenablingthe 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:
initializein interfaceIJavaFoldingStructureProvider
-
alignRegion
protected final org.eclipse.jface.text.IRegion alignRegion(org.eclipse.jface.text.IRegion region, DefaultJavaFoldingStructureProvider.FoldingStructureComputationContext ctx) Alignsregionto 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.nullis returned ifregionisnullitself or does not comprise at least one line delimiter, as a single line cannot be folded.- Parameters:
region- the region to align, may benullctx- the folding context- Returns:
- a region equal or greater than
regionthat is aligned with line offsets,nullif the region is too small to be foldable (e.g. covers only one line)
-
createCommentPosition
protected org.eclipse.jface.text.Position createCommentPosition(org.eclipse.jface.text.IRegion aligned) Creates a comment folding position from analignedregion.- Parameters:
aligned- an aligned region- Returns:
- a folding position corresponding to
aligned
-
computeFoldingStructure
protected void computeFoldingStructure(IJavaElement element, DefaultJavaFoldingStructureProvider.FoldingStructureComputationContext ctx) Computes the folding structure for a givenjava element. Computed projection annotations areaddedto 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
-
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 analignedregion.- Parameters:
aligned- an aligned regionmember- the member to remember- Returns:
- a folding position corresponding to
aligned
-
collapseMembers
public final void collapseMembers()Description copied from interface:IJavaFoldingStructureProviderExtensionCollapses all members except for top level types.- Specified by:
collapseMembersin interfaceIJavaFoldingStructureProviderExtension
-
collapseComments
public final void collapseComments()Description copied from interface:IJavaFoldingStructureProviderExtensionCollapses all comments.- Specified by:
collapseCommentsin interfaceIJavaFoldingStructureProviderExtension
-
collapseElements
Description copied from interface:IJavaFoldingStructureProviderExtensionCollapses the given elements.- Specified by:
collapseElementsin interfaceIJavaFoldingStructureProviderExtension- Parameters:
elements- the java elements to collapse (the array and its elements must not be modified)
-
expandElements
Description copied from interface:IJavaFoldingStructureProviderExtensionExpands the given elements.- Specified by:
expandElementsin interfaceIJavaFoldingStructureProviderExtension- Parameters:
elements- the java elements to expand (the array and its elements must not be modified)
-