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();
}
}
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);
}
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;
}
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;
}
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;
}
Aggregations