congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
InfixOpNode
Code IndexAdd Tabnine to your IDE (free)

How to use
InfixOpNode
in
org.kie.dmn.feel.lang.ast

Best Java code snippets using org.kie.dmn.feel.lang.ast.InfixOpNode (Showing top 20 results out of 315)

origin: org.kie/kie-dmn-feel

public static InfixOpNode newInfixOpNode(ParserRuleContext ctx, BaseNode left, String op, BaseNode right) {
  return new InfixOpNode( ctx, left, op, right );
}
origin: org.kie/kie-dmn-feel

/**
 * FEEL spec Table 45
 * Delegates to {@link InfixOpNode} except evaluationcontext
 */
public static Object add(Object left, Object right) {
  return InfixOpNode.add(left, right, null);
}
origin: org.kie/kie-dmn-feel

/**
 * FEEL spec Table 38
 * Delegates to {@link InfixOpNode} except evaluationcontext
 */
public static Object and(Object left, Object right) {
  return InfixOpNode.and(left, right, null);
}
origin: org.kie/kie-dmn-feel

@Override
public DirectCompilerResult visit(InfixOpNode n) {
  DirectCompilerResult left = n.getLeft().accept(this);
  DirectCompilerResult right = n.getRight().accept(this);
  MethodCallExpr expr = Expressions.binary(
      n.getOperator(),
      left.getExpression(),
      right.getExpression());
  return DirectCompilerResult.of(expr, BuiltInType.UNKNOWN).withFD(left).withFD(right);
}
origin: org.kie/kie-dmn-feel

