Package org.eclipse.xtext.formatting2
Interface IFormattableDocument
-
- All Known Subinterfaces:
IFormattableSubDocument
- All Known Implementing Classes:
FilteredSubDocument
,FormattableDocument
,MaxLineWidthDocument
,RootDocument
,SubDocument
public interface IFormattableDocument
A FormattableDocument is a stateful object that holds a list of
replacers
. Each replacer is responsible for a text region inside this document. The document can be populated with replacers in any order. However, it is not possible and not intended to register two or more replacers for the same or overlappingregion
.Eventually, all replacers are invoked from the beginning of the document to the end of the document. Each replacer produces
text replacements
for their region. AITextReplacerContext
is passed on from replacer to replacer and holds state such as the current indentation level.Besides this, a formattable document
- offers convenience API to define formatting for HiddenRegions. See
ITextRegionAccess
for a definition of HiddenRegions andIHiddenRegionFormatter
for how they can be formatted. - supports conditional formatting. For example, it can try to format a region into the current line and. if that doesn't work, apply an alternative strategy.
- Since:
- 2.8
- Noextend:
- This interface is not intended to be extended by clients.
- Noimplement:
- This interface is not intended to be implemented by clients.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addReplacer(ITextReplacer replacer)
Add a new replacer to the document.ISemanticRegion
append(ISemanticRegion appendAfter, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> initializer)
Create a newIHiddenRegionFormatting
, initialize it, and add it behind the given semanticRegion.<T extends org.eclipse.emf.ecore.EObject>
Tappend(T appendAfter, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> initializer)
Create a newIHiddenRegionFormatting
, initialize it, and add it behind the given semantic object.<T> T
format(T obj)
void
formatConditionally(int offset, int length, ISubFormatter... formatters)
Apply the formatting of the first sub formatter that can successfully format the given region.void
formatConditionally(org.eclipse.emf.ecore.EObject owner, ISubFormatter... formatters)
Apply the formatting of the first sub formatter that can successfully format the given owner's region.AbstractFormatter2
getFormatter()
Returns the formatter that is being used.ITextSegment
getRegion()
Returns the region this formattable document is responsible for.FormatterRequest
getRequest()
Returns the current formatting request.<T1 extends ISemanticRegion,T2 extends ISemanticRegion>
org.eclipse.xtext.xbase.lib.Pair<T1,T2>interior(org.eclipse.xtext.xbase.lib.Pair<T1,T2> pair, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> init)
<T1 extends ISemanticRegion,T2 extends ISemanticRegion>
org.eclipse.xtext.xbase.lib.Pair<T1,T2>interior(T1 first, T2 second, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> init)
<T extends org.eclipse.emf.ecore.EObject>
Tinterior(T object, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> init)
ISemanticRegion
prepend(ISemanticRegion prependBefore, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> initializer)
Create a newIHiddenRegionFormatting
, initialize it, and add it before the given semanticRegion.<T extends org.eclipse.emf.ecore.EObject>
Tprepend(T prependBefore, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> initializer)
Create a newIHiddenRegionFormatting
, initialize it, and add it before the given semantic object.java.util.List<ITextReplacement>
renderToTextReplacements()
Render the document.org.eclipse.xtext.xbase.lib.Pair<IHiddenRegion,IHiddenRegion>
set(IHiddenRegion first, IHiddenRegion second, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> init)
IHiddenRegion
set(IHiddenRegion hiddenRegion, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> init)
Create a newIHiddenRegionFormatting
, initialize it, and add it for the given hidden region.ISemanticRegion
surround(ISemanticRegion semanticRegion, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> beforeAndAfter)
Create a newIHiddenRegionFormatting
, initialize it, and add it before and after the given semantic region.<T extends org.eclipse.emf.ecore.EObject>
Tsurround(T owner, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> beforeAndAfter)
Create a newIHiddenRegionFormatting
, initialize it, and add it before and after the given semantic object.IFormattableDocument
withReplacerFilter(com.google.common.base.Predicate<? super ITextReplacer> filter)
Creates a new formattable document to which only replacers can be added for which the provided predicate yieldstrue
.
-
-
-
Method Detail
-
withReplacerFilter
IFormattableDocument withReplacerFilter(com.google.common.base.Predicate<? super ITextReplacer> filter)
Creates a new formattable document to which only replacers can be added for which the provided predicate yieldstrue
.
-
getRegion
ITextSegment getRegion()
Returns the region this formattable document is responsible for.
-
getFormatter
AbstractFormatter2 getFormatter()
Returns the formatter that is being used.
-
getRequest
FormatterRequest getRequest()
Returns the current formatting request.
-
addReplacer
void addReplacer(ITextReplacer replacer)
Add a new replacer to the document.
-
renderToTextReplacements
java.util.List<ITextReplacement> renderToTextReplacements()
Render the document. This executes all contained replacers and returns the text replacements created by them.
-
append
ISemanticRegion append(ISemanticRegion appendAfter, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> initializer)
Create a newIHiddenRegionFormatting
, initialize it, and add it behind the given semanticRegion. Returns the given semantic region.
-
append
<T extends org.eclipse.emf.ecore.EObject> T append(T appendAfter, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> initializer)
Create a newIHiddenRegionFormatting
, initialize it, and add it behind the given semantic object. Returns the given semantic object.
-
prepend
ISemanticRegion prepend(ISemanticRegion prependBefore, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> initializer)
Create a newIHiddenRegionFormatting
, initialize it, and add it before the given semanticRegion. Returns the given semantic region.
-
prepend
<T extends org.eclipse.emf.ecore.EObject> T prepend(T prependBefore, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> initializer)
Create a newIHiddenRegionFormatting
, initialize it, and add it before the given semantic object. Returns the given semantic object.
-
surround
ISemanticRegion surround(ISemanticRegion semanticRegion, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> beforeAndAfter)
Create a newIHiddenRegionFormatting
, initialize it, and add it before and after the given semantic region. Returns the given semantic region.
-
surround
<T extends org.eclipse.emf.ecore.EObject> T surround(T owner, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> beforeAndAfter)
Create a newIHiddenRegionFormatting
, initialize it, and add it before and after the given semantic object. Returns the given semantic object.
-
formatConditionally
void formatConditionally(org.eclipse.emf.ecore.EObject owner, ISubFormatter... formatters) throws FormattingNotApplicableException
Apply the formatting of the first sub formatter that can successfully format the given owner's region. A sub formatters execution is considered successful if it didn't throw anFormattingNotApplicableException
.- Throws:
FormattingNotApplicableException
-
formatConditionally
void formatConditionally(int offset, int length, ISubFormatter... formatters) throws FormattingNotApplicableException
Apply the formatting of the first sub formatter that can successfully format the given region. A sub formatters execution is considered successful if it didn't throw anFormattingNotApplicableException
.- Throws:
FormattingNotApplicableException
-
set
IHiddenRegion set(IHiddenRegion hiddenRegion, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> init)
Create a newIHiddenRegionFormatting
, initialize it, and add it for the given hidden region. Returns the given hidden region.
-
set
org.eclipse.xtext.xbase.lib.Pair<IHiddenRegion,IHiddenRegion> set(IHiddenRegion first, IHiddenRegion second, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> init)
-
interior
<T1 extends ISemanticRegion,T2 extends ISemanticRegion> org.eclipse.xtext.xbase.lib.Pair<T1,T2> interior(T1 first, T2 second, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> init)
-
interior
<T1 extends ISemanticRegion,T2 extends ISemanticRegion> org.eclipse.xtext.xbase.lib.Pair<T1,T2> interior(org.eclipse.xtext.xbase.lib.Pair<T1,T2> pair, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> init)
-
interior
<T extends org.eclipse.emf.ecore.EObject> T interior(T object, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> init)
-
format
<T> T format(T obj)
-
-