public abstract class AbstractEplModule extends ErlModule implements IEplModule
Modifier and Type | Class and Description |
---|---|
protected static interface |
AbstractEplModule.LazyAdvancedRoleInstancesInitializer |
protected static interface |
AbstractEplModule.LazyBasicRoleInstancesInitializer |
Modifier and Type | Field and Description |
---|---|
protected ArrayList<Pattern> |
declaredPatterns |
static int |
INFINITE |
protected int |
maxLoops |
protected String |
patternMatchModelName |
protected List<Pattern> |
patterns |
protected boolean |
repeatWhileMatchesFound |
declaredPost, declaredPre, post, pre
compilationContext, context, declaredModelDeclarations, declaredOperations, imports, main, modelDeclarations, operations, postOperationStatements
parseProblems, parser, sourceFile, sourceUri
Constructor and Description |
---|
AbstractEplModule() |
AbstractEplModule(IEplContext context) |
Modifier and Type | Method and Description |
---|---|
ModuleElement |
adapt(AST cst,
ModuleElement parentAst) |
void |
build(AST cst,
IModule module) |
protected org.antlr.runtime.Lexer |
createLexer(org.antlr.runtime.ANTLRInputStream inputStream) |
protected PatternMatchModel |
createModel()
PatternMatchModel factory method.
|
EpsilonParser |
createParser(org.antlr.runtime.TokenStream tokenStream) |
protected PatternMatch |
createPatternMatch(Pattern pattern,
Collection<? extends Iterable<?>> combination)
Converts all roles of the pattern into a PatternMatch with the specified bindings.
|
protected Object |
executeDoBlock(ExecutableBlock<?> doBlock,
Map<String,Object> roleBindings)
Executes the do block with the specified variables.
|
protected Collection<?> |
filterElements(ExecutableBlock<Boolean> guard,
String roleName,
Collection<?> currentInstances)
Executes the guard block when called by
getAllRoleInstances(Role, String, Collection) |
protected static Collection<Variable> |
flatMapRoleBindings(Collection<Role> roles,
Collection<? extends Iterable<?>> combination)
This method simply flatmaps the results of calling getVariables(Iterable, Role)
for each role in the pattern.
|
protected abstract Iterator<? extends Collection<? extends Iterable<?>>> |
getCandidates(Pattern pattern)
The dimensions of the returned nested Iterables are as follows:
Outer: The number of roles in the pattern (i.e. |
IEplContext |
getContext() |
List<Pattern> |
getDeclaredPatterns() |
HashMap<String,Class<?>> |
getImportConfiguration() |
String |
getMainRule() |
protected boolean |
getMatchResult(Pattern pattern)
Gets the result of the match block for the specified pattern.
|
int |
getMaxLoops() |
List<Pattern> |
getPatterns() |
protected Collection<?> |
getRoleInstances(Role role,
String roleName)
Executes the role, returning applicable model elements which satisfy the conditions specified
in the role.
|
protected static Collection<Variable> |
getVariables(Iterable<?> bindings,
Role role)
Binds role names to the objects returned by the bindings iterator.
|
boolean |
isRepeatWhileMatches() |
protected boolean |
isValidCombination(Pattern pattern,
List<? extends Iterable<?>> combination)
Validates whether the given combination matches the constraints imposed by the pattern.
|
Collection<PatternMatch> |
match(Pattern pattern)
This method provides the main high-level execution logic for EPL.
|
protected Optional<PatternMatch> |
matchCombination(Collection<? extends Iterable<?>> combination,
Pattern pattern)
Executes the match, onmatch and/or nomatch blocks.
|
PatternMatchModel |
matchPatterns() |
protected Set<PatternMatch> |
matchPatterns(int level,
PatternMatchModel model)
Adds all matches returned by
IEplModule#match() to the match model
for all patterns at the specified level. |
protected boolean |
negativeGuard(ExecutableBlock<Boolean> guard,
String roleName,
Collection<?> currentInstances)
Executes the guard block when called by
getNegativeRoleInstances(Role, String, Collection) |
protected void |
postProcessMatches(int level,
Collection<PatternMatch> matches)
Executes the do block for all matched patterns at the specified level.
|
protected void |
preMatch(PatternMatchModel model)
Pre-processes the model.
|
protected Object |
processRules()
Main rule processing logic.
|
protected static int |
putRoleBindingsIntoFrame(Collection<Role> roles,
Collection<? extends Iterable<?>> combination,
Frame frame)
Puts the result of
#flatMapRoleBindings(Pattern, Collection) into the frame. |
void |
setMaxLoops(int maxLoops) |
void |
setRepeatWhileMatches(boolean repeatWhileMatches) |
protected abstract Collection<?> |
wrapAdvancedRoleInstances(Role role,
String roleName,
Collection<?> currentInstances,
AbstractEplModule.LazyAdvancedRoleInstancesInitializer initializer) |
protected abstract Collection<?> |
wrapBasicRoleInstances(Role role,
String roleName,
AbstractEplModule.LazyBasicRoleInstancesInitializer initializer)
Wraps the result of
preprocessRoleInstances(Role, String) into the specified collection. |
calculateSuperRules, execute, execute, executeImpl, getDeclaredPost, getDeclaredPre, getPost, getPre, postExecution, prepareExecution
checkImports, clearCache, compile, execute, getCompilationContext, getDeclaredModelDeclarations, getDeclaredOperations, getImports, getImportsByExtension, getMain, getModelDelcarations, getOperations, getParentModule, getPostOperationStatements, prepareContext, setContext, setMain, setParentModule, toString
assignAnnotations, assignComment, assignComments, createAst, extractComments, getParseProblems, getSourceFile, getSourceUri, invokeMainRule, parse, parse
equals, getChildren, getComments, getDebugInfo, getFile, getModule, getParent, getRegion, getUri, hashCode, setModule, setParent, setRegion, setUri
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getMaximumLevel
getDeclaredPost, getDeclaredPre, getPost, getPre
configure, execute, getCompilationContext, getConfigurationProperties, getDeclaredModelDeclarations, getDeclaredOperations, getImports, getMain, getModelDelcarations, getOperations, getParentModule, getParseProblems, getPostOperationStatements, parse, setContext, setParentModule
public static final int INFINITE
protected boolean repeatWhileMatchesFound
protected int maxLoops
protected String patternMatchModelName
public AbstractEplModule()
public AbstractEplModule(IEplContext context)
public IEplContext getContext()
getContext
in interface IEolModule
getContext
in interface IErlModule
getContext
in class ErlModule
protected org.antlr.runtime.Lexer createLexer(org.antlr.runtime.ANTLRInputStream inputStream)
createLexer
in class ErlModule
public EpsilonParser createParser(org.antlr.runtime.TokenStream tokenStream)
createParser
in class ErlModule
public String getMainRule()
getMainRule
in class ErlModule
public HashMap<String,Class<?>> getImportConfiguration()
getImportConfiguration
in class ErlModule
public ModuleElement adapt(AST cst, ModuleElement parentAst)
public void build(AST cst, IModule module)
build
in interface ModuleElement
build
in class ErlModule
protected Object processRules() throws EolRuntimeException
ErlModule
processRules
in class ErlModule
EolRuntimeException
public List<Pattern> getDeclaredPatterns()
getDeclaredPatterns
in interface IEplModule
public List<Pattern> getPatterns()
getPatterns
in interface IEplModule
public int getMaxLoops()
getMaxLoops
in interface IEplModule
public void setMaxLoops(int maxLoops)
setMaxLoops
in interface IEplModule
public boolean isRepeatWhileMatches()
isRepeatWhileMatches
in interface IEplModule
public void setRepeatWhileMatches(boolean repeatWhileMatches)
setRepeatWhileMatches
in interface IEplModule
public final PatternMatchModel matchPatterns() throws EolRuntimeException
matchPatterns
in interface IEplModule
EolRuntimeException
public Collection<PatternMatch> match(Pattern pattern) throws EolRuntimeException
matchPatterns(int, PatternMatchModel)
) and the low-level ones (e.g.
getRoleInstances(Role, String)
). matchCombination(Collection, Pattern)
, and so the sole responsibility
of this method is to loop through the combinations returned by getCandidates(Pattern)
and collect all the results. Subclasses may override this method to alter the type of collection
returned and/or alter the looping mechanism.match
in interface IEplModule
EolRuntimeException
protected final Optional<PatternMatch> matchCombination(Collection<? extends Iterable<?>> combination, Pattern pattern) throws EolRuntimeException
combination
- The values to use for role bindings.pattern
- EolRuntimeException
protected PatternMatchModel createModel() throws EolRuntimeException
EolRuntimeException
protected void preMatch(PatternMatchModel model) throws EolRuntimeException
EolRuntimeException
protected Set<PatternMatch> matchPatterns(int level, PatternMatchModel model) throws EolRuntimeException
IEplModule#match()
to the match model
for all patterns at the specified level.EolRuntimeException
protected final void postProcessMatches(int level, Collection<PatternMatch> matches) throws EolRuntimeException
executeDoBlock(ExecutableBlock, Map)
method.EolRuntimeException
protected Object executeDoBlock(ExecutableBlock<?> doBlock, Map<String,Object> roleBindings) throws EolRuntimeException
doBlock
- The block to execute.roleBindings
- The effective collection of variables.null
.EolRuntimeException
protected final boolean getMatchResult(Pattern pattern) throws EolRuntimeException
pattern
- the pattern being executedcontext
- the contexttrue
if the pattern does not define a match block.EolRuntimeException
- if the result is not a boolean.protected PatternMatch createPatternMatch(Pattern pattern, Collection<? extends Iterable<?>> combination)
#flatMapRoleBindings(Pattern, Iterable)
protected static final Collection<Variable> flatMapRoleBindings(Collection<Role> roles, Collection<? extends Iterable<?>> combination)
pattern.getRoles()
and combination
collections first.roles
- The roles of a pattern.combination
- The instances for each binding. Note that the inner iterable's size must
be equal to the number of names in the role. However the outer size (that is,
combination.size()
) need not necessarily be equal to the number of roles in the pattern.protected static Collection<Variable> getVariables(Iterable<?> bindings, Role role)
bindings
- The elements to map to each role name. Note that the number
of objects returned by the iterator must be equal to the number of role names.role
- protected static final int putRoleBindingsIntoFrame(Collection<Role> roles, Collection<? extends Iterable<?>> combination, Frame frame)
#flatMapRoleBindings(Pattern, Collection)
into the frame.roles
- combinations
- frame
- protected boolean isValidCombination(Pattern pattern, List<? extends Iterable<?>> combination) throws EolRuntimeException
pattern
- combination
- EolRuntimeException
protected abstract Iterator<? extends Collection<? extends Iterable<?>>> getCandidates(Pattern pattern) throws EolRuntimeException
pattern.getRoles().size()
)
RoleExecutor#getRoleInstances(Role, String)
multiplied by
the number of names for that role (i.e. getRoleInstances(role).size()*role.getNames().size()
).
pattern
- EolRuntimeException
protected final Collection<?> getRoleInstances(Role role, String roleName) throws EolRuntimeException
#negativeGuard(ExecutableBlock, Collection)
and/or #filterElements(ExecutableBlock, Collection)
methods as these involve executing guard
blocks for each element. If even greater control is desired (e.g. to change the return type of the
collection), subclasses can override the intermediate methods, which are:
role
- roleName
- The name to which instances will be bound when executing the guard block. This
will always come from role.getNames()
EolRuntimeException
protected abstract Collection<?> wrapBasicRoleInstances(Role role, String roleName, AbstractEplModule.LazyBasicRoleInstancesInitializer initializer) throws EolRuntimeException
preprocessRoleInstances(Role, String)
into the specified collection.role
- roleName
- initializer
- Method reference to preprocessRoleInstances(Role, String)
.EolRuntimeException
protected abstract Collection<?> wrapAdvancedRoleInstances(Role role, String roleName, Collection<?> currentInstances, AbstractEplModule.LazyAdvancedRoleInstancesInitializer initializer) throws EolRuntimeException
role
- roleName
- currentInstances
- The values returned from wrapBasicRoleInstances(Role, String, LazyBasicRoleInstancesInitializer)
.initializer
- Method reference to getNegativeRoleInstances(Role, String, Collection)
or getAllRoleInstances(Role, String, Collection)
.EolRuntimeException
protected boolean negativeGuard(ExecutableBlock<Boolean> guard, String roleName, Collection<?> currentInstances) throws EolRuntimeException
getNegativeRoleInstances(Role, String, Collection)
guard
- currentInstances
- The model elements of the negative role.EolRuntimeException
protected Collection<?> filterElements(ExecutableBlock<Boolean> guard, String roleName, Collection<?> currentInstances) throws EolRuntimeException
getAllRoleInstances(Role, String, Collection)
guard
- currentInstances
- The model elements of the role.EolRuntimeException
Copyright © 2020. All rights reserved.