switch ( operator ) {
  case ADD:
    return add( left, right, ctx );
  case SUB:
    return sub( left, right, ctx );
  case MULT:
    return mult( left, right, ctx );
  case DIV:
    return div( left, right, ctx );
  case POW:
    return math( left, right, ctx, (l, r) -> BigDecimalMath.pow( l, r, MathContext.DECIMAL128 ) );
  case AND:
    return and( left, right, ctx );
  case OR:
    return or( left, right, ctx );
  case LTE:
    return EvalHelper.compare( left, right, ctx, (l, r) -> l.compareTo( r ) <= 0 );
origin: org.kie/kie-dmn-feel

@Test
public void testComparisonInFixOp() {
  String inputExpression = "foo >= bar * 10";
  BaseNode infix = parse( inputExpression );
  assertThat( infix, is( instanceOf( InfixOpNode.class ) ) );
  assertThat( infix.getResultType(), is( BuiltInType.BOOLEAN ) );
  assertThat( infix.getText(), is( inputExpression ) );
  InfixOpNode in = (InfixOpNode) infix;
  assertThat( in.getLeft(), is( instanceOf( NameRefNode.class ) ) );
  assertThat( in.getLeft().getText(), is( "foo" ) );
  assertThat( in.getRight(), is( instanceOf( InfixOpNode.class ) ) );
  assertThat( in.getRight().getText(), is( "bar * 10" ) );
}
origin: org.kie/kie-dmn-feel

public static Object pow(Object left, Object right) {
  return InfixOpNode.math(left, right, null, (l, r) -> BigDecimalMath.pow(l, r, MathContext.DECIMAL128));
}
origin: org.kie/kie-dmn-feel

/**
 * FEEL spec Table 45
 * Delegates to {@link InfixOpNode} except evaluationcontext
 */
public static Object div(Object left, Object right) {
  return InfixOpNode.div(left, right, null);
}
origin: org.kie/kie-dmn-feel

/**
 * FEEL spec Table 45
 * Delegates to {@link InfixOpNode} except evaluationcontext
 */
public static Object mult(Object left, Object right) {
  return InfixOpNode.mult(left, right, null);
}
origin: org.kie/kie-dmn-feel

} else if( param instanceof InNode ) {
  return ASTBuilderFactory.newFunctionInvocationNode( ctx, name, params );
} else if( param instanceof InfixOpNode && ((InfixOpNode)param).isBoolean() ) {
  return ASTBuilderFactory.newFunctionInvocationNode( ctx, name, params );
} else if (param instanceof FunctionInvocationNode) {
origin: org.kie/kie-dmn-feel

@Test
public void testConditionalLogicalOp() {
  String inputExpression = "foo < 10 and bar = \"x\" or baz";
  BaseNode infix = parse( inputExpression );
  assertThat( infix, is( instanceOf( InfixOpNode.class ) ) );
  assertThat( infix.getResultType(), is( BuiltInType.BOOLEAN ) );
  assertThat( infix.getText(), is( inputExpression ) );
  InfixOpNode or = (InfixOpNode) infix;
  assertThat( or.getLeft(), is( instanceOf( InfixOpNode.class ) ) );
  assertThat( or.getLeft().getText(), is( "foo < 10 and bar = \"x\"" ) );
  assertThat( or.getOperator(), is( InfixOpNode.InfixOperator.OR ) );
  assertThat( or.getRight(), is( instanceOf( NameRefNode.class ) ) );
  assertThat( or.getRight().getText(), is( "baz" ) );
  InfixOpNode and = (InfixOpNode) or.getLeft();
  assertThat( and.getLeft(), is( instanceOf( InfixOpNode.class ) ) );
  assertThat( and.getLeft().getText(), is( "foo < 10" ) );
  assertThat( and.getOperator(), is( InfixOpNode.InfixOperator.AND ) );
  assertThat( and.getRight(), is( instanceOf( InfixOpNode.class ) ) );
  assertThat( and.getRight().getText(), is( "bar = \"x\"" ) );
}
origin: org.kie/kie-dmn-feel

public static Object mult(Object left, Object right, EvaluationContext ctx) {
  if ( left == null || right == null ) {
    return null;
  } else if ( left instanceof Duration && right instanceof Number ) {
    return ((Duration)left).multipliedBy( ((Number) right).longValue() );
  } else if ( left instanceof Number && right instanceof Duration ) {
    return Duration.ofSeconds( EvalHelper.getBigDecimalOrNull( left ).multiply( EvalHelper.getBigDecimalOrNull( ((Duration)right).getSeconds() ), MathContext.DECIMAL128 ).longValue() );
  } else if ( left instanceof Duration && right instanceof Duration ) {
    return EvalHelper.getBigDecimalOrNull( ((Duration) left).getSeconds() ).multiply( EvalHelper.getBigDecimalOrNull( ((Duration)right).getSeconds() ), MathContext.DECIMAL128 );
  } else if ( left instanceof Period && right instanceof Number ) {
    return Period.ofMonths( EvalHelper.getBigDecimalOrNull( ((Period)left).toTotalMonths() ).multiply( EvalHelper.getBigDecimalOrNull( ((Number) right).longValue() ), MathContext.DECIMAL128 ).intValue() );
  } else if ( left instanceof Number && right instanceof Period ) {
    return Period.ofMonths( EvalHelper.getBigDecimalOrNull( left ).multiply( EvalHelper.getBigDecimalOrNull( ((Period)right).toTotalMonths() ), MathContext.DECIMAL128 ).intValue() );
  } else if ( left instanceof Period && right instanceof Period ) {
    return EvalHelper.getBigDecimalOrNull( ((Period) left).toTotalMonths() ).multiply( EvalHelper.getBigDecimalOrNull( ((Period)right).toTotalMonths() ), MathContext.DECIMAL128 );
  } else {
    return math( left, right, ctx, (l, r) -> l.multiply( r, MathContext.DECIMAL128 ) );
  }
}
origin: org.kie/kie-dmn-feel

public static Object div(Object left, BigDecimal right) {
  return right == null || right.signum() == 0 ? null : InfixOpNode.div(left, right, null);
}
origin: org.kie/kie-dmn-feel

@Test
public void testPower1() {
  String inputExpression = "y * 5 ** 3";
  BaseNode infix = parse( inputExpression, mapOf(entry("y", BuiltInType.NUMBER)) );
  assertThat( infix, is( instanceOf( InfixOpNode.class ) ) );
  assertThat( infix.getResultType(), is( BuiltInType.NUMBER ) );
  assertThat( infix.getText(), is( inputExpression ) );
  InfixOpNode mult = (InfixOpNode) infix;
  assertThat( mult.getLeft(), is( instanceOf( NameRefNode.class ) ) );
  assertThat( mult.getLeft().getText(), is( "y" ) );
  assertThat( mult.getOperator(), is( InfixOpNode.InfixOperator.MULT ) );
  assertThat( mult.getRight(), is( instanceOf( InfixOpNode.class ) ) );
  assertThat( mult.getRight().getText(), is( "5 ** 3" ) );
  InfixOpNode exp = (InfixOpNode) mult.getRight();
  assertThat( exp.getLeft(), is( instanceOf( NumberNode.class ) ) );
  assertThat( exp.getLeft().getText(), is( "5" ) );
  assertThat( exp.getOperator(), is( InfixOpNode.InfixOperator.POW ) );
  assertThat( exp.getRight(), is( instanceOf( NumberNode.class ) ) );
  assertThat( exp.getRight().getText(), is( "3" ) );
}
origin: org.kie/kie-dmn-feel

public static Object div(Object left, Object right, EvaluationContext ctx) {
  if ( left == null || right == null ) {
    return null;
  } else if ( left instanceof Duration && right instanceof Number ) {
    return ((Duration)left).dividedBy( ((Number) right).longValue() );
  } else if ( left instanceof Number && right instanceof Duration ) {
    return Duration.ofSeconds( EvalHelper.getBigDecimalOrNull( left ).divide( EvalHelper.getBigDecimalOrNull( ((Duration)right).getSeconds() ), MathContext.DECIMAL128 ).longValue() );
  } else if ( left instanceof Duration && right instanceof Duration ) {
    return EvalHelper.getBigDecimalOrNull( ((Duration) left).getSeconds() ).divide( EvalHelper.getBigDecimalOrNull( ((Duration)right).getSeconds() ), MathContext.DECIMAL128 );
  } else if ( left instanceof Period && right instanceof Number ) {
    return Period.ofMonths( EvalHelper.getBigDecimalOrNull( ((Period)left).toTotalMonths() ).divide( EvalHelper.getBigDecimalOrNull( ((Number) right).longValue() ), MathContext.DECIMAL128 ).intValue() );
  } else if ( left instanceof Number && right instanceof Period ) {
    return Period.ofMonths( EvalHelper.getBigDecimalOrNull( left ).divide( EvalHelper.getBigDecimalOrNull( ((Period)right).toTotalMonths() ), MathContext.DECIMAL128 ).intValue() );
  } else if ( left instanceof Period && right instanceof Period ) {
    return EvalHelper.getBigDecimalOrNull( ((Period) left).toTotalMonths() ).divide( EvalHelper.getBigDecimalOrNull( ((Period)right).toTotalMonths() ), MathContext.DECIMAL128 );
  } else {
    return math( left, right, ctx, (l, r) -> l.divide( r, MathContext.DECIMAL128 ) );
  }
}
origin: org.kie/kie-dmn-feel

@Test
public void testAdd1() {
  String inputExpression = "y + 5 * 3";
  BaseNode infix = parse( inputExpression, mapOf(entry("y", BuiltInType.NUMBER)) );
  assertThat( infix, is( instanceOf( InfixOpNode.class ) ) );
  assertThat( infix.getResultType(), is( BuiltInType.NUMBER ) );
  assertThat( infix.getText(), is( inputExpression ) );
  InfixOpNode add = (InfixOpNode) infix;
  assertThat( add.getLeft(), is( instanceOf( NameRefNode.class ) ) );
  assertThat( add.getLeft().getText(), is( "y" ) );
  assertThat( add.getOperator(), is( InfixOpNode.InfixOperator.ADD ) );
  assertThat( add.getRight(), is( instanceOf( InfixOpNode.class ) ) );
  assertThat( add.getRight().getText(), is( "5 * 3" ) );
  InfixOpNode mult = (InfixOpNode) add.getRight();
  assertThat( mult.getLeft(), is( instanceOf( NumberNode.class ) ) );
  assertThat( mult.getLeft().getText(), is( "5" ) );
  assertThat( mult.getOperator(), is( InfixOpNode.InfixOperator.MULT ) );
  assertThat( mult.getRight(), is( instanceOf( NumberNode.class ) ) );
  assertThat( mult.getRight().getText(), is( "3" ) );
}
origin: org.kie/kie-dmn-feel

  return ((OffsetTime) left).minus( (Duration) right);
} else {
  return math( left, right, ctx, (l, r) -> l.subtract( r, MathContext.DECIMAL128 )  );
origin: org.kie/kie-dmn-feel

@Test
public void testPower3() {
  String inputExpression = "y ** 5 * 3";
  BaseNode infix = parse( inputExpression, mapOf(entry("y", BuiltInType.NUMBER)) );
  assertThat( infix, is( instanceOf( InfixOpNode.class ) ) );
  assertThat( infix.getResultType(), is( BuiltInType.NUMBER ) );
  assertThat( infix.getText(), is( inputExpression ) );
  InfixOpNode mult = (InfixOpNode) infix;
  assertThat( mult.getLeft(), is( instanceOf( InfixOpNode.class ) ) );
  assertThat( mult.getLeft().getText(), is( "y ** 5" ) );
  assertThat( mult.getOperator(), is( InfixOpNode.InfixOperator.MULT ) );
  assertThat( mult.getRight(), is( instanceOf( NumberNode.class ) ) );
  assertThat( mult.getRight().getText(), is( "3" ) );
  InfixOpNode exp = (InfixOpNode) mult.getLeft();
  assertThat( exp.getLeft(), is( instanceOf( NameRefNode.class ) ) );
  assertThat( exp.getLeft().getText(), is( "y" ) );
  assertThat( exp.getOperator(), is( InfixOpNode.InfixOperator.POW ) );
  assertThat( exp.getRight(), is( instanceOf( NumberNode.class ) ) );
  assertThat( exp.getRight().getText(), is( "5" ) );
}
origin: org.kie/kie-dmn-feel

  return ((OffsetTime) right).plus( (Duration) left);
} else {
  return math( left, right, ctx, (l, r) -> l.add( r, MathContext.DECIMAL128 ) );
origin: org.kie/kie-dmn-feel

@Test
public void testPower4() {
  String inputExpression = "y ** ( 5 * 3 )";
  BaseNode infix = parse( inputExpression, mapOf(entry("y", BuiltInType.NUMBER)) );
  assertThat( infix, is( instanceOf( InfixOpNode.class ) ) );
  assertThat( infix.getResultType(), is( BuiltInType.NUMBER ) );
  assertThat( infix.getText(), is( inputExpression ) );
  InfixOpNode exp = (InfixOpNode) infix;
  assertThat( exp.getLeft(), is( instanceOf( NameRefNode.class ) ) );
  assertThat( exp.getLeft().getText(), is( "y" ) );
  assertThat( exp.getOperator(), is( InfixOpNode.InfixOperator.POW ) );
  assertThat( exp.getRight(), is( instanceOf( InfixOpNode.class ) ) );
  assertThat( exp.getRight().getText(), is( "5 * 3" ) );
  InfixOpNode mult = (InfixOpNode) exp.getRight();
  assertThat( mult.getLeft(), is( instanceOf( NumberNode.class ) ) );
  assertThat( mult.getLeft().getText(), is( "5" ) );
  assertThat( mult.getOperator(), is( InfixOpNode.InfixOperator.MULT ) );
  assertThat( mult.getRight(), is( instanceOf( NumberNode.class ) ) );
  assertThat( mult.getRight().getText(), is( "3" ) );
}
org.kie.dmn.feel.lang.astInfixOpNode

Most used methods

  • getLeft
  • getOperator
  • getRight
  • <init>
  • add
  • and
    Implements the ternary logic AND operation
  • div
  • isBoolean
  • math
  • mult
  • or
    Implements the ternary logic OR operation
  • sub
  • or,
  • sub

Popular in Java

  • Updating database using SQL prepared statement
  • onCreateOptionsMenu (Activity)
  • requestLocationUpdates (LocationManager)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • Enumeration (java.util)
    A legacy iteration interface.New code should use Iterator instead. Iterator replaces the enumeration
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
  • TimeUnit (java.util.concurrent)
    A TimeUnit represents time durations at a given unit of granularity and provides utility methods to
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • JList (javax.swing)
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now