Package org.eclipse.core.runtime

Examples of org.eclipse.core.runtime.SubProgressMonitor


      IType aspect = getAspect();
      if (aspect == null) {
        lineDelimiter = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$

        ICompilationUnit parentCU = pack.createCompilationUnit(
            aspectName + ".java", "", false, new SubProgressMonitor(monitor, 2)); //$NON-NLS-1$ //$NON-NLS-2$
        // create a working copy with a new owner
        createdWorkingCopy = parentCU.getWorkingCopy(null);

        // use the compiler template a first time to read the imports
        String content = CodeGeneration.getCompilationUnitContent(createdWorkingCopy, null, "", lineDelimiter); //$NON-NLS-1$
        if (content != null) {
          createdWorkingCopy.getBuffer().setContents(content);
        }

        ImportsManager imports = new ImportsManager(createdWorkingCopy);
        // add an import that will be removed again. Having this import solves 14661
        imports.addImport(JavaModelUtil.concatenateName(pack.getElementName(), aspectName));

        String typeContent = writeBasicAspect(imports, lineDelimiter);
        String cuContent = constructCUContent(parentCU, typeContent, lineDelimiter);
        createdWorkingCopy.getBuffer().setContents(cuContent);
        if (monitor.isCanceled()) {
          throw new InterruptedException();
        }

        imports.create(false, new SubProgressMonitor(monitor, 1));
        JavaModelUtil.reconcile(createdWorkingCopy);
        aspect = createdWorkingCopy.getType(aspectName);
        needsCommit = true;
      }
      if (monitor.isCanceled()) {
        throw new InterruptedException();
      }

      ICompilationUnit cu = aspect.getCompilationUnit();
      boolean needsSave = cu.isWorkingCopy();
      ImportsManager imports = new ImportsManager(cu);
      lineDelimiter = StubUtility.getLineDelimiterUsed(aspect);

      // Write crosscut and format it
      IField field = fCrosscutPage.writeCrosscut(aspect, fCrosscutTypeDialogField.getSelectionIndex(), imports,
          new SubProgressMonitor(monitor, 2), lineDelimiter);
      ISourceRange range = field.getSourceRange();
      IBuffer buf = cu.getBuffer();
      String originalContent = buf.getText(range.getOffset(), range.getLength());
      String formattedContent = CodeFormatterUtil.format(CodeFormatter.K_CLASS_BODY_DECLARATIONS, originalContent, 1, null,
          lineDelimiter, field.getJavaProject());
      buf.replace(range.getOffset(), range.getLength(), formattedContent);
      if (!cu.isWorkingCopy())
        buf.save(null, false);

      imports.create(needsSave, new SubProgressMonitor(monitor, 1));
      removeUnusedImports(cu, needsSave);
      if (needsCommit)
        cu.commitWorkingCopy(false, new SubProgressMonitor(monitor, 1));
    } finally {
      if (createdWorkingCopy != null) {
        createdWorkingCopy.discardWorkingCopy();
      }
      monitor.done();
View Full Code Here


        source.append(nl);
        source.append("};");
        source.append(nl);
        source.append(nl);

        return aspect.createField(source.toString(), null, false, new SubProgressMonitor(monitor, 2));
    }
View Full Code Here

        source.append(nl);
        source.append("};");
        source.append(nl);
        source.append(nl);

        return aspect.createField(source.toString(), null, false, new SubProgressMonitor(monitor, 2));
    }
View Full Code Here

        source.append(nl);
        source.append("};");
        source.append(nl);
        source.append(nl);

        return aspect.createField(source.toString(), null, false, new SubProgressMonitor(monitor, 2));
    }
View Full Code Here

        source.append(nl);
        source.append("};");
        source.append(nl);
        source.append(nl);

        return aspect.createField(source.toString(), null, false, new SubProgressMonitor(monitor, 2));
    }
