org.eclipse.core.runtime.OperationCanceledException Java Examples

The following examples show how to use org.eclipse.core.runtime.OperationCanceledException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: n4js   Author: eclipse   File: ResourceUIValidatorExtension.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private void addMarkers(IFile file, Resource resource, CheckMode mode, IProgressMonitor monitor)
		throws OperationCanceledException {
	try {
		List<Issue> list = getValidator(resource).validate(resource, mode, getCancelIndicator(monitor));
		if (monitor.isCanceled()) {
			throw new OperationCanceledException();
		}
		deleteMarkers(file, mode, monitor);
		if (monitor.isCanceled()) {
			throw new OperationCanceledException();
		}
		createMarkers(file, resource, list);
	} catch (OperationCanceledError error) {
		throw error.getWrapped();
	} catch (CoreException e) {
		LOGGER.error(e.getMessage(), e);
	}
}
 
Example #2
Source Project: tmxeditor8   Author: heartsome   File: Html2Xliff.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Process list.
 * @throws ParserConfigurationException
 *             * @throws SAXException the SAX exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 * @throws SAXException
 *             the SAX exception
 */
private void processList(IProgressMonitor monitor) throws IOException, SAXException {
	monitor.beginTask(Messages.getString("html.Html2Xliff.task2"), segments.size());
	monitor.subTask("");
	for (int i = 0; i < segments.size(); i++) {
		if (monitor.isCanceled()) {
			throw new OperationCanceledException(Messages.getString("html.cancel"));
		}
		monitor.worked(1);
		String text = segments.get(i);
		if (isTranslateable(text)) {
			extractSegment(text);
		} else {
			// send directly to skeleton
			writeSkeleton(text);
		}
	}
	monitor.done();
}
 
Example #3
Source Project: tmxeditor8   Author: heartsome   File: SplitTmx.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 是否覆盖
 * @param fileLC
 * @return ;
 */
private void checkRepeate(final String fileLC, final IProgressMonitor monitor) {
	if (new File(fileLC).exists()) {
		if (!always) {
			Display.getDefault().syncExec(new Runnable() {
				@Override
				public void run() {
					FileCoverMsgDialog dialog = new FileCoverMsgDialog(Display.getDefault().getActiveShell(), fileLC);
					retunCode = dialog.open();
					always = dialog.isAlways();
				}
			});
		}
	}else {
		retunCode = FileCoverMsgDialog.OVER;
	}
	if (retunCode == FileCoverMsgDialog.CANCEL) {
		monitor.setCanceled(true);
		throw new OperationCanceledException();
	}
}
 
Example #4
Source Project: google-cloud-eclipse   Author: GoogleCloudPlatform   File: WarPublisher.java    License: Apache License 2.0 6 votes vote down vote up
public static IStatus[] publishExploded(IProject project, IPath destination,
    IPath safeWorkDirectory, IProgressMonitor monitor) throws CoreException {
  Preconditions.checkNotNull(project, "project is null"); //$NON-NLS-1$
  Preconditions.checkNotNull(destination, "destination is null"); //$NON-NLS-1$
  Preconditions.checkArgument(!destination.isEmpty(), "destination is empty path"); //$NON-NLS-1$
  Preconditions.checkNotNull(safeWorkDirectory, "safeWorkDirectory is null"); //$NON-NLS-1$
  if (monitor.isCanceled()) {
    throw new OperationCanceledException();
  }

  SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
  subMonitor.setTaskName(Messages.getString("task.name.publish.war")); //$NON-NLS-1$

  IModuleResource[] resources =
      flattenResources(project, safeWorkDirectory, subMonitor.newChild(10));
  if (resources.length == 0) {
    IStatus error = StatusUtil.error(WarPublisher.class, project.getName()
        + " has no resources to publish"); //$NON-NLS-1$
    return new IStatus[] {error};
  }
  return PublishUtil.publishFull(resources, destination, subMonitor.newChild(90));
}
 
Example #5
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: BuildPathsBlock.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public static void addJavaNature(IProject project, IProgressMonitor monitor) throws CoreException {
	if (monitor != null && monitor.isCanceled()) {
		throw new OperationCanceledException();
	}
	if (!project.hasNature(JavaCore.NATURE_ID)) {
		IProjectDescription description = project.getDescription();
		String[] prevNatures= description.getNatureIds();
		String[] newNatures= new String[prevNatures.length + 1];
		System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
		newNatures[prevNatures.length]= JavaCore.NATURE_ID;
		description.setNatureIds(newNatures);
		project.setDescription(description, monitor);
	} else {
		if (monitor != null) {
			monitor.worked(1);
		}
	}
}
 
