Package org.eclipse.xtext.naming

Examples of org.eclipse.xtext.naming.QualifiedName


      this.matchStrategy = matchingStrategy;
    }

    @Override
    public boolean apply(IEObjectDescription candidate) {
      QualifiedName candidateName = candidate.getQualifiedName();
      // error, not a valid name (can not possibly match).
      if(candidateName.getSegmentCount() == 0)
        return false;

      // it is faster to compare exact match as this is a common case, before trying isSuperTypeOf
      int found = -1;
      for(int i = 0; i < eclasses.length; i++)
        if(eclasses[i] == candidate.getEClass() || eclasses[i].isSuperTypeOf(candidate.getEClass())) {
          found = i;
          break;
        }
      if(found < 0)
        return false; // wrong type

      if(absolute)
        return candidateName.equals(name);

      // Since most references are exact (they are global), this is the fastest for the common case.
      if(matches(candidateName, name, matchStrategy))
        return true;

      if(!matchStrategy.searchOuterScopes())
        return false;

      // need to find the common outer scope
      QualifiedName candidateParent = candidateName.skipLast(1);

      // Note: it is not possible to refer to the parent i.e. class foo::bar { bar { }}

      // find the common outer scope
      int commonCount = 0;
      int limit = Math.min(scopeName.getSegmentCount(), candidateParent.getSegmentCount());
      for(int i = 0; i < limit; i++)
        if(scopeName.getSegment(i).equals(candidateName.getSegment(i)))
          commonCount++;
        else
          break;
View Full Code Here


    Set<QualifiedName> visited = Sets.newHashSet();

    classesToSearch.add(currentName.skipLast(1));

    while(classesToSearch.size() > 0) {
      QualifiedName prefix = classesToSearch.remove(0);
      if(visited.contains(prefix))
        continue;
      visited.add(prefix); // prevent recursion

      // find all that start with className and are properties or parameters
      // also find the class/definition itself (possibly ambiguous).
      for(IEObjectDescription d : descs) {
        if(searchPath.searchIndexOf(d) == -1)
          continue; // not visible
        EClass ec = d.getEClass();
        QualifiedName name = d.getName();
        if(name.startsWith(prefix)) {
          if(name.getSegmentCount() == prefix.getSegmentCount()) {
            // exact match, check if this is the correct type
            if(DEF_AND_TYPE[0].isSuperTypeOf(ec) || DEF_AND_TYPE[1].isSuperTypeOf(ec)) {
              String parentName = d.getUserData(PPDSLConstants.PARENT_NAME_DATA);
              if(parentName != null && parentName.length() > 0)
                classesToSearch.add(converter.toQualifiedName(parentName));
View Full Code Here

      return s;
    return Character.toString(c).toUpperCase() + s.substring(1);
  }

  private String toUpperCaseProposal(String original) {
    QualifiedName fqn = converter.toQualifiedName(original);
    String[] segments = new String[fqn.getSegmentCount()];
    for(int i = 0; i < fqn.getSegmentCount(); i++)
      segments[i] = toInitialUpperCase(fqn.getSegment(i));
    return converter.toString(QualifiedName.create(segments));
  }
View Full Code Here

  @Fix(IPPDiagnostics.ISSUE__NOT_NAME_OR_REF)
  public void makeAllSegmentsSameCase(final Issue issue, IssueResolutionAcceptor acceptor) {
    String data[] = issue.getData();
    if(data == null || data.length != 1)
      return;
    QualifiedName fqn = getQualifiedNameConverter().toQualifiedName(data[0]);
    if(fqn.getSegmentCount() < 2)
      return;
    int upper = 0;
    int lower = 0;
    for(int i = 0; i < fqn.getSegmentCount(); i++) {
      String s = fqn.getSegment(i);
      if(s.length() > 0) {
        if(Character.isUpperCase(s.charAt(0)))
          upper++;
        else if(Character.isLowerCase(s.charAt(0)))
          lower++;
      }
    }
    // if all have same case, or if some where not letters
    if(upper + lower != fqn.getSegmentCount() || upper == 0 || lower == 0)
      return; // some other "unfixable" problem

    String[] segments = fqn.getSegments().toArray(new String[0]);
    for(int i = 0; i < segments.length; i++)
      segments[i] = toInitialCase(segments[i], true);
    QualifiedName upperCaseName = QualifiedName.create(segments);
    for(int i = 0; i < segments.length; i++)
      segments[i] = toInitialCase(segments[i], false);
    QualifiedName lowerCaseName = QualifiedName.create(segments);

    String tmp = getQualifiedNameConverter().toString(upperCaseName);
    acceptor.accept(issue, "Make all segments start with upper case", //
      "Change the name to '" + tmp + "'", null, new ReplacingModification(
        issue.getOffset(), issue.getLength(), tmp));
View Full Code Here

  private QualifiedName nameOfScope(EObject target) {
    if(target instanceof PuppetManifest)
      return converter.toQualifiedName("::"); // global scope

    QualifiedName scopeName = fqnProvider.getFullyQualifiedName(target);

    // the target happens to be a scope
    if(scopeName != null)
      return scopeName;
    return nameOfScope(target.eContainer());
View Full Code Here

        String issueString = xtextDocument.get(issue.getOffset(), issue.getLength());
        boolean dollarVar = issueString.startsWith("$");
        if(dollarVar)
          issueString = issueString.substring(1);
        QualifiedName fqn = converter.toQualifiedName(issueString);
        if(fqn.getSegmentCount() > 1) {
          ppFinder.configure(varExpr);
          String[] proposals = proposer.computeProposals(issueString, //
            ppFinder.getExportedDescriptions(), //
            searchPathProvider.get(varExpr.eResource()), PARAMS_AND_VARIABLES);
          for(String s : proposals)
View Full Code Here

            ? 1
            : 0), issueString.length(), "::" + issueString));

        // --NAME IN THIS SCOPE - AND OUTER
        // (Propose existing names in this and outer scopes)
        QualifiedName nameOfScope = nameOfScope(varExpr);
        if(nameOfScope.getSegmentCount() < 1)
          return; // it is in global scope (which was already proposed)

        ppFinder.configure(varExpr);
        for(IEObjectDescription desc : ppFinder.findVariables(varExpr, nameOfScope.append(issueString), null).getAdjusted()) {
          String nameInScopeString = converter.toString(desc.getName());
          String foundNameOfScope = converter.toString(desc.getName().skipLast(1));
          String scopeType = desc.getName().skipLast(1).equals(nameOfScope)
              ? "current"
              : "inhertied";
          acceptor.accept(
            issue, "Change to '$" + nameInScopeString + "'", "Change to '$" + issueString + "' in the " +
                scopeType + " scope:\n '" + foundNameOfScope + "'", null, new ReplacingModification(
              issue.getOffset() + (dollarVar
                  ? 1
                  : 0), issueString.length(), nameInScopeString));
        }
        // String scopeType = "current";

        for(QualifiedName qn = nameOfScope.skipLast(1); qn.getSegmentCount() > 0; qn = qn.skipLast(1)) {
          QualifiedName nameInScope = qn.append(issueString);
          String nameInScopeString = converter.toString(nameInScope);
          // TODO: Only propose if this name exists
          // configure for lookup of things
          if(ppFinder.findVariables(varExpr, nameInScopeString, null).getAdjusted().size() > 0)
            acceptor.accept(
View Full Code Here

  @Override
  public boolean createEObjectDescriptions(EObject eObject, IAcceptor<IEObjectDescription> acceptor) {
    if(getQualifiedNameProvider() == null)
      return false;
    try {
      QualifiedName qualifiedName = getQualifiedNameProvider().getFullyQualifiedName(eObject);
      if(qualifiedName != null) {
        acceptor.accept(EObjectDescription.create(qualifiedName, eObject, getDataForEObject(eObject)));
      }
    }
    catch(Exception exc) {
View Full Code Here

   * @param o
   * @return
   */
  QualifiedName getParentsFullyQualifiedName(EObject o) {
    for(EObject tmp = o.eContainer(); tmp != null; tmp = tmp.eContainer()) {
      QualifiedName n = getFullyQualifiedName(tmp);
      if(n != null)
        return n;
    }
    return null;
  }
View Full Code Here

      // there is an import statement - apply computed replacementString
      if (!proposalReplacementString.equals(replacementString)) {
        String shortTypeName = replacementString;
        if (valueConverter != null)
          shortTypeName = valueConverter.toValue(replacementString, null);
        QualifiedName shortQualifiedName = qualifiedNameConverter.toQualifiedName(shortTypeName);
        if (shortQualifiedName.getSegmentCount() == 1) {
          proposal.setCursorPosition(replacementString.length());
          document.replace(proposal.getReplacementOffset(), proposal.getReplacementLength(), replacementString);
          return;
        }
      }
      // we could create an import statement if there is no conflict
      Model file = (Model) context.getContents().get(0);
      ComponentDefinition clazz = file.getComponentDef();
     
      QualifiedName qualifiedName = qualifiedNameConverter.toQualifiedName(typeName);     
      if (qualifiedName.getSegmentCount() == 1) {
        // type resides in default package - no need to hassle with imports
        proposal.setCursorPosition(proposalReplacementString.length());
        document.replace(proposal.getReplacementOffset(), proposal.getReplacementLength(), proposalReplacementString);
        return;
      }
     
      IEObjectDescription description = scope.getSingleElement(qualifiedName.skipFirst(qualifiedName.getSegmentCount() - 1));
      if (description != null) {
        // there exists a conflict - insert fully qualified name
        proposal.setCursorPosition(proposalReplacementString.length());
        document.replace(proposal.getReplacementOffset(), proposal.getReplacementLength(), proposalReplacementString);
        return;
      }
     
      String fqnName = importConverter.toString(typeName);
      boolean found = false;
      for( Import i : file.getImports() ) {
        if( i.getImportedNamespace().equals(fqnName) ) {
          found = true;
        }
      }
     
      // Import does not introduce ambiguities - add import and insert short name
      String shortName = qualifiedName.getLastSegment();
      int topPixel = -1;
      // store the pixel coordinates to prevent the ui from flickering
      StyledText widget = viewer.getTextWidget();
      if (widget != null)
        topPixel = widget.getTopPixel();
View Full Code Here

TOP

Related Classes of org.eclipse.xtext.naming.QualifiedName

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.