use of org.eclipse.xtext.generator.trace.LineMappingProvider.LineMapping in project xtext-core by eclipse.
the class LineMappingNormalizationTest method testNomalization.
@Test
public void testNomalization() {
Set<LineMapping> mappings = newHashSet(new LineMapping(1, 1, 1, source), new LineMapping(2, 5, 5, source), new LineMapping(1, 6, 6, source), new LineMapping(3, 7, 8, source), new LineMapping(3, 8, 8, source));
List<LineMapping> info = support.normalizeLineInfo(mappings);
assertEquals(info.toString(), 4, info.size());
assertEquals(1, info.get(0).sourceStartLine);
assertEquals(1, info.get(0).targetStartLine);
assertEquals(1, info.get(0).targetEndLine);
assertEquals(2, info.get(1).sourceStartLine);
assertEquals(5, info.get(1).targetStartLine);
assertEquals(5, info.get(1).targetEndLine);
assertEquals(1, info.get(2).sourceStartLine);
assertEquals(6, info.get(2).targetStartLine);
assertEquals(6, info.get(2).targetEndLine);
assertEquals(3, info.get(3).sourceStartLine);
assertEquals(7, info.get(3).targetStartLine);
assertEquals(8, info.get(3).targetEndLine);
}
use of org.eclipse.xtext.generator.trace.LineMappingProvider.LineMapping in project xtext-core by eclipse.
the class TraceAsPrimarySourceInstaller method getTargetToSourceLineMapping.
protected int[] getTargetToSourceLineMapping(AbstractTraceRegion rootTraceRegion) {
List<LineMapping> lineInfo = lineMappingProvider.getLineMapping(rootTraceRegion);
if (lineInfo == null)
return null;
int maxLineEnd = 0;
for (LineMapping lineMapping : lineInfo) if (maxLineEnd < lineMapping.targetEndLine)
maxLineEnd = lineMapping.targetEndLine;
int[] target2source = new int[maxLineEnd + 2];
Arrays.fill(target2source, -1);
for (LineMapping lineMapping : lineInfo) for (int targetLine = lineMapping.targetStartLine + 1; targetLine <= lineMapping.targetEndLine + 1; targetLine++) {
int startLine = lineMapping.sourceStartLine;
if (target2source[targetLine] == -1 || startLine < target2source[targetLine])
target2source[targetLine] = startLine;
}
return target2source;
}
use of org.eclipse.xtext.generator.trace.LineMappingProvider.LineMapping 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;
}
}
Aggregations