예제 #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);
  }
  private void createFolder(IPath path) {
    final AbstractSample sampleContent = page.getCurrentSample();

    IPath containerPath = path.removeLastSegments(1);

    IResource container = ResourceUtil.getResource(containerPath.toFile());

    if (container != null) {
      IPath newFolderPath = container.getFullPath().append(path.lastSegment());

      final IFolder newFolderHandle =
          IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getFolder(newFolderPath);

      IRunnableWithProgress op =
          new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException {
              AbstractOperation op;
              op =
                  new CreateFolderOperation(
                      newFolderHandle,
                      null,
                      IDEWorkbenchMessages.WizardNewFolderCreationPage_title);
              try {

                IStatus status =
                    op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(getShell()));

                if (status.isOK()) {
                  createdFile =
                      createProjectContent(
                          newProject, newFolderHandle, newFolderHandle.getName(), sampleContent);
                }

              } catch (ExecutionException e) {
                throw new InvocationTargetException(e);
              } catch (CoreException e) {
                throw new InvocationTargetException(e);
              }
            }
          };

      try {
        getContainer().run(true, true, op);
      } catch (InterruptedException e) {

      } catch (InvocationTargetException e) {
        // ExecutionExceptions are handled above, but unexpected runtime
        // exceptions and errors may still occur.
        IDEWorkbenchPlugin.log(
            getClass(), "createNewFolder()", e.getTargetException()); // $NON-NLS-1$
        MessageDialog.open(
            MessageDialog.ERROR,
            getContainer().getShell(),
            IDEWorkbenchMessages.WizardNewFolderCreationPage_internalErrorTitle,
            NLS.bind(
                IDEWorkbenchMessages.WizardNewFolder_internalError,
                e.getTargetException().getMessage()),
            SWT.SHEET);
      }

      newProject = newFolderHandle.getProject();
    }
  }