Package com.puppetlabs.geppetto.pp.dsl.linking.PPFinder

Examples of com.puppetlabs.geppetto.pp.dsl.linking.PPFinder.SearchResult


            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
View Full Code Here


      }
      stack.add(name);
      String parentName = d.getUserData(PPDSLConstants.PARENT_NAME_DATA);
      if(parentName == null || parentName.length() == 0)
        continue;
      SearchResult searchResult = ppFinder.findHostClasses(d.getEObjectOrProxy(), parentName, importedNames);
      List<IEObjectDescription> parents = searchResult.getAdjusted(); // findHostClasses(d.getEObjectOrProxy(), parentName, importedNames);
      checkCircularInheritence(o, parents, stack, acceptor, importedNames);
    }
  }
View Full Code Here

      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,
View Full Code Here

      int parameterIndex = -1;
      for(Expression pe : o.getParameters()) {
        parameterIndex++;
        final String className = stringConstantEvaluator.doToString(pe);
        if(className != null) {
          SearchResult searchResult = ppFinder.findHostClasses(o, className, importedNames);
          List<IEObjectDescription> foundClasses = searchResult.getAdjusted(); // findHostClasses(o, className, importedNames);
          if(foundClasses.size() > 1) {
            // ambiguous
            importedNames.addAmbiguous(foundClasses);
            acceptor.acceptWarning(
              "Ambiguous reference to: '" + className + "' found in: " +
                  visibleResourceList(o.eResource(), foundClasses), o,
              PPPackage.Literals.PARAMETERIZED_EXPRESSION__PARAMETERS, parameterIndex,
              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());
              acceptor.acceptWarning(
                "Found outside current search path: '" + className + "'", o,
                PPPackage.Literals.PARAMETERIZED_EXPRESSION__PARAMETERS, parameterIndex,
                IPPDiagnostics.ISSUE__NOT_ON_PATH);
            }
View Full Code Here

    }
  }

  private void internalLinkFunctionCall(ParameterizedExpression o, EObject nameExpr, String name,
      PPImportedNamesAdapter importedNames, IMessageAcceptor acceptor) {
    final SearchResult searchResult = ppFinder.findFunction(o, name, importedNames);
    final List<IEObjectDescription> found = searchResult.getAdjusted(); // findFunction(o, name, importedNames);
    if(found.size() > 0) {
      // record resolution at resource level
      importedNames.addResolved(found);
      CrossReferenceAdapter.set(nameExpr, found);
      internalLinkFunctionArguments(name, o, importedNames, acceptor);
      return; // ok, found
    }
    if(searchResult.getRaw().size() > 0) {
      // Not a hard error, it may be valid with a different path
      // not found on path, but exists somewhere in what is visible
      // record resolution at resource level
      importedNames.addResolved(searchResult.getRaw());
      CrossReferenceAdapter.set(nameExpr, searchResult.getRaw());
      internalLinkFunctionArguments(name, o, importedNames, acceptor);
      acceptor.acceptWarning("Found outside current path: '" + name + "'", nameExpr, //
        IPPDiagnostics.ISSUE__NOT_ON_PATH //
      );
      return; // sort of ok
View Full Code Here

    // 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));
View Full Code Here

        // the next expression is consumed as a single arg, or an expr list
        // TODO: if there are expressions that can not be used as arguments check them here
        i++;
        // Expression arg = statements.get(i); // not used yet...
        String name = ((LiteralNameOrReference) s).getValue();
        SearchResult searchResult = ppFinder.findFunction(s, name, importedNames);
        final boolean existsAdjusted = searchResult.getAdjusted().size() > 0;
        final boolean existsOutside = searchResult.getRaw().size() > 0;

        recordCrossReference(
          converter.toQualifiedName(name), searchResult, existsAdjusted, existsOutside, true, importedNames,
          s);
        if(existsAdjusted || existsOutside) {
View Full Code Here

      IMessageAcceptor acceptor) {
    boolean qualified = false;
    boolean global = false;
    boolean disqualified = false;
    QualifiedName qName = null;
    SearchResult searchResult = null;
    boolean existsAdjusted = false; // variable found as stated
    boolean existsOutside = false; // if not found, reflects if found outside search path
    try {
      qName = converter.toQualifiedName(varName);
      if(patternHelper.isDECIMALVAR(varName)) {
        internalLinkRegexpVariable(o, varName, attr, acceptor);
        return;
      }

      qualified = qName.getSegmentCount() > 1;
      global = qName.getFirstSegment().length() == 0;
      searchResult = ppFinder.findVariable(o, qName, importedNames);

      // remove all references to not yet initialized variables
      disqualified = (0 != removeDisqualifiedVariables(searchResult.getRaw(), o));
      if(disqualified) // adjusted can not have disqualified entries if raw did not have them
        removeDisqualifiedVariables(searchResult.getAdjusted(), o);
      existsAdjusted = searchResult.getAdjusted().size() > 0;
      existsOutside = existsAdjusted
          ? false // we are not interested in that it may be both adjusted and raw
          : searchResult.getRaw().size() > 0;
    }
    catch(IllegalArgumentException iae) {
      // Can happen if there is something seriously wrong with the qualified name, should be caught by
      // validation - just ignore it here
      return;
View Full Code Here

        // normal converter does not add trailing empty segment, do so here to enable search in xxx::* namespace
        if(prefix.endsWith("::") && fqn.getSegmentCount() > 0)
          fqn = fqn.append("");

        // find variables using prefixed variant of find
        SearchResult r = ppFinder.findVariablesPrefixed(model, fqn, null);

        // get the name of the scope we are in to enable reduction of proposal to use locally scoped name
        QualifiedName scopeFQN = ppFinder.getNameOfScope(model);

        // Remove disqualified entries (known to be uninitialized) ( $x = $x, and define foo ($x, $y = $x) ) (surgical operation)
        removeDisqualifiedVariables(r.getAdjusted(), model);

        // Create proposals
        for(IEObjectDescription d : r.getAdjusted()) {
          // Filter out bad name(s)
          // https://github.com/puppetlabs/geppetto/issues/263
          if("*".equals(d.getQualifiedName().getLastSegment()))
            continue;

 
View Full Code Here

    else if(parent.eClass() == PPPackage.Literals.LITERAL_NAME_OR_REFERENCE)
      parentString = ((LiteralNameOrReference) parent).getValue();
    if(parentString == null || parentString.length() < 1)
      return;

    SearchResult searchResult = ppFinder.findHostClasses(o, parentString, importedNames);
    List<IEObjectDescription> descs = searchResult.getAdjusted();
    if(descs.size() > 0) {
      // make list only contain unique references
      descs = Lists.newArrayList(Sets.newHashSet(descs));

      CrossReferenceAdapter.set(parent, descs);
      // record resolution at resource level
      importedNames.addResolved(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).
        importedNames.addAmbiguous(descs);
        acceptor.acceptWarning(
          "Ambiguous reference to: '" + parentString + "' found in: " +
              visibleResourceList(o.eResource(), descs), o,
          PPPackage.Literals.HOST_CLASS_DEFINITION__PARENT,
          IPPDiagnostics.ISSUE__RESOURCE_AMBIGUOUS_REFERENCE,
          proposer.computeDistinctProposals(parentString, descs));
      }
      // must check for circularity
      List<QualifiedName> visited = Lists.newArrayList();
      visited.add(converter.toQualifiedName(o.getClassName()));
      checkCircularInheritence(o, descs, visited, acceptor, importedNames);
    }
    else if(searchResult.getRaw().size() > 0) {
      List<IEObjectDescription> raw = searchResult.getRaw();
      CrossReferenceAdapter.set(parent, raw);

      // Sort of ok, it is not on the current path
      // record resolution at resource level, so recompile knows about the dependencies
      importedNames.addResolved(raw);
      acceptor.acceptWarning(
        "Found outside current search path: '" + parentString + "'", o,
        PPPackage.Literals.HOST_CLASS_DEFINITION__PARENT, IPPDiagnostics.ISSUE__NOT_ON_PATH);

    }
    else {
      // record unresolved name at resource level
      addUnresolved(
        importedNames, converter.toQualifiedName(parentString), NodeModelUtils.findActualNodeFor(parent));
      // importedNames.addUnresolved(converter.toQualifiedName(parentString));
      CrossReferenceAdapter.clear(parent);

      // ... and finally, if there was neither a type nor a definition reference
      String[] proposals = proposer.computeProposals(
        parentString, ppFinder.getExportedDescriptions(), searchPath, CLASS_AND_TYPE);
      acceptor.acceptError(
        "Unknown class: '" + parentString + "'", o, //
        PPPackage.Literals.HOST_CLASS_DEFINITION__PARENT,
        proposalIssue(IPPDiagnostics.ISSUE__RESOURCE_UNKNOWN_TYPE, proposals), //
        proposals);
    }

    if(!advisor().allowInheritanceFromParameterizedClass()) {
      List<IEObjectDescription> targets = descs.size() > 0
          ? descs
          : searchResult.getRaw();
      if(targets.size() > 0) {
        IEObjectDescription target = targets.get(0);
        if(target.getUserData(PPDSLConstants.CLASS_ARG_COUNT) != null)
          acceptor.acceptError(
            "Can not inherit from a parameterized class in Puppet versions < 3.0.", o, //
View Full Code Here

TOP

Related Classes of com.puppetlabs.geppetto.pp.dsl.linking.PPFinder.SearchResult

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.