@Test public void numeric_literal() throws Exception { Tree tree = tree("42", Kind.NUMERIC_LITERAL); Optional<ProgramState> newState = new LiteralProgramPoint(tree).execute(ProgramState.emptyState()); assertThat(resultingConstraint(newState)).isEqualTo(Constraint.POSITIVE_NUMBER_PRIMITIVE); }
@Override public Optional<ProgramState> execute(ProgramState state) { ExpressionStack stack = state.getStack(); ExpressionStack stackAfterExecution = stack.apply(newStack -> { SymbolicValue value = SpecialSymbolicValue.UNDEFINED; if (tree.is(Kind.NULL_LITERAL)) { value = SpecialSymbolicValue.NULL; } else if (tree.is(Kind.NUMERIC_LITERAL, Kind.STRING_LITERAL, Kind.BOOLEAN_LITERAL, Kind.REGULAR_EXPRESSION_LITERAL)) { value = LiteralSymbolicValue.get((LiteralTree) tree); } else if (tree.is(Kind.ARRAY_LITERAL)) { pop(newStack, ((ArrayLiteralTree) tree).elements().size()); value = new SymbolicValueWithConstraint(Constraint.ARRAY); } else if (tree.is(Kind.OBJECT_LITERAL)) { popObjectLiteralProperties(newStack, (ObjectLiteralTree) tree); value = new SymbolicValueWithConstraint(Constraint.OTHER_OBJECT); } else if (tree.is(Kind.TEMPLATE_LITERAL)) { pop(newStack, ((TemplateLiteralTree) tree).expressions().size()); value = new SymbolicValueWithConstraint(Constraint.STRING_PRIMITIVE); } newStack.push(value); }); return Optional.of(state.withStack(stackAfterExecution)); }
LiteralProgramPoint implements ProgramPoint { @Override public Optional<ProgramState> execute(ProgramState state) { ExpressionStack stack = state.getStack(); ExpressionStack stackAfterExecution = stack.apply(newStack -> { SymbolicValue value = SpecialSymbolicValue.UNDEFINED; if (tree.is(Kind.NULL_LITERAL)) { value = SpecialSymbolicValue.NULL; } else if (tree.is(Kind.NUMERIC_LITERAL, Kind.STRING_LITERAL, Kind.BOOLEAN_LITERAL, Kind.REGULAR_EXPRESSION_LITERAL)) { value = LiteralSymbolicValue.get((LiteralTree) tree); } else if (tree.is(Kind.ARRAY_LITERAL)) { pop(newStack, ((ArrayLiteralTree) tree).elements().size()); value = new SymbolicValueWithConstraint(Constraint.ARRAY); } else if (tree.is(Kind.OBJECT_LITERAL)) { popObjectLiteralProperties(newStack, (ObjectLiteralTree) tree); value = new SymbolicValueWithConstraint(Constraint.OTHER_OBJECT); } else if (tree.is(Kind.TEMPLATE_LITERAL)) { pop(newStack, ((TemplateLiteralTree) tree).expressions().size()); value = new SymbolicValueWithConstraint(Constraint.STRING_PRIMITIVE); } newStack.push(value); }); return Optional.of(state.withStack(stackAfterExecution)); } }
LiteralProgramPoint implements ProgramPoint { @Override public Optional<ProgramState> execute(ProgramState state) { ExpressionStack stack = state.getStack(); ExpressionStack stackAfterExecution = stack.apply(newStack -> { SymbolicValue value = SpecialSymbolicValue.UNDEFINED; if (tree.is(Kind.NULL_LITERAL)) { value = SpecialSymbolicValue.NULL; } else if (tree.is(Kind.NUMERIC_LITERAL, Kind.STRING_LITERAL, Kind.BOOLEAN_LITERAL, Kind.REGULAR_EXPRESSION_LITERAL)) { value = LiteralSymbolicValue.get((LiteralTree) tree); } else if (tree.is(Kind.ARRAY_LITERAL)) { pop(newStack, ((ArrayLiteralTree) tree).elements().size()); value = new SymbolicValueWithConstraint(Constraint.ARRAY); } else if (tree.is(Kind.OBJECT_LITERAL)) { popObjectLiteralProperties(newStack, (ObjectLiteralTree) tree); value = new SymbolicValueWithConstraint(Constraint.OTHER_OBJECT); } else if (tree.is(Kind.TEMPLATE_LITERAL)) { pop(newStack, ((TemplateLiteralTree) tree).expressions().size()); value = new SymbolicValueWithConstraint(Constraint.STRING_PRIMITIVE); } newStack.push(value); }); return Optional.of(state.withStack(stackAfterExecution)); } LiteralProgramPoint(Tree tree); }
LiteralProgramPoint implements ProgramPoint { @Override public Optional<ProgramState> execute(ProgramState state) { ExpressionStack stack = state.getStack(); ExpressionStack stackAfterExecution = stack.apply(newStack -> { SymbolicValue value = SpecialSymbolicValue.UNDEFINED; if (tree.is(Kind.NULL_LITERAL)) { value = SpecialSymbolicValue.NULL; } else if (tree.is(Kind.NUMERIC_LITERAL, Kind.STRING_LITERAL, Kind.BOOLEAN_LITERAL, Kind.REGULAR_EXPRESSION_LITERAL)) { value = LiteralSymbolicValue.get((LiteralTree) tree); } else if (tree.is(Kind.ARRAY_LITERAL)) { pop(newStack, ((ArrayLiteralTree) tree).elements().size()); value = new SymbolicValueWithConstraint(Constraint.ARRAY); } else if (tree.is(Kind.OBJECT_LITERAL)) { popObjectLiteralProperties(newStack, (ObjectLiteralTree) tree); value = new SymbolicValueWithConstraint(Constraint.OTHER_OBJECT); } else if (tree.is(Kind.TEMPLATE_LITERAL)) { pop(newStack, ((TemplateLiteralTree) tree).expressions().size()); value = new SymbolicValueWithConstraint(Constraint.STRING_PRIMITIVE); } newStack.push(value); }); return Optional.of(state.withStack(stackAfterExecution)); } LiteralProgramPoint(Tree tree); static boolean originatesFrom(Tree element); @Override Optional<ProgramState> execute(ProgramState state); }
LiteralProgramPoint implements ProgramPoint { @Override public Optional<ProgramState> execute(ProgramState state) { ExpressionStack stack = state.getStack(); ExpressionStack stackAfterExecution = stack.apply(newStack -> { SymbolicValue value = SpecialSymbolicValue.UNDEFINED; if (tree.is(Kind.NULL_LITERAL)) { value = SpecialSymbolicValue.NULL; } else if (tree.is(Kind.NUMERIC_LITERAL, Kind.STRING_LITERAL, Kind.BOOLEAN_LITERAL, Kind.REGULAR_EXPRESSION_LITERAL)) { value = LiteralSymbolicValue.get((LiteralTree) tree); } else if (tree.is(Kind.ARRAY_LITERAL)) { pop(newStack, ((ArrayLiteralTree) tree).elements().size()); value = new SymbolicValueWithConstraint(Constraint.ARRAY); } else if (tree.is(Kind.OBJECT_LITERAL)) { popObjectLiteralProperties(newStack, (ObjectLiteralTree) tree); value = new SymbolicValueWithConstraint(Constraint.OTHER_OBJECT); } else if (tree.is(Kind.TEMPLATE_LITERAL)) { pop(newStack, ((TemplateLiteralTree) tree).expressions().size()); value = new SymbolicValueWithConstraint(Constraint.STRING_PRIMITIVE); } newStack.push(value); }); return Optional.of(state.withStack(stackAfterExecution)); } LiteralProgramPoint(Tree tree); static boolean originatesFrom(Tree element); @Override Optional<ProgramState> execute(ProgramState state);  }