Search in sources :

Example 6 with IEclipseTrace

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

the class XbaseEditorInputRedirector method findOriginalSource.

public IEditorInput findOriginalSource(IEditorInput input) {
    IFile resource = ResourceUtil.getFile(input);
    if (resource == null) {
        return input;
    }
    IEditorInput original = findOriginalSourceForOuputFolderCopy(input);
    if (original != input) {
        return original;
    }
    IEclipseTrace trace = traceInformation.getTraceToSource(resource);
    if (trace == null) {
        return input;
    }
    for (ILocationInEclipseResource candidate : trace.getAllAssociatedLocations()) {
        if (languageInfo.equals(candidate.getLanguage())) {
            IStorage storage = candidate.getPlatformResource();
            if (storage != null) {
                return EditorUtils.createEditorInput(storage);
            }
        }
    }
    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 7 with IEclipseTrace

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

the class JavaBreakPointProvider method getJavaTrace.

private IEclipseTrace getJavaTrace(final IJavaStratumLineBreakpoint breakpoint) throws CoreException {
    IEclipseTrace result;
    IClassFile classFile = getClassFile(breakpoint);
    if (classFile == null) {
        URI uri = URI.createURI((String) breakpoint.getMarker().getAttribute(StratumBreakpointAdapterFactory.ORG_ECLIPSE_XTEXT_XBASE_SOURCE_URI));
        Pair<IStorage, IProject> storage = Iterables.getFirst(storage2UriMapper.getStorages(uri), null);
        if (storage == null)
            return null;
        result = traceForStorageProvider.getTraceToTarget(storage.getFirst());
    } else {
        result = traceForTypeRootProvider.getTraceToSource(classFile);
    }
    return result;
}
Also used : IClassFile(org.eclipse.jdt.core.IClassFile) IEclipseTrace(org.eclipse.xtext.ui.generator.trace.IEclipseTrace) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) IProject(org.eclipse.core.resources.IProject)

Example 8 with IEclipseTrace

use of org.eclipse.xtext.ui.generator.trace.IEclipseTrace 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 9 with IEclipseTrace

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

the class JavaEditorInputMatcher method matches.

@Override
public boolean matches(IEditorReference editorRef, IEditorInput inputToCheck) {
    try {
        if (!editorInfo.getEditorId().equals(editorRef.getId())) {
            return false;
        }
        IEditorInput newInput = editorInputRedirector.findOriginalSourceForOuputFolderCopy(inputToCheck);
        IEditorInput currentInput = editorRef.getEditorInput();
        if (newInput.equals(currentInput)) {
            if (decisions.decideAccordingToCaller() != Decision.FORCE_JAVA) {
                ITypeRoot newTypeRoot = editorInputRedirector.getTypeRoot(newInput);
                if (newTypeRoot != null) {
                    IEditorPart existingEditor = editorRef.getEditor(true);
                    if (existingEditor instanceof XbaseEditor) {
                        ((XbaseEditor) existingEditor).markNextSelectionAsJavaOffset(newTypeRoot);
                    }
                }
            }
            return true;
        }
        if (decisions.decideAccordingToCaller() == Decision.FORCE_JAVA)
            return false;
        ITypeRoot newTypeRoot = editorInputRedirector.getTypeRoot(newInput);
        if (newTypeRoot == null) {
            return false;
        }
        IResource currentResource = ResourceUtil.getResource(currentInput);
        if (currentResource == null) {
            return false;
        }
        IEclipseTrace traceToSource = traceInformation.getTraceToSource(newTypeRoot);
        if (traceToSource == null) {
            return false;
        }
        if (isCurrentResource(currentResource, traceToSource)) {
            IEditorPart existingEditor = editorRef.getEditor(true);
            if (existingEditor instanceof XbaseEditor) {
                ((XbaseEditor) existingEditor).markNextSelectionAsJavaOffset(newTypeRoot);
                return true;
            }
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    return false;
}
Also used : ITypeRoot(org.eclipse.jdt.core.ITypeRoot) IEditorPart(org.eclipse.ui.IEditorPart) IEclipseTrace(org.eclipse.xtext.ui.generator.trace.IEclipseTrace) IEditorInput(org.eclipse.ui.IEditorInput) IResource(org.eclipse.core.resources.IResource)

Aggregations

IEclipseTrace (org.eclipse.xtext.ui.generator.trace.IEclipseTrace)9 IFile (org.eclipse.core.resources.IFile)5 TextRegion (org.eclipse.xtext.util.TextRegion)4 IStorage (org.eclipse.core.resources.IStorage)3 CoreException (org.eclipse.core.runtime.CoreException)3 ILocationInEclipseResource (org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource)3 InputStream (java.io.InputStream)2 IEditorInput (org.eclipse.ui.IEditorInput)2 ITextRegion (org.eclipse.xtext.util.ITextRegion)2 Function (com.google.common.base.Function)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 WrappedRuntimeException (org.eclipse.core.internal.utils.WrappedRuntimeException)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 URI (org.eclipse.emf.common.util.URI)1 IClassFile (org.eclipse.jdt.core.IClassFile)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 ITypeRoot (org.eclipse.jdt.core.ITypeRoot)1