Package com.puppetlabs.geppetto.pp.adapters

Examples of com.puppetlabs.geppetto.pp.adapters.ClassifierAdapter


    // }
    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).
      if(resourceType == RESOURCE_IS_CLASSPARAMS) {
        // resource is pp: class { classname : parameter => value }

        // Find parameters for the class
        // Find the class
        final String className = stringConstantEvaluator.doToString(resourceBody.getNameExpr());
        if(className == null)
          return; // not a static expression
        // Need the class to get its full name
        ppFinder.configure(model.eResource());
        List<IEObjectDescription> descs = ppFinder.findHostClasses(resourceBody, className, null).getAdjusted();
        if(descs.size() < 1)
          return; // can't find class, no proposals
        IEObjectDescription desc = descs.get(0); // pick first if ambiguous

        // which attribute(s) are we trying to find.
        String prefix = context.getPrefix();
        QualifiedName fqn = desc.getQualifiedName().append(prefix);

        for(IEObjectDescription d : ppFinder.findAttributesWithPrefix(resourceBody, fqn).getAdjusted())
          acceptor.accept(createCompletionProposal(d.getName().getLastSegment(), context));

      }
      else if(resourceType == RESOURCE_IS_OVERRIDE) {
        // do nothing (too complicated due to the query being able to match all sorts of things)
      }
      else {
        // Normal Resource
        ppFinder.configure(model.eResource());

        // Either a default setting Type { } or instance type { }, in both cases propose all properties and parameters
        // including meta
        IEObjectDescription desc = (IEObjectDescription) adapter.getTargetObjectDescription();
        if(desc != null) {
          // the type is known
          // which attribute(s) are we trying to find.
          String prefix = context.getPrefix();
          QualifiedName fqn = desc.getQualifiedName().append(prefix);
View Full Code Here


    }
    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)
        acceptor.accept(createCompletionProposal("+>", context));
    }
    catch(ClassCastException e) {
View Full Code Here

  @Inject
  private Provider<IValidationAdvisor> validationAdvisorProvider;

  private void _link(CollectExpression o, PPImportedNamesAdapter importedNames, IMessageAcceptor acceptor) {
    classifier.classify(o);
    ClassifierAdapter adapter = ClassifierAdapterFactory.eINSTANCE.adapt(o);
    int resourceType = adapter.getClassifier();
    String resourceTypeName = adapter.getResourceTypeName();

    // Should not really happen, but if a workspace state is maintained with old things...
    if(resourceTypeName == null || resourceType != COLLECTOR_IS_REGULAR)
      return;

    internalLinkTypeExpression(o, o.getClassReference(), true, importedNames, acceptor);
    IEObjectDescription desc = adapter.getTargetObjectDescription(IEObjectDescription.class);
    if(desc != null)
      internalLinkAttributeOperations(o.getAttributes(), desc, importedNames, acceptor);
  }
View Full Code Here

   */
  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

   * polymorph {@link #link(EObject, IMessageAcceptor)}
   */
  private void _link(ResourceExpression o, PPImportedNamesAdapter importedNames, IMessageAcceptor acceptor) {
    classifier.classify(o);

    ClassifierAdapter adapter = ClassifierAdapterFactory.eINSTANCE.adapt(o);
    int resourceType = adapter.getClassifier();
    String resourceTypeName = adapter.getResourceTypeName();

    // Should not really happen, but if a workspace state is maintained with old things...
    if(resourceTypeName == null)
      return;

View Full Code Here

  }

  private void internalLinkTypeExpression(EObject o, EObject reference, boolean upperCaseProposals,
      PPImportedNamesAdapter importedNames, IMessageAcceptor acceptor) {
    ClassifierAdapter adapter = ClassifierAdapterFactory.eINSTANCE.adapt(o);
    // int resourceType = adapter.getClassifier();
    String resourceTypeName = adapter.getResourceTypeName();

    // Should not really happen, but if a workspace state is maintained with old things...
    if(resourceTypeName == null)
      return;

    // normal resource
    SearchResult searchResult = ppFinder.findDefinitions(o, resourceTypeName, importedNames);
    List<IEObjectDescription> descs = searchResult.getAdjusted(); // findDefinitions(o, resourceTypeName, importedNames);
    if(descs.size() > 0) {
      // make list only contain unique references
      descs = Lists.newArrayList(Sets.newHashSet(descs));
      removeDisqualifiedContainers(descs, o);
      // if any remain, pick the first type (or the first if there are no types)
      IEObjectDescription usedResolution = null;
      if(descs.size() > 0) {
        usedResolution = getFirstTypeDescription(descs);
        adapter.setTargetObject(usedResolution); // Resource expression's resolution of type
        CrossReferenceAdapter.set(reference, descs); // the actual reference
      }

      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).
        importedNames.addAmbiguous(descs);
        acceptor.acceptWarning(
          "Ambiguous reference to: '" + resourceTypeName + "' found in: " +
              visibleResourceList(o.eResource(), descs), reference,
          IPPDiagnostics.ISSUE__RESOURCE_AMBIGUOUS_REFERENCE,
          proposer.computeDistinctProposals(resourceTypeName, descs, upperCaseProposals));
      }
      // Add resolved information at resource level
      if(usedResolution != null)
        importedNames.addResolved(usedResolution);
      else
        importedNames.addResolved(descs);
    }
    else if(searchResult.getRaw().size() > 0) {
      // sort of ok
      importedNames.addResolved(searchResult.getRaw());
      CrossReferenceAdapter.set(reference, searchResult.getRaw());

      // do not record the type

      acceptor.acceptWarning(
        "Found outside search path: '" + resourceTypeName + "'", reference, IPPDiagnostics.ISSUE__NOT_ON_PATH);

    }
    // only report unresolved if no raw (since if not found adjusted, error is reported as warning)
    if(searchResult.getRaw().size() < 1) {
      CrossReferenceAdapter.clear(reference);
      // ... and finally, if there was neither a type nor a definition reference
      if(adapter.getResourceType() == null && adapter.getTargetObjectDescription() == null) {
        // Add unresolved info at resource level
        addUnresolved(importedNames, resourceTypeName, NodeModelUtils.findActualNodeFor(reference));
        String[] proposals = proposer.computeProposals(
          resourceTypeName, ppFinder.getExportedDescriptions(), upperCaseProposals, searchPath, DEF_AND_TYPE);
        acceptor.acceptError("Unknown resource type: '" + resourceTypeName + "'", reference,
View Full Code Here

    String resourceTypeName = null;
    if(resourceExpr instanceof LiteralNameOrReference) {
      resourceType = COLLECTOR_IS_REGULAR;
      resourceTypeName = ((LiteralNameOrReference) resourceExpr).getValue();
    }
    ClassifierAdapter adapter = ClassifierAdapterFactory.eINSTANCE.adapt(o);
    adapter.setClassifier(resourceType);
    adapter.setResourceType(null); // unresolved
    adapter.setResourceTypeName(resourceTypeName);
  }
View Full Code Here

    /*
     * IMPORTANT: set the validated classifier to enable others to more quickly determine the type of
     * resource, and its typeName (what it is a reference to).
     */
    ClassifierAdapter adapter = ClassifierAdapterFactory.eINSTANCE.adapt(o);
    adapter.setClassifier(resourceType);
    adapter.setResourceType(null);
    adapter.setResourceTypeName(resourceTypeName);

  }
View Full Code Here

   * @param o
   */
  @Check
  public void checkResourceExpression(ResourceExpression o) {
    classifier.classify(o);
    ClassifierAdapter adapter = ClassifierAdapterFactory.eINSTANCE.adapt(o);
    int resourceType = adapter.getClassifier();

    if(resourceType == RESOURCE_IS_BAD) {
      acceptor.acceptError(
        "Resource type must be a literal name, 'class', class reference, or a resource reference.", o,
        PPPackage.Literals.RESOURCE_EXPRESSION__RESOURCE_EXPR, INSIGNIFICANT_INDEX,
View Full Code Here

TOP

Related Classes of com.puppetlabs.geppetto.pp.adapters.ClassifierAdapter

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.