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 Classes Modifier and Type Class Description protected classDefaultJavaFoldingStructureProvider.FoldingStructureComputationContextA context that contains the information needed to compute the folding structure of anICompilationUnitor anIClassFile.protected static classDefaultJavaFoldingStructureProvider.JavaProjectionAnnotationAProjectionAnnotationfor java code.
-
Constructor Summary
Constructors Constructor Description DefaultJavaFoldingStructureProvider()Creates a new folding provider.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected IRegionalignRegion(IRegion region, DefaultJavaFoldingStructureProvider.FoldingStructureComputationContext ctx)Alignsregionto start and end at a line offset.voidcollapseComments()Collapses all comments.voidcollapseElements(IJavaElement[] elements)Collapses the given elements.voidcollapseMembers()Collapses all members except for top level types.protected voidcomputeFoldingStructure(IJavaElement element, DefaultJavaFoldingStructureProvider.FoldingStructureComputationContext ctx)Computes the folding structure for a givenjava element.protected IRegion[]computeProjectionRanges(ISourceReference reference, DefaultJavaFoldingStructureProvider.FoldingStructureComputationContext ctx)Computes the projection ranges for a givenISourceReference.protected PositioncreateCommentPosition(IRegion aligned)Creates a comment folding position from analignedregion.protected PositioncreateMemberPosition(IRegion aligned, IMember member)Creates a folding position that remembers its member from analignedregion.voidexpandElements(IJavaElement[] elements)Expands the given elements.protected voidhandleProjectionDisabled()Called whenever projection is disabled, for example when the provider isuninstalled, when the viewer issues aprojectionDisabledmessage and beforeenablingthe provider.protected voidhandleProjectionEnabled()Called whenever projection is enabled, for example when the viewer issues aprojectionEnabledmessage.voidinitialize()(Re-)initializes the structure provided by the receiver.voidinstall(ITextEditor editor, ProjectionViewer viewer)Installs this structure provider on the given editor and viewer.protected booleanisInstalled()Returnstrueif the provider is installed,falseotherwise.voiduninstall()Uninstalls this structure provider.
-
-
-
Constructor Detail
-
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 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 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
-
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 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 Position createCommentPosition(IRegion aligned)
Creates a comment folding position from analignedregion.- 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 analignedregion.- Parameters:
aligned- an aligned regionmember- the member to remember- Returns:
- a folding position corresponding to
aligned
-
alignRegion
protected final IRegion alignRegion(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)
-
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
public final void collapseElements(IJavaElement[] elements)
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
public final void expandElements(IJavaElement[] elements)
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)
-
-