/** * Analyzes the given source code and populates the constraint. * * @param source the source code of the constraint */ public void analyzeSource(String source) { // First analyze the expressions contained in the source: ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(); List<Expression> expressions = expressionAnalyzer.analyzeExpressions(source); // Transform all the expressions replacing methods and fields with parameters and attributes: expressions = expressions.stream().map(this::transform).collect(Collectors.toList()); // Add the resulting expressions to the constraint: constraint.addExpressions(expressions); }
@Override public String toString() { return getName().toString() + expressions.stream().map(Expression::toString).collect(joining(",", "[", "]")); } }
private void analyzeConstraint(JavaMethod javaMethod, Method method) { // Create the constraint: Constraint constraint = new Constraint(); analyzeName(javaMethod, constraint); analyzeAnnotations(javaMethod, constraint); analyzeDocumentation(javaMethod, constraint); // Get the direction: if (isAnnotatedWith(javaMethod, ModelAnnotations.IN)) { constraint.setIn(true); } if (isAnnotatedWith(javaMethod, ModelAnnotations.OUT)) { constraint.setOut(true); } // Get the source: String source = javaMethod.getSourceCode(); constraint.setSource(source); // Remember to analyze the constraint source once the types and services have been completely defined: undefinedConstraints.add(constraint); // Add the constraint to the method: constraint.setDeclaringMethod(method); method.addConstraint(constraint); }
/** * Parse the source of the given constraint. */ private void parseConstraint(Constraint constraint) { ConstraintAnalyzer analyzer = new ConstraintAnalyzer(); analyzer.setModel(model); analyzer.setMethod(constraint.getDeclaringMethod()); analyzer.setConstraint(constraint); analyzer.analyzeSource(constraint.getSource()); }