Esempio n. 1
0
 protected boolean checkImportedNamespaceExists(String importedNamespace, Resource res) {
   if (importedNamespace.endsWith(".*")) {
     importedNamespace = importedNamespace.substring(0, importedNamespace.length() - 2); // remove
     // wildcard
   }
   IResourceDescriptions resourceDescriptions =
       resourceDescriptionsProvider.getResourceDescriptions(res);
   URI uri = res.getURI();
   IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(uri);
   if (resourceDescription == null) {
     return false; // no resource description could be found, so package
     // cannot be resolved anyway
   }
   for (IContainer container :
       containerManager.getVisibleContainers(resourceDescription, resourceDescriptions)) {
     final Iterable<IResourceDescription> currentDescriptions =
         container.getResourceDescriptions();
     for (IResourceDescription resDesc : currentDescriptions) {
       Iterable<IEObjectDescription> visiblePackages =
           resDesc.getExportedObjectsByType(TypesPackage.Literals.PACKAGE);
       for (IEObjectDescription pkgDesc : visiblePackages) {
         if (pkgDesc.getName().toString().equals(importedNamespace)) {
           return true;
         }
       }
     }
   }
   return false;
 }
Esempio n. 2
0
 public void configure(Resource r) {
   resource = r;
   IResourceDescriptions descriptionIndex = indexProvider.getResourceDescriptions(resource);
   IResourceDescription descr = descriptionIndex.getResourceDescription(resource.getURI());
   manager = resourceServiceProvider.getContainerManager();
   buildExportedObjectsIndex(descr, descriptionIndex);
   searchPath = searchPathProvider.get(r);
 }
 private boolean atLeastOnePackageExistsInIndex(Resource res) {
   IResourceDescriptions resourceDescriptions =
       resourceDescriptionsProvider.getResourceDescriptions(res);
   URI uri = res.getURI();
   IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(uri);
   for (IContainer container :
       containerManager.getVisibleContainers(resourceDescription, resourceDescriptions)) {
     final Iterable<IResourceDescription> currentDescriptions =
         container.getResourceDescriptions();
     for (IResourceDescription resDesc : currentDescriptions) {
       Iterable<IEObjectDescription> visisblePackages =
           resDesc.getExportedObjectsByType(TypesPackage.Literals.PACKAGE);
       if (!Iterables.isEmpty(visisblePackages)) {
         return true;
       }
     }
   }
   return false;
 }
Esempio n. 4
0
  protected void cacheMetaParameters(EObject scopeDetermeningObject) {
    // System.err.println("Computing meta cache");
    metaCache = Maps.newHashMap();
    Resource scopeDetermeningResource = scopeDetermeningObject.eResource();

    IResourceDescriptions descriptionIndex =
        indexProvider.getResourceDescriptions(scopeDetermeningResource);
    IResourceDescription descr =
        descriptionIndex.getResourceDescription(scopeDetermeningResource.getURI());
    if (descr == null) return; // give up - some sort of clean build
    EClass wantedType = PPTPPackage.Literals.TYPE_ARGUMENT;
    for (IContainer visibleContainer : manager.getVisibleContainers(descr, descriptionIndex)) {
      for (IEObjectDescription objDesc : visibleContainer.getExportedObjects()) {
        QualifiedName q = objDesc.getQualifiedName();
        if ("Type".equals(q.getFirstSegment())) {
          if (wantedType == objDesc.getEClass() || wantedType.isSuperTypeOf(objDesc.getEClass()))
            metaCache.put(q.getLastSegment(), objDesc);
        }
      }
    }
  }
Esempio n. 5
0
  protected List<IEObjectDescription> findExternal(
      EObject scopeDetermeningObject,
      QualifiedName fqn,
      PPImportedNamesAdapter importedNames,
      boolean prefixMatch,
      EClass... eClasses) {
    if (scopeDetermeningObject == null)
      throw new IllegalArgumentException("scope determening object is null");
    if (fqn == null) throw new IllegalArgumentException("name is null");
    if (eClasses == null || eClasses.length < 1)
      throw new IllegalArgumentException("eClass is null or empty");

    if (fqn.getSegmentCount() == 1 && "".equals(fqn.getSegment(0)))
      throw new IllegalArgumentException("FQN has one empty segment");

    // Not meaningful to record the fact that an Absolute reference was used as nothing
    // is named with an absolute FQN (i.e. it is only used to do lookup).
    final boolean absoluteFQN = fqn.getSegmentCount() > 0 && "".equals(fqn.getSegment(0));
    if (importedNames != null) importedNames.add(absoluteFQN ? fqn.skipFirst(1) : fqn);

    List<IEObjectDescription> targets = Lists.newArrayList();
    Resource scopeDetermeningResource = scopeDetermeningObject.eResource();

    if (scopeDetermeningResource != resource) {
      // This is a lookup in the perspective of some other resource
      IResourceDescriptions descriptionIndex =
          indexProvider.getResourceDescriptions(scopeDetermeningResource);
      IResourceDescription descr =
          descriptionIndex.getResourceDescription(scopeDetermeningResource.getURI());

      // GIVE UP (the system is performing a build clean).
      if (descr == null) return targets;
      QualifiedName nameOfScope = getNameOfScope(scopeDetermeningObject);

      // for(IContainer visibleContainer : manager.getVisibleContainers(descr, descriptionIndex)) {
      // for(EClass aClass : eClasses)
      for (IEObjectDescription objDesc :
          new NameInScopeFilter(
              prefixMatch,
              getExportedObjects(descr, descriptionIndex),
              // visibleContainer.getExportedObjects(),
              fqn,
              nameOfScope,
              eClasses)) targets.add(objDesc);
    } else {
      // This is lookup from the main resource perspective
      QualifiedName nameOfScope = getNameOfScope(scopeDetermeningObject);
      for (IEObjectDescription objDesc :
          new NameInScopeFilter(
              prefixMatch, //
              prefixMatch
                  ? exportedPerLastSegment.values()
                  : exportedPerLastSegment.get(fqn.getLastSegment()), //
              fqn,
              nameOfScope,
              eClasses)) targets.add(objDesc);
    }
    if (tracer.isTracing()) {
      for (IEObjectDescription d : targets)
        tracer.trace("    : ", converter.toString(d.getName()), " in: ", d.getEObjectURI().path());
    }
    return searchPathAdjusted(targets);
  }