Search in sources :

Example 1 with ILocationInEclipseResource

use of org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource in project xtext-eclipse by eclipse.

the class OriginalEditorSelector method getXtextEditor.

/**
 * @param traceToSource
 */
protected IEditorDescriptor getXtextEditor(IEclipseTrace traceToSource) {
    if (traceToSource != null) {
        Iterator<? extends ILocationInEclipseResource> sourceInformationIterator = traceToSource.getAllAssociatedLocations().iterator();
        if (sourceInformationIterator.hasNext()) {
            ILocationInEclipseResource sourceInformation = sourceInformationIterator.next();
            AbsoluteURI absoluteURI = sourceInformation.getAbsoluteResourceURI();
            if (absoluteURI != null) {
                URI uri = absoluteURI.getURI();
                return getXtextEditor(uri);
            }
        }
    }
    return null;
}
Also used : ILocationInEclipseResource(org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource) AbsoluteURI(org.eclipse.xtext.generator.trace.AbsoluteURI) URI(org.eclipse.emf.common.util.URI) AbsoluteURI(org.eclipse.xtext.generator.trace.AbsoluteURI)

Example 2 with ILocationInEclipseResource

use of org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource in project xtext-eclipse by eclipse.

the class JavaBreakPointProvider method getJavaLocation.

private ILocationInEclipseResource getJavaLocation(final IJavaStratumLineBreakpoint breakpoint) throws CoreException {
    IEclipseTrace javaTrace = getJavaTrace(breakpoint);
    if (javaTrace == null)
        return null;
    TextRegion textRegion = new TextRegion(breakpoint.getCharStart(), 0);
    ILocationInEclipseResource javaLocation = javaTrace.getBestAssociatedLocation(textRegion);
    if (javaLocation == null)
        return null;
    return javaLocation;
}
Also used : ILocationInEclipseResource(org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource) TextRegion(org.eclipse.xtext.util.TextRegion) IEclipseTrace(org.eclipse.xtext.ui.generator.trace.IEclipseTrace)

Example 3 with ILocationInEclipseResource

use of org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource in project xtext-eclipse by eclipse.

the class XbaseDocumentProvider method setDocumentContent.

