Java Code Examples for org.eclipse.xtext.util.Exceptions#throwUncheckedException()

The following examples show how to use org.eclipse.xtext.util.Exceptions#throwUncheckedException() . 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 File: FutureUtil.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Obtains the given future's result via {@link Future#get()}, but converts <code>java.util.concurrent</code>'s
 * {@link CancellationException} to Xtext's {@link OperationCanceledException} and wraps checked exceptions in a
 * {@link RuntimeException}.
 */
public static <T> T getCancellableResult(Future<T> future) {
	try {
		return future.get();
	} catch (Throwable e) {
		Throwable cancellation = getCancellation(e);
		if (cancellation instanceof OperationCanceledError) {
			throw (OperationCanceledError) cancellation;
		} else if (cancellation instanceof OperationCanceledException) {
			throw (OperationCanceledException) cancellation;
		} else if (cancellation instanceof CancellationException) {
			String msg = e.getMessage();
			if (msg != null) {
				throw new OperationCanceledException(e.getMessage());
			}
			throw new OperationCanceledException();
		}
		return Exceptions.throwUncheckedException(e);
	}
}
 
Example 2
Source File: TestedWorkspace.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public <Result> Result run(IWorkspaceModifyOperationWithResult<? extends Result> op) {
	try {
		return new WorkspaceModifyOperation(op.getRule()) {
			Result result;
			@Override
			protected void execute(IProgressMonitor monitor) throws InvocationTargetException, CoreException, InterruptedException {
				this.result = op.compute(monitor);
			}
			protected Result getResult() throws InvocationTargetException, InterruptedException {
				run(monitor());
				return result;
			}
		}.getResult();
	} catch (InvocationTargetException | InterruptedException e) {
		return Exceptions.throwUncheckedException(e);
	}
}
 
Example 3
Source File: CompilationTestHelper.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Parses, validates and compiles the given source. Calls the given acceptor for each
 * resource which is generated from the source.
 *  
 * @param resourceSet - the {@link ResourceSet} to use
 * @param acceptor gets called once for each file generated in {@link IGenerator}
 */
public void compile(final ResourceSet resourceSet, IAcceptor<Result> acceptor) {
	try {
		List<Resource> resourcesToCheck = newArrayList(resourceSet.getResources());
		Result result = resultProvider.get();
		result.setJavaCompiler(javaCompiler);
		result.setCheckMode(getCheckMode());
		result.setResources(resourcesToCheck);
		result.setResourceSet(resourceSet);
		result.setOutputConfigurations(getOutputConfigurations());
		result.doGenerate();
		acceptor.accept(result);
	} catch (Exception e) {
		Exceptions.throwUncheckedException(e);
	}
}
 
Example 4
Source File: N4IDEXpectCompareEditorInput.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected Object prepareInput(IProgressMonitor pm) {
	try {
		ResourceNode ancestor = new ResourceNode(file);
		String ancestorContent = getContent(ancestor);
		String leftContent, rightContent;

		leftContent = this.comparisonFailure.getExpected();
		rightContent = this.comparisonFailure.getActual();
		if (!leftContent.equals(ancestorContent))
			getCompareConfiguration().setProperty(ICompareUIConstants.PROP_ANCESTOR_VISIBLE, Boolean.TRUE);
		CompareItem left = new EditableCompareItem("Left", leftContent, file);
		CompareItem right = new CompareItem("Right", rightContent);
		return new DiffNode(null, Differencer.CHANGE | Differencer.DIRECTION_MASK, ancestor, left, right);
	} catch (Throwable t) {
		LOG.error(t.getMessage(), t);
		Exceptions.throwUncheckedException(t);
		return null;
	}
}
 
Example 5
Source File: AbstractExtraLanguageValidator.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Handle an exception.
 *
 * @param targetException the exception.
 * @param context the context.
 */
@SuppressWarnings("static-method")
protected void handleInvocationTargetException(Throwable targetException, Context context) {
	// ignore NullPointerException, as not having to check for NPEs all the time is a convenience feature
	if (!(targetException instanceof NullPointerException)) {
		Exceptions.throwUncheckedException(targetException);
	}
}
 
Example 6
Source File: TestedWorkspace.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void addNature(IProject project, String natureId) {
	try {
		IResourcesSetupUtil.addNature(project, natureId);
	} catch (Exception e) {
		Exceptions.throwUncheckedException(e);
	}
}
 
Example 7
Source File: TestedWorkspace.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void cleanBuild() {
	try {
		joinJobsBeforeBuild();
		IResourcesSetupUtil.cleanBuild();
	} catch (Exception e) {
		Exceptions.throwUncheckedException(e);
	}
}
 
Example 8
Source File: TestedWorkspace.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void setReference(final IProject from, final IProject to) {
	try {
		IResourcesSetupUtil.setReference(from, to);
	} catch (Exception e) {
		Exceptions.throwUncheckedException(e);
	}
}
 
Example 9
Source File: TestedWorkspaceWithJDT.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public IFolder createSubFolder(IProject project, String name) {
	try {
		return IResourcesSetupUtil.createFolder(project.getFolder(name).getFullPath());
	} catch(Exception e) {
		return Exceptions.throwUncheckedException(e);
	}
}
 
Example 10
Source File: TestedWorkspaceWithJDT.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void addSourceFolder(IJavaProject project, String folder) {
	try {
		JavaProjectSetupUtil.addSourceFolder(project, folder, false);
		build();
	} catch(Exception e) {
		Exceptions.throwUncheckedException(e);
	}
}
 
Example 11
Source File: TestedWorkspaceWithJDT.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void removeProjectReference(IJavaProject from, IJavaProject to) {
	try {
		JavaProjectSetupUtil.removeProjectReference(from, to);
		removeDynamicProjectReference(from.getProject(), to.getProject());
		build();
	} catch(Exception e) {
		Exceptions.throwUncheckedException(e);
	}
}
 
Example 12
Source File: TestedWorkspace.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public String readFile(IFile file) {
	try {
		return IResourcesSetupUtil.fileToString(file);
	} catch (Exception e) {
		return Exceptions.throwUncheckedException(e);
	}
}
 
Example 13
Source File: TestedWorkspaceWithJDT.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void addToClasspath(IJavaProject project, IClasspathEntry newClassPathEntry) {
	try {
		JavaProjectSetupUtil.addToClasspath(project, newClassPathEntry, false);
		build();
	} catch(Exception e) {
		Exceptions.throwUncheckedException(e);
	}
}
 
Example 14
Source File: TestedWorkspaceWithJDT.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Join on the job that updates the classpath after a manifest change. 
 * The calling thread will effectively wait for that job to finish.
 */
protected void joinUpdateClasspathJob() {
	try {
		// Pseudo fence to make sure that we see what we want to see.
		synchronized (this) {
			wait(1);
		}
		Job joinMe = updateClasspathJob;
		if (joinMe != null) {
			joinMe.join();
		}
	} catch (Exception e) {
		Exceptions.throwUncheckedException(e);
	}
}
 
Example 15
Source File: Bug486584Test.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private IFile copyAndGetXtendExampleJar(IJavaProject javaProject) throws CoreException {
	IFile file = javaProject.getProject().getFile(XTEND_EXAMPLE_JAR);
	try (InputStream inputStream = Bug486584Test.class.getResourceAsStream(XTEND_EXAMPLE_JAR)) {
		file.create(inputStream, IResource.FORCE, null);	
	} catch (IOException e) {
		Exceptions.throwUncheckedException(e);
	}
	return file;
}
 
Example 16
Source File: TestedWorkspace.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public IProject createProject(String name) {
	try {
		return IResourcesSetupUtil.createProject(name);
	} catch (Exception e) {
		return Exceptions.throwUncheckedException(e);
	}
}
 
Example 17
Source File: TestedWorkspace.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void removeNature(IProject project, String natureId) {
	try {
		IResourcesSetupUtil.removeNature(project, natureId);
	} catch (Exception e) {
		Exceptions.throwUncheckedException(e);
	}
}
 
Example 18
Source File: SARLLabelProvider.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Invoked when an image descriptor cannot be found.
 *
 * @param params the parameters given to the method polymorphic dispatcher.
 * @param exception the cause of the error.
 * @return the image descriptor for the error.
 */
protected ImageDescriptor handleImageDescriptorError(Object[] params, Throwable exception) {
	if (exception instanceof NullPointerException) {
		final Object defaultImage = getDefaultImage();
		if (defaultImage instanceof ImageDescriptor) {
			return (ImageDescriptor) defaultImage;
		}
		if (defaultImage instanceof Image) {
			return ImageDescriptor.createFromImage((Image) defaultImage);
		}
		return super.imageDescriptor(params[0]);
	}
	return Exceptions.throwUncheckedException(exception);
}
 
Example 19
Source File: DeclarativeLabelProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected Object handleImageError(Object[] params, Throwable e) {
	if(e instanceof NullPointerException) {
		return getDefaultImage();
	}
	return Exceptions.throwUncheckedException(e);
}
 
Example 20
Source File: AbstractDeclarativeValidator.java    From xtext-core with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Handles exceptions occuring during execution of validation code. 
 * By default this method will swallow {@link NullPointerException NullPointerExceptions} and {@link GuardException}s.
 * Clients may override this method to propagate {@link NullPointerException NullPointerExceptions} or more smarter
 * handling.
 * 
 * @since 2.17
 */
protected void handleExceptionDuringValidation(Throwable targetException) throws RuntimeException {
	// ignore NullPointerException, as not having to check for NPEs all the time is a convenience feature
	// ignore GuardException, check is just not evaluated if guard is false
	if (!(targetException instanceof GuardException) && !(targetException instanceof NullPointerException)) {
		Exceptions.throwUncheckedException(targetException);
	}
}