Example #6
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: ReorgQueries.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private boolean getResult(int[] result) throws OperationCanceledException {
	switch(result[0]){
		case IDialogConstants.YES_TO_ALL_ID:
			fYesToAll= true;
			return true;
		case IDialogConstants.YES_ID:
			return true;
		case IDialogConstants.CANCEL_ID:
			throw new OperationCanceledException();
		case IDialogConstants.NO_ID:
			return false;
		case IDialogConstants.NO_TO_ALL_ID:
			fNoToAll= true;
			return false;
		default:
			Assert.isTrue(false);
			return false;
	}
}
 
Example #7
Source Project: xtext-core   Author: eclipse   File: ReferenceFinder.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void findReferences(
		TargetURIs targetURIs,
		Set<URI> candidates,
		IResourceAccess resourceAccess,
		IResourceDescriptions descriptions,
		Acceptor acceptor,
		IProgressMonitor monitor) {
	if (!targetURIs.isEmpty() && !candidates.isEmpty()) {
		SubMonitor subMonitor = SubMonitor.convert(monitor, targetURIs.size() / MONITOR_CHUNK_SIZE + 1);
		IProgressMonitor useMe = subMonitor.newChild(1);
		int i = 0;
		for (URI candidate : candidates) {
			if (subMonitor.isCanceled())
				throw new OperationCanceledException();
			IReferenceFinder languageSpecific = getLanguageSpecificReferenceFinder(candidate);
			doFindReferencesWith(languageSpecific, targetURIs, candidate, resourceAccess, descriptions, acceptor, useMe);
			i++;
			if (i % MONITOR_CHUNK_SIZE == 0) {
				useMe = subMonitor.newChild(1);
			}
		}
	}
}
 
Example #8
Source Project: translationstudio8   Author: heartsome   File: Html2Xliff.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Process list.
 * @throws ParserConfigurationException
 *             * @throws SAXException the SAX exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 * @throws SAXException
 *             the SAX exception
 */
private void processList(IProgressMonitor monitor) throws IOException, SAXException {
	monitor.beginTask(Messages.getString("html.Html2Xliff.task2"), segments.size());
	monitor.subTask("");
	for (int i = 0; i < segments.size(); i++) {
		if (monitor.isCanceled()) {
			throw new OperationCanceledException(Messages.getString("html.cancel"));
		}
		monitor.worked(1);
		String text = segments.get(i);
		if (isTranslateable(text)) {
			extractSegment(text);
		} else {
			// send directly to skeleton
			writeSkeleton(text);
		}
	}
	monitor.done();
}
 
Example #9
Source Project: xtext-eclipse   Author: eclipse   File: AbstractBuilderState.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public synchronized ImmutableList<IResourceDescription.Delta> update(BuildData buildData, IProgressMonitor monitor) {
	ensureLoaded();
	final SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.AbstractBuilderState_0, 1);
	subMonitor.subTask(Messages.AbstractBuilderState_0);
	if (buildData.isEmpty())
		return ImmutableList.of();
	if (monitor.isCanceled())
		throw new OperationCanceledException();

	final ResourceDescriptionsData newData = getCopiedResourceDescriptionsData();
	final Collection<IResourceDescription.Delta> result = doUpdate(buildData, newData, subMonitor.split(1));

	if (monitor.isCanceled())
		throw new OperationCanceledException();
	final ResourceDescriptionChangeEvent event = new ResourceDescriptionChangeEvent(result);
	// update the reference
	setResourceDescriptionsData(newData);
	notifyListeners(event);
	return event.getDeltas();
}
 
Example #10
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: ExternalizeStringsAction.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private List<NonNLSElement> analyze(IPackageFragment pack, IProgressMonitor pm) throws CoreException {
	try{
		if (pack == null)
			return new ArrayList<NonNLSElement>(0);

		ICompilationUnit[] cus= pack.getCompilationUnits();

		pm.beginTask("", cus.length); //$NON-NLS-1$
		pm.setTaskName(pack.getElementName());

		List<NonNLSElement> l= new ArrayList<NonNLSElement>(cus.length);
		for (int i= 0; i < cus.length; i++){
			pm.subTask(BasicElementLabels.getFileName(cus[i]));
			NonNLSElement element= analyze(cus[i]);
			if (element != null)
				l.add(element);
			pm.worked(1);
			if (pm.isCanceled())
				throw new OperationCanceledException();
		}
		return l;
	} finally {
		pm.done();
	}
}
 