View Full Code Here

        try {
            initLabels();
            Differencer differencer = new Differencer();
            monitor.beginTask("Bytecode Outline: comparing...", 30); //$NON-NLS-1$
            IProgressMonitor sub = new SubProgressMonitor(monitor, 10);
            try {
                sub.beginTask("Bytecode Outline: comparing...", 100); //$NON-NLS-1$

                return differencer.findDifferences(
                    false, sub, null, null, left, right);
            } finally {
                sub.done();
            }
        } catch (OperationCanceledException e) {
            throw new InterruptedException(e.getMessage());
        } finally {
            monitor.done();
View Full Code Here

    private void createProject(IProjectDescription description,
            IProject projectHandle, IProgressMonitor monitor)
            throws CoreException, OperationCanceledException {
        try {
            monitor.beginTask("", 2000);
            projectHandle.create(description, new SubProgressMonitor(monitor,
                    1000));
            if (monitor.isCanceled()) {
                throw new OperationCanceledException();
            }
            projectHandle.open(IResource.BACKGROUND_REFRESH,
                new SubProgressMonitor(monitor, 1000));
        } finally {
            monitor.done();
        }
    }
View Full Code Here

      // initialize all containers and variables
      JavaModelManager manager = JavaModelManager.getJavaModelManager();
      try {
        if (monitor != null) {
          monitor.subTask(Messages.javamodel_configuring_classpath_containers);
          manager.batchContainerInitializationsProgress.set(new SubProgressMonitor(monitor, 50)); // 50% of the time is spent in initializing containers and variables
        }
       
        // all classpaths in the workspace are going to be resolved, ensure that containers are initialized in one batch
        manager.batchContainerInitializations = true;
       
        // avoid leaking source attachment properties (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=183413)
        IJavaProject[] projects = manager.getJavaModel().getJavaProjects();
        for (int i = 0, length = projects.length; i < length; i++) {
          IClasspathEntry[] classpath;
          try {
            classpath = ((JavaProject) projects[i]).getResolvedClasspath();
          } catch (JavaModelException e) {
            // project no longer exist: ignore
            continue;
          }
          if (classpath != null) {
            for (int j = 0, length2 = classpath.length; j < length2; j++) {
              IClasspathEntry entry = classpath[j];
              if (entry.getSourceAttachmentPath() != null)
                Util.setSourceAttachmentProperty(entry.getPath(), null);
              // else source might have been attached by IPackageFragmentRoot#attachSource(...), we keep it
            }
          }
        }
       
        // initialize delta state
        manager.deltaState.rootsAreStale = true; // in case it was already initialized before we cleaned up the source attachment proprties
        manager.deltaState.initializeRoots();
      } finally {
        manager.batchContainerInitializationsProgress.set(null);
      }

      // dummy query for waiting until the indexes are ready
      SearchEngine engine = new SearchEngine();
      IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
      try {
        if (monitor != null)
          monitor.subTask(Messages.javamodel_configuring_searchengine);
        engine.searchAllTypeNames(
          null,
          SearchPattern.R_EXACT_MATCH,
          "!@$#!@".toCharArray(), //$NON-NLS-1$
          SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE,
          IJavaSearchConstants.CLASS,
          scope,
          new TypeNameRequestor() {
            public void acceptType(
              int modifiers,
              char[] packageName,
              char[] simpleTypeName,
              char[][] enclosingTypeNames,
              String path) {
              // no type to accept
            }
          },
          // will not activate index query caches if indexes are not ready, since it would take to long
          // to wait until indexes are fully rebuild
          IJavaSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH,
          monitor == null ? null : new SubProgressMonitor(monitor, 49) // 49% of the time is spent in the dummy search
        );
      } catch (JavaModelException e) {
        // /search failed: ignore
      } catch (OperationCanceledException e) {
        if (monitor != null && monitor.isCanceled())
          throw e;
        // else indexes were not ready: catch the exception so that jars are still refreshed
      }

      // check if the build state version number has changed since last session
      // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=98969)
      if (monitor != null)
        monitor.subTask(Messages.javamodel_getting_build_state_number);
      QualifiedName qName = new QualifiedName(JavaCore.PLUGIN_ID, "stateVersionNumber"); //$NON-NLS-1$
      IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
      String versionNumber = null;
      try {
        versionNumber = root.getPersistentProperty(qName);
      } catch (CoreException e) {
        // could not read version number: consider it is new
      }
      final JavaModel model = manager.getJavaModel();
      String newVersionNumber = Byte.toString(State.VERSION);
      if (!newVersionNumber.equals(versionNumber)) {
        // build state version number has changed: touch every projects to force a rebuild
        if (JavaBuilder.DEBUG)
          System.out.println("Build state version number has changed"); //$NON-NLS-1$
        IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
          public void run(IProgressMonitor progressMonitor2) throws CoreException {
            IJavaProject[] projects = null;
            try {
              projects = model.getJavaProjects();
            } catch (JavaModelException e) {
              // could not get Java projects: ignore
            }
            if (projects != null) {
              for (int i = 0, length = projects.length; i < length; i++) {
                IJavaProject project = projects[i];
                try {
                  if (JavaBuilder.DEBUG)
                    System.out.println("Touching " + project.getElementName()); //$NON-NLS-1$
                  project.getProject().touch(progressMonitor2);
                } catch (CoreException e) {
                  // could not touch this project: ignore
                }
              }
            }
          }
        };
        if (monitor != null)
          monitor.subTask(Messages.javamodel_building_after_upgrade);
        try {
          ResourcesPlugin.getWorkspace().run(runnable, monitor);
        } catch (CoreException e) {
          // could not touch all projects
        }
        try {
          root.setPersistentProperty(qName, newVersionNumber);
        } catch (CoreException e) {
          Util.log(e, "Could not persist build state version number"); //$NON-NLS-1$
        }
      }

      // ensure external jars are refreshed (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=93668)
      try {
        if (monitor != null)
          monitor.subTask(Messages.javamodel_refreshing_external_jars);
        model.refreshExternalArchives(
          null/*refresh all projects*/,
          monitor == null ? null : new SubProgressMonitor(monitor, 1) // 1% of the time is spent in jar refresh
        );
      } catch (JavaModelException e) {
        // refreshing failed: ignore
      }
     
