Search in sources :

Example 1 with IEclipseTrace

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

the class DebugSourceInstallingCompilationParticipant method buildFinished.

@Override
public void buildFinished(IJavaProject project) {
    StoppedTask task = Stopwatches.forTask("DebugSourceInstallingCompilationParticipant.install");
    try {
        task.start();
        super.buildFinished(project);
        if (files == null)
            return;
        for (BuildContext ctx : files) {
            try {
                IFile generatedJavaFile = ctx.getFile();
                // This may fail if there is no trace file.
                IEclipseTrace traceToSource = traceInformation.getTraceToSource(generatedJavaFile);
                if (traceToSource == null) {
                    continue;
                }
                AbstractTraceRegion rootTraceRegion = findRootTraceRegion(traceToSource);
                if (rootTraceRegion == null)
                    continue;
                SourceRelativeURI dslSourceFile = rootTraceRegion.getAssociatedSrcRelativePath();
                // OutputConfigurations are only available for folders targeted by Xtext's code generation.
                OutputConfiguration outputConfiguration = findOutputConfiguration(dslSourceFile, generatedJavaFile);
                if (outputConfiguration == null)
                    continue;
                IJavaElement element = JavaCore.create(generatedJavaFile);
                if (element == null)
                    continue;
                deleteTaskMarkers(generatedJavaFile);
                markerReflector.reflectErrorMarkerInSource(generatedJavaFile, traceToSource);
                ITraceToBytecodeInstaller installer = getInstaller(outputConfiguration);
                installer.setTrace(generatedJavaFile.getName(), rootTraceRegion);
                for (IFile javaClassFile : findGeneratedJavaClassFiles(element)) {
                    InputStream contents = javaClassFile.getContents();
                    try {
                        byte[] byteCode = installer.installTrace(ByteStreams.toByteArray(contents));
                        if (byteCode != null) {
                            javaClassFile.setContents(new ByteArrayInputStream(byteCode), 0, null);
                        } else {
                            // we need to touch the class file to do a respin of the build
                            // otherwise a needsRebuild request is ignored since no IResourceDelta is available
                            javaClassFile.touch(null);
                        }
                    } finally {
                        contents.close();
                    }
                }
            } catch (Exception e) {
                String msg = "Could not process %s to install source information: %s";
                log.error(String.format(msg, ctx.getFile().getFullPath().toString(), e.getMessage()), e);
            }
        }
    } finally {
        files = null;
        task.stop();
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StoppedTask(org.eclipse.xtext.util.internal.Stopwatches.StoppedTask) CoreException(org.eclipse.core.runtime.CoreException) ITraceToBytecodeInstaller(org.eclipse.xtext.generator.trace.ITraceToBytecodeInstaller) BuildContext(org.eclipse.jdt.core.compiler.BuildContext) ByteArrayInputStream(java.io.ByteArrayInputStream) OutputConfiguration(org.eclipse.xtext.generator.OutputConfiguration) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) IEclipseTrace(org.eclipse.xtext.ui.generator.trace.IEclipseTrace) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI)

Example 2 with IEclipseTrace

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

the class OriginalEditorSelector method findXbaseEditor.

public IEditorDescriptor findXbaseEditor(IEditorInput editorInput, boolean ignorePreference) {
    IFile file = ResourceUtil.getFile(editorInput);
    if (file == null)
        return null;
    if (!ignorePreference) {
        if (file.exists()) {
            try {
                String favoriteEditor = file.getPersistentProperty(IDE.EDITOR_KEY);
                if (favoriteEditor != null)
                    return null;
            } catch (CoreException e) {
                logger.debug(e.getMessage(), e);
            }
        }
    }
    // TODO stay in same editor if local navigation
    Decision decision = decisions.decideAccordingToCaller();
    if (decision == Decision.FORCE_JAVA) {
        return null;
    }
    IEclipseTrace traceToSource = traceInformation.getTraceToSource(file);
    return getXtextEditor(traceToSource);
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IEclipseTrace(org.eclipse.xtext.ui.generator.trace.IEclipseTrace) Decision(org.eclipse.xtext.xbase.ui.editor.StacktraceBasedEditorDecider.Decision)

Example 3 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 4 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 5 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(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)

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