Skip to content

Commit b82e619

Browse files
committed
[#753] Add transformer to correct the variable names. Improve error handling in DMN environment factory.
1 parent 66e6eaa commit b82e619

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

dmn-core/src/main/java/com/gs/dmn/error/ErrorFactory.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
*/
1313
package com.gs.dmn.error;
1414

15-
import com.gs.dmn.ast.TDMNElement;
16-
import com.gs.dmn.ast.TDefinitions;
17-
import com.gs.dmn.ast.TExpression;
18-
import com.gs.dmn.ast.TNamedElement;
15+
import com.gs.dmn.ast.*;
1916
import com.gs.dmn.el.analysis.semantics.type.Type;
2017
import com.gs.dmn.el.analysis.syntax.ast.expression.Expression;
2118
import org.apache.commons.lang3.StringUtils;
@@ -65,7 +62,13 @@ private static String makeExpressionErrorMessage(TDefinitions definitions, TDMNE
6562
}
6663

6764
private static String expressionDescription(Object expression) {
68-
return expression == null ? null : expression.toString();
65+
if (expression == null) {
66+
return null;
67+
} else if (expression instanceof TLiteralExpression) {
68+
return ((TLiteralExpression) expression).getText();
69+
} else {
70+
return expression.toString();
71+
}
6972
}
7073

7174
public static String makeErrorMessage(String location, String errorMessage) {

dmn-core/src/main/java/com/gs/dmn/transformation/basic/StandardDMNEnvironmentFactory.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -550,18 +550,19 @@ public Type toFEELType(TDefinitions model, QualifiedName typeRef) {
550550
private Type toFEELTypeNoCache(TDefinitions model, QualifiedName typeRef) {
551551
// Lookup item definitions
552552
if (model != null) {
553-
TItemDefinition itemDefinition = this.dmnModelRepository.lookupItemDefinition(model, typeRef);
554-
if (itemDefinition != null) {
555-
return toFEELType(itemDefinition);
556-
}
553+
TItemDefinition itemDefinition = this.dmnModelRepository.lookupItemDefinition(model, typeRef);
554+
if (itemDefinition != null) {
555+
return toFEELType(itemDefinition);
556+
}
557557
}
558558

559559
// Lookup primitive types
560560
Type primitiveType = lookupPrimitiveType(typeRef);
561561
if (primitiveType != null) {
562562
return primitiveType;
563563
}
564-
throw new SemanticError(String.format("Cannot map type '%s' to FEEL", typeRef));
564+
565+
throw new SemanticError(ErrorFactory.makeDMNErrorMessage(model, null, String.format("Cannot map type '%s' to FEEL", typeRef)));
565566
}
566567

567568
@Override
@@ -821,7 +822,7 @@ private Environment makeEnvironmentNoCache(TDRGElement element) {
821822

822823
return elementEnvironment;
823824
} catch (Exception e) {
824-
throw new SemanticError(ErrorFactory.makeDMNErrorMessage(definitions, element, e.getMessage()), e);
825+
throw new SemanticError(ErrorFactory.makeDMNErrorMessage(definitions, element, "Cannot create environment due to semantic errors"), e);
825826
}
826827
}
827828

0 commit comments

Comments
 (0)