Example #11
Source Project: xtext-eclipse   Author: eclipse   File: ResourceRelocationProcessor.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected void executeParticipants(ResourceRelocationContext context, SubMonitor monitor) {
	List<? extends IResourceRelocationStrategy> strategies = strategyRegistry.getStrategies();
	if (context.getChangeType() == ResourceRelocationContext.ChangeType.COPY) {
		context.getChangeSerializer().setUpdateRelatedFiles(false);
	}

	monitor.setWorkRemaining(strategies.size());

	for (IResourceRelocationStrategy strategy : strategies) {
		try {
			monitor.split(1);
			strategy.applyChange(context);
		} catch (OperationCanceledException t) {
			issues.add(ERROR, "Operation was cancelled while applying resource changes", t);
			LOG.error(t.getMessage(), t);
			break;
		}
	}
}
 
Example #12
Source Project: eclipse.jdt.ls   Author: eclipse   File: CreateCopyOfCompilationUnitChange.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected IFile getOldFile(IProgressMonitor monitor) throws OperationCanceledException {
	try {
		monitor.beginTask("", 12); //$NON-NLS-1$
		String oldSource= super.getSource();
		IPath oldPath= super.getPath();
		String newTypeName= fNameQuery.getNewName();
		try {
			String newSource= getCopiedFileSource(new SubProgressMonitor(monitor, 9), fOldCu, newTypeName);
			setSource(newSource);
			setPath(fOldCu.getResource().getParent().getFullPath().append(JavaModelUtil.getRenamedCUName(fOldCu, newTypeName)));
			return super.getOldFile(new SubProgressMonitor(monitor, 1));
		} catch (CoreException e) {
			setSource(oldSource);
			setPath(oldPath);
			return super.getOldFile(new SubProgressMonitor(monitor, 2));
		}
	} finally {
		monitor.done();
	}
}
 
Example #13
Source Project: typescript.java   Author: angelozerr   File: TypeScriptRenameProcessor.java    License: MIT License 6 votes vote down vote up
@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm, CheckConditionsContext context)
		throws CoreException, OperationCanceledException {
	RefactoringStatus status = new RefactoringStatus();
	// Consume "rename" tsserver command.
	try {
		rename = tsFile.rename(offset, isFindInComments(), isFindInStrings()).get(1000, TimeUnit.MILLISECONDS);
		RenameInfo info = rename.getInfo();
		if (!info.isCanRename()) {
			// Refactoring cannot be done.
			status.addError(info.getLocalizedErrorMessage());
		}
	} catch (Exception e) {
		status.addError(e.getMessage());
	}
	return status;
}
 
Example #14
Source Project: xtext-eclipse   Author: eclipse   File: DerivedResourceCleanerJob.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected IStatus cleanUpDerivedResources(IProgressMonitor monitor, IProject project) throws CoreException, OperationCanceledException {
	if (monitor.isCanceled()) {
		return Status.CANCEL_STATUS;
	}
	if (shouldBeProcessed(project)) {
		IContainer container = project;
		if (folderNameToClean != null)
			container = container.getFolder(new Path(folderNameToClean));
		for (IFile derivedFile : derivedResourceMarkers.findDerivedResources(container, null)) {
			derivedFile.delete(true, monitor);
			if (monitor.isCanceled()) {
				return Status.CANCEL_STATUS;
			}
		}
	}
	return Status.OK_STATUS;
}
 
Example #15
Source Project: xtext-eclipse   Author: eclipse   File: RenamedElementTracker.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Map<URI, URI> renameAndTrack(Iterable<URI> renamedElementURIs, String newName, ResourceSet resourceSet, IRenameStrategy renameStrategy, IProgressMonitor monitor) {
	Map<EObject, URI> renamedElement2oldURI = resolveRenamedElements(renamedElementURIs, resourceSet);
	if (monitor.isCanceled()) {
		throw new OperationCanceledException();
	}
	renameStrategy.applyDeclarationChange(newName, resourceSet);
	if (monitor.isCanceled()) {
		throw new OperationCanceledException();
	}
	Map<URI, URI> old2newURI = relocateRenamedElements(renamedElement2oldURI);
	if (monitor.isCanceled()) {
		throw new OperationCanceledException();
	}
	renameStrategy.revertDeclarationChange(resourceSet);
	return old2newURI;
}
 
