Class AbstractPathRuleMatchExpression
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.expressions.Expression
-
- net.ssehub.easy.instantiation.core.model.buildlangModel.ruleMatch.AbstractRuleMatchExpression
-
- net.ssehub.easy.instantiation.core.model.buildlangModel.ruleMatch.AbstractPathRuleMatchExpression
-
- Direct Known Subclasses:
CompoundMatchExpression,PathMatchExpression,StringMatchExpression
public abstract class AbstractPathRuleMatchExpression extends AbstractRuleMatchExpression
Path matching expressions.- Author:
- Holger Eichelberger
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classAbstractPathRuleMatchExpression.MatchStateDefines matching states.
-
Field Summary
Fields Modifier and Type Field Description private static intINDEX_LEFTprivate static intINDEX_RIGHTprivate static java.lang.StringMULTIPLE_CHAR_MATCHprivate static charMULTIPLE_CHAR_MATCH_CHARprivate static java.lang.StringNORMALIZED_FILE_SEPARATORprivate static charNORMALIZED_FILE_SEPARATOR_CHARprivate static java.lang.StringSINGLE_CHAR_MATCHprivate static charSINGLE_CHAR_MATCH_CHAR
-
Constructor Summary
Constructors Constructor Description AbstractPathRuleMatchExpression()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private static booleancontainsWildcards(java.util.List<java.lang.String> tokens)Returns whethertokenscontains wildcards.booleancontributesTo(AbstractRuleMatchExpression expression)Returns whether this rule match expression may contribute to the fulfillment ofexpression.java.lang.ObjectdetermineExpected(AbstractRuleMatchExpression rhsExpr, java.lang.Object rhsValue)Determines the expected value on the left side (represented by this object) based on the actual value for the corresponding right side.private static AbstractPathRuleMatchExpression.MatchStatedetermineNextState(java.lang.String text, int pos, int lastPos, AbstractPathRuleMatchExpression.MatchState state)Determines the next matching state at the given position intext.private static AbstractPathRuleMatchExpression.MatchStatedetermineState(java.lang.String text, int pos)Determines the current matching state at the given position intext.protected abstract PathgetResolved()Returns the resolved expression.private static booleanisPatternChar(char ch)Returns whetherchbelongs to a pattern.private static booleanisWildcard(java.lang.String token)Returns whethertokenis a wildcard.private static voidmatch(java.util.List<java.lang.String> tokens, java.lang.String valueText)Matches thetokensagainst the (matching!)value, removes common parts and replaces wildcards.static booleanoverlaps(java.lang.String leftPattern, int lPos, java.lang.String rightPattern, int rPos)Returns whether theleftPatternandrightPatternmatch, i.e., whether the matches on one side can be considered as the same or a subset of the matches on the other side.static booleanoverlaps(java.lang.String leftPattern, java.lang.String rightPattern)Returns whether theleftPatternandrightPatternmatch, i.e., whether the matches on one side can be considered as the same or a subset of the matches on the other side.private static java.lang.StringpreparePattern(java.lang.String pattern)Prepares the given pattern conventions.static java.lang.Stringreplace(java.lang.String lhsPattern, java.lang.String rhsPattern, java.lang.String rhsValue)Replaces the wildcards inlhsPatternwith corresponding wildcard matches inrhsPatternderived fromrhsValue.private static java.lang.StringreplaceWildcards(java.util.List<java.lang.String> tokens, java.util.List<java.lang.String> values)Replaces the wildcards intokensby the values invalues.private static java.util.List<java.lang.String>tokenize(java.lang.String text, boolean considerSeparator)Tokenizes the given path according to wildcards.private static booleantryAndTrackBack(java.lang.String leftPattern, AbstractPathRuleMatchExpression.MatchState leftState, java.lang.String rightPattern, AbstractPathRuleMatchExpression.MatchState rightState, int[] pos)Tries a match at the offsets determined by the states and tracks back if the match cannot be made.-
Methods inherited from class net.ssehub.easy.instantiation.core.model.buildlangModel.ruleMatch.AbstractRuleMatchExpression
accept, accept, ensureType, evaluate, getEntryType, inferType
-
Methods inherited from class net.ssehub.easy.instantiation.core.model.expressions.Expression
replaceEmptyLine
-
-
-
-
Field Detail
-
MULTIPLE_CHAR_MATCH_CHAR
private static final char MULTIPLE_CHAR_MATCH_CHAR
- See Also:
- Constant Field Values
-
SINGLE_CHAR_MATCH_CHAR
private static final char SINGLE_CHAR_MATCH_CHAR
- See Also:
- Constant Field Values
-
NORMALIZED_FILE_SEPARATOR_CHAR
private static final char NORMALIZED_FILE_SEPARATOR_CHAR
- See Also:
- Constant Field Values
-
MULTIPLE_CHAR_MATCH
private static final java.lang.String MULTIPLE_CHAR_MATCH
-
SINGLE_CHAR_MATCH
private static final java.lang.String SINGLE_CHAR_MATCH
-
NORMALIZED_FILE_SEPARATOR
private static final java.lang.String NORMALIZED_FILE_SEPARATOR
-
INDEX_LEFT
private static final int INDEX_LEFT
- See Also:
- Constant Field Values
-
INDEX_RIGHT
private static final int INDEX_RIGHT
- See Also:
- Constant Field Values
-
-
Method Detail
-
getResolved
protected abstract Path getResolved()
Returns the resolved expression.- Returns:
- the resolved expression
-
determineExpected
public java.lang.Object determineExpected(AbstractRuleMatchExpression rhsExpr, java.lang.Object rhsValue) throws VilException
Description copied from class:AbstractRuleMatchExpressionDetermines the expected value on the left side (represented by this object) based on the actual value for the corresponding right side.- Specified by:
determineExpectedin classAbstractRuleMatchExpression- Parameters:
rhsExpr- the (resolved) RHS expressionrhsValue- the RHS value- Returns:
- the expected LHS value (null denotes no expectation)
- Throws:
VilException- in case that determining the expected object fails
-
contributesTo
public boolean contributesTo(AbstractRuleMatchExpression expression)
Description copied from class:AbstractRuleMatchExpressionReturns whether this rule match expression may contribute to the fulfillment ofexpression.- Specified by:
contributesToin classAbstractRuleMatchExpression- Parameters:
expression- the expression to be considered (typically a RHS expression, while this is a LHS expression)- Returns:
trueif this rule may contribute,falseelse
-
overlaps
public static boolean overlaps(java.lang.String leftPattern, java.lang.String rightPattern)Returns whether theleftPatternandrightPatternmatch, i.e., whether the matches on one side can be considered as the same or a subset of the matches on the other side.- Parameters:
leftPattern- the first pattern to match (LHS)rightPattern- the right pattern to match (RHS)- Returns:
trueif the patterns overlap,falseelse
-
overlaps
public static boolean overlaps(java.lang.String leftPattern, int lPos, java.lang.String rightPattern, int rPos)Returns whether theleftPatternandrightPatternmatch, i.e., whether the matches on one side can be considered as the same or a subset of the matches on the other side. This method executes the implied recognizing state machines in intertwined fashion and stops as soon as no match is possible anymore.- Parameters:
leftPattern- the first pattern to match (LHS)lPos- the position to start from withinleftPatternrightPattern- the right pattern to match (RHS)rPos- the position to start from withinrightPattern- Returns:
trueif the patterns overlap,falseelse
-
tryAndTrackBack
private static boolean tryAndTrackBack(java.lang.String leftPattern, AbstractPathRuleMatchExpression.MatchState leftState, java.lang.String rightPattern, AbstractPathRuleMatchExpression.MatchState rightState, int[] pos)Tries a match at the offsets determined by the states and tracks back if the match cannot be made.- Parameters:
leftPattern- the left patternleftState- the matching state for the left patternrightPattern- the right patternrightState- the matching state for the right patternpos- the current positions, at index 0 for left pattern, at index 1 for right- Returns:
trueif a match was found at the given positions,falseelse
-
preparePattern
private static java.lang.String preparePattern(java.lang.String pattern)
Prepares the given pattern conventions.- Parameters:
pattern- the pattern to be prepared- Returns:
- the prepared pattern, may be
patternif nothing is changed
-
isPatternChar
private static boolean isPatternChar(char ch)
Returns whetherchbelongs to a pattern.- Parameters:
ch- the char to be tested- Returns:
trueifchbelongs to a pattern,falseelse
-
determineNextState
private static AbstractPathRuleMatchExpression.MatchState determineNextState(java.lang.String text, int pos, int lastPos, AbstractPathRuleMatchExpression.MatchState state)
Determines the next matching state at the given position intext.- Parameters:
text- the text to be consideredpos- the actual position withintextlastPos- the last position wherestatewas determinedstate- the actual state (determined at lastPos)- Returns:
- the current state or null if
posis invalid
-
determineState
private static AbstractPathRuleMatchExpression.MatchState determineState(java.lang.String text, int pos)
Determines the current matching state at the given position intext.- Parameters:
text- the text to be consideredpos- the actual position withintext- Returns:
- the current state or null if
posis invalid
-
replace
public static java.lang.String replace(java.lang.String lhsPattern, java.lang.String rhsPattern, java.lang.String rhsValue)Replaces the wildcards inlhsPatternwith corresponding wildcard matches inrhsPatternderived fromrhsValue.- Parameters:
lhsPattern- the pattern to be filledrhsPattern- the pattern to be used use to determine the valuesrhsValue- the value string (must matchrhsPattern)- Returns:
lhsPatternwith resolved wildcards or the originallhsPatternifrhsValuedoes not matchrhsValueorlhsPatternhas no wildcards
-
isWildcard
private static boolean isWildcard(java.lang.String token)
Returns whethertokenis a wildcard.- Parameters:
token- the token to be tested- Returns:
trueiftokenis a wildcard,falseelse
-
containsWildcards
private static boolean containsWildcards(java.util.List<java.lang.String> tokens)
Returns whethertokenscontains wildcards.- Parameters:
tokens- the tokens to be tested- Returns:
trueiftokenscontains wildcards,falseelse
-
match
private static void match(java.util.List<java.lang.String> tokens, java.lang.String valueText)Matches thetokensagainst the (matching!)value, removes common parts and replaces wildcards. Prerequisit:valuealready matchestokens!- Parameters:
tokens- the tokens to consider and to be modified as a side effectvalueText- the value
-
replaceWildcards
private static java.lang.String replaceWildcards(java.util.List<java.lang.String> tokens, java.util.List<java.lang.String> values)Replaces the wildcards intokensby the values invalues. Replacement happens as long as values are available.- Parameters:
tokens- the tokens to be considered for creating the resultvalues- the values replacing wildcards in sequence- Returns:
- the concatenated tokens and replaced wildcards
-
tokenize
private static java.util.List<java.lang.String> tokenize(java.lang.String text, boolean considerSeparator)Tokenizes the given path according to wildcards.- Parameters:
text- the text to be tokenizedconsiderSeparator- tokenize also separators- Returns:
- the tokens
-
-