public abstract class AlignmentStrategy
extends java.lang.Object
GoF 'Strategy'
for Alignment
retrieval.Modifier and Type | Class and Description |
---|---|
static class |
AlignmentStrategy.AlignmentPerTypeStrategy
Alignment strategy that creates and caches alignments for target element types and returns them for elements with the
same types.
|
Constructor and Description |
---|
AlignmentStrategy() |
Modifier and Type | Method and Description |
---|---|
static AlignmentStrategy.AlignmentPerTypeStrategy |
createAlignmentPerTypeStrategy(java.util.Collection<IElementType> targetTypes,
boolean allowBackwardShift)
Delegates to
createAlignmentPerTypeStrategy(Collection, IElementType, boolean, Alignment.Anchor) with no parent type
check (null is delivered as a parent type) and left anchor . |
static AlignmentStrategy.AlignmentPerTypeStrategy |
createAlignmentPerTypeStrategy(java.util.Collection<IElementType> targetTypes,
IElementType parentType,
boolean allowBackwardShift)
Delegates the processing to
createAlignmentPerTypeStrategy(Collection, IElementType, boolean, Alignment.Anchor)
with the given arguments and left anchor . |
static AlignmentStrategy.AlignmentPerTypeStrategy |
createAlignmentPerTypeStrategy(java.util.Collection<IElementType> targetTypes,
IElementType parentType,
boolean allowBackwardShift,
Alignment.Anchor anchor)
Creates strategy that creates and caches one alignment per given type internally and returns it on subsequent calls
to
getAlignment(IElementType, IElementType) for elements which type is listed at the given collection and parent type
(if defined) is the same as the given one; null is returned from getAlignment(IElementType, IElementType) for all
other elements. |
Alignment |
getAlignment(IElementType childType)
Delegates the processing to
getAlignment(IElementType, IElementType) without parent element type
filtering (null is used as parent element type). |
abstract Alignment |
getAlignment(IElementType parentType,
IElementType childType)
Requests current strategy for alignment to use for the child of the given type assuming that parent node has the given type.
|
static AlignmentStrategy |
getNullStrategy() |
static AlignmentStrategy |
wrap(Alignment alignment,
boolean ignoreFilterTypes,
IElementType... filterTypes)
Constructs strategy that returns given alignment for all elements which types pass through the target filter.
|
static AlignmentStrategy |
wrap(Alignment alignment,
IElementType... filterTypes)
Delegates the processing to
wrap(Alignment, boolean, IElementType...) with 'true' as the second argument |
public static AlignmentStrategy getNullStrategy()
null
all the timepublic static AlignmentStrategy wrap(Alignment alignment, IElementType... filterTypes)
wrap(Alignment, boolean, IElementType...)
with 'true'
as the second argumentalignment
- target alignment to wrapfilterTypes
- types to use as a filterpublic static AlignmentStrategy wrap(Alignment alignment, boolean ignoreFilterTypes, IElementType... filterTypes)
alignment
- target alignment to wrapignoreFilterTypes
- flag that defines if given alignment should be returned for all elements with given types or
all elements except those with the given typesfilterTypes
- element types that should be used for filtering on subsequent calls
to getAlignment(IElementType)
null
otherwisepublic static AlignmentStrategy.AlignmentPerTypeStrategy createAlignmentPerTypeStrategy(java.util.Collection<IElementType> targetTypes, boolean allowBackwardShift)
createAlignmentPerTypeStrategy(Collection, IElementType, boolean, Alignment.Anchor)
with no parent type
check (null
is delivered as a parent type) and left anchor
.targetTypes
- target child typesallowBackwardShift
- flag that defines if backward alignment shift is allowedpublic static AlignmentStrategy.AlignmentPerTypeStrategy createAlignmentPerTypeStrategy(java.util.Collection<IElementType> targetTypes, IElementType parentType, boolean allowBackwardShift)
createAlignmentPerTypeStrategy(Collection, IElementType, boolean, Alignment.Anchor)
with the given arguments and left anchor
.targetTypes
- target types for which cached alignment should be returnedparentType
- target parent typeallowBackwardShift
- flag that specifies if former aligned element may be shifted to right in order to align
to subsequent elementpublic static AlignmentStrategy.AlignmentPerTypeStrategy createAlignmentPerTypeStrategy(java.util.Collection<IElementType> targetTypes, IElementType parentType, boolean allowBackwardShift, Alignment.Anchor anchor)
getAlignment(IElementType, IElementType)
for elements which type is listed at the given collection and parent type
(if defined) is the same as the given one; null
is returned from getAlignment(IElementType, IElementType)
for all
other elements.
This strategy is assumed to be used at following situations - suppose we want to align code blocks that doesn't belong
to the same parent but have similar structure, e.g. variable declaration assignments like the one below:
int start = 1; int finish = 2;We can provide parent blocks of that target blocks with the same instance of this alignment strategy and let them eventually reuse the same alignment objects for target sub-blocks of the same type.
targetTypes
- target types for which cached alignment should be returnedparentType
- target parent typeallowBackwardShift
- flag that specifies if former aligned element may be shifted to right in order to align
to subsequent element (e.g. '='
block of 'int start = 1'
statement
below is shifted one symbol right in order to align to the '='
block
of 'int finish = 1'
statement)public Alignment getAlignment(IElementType childType)
getAlignment(IElementType, IElementType)
without parent element type
filtering (null
is used as parent element type).childType
- target child typepublic abstract Alignment getAlignment(IElementType parentType, IElementType childType)
parentType
- parent type to use for filtering (if not null
)childType
- child type to use for filtering (if not null
)