Package com.puppetlabs.geppetto.pp

Examples of com.puppetlabs.geppetto.pp.Expression


  }

  protected void _format(ExprList o, ITextFlow.WithText stream) {
    int size = o.getExpressions().size();
    for(int i = 0; i < size; i++) {
      Expression e = o.getExpressions().get(i);
      doFormat(e, stream);
      if(i + 1 < size) {
        stream.appendText(",");
        stream.appendSpace();
      }
View Full Code Here


  }

  protected void formatStatementList(EList<Expression> statements, ITextFlow.WithText stream) {
    int size = statements.size();
    for(int i = 0; i < size; i++) {
      Expression s = statements.get(i);
      if(s instanceof LiteralNameOrReference) {
        _format((LiteralNameOrReference) s, stream);
        if(i + 1 < size) {
          stream.appendSpace();
          doFormat(statements.get(i + 1), stream);
View Full Code Here

   * @param o
   * @param importedNames
   * @param acceptor
   */
  private void _link(ExpressionTE o, PPImportedNamesAdapter importedNames, IMessageAcceptor acceptor) {
    Expression expr = o.getExpression();
    if(expr instanceof ParenthesisedExpression)
      expr = ((ParenthesisedExpression) expr).getExpr();
    String varName = null;
    if(expr instanceof LiteralNameOrReference)
      varName = ((LiteralNameOrReference) expr).getValue();
View Full Code Here

  }

  private void _link(MethodCall o, PPImportedNamesAdapter importedNames, IMessageAcceptor acceptor) {
    // if not a name, then there is nothing to link, and this error is handled
    // elsewhere
    Expression methodExpr = o.getMethodExpr();
    if(!(methodExpr instanceof LiteralName))
      return;
    final String name = ((LiteralName) methodExpr).getValue();
    internalLinkFunctionCall(o, methodExpr, name, importedNames, acceptor);
  }
View Full Code Here

          PPPackage.Literals.LITERAL_NAME_OR_REFERENCE__VALUE, //
          IPPDiagnostics.ISSUE__REQUIRED_EXPRESSION);
        return;
      }

      Expression param = statements.get(idx);
      List<Expression> parameterList = null;
      if(param instanceof ExprList)
        parameterList = ((ExprList) param).getExpressions();
      else
        parameterList = Lists.newArrayList(param);

      int parameterIndex = -1;
      for(Expression pe : parameterList) {
        parameterIndex++;
        final String className = stringConstantEvaluator.doToString(pe);
        if(className != null) {
          SearchResult searchResult = ppFinder.findHostClasses(s, className, importedNames);
          List<IEObjectDescription> foundClasses = searchResult.getAdjusted(); // findHostClasses(o, className, importedNames);
          if(foundClasses.size() > 1) {
            // ambiguous
            importedNames.addAmbiguous(foundClasses);
            if(param instanceof ExprList)
              acceptor.acceptWarning(
                "Ambiguous reference to: '" + className + "' found in: " +
                    visibleResourceList(s.eResource(), foundClasses), //
                param, //
                PPPackage.Literals.EXPR_LIST__EXPRESSIONS,
                parameterIndex, //
                IPPDiagnostics.ISSUE__RESOURCE_AMBIGUOUS_REFERENCE,
                proposer.computeDistinctProposals(className, foundClasses));
            else
              acceptor.acceptWarning(
                "Ambiguous reference to: '" + className + "' found in: " +
                    visibleResourceList(s.eResource(), foundClasses), //
                param.eContainer(), param.eContainingFeature(),
                idx, //
                IPPDiagnostics.ISSUE__RESOURCE_AMBIGUOUS_REFERENCE,
                proposer.computeDistinctProposals(className, foundClasses));

          }
          else if(foundClasses.size() < 1) {
            if(searchResult.getRaw().size() > 0) {
              // sort of ok
              importedNames.addResolved(searchResult.getRaw());
              CrossReferenceAdapter.set(pe, searchResult.getRaw());

              if(param instanceof ExprList)
                acceptor.acceptWarning(
                  "Found outside current search path: '" + className + "'", param,
                  PPPackage.Literals.EXPR_LIST__EXPRESSIONS, parameterIndex,
                  IPPDiagnostics.ISSUE__NOT_ON_PATH);
              else
                acceptor.acceptWarning("Found outside current search path: '" + className + "'", //
                  param.eContainer(), param.eContainingFeature(), idx, // IPPDiagnostics.ISSUE__NOT_ON_PATH);
                  IPPDiagnostics.ISSUE__NOT_ON_PATH);

            }
            else {
              // not found
              // record unresolved name at resource level
              addUnresolved(importedNames, className, NodeModelUtils.findActualNodeFor(pe));
              // importedNames.addUnresolved(converter.toQualifiedName(className));
              CrossReferenceAdapter.clear(pe);

              String[] proposals = proposer.computeProposals(
                className, ppFinder.getExportedDescriptions(), searchPath, CLASS_AND_TYPE);
              String issueCode = proposalIssue(IPPDiagnostics.ISSUE__RESOURCE_UNKNOWN_TYPE, proposals);
              if(param instanceof ExprList) {
                acceptor.acceptError("Unknown class: '" + className + "'", //
                  param, //
                  PPPackage.Literals.EXPR_LIST__EXPRESSIONS, parameterIndex, //
                  issueCode, //
                  proposals);
              }
              else {
                acceptor.acceptError("Unknown class: '" + className + "'", //
                  param.eContainer(), param.eContainingFeature(), idx, //
                  issueCode, //
                  proposals);
              }
            }
          }
          else {
            // found
            importedNames.addResolved(foundClasses);
            CrossReferenceAdapter.set(pe, foundClasses);
          }
        }
        else {
          CrossReferenceAdapter.clear(pe);

          // warning or error depending on if this is a reasonable class reference expr or not
          String msg = null;
          boolean error = false;
          if(canBeAClassReference(pe)) {
            msg = "Can not determine until runtime if this is a valid class reference";
          }
          else {
            msg = "Not an acceptable parameter. Function '" + name + "' requires a class reference.";
            error = true;
          }
          if(param instanceof ExprList)
            acceptor.accept(error
                ? Severity.ERROR
                : Severity.WARNING, msg, //
              param, //
              PPPackage.Literals.EXPR_LIST__EXPRESSIONS, parameterIndex, //
              IPPDiagnostics.ISSUE__RESOURCE_UNKNOWN_TYPE);

          else
            acceptor.accept(error
                ? Severity.ERROR
                : Severity.WARNING, msg, //
              param.eContainer(), param.eContainingFeature(), idx, //
              IPPDiagnostics.ISSUE__RESOURCE_UNKNOWN_TYPE);
        }
      }
    }
  }
View Full Code Here

      IMessageAcceptor acceptor) {
    if(statements == null || statements.size() == 0)
      return;

    each_top: for(int i = 0; i < statements.size(); 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
View Full Code Here

        case PPPackage.RUBY_LAMBDA:
          internalLinkUnparenthesisedCall(((Lambda) o).getStatements(), importedNames, acceptor);
          break;

        case PPPackage.UNQUOTED_STRING:
          Expression expr = ((UnquotedString) o).getExpression();
          if(expr != null && expr instanceof LiteralNameOrReference) {
            //
            String varName = ((LiteralNameOrReference) expr).getValue();
            StringBuilder varName2 = new StringBuilder();
            if(!varName.startsWith("$"))
View Full Code Here

  @Inject
  private PPPatternHelper patternHelper;

  private void _classify(CollectExpression o) {
    int resourceType = RESOURCE_IS_BAD; // unknown at this point
    final Expression resourceExpr = o.getClassReference();
    String resourceTypeName = null;
    if(resourceExpr instanceof LiteralNameOrReference) {
      resourceType = COLLECTOR_IS_REGULAR;
      resourceTypeName = ((LiteralNameOrReference) resourceExpr).getValue();
    }
View Full Code Here

    // A regular resource must have a classname
    // Use of class reference is deprecated
    // classname : NAME | "class" | CLASSNAME

    int resourceType = RESOURCE_IS_BAD; // unknown at this point
    final Expression resourceExpr = o.getResourceExpr();
    String resourceTypeName = null;

    if(resourceExpr instanceof LiteralNameOrReference) {
      LiteralNameOrReference resourceTypeExpr = (LiteralNameOrReference) resourceExpr;
      resourceTypeName = resourceTypeExpr.getValue();
    }
    else if(resourceExpr instanceof LiteralClass) {
      resourceTypeName = "class";
    }
    else if(resourceExpr instanceof VirtualNameOrReference) {
      VirtualNameOrReference vn = (VirtualNameOrReference) resourceExpr;
      resourceTypeName = vn.getValue();
    }
    if(resourceTypeName != null) {
      if("class".equals(resourceTypeName))
        resourceType = RESOURCE_IS_CLASSPARAMS;
      else if(patternHelper.isCLASSREF(resourceTypeName))
        resourceType = RESOURCE_IS_DEFAULT;
      else if(patternHelper.isNAME(resourceTypeName) || patternHelper.isCLASSNAME(resourceTypeName))
        resourceType = RESOURCE_IS_REGULAR;
      // else the resource is BAD
    }
    else if(resourceExpr instanceof AtExpression) {
      resourceType = RESOURCE_IS_OVERRIDE;
      AtExpression at = (AtExpression) resourceExpr;
      Expression left = at.getLeftExpr();
      if(left instanceof LiteralNameOrReference)
        resourceTypeName = ((LiteralNameOrReference) left).getValue();
    }
    else if(resourceExpr instanceof CollectExpression) {
      resourceType = RESOURCE_IS_OVERRIDE;
      CollectExpression collect = (CollectExpression) resourceExpr;
      Expression classReference = collect.getClassReference();
      if(classReference instanceof LiteralNameOrReference)
        resourceTypeName = ((LiteralNameOrReference) classReference).getValue();
    }

    /*
 
View Full Code Here

      }
    }
  }

  public void highlight(CollectExpression expr, IHighlightedPositionAcceptor acceptor) {
    Expression classReference = expr.getClassReference();
    if(classReference != null) {
      highlightObject(classReference, PPHighlightConfiguration.RESOURCE_REF_ID, acceptor);
    }
  }
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.