use of org.eclipse.xtext.generator.trace.SourceRelativeURI 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.generator.trace.SourceRelativeURI in project xtext-eclipse by eclipse.
the class XbaseBreakpointUtil method getBreakpointURI.
// this URI is only used for breakpoints on JARed files
public SourceRelativeURI getBreakpointURI(IEditorInput input) {
Object adapter = input.getAdapter(IResource.class);
if (adapter != null)
return null;
if (input instanceof IStorageEditorInput) {
IStorage storage;
try {
storage = ((IStorageEditorInput) input).getStorage();
if (storage instanceof IResource)
return null;
if (storage instanceof IJarEntryResource) {
IJarEntryResource jarEntryResource = (IJarEntryResource) storage;
if (!jarEntryResource.getPackageFragmentRoot().isArchive())
return null;
Object parent = jarEntryResource.getParent();
if (parent instanceof IPackageFragment) {
String path = ((IPackageFragment) parent).getElementName().replace('.', '/');
return new SourceRelativeURI(path + "/" + storage.getName());
} else if (parent instanceof IPackageFragmentRoot) {
return new SourceRelativeURI(storage.getName());
}
}
} catch (CoreException e) {
logger.error("Error finding breakpoint URI", e);
return null;
}
} else if (input.getAdapter(IClassFile.class) != null) {
IClassFile classFile = (IClassFile) input.getAdapter(IClassFile.class);
ITrace traceToSource = traceForTypeRootProvider.getTraceToSource(classFile);
if (traceToSource == null)
return null;
for (ILocationInResource loc : traceToSource.getAllAssociatedLocations()) return loc.getSrcRelativeResourceURI();
return null;
}
return null;
}
use of org.eclipse.xtext.generator.trace.SourceRelativeURI in project xtext-eclipse by eclipse.
the class TraceEditor method updateText.
protected void updateText(EObject obj) {
DebugTraceRegion region = EcoreUtil2.getContainerOfType(obj, DebugTraceRegion.class);
if (region == null) {
text.setText("No " + DebugTraceRegion.class.getSimpleName() + " found for " + obj.eClass().getName());
return;
}
final DebugTraceBasedRegion trace = new DebugTraceBasedRegion(null, region);
SourceRelativeURI sourceURI = trace.getAssociatedSrcRelativePath();
if (sourceURI == null) {
text.setText("Could not find associated URI");
return;
}
Registry registry = IResourceServiceProvider.Registry.INSTANCE;
IResourceServiceProvider serviceProvider = registry.getResourceServiceProvider(sourceURI.getURI());
URI traceURI = obj.eResource().getURI();
IStorage localStorage = getLocalStorage(serviceProvider, traceURI);
StorageAwareTrace traceProvider = serviceProvider.get(StorageAwareTrace.class);
traceProvider.setLocalStorage(localStorage);
traceProvider.setTraceToSource(true);
traceProvider.setTraceRegionProvider(new ITraceRegionProvider() {
@Override
public AbstractTraceRegion getTraceRegion() throws TraceNotFoundException {
return trace;
}
});
String newText = traceProvider.toString();
text.setText(newText);
}
use of org.eclipse.xtext.generator.trace.SourceRelativeURI in project xtext-eclipse by eclipse.
the class TraceForTypeRootProvider method getTraceToSource.
public IEclipseTrace getTraceToSource(final IClassFile classFile) {
IPath sourcePath = getSourcePath(classFile);
if (sourcePath == null)
return null;
IProject project = classFile.getJavaProject().getProject();
final String javaSimpleFileName = getJavaSimpleFileName(classFile);
SourceRelativeURI localURI = getPathInFragmentRoot(classFile, javaSimpleFileName);
class TraceRegionProvider implements ITraceRegionProvider {
private AbstractTraceWithoutStorage trace;
TraceRegionProvider(AbstractTraceWithoutStorage trace) {
this.trace = trace;
}
@Override
public AbstractTraceRegion getTraceRegion() {
if (javaSimpleFileName == null)
throw new TraceNotFoundException();
String traceSimpleFileName = traceFileNameProvider.getTraceFromJava(javaSimpleFileName);
SourceRelativeURI traceURI = getPathInFragmentRoot(classFile, traceSimpleFileName);
try {
InputStream contents = trace.getContents(traceURI, trace.getLocalProject());
if (contents != null)
try {
return traceRegionSerializer.readTraceRegionFrom(contents);
} finally {
contents.close();
}
} catch (IOException e) {
log.error("Error finding trace region", e);
}
throw new TraceNotFoundException();
}
}
if (isZipFile(sourcePath)) {
ZipFileAwareTrace zipFileAwareTrace = zipFileAwareTraceProvider.get();
zipFileAwareTrace.setProject(project);
zipFileAwareTrace.setZipFilePath(sourcePath);
zipFileAwareTrace.setLocalURI(localURI);
zipFileAwareTrace.setEncoding(getSourceEncoding(classFile));
zipFileAwareTrace.setTraceRegionProvider(new TraceRegionProvider(zipFileAwareTrace));
return zipFileAwareTrace;
} else {
FolderAwareTrace folderAwareTrace = folderAwareTraceProvider.get();
folderAwareTrace.setProject(project);
folderAwareTrace.setRootFolder(sourcePath.toString());
folderAwareTrace.setLocalURI(localURI);
folderAwareTrace.setEncoding(getSourceEncoding(classFile));
folderAwareTrace.setTraceRegionProvider(new TraceRegionProvider(folderAwareTrace));
return folderAwareTrace;
}
}
use of org.eclipse.xtext.generator.trace.SourceRelativeURI in project xtext-eclipse by eclipse.
the class DefaultUITraceURIConverterTest method assertConversion.
private void assertConversion(String expected, IFile source) {
AbsoluteURI sourceURI = new AbsoluteURI(URI.createPlatformResourceURI(source.getFullPath().toString(), true));
IProjectConfig projectConfig = projectConfigProvider.createProjectConfig(project.getProject());
SourceRelativeURI traceUri = converter.getURIForTrace(projectConfig, sourceURI);
assertEquals(expected, traceUri.toString());
}
Aggregations