View Full Code Here

      if (usedAstRoot == null) {
        ASTParser parser= ASTParser.newParser(AST.JLS3);
        parser.setSource(this.compilationUnit);
        parser.setFocalPosition(0); // reduced AST
        parser.setResolveBindings(false);
        usedAstRoot= (CompilationUnit) parser.createAST(new SubProgressMonitor(monitor, 1));
      }
           
      ImportRewriteAnalyzer computer= new ImportRewriteAnalyzer(this.compilationUnit, usedAstRoot, this.importOrder, this.importOnDemandThreshold, this.staticImportOnDemandThreshold, this.restoreExistingImports);
      computer.setFilterImplicitImports(this.filterImplicitImports);
     
      if (this.addedImports != null) {
        for (int i= 0; i < this.addedImports.size(); i++) {
          String curr= (String) this.addedImports.get(i);
          computer.addImport(curr.substring(1), STATIC_PREFIX == curr.charAt(0));
        }
      }
     
      if (this.removedImports != null) {
        for (int i= 0; i < this.removedImports.size(); i++) {
          String curr= (String) this.removedImports.get(i);
          computer.removeImport(curr.substring(1), STATIC_PREFIX == curr.charAt(0));
        }
      }
       
      TextEdit result= computer.getResultingEdits(new SubProgressMonitor(monitor, 1));
      this.createdImports= computer.getCreatedImports();
      this.createdStaticImports= computer.getCreatedStaticImports();
      return result;
    } finally {
      monitor.done();
View Full Code Here

       
    if (this.hierarchy.focusType == null || computeSubtypes) {
      IProgressMonitor typeInRegionMonitor =
        this.hierarchy.progressMonitor == null ?
          null :
          new SubProgressMonitor(this.hierarchy.progressMonitor, 30);
      HashMap allOpenablesInRegion = determineOpenablesInRegion(typeInRegionMonitor);
      this.hierarchy.initialize(allOpenablesInRegion.size());
      IProgressMonitor buildMonitor =
        this.hierarchy.progressMonitor == null ?
          null :
          new SubProgressMonitor(this.hierarchy.progressMonitor, 70);
      createTypeHierarchyBasedOnRegion(allOpenablesInRegion, buildMonitor);
      ((RegionBasedTypeHierarchy)this.hierarchy).pruneDeadBranches();
    } else {
      this.hierarchy.initialize(1);
      this.buildSupertypes();
View Full Code Here

TOP

Related Classes of org.eclipse.core.runtime.SubProgressMonitor

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.