Class AbstractFormatJob
java.lang.Object
de.funfried.netbeans.plugins.external.formatter.AbstractFormatJob
- All Implemented Interfaces:
FormatJob
- Direct Known Subclasses:
AbstractEclipseFormatJob
Abstract base implementation of a
FormatJob
which is called by the
FormatterService
where this implementation belongs to.- Author:
- bahlef
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
RuntimeException
which is used as abreak
condition inside aIterable.forEach(java.util.function.Consumer)
. -
Field Summary
FieldsModifier and TypeFieldDescriptionSortedSet
containing document offset ranges which should be formatted.protected final StyledDocument
TheStyledDocument
from which the content should be formatted. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractFormatJob
(StyledDocument document, SortedSet<Pair<Integer, Integer>> changedElements) Constructor which has to be used by subclasses. -
Method Summary
Modifier and TypeMethodDescriptionavoidGuardedSection
(Pair<Integer, Integer> section, Iterable<GuardedSection> guardedSections) Checks if a givensection
interferes with the givenguardedSections
and if so splits the givensection
into multiple sections and returns them as aSortedSet
.protected String
getCode()
Returns the content of thedocument
.getFormatableSections
(String code) Returns aSortedSet
within ranges asPair
s ofInteger
s which describe the start and end offsets that can be formatted, it automatically checks for guarded sections and removes them before returning theSortedSet
, this means if an emptySortedSet
was removed nothing can be formatted, because all ranges in thechangedElements
are in guarded sections.protected boolean
setFormattedCode
(String code, String formattedContent) Applies the givenformattedContent
to thedocument
.
-
Field Details
-
changedElements
SortedSet
containing document offset ranges which should be formatted. -
document
TheStyledDocument
from which the content should be formatted.
-
-
Constructor Details
-
AbstractFormatJob
protected AbstractFormatJob(StyledDocument document, SortedSet<Pair<Integer, Integer>> changedElements) Constructor which has to be used by subclasses.- Parameters:
document
- theStyledDocument
from which the content should be formattedchangedElements
-SortedSet
containing document offset ranges which should be formatted ornull
to format the whole document
-
-
Method Details
-
setFormattedCode
protected boolean setFormattedCode(String code, String formattedContent) throws BadLocationException Applies the givenformattedContent
to thedocument
.- Parameters:
code
- the previous (unformatted) contentformattedContent
- the formatted code- Returns:
true
if and only if the givenformattedContent
was set to thedocument
, if due to any circumstances (old code equals formatted code, thrown exceptions, ...) theformattedContent
wasn't appliedfalse
is returned- Throws:
BadLocationException
- if there is an issue while applying the formatted code
-
getCode
Returns the content of thedocument
.- Returns:
- The content of the
document
-
getFormatableSections
Returns aSortedSet
within ranges asPair
s ofInteger
s which describe the start and end offsets that can be formatted, it automatically checks for guarded sections and removes them before returning theSortedSet
, this means if an emptySortedSet
was removed nothing can be formatted, because all ranges in thechangedElements
are in guarded sections. -
avoidGuardedSection
protected SortedSet<Pair<Integer,Integer>> avoidGuardedSection(Pair<Integer, Integer> section, Iterable<GuardedSection> guardedSections) Checks if a givensection
interferes with the givenguardedSections
and if so splits the givensection
into multiple sections and returns them as aSortedSet
.- Parameters:
section
- the section that should be checkedguardedSections
- the guarded sections of thedocument
- Returns:
- A
SortedSet
containing the splitted sections or just the initialsection
itself if there was no interference with the givenguardedSections
-