Package com.puppetlabs.geppetto.pp

Examples of com.puppetlabs.geppetto.pp.ResourceExpression


        if(result == null)
          result = defaultCase(theEObject);
        return result;
      }
      case PPPackage.RESOURCE_EXPRESSION: {
        ResourceExpression resourceExpression = (ResourceExpression) theEObject;
        T result = caseResourceExpression(resourceExpression);
        if(result == null)
          result = caseExpression(resourceExpression);
        if(result == null)
          result = defaultCase(theEObject);
View Full Code Here


    // if(ppga.getWSRule() == context.getCurrentNode().getGrammarElement())
    // return;
    // }
    try {
      // figure out the shape of the resource
      ResourceExpression resourceExpr = (ResourceExpression) resourceBody.eContainer();

      ClassifierAdapter adapter = ClassifierAdapterFactory.eINSTANCE.adapt(resourceExpr);
      int resourceType = adapter.getClassifier();
      // If resource is good, and not 'class', then it must have a known reference type.
      // the resource type - also requires getting the type name from the override's expression).
View Full Code Here

      super.completeAttributeOperation_Op(model, assignment, context, acceptor);
      return;
    }
    try {
      // figure out the shape of the resource
      ResourceExpression resourceExpr = (ResourceExpression) resourceBody.eContainer();

      ClassifierAdapter adapter = ClassifierAdapterFactory.eINSTANCE.adapt(resourceExpr);
      int resourceType = adapter.getClassifier();
      acceptor.accept(createCompletionProposal("=>", context));
      if(resourceType == RESOURCE_IS_OVERRIDE)
View Full Code Here

   * polymorph {@link #link(EObject, IMessageAcceptor)}
   */
  private void _link(ResourceBody o, PPImportedNamesAdapter importedNames, IMessageAcceptor acceptor,
      boolean profileThis) {

    ResourceExpression resource = (ResourceExpression) o.eContainer();
    ClassifierAdapter adapter = ClassifierAdapterFactory.eINSTANCE.adapt(resource);
    if(adapter.getClassifier() == ClassifierAdapter.UNKNOWN) {
      classifier.classify(resource);
      adapter = ClassifierAdapterFactory.eINSTANCE.adapt(resource);
    }
    CLASSPARAMS: if(adapter.getClassifier() == RESOURCE_IS_CLASSPARAMS) {
      // pp: class { classname : parameter => value ... }

      final String className = stringConstantEvaluator.doToString(o.getNameExpr());
      if(className == null) {
        if(canBeAClassReference(o.getNameExpr())) {
          acceptor.acceptWarning(
            "Can not determine until runtime if this is a valid class reference (parameters not validated).", //
            o, // Flag entire body
              // PPPackage.Literals.RESOURCE_BODY__NAME_EXPR, //
            IPPDiagnostics.ISSUE__RESOURCE_UNKNOWN_TYPE);
        }
        else {
          acceptor.acceptError(
            "Not a valid class reference", o, PPPackage.Literals.RESOURCE_BODY__NAME_EXPR,
            IPPDiagnostics.ISSUE__NOT_CLASSREF);
        }
        CrossReferenceAdapter.clear(o.getNameExpr());
        break CLASSPARAMS;
      }
      SearchResult searchResult = ppFinder.findHostClasses(o, className, importedNames);
      List<IEObjectDescription> descs = searchResult.getAdjusted();
      if(descs.size() < 1) {
        if(searchResult.getRaw().size() > 0) {
          // Sort of ok
          importedNames.addResolved(searchResult.getRaw());
          CrossReferenceAdapter.set(o.getNameExpr(), searchResult.getRaw());
          acceptor.acceptWarning(
            "Found outside current search path (parameters not validated): '" + className + "'", o,
            PPPackage.Literals.RESOURCE_BODY__NAME_EXPR, IPPDiagnostics.ISSUE__NOT_ON_PATH);
          return; // skip validating parameters

        }

        // Add unresolved info at resource level
        addUnresolved(
          importedNames, converter.toQualifiedName(className),
          NodeModelUtils.findActualNodeFor(o.getNameExpr()));
        // importedNames.addUnresolved(converter.toQualifiedName(className));
        CrossReferenceAdapter.clear(o.getNameExpr());

        String[] proposals = proposer.computeProposals(
          className, ppFinder.getExportedDescriptions(), searchPath, CLASS_AND_TYPE);
        acceptor.acceptError(
          "Unknown class: '" + className + "'", o, //
          PPPackage.Literals.RESOURCE_BODY__NAME_EXPR,
          proposalIssue(IPPDiagnostics.ISSUE__RESOURCE_UNKNOWN_TYPE, proposals), //
          proposals);
        return; // not meaningful to continue (do not report errors for each "inner name")
      }
      if(descs.size() > 0) {
        descs = Lists.newArrayList(Sets.newHashSet(descs));
        // Report resolution at resource level
        importedNames.addResolved(descs);
        CrossReferenceAdapter.set(o.getNameExpr(), descs);

        if(descs.size() > 1) {
          // this is an ambiguous link - multiple targets available and order depends on the
          // order at runtime (may not be the same). ISSUE: o can be a ResourceBody
          importedNames.addAmbiguous(descs);
          acceptor.acceptWarning(
            "Ambiguous reference to: '" + className + "' found in: " +
                visibleResourceList(o.eResource(), descs), o,
            PPPackage.Literals.RESOURCE_BODY__NAME_EXPR,
            IPPDiagnostics.ISSUE__RESOURCE_AMBIGUOUS_REFERENCE,
            proposer.computeDistinctProposals(className, descs));
        }
        // use the first description found to find attributes
        internalLinkAttributeOperations(o.getAttributes(), descs.get(0), importedNames, acceptor);
      }

    }
    else if(adapter.getClassifier() != RESOURCE_IS_OVERRIDE || resource.getResourceExpr() instanceof AtExpression) {
      // normal resource or override file{} or File[x] { }
      IEObjectDescription desc = (IEObjectDescription) adapter.getTargetObjectDescription();
      // do not flag undefined parameters as errors if type is unknown
      if(desc != null) {
        internalLinkAttributeOperations(o.getAttributes(), desc, importedNames, acceptor);
View Full Code Here

      return result; // ok, they are chained

    // first check classes where validity depends on semantics
    if(o instanceof ResourceExpression) {
      // may not be a resource override
      ResourceExpression re = (ResourceExpression) o;
      if(re.getResourceExpr() instanceof AtExpression) {
        acceptor.acceptError(
          "Dependency can not be defined for a resource override.", r, feature, INSIGNIFICANT_INDEX,
          IPPDiagnostics.ISSUE__UNSUPPORTED_EXPRESSION);
        result = false;
      }
View Full Code Here

  private void subTestValidateExpressionTitles(Expression titleExpr) {
    PuppetManifest pp = pf.createPuppetManifest();
    EList<Expression> statements = pp.getStatements();

    ResourceExpression re = createVirtualResourceExpression("file", titleExpr, "owner", createValue("0777"));
    statements.add(re);
    tester.validator().checkResourceExpression(re);
    tester.validator().checkResourceBody(re.getResourceData().get(0));
    tester.diagnose().assertOK();

  }
View Full Code Here

  @Test
  public void test_Serialize_MResourcesMAttributes() throws Exception {
    PuppetManifest pp = pf.createPuppetManifest();
    EList<Expression> statements = pp.getStatements();
    ResourceExpression re = createResourceExpression(
      "file", "a resource", "owner", createValue("0777"), "group", createValue("0666"), "other",
      createValue("0555"));
    re.getResourceData().add(
      createResourceBody(
        "another resource", "a", createValue("1"), "bb", createValue("2"), "ccc", createValue("3")));
    statements.add(re);
    String s = serializeFormatted(pp);
    assertEquals("serialization should produce specified result", Sample_MResourcesMAttributes, s);
View Full Code Here

    at.setLeftExpr(reqType);
    at.getParameters().add(createSqString("a"));
    at.getParameters().add(createSqString("b"));
    at.getParameters().add(createSqString("c"));

    ResourceExpression vr = createResourceExpression("file", "x", "require", at);
    statements.add(vr);
    String s = serializeFormatted(pp);
    assertEquals("serialization should produce specified result", Sample_ResourceWithRequire, s);

  }
View Full Code Here

  @Test
  public void test_Serialize_VirtualResource() {
    // --with attribute definition
    PuppetManifest pp = pf.createPuppetManifest();
    EList<Expression> statements = pp.getStatements();
    ResourceExpression vr = createVirtualResourceExpression("file", "a resource", "owner", "fred");
    statements.add(vr);
    String s = serializeFormatted(pp);
    assertEquals("serialization should produce specified result", Sample_VirtualResource, s);

    pp = pf.createPuppetManifest();
View Full Code Here

    // -- multiple bodies
    PuppetManifest pp = pf.createPuppetManifest();
    EList<Expression> statements = pp.getStatements();

    ResourceExpression re = createResourceExpression(
      "File", NOTITLE, "owner", createValue("0777"), "group", createValue("0666"), "other", createValue("0555"));
    re.getResourceData().add(createResourceBody(null, "a", "1", "b", "2", "c", "3"));
    statements.add(re);
    tester.validator().checkResourceExpression(re);
    tester.diagnose().assertError(IPPDiagnostics.ISSUE__RESOURCE_MULTIPLE_BODIES);

    // -- bodies with titles
    pp = pf.createPuppetManifest();
    statements = pp.getStatements();
    re = createResourceExpression(
      "File", "title in error", "owner", createValue("0777"), "group", createValue("0666"), "other",
      createValue("0555"));
    re.getResourceData().add(createResourceBody(null, "a", "1", "b", "2", "c", "3"));
    statements.add(re);
    tester.validator().checkResourceExpression(re);
    tester.diagnose().assertAll(
      AssertableDiagnostics.errorCode(IPPDiagnostics.ISSUE__RESOURCE_WITH_TITLE),
      AssertableDiagnostics.errorCode(IPPDiagnostics.ISSUE__RESOURCE_MULTIPLE_BODIES));
View Full Code Here

TOP

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

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.