protected Iterable<ILocationInResource> toLocations(Iterable<AbstractTraceRegion> allTraceRegions) { List<ILocationInResource> result = Lists.newArrayList(); for (AbstractTraceRegion region : allTraceRegions) { for (ILocationData locationData : region.getAssociatedLocations()) { ILocationInResource locationInResource = createLocationInResourceFor(locationData, region); if (locationInResource != null) result.add(locationInResource); } } return result; }
@Override public String toString() { List<AbstractTraceRegion> nested = getNestedRegions(); String nestedText; if (nested.isEmpty()) nestedText = ""; else nestedText = " nestedRegions={\n " + Joiner.on("\n").join(nested).replace("\n", "\n ") + "\n}"; List<ILocationData> associated = getAssociatedLocations(); String associatedText; if (associated.isEmpty()) associatedText = ""; else associatedText = " associations={\n " + Joiner.on("\n").join(associated).replace("\n", "\n ") + "\n}"; return getClass().getSimpleName() + " [myOffset=" + getMyOffset() + ", myLength=" + getMyLength() + "]" + associatedText + nestedText; }
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; }
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; }
@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(); }
/** * Returns the hash code value for this region. The hash code * of a trace region <code>r</code> is defined to be: <pre> * r.getMyOffset() * ^ r.getMyLength() * ^ r.getAssociatedOffset() * ^ r.getAssociatedLength() * ^ (r.getParent() == null ? 0 : r.getParent().hashCode()) * </pre> * This ensures that <tt>r1.equals(r2)</tt> implies that * <tt>r1.hashCode()==r2.hashCode()</tt> for any two {@link AbstractTraceRegion} * <tt>r1</tt> and <tt>r2</tt>, as required by the general * contract of <tt>Object.hashCode</tt>. * * @return the hash code value for this trace region * @see Object#hashCode() * @see Object#equals(Object) * @see #equals(Object) */ @Override public int hashCode() { AbstractTraceRegion parent = getParent(); return getMyOffset() ^ getMyLength() ^ getAssociatedLocations().hashCode() ^ (parent == null ? 0 : parent.hashCode()); }
if (getMyOffset() != other.getMyOffset()) return false; if (!getAssociatedLocations().equals(other.getAssociatedLocations())) return false; AbstractTraceRegion otherParent = other.getParent();
List<ILocationData> allData = getAssociatedLocations(); if (allData.isEmpty()) { return null;
public void writeRegion(AbstractTraceRegion region, Callback<AbstractTraceRegion, ILocationData> callback) throws IOException { callback.doWriteRegion(region.getMyOffset(), region.getMyLength(), region.getMyLineNumber(), region.getMyEndLineNumber(), region.getAssociatedLocations(), region.getNestedRegions()); }
protected AbstractTraceRegion firstLeafOfCurrent() { while(!current.getNestedRegions().isEmpty()) { AbstractTraceRegion next = current.getNestedRegions().get(0); if (next.getMyOffset() != current.getMyOffset()) { AbstractTraceRegion result = new TemporaryTraceRegion( current.getMyOffset(), next.getMyOffset() - current.getMyOffset(), current.getMyLineNumber(), next.getMyLineNumber(), current.getAssociatedLocations(), current); traversalIndizes.add(-1); expectedOffset = next.getMyOffset(); expectedLine = next.getMyLineNumber(); return result; } traversalIndizes.add(0); current = next; } expectedOffset = current.getMyOffset() + current.getMyLength(); expectedLine = current.getMyEndLineNumber(); return current; } }
while(iterator.hasNext()) { AbstractTraceRegion region = iterator.next(); for(ILocationData location: region.getAssociatedLocations()) { URI path = location.getPath(); if (path != null) {
expectedOffset, current.getMyOffset() + current.getMyLength() - expectedOffset, expectedLine, current.getMyEndLineNumber(), current.getAssociatedLocations(), current); expectedOffset = current.getMyOffset() + current.getMyLength(); expectedLine = current.getMyEndLineNumber(); expectedOffset, next.getMyOffset() - expectedOffset, expectedLine, next.getMyLineNumber(), current.getAssociatedLocations(), parent); traversalIndizes.add(idx); expectedOffset = next.getMyOffset();
public String toLocationString(final AbstractTraceRegion traceRegion) { StringConcatenation _builder = new StringConcatenation(); String _string = traceRegion.getAssociatedSrcRelativePath().toString(); _builder.append(_string); _builder.append(":"); final Function1<ILocationData, String> _function = (ILocationData it) -> { return this.toReportableString(it); }; String _join = IterableExtensions.join(ListExtensions.<ILocationData, String>map(traceRegion.getAssociatedLocations(), _function), ", "); _builder.append(_join); return _builder.toString(); }