Example #16
Source Project: eclipse-cs   Author: checkstyle   File: Auditor.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void fileStarted(AuditEvent event) {

  if (mMonitor.isCanceled()) {
    throw new OperationCanceledException();
  }

  // get the current IFile reference
  mResource = getFile(event.getFileName());
  mMarkerCount = 0;

  if (mResource != null) {

    // begin subtask
    if (mMonitorCounter == 0) {
      mMonitor.subTask(NLS.bind(Messages.Auditor_msgCheckingFile, mResource.getName()));
    }

    // increment monitor-counter
    this.mMonitorCounter++;
  } else {

    IPath filePath = new Path(event.getFileName());
    IPath dirPath = filePath.removeFileExtension().removeLastSegments(1);

    IPath projectPath = mProject.getLocation();
    if (projectPath.isPrefixOf(dirPath)) {
      // find the resource with a project relative path
      mResource = mProject.findMember(dirPath.removeFirstSegments(projectPath.segmentCount()));
    } else {
      // if the resource is not inside the project, take project
      // as resource - this should not happen
      mResource = mProject;
    }
  }
}
 
Example #17
Source Project: xtext-eclipse   Author: eclipse   File: EmfResourceReferenceUpdater.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void createReferenceUpdates(ElementRenameArguments elementRenameArguments,
		Multimap<URI, IReferenceDescription> resource2references, ResourceSet resourceSet,
		IRefactoringUpdateAcceptor updateAcceptor, IProgressMonitor monitor) {
	for (URI referringResourceURI : resource2references.keySet()) {
		try {
			if (monitor.isCanceled())
				throw new OperationCanceledException();
			Resource referringResource = resourceSet.getResource(referringResourceURI, false);
			EObject refactoredElement = resourceSet.getEObject(elementRenameArguments.getNewElementURI(elementRenameArguments.getTargetElementURI()), true);
			if (referringResource != refactoredElement.eResource()) {
				if (refactoredElement instanceof EClassifier) { 
					for (IReferenceDescription reference : resource2references.get(referringResourceURI)) {
						EObject source = referringResource.getEObject(reference.getSourceEObjectUri().fragment());
						if (source == null) {
							LOG.error("Couldn't find source element "+ reference.getSourceEObjectUri() + " in " + referringResource.getURI());
						} else {
							EObject referringEReference = source.eContainer();
							if (referringEReference != null && referringEReference instanceof EReference)
								((EReference) referringEReference).setEType((EClassifier) refactoredElement);
						}
					}
				}
				changeUtil.addSaveAsUpdate(referringResource, updateAcceptor);
			}
		} catch (OperationCanceledException e) {
			throw e;
		} catch (Exception exc) {
			throw new WrappedException(exc);
		}
	}
}
 
Example #18
Source Project: saros   Author: saros-project   File: EclipseFileImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Updates encoding of a file. An effort is made to use the inherited encoding if available.
 *
 * <p>Does nothing if the file does not exist.
 *
 * @param encoding the encoding that should be used
 * @throws CoreException if setting the encoding failed
 * @throws OperationCanceledException if the setting of the charset was canceled
 * @see org.eclipse.core.resources.IFile#setCharset(String, IProgressMonitor)
 */
private void updateFileEncoding(final String encoding)
    throws CoreException, OperationCanceledException {

  final org.eclipse.core.resources.IFile file = getDelegate();

  if (!file.exists()) return;

  String projectEncoding = file.getProject().getDefaultCharset();
  String fileEncoding = file.getCharset();

  if (encoding.equals(fileEncoding)) {
    log.debug("encoding does not need to be changed for file: " + file);

    return;
  }

  // use inherited encoding if possible
  if (encoding.equals(projectEncoding)) {
    log.debug(
        "changing encoding for file "
            + file
            + " to use default project encoding: "
            + projectEncoding);

    file.setCharset(null, new NullProgressMonitor());

    return;
  }

  log.debug("changing encoding for file " + file + " to encoding: " + encoding);

  file.setCharset(encoding, new NullProgressMonitor());
}
 
Example #19
Source Project: APICloud-Studio   Author: apicloudcom   File: SubclipseSubscriberChangeSetManager.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected boolean doDispatchEvents(IProgressMonitor monitor) throws TeamException {
         if (dispatchEvents.isEmpty()) {
             return false;
         }
         if (isShutdown())
             throw new OperationCanceledException();
         ResourceDiffTree[] locked = null;
         try {
             locked = beginDispath();
             for (Iterator iter = dispatchEvents.iterator(); iter.hasNext();) {
                 Event event = (Event) iter.next();
              switch (event.getType()) {
              case RESOURCE_REMOVAL:
                  handleRemove(event.getResource());
                  break;
              case RESOURCE_CHANGE:
                  handleChange(event.getResource(), ((ResourceEvent)event).getDepth());
                  break;
              default:
                  break;
              }
                 if (isShutdown())
                     throw new OperationCanceledException();
             }
         } catch (CoreException e) {
	throw TeamException.asTeamException(e);
} finally {
             try {
                 endDispatch(locked, monitor);
             } finally {
                 dispatchEvents.clear();
             }
         }
         return true;
     }
 
Example #20
Source Project: eclipse.jdt.ls   Author: eclipse   File: ModelBasedSearchableEnvironment.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void findTypes(char[] prefix, final boolean findMembers, boolean camelCaseMatch, int searchFor, final ISearchRequestor storage, IProgressMonitor monitor) {
	if (monitor != null && monitor.isCanceled()) {
		throw new OperationCanceledException();
	}

	JavaLanguageServerPlugin.logInfo("Search engine disabled, searching directly.");
	// Look for types in the model instead of a search request
	findTypes(new String(prefix), storage, convertSearchFilterToModelFilter(searchFor));
}
 
Example #21
Source Project: n4js   Author: eclipse   File: FutureUtil.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private static Throwable getCancellation(Throwable e) {
	while (e != null) {
		if (e instanceof OperationCanceledError
				|| e instanceof OperationCanceledException
				|| e instanceof CancellationException) {
			return e;
		}
		e = e.getCause();
	}
	return null;
}
 
Example #22
Source Project: gwt-eclipse-plugin   Author: gwt-plugins   File: PairedInterfaceRenameParticipant.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Change createChange(IProgressMonitor pm) throws CoreException,
    OperationCanceledException {

  // checkConditions is the first entry point (for us) after the user
  // changes the refactoring's new name. Recompute it here.
  if (!updateNewNameMetadata()) {
    return null;
  }

  // Prevent infinite recursion
  if (typeContainer.getPairedType().equals(refactoringContext.visitedType)) {
    return null;
  }

  Change change;
  try {
    change = createChangeForInterfaceRename();
  } catch (RefactoringException e) {
    GWTPluginLog.logError(e);
    return null;
  }

  if (ChangeUtilities.mergeParticipantTextChanges(this, change)) {
    // All our changes were merged into existing shared text changes,
    // therefore this participant does nothing
    return null;
  }

  weaveChange(change);

  return change;
}
 
Example #23
Source Project: Pydev   Author: fabioz   File: ChangedFilesChecker.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Checks the given files that have been changed by validating them with the workspace.
 * 
 * @param files the files to check
 * @param validationContext the context for validating the files.  Should be the value of 
 *      {@link org.eclipse.ltk.core.refactoring.Refactoring#getValidationContext()}.
 * @param refactoringStatus the value to store the detection of problems.
 * @throws CoreException when the validation is canceled
 */
public static void checkFiles(Collection<IFile> files, Object validationContext,
        RefactoringStatus refactoringStatus) throws CoreException {
    List<IFile> readOnly = new ArrayList<IFile>();
    for (IFile file : files) {
        if (file.isReadOnly()) {
            readOnly.add(file);
        }
    }
    if (ResourcesPlugin.getPlugin() == null) {
        //i.e.: in test mode we won't be able to get the workspace
        return;
    }
    if (!readOnly.isEmpty()) {
        IFile[] readOnlyFiles = readOnly.toArray(new IFile[readOnly.size()]);
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IStatus status = workspace.validateEdit(readOnlyFiles, validationContext);
        if (status.getSeverity() == IStatus.CANCEL) {
            throw new OperationCanceledException();
        }
        refactoringStatus.merge(RefactoringStatus.create(status));
        if (refactoringStatus.hasFatalError()) {
            return;
        }
    }
    refactoringStatus.merge(ResourceChangeChecker.checkFilesToBeChanged(
            files.toArray(new IFile[files.size()]), null));
}
 
Example #24
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: ReorgQueries.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public boolean confirm(String question, Object[] elements) throws OperationCanceledException {
	if (fYesToAll)
		return true;

	if (fNoToAll)
		return false;

	final int[] result= new int[1];
	fShell.getDisplay().syncExec(createQueryRunnable(question, elements, result));
	return getResult(result);
}
 
Example #25
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException,
		OperationCanceledException {
	RefactoringStatus status = preCheckInitialConditions(pm);
	if(status.hasError())
		return status;
	return super.checkInitialConditions(pm);
}
 
Example #26
private void internalRun(boolean fork, final IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException {
	Thread thread= Thread.currentThread();
	// Do not spawn another thread if we are already in a modal context
	// thread or inside a busy context thread.
	if (thread instanceof ThreadContext || ModalContext.isModalContextThread(thread))
		fork= false;

	if (fork) {
		final ThreadContext t= new ThreadContext(runnable);
		t.start();
		t.sync();
		// Check if the separate thread was terminated by an exception
		Throwable throwable= t.fThrowable;
		if (throwable != null) {
			if (throwable instanceof InvocationTargetException) {
				throw (InvocationTargetException) throwable;
			} else if (throwable instanceof InterruptedException) {
				throw (InterruptedException) throwable;
			} else if (throwable instanceof OperationCanceledException) {
				throw new InterruptedException();
			} else {
				throw new InvocationTargetException(throwable);
			}
		}
	} else {
		try {
			runnable.run(new NullProgressMonitor());
		} catch (OperationCanceledException e) {
			throw new InterruptedException();
		}
	}
}
 
Example #27
Source Project: JDeodorant   Author: tsantalis   File: MoveMethodRefactoring.java    License: MIT License 5 votes vote down vote up
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
		throws CoreException, OperationCanceledException {
	RefactoringStatus status= new RefactoringStatus();
	try {
		pm.beginTask("Checking preconditions...", 1);
	} finally {
		pm.done();
	}
	return status;
}
 
Example #28
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: CleanUpRefactoring.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
	if (pm != null) {
		pm.beginTask("", 1); //$NON-NLS-1$
		pm.worked(1);
		pm.done();
	}
	return new RefactoringStatus();
}
 
Example #29
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: OpenTypeHistory.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private synchronized void internalCheckConsistency(IProgressMonitor monitor) throws OperationCanceledException {
	// Setting fNeedsConsistencyCheck is necessary here since
	// markAsInconsistent isn't synchronized.
	fNeedsConsistencyCheck= true;
	List<Object> typesToCheck= new ArrayList<Object>(getKeys());
	monitor.beginTask(CorextMessages.TypeInfoHistory_consistency_check, typesToCheck.size());
	monitor.setTaskName(CorextMessages.TypeInfoHistory_consistency_check);
	for (Iterator<Object> iter= typesToCheck.iterator(); iter.hasNext();) {
		TypeNameMatch type= (TypeNameMatch)iter.next();
		long currentTimestamp= getContainerTimestamp(type);
		Long lastTested= fTimestampMapping.get(type);
		if (lastTested != null && currentTimestamp != IResource.NULL_STAMP && currentTimestamp == lastTested.longValue() && !isContainerDirty(type))
			continue;
		try {
			IType jType= type.getType();
			if (jType == null || !jType.exists()) {
				remove(type);
			} else {
				// copy over the modifiers since they may have changed
				int modifiers= jType.getFlags();
				if (modifiers != type.getModifiers()) {
					replace(type, SearchEngine.createTypeNameMatch(jType, modifiers));
				} else {
					fTimestampMapping.put(type, new Long(currentTimestamp));
				}
			}
		} catch (JavaModelException e) {
			remove(type);
		}
		if (monitor.isCanceled())
			throw new OperationCanceledException();
		monitor.worked(1);
	}
	monitor.done();
	fNeedsConsistencyCheck= false;
}
 
Example #30
Source Project: saros   Author: saros-project   File: EclipseFileImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void create(InputStream input) throws IOException {
  try {
    getDelegate().create(input, false, null);
  } catch (CoreException | OperationCanceledException e) {
    throw new IOException(e);
  }
}