Ejemplo n.º 1
0
  /**
   * Process the given resource within the context of the given working set in order to record the
   * data and relationships found within the resource.
   */
  public void indexResource(File libraryFile, File sourceFile, DartUnit dartUnit)
      throws DartModelException {

    // Get the LibrarySource

    LibrarySource librarySource = dartUnit.getLibrary().getSource();

    // Get the DartLibrary

    DartLibraryImpl library;
    IResource resource = ResourceUtil.getResource(libraryFile);
    if (resource == null) {
      library = new DartLibraryImpl(librarySource);
    } else {
      DartElement element = DartCore.create(resource);
      if (element instanceof CompilationUnitImpl) {
        element = ((CompilationUnitImpl) element).getLibrary();
      }
      if (!(element instanceof DartLibrary)) {
        DartCore.logError("Expected library to be associated with " + libraryFile);
        return;
      }
      library = (DartLibraryImpl) element;
    }

    // Get the CompilationUnit

    DartSource unitSource = (DartSource) dartUnit.getSourceInfo().getSource();
    CompilationUnit compilationUnit;
    IResource res = ResourceUtil.getResource(sourceFile);
    if (res != null) {
      DefaultWorkingCopyOwner workingCopy = DefaultWorkingCopyOwner.getInstance();
      compilationUnit = new CompilationUnitImpl(library, (IFile) res, workingCopy);
    } else {
      String relPath = unitSource.getRelativePath();
      compilationUnit = new ExternalCompilationUnitImpl(library, relPath, unitSource);
    }

    URI unitUri = unitSource.getUri();
    Resource indexerResource;
    if (PackageLibraryManager.isDartUri(unitUri)) {
      indexerResource =
          new Resource(
              ResourceFactory.composeResourceId(
                  librarySource.getUri().toString(), unitUri.toString()));
    } else if (PackageLibraryManager.isPackageUri(unitUri)) {
      indexerResource =
          new Resource(
              ResourceFactory.composeResourceId(
                  libraryFile.toURI().toString(), sourceFile.toURI().toString()));
    } else {
      indexerResource = ResourceFactory.getResource(compilationUnit);
    }

    // Queue the resource to be indexed

    indexResource(indexerResource, libraryFile, compilationUnit, dartUnit);
  }
Ejemplo n.º 2
0
 public CompilationUnitImpl getCompUnit(Class<?> base, String relPath)
     throws CoreException, IOException, DartModelException {
   DartLibraryImpl lib = getDartApp();
   String expected = TestFileUtil.readResource(base, relPath);
   String fileName = relPath.substring(relPath.lastIndexOf('/') + 1);
   IFile file = getOrCreateFile(fileName, expected);
   DefaultWorkingCopyOwner wcopy = DefaultWorkingCopyOwner.getInstance();
   CompilationUnitImpl unit = new CompilationUnitImpl(lib, file, wcopy);
   String actual = unit.getSource();
   assertEquals(expected, actual);
   return unit;
 }