Package com.puppetlabs.geppetto.pp

Examples of com.puppetlabs.geppetto.pp.Expression


    if(!(container instanceof PuppetManifest || container instanceof HostClassDefinition))
      acceptor.acceptError(
        "A node definition may only appear at toplevel or directly inside classes.", container,
        o.eContainingFeature(), INSIGNIFICANT_INDEX, IPPDiagnostics.ISSUE__NOT_AT_TOPLEVEL_OR_CLASS);

    Expression parentExpr = o.getParentName();
    if(parentExpr != null) {
      String parentName = stringConstantEvaluator.doToString(parentExpr);
      if(parentName == null)
        acceptor.acceptError(
          "Must be a constant name/string expression.", o, PPPackage.Literals.NODE_DEFINITION__PARENT_NAME,
View Full Code Here


    }
  }

  @Check
  public void checkResourceBody(ResourceBody o) {
    Expression nameExpr = o.getNameExpr();
    // missing name is checked by container (if it is ok or not)
    if(nameExpr == null)
      return;
    if(!(nameExpr instanceof StringExpression ||
        // TODO: was LiteralString, follow up
View Full Code Here

    }
  }

  @Check
  public void checkSelectorEntry(SelectorEntry o) {
    Expression lhs = o.getLeftExpr();
    if(!isSELECTOR_LHS(lhs))
      acceptor.acceptError(
        "Not an acceptable selector entry left hand side expression. Was: " +
            expressionTypeNameProvider.doToString(lhs), o, PPPackage.Literals.BINARY_EXPRESSION__LEFT_EXPR,
        INSIGNIFICANT_INDEX, IPPDiagnostics.ISSUE__UNSUPPORTED_EXPRESSION);
View Full Code Here

    // TODO: check rhs is "rvalue"
  }

  @Check
  public void checkSelectorExpression(SelectorExpression o) {
    Expression lhs = o.getLeftExpr();

    // -- non null lhs, and must be an acceptable lhs value for selector
    if(lhs == null)
      acceptor.acceptError(
        "A selector expression must have a left expression", o,
        PPPackage.Literals.PARAMETERIZED_EXPRESSION__LEFT_EXPR, INSIGNIFICANT_INDEX,
        IPPDiagnostics.ISSUE__NULL_EXPRESSION);
    else if(!isSELECTOR_LHS(lhs))
      acceptor.acceptError(
        "Not an acceptable selector left hand side expression", o,
        PPPackage.Literals.PARAMETERIZED_EXPRESSION__LEFT_EXPR, INSIGNIFICANT_INDEX,
        IPPDiagnostics.ISSUE__UNSUPPORTED_EXPRESSION);

    // -- there must be at least one parameter
    if(o.getParameters().size() < 1)
      acceptor.acceptError(
        "A selector expression must have at least one right side entry", o,
        PPPackage.Literals.PARAMETERIZED_EXPRESSION__PARAMETERS, INSIGNIFICANT_INDEX,
        IPPDiagnostics.ISSUE__NULL_EXPRESSION);

    // -- all parameters must be SelectorEntry instances
    // -- one of them should have LiteralDefault as left expr
    // -- there should only be one default
    boolean theDefaultIsSeen = false;
    IValidationAdvisor advisor = advisor();
    // 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(Expression e : o.getParameters()) {
      if(!(e instanceof SelectorEntry)) {
        acceptor.acceptError(
          "Must be a selector entry. Was:" + expressionTypeNameProvider.doToString(e), o,
          PPPackage.Literals.PARAMETERIZED_EXPRESSION__PARAMETERS, o.getParameters().indexOf(e),
          IPPDiagnostics.ISSUE__UNSUPPORTED_EXPRESSION);
        caseExpressions.add(null); // to be skipped later
      }
      else {
        // it is a selector entry
        SelectorEntry se = (SelectorEntry) e;
        Expression e1 = se.getLeftExpr();
        caseExpressions.add(e1);
        if(e1 instanceof LiteralDefault)
          theDefaultIsSeen = true;
      }
    }

    ValidationPreference defaultLast = advisor.selectorDefaultShouldAppearLast();
    if(defaultLast.isWarningOrError() && theDefaultIsSeen) {
      for(int i = 0; i < caseExpressions.size() - 1; i++) {
        Expression e1 = caseExpressions.get(i);
        if(e1 == null)
          continue;
        if(e1 instanceof LiteralDefault) {
          acceptor.accept(
            severity(defaultLast), "A 'default' should be placed last", e1,
            IPPDiagnostics.ISSUE__DEFAULT_NOT_LAST);
        }
      }
    }

    // check that there is a default
    if(!theDefaultIsSeen) {
      ValidationPreference missingDefaultInSelector = advisor.missingDefaultInSelector();
      if(missingDefaultInSelector.isWarningOrError())
        acceptor.accept(
          severity(missingDefaultInSelector), "Missing 'default' selector case", o,
          IPPDiagnostics.ISSUE__MISSING_DEFAULT);
    }

    // Check unreachable by equivalence
    // If a case expr is the same as the switch, all other are unreachable
    // Check for duplicates
    for(int i = 0; i < caseExpressions.size(); i++) {
      Expression e1 = caseExpressions.get(i);
      if(e1 == null)
        continue;
      if(eqCalculator.isEquivalent(e1, o.getLeftExpr()))
        for(int u = 0; u < caseExpressions.size(); u++) {
          if(i == u || caseExpressions.get(u) == null)
            continue;
          unreachables.add(u);
        }
      for(int j = i + 1; j < caseExpressions.size(); j++) {
        Expression e2 = caseExpressions.get(j);
        if(e2 == null)
          continue;
        if(eqCalculator.isEquivalent(e1, e2)) {
          duplicates.add(i);
          duplicates.add(j);
        }
      }
    }

    for(Integer i : unreachables)
      if(caseExpressions.get(i) != null)
        acceptor.acceptWarning("Unreachable", caseExpressions.get(i), IPPDiagnostics.ISSUE__UNREACHABLE);

    for(Integer i : duplicates)
      if(caseExpressions.get(i) != null)
        acceptor.acceptError(
          "Duplicate selector case", caseExpressions.get(i), IPPDiagnostics.ISSUE__DUPLICATE_CASE);

    // check missing comma between entries
    final int count = o.getParameters().size();
    EList<Expression> params = o.getParameters();
    for(int i = 0; i < count - 1; i++) {
      // do not complain about missing ',' if expression is not a selector entry
      Expression e1 = params.get(i);
      if(e1 instanceof SelectorEntry == false)
        continue;
      INode n = NodeModelUtils.getNode(e1);
      INode n2 = NodeModelUtils.getNode(params.get(i + 1));
View Full Code Here

      return;
    // check that Separator is not first, and that separator expressions are not adjacent
    int limit = statements.size();
    boolean prevSep = false;
    for(int i = 0; i < limit; i++) {
      Expression s = statements.get(i);
      boolean isSep = s instanceof SeparatorExpression;
      if(isSep && (i == 0 || prevSep)) {
        // First is separator, or this is separator and previous was too
        acceptor.acceptError(
          "Empty statement", s.eContainer(), s.eContainingFeature(), i, IPPDiagnostics.ISSUE__EMPTY_STATEMENT);
      }
      prevSep = isSep;
    }
  }
View Full Code Here

    for(int i = limit - 1; i >= 0; i--)
      if(statements.get(i) instanceof SeparatorExpression)
        limit--;

    each_top: for(int i = 0; i < limit; i++) {
      Expression s = statements.get(i);
      // -- may be a non parenthesized function call
      if(s instanceof LiteralNameOrReference) {
        // There must be one more expression in the list (a single argument, or
        // an Expression list) unless the expression is last and allowExprLast (i.e. a return value)
        if((i + 1) >= limit && !allowExprLast) {
          acceptor.acceptError(
            "Not a top level expression. (Looks like a function call without arguments, use '()')",
            s.eContainer(), s.eContainingFeature(), i, IPPDiagnostics.ISSUE__NOT_TOPLEVEL);
          // continue each_top;
        }
        // the next expression is consumed as a single arg, or an expr list
        i++;
        if(i < limit) {
          // Check expressions that can not be used as arguments
          Expression arg = statements.get(i);
          if(arg instanceof SeparatorExpression)
            acceptor.acceptError(
              "A function call without arguments must use '()')", s.eContainer(), s.eContainingFeature(),
              i - 1, IPPDiagnostics.ISSUE__NOT_TOPLEVEL);
        }
View Full Code Here

    return false;
  }

  private boolean isStandardAtExpression(AtExpression o) {
    // an At expression is standard if the lhs is a variable or an AtExpression
    Expression lhs = o.getLeftExpr();
    return (lhs instanceof VariableExpression || lhs instanceof AtExpression || (lhs instanceof LiteralNameOrReference && isFirstNameInTE((LiteralNameOrReference) lhs)));

  }
View Full Code Here

   * <!-- end-user-doc -->
   *
   * @generated
   */
  public NotificationChain basicSetValue(Expression newValue, NotificationChain msgs) {
    Expression oldValue = value;
    value = newValue;
    if(eNotificationRequired()) {
      ENotificationImpl notification = new ENotificationImpl(
        this, Notification.SET, PPPackage.ATTRIBUTE_OPERATION__VALUE, oldValue, newValue);
      if(msgs == null)
View Full Code Here

  }

  private boolean isExprClass(TextExpression te, Class<?> clazz) {
    if(!(te instanceof ExpressionTE))
      return false;
    Expression pe = ((ExpressionTE) te).getExpression();
    if(!ParenthesisedExpression.class.isAssignableFrom(pe.getClass()))
      return false;
    Expression peExpr = ((ParenthesisedExpression) pe).getExpr();
    if(peExpr == null)
      return false;
    return clazz.isAssignableFrom(peExpr.getClass());
  }
View Full Code Here

   * <!-- end-user-doc -->
   *
   * @generated
   */
  public NotificationChain basicSetExpression(Expression newExpression, NotificationChain msgs) {
    Expression oldExpression = expression;
    expression = newExpression;
    if(eNotificationRequired()) {
      ENotificationImpl notification = new ENotificationImpl(
        this, Notification.SET, PPPackage.UNQUOTED_STRING__EXPRESSION, oldExpression, newExpression);
      if(msgs == null)
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.