public void writeLocation(ILocationData location, Callback<AbstractTraceRegion, ILocationData> callback) throws IOException { callback.doWriteLocation(location.getOffset(), location.getLength(), location.getLineNumber(), location.getEndLineNumber(), location.getPath()); }
public int compare(@Nullable Pair<ILocationData, AbstractTraceRegion> o1, @Nullable Pair<ILocationData, AbstractTraceRegion> o2) { if (o1 == null || o2 == null) throw new IllegalArgumentException("o1 == null || o2 == null"); ILocationData loc1 = o1.getFirst(); ILocationData loc2 = o2.getFirst(); int result = Ints.compare(loc1.getOffset(), loc2.getOffset()); if (result == 0) { result = Ints.compare(loc2.getLength(), loc1.getLength()); } return result; } });
private String toReportableString(final ILocationData locationData) { int _lineNumber = locationData.getLineNumber(); int _endLineNumber = locationData.getEndLineNumber(); boolean _equals = (_lineNumber == _endLineNumber); if (_equals) { int _lineNumber_1 = locationData.getLineNumber(); int _plus = (_lineNumber_1 + 1); return Integer.toString(_plus); } else { StringConcatenation _builder = new StringConcatenation(); int _lineNumber_2 = locationData.getLineNumber(); int _plus_1 = (_lineNumber_2 + 1); _builder.append(_plus_1); _builder.append("-"); int _endLineNumber_1 = locationData.getEndLineNumber(); int _plus_2 = (_endLineNumber_1 + 1); _builder.append(_plus_2); return _builder.toString(); } } }
public TraceRegion(int myOffset, int myLength, int myLineNumber, int myEndLineNumber, ILocationData locationData, @Nullable AbstractTraceRegion parent) { super(new TextRegionWithLineInformation(myOffset, myLength, myLineNumber, myEndLineNumber), locationData, parent); if (myOffset == myLength && myOffset == 0) { throw new IllegalArgumentException(); } if (parent == null) { if (locationData.getPath() == null) { throw new IllegalArgumentException("associatedPath may not be null"); } } else { if (parent.getAssociatedPath() == null && locationData.getPath() == null) { throw new IllegalArgumentException("associatedPath may not be null"); } } }
protected Set<Integer> createSmapInfo(AbstractTraceRegion targetRegion, Set<LineMapping> lineMappings) { Set<Integer> mapped = newHashSet(); for (AbstractTraceRegion nested : targetRegion.getNestedRegions()) { mapped.addAll(createSmapInfo(nested, lineMappings)); } if (targetRegion.isUseForDebugging()) { ILocationData location = targetRegion.getMergedAssociatedLocation(); if (location != null) { final URI path = targetRegion.getAssociatedPath(); if (path != null) { int myLineNumber = targetRegion.getMyLineNumber(); int myEndLineNumber = targetRegion.getMyEndLineNumber(); for (int i = myLineNumber; i <= myEndLineNumber; i++) { if (!mapped.contains(i)) { final LineMapping e = new LineMapping(location.getLineNumber() + 1, i, i, path); lineMappings.add(e); mapped.add(i); } } } } } return mapped; }
private boolean allLocationsMatch(TreeAppendable appendable, SourceRelativeURI path) { for(ILocationData locationData: appendable.getLocationData()) { if (!path.equals(locationData.getSrcRelativePath())) { return false; } } return true; }
private int doAnnotateTrace(String input, StringBuilder result, int nextOffset) { if (nextOffset < getMyOffset()) { result.append(input.substring(nextOffset, getMyOffset())); nextOffset = getMyOffset(); } result.append('<'); List<ILocationData> associatedLocations = getAssociatedLocations(); for(int i = 0; i < associatedLocations.size(); i++) { if (i != 0) result.append("/"); ILocationData associatedLocation = associatedLocations.get(i); result.append(associatedLocation.getOffset()).append(':').append(associatedLocation.getLength()); } result.append("["); for(AbstractTraceRegion nested: getNestedRegions()) { nextOffset = nested.doAnnotateTrace(input, result, nextOffset); } if (nextOffset < getMyOffset() + getMyLength()) { result.append(input.substring(nextOffset, getMyOffset() + getMyLength())); nextOffset = getMyOffset() + getMyLength(); } result.append(']'); return nextOffset; }
public TraceRegion(int myOffset, int myLength, int myLineNumber, int myEndLineNumber, List<ILocationData> allLocationData, @Nullable AbstractTraceRegion parent) { super(new TextRegionWithLineInformation(myOffset, myLength, myLineNumber, myEndLineNumber), Lists.newArrayList(allLocationData), parent); if (parent == null) { for(ILocationData locationData: allLocationData) { if (locationData.getPath() == null) { throw new IllegalArgumentException("associatedPath may not be null"); } } } else { boolean nullSeen = false; boolean notNullSeen = false; for(ILocationData locationData: allLocationData) { if (locationData.getPath() == null) { nullSeen = true; } else { notNullSeen = true; } if (nullSeen && notNullSeen) { throw new IllegalArgumentException("list of locations is inconsistent"); } } if (parent.getAssociatedPath() == null) { if (nullSeen) { throw new IllegalArgumentException("list of locations is inconsistent with parent"); } } } }
/** * Creates a new location for a target resource that matches the given {@code location}. * @param location the location * @return the location in resource, <code>null</code> detecting a path fails. */ @Nullable protected ILocationInResource createLocationInResourceFor(ILocationData location, AbstractTraceRegion traceRegion) { URI path = location.getPath(); if (path == null) path = traceRegion.getAssociatedPath(); if (path == null) return null; return new LocationInResource(location.getOffset(), location.getLength(), location.getLineNumber(), location.getEndLineNumber(), path, this); }
@Nullable public URI getAssociatedPath() { ILocationData data = getMergedAssociatedLocation(); if (data != null) { URI result = data.getPath(); if (result != null) { return result; } } if (parent == null) return null; boolean uriSeen = false; for (ILocationData associated : getAssociatedLocations()) if (associated.getPath() != null) { if (!uriSeen) uriSeen = true; else return null; } return parent.getAssociatedPath(); }
for(ILocationData data: allData) { if (path != null) { if (!path.equals(data.getPath())) { return null; if (data.getPath() == null) { if (!allNull) throw new IllegalStateException("Iff multiple associated locations are present, the path has to be set"); } else { allNull = false; path = data.getPath(); region = region.merge(new TextRegionWithLineInformation(data.getOffset(), data.getLength(), data.getLineNumber(), data.getEndLineNumber()));
protected Map<URI, List<Pair<ILocationData, AbstractTraceRegion>>> collectMatchingLocations(@Nullable URI expectedAssociatedPath) { Map<URI, List<Pair<ILocationData, AbstractTraceRegion>>> result = Maps.newHashMapWithExpectedSize(2); Iterator<AbstractTraceRegion> treeIterator = treeIterator(); while(treeIterator.hasNext()) { AbstractTraceRegion next = treeIterator.next(); URI associatedPath = next.getAssociatedPath(); List<Pair<ILocationData, AbstractTraceRegion>> matchingLocations = getCollectingList(associatedPath, expectedAssociatedPath, result); for(ILocationData locationData: next.getAssociatedLocations()) { if (associatedPath == null) { matchingLocations = getCollectingList(locationData.getPath(), expectedAssociatedPath, result); } if (matchingLocations != null) { matchingLocations.add(Tuples.create(locationData, next)); } } } return result; }
if (current.getMyOffset() == nextLocation.getOffset() && current.getMyLength() == nextLocation.getLength()) { List<ILocationData> writableLocations = current.getWritableAssociatedLocations(); ILocationData newData = createLocationData(nextRegion, myPath); while(current != null && currentEndOffset <= nextLocation.getOffset()) { current = (TraceRegion) current.getParent(); if (current != null) int nextOffset = nextLocation.getOffset(); if (nextOffset + nextLocation.getLength() <= currentEndOffset) { current = new TraceRegion(nextOffset, nextLocation.getLength(), nextLocation.getLineNumber(), nextLocation.getEndLineNumber(), createLocationData(nextRegion, myPath), current); currentEndOffset = nextLocation.getOffset() + nextLocation.getLength(); } else { int nextLength = currentEndOffset - nextOffset; int nextEndLine = current.getMyEndLineNumber(); int splittedLength = nextLocation.getLength() - nextLength; int splittedBeginLine = nextEndLine; ILocationData splitted = new LocationData(currentEndOffset, splittedLength, splittedBeginLine, nextLocation.getEndLineNumber(), nextLocation.getPath()); for(int j = i + 1; j < locations.size() && splitted != null; j++) { ILocationData shiftMe = locations.get(j).getFirst(); if (splitted.getOffset() == shiftMe.getOffset()) { if (splitted.getLength() > shiftMe.getLength()) { locations.add(j, Tuples.create(splitted, nextRegion)); splitted = null; } else if (splitted.getOffset() < shiftMe.getOffset()) { locations.add(j, Tuples.create(splitted, nextRegion)); splitted = null;
AbstractTraceRegion region = iterator.next(); for(ILocationData location: region.getAssociatedLocations()) { URI path = location.getPath(); if (path != null) { sourceTraces.put(path, tracePath);