Class StringResolver<I extends VariableDeclaration,R extends Resolver<I>,E extends ExpressionStatement>
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.expressions.StringParser<CompositeExpression,I,R>
-
- net.ssehub.easy.instantiation.core.model.expressions.StringResolver<I,R,E>
-
- Type Parameters:
I- the actual variable declaration typeR- the actual resolver typeE- the actual expression statement type
- All Implemented Interfaces:
IMessageReceiver
public class StringResolver<I extends VariableDeclaration,R extends Resolver<I>,E extends ExpressionStatement> extends StringParser<CompositeExpression,I,R> implements IMessageReceiver
StringResolver to resolve variables and expressions on compiling. Use the StringReplacer if you need to replace expressions or variables on runtime.- Author:
- Sass, Eichelberger
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceStringResolver.IExpressionTranslator<I extends VariableDeclaration,R extends Resolver<I>>The general interface of an expression translator.-
Nested classes/interfaces inherited from class net.ssehub.easy.instantiation.core.model.expressions.StringParser
StringParser.State
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<Expression>expressionsprivate StringResolver.IExpressionTranslator<I,R>translatorprivate java.lang.StringBuilderwarnings
-
Constructor Summary
Constructors Modifier Constructor Description privateStringResolver(java.lang.String text, R resolver, StringResolver.IExpressionTranslator<I,R> translator, java.lang.StringBuilder warnings, IStringParserFactory<I> factory)Creates a replacer instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidappendWarning(java.lang.String message)Appends message as a warning.static voidappendWarning(java.lang.StringBuilder warnings, java.lang.String message)Appends message as a warning.voidcollect(IMessage message, org.eclipse.emf.ecore.EObject cause, org.eclipse.emf.ecore.EStructuralFeature causeFeature, int code)Receives an EASy message.protected CompositeExpressioncreateParseResult()Creates the result of parsing a string.voiderror(java.lang.String message, org.eclipse.emf.ecore.EObject cause, org.eclipse.emf.ecore.EStructuralFeature causeFeature, int code)Receives an error message.private voidhandleConstant(int curStart, int position)Handle constant placeholder fromcurStartuntilposition.private java.util.List<Expression>handleConstant(java.lang.String text)Handle constant for a given text.protected inthandleEndOfText(int curStart, int pos, StringParser.State state)Handles the very end of text at so far unhandled state.protected inthandleExpression(int curStart, int pos)Handle an expression placeholder.protected voidhandleQuote(int pos)Called to handle a quote character atpos(beginning) of the internal parse buffer.protected voidhandleTextEnd(int curStart, int pos)Handles the end of the text if there is no variable/expression.protected inthandleVariable(int curStart, int pos)Handle a variable placeholder.protected inthandleVariableStartExpression(int curStart, int pos)Handles the transition from stateStringParser.State.VARIABLE_STARTtoStringParser.State.EXPRESSION.protected inthandleVariableStartVariable(int curStart, int pos)Handles the transition from stateStringParser.State.VARIABLE_STARTtoStringParser.State.VARIABLE.protected ExpressionparseExpressionImpl(java.lang.String expressionString)Parses an expression fromexpressionString.protected CompositeExpressionresolveVariable(java.lang.String text)Handle variable.static <I extends VariableDeclaration,R extends Resolver<I>,E extends ExpressionStatement>
Expressionsubstitute(java.lang.String text, R resolver, StringResolver.IExpressionTranslator<I,R> translator, java.lang.StringBuilder warnings, IStringParserFactory<I> factory)Substitutes a given text and returns a CompositeExpression.voidwarning(java.lang.String message, org.eclipse.emf.ecore.EObject cause, org.eclipse.emf.ecore.EStructuralFeature causeFeature, int code)Receives a warning message.-
Methods inherited from class net.ssehub.easy.instantiation.core.model.expressions.StringParser
addExpression, charAt, clearStatementStack, consume, consumeJavaIdentifierPart, consumeWhitespaces, createConstantStringExpression, delete, deleteCharAt, getCurrentInPlaceCommand, getFactory, getLogger, getResolver, handleInPlaceCommands, isNonEmptyCommandStack, join, length, notifyBracketsClosed, notifyEndInPlaceCommand, notifyStartInPlaceCommand, parse, parseExpression, popFromCommandStack, removePrefix, replace, setPos, substring, toText, warnParsingIgnoring
-
-
-
-
Field Detail
-
translator
private StringResolver.IExpressionTranslator<I extends VariableDeclaration,R extends Resolver<I>> translator
-
warnings
private java.lang.StringBuilder warnings
-
expressions
private java.util.List<Expression> expressions
-
-
Constructor Detail
-
StringResolver
private StringResolver(java.lang.String text, R resolver, StringResolver.IExpressionTranslator<I,R> translator, java.lang.StringBuilder warnings, IStringParserFactory<I> factory)Creates a replacer instance.- Parameters:
text- the text to be analyzedtranslator- the translator to be usedresolver- the resolver to be usedwarnings- to collect warnings (may be null)factory- a factory turning in-place commands into language-specific expressions (may be null, then in-place commands are not resolved but remain as string expressions)
-
-
Method Detail
-
substitute
public static <I extends VariableDeclaration,R extends Resolver<I>,E extends ExpressionStatement> Expression substitute(java.lang.String text, R resolver, StringResolver.IExpressionTranslator<I,R> translator, java.lang.StringBuilder warnings, IStringParserFactory<I> factory) throws VilException
Substitutes a given text and returns a CompositeExpression.- Type Parameters:
I- the variable declaration typeR- the resolver typeE- the expression statement type- Parameters:
text- the text to be analyzedresolver- the resolver to be used.translator- the translator to be used.warnings- an optional (may be null buffer to collect warningsfactory- a factory turning in-place commands into language-specific expressions (may be null, then in-place commands are not resolved but remain as string expressions)- Returns:
- a
CompositeExpression - Throws:
VilException- delegates the exception
-
createParseResult
protected CompositeExpression createParseResult() throws VilException
Description copied from class:StringParserCreates the result of parsing a string.- Specified by:
createParseResultin classStringParser<CompositeExpression,I extends VariableDeclaration,R extends Resolver<I>>- Returns:
- the result
- Throws:
VilException- in case of evaluation problems- See Also:
StringParser.parse()
-
handleQuote
protected void handleQuote(int pos) throws VilExceptionDescription copied from class:StringParserCalled to handle a quote character atpos(beginning) of the internal parse buffer.- Specified by:
handleQuotein classStringParser<CompositeExpression,I extends VariableDeclaration,R extends Resolver<I>>- Parameters:
pos- the position within the parse buffer- Throws:
VilException- in case of evaluation problems
-
handleTextEnd
protected void handleTextEnd(int curStart, int pos) throws VilExceptionDescription copied from class:StringParserHandles the end of the text if there is no variable/expression.- Specified by:
handleTextEndin classStringParser<CompositeExpression,I extends VariableDeclaration,R extends Resolver<I>>- Parameters:
curStart- the start positionpos- the actual position (end of text)- Throws:
VilException- in case of evaluation problems
-
handleVariableStartExpression
protected int handleVariableStartExpression(int curStart, int pos) throws VilExceptionDescription copied from class:StringParserHandles the transition from stateStringParser.State.VARIABLE_STARTtoStringParser.State.EXPRESSION.- Specified by:
handleVariableStartExpressionin classStringParser<CompositeExpression,I extends VariableDeclaration,R extends Resolver<I>>- Parameters:
curStart- the start positionpos- the actual position- Returns:
- the next start position (typically
pos, ignored if negative) - Throws:
VilException- in case of evaluation problems
-
handleVariableStartVariable
protected int handleVariableStartVariable(int curStart, int pos) throws VilExceptionDescription copied from class:StringParserHandles the transition from stateStringParser.State.VARIABLE_STARTtoStringParser.State.VARIABLE.- Specified by:
handleVariableStartVariablein classStringParser<CompositeExpression,I extends VariableDeclaration,R extends Resolver<I>>- Parameters:
curStart- the start positionpos- the actual position- Returns:
- the next start position (typically
pos, ignored if negative) - Throws:
VilException- in case of evaluation problems
-
handleEndOfText
protected int handleEndOfText(int curStart, int pos, StringParser.State state) throws VilExceptionDescription copied from class:StringParserHandles the very end of text at so far unhandled state.- Specified by:
handleEndOfTextin classStringParser<CompositeExpression,I extends VariableDeclaration,R extends Resolver<I>>- Parameters:
curStart- the start positionpos- the current positionstate- the current state- Returns:
- the next start position (typically
pos, ignored if negative) - Throws:
VilException- in case of evaluation problems
-
handleExpression
protected int handleExpression(int curStart, int pos) throws VilExceptionDescription copied from class:StringParserHandle an expression placeholder.startpoints to "${",posto "}". name.- Specified by:
handleExpressionin classStringParser<CompositeExpression,I extends VariableDeclaration,R extends Resolver<I>>- Parameters:
curStart- the start positionpos- the actual/end position- Returns:
- the next start position (typically
pos, ignored if negative) - Throws:
VilException- in case of evaluation problems- See Also:
StringParser.parse()
-
parseExpressionImpl
protected Expression parseExpressionImpl(java.lang.String expressionString) throws VilException
Description copied from class:StringParserParses an expression fromexpressionString.- Specified by:
parseExpressionImplin classStringParser<CompositeExpression,I extends VariableDeclaration,R extends Resolver<I>>- Parameters:
expressionString- the string representation of the expression- Returns:
- the parsed expression
- Throws:
VilException- in case that parsing/creating the expression fails
-
handleConstant
private void handleConstant(int curStart, int position) throws VilExceptionHandle constant placeholder fromcurStartuntilposition.- Parameters:
curStart- the current start positionposition- the actual position in the text.- Throws:
VilException- in case of evaluation problems
-
handleConstant
private java.util.List<Expression> handleConstant(java.lang.String text) throws VilException
Handle constant for a given text. Splits the text into constants by seperating the string on whitespaces.- Parameters:
text- to be analyzed- Returns:
- List of ConstantExpressions
- Throws:
VilException- in case of evaluation problems
-
resolveVariable
protected CompositeExpression resolveVariable(java.lang.String text)
Handle variable.- Parameters:
text- the variable name- Returns:
- CompositeExpression containing the variable
-
handleVariable
protected int handleVariable(int curStart, int pos) throws VilExceptionDescription copied from class:StringParserHandle a variable placeholder.startpoints to "$",posto the end position of the variable name.- Specified by:
handleVariablein classStringParser<CompositeExpression,I extends VariableDeclaration,R extends Resolver<I>>- Parameters:
curStart- the start positionpos- the actual/end position- Returns:
- the next start position (typically
pos, ignored if negative) - Throws:
VilException- in case of evaluation problems- See Also:
StringParser.parse()
-
error
public void error(java.lang.String message, org.eclipse.emf.ecore.EObject cause, org.eclipse.emf.ecore.EStructuralFeature causeFeature, int code)Description copied from interface:IMessageReceiverReceives an error message.- Specified by:
errorin interfaceIMessageReceiver- Parameters:
message- the messagecause- the cause (as instance of the EMF grammar model)causeFeature- the cause of the feature as an appropriate constant fromIvmlPackage.Literalscode- a numerical identification of the error
-
warning
public void warning(java.lang.String message, org.eclipse.emf.ecore.EObject cause, org.eclipse.emf.ecore.EStructuralFeature causeFeature, int code)Description copied from interface:IMessageReceiverReceives a warning message.- Specified by:
warningin interfaceIMessageReceiver- Parameters:
message- the messagecause- the cause (as instance of the EMF grammar model)causeFeature- the cause of the feature as an appropriate constant fromIvmlPackage.Literalscode- a numerical identification of the warning
-
collect
public void collect(IMessage message, org.eclipse.emf.ecore.EObject cause, org.eclipse.emf.ecore.EStructuralFeature causeFeature, int code)
Description copied from interface:IMessageReceiverReceives an EASy message. This allows re-directing the message while keeping the relation to the original one, e.g., for cleaning up messages.- Specified by:
collectin interfaceIMessageReceiver- Parameters:
message- the messagecause- the cause (as instance of the EMF grammar model)causeFeature- the cause of the feature as an appropriate constant fromIvmlPackage.Literalscode- a numerical identification of the error
-
appendWarning
private void appendWarning(java.lang.String message)
Appends message as a warning.- Parameters:
message- the message to append
-
appendWarning
public static void appendWarning(java.lang.StringBuilder warnings, java.lang.String message)Appends message as a warning.- Parameters:
warnings- the warnings collected so far, nothing will happen if nullmessage- the message to append
-
-