org.eclipse.xtext.generator.trace.LineMappingProvider Java Examples

The following examples show how to use org.eclipse.xtext.generator.trace.LineMappingProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LineNumberMappingTests.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public LineMappingProvider.LineMapping findMapping(final List<LineMappingProvider.LineMapping> mappings, final Integer sourceLine) {
  for (final LineMappingProvider.LineMapping m : mappings) {
    if ((m.sourceStartLine == ((sourceLine).intValue() + 1))) {
      return m;
    }
  }
  return null;
}
 
Example #2
Source File: LineNumberMappingTests.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public void assertLineNumbers(final CharSequence xtendCodeWithLineNumbers) {
  final AbstractTraceRegion region = this.getTraceRegion(xtendCodeWithLineNumbers);
  final List<LineMappingProvider.LineMapping> normalizedMappings = this.lineMappingProvider.getLineMapping(region);
  final String[] lines = xtendCodeWithLineNumbers.toString().split("\n");
  int _size = ((List<String>)Conversions.doWrapArray(lines)).size();
  int _minus = (_size - 1);
  IntegerRange _upTo = new IntegerRange(0, _minus);
  for (final Integer lineNumber : _upTo) {
    {
      final LineMappingProvider.LineMapping mapping = this.findMapping(normalizedMappings, lineNumber);
      final String line = lines[(lineNumber).intValue()];
      if ((mapping != null)) {
        int _indexOf = line.indexOf("//");
        boolean _equals = (_indexOf == (-1));
        if (_equals) {
          StringConcatenation _builder = new StringConcatenation();
          _builder.append("Line ");
          _builder.append(lineNumber);
          _builder.append(" is mapped to ");
          _builder.append(mapping.targetStartLine);
          _builder.append("(\'");
          _builder.append(line);
          _builder.append("\')");
          Assert.fail(_builder.toString());
        }
        int _indexOf_1 = line.indexOf("//");
        int _plus = (_indexOf_1 + 2);
        final String expectation = line.substring(_plus).trim();
        int expTargetStart = (-1);
        int expTargetEnd = (-1);
        int _indexOf_2 = expectation.indexOf("..");
        boolean _notEquals = (_indexOf_2 != (-1));
        if (_notEquals) {
          final int idx = expectation.indexOf("..");
          expTargetStart = Integer.parseInt(expectation.substring(0, idx));
          expTargetEnd = Integer.parseInt(expectation.substring((idx + 2)));
        } else {
          expTargetStart = (expTargetEnd = Integer.parseInt(expectation));
        }
        Assert.assertEquals(line, expTargetStart, mapping.targetStartLine);
        Assert.assertEquals(("unexpected end in line : " + line), expTargetEnd, mapping.targetEndLine);
      } else {
        int _indexOf_3 = line.indexOf("//");
        boolean _notEquals_1 = (_indexOf_3 != (-1));
        if (_notEquals_1) {
          Assert.fail(("Unmatched expectation : " + line));
        }
      }
    }
  }
}