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 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; }
/** * 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); }
public void writeLocation(ILocationData location, Callback<AbstractTraceRegion, ILocationData> callback) throws IOException { callback.doWriteLocation(location.getOffset(), location.getLength(), location.getLineNumber(), location.getEndLineNumber(), location.getPath()); }
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; 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; current = new TraceRegion(nextLocation.getOffset(), nextLocation.getLength(), nextLocation.getLineNumber(), nextLocation.getEndLineNumber(), createLocationData(nextRegion, myPath), null);
region = region.merge(new TextRegionWithLineInformation(data.getOffset(), data.getLength(), data.getLineNumber(), data.getEndLineNumber()));