Class ExprCompiler<T extends org.faktorips.codegen.CodeFragment>
- Direct Known Subclasses:
JavaExprCompiler
JavaExprCompiler.
This class is not thread safe!
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe Expression calls a function, which could be resolved to several functions.static final StringThe expression contains a data type that can not be instantiated by this compiler.static final StringAn internal compiler error occurred during compilation.static final StringThe expression has a lexical error.static final StringAn identifier is resolved to an association but the association's target can't be found.static final StringAn identifier is resolved to an 1to1 association but an index is also provided.static final StringThe expression contains a the expressionnull.static final StringThe prefix for all compiler messages.static final StringThe expression has a syntax error, it does not confirm to the grammar.static final StringThe expression contains a call to an undefined function.static final StringAn identifier can't be resolved.static final StringThe operation like +, *, - can't be done on the provided types.static final StringA qualifier can't be resolved.static final StringThe expression contains a function call to a function with wrong argument types.static final StringThe expression contains a literal that is identified by the parser as a money literal that doesn't have a valid currency. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new compiler.ExprCompiler(Locale locale) Creates a new compiler.ExprCompiler(Locale locale, IdentifierResolver<T> identifierResolver, org.faktorips.codegen.ConversionCodeGenerator<T> conversionCg, DatatypeHelperProvider<T> datatypeHelperProvider) Creates a new Compiler. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(FunctionResolver<T> fctResolver) Adds the function resolver to the ones used by the compiler to resolve function calls in expressions.Compiles the given expression string intosource code.protected abstract TconvertPrimitiveToWrapper(org.faktorips.datatype.Datatype resultType, T codeFragment) getAmbiguousFunctions(FlFunction<T>[] functions) Returns a Set of ambiguousFlFunctions, which the parser could not differentiate.getBinaryOperation(String operator, AbstractCompilationResult<T> lhsResult, AbstractCompilationResult<T> rhsResult) org.faktorips.codegen.ConversionCodeGenerator<T>Returns theConversionCodeGeneratorthat defines the compiler's implicit conversions, e.g.org.faktorips.codegen.BaseDatatypeHelper<T>getDatatypeHelper(org.faktorips.datatype.Datatype type) Returns thecode generation helperfor the given type ornullif no helper is available.booleanReturns the compiler'sEnsureResultIsObjectproperty.FlFunction<T>[]Return the functions supported by the compiler.Returns the resolver the compiler uses to resolve identifiers.Returns theLocalethe compiler uses for it'smessages.static org.faktorips.datatype.util.LocalizedStringsSetgetMatchingFunctionUsingConversion(CompilationResult<T>[] argResults, org.faktorips.datatype.Datatype[] argTypes, String fctName) getMatchingFunctionUsingConversionSingleArgument(AbstractCompilationResult<T> argResult, org.faktorips.datatype.Datatype argTypes, String fctName) static final booleanisValidIdentifier(String identifier) Verifies if the provided string is a valid identifier according to the identifier definition of the Fl-Parser.protected abstract AbstractCompilationResult<T>newCompilationResultImpl(org.faktorips.runtime.Message message) protected abstract AbstractCompilationResult<T>newCompilationResultImpl(T sourcecode, org.faktorips.datatype.Datatype datatype) protected abstract ParseTreeVisitor<T>protected SimpleNodeprotected CompilationResult<T>voidregister(BinaryOperation<T> op) Registers the binary operation.voidregister(UnaryOperation<T> op) Registers the unary operation.protected abstract voidRegisters the default operations.voidremove(FunctionResolver<T> fctResolver) Removes the function resolver from the ones used by the compiler to resolve function calls.voidsetBinaryOperations(BinaryOperation<T>[] operations) Sets theBinaryOperationsthe compiler uses.voidsetConversionCodeGenerator(org.faktorips.codegen.ConversionCodeGenerator<T> ccg) Sets theConversionCodeGeneratorthat the compiler uses for implicit conversions, e.g.voidsetDatatypeHelperProvider(DatatypeHelperProvider<T> provider) voidsetEnsureResultIsObject(boolean newValue) Sets the compiler'sEnsureResultIsObjectproperty.voidsetIdentifierResolver(IdentifierResolver<T> resolver) Sets theIdentifierResolverthe compiler uses to resolve identifiers.voidSets theLocalethe compiler uses to generate it'smessages.voidsetUnaryOperations(UnaryOperation<T>[] operations) Sets theUnaryOperationsthe compiler uses.
-
Field Details
-
PREFIX
The prefix for all compiler messages.- See Also:
-
INTERNAL_ERROR
An internal compiler error occurred during compilation. This message is generated if the compiler fails because of a bug, there is nothing wrong with the expression.- See Also:
-
SYNTAX_ERROR
The expression has a syntax error, it does not confirm to the grammar.Example: 2 + + b does not conform to the grammar.
- See Also:
-
DATATYPE_CREATION_ERROR
The expression contains a data type that can not be instantiated by this compiler.- See Also:
-
LEXICAL_ERROR
The expression has a lexical error.- See Also:
-
UNDEFINED_OPERATOR
The operation like +, *, - can't be done on the provided types.Example: You can't multiply (*) two money values.
- See Also:
-
UNDEFINED_IDENTIFIER
An identifier can't be resolved.Example: a * 2
In the expression a is an identifier and it is possible that it can't be resolved by the {IdentifierResolver} the compiler uses.
- See Also:
-
UNKNOWN_QUALIFIER
A qualifier can't be resolved.Example: a.b(qual)
In the expression a and b are identifiers, qual is a qualifier which does not correspond to any product component's unqualified name.
- See Also:
-
NO_ASSOCIATION_TARGET
An identifier is resolved to an association but the association's target can't be found.Example: a.b.c * 2
In the expression a, b, c are identifiers. If the {IdentifierResolver} the compiler uses can't identify the target types of associations a and b then an error message
NO_ASSOCIATION_TARGETis returned.- See Also:
-
NO_INDEX_FOR_1TO1_ASSOCIATION
An identifier is resolved to an 1to1 association but an index is also provided.Example: a.b[0]
In the expression a and b are identifiers. The identifier b is resolved to a 1to1 association.
- See Also:
-
UNDEFINED_FUNCTION
The expression contains a call to an undefined function.- See Also:
-
WRONG_ARGUMENT_TYPES
The expression contains a function call to a function with wrong argument types.- See Also:
-
WRONG_MONEY_LITERAL
The expression contains a literal that is identified by the parser as a money literal that doesn't have a valid currency.- See Also:
-
AMBIGUOUS_FUNCTION_CALL
The Expression calls a function, which could be resolved to several functions.- See Also:
-
NULL_NOT_ALLOWED
The expression contains a the expressionnull.- See Also:
-
-
Constructor Details
-
ExprCompiler
public ExprCompiler()Creates a new compiler. Messages returned by the compiler are generated using thedefault locale. AConversionCodeGenerator,DatatypeHelperProviderandIdentifierResolvermust be set via the corresponding setters. -
ExprCompiler
Creates a new compiler. AConversionCodeGenerator,DatatypeHelperProviderandIdentifierResolvermust be set via the corresponding setters.- Parameters:
locale- The locale that is used to generate locale dependent messages.
-
ExprCompiler
public ExprCompiler(Locale locale, IdentifierResolver<T> identifierResolver, org.faktorips.codegen.ConversionCodeGenerator<T> conversionCg, DatatypeHelperProvider<T> datatypeHelperProvider) Creates a new Compiler.- Parameters:
locale- theLocaleused to generate locale dependent messagesidentifierResolver- theIdentifierResolverused to convert formula language identifiers to target language codeconversionCg- theConversionCodeGeneratorused to convert betweendata typesdatatypeHelperProvider- theDatatypeHelperProviderused to getDatatypeHelpersthat generate code for the creation and processing of values in their respectivedata types
-
-
Method Details
-
isValidIdentifier
Verifies if the provided string is a valid identifier according to the identifier definition of the Fl-Parser. -
registerDefaults
protected abstract void registerDefaults()Registers the default operations. -
register
Registers the binary operation. -
register
Registers the unary operation. -
setBinaryOperations
Sets theBinaryOperationsthe compiler uses. Overwrites all operations previously registered.- Throws:
IllegalArgumentException- if operations isnull.
-
setUnaryOperations
Sets theUnaryOperationsthe compiler uses. Overwrites all operations previously registered.- Throws:
IllegalArgumentException- if operations isnull.
-
getEnsureResultIsObject
public boolean getEnsureResultIsObject()Returns the compiler'sEnsureResultIsObjectproperty.- See Also:
-
setEnsureResultIsObject
public void setEnsureResultIsObject(boolean newValue) Sets the compiler'sEnsureResultIsObjectproperty. If set totrue, the compiler will check if an expression's type is a Java primitive before returning the result. If the type is a primitive the compiler will convert it to the appropriate wrapper class. E.g. the expression2+4is of type primitive int. If this property is set to true the compiler would wrap the resulting source code with aInteger(..). -
getIdentifierResolver
Returns the resolver the compiler uses to resolve identifiers. -
setIdentifierResolver
Sets theIdentifierResolverthe compiler uses to resolve identifiers.- Throws:
IllegalArgumentException- if resolver is null.
-
getConversionCodeGenerator
Returns theConversionCodeGeneratorthat defines the compiler's implicit conversions, e.g. convert a primitive int to an Integer. -
setConversionCodeGenerator
Sets theConversionCodeGeneratorthat the compiler uses for implicit conversions, e.g. convert a primitive int to an Integer.- Throws:
IllegalArgumentException- if ccg is null.
-
getLocale
Returns theLocalethe compiler uses for it'smessages. -
setLocale
Sets theLocalethe compiler uses to generate it'smessages.- Throws:
IllegalArgumentException- if locale is null.
-
add
Adds the function resolver to the ones used by the compiler to resolve function calls in expressions.- Throws:
IllegalArgumentException- if fctResolver is null.
-
remove
Removes the function resolver from the ones used by the compiler to resolve function calls. If the resolver hasn't been added before, this method does nothing.- Throws:
IllegalArgumentException- if fctResolver is null.
-
getFunctions
Return the functions supported by the compiler. -
getAmbiguousFunctions
Returns a Set of ambiguousFlFunctions, which the parser could not differentiate.Maybe the rolename of a table equals the qualified name of a table structure in the root package.
-
compile
Compiles the given expression string intosource code. If the compilation is not successful, theresultcontainsmessagesthat describe the error/problem that has occurred. If the compilation is successful, the result containssource codethat represents the expression along with the expression'sDatatype. In this case the result does not contain anyerrormessages, but may containwarningsorinformations. -
convertPrimitiveToWrapper
-
newParseTreeVisitor
-
newCompilationResultImpl
protected abstract AbstractCompilationResult<T> newCompilationResultImpl(org.faktorips.runtime.Message message) -
newCompilationResultImpl
protected abstract AbstractCompilationResult<T> newCompilationResultImpl(T sourcecode, org.faktorips.datatype.Datatype datatype) -
parse
- Throws:
ParseException
-
parseExceptionToResult
-
getDatatypeHelperProvider
- Returns:
- Returns the
DatatypeHelperProvider.
-
setDatatypeHelperProvider
- Parameters:
provider- TheDatatypeHelperProviderto set.
-
getDatatypeHelper
public org.faktorips.codegen.BaseDatatypeHelper<T> getDatatypeHelper(org.faktorips.datatype.Datatype type) Returns thecode generation helperfor the given type ornullif no helper is available. -
getLocalizedStrings
public static org.faktorips.datatype.util.LocalizedStringsSet getLocalizedStrings() -
getMatchingFunctionUsingConversion
public CompilationResult<T> getMatchingFunctionUsingConversion(CompilationResult<T>[] argResults, org.faktorips.datatype.Datatype[] argTypes, String fctName) -
getMatchingFunctionUsingConversionSingleArgument
public CompilationResult<T> getMatchingFunctionUsingConversionSingleArgument(AbstractCompilationResult<T> argResult, org.faktorips.datatype.Datatype argTypes, String fctName) -
getBinaryOperation
public CompilationResult<T> getBinaryOperation(String operator, AbstractCompilationResult<T> lhsResult, AbstractCompilationResult<T> rhsResult)
-