Class StringResolver<I extends VariableDeclaration,​R extends Resolver<I>,​E extends ExpressionStatement>

  • Type Parameters:
    I - the actual variable declaration type
    R - the actual resolver type
    E - 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
    • 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 analyzed
        translator - the translator to be used
        resolver - the resolver to be used
        warnings - 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 ExpressionStatementExpression 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 type
        R - the resolver type
        E - the expression statement type
        Parameters:
        text - the text to be analyzed
        resolver - the resolver to be used.
        translator - the translator to be used.
        warnings - an optional (may be null buffer to collect warnings
        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)
        Returns:
        a CompositeExpression
        Throws:
        VilException - delegates the exception
      • handleConstant

        private void handleConstant​(int curStart,
                                    int position)
                             throws VilException
        Handle constant placeholder from curStart until position.
        Parameters:
        curStart - the current start position
        position - 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
      • 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: IMessageReceiver
        Receives an error message.
        Specified by:
        error in interface IMessageReceiver
        Parameters:
        message - the message
        cause - the cause (as instance of the EMF grammar model)
        causeFeature - the cause of the feature as an appropriate constant from IvmlPackage.Literals
        code - 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: IMessageReceiver
        Receives a warning message.
        Specified by:
        warning in interface IMessageReceiver
        Parameters:
        message - the message
        cause - the cause (as instance of the EMF grammar model)
        causeFeature - the cause of the feature as an appropriate constant from IvmlPackage.Literals
        code - 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: IMessageReceiver
        Receives 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:
        collect in interface IMessageReceiver
        Parameters:
        message - the message
        cause - the cause (as instance of the EMF grammar model)
        causeFeature - the cause of the feature as an appropriate constant from IvmlPackage.Literals
        code - 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 null
        message - the message to append