Search in sources :

Example 36 with IStorage

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);
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) TypeResource(org.eclipse.xtext.common.types.access.TypeResource) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) TextRegion(org.eclipse.xtext.util.TextRegion) ITrace(org.eclipse.xtext.generator.trace.ITrace) IStorage(org.eclipse.core.resources.IStorage) IMember(org.eclipse.jdt.core.IMember) IResource(org.eclipse.core.resources.IResource) ILocationInResource(org.eclipse.xtext.generator.trace.ILocationInResource) ISourceRange(org.eclipse.jdt.core.ISourceRange)

Example 37 with IStorage

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);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IMarker(org.eclipse.core.resources.IMarker) IStorage(org.eclipse.core.resources.IStorage) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource)

Example 38 with IStorage

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;
}
Also used : IStorage(org.eclipse.core.resources.IStorage) IProject(org.eclipse.core.resources.IProject) OutputConfiguration(org.eclipse.xtext.generator.OutputConfiguration) IContainer(org.eclipse.core.resources.IContainer) SourceMapping(org.eclipse.xtext.generator.OutputConfiguration.SourceMapping) IResource(org.eclipse.core.resources.IResource) Pair(org.eclipse.xtext.util.Pair)

Example 39 with IStorage

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());
}
Also used : WorkspaceProjectsState(org.eclipse.xtext.ui.containers.WorkspaceProjectsState) StateBasedContainerManager(org.eclipse.xtext.resource.containers.StateBasedContainerManager) ProjectDescriptionBasedContainerManager(org.eclipse.xtext.resource.containers.ProjectDescriptionBasedContainerManager) Storage2UriMapperImpl(org.eclipse.xtext.ui.resource.Storage2UriMapperImpl) WorkspaceProjectsStateHelper(org.eclipse.xtext.ui.containers.WorkspaceProjectsStateHelper) UriValidator(org.eclipse.xtext.ui.resource.UriValidator) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI)

Example 40 with IStorage

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;
}
Also used : WrappedException(org.eclipse.emf.common.util.WrappedException) IFile(org.eclipse.core.resources.IFile) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) IStorage(org.eclipse.core.resources.IStorage) Pair(org.eclipse.xtext.util.Pair)

Aggregations

IStorage (org.eclipse.core.resources.IStorage)96 URI (org.eclipse.emf.common.util.URI)32 IFile (org.eclipse.core.resources.IFile)31 IProject (org.eclipse.core.resources.IProject)27 CoreException (org.eclipse.core.runtime.CoreException)25 IResource (org.eclipse.core.resources.IResource)20 Pair (org.eclipse.xtext.util.Pair)16 Test (org.junit.Test)15 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)13 IStorageEditorInput (org.eclipse.ui.IStorageEditorInput)12 IPath (org.eclipse.core.runtime.IPath)11 IJavaProject (org.eclipse.jdt.core.IJavaProject)10 IOException (java.io.IOException)7 WrappedException (org.eclipse.emf.common.util.WrappedException)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 GitSynchronizeData (org.eclipse.egit.core.synchronize.dto.GitSynchronizeData)6 GitSynchronizeDataSet (org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)6 Storage2UriMapperJavaImpl (org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl)6