use of org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource in project xtext-eclipse by eclipse.
the class DerivedResourceMarkerCopier method copyProblemMarker.
private void copyProblemMarker(IFile javaFile, IEclipseTrace traceToSource, Set<IMarker> problemsInJava, IFile srcFile) throws CoreException {
String sourceMarkerType = null;
for (IMarker marker : problemsInJava) {
String message = (String) marker.getAttribute(IMarker.MESSAGE);
if (message == null) {
continue;
}
Integer charStart = marker.getAttribute(IMarker.CHAR_START, 0);
Integer charEnd = marker.getAttribute(IMarker.CHAR_END, 0);
int severity = MarkerUtilities.getSeverity(marker);
ILocationInEclipseResource associatedLocation = traceToSource.getBestAssociatedLocation(new TextRegion(charStart, charEnd - charStart));
if (associatedLocation != null) {
if (sourceMarkerType == null) {
sourceMarkerType = determinateMarkerTypeByURI(associatedLocation.getSrcRelativeResourceURI());
}
if (!srcFile.equals(findIFile(associatedLocation, srcFile.getWorkspace()))) {
LOG.error("File in associated location is not the same as main source file.");
}
IMarker xtendMarker = srcFile.createMarker(sourceMarkerType);
xtendMarker.setAttribute(IMarker.MESSAGE, "Java problem: " + message);
xtendMarker.setAttribute(IMarker.SEVERITY, severity);
ITextRegionWithLineInformation region = associatedLocation.getTextRegion();
xtendMarker.setAttribute(IMarker.LINE_NUMBER, region.getLineNumber());
xtendMarker.setAttribute(IMarker.CHAR_START, region.getOffset());
xtendMarker.setAttribute(IMarker.CHAR_END, region.getOffset() + region.getLength());
xtendMarker.setAttribute(COPIED_FROM_FILE, javaFile.getFullPath().toString());
}
}
}
use of org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource in project xtext-eclipse by eclipse.
the class JavaBreakPointProvider method getJavaLineNumber.
private int getJavaLineNumber(final IJavaStratumLineBreakpoint breakpoint) throws CoreException {
ILocationInEclipseResource javaLocation = getJavaLocation(breakpoint);
if (javaLocation == null)
return -1;
IStorage storage = javaLocation.getPlatformResource();
if (storage == null) {
ITextRegionWithLineInformation textRegion = javaLocation.getTextRegion();
if (textRegion == null)
return -1;
return textRegion.getEndLineNumber();
} else {
AbstractEclipseTrace sourceTrace = (AbstractEclipseTrace) traceForStorageProvider.getTraceToSource(storage);
if (sourceTrace == null)
return -1;
AbstractTraceRegion rootTraceRegion = sourceTrace.getRootTraceRegion();
if (rootTraceRegion == null)
return -1;
List<LineMapping> lineMappings = lineMappingProvider.getLineMapping(rootTraceRegion);
if (lineMappings == null) {
return -1;
}
for (LineMapping lineMapping : lineMappings) {
if (lineMapping.sourceStartLine == breakpoint.getLineNumber()) {
return lineMapping.targetEndLine + 1;
}
}
return -1;
}
}
use of org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource in project xtext-eclipse by eclipse.
the class JavaBreakPointProvider method getHandleId.
private String getHandleId(final IJavaStratumLineBreakpoint breakpoint) throws CoreException {
IClassFile classFile = getClassFile(breakpoint);
if (classFile != null)
return classFile.getType().getHandleIdentifier();
ILocationInEclipseResource javaLocation = getJavaLocation(breakpoint);
if (javaLocation == null)
return null;
IStorage javaResource = javaLocation.getPlatformResource();
if (!(javaResource instanceof IFile))
return null;
ICompilationUnit compilationUnit = (ICompilationUnit) JavaCore.create((IFile) javaResource);
IJavaElement element = compilationUnit.getElementAt(javaLocation.getTextRegion().getOffset());
return element == null ? null : element.getHandleIdentifier();
}
Aggregations