org.eclipse.emf.common.util.WrappedException Java Examples

The following examples show how to use org.eclipse.emf.common.util.WrappedException. 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: JavaClassPathResourceForIEditorInputFactoryTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test(expected=CoreException.class) public void testBug463258_03b() throws Throwable {
	IJavaProject project = createJavaProject("foo");
	IFile file = project.getProject().getFile("foo.jar");
	file.create(jarInputStream(new TextFile("foo/bar.testlanguage", "//empty")), true, monitor());
	
	IPackageFragmentRoot root = JarPackageFragmentRootTestUtil.getJarPackageFragmentRoot(file, (JavaProject) project);
	IPackageFragment foo = root.getPackageFragment("foo");
	JarEntryFile fileInJar = new JarEntryFile("bar.testlanguage");
	fileInJar.setParent(foo);
	
	File jarFile = file.getLocation().toFile();
	assertTrue("exists", jarFile.exists());
	assertTrue("delete", jarFile.delete());
	
	XtextReadonlyEditorInput editorInput = new XtextReadonlyEditorInput(fileInJar);
	try {
		factory.createResource(editorInput);
	} catch(WrappedException e) {
		throw e.getCause();
	}
}
 
Example #2
Source File: BuildInstruction.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private boolean shouldGenerate(Resource resource, IProject aProject) {
	try {
		Iterable<Pair<IStorage, IProject>> storages = storage2UriMapper.getStorages(resource.getURI());
		for (Pair<IStorage, IProject> pair : storages) {
			if (pair.getFirst() instanceof IFile && pair.getSecond().equals(aProject)) {
				IFile file = (IFile) pair.getFirst();
				int findMaxProblemSeverity = file.findMaxProblemSeverity(null, true, IResource.DEPTH_INFINITE);
				// If the generator itself placed an error marker on the resource, we have to ignore that error.
				// Easiest way here is to remove that error marker-type and look for other severe errors once more:
				if (findMaxProblemSeverity == IMarker.SEVERITY_ERROR) {
					// clean
					GeneratorMarkerSupport generatorMarkerSupport = injector
							.getInstance(GeneratorMarkerSupport.class);
					generatorMarkerSupport.deleteMarker(resource);
					// and recompute:
					findMaxProblemSeverity = file.findMaxProblemSeverity(null, true, IResource.DEPTH_INFINITE);
				}
				// the final decision to build:
				return findMaxProblemSeverity != IMarker.SEVERITY_ERROR;
			}
		}
		return false;
	} catch (CoreException exc) {
		throw new WrappedException(exc);
	}
}
 
Example #3
Source File: CompositeProcessorPropertiesEditionComponent.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
 * 
 */
public Diagnostic validateValue(IPropertiesEditionEvent event) {
	Diagnostic ret = Diagnostic.OK_INSTANCE;
	if (event.getNewValue() != null) {
		try {
			if (EipViewsRepository.CompositeProcessor.Properties.name == event.getAffectedEditor()) {
				Object newValue = event.getNewValue();
				if (newValue instanceof String) {
					newValue = EEFConverterUtil.createFromString(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), (String)newValue);
				}
				ret = Diagnostician.INSTANCE.validate(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), newValue);
			}
		} catch (IllegalArgumentException iae) {
			ret = BasicDiagnostic.toDiagnostic(iae);
		} catch (WrappedException we) {
			ret = BasicDiagnostic.toDiagnostic(we);
		}
	}
	return ret;
}
 
Example #4
Source File: TransformerPropertiesEditionComponent.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
 * 
 */
public Diagnostic validateValue(IPropertiesEditionEvent event) {
	Diagnostic ret = Diagnostic.OK_INSTANCE;
	if (event.getNewValue() != null) {
		try {
			if (EipViewsRepository.Transformer.Properties.name == event.getAffectedEditor()) {
				Object newValue = event.getNewValue();
				if (newValue instanceof String) {
					newValue = EEFConverterUtil.createFromString(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), (String)newValue);
				}
				ret = Diagnostician.INSTANCE.validate(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), newValue);
			}
		} catch (IllegalArgumentException iae) {
			ret = BasicDiagnostic.toDiagnostic(iae);
		} catch (WrappedException we) {
			ret = BasicDiagnostic.toDiagnostic(we);
		}
	}
	return ret;
}
 
Example #5
Source File: InvocableEndpointPropertiesEditionComponent.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
 * 
 */
public Diagnostic validateValue(IPropertiesEditionEvent event) {
	Diagnostic ret = Diagnostic.OK_INSTANCE;
	if (event.getNewValue() != null) {
		try {
			if (EipViewsRepository.InvocableEndpoint.Properties.name == event.getAffectedEditor()) {
				Object newValue = event.getNewValue();
				if (newValue instanceof String) {
					newValue = EEFConverterUtil.createFromString(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), (String)newValue);
				}
				ret = Diagnostician.INSTANCE.validate(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), newValue);
			}
		} catch (IllegalArgumentException iae) {
			ret = BasicDiagnostic.toDiagnostic(iae);
		} catch (WrappedException we) {
			ret = BasicDiagnostic.toDiagnostic(we);
		}
	}
	return ret;
}
 
Example #6
Source File: JdtRenameParticipant.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected EClass getExpectedJvmType(IJavaElement javaElement) {
	try {
		switch (javaElement.getElementType()) {
			case IJavaElement.TYPE:
				if (((IType) javaElement).isEnum())
					return TypesPackage.Literals.JVM_ENUMERATION_TYPE;
				else
					return TypesPackage.Literals.JVM_TYPE;
			case IJavaElement.METHOD:
				if (((IMethod) javaElement).isConstructor())
					return TypesPackage.Literals.JVM_CONSTRUCTOR;
				else
					return TypesPackage.Literals.JVM_OPERATION;
			case IJavaElement.FIELD:
				if (((IField) javaElement).isEnumConstant())
					return TypesPackage.Literals.JVM_ENUMERATION_LITERAL;
				else
					return TypesPackage.Literals.JVM_FIELD;
			default:
				return null;
		}
	} catch (JavaModelException exc) {
		throw new WrappedException(exc);
	}
}
 
Example #7
Source File: AbstractAcfContentAssistTest.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Asserts the expected valid and invalid proposals based on the given registered source filename.
 *
 * @param sourceFileName
 *          the filename of the test source that the proposals were to be computed from, must not be {@code null}
 */
@SuppressWarnings("restriction")
private void assertSourceProposals(final String sourceFileName) {
  try {
    AcfContentAssistProcessorTestBuilder builder = newBuilder().append(getTestSource(sourceFileName).getContent());
    assertFalse(EXPECTED_PROPOSALS_NOT_SET, (acfContentAssistMarkerTagInfo.expectedProposalMap.isEmpty()
        && acfContentAssistMarkerTagInfo.notExpectedProposalMap.isEmpty() && acfContentAssistMarkerTagInfo.expectedExactlyProposalMap.isEmpty()));
    for (int markerId : getUsedTagsItems()) {
      final ICompletionProposal[] proposals = builder.computeCompletionProposals(getOffsetForTag(markerId));
      if (acfContentAssistMarkerTagInfo.expectedProposalMap.containsKey(markerId)) {
        assertCompletionProposal(proposals, acfContentAssistMarkerTagInfo.expectedProposalMap.get(markerId));
      }
      if (acfContentAssistMarkerTagInfo.notExpectedProposalMap.containsKey(markerId)) {
        assertNotCompletionProposal(proposals, acfContentAssistMarkerTagInfo.notExpectedProposalMap.get(markerId));
      }
      if (acfContentAssistMarkerTagInfo.expectedExactlyProposalMap.containsKey(markerId)) {
        assertExactlyCompletionProposal(proposals, acfContentAssistMarkerTagInfo.expectedExactlyProposalMap.get(markerId));
      }
    }
    // CHECKSTYLE:OFF
  } catch (Exception e) {
    // CHECKSTYLE:ON
    throw new WrappedException("Could not assert the expected valid and invalid proposals.", e);
  }
}
 
Example #8
Source File: AbstractPackratParser.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected final IParseResult parse(INonTerminalConsumer consumer) {
	if (activeMarker != null)
		throw new IllegalStateException("cannot parse now. Active marker is already assigned.");
	IMarker rootMarker = mark();
	IRootConsumerListener listener = new RootConsumerListener();
	try {
		consumer.consumeAsRoot(listener);
		IParseResult result = getParseResultFactory().createParseResult(activeMarker, input);
		rootMarker.commit();
		if (activeMarker != null)
			throw new IllegalStateException("cannot finish parse: active marker is still present.");
		return result;
	} catch(Exception e) {
		throw new WrappedException(e);
	}
}
 
Example #9
Source File: BaseEPackageAccess.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public static Resource loadResource(String string, XtextResourceSet resourceSet) {
	URI uri = URI.createURI(string);
	Resource resource;
	try {
		resource = resourceSet.getResource(uri, true);
		if (resource == null) {
			throw new IllegalArgumentException("Couldn't create resource for URI : " + uri);
		}
	} catch (Exception e) {
		throw new WrappedException(e);
	}
	EList<EObject> contents = resource.getContents();
	if (contents.size() < 1) {
		throw new IllegalStateException("loading classpath:" + string + " : Expected at least root element but found "
				+ contents.size());
	}
	return resource;
}
 
Example #10
Source File: ServiceActivatorPropertiesEditionComponent.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
 * 
 */
public Diagnostic validateValue(IPropertiesEditionEvent event) {
	Diagnostic ret = Diagnostic.OK_INSTANCE;
	if (event.getNewValue() != null) {
		try {
			if (EipViewsRepository.ServiceActivator.Properties.name == event.getAffectedEditor()) {
				Object newValue = event.getNewValue();
				if (newValue instanceof String) {
					newValue = EEFConverterUtil.createFromString(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), (String)newValue);
				}
				ret = Diagnostician.INSTANCE.validate(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), newValue);
			}
		} catch (IllegalArgumentException iae) {
			ret = BasicDiagnostic.toDiagnostic(iae);
		} catch (WrappedException we) {
			ret = BasicDiagnostic.toDiagnostic(we);
		}
	}
	return ret;
}
 
Example #11
Source File: CustomClassEcoreGeneratorFragment.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Generates a stub for a custom class (e.g. FooImplCustom) into the {@link CustomClassEcoreGeneratorFragment#javaModelSrcDirectories specified SRC folder}.
 *
 * @param from
 *          qualified name of default implementation class (e.g. FooImpl) to extend
 * @param customClassName
 *          qualified name of custom class to generate
 * @param path
 *          URI for resource to generate into
 */
@SuppressWarnings({"nls", "PMD.InsufficientStringBufferDeclaration"})
protected void generateCustomClassStub(final String from, final String customClassName, final URI path) {
  StringBuilder sb = new StringBuilder();
  // sb.append(copyright()).append("\n");
  int lastIndexOfDot = customClassName.lastIndexOf('.');
  sb.append("package ").append(customClassName.substring(0, lastIndexOfDot)).append(";\n\n\n");
  sb.append("public class ").append(customClassName.substring(lastIndexOfDot + 1)).append(" extends ").append(from).append(" {\n\n");
  sb.append("}\n");

  try {
    OutputStream stream = URIConverter.INSTANCE.createOutputStream(path);
    stream.write(sb.toString().getBytes());
    stream.close();
  } catch (IOException e) {
    throw new WrappedException(e);
  }
}
 
Example #12
Source File: EMFGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.0
 */
protected GenModel getSaveAndReconcileGenModel(ResourceSet rs, Grammar grammar, XpandExecutionContext ctx,
		List<EPackage> packs) throws ConfigurationException {
	GenModel genModel = getGenModel(rs, grammar, ctx, packs);
	genModel.initialize(packs);
	for (GenPackage genPackage : genModel.getGenPackages()) {
		genPackage.setBasePackage(getBasePackage(grammar));
		if (isSuppressLoadInitialization()) {
			genPackage.setLoadInitialization(false);
		}
		if (getFileExtensions() != null && packs.contains(genPackage.getEcorePackage())) {
			genPackage.setFileExtensions(getFileExtensions());
		}
	}
	Set<EPackage> referencedEPackages = getReferencedEPackages(packs);
	List<GenPackage> usedGenPackages = getGenPackagesForPackages(genModel, referencedEPackages);
	reconcileMissingGenPackagesInUsedModels(usedGenPackages);
	genModel.getUsedGenPackages().addAll(usedGenPackages);
	try {
		saveResource(genModel.eResource());
	} catch (IOException e) {
		throw new WrappedException(e);
	}
	new GenModelHelper().registerGenModel(genModel);
	return genModel;
}
 
Example #13
Source File: FileResourceHandler.java    From xtext-web with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public XtextWebDocument get(String resourceId, IServiceContext serviceContext) throws IOException {
	try {
		URI uri = resourceBaseProvider.getFileURI(resourceId);
		if (uri == null) {
			throw new IOException("The requested resource does not exist.");
		}
		ResourceSet resourceSet = resourceSetProvider.get(resourceId, serviceContext);
		XtextResource resource = (XtextResource) resourceSet.getResource(uri, true);
		XtextWebDocument document = documentProvider.get(resourceId, serviceContext);
		document.setInput(resource);
		return document;
	} catch (WrappedException exception) {
		throw Exceptions.sneakyThrow(exception.getCause());
	}
}
 
Example #14
Source File: YangPackageImpl.java    From yang-design-studio with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Laods the package and any sub-packages from their serialized form.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void loadPackage()
{
  if (isLoaded) return;
  isLoaded = true;

  URL url = getClass().getResource(packageFilename);
  if (url == null)
  {
    throw new RuntimeException("Missing serialized package: " + packageFilename);
  }
  URI uri = URI.createURI(url.toString());
  Resource resource = new EcoreResourceFactoryImpl().createResource(uri);
  try
  {
    resource.load(null);
  }
  catch (IOException exception)
  {
    throw new WrappedException(exception);
  }
  initializeFromLoadedEPackage(this, (EPackage)resource.getContents().get(0));
  createResource(eNS_URI);
}
 
Example #15
Source File: CoreSwtbotTools.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Performs some weird initialization steps needed to run the tests.
 *
 * @param bot
 *          to work with, must not be {@code null}
 */
public static void initializeWorkbench(final SwtWorkbenchBot bot) {
  Assert.isNotNull(bot, ARGUMENT_BOT);
  // Move mouse outside client area (to prevent problems with context menus)
  PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
    @Override
    public void run() {
      try {
        final Robot robot = new Robot();
        robot.mouseMove(MOUSE_POSITION_X, MOUSE_POSITION_Y);
      } catch (SWTException | AWTException wte) {
        throw new WrappedException("Error during initialisation SWT mouse", wte);
      }
    }
  });
  // The welcome page must be closed before resetting the workbench to avoid trashing the UI:
  bot.closeWelcomePage();
  bot.resetActivePerspective();
}
 
Example #16
Source File: ProjectCacheInvalidationPluginTest.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Performs the given {@code updateOperation} on the loaded AST of the given {@code packageJsonFile} and saves it to
 * disk.
 */
private void updatePackageJsonFile(IFile packageJsonFile, Consumer<JSONObject> updateOperation)
		throws CoreException {
	final IProject project = packageJsonFile.getProject();
	final ResourceSet resourceSet = resourceSetProvider.get(project);

	// read and parse package.json contents
	final String path = packageJsonFile.getFullPath().toString();
	final URI uri = URI.createPlatformResourceURI(path, true);
	final Resource resource = resourceSet.getResource(uri, true);

	final JSONObject root = PackageJSONTestUtils.getPackageJSONRoot(resource);
	updateOperation.accept(root);

	try {
		resource.save(null);
	} catch (IOException e) {
		throw new WrappedException("Failed to save package.json resource at " + resource.getURI().toString() + ".",
				e);
	}
	packageJsonFile.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
}
 
Example #17
Source File: JavaClassPathResourceForIEditorInputFactoryTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test(expected=CoreException.class) public void testBug463258_03c() throws Throwable {
	IJavaProject project = createJavaProject("foo");
	IFile file = project.getProject().getFile("foo.jar");
	file.create(jarInputStream(new TextFile("foo/bar.testlanguage", "//empty")), true, monitor());
	addJarToClasspath(project, file);
	
	IPackageFragmentRoot root = JarPackageFragmentRootTestUtil.getJarPackageFragmentRoot(file, (JavaProject) project);
	IPackageFragment foo = root.getPackageFragment("foo");
	JarEntryFile fileInJar = new JarEntryFile("bar.testlanguage");
	fileInJar.setParent(foo);
	
	File jarFile = file.getLocation().toFile();
	assertTrue("exists", jarFile.exists());
	assertTrue("delete", jarFile.delete());
	// simulate an automated refresh
	file.refreshLocal(IResource.DEPTH_ONE, null);
	XtextReadonlyEditorInput editorInput = new XtextReadonlyEditorInput(fileInJar);
	try {
		factory.createResource(editorInput);
	} catch(WrappedException e) {
		throw e.getCause();
	}
}
 
Example #18
Source File: JavaClassPathResourceForIEditorInputFactoryTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test(expected=CoreException.class) public void testBug463258_04() throws Throwable {
	IFolder externalFolder = createExternalFolder("externalFolder");
	IJavaProject project = createJavaProject("foo");
	
	addExternalFolderToClasspath(project, externalFolder);
	
	IPackageFragmentRoot root = project.getPackageFragmentRoot(externalFolder);
	IPackageFragment foo = root.getPackageFragment("foo");
	NonJavaResource fileInFolder = new NonJavaResource(foo, externalFolder.getFile("foo/doesNotExist.testlanguage"));
	
	externalFolder.delete(true, null);
	XtextReadonlyEditorInput editorInput = new XtextReadonlyEditorInput(fileInFolder);
	try {
		factory.createResource(editorInput);
	} catch(WrappedException e) {
		throw e.getCause();
	}
}
 
Example #19
Source File: EObjectDescriptions.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns scoped elements for all given objects by applying all given name functions. The result is first ordered by function
 * then by object. If a function returns null for a given object no corresponding scoped element will be included in the result.
 *
 * @param <T>
 *          type of model objects
 * @param objects
 *          model objects iterable
 * @param nameFunctions
 *          list of name functions
 * @return scoped element iterable
 */
public static <T extends IEObjectDescription> Iterable<IEObjectDescription> map(final Iterable<T> objects, final Iterable<INameFunction> nameFunctions) {
  return Iterables.concat(Iterables.transform(nameFunctions, new Function<INameFunction, Iterable<IEObjectDescription>>() {
    @Override
    public Iterable<IEObjectDescription> apply(final INameFunction param) {
      return Iterables.filter(Iterables.transform(objects, new Function<T, IEObjectDescription>() {
        @Override
        public IEObjectDescription apply(final T from) {
          try {
            if (from == null) {
              return null;
            }
            final QualifiedName name = param.apply(from);
            return (name == null) ? null : (name.equals(from.getName()) ? from : new AliasingEObjectDescription(name, from)); // NOPMD
            // CHECKSTYLE:OFF
          } catch (final Exception e) {
            // CHECKSTYLE:ON
            LOGGER.error(e.getMessage(), e);
            throw new WrappedException(e);
          }
        }
      }), Predicates.notNull());
    }
  }));
}
 
Example #20
Source File: DefaultMergeViewer.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected Object updateAsDocument(Object object) {
	if (object instanceof IResourceProvider && supportsSharedDocuments(object)) {
		return object;
	}
	if (object instanceof IStreamContentAccessor) {
		try {
			StreamContentAccessorDelegate streamContentAccessorDelegate = new StreamContentAccessorDelegate(
					(IStreamContentAccessor) object, createResourceProvider(object));
			documentProvider.connect(streamContentAccessorDelegate);
			inputObjectStreamContentAccessorMap.put(object, streamContentAccessorDelegate);
			return documentProvider.getDocument(streamContentAccessorDelegate);
		} catch (CoreException coreException) {
			throw new WrappedException(coreException);
		}
	}
	return object;
}
 
Example #21
Source File: DefaultMergeViewer.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected SourceViewerConfiguration createSourceViewerConfiguration(SourceViewer sourceViewer,
		IEditorInput editorInput) {
	SourceViewerConfiguration sourceViewerConfiguration = null;
	if (editorInput != null && getEditor(sourceViewer) != null) {
		DefaultMergeEditor mergeEditor = getEditor(sourceViewer);
		sourceViewerConfiguration = mergeEditor.getXtextSourceViewerConfiguration();
		try {
			mergeEditor.init((IEditorSite) mergeEditor.getSite(), editorInput);
			mergeEditor.createActions();
		} catch (PartInitException partInitException) {
			throw new WrappedException(partInitException);
		}
	} else {
		sourceViewerConfiguration = sourceViewerConfigurationProvider.get();
	}
	return sourceViewerConfiguration;
}
 
Example #22
Source File: GatewayPropertiesEditionComponent.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
 * 
 */
public Diagnostic validateValue(IPropertiesEditionEvent event) {
	Diagnostic ret = Diagnostic.OK_INSTANCE;
	if (event.getNewValue() != null) {
		try {
			if (EipViewsRepository.Gateway.Properties.name == event.getAffectedEditor()) {
				Object newValue = event.getNewValue();
				if (newValue instanceof String) {
					newValue = EEFConverterUtil.createFromString(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), (String)newValue);
				}
				ret = Diagnostician.INSTANCE.validate(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), newValue);
			}
		} catch (IllegalArgumentException iae) {
			ret = BasicDiagnostic.toDiagnostic(iae);
		} catch (WrappedException we) {
			ret = BasicDiagnostic.toDiagnostic(we);
		}
	}
	return ret;
}
 
Example #23
Source File: AbstractSimulationEngine.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
protected void handleException(Throwable t) {
	if (t instanceof WrappedException) {
		t = ((WrappedException) t).getCause();
	}
	String statusMessage = t.getMessage() == null ? ERROR_MSG : t.getMessage();
	Status errorStatus = new Status(Status.ERROR, SimulationCoreActivator.PLUGIN_ID, ERROR_DURING_SIMULATION,
			statusMessage, t);
	SimulationCoreActivator.getDefault().getLog().log(errorStatus);
	IStatusHandler statusHandler = DebugPlugin.getDefault().getStatusHandler(errorStatus);
	try {
		statusHandler.handleStatus(errorStatus, getDebugTarget());
	} catch (CoreException e) {
		e.printStackTrace();
	} finally {
		terminate();
	}
}
 
Example #24
Source File: StreamContentDocumentProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void loadResource(Object element, Resource resource) {
	if (resource == null) {
		return;
	}
	if (element instanceof IStreamContentAccessor) {
		IStreamContentAccessor streamContentAccessor = (IStreamContentAccessor) element;
		InputStream inputStream = null;
		try {
			inputStream = streamContentAccessor.getContents();
			if (inputStream != null) {
				resource.load(inputStream,
						Collections.singletonMap(XtextResource.OPTION_ENCODING, getEncoding(element)));
			}
		} catch (Exception exception) {
			throw new WrappedException(exception);
		} finally {
			if (inputStream != null) {
				try {
					inputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
 
Example #25
Source File: Bpmn2PackageImpl.java    From fixflow with Apache License 2.0 6 votes vote down vote up
/**
 * Laods the package and any sub-packages from their serialized form.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void loadPackage() {
    if (isLoaded)
        return;
    isLoaded = true;

    URL url = getClass().getResource(packageFilename);
    if (url == null) {
        throw new RuntimeException("Missing serialized package: " + packageFilename);
    }
    URI uri = URI.createURI(url.toString());
    Resource resource = new EcoreResourceFactoryImpl().createResource(uri);
    try {
        resource.load(null);
    } catch (IOException exception) {
        throw new WrappedException(exception);
    }
    initializeFromLoadedEPackage(this, (EPackage) resource.getContents().get(0));
    createResource(eNS_URI);
}
 
Example #26
Source File: SplitterPropertiesEditionComponent.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
 * 
 */
public Diagnostic validateValue(IPropertiesEditionEvent event) {
	Diagnostic ret = Diagnostic.OK_INSTANCE;
	if (event.getNewValue() != null) {
		try {
			if (EipViewsRepository.Splitter.Properties.name == event.getAffectedEditor()) {
				Object newValue = event.getNewValue();
				if (newValue instanceof String) {
					newValue = EEFConverterUtil.createFromString(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), (String)newValue);
				}
				ret = Diagnostician.INSTANCE.validate(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), newValue);
			}
		} catch (IllegalArgumentException iae) {
			ret = BasicDiagnostic.toDiagnostic(iae);
		} catch (WrappedException we) {
			ret = BasicDiagnostic.toDiagnostic(we);
		}
	}
	return ret;
}
 
Example #27
Source File: XtextDocumentProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public String getEncoding(Object element) {
	String encoding = super.getEncoding(element);
	if (encoding == null && element instanceof IStorageEditorInput) {
		try {
			IStorage storage = ((IStorageEditorInput) element).getStorage();
			URI uri = storage2UriMapper.getUri(storage);
			if (uri != null) {
				encoding = encodingProvider.getEncoding(uri);
			} else if (storage instanceof IEncodedStorage) {
				encoding = ((IEncodedStorage)storage).getCharset();
			}
		} catch (CoreException e) {
			throw new WrappedException(e);
		}
	}
	if (encoding == null) {
		if (isWorkspaceExternalEditorInput(element))
			encoding = getWorkspaceExternalEncoding((IURIEditorInput)element);
		else
			encoding = getWorkspaceOrDefaultEncoding();
	}
	return encoding;
}
 
Example #28
Source File: LoadingResourceAccess.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public <R> R readOnly(URI targetURI, IUnitOfWork<R, ResourceSet> work) {
	URI resourceURI = targetURI.trimFragment();
	Iterable<Pair<IStorage, IProject>> storages = storage2UriMapper.getStorages(resourceURI);
	Iterator<Pair<IStorage, IProject>> iterator = storages.iterator();
	while(iterator.hasNext()) {
		Pair<IStorage, IProject> pair = iterator.next();
		IProject project = pair.getSecond();
		if (project != null) {
			ResourceSet resourceSet = resourceSetProvider.get(project);
			if(resourceSet != null)
				resourceSet.getResource(resourceURI, true);
				try {
					return work.exec(resourceSet);
				} catch (Exception e) {
					throw new WrappedException(e);
				}
		}
	}
	return null;
}
 
Example #29
Source File: ResourceAccess.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public <R> R readOnly(URI targetURI, IUnitOfWork<R, ResourceSet> work) {
	URI resourceURI = targetURI.trimFragment();
	Iterable<Pair<IStorage, IProject>> storages = storage2UriMapper.getStorages(resourceURI);
	Iterator<Pair<IStorage, IProject>> iterator = storages.iterator();
	ResourceSet resourceSet = fallBackResourceSet; 
	while(iterator.hasNext()) {
		Pair<IStorage, IProject> pair = iterator.next();
		IProject project = pair.getSecond();
		if (project != null) {
			resourceSet = getResourceSet(project);
			break;
		}
	}
	if(resourceSet != null) {
		resourceSet.getResource(resourceURI, true);
		try {
			return work.exec(resourceSet);
		} catch (Exception e) {
			throw new WrappedException(e);
		}
	}
	return null;
}
 
Example #30
Source File: LanguageSpecificURIEditorOpener.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public IEditorPart open(final URI uri, final EReference crossReference, final int indexInList, final boolean select) {
	Iterator<Pair<IStorage, IProject>> storages = mapper.getStorages(uri.trimFragment()).iterator();
	if (storages != null && storages.hasNext()) {
		try {
			IStorage storage = storages.next().getFirst();
			IEditorInput editorInput = EditorUtils.createEditorInput(storage);
			IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
			final IEditorPart editor = IDE.openEditor(activePage, editorInput, getEditorId());
			selectAndReveal(editor, uri, crossReference, indexInList, select);
			return EditorUtils.getXtextEditor(editor);
		} catch (WrappedException e) {
			logger.error("Error while opening editor part for EMF URI '" + uri + "'", e.getCause());
		} catch (PartInitException partInitException) {
			logger.error("Error while opening editor part for EMF URI '" + uri + "'", partInitException);
		}
	}
	return null;
}