Skip to content

Commit

Permalink
Fixes #455
Browse files Browse the repository at this point in the history
- Updated migrant and parser versions to 2.4.0 (fixes DW expression parenthesis removal after migration)
- Fixed toInstanceOf and toExceptionFunction Migrator methods
  • Loading branch information
olamiral-mulesoft authored and jesica-fera committed Mar 14, 2022
1 parent ccae224 commit a4d91fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.mulesoft.tools

import java.util
import java.util.Date

import com.mulesoft.tools.ast._
import com.mulesoft.tools.{ast => mel}
import org.mule.weave.v2.grammar._
Expand All @@ -13,6 +12,7 @@ import org.mule.weave.v2.parser.ast.header.HeaderNode
import org.mule.weave.v2.parser.ast.structure.schema.{SchemaNode, SchemaPropertyNode}
import org.mule.weave.v2.parser.ast.types.TypeReferenceNode
import org.mule.weave.v2.parser.ast.variables.{NameIdentifier, VariableReferenceNode}
import org.mule.weave.v2.parser.location.UnknownLocation
import org.mule.weave.v2.parser.{ast => dw}

import scala.util.{Failure, Success, Try}
Expand Down Expand Up @@ -146,15 +146,15 @@ object Migrator {
val rRes = toDataweaveAst(right)
val variableReferenceNode = VariableReferenceNode(NameIdentifier("Java::isInstanceOf"))
val metadata = lRes.metadata.children ++ rRes.metadata.children
val classNameNode = dw.structure.StringNode(rRes.getGeneratedCode(HeaderNode(Seq())).replaceFirst("---\nvars\\.", "")).annotate(QuotedStringAnnotation('''))
val classNameNode = dw.structure.StringNode(rRes.getGeneratedCode(HeaderNode(Seq())).replaceFirst("(---\n){0,1}vars\\.", "")).annotate(QuotedStringAnnotation('''))
new MigrationResult(dw.functions.FunctionCallNode(variableReferenceNode, FunctionCallParametersNode(Seq(lRes.dwAstNode, classNameNode))), DefaultMigrationMetadata(JavaModuleRequired() +: metadata))
}

private def toExceptionFunction(functionName: String, parametersNode: MelExpressionNode, strictMatch: Boolean) = {
val parameters = toDataweaveAst(parametersNode)
val metadata = parameters.metadata.children
val variableReferenceNode = VariableReferenceNode(NameIdentifier("Java::isCausedBy"))
val classNameNode = dw.structure.StringNode(parameters.getGeneratedCode(HeaderNode(Seq())).replaceFirst("---\nvars\\.", "")).annotate(QuotedStringAnnotation('''))
val classNameNode = dw.structure.StringNode(parameters.getGeneratedCode(HeaderNode(Seq())).replaceFirst("(---\n){0,1}vars\\.", "")).annotate(QuotedStringAnnotation('''))
val errorCauseNode = dw.structure.StringNode("error.cause")
val strictMatchNode = dw.structure.BooleanNode(strictMatch.toString)
new MigrationResult(dw.functions.FunctionCallNode(variableReferenceNode, FunctionCallParametersNode(Seq(errorCauseNode, classNameNode, strictMatchNode))),DefaultMigrationMetadata(JavaModuleRequired() +: metadata))
Expand Down Expand Up @@ -225,7 +225,7 @@ object Migrator {

private def toDataweaveEnclosedExpressionNode(expression: MelExpressionNode): MigrationResult = {
val result = toDataweaveAst(expression)
new MigrationResult(result.dwAstNode.annotate(EnclosedMarkAnnotation()), DefaultMigrationMetadata(result.metadata.children))
new MigrationResult(result.dwAstNode.annotate(EnclosedMarkAnnotation(UnknownLocation)), DefaultMigrationMetadata(result.metadata.children))
}

private def toDataweaveConstructorNode(canonicalName: CanonicalNameNode, arguments: Seq[MelExpressionNode]): MigrationResult = {
Expand Down Expand Up @@ -272,7 +272,7 @@ object Migrator {
val objectNode = dw.structure.ArrayNode(Seq())
val classValue = dw.structure.StringNode(canonicalName.name)
//class: "java.util.ArrayList"
val schemaProperty = SchemaPropertyNode(NameIdentifier(CLASS_PROPERTY_NAME), classValue)
val schemaProperty = SchemaPropertyNode(NameIdentifier(CLASS_PROPERTY_NAME), classValue, None)
val arrayTypeRef = TypeReferenceNode(NameIdentifier("Array"), None, Some(SchemaNode(Seq(schemaProperty))))
new MigrationResult(dw.operators.BinaryOpNode(AsOpId, objectNode, arrayTypeRef))
}
Expand All @@ -281,7 +281,7 @@ object Migrator {
val objectNode = dw.structure.ObjectNode(Seq())
val classValue = dw.structure.StringNode(canonicalName.name)
//class: "java.util.HashMap"
val schemaProperty = SchemaPropertyNode(NameIdentifier(CLASS_PROPERTY_NAME), classValue)
val schemaProperty = SchemaPropertyNode(NameIdentifier(CLASS_PROPERTY_NAME), classValue, None)
val objectTypeRef = TypeReferenceNode(NameIdentifier("Object"), None, Some(SchemaNode(Seq(schemaProperty))))
new MigrationResult(dw.operators.BinaryOpNode(AsOpId, objectNode, objectTypeRef))
}
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@
<munit.version>2.2.1</munit.version>

<mule.api.version>1.1.5</mule.api.version>
<migrant.version>2.1.10</migrant.version>
<parser.version>2.1.3</parser.version>
<migrant.version>2.4.0</migrant.version>
<parser.version>2.4.0</parser.version>

<!-- Properties -->
<lib-dir>${basedir}/lib</lib-dir>
Expand Down

0 comments on commit a4d91fd

Please sign in to comment.