Class FormattableDocument
- java.lang.Object
-
- org.eclipse.xtext.formatting2.internal.FormattableDocument
-
- All Implemented Interfaces:
IFormattableDocument
- Direct Known Subclasses:
RootDocument
,SubDocument
public abstract class FormattableDocument extends java.lang.Object implements IFormattableDocument
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
FormattableDocument()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addReplacer(ITextReplacer replacer)
Add a new replacer to the document.ISemanticRegion
append(ISemanticRegion token, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> after)
Create a newIHiddenRegionFormatting
, initialize it, and add it behind the given semanticRegion.<T extends org.eclipse.emf.ecore.EObject>
Tappend(T owner, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> after)
Create a newIHiddenRegionFormatting
, initialize it, and add it behind the given semantic object.protected java.lang.String
applyTextReplacements(java.lang.Iterable<ITextReplacement> replacements)
protected ITextReplacerContext
createReplacements(ITextReplacerContext previous)
protected TextSegmentSet<ITextReplacer>
createTextReplacerSet()
<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.ITypedPreferenceValues
getPreferences()
protected TextSegmentSet<ITextReplacer>
getReplacers()
ITextRegionAccess
getTextRegionAccess()
<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)
protected boolean
needsAutowrap(ITextReplacerContext wrappable, ITextReplacerContext context, int maxLineWidth)
ISemanticRegion
prepend(ISemanticRegion token, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> before)
Create a newIHiddenRegionFormatting
, initialize it, and add it before the given semanticRegion.<T extends org.eclipse.emf.ecore.EObject>
Tprepend(T owner, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> before)
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 token, 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.java.lang.String
toString()
IFormattableSubDocument
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
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.xtext.formatting2.IFormattableDocument
getFormatter, getRegion, getRequest
-
-
-
-
Method Detail
-
getReplacers
protected TextSegmentSet<ITextReplacer> getReplacers()
-
addReplacer
public void addReplacer(ITextReplacer replacer)
Description copied from interface:IFormattableDocument
Add a new replacer to the document.- Specified by:
addReplacer
in interfaceIFormattableDocument
-
append
public ISemanticRegion append(ISemanticRegion token, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> after)
Description copied from interface:IFormattableDocument
Create a newIHiddenRegionFormatting
, initialize it, and add it behind the given semanticRegion. Returns the given semantic region.- Specified by:
append
in interfaceIFormattableDocument
-
append
public <T extends org.eclipse.emf.ecore.EObject> T append(T owner, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> after)
Description copied from interface:IFormattableDocument
Create a newIHiddenRegionFormatting
, initialize it, and add it behind the given semantic object. Returns the given semantic object.- Specified by:
append
in interfaceIFormattableDocument
-
applyTextReplacements
protected java.lang.String applyTextReplacements(java.lang.Iterable<ITextReplacement> replacements)
-
createReplacements
protected ITextReplacerContext createReplacements(ITextReplacerContext previous)
-
createTextReplacerSet
protected TextSegmentSet<ITextReplacer> createTextReplacerSet()
-
format
public <T> T format(T obj)
- Specified by:
format
in interfaceIFormattableDocument
-
formatConditionally
public void formatConditionally(org.eclipse.emf.ecore.EObject owner, ISubFormatter... formatters)
Description copied from interface:IFormattableDocument
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
.- Specified by:
formatConditionally
in interfaceIFormattableDocument
-
formatConditionally
public void formatConditionally(int offset, int length, ISubFormatter... formatters) throws FormattingNotApplicableException
Description copied from interface:IFormattableDocument
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
.- Specified by:
formatConditionally
in interfaceIFormattableDocument
- Throws:
FormattingNotApplicableException
-
getPreferences
public ITypedPreferenceValues getPreferences()
-
getTextRegionAccess
public ITextRegionAccess getTextRegionAccess()
-
interior
public <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)
- Specified by:
interior
in interfaceIFormattableDocument
-
interior
public <T extends org.eclipse.emf.ecore.EObject> T interior(T object, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> init)
- Specified by:
interior
in interfaceIFormattableDocument
-
interior
public <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)
- Specified by:
interior
in interfaceIFormattableDocument
-
needsAutowrap
protected boolean needsAutowrap(ITextReplacerContext wrappable, ITextReplacerContext context, int maxLineWidth)
-
prepend
public ISemanticRegion prepend(ISemanticRegion token, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> before)
Description copied from interface:IFormattableDocument
Create a newIHiddenRegionFormatting
, initialize it, and add it before the given semanticRegion. Returns the given semantic region.- Specified by:
prepend
in interfaceIFormattableDocument
-
prepend
public <T extends org.eclipse.emf.ecore.EObject> T prepend(T owner, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> before)
Description copied from interface:IFormattableDocument
Create a newIHiddenRegionFormatting
, initialize it, and add it before the given semantic object. Returns the given semantic object.- Specified by:
prepend
in interfaceIFormattableDocument
-
renderToTextReplacements
public java.util.List<ITextReplacement> renderToTextReplacements()
Description copied from interface:IFormattableDocument
Render the document. This executes all contained replacers and returns the text replacements created by them.- Specified by:
renderToTextReplacements
in interfaceIFormattableDocument
-
set
public org.eclipse.xtext.xbase.lib.Pair<IHiddenRegion,IHiddenRegion> set(IHiddenRegion first, IHiddenRegion second, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> init)
- Specified by:
set
in interfaceIFormattableDocument
-
set
public IHiddenRegion set(IHiddenRegion hiddenRegion, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> init)
Description copied from interface:IFormattableDocument
Create a newIHiddenRegionFormatting
, initialize it, and add it for the given hidden region. Returns the given hidden region.- Specified by:
set
in interfaceIFormattableDocument
-
surround
public ISemanticRegion surround(ISemanticRegion token, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> beforeAndAfter)
Description copied from interface:IFormattableDocument
Create a newIHiddenRegionFormatting
, initialize it, and add it before and after the given semantic region. Returns the given semantic region.- Specified by:
surround
in interfaceIFormattableDocument
-
surround
public <T extends org.eclipse.emf.ecore.EObject> T surround(T owner, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super IHiddenRegionFormatter> beforeAndAfter)
Description copied from interface:IFormattableDocument
Create a newIHiddenRegionFormatting
, initialize it, and add it before and after the given semantic object. Returns the given semantic object.- Specified by:
surround
in interfaceIFormattableDocument
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
withReplacerFilter
public IFormattableSubDocument withReplacerFilter(com.google.common.base.Predicate<? super ITextReplacer> filter)
Description copied from interface:IFormattableDocument
Creates a new formattable document to which only replacers can be added for which the provided predicate yieldstrue
.- Specified by:
withReplacerFilter
in interfaceIFormattableDocument
-
-