Package com.puppetlabs.geppetto.pp

Examples of com.puppetlabs.geppetto.pp.Expression


    checkNumericBinaryExpression(o);
  }

  @Check
  public void checkAppendExpression(AppendExpression o) {
    Expression leftExpr = o.getLeftExpr();
    if(!(leftExpr instanceof VariableExpression))
      acceptor.acceptError(
        "Not an appendable expression", o, PPPackage.Literals.BINARY_EXPRESSION__LEFT_EXPR,
        INSIGNIFICANT_INDEX, IPPDiagnostics.ISSUE__NOT_APPENDABLE);
    else
View Full Code Here


  }

  @Check
  public void checkAssignmentExpression(AssignmentExpression o) {
    Expression leftExpr = o.getLeftExpr();
    if(!(leftExpr instanceof VariableExpression || leftExpr instanceof AtExpression))
      acceptor.acceptError(
        "Not an assignable expression", o, PPPackage.Literals.BINARY_EXPRESSION__LEFT_EXPR,
        INSIGNIFICANT_INDEX, IPPDiagnostics.ISSUE__NOT_ASSIGNABLE);
    if(leftExpr instanceof VariableExpression)
View Full Code Here

      return;
    }

    // Puppet grammar At expression is VARIABLE[expr]([expr])? (i.e. only one nested level).
    //
    final Expression leftExpr = o.getLeftExpr();
    if(leftExpr == null)
      acceptor.acceptError(
        "Expression left of [] is required", o, PPPackage.Literals.PARAMETERIZED_EXPRESSION__LEFT_EXPR,
        INSIGNIFICANT_INDEX, IPPDiagnostics.ISSUE__REQUIRED_EXPRESSION);
    else if(!(leftExpr instanceof VariableExpression || (leftExpr instanceof LiteralNameOrReference && isFirstNameInTE((LiteralNameOrReference) leftExpr)))) {
      // then, the leftExpression *must* be an AtExpression with a leftExpr being a variable
      if(leftExpr instanceof AtExpression) {
        // older versions limited access to two levels.
        if(!advisor().allowMoreThan2AtInSequence()) {
          final Expression nestedLeftExpr = ((AtExpression) leftExpr).getLeftExpr();
          // if nestedLeftExpr is null, it is validated for the nested instance
          if(nestedLeftExpr != null &&
              !(nestedLeftExpr instanceof VariableExpression || (nestedLeftExpr instanceof LiteralNameOrReference && isFirstNameInTE((LiteralNameOrReference) nestedLeftExpr))))
            acceptor.acceptError(
              "Expression left of [] must be a variable.", nestedLeftExpr,
View Full Code Here

   * @param resourceRef
   * @param errorStartText
   */
  public void checkAtExpressionAsResourceReference(AtExpression resourceRef) {
    final String errorStartText = "A resource reference";
    Expression leftExpr = resourceRef.getLeftExpr();
    if(leftExpr == null)
      acceptor.acceptError(
        errorStartText + " must start with a name or referece (was null).", resourceRef,
        PPPackage.Literals.PARAMETERIZED_EXPRESSION__LEFT_EXPR, INSIGNIFICANT_INDEX,
        IPPDiagnostics.ISSUE__RESOURCE_REFERENCE_NO_REFERENCE);
View Full Code Here

    }
  }

  @Check
  public void checkCaseExpression(CaseExpression o) {
    final Expression switchExpr = o.getSwitchExpr();

    boolean theDefaultIsSeen = false;
    // collect unreachable entries to avoid multiple unreachable markers for an entry
    Set<Integer> unreachables = Sets.newHashSet();
    Set<Integer> duplicates = Sets.newHashSet();
    List<Expression> caseExpressions = Lists.newArrayList();
    for(Case caze : o.getCases()) {
      for(Expression e : caze.getValues()) {
        caseExpressions.add(e);

        if(e instanceof LiteralDefault)
          theDefaultIsSeen = true;
      }
    }

    // if a default is seen it should (optionally) appear last
    if(theDefaultIsSeen) {
      IValidationAdvisor advisor = advisor();
      ValidationPreference shouldBeLast = advisor.caseDefaultShouldAppearLast();
      if(shouldBeLast.isWarningOrError()) {
        int last = caseExpressions.size() - 1;
        for(int i = 0; i < last; i++)
          if(caseExpressions.get(i) instanceof LiteralDefault)
            acceptor.accept(
              severity(shouldBeLast), "A 'default' should appear last", caseExpressions.get(i),
              IPPDiagnostics.ISSUE__DEFAULT_NOT_LAST);
      }
    }

    // Check duplicate by equivalence (mark as duplicate)
    // Check equality to switch expression (mark all others as unreachable),
    for(int i = 0; i < caseExpressions.size(); i++) {
      Expression e1 = caseExpressions.get(i);

      // if a case value is equivalent to the switch expression, all other are unreachable
      if(eqCalculator.isEquivalent(e1, switchExpr))
        for(int u = 0; u < caseExpressions.size(); u++)
          if(u != i)
View Full Code Here

  @Check
  public void checkCollectExpression(CollectExpression o) {

    // -- the class reference must have valid class ref format
    final Expression classRefExpr = o.getClassReference();
    if(classRefExpr instanceof LiteralNameOrReference) {
      final String classRefString = ((LiteralNameOrReference) classRefExpr).getValue();
      if(!isCLASSREF(classRefString))
        acceptor.acceptError(
          "Not a well formed class reference.", o, PPPackage.Literals.COLLECT_EXPRESSION__CLASS_REFERENCE,
          INSIGNIFICANT_INDEX, IPPDiagnostics.ISSUE__NOT_CLASSREF);
    }
    else {
      acceptor.acceptError(
        "Not a class reference.", o, PPPackage.Literals.COLLECT_EXPRESSION__CLASS_REFERENCE,
        INSIGNIFICANT_INDEX, IPPDiagnostics.ISSUE__NOT_CLASSREF);
    }

    // -- the rhs expressions do not allow a full set of expressions, an extensive search must be made
    // Note: queries must implement both IQuery and be UnaryExpressions
    UnaryExpression q = (UnaryExpression) o.getQuery();
    Expression queryExpr = q.getExpr();

    // null expression is accepted, if stated it must comply with the simplified expressions allowed
    // for a collect expression
    if(queryExpr != null) {
      CollectChecker cc = new CollectChecker();
View Full Code Here

        switch(te.eClass().getClassifierID()) {
          case PPPackage.VARIABLE_TE:
            replacement = ((VariableTE) te).getVarName();
            break;
          case PPPackage.EXPRESSION_TE:
            Expression expr = ((ExpressionTE) te).getExpression();
            expr = ((ParenthesisedExpression) expr).getExpr();
            if(expr instanceof LiteralNameOrReference)
              replacement = "$" + ((LiteralNameOrReference) expr).getValue();
            break;
          default:
View Full Code Here

  }

  @Check
  public void checkIfExpression(IfExpression o) {
    internalCheckTopLevelExpressions(o.getThenStatements());
    Expression elseStatement = o.getElseStatement();
    if(elseStatement == null || elseStatement instanceof ElseExpression || elseStatement instanceof IfExpression ||
        elseStatement instanceof ElseIfExpression)
      return;
    acceptor.acceptError(
      "If Expression's else part can only be an 'if' or 'elsif'", o,
View Full Code Here

        IPPDiagnostics.ISSUE__UNSUPPORTED_REGEX_FLAGS);
  }

  @Check
  public void checkMatchingExpression(MatchingExpression o) {
    Expression regex = o.getRightExpr();
    if(regex == null || !(regex instanceof LiteralRegex))
      acceptor.acceptError(
        "Right expression must be a regular expression.", o, PPPackage.Literals.BINARY_EXPRESSION__RIGHT_EXPR,
        INSIGNIFICANT_INDEX, IPPDiagnostics.ISSUE__UNSUPPORTED_EXPRESSION);
View Full Code Here

      acceptor.acceptError(
        "A call on the form 'a.b()' is only available in Puppet version >= 3.2 --parser future. (Change target preference?)",
        o, IPPDiagnostics.ISSUE__UNSUPPORTED_METHOD_CALL);
    }
    else {
      Expression methodExpr = o.getMethodExpr();
      if(methodExpr == null)
        acceptor.acceptError("Missing function name after '.'", o, IPPDiagnostics.ISSUE__MISSING_METHOD_NAME);
      if(methodExpr instanceof LiteralName == false)
        acceptor.acceptError("Illegal function name", methodExpr, IPPDiagnostics.ISSUE__UNSUPPORTED_EXPRESSION);
    }
View Full Code Here

TOP

Related Classes of com.puppetlabs.geppetto.pp.Expression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.