use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.
the class JvmOutlineNodeElementOpener method openEObject.
@Override
protected void openEObject(EObject state) {
try {
if (state instanceof JvmIdentifiableElement && state.eResource() instanceof TypeResource) {
IJavaElement javaElement = javaElementFinder.findElementFor((JvmIdentifiableElement) state);
if (javaElement instanceof IMember) {
IResource resource = javaElement.getResource();
if (resource instanceof IStorage) {
ITrace traceToSource = traceInformation.getTraceToSource((IStorage) resource);
if (traceToSource != null) {
ISourceRange sourceRange = ((IMember) javaElement).getSourceRange();
ILocationInResource sourceInformation = traceToSource.getBestAssociatedLocation(new TextRegion(sourceRange.getOffset(), sourceRange.getLength()));
if (sourceInformation != null) {
globalURIEditorOpener.open(sourceInformation.getAbsoluteResourceURI().getURI(), javaElement, true);
return;
}
}
}
globalURIEditorOpener.open(null, javaElement, true);
return;
}
}
} catch (Exception exc) {
LOG.error("Error opening java editor", exc);
}
super.openEObject(state);
}
use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.
the class BuilderParticipant method addMarkerAndLogError.
/**
* @since 2.7
*/
protected void addMarkerAndLogError(URI uri, Throwable e) {
for (Pair<IStorage, IProject> storage : getStorage2UriMapper().getStorages(uri)) {
IResource resource = null;
if (storage.getFirst() instanceof IResource) {
resource = (IResource) storage.getFirst();
} else {
resource = storage.getSecond();
}
if (resource != null) {
try {
IMarker marker = resource.createMarker(MarkerTypes.NORMAL_VALIDATION);
marker.setAttribute(IMarker.MESSAGE, e.getMessage() + " - See error log for details");
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
marker.setAttribute(IMarker.LINE_NUMBER, 1);
} catch (CoreException ce) {
logger.error("Could not create marker", ce);
}
}
}
Throwable cause = e;
if (cause instanceof CoreException) {
cause = cause.getCause();
}
if (uri == null) {
logger.error("Error during compilation.", e);
} else {
logger.error("Error during compilation of '" + uri + "'.", e);
}
}
use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.
the class BuilderParticipant method getCurrentSourceFolder.
/**
* @since 2.7
*/
protected String getCurrentSourceFolder(IBuildContext context, Delta delta) {
Iterable<org.eclipse.xtext.util.Pair<IStorage, IProject>> storages = storage2UriMapper.getStorages(delta.getUri());
for (org.eclipse.xtext.util.Pair<IStorage, IProject> pair : storages) {
if (pair.getFirst() instanceof IResource) {
final IResource resource = (IResource) pair.getFirst();
IProject project = pair.getSecond();
for (OutputConfiguration output : getOutputConfigurations(context).values()) {
for (SourceMapping sourceMapping : output.getSourceMappings()) {
IContainer folder = ResourceUtil.getContainer(project, sourceMapping.getSourceFolder());
if (folder.contains(resource)) {
return sourceMapping.getSourceFolder();
}
}
}
}
}
return null;
}
use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.
the class StateBasedContainerManagerTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
IResourcesSetupUtil.setReference(project1, project2);
uri1 = createFileAndRegisterResource(project1, "file1");
uri2 = createFileAndRegisterResource(project1, "file2");
uri3 = createFileAndRegisterResource(project2, "file3");
Storage2UriMapperImpl mapper = new Storage2UriMapperImpl() {
@Override
public boolean isValidUri(URI uri, IStorage storage) {
return uri != null && !uri.toString().endsWith("/.project");
}
};
mapper.setUriValidator(new UriValidator() {
@Override
public boolean isPossiblyManaged(IStorage storage) {
return true;
}
@Override
public boolean isValid(URI uri, IStorage storage) {
return true;
}
});
projectsState = new WorkspaceProjectsState();
projectsState.setMapper(mapper);
WorkspaceProjectsStateHelper helper = new WorkspaceProjectsStateHelper();
helper.setMapper(mapper);
helper.setWorkspace(ResourcesPlugin.getWorkspace());
projectsState.setHelper(helper);
containerManager = new StateBasedContainerManager();
containerManager.setStateProvider(this);
containerManager.setDelegate(new ProjectDescriptionBasedContainerManager());
}
use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.
the class GlobalURIEditorOpener method openDefaultEditor.
protected IEditorPart openDefaultEditor(URI uri, EReference crossReference, int indexInList, boolean select) {
Iterator<Pair<IStorage, IProject>> storages = mapper.getStorages(uri.trimFragment()).iterator();
if (storages != null && storages.hasNext()) {
try {
IStorage storage = storages.next().getFirst();
IEditorPart editor = null;
if (storage instanceof IFile) {
editor = openDefaultEditor((IFile) storage);
} else {
editor = openDefaultEditor(storage, uri);
}
selectAndReveal(editor, uri, crossReference, indexInList, select);
return 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;
}
Aggregations