@Override
protected boolean setDocumentContent(IDocument document, IEditorInput input, String encoding) throws CoreException {
    if (input instanceof IClassFileEditorInput) {
        IClassFile classFile = ((IClassFileEditorInput) input).getClassFile();
        ILocationInEclipseResource source = getClassFileSourceStorage(classFile);
        if (source == null) {
            return false;
        }
        InputStream contents = null;
        try {
            contents = source.getContents();
            if (contents != null)
                setDocumentContent(document, contents, encoding);
        } catch (WrappedCoreException e) {
            throw e.getCause();
        } catch (IOException e) {
            throw new CoreException(new Status(IStatus.ERROR, plugin.getBundle().getSymbolicName(), e.getMessage(), e));
        } finally {
            try {
                if (contents != null)
                    contents.close();
            } catch (IOException e1) {
            }
        }
        setDocumentResource((XtextDocument) document, input, encoding);
        return true;
    }
    return super.setDocumentContent(document, input, encoding);
}
Also used : ILocationInEclipseResource(org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IClassFile(org.eclipse.jdt.core.IClassFile) CoreException(org.eclipse.core.runtime.CoreException) WrappedCoreException(org.eclipse.xtext.ui.generator.trace.WrappedCoreException) InputStream(java.io.InputStream) WrappedCoreException(org.eclipse.xtext.ui.generator.trace.WrappedCoreException) IOException(java.io.IOException) IClassFileEditorInput(org.eclipse.jdt.internal.ui.javaeditor.IClassFileEditorInput)

Example 4 with ILocationInEclipseResource

use of org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource in project xtext-eclipse by eclipse.

the class XbaseEditorInputRedirector method findOriginalSource.

public IEditorInput findOriginalSource(final IEditorInput input) {
    final IFile resource = ResourceUtil.getFile(input);
    if ((resource != null)) {
        final IEditorInput original = this.findOriginalSourceForOuputFolderCopy(input);
        if ((original != input)) {
            return original;
        }
        final IEclipseTrace trace = this.traceInformation.getTraceToSource(resource);
        if ((trace == null)) {
            return input;
        }
        final Iterator<? extends ILocationInEclipseResource> allLocations = trace.getAllAssociatedLocations().iterator();
        ILocationInEclipseResource sourceInformation = null;
        while ((allLocations.hasNext() && (sourceInformation == null))) {
            {
                final ILocationInEclipseResource candidate = allLocations.next();
                boolean _equals = this.languageInfo.equals(candidate.getLanguage());
                if (_equals) {
                    sourceInformation = candidate;
                }
            }
        }
        if ((sourceInformation == null)) {
            return input;
        }
        final IStorage originalStorage = sourceInformation.getPlatformResource();
        if ((originalStorage != null)) {
            return EditorUtils.createEditorInput(originalStorage);
        }
    }
    return input;
}
Also used : ILocationInEclipseResource(org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource) IFile(org.eclipse.core.resources.IFile) IEclipseTrace(org.eclipse.xtext.ui.generator.trace.IEclipseTrace) IStorage(org.eclipse.core.resources.IStorage) IEditorInput(org.eclipse.ui.IEditorInput)

Example 5 with ILocationInEclipseResource

use of org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource in project xtext-xtend by eclipse.

the class DerivedSourceView method computeInput.

@Override
protected String computeInput(IWorkbenchPartSelection workbenchPartSelection) {
    openEditorAction.setInputFile(null);
    openEditorAction.setSelectedRegion(null);
    IEclipseTrace trace = traceInformation.getTraceToTarget(getEditorResource(workbenchPartSelection));
    if (trace != null) {
        if (workbenchPartSelection instanceof DerivedSourceSelection) {
            DerivedSourceSelection derivedSourceSelection = (DerivedSourceSelection) workbenchPartSelection;
            selectedSource = derivedSourceSelection.getStorage();
        } else {
            derivedSources = Sets.newHashSet();
            TextRegion localRegion = mapTextRegion(workbenchPartSelection);
            Iterable<IStorage> transform = Iterables.filter(transform(trace.getAllAssociatedLocations(localRegion), new Function<ILocationInEclipseResource, IStorage>() {

                @Override
                public IStorage apply(ILocationInEclipseResource input) {
                    return input.getPlatformResource();
                }
            }), Predicates.notNull());
            addAll(derivedSources, transform);
            ILocationInEclipseResource bestAssociatedLocation = trace.getBestAssociatedLocation(localRegion);
            if (bestAssociatedLocation != null) {
                selectedSource = bestAssociatedLocation.getPlatformResource();
            } else if (!derivedSources.isEmpty()) {
                selectedSource = derivedSources.iterator().next();
            }
        }
    }
    IFile file = getSelectedFile();
    if (file != null) {
        try {
            file.refreshLocal(1, new NullProgressMonitor());
            if (file.exists()) {
                openEditorAction.setInputFile(file);
                try (InputStream contents = file.getContents()) {
                    return Files.readStreamIntoString(contents);
                }
            }
        } catch (CoreException | IOException e) {
            throw new WrappedRuntimeException(e);
        }
    }
    return null;
}
Also used : ILocationInEclipseResource(org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) InputStream(java.io.InputStream) IOException(java.io.IOException) IStorage(org.eclipse.core.resources.IStorage) Function(com.google.common.base.Function) CoreException(org.eclipse.core.runtime.CoreException) IEclipseTrace(org.eclipse.xtext.ui.generator.trace.IEclipseTrace) WrappedRuntimeException(org.eclipse.core.internal.utils.WrappedRuntimeException)

Aggregations

ILocationInEclipseResource (org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource)8 IStorage (org.eclipse.core.resources.IStorage)4 IFile (org.eclipse.core.resources.IFile)3 IEclipseTrace (org.eclipse.xtext.ui.generator.trace.IEclipseTrace)3 TextRegion (org.eclipse.xtext.util.TextRegion)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 CoreException (org.eclipse.core.runtime.CoreException)2 IClassFile (org.eclipse.jdt.core.IClassFile)2 ITextRegionWithLineInformation (org.eclipse.xtext.util.ITextRegionWithLineInformation)2 Function (com.google.common.base.Function)1 WrappedRuntimeException (org.eclipse.core.internal.utils.WrappedRuntimeException)1 IMarker (org.eclipse.core.resources.IMarker)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Status (org.eclipse.core.runtime.Status)1 URI (org.eclipse.emf.common.util.URI)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 IClassFileEditorInput (org.eclipse.jdt.internal.ui.javaeditor.IClassFileEditorInput)1