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()); }
return false; AbstractTraceRegion other = (AbstractTraceRegion) obj; if (getMyLength() != other.getMyLength()) return false; if (getMyOffset() != other.getMyOffset()) return false; if (!getAssociatedLocations().equals(other.getAssociatedLocations())) return false; AbstractTraceRegion otherParent = other.getParent(); AbstractTraceRegion parent = getParent(); if (otherParent == null) { if (parent!= null) if (parent == null) return false; if (!parent.equals(otherParent)) return false;
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; }
public LeafIterator(AbstractTraceRegion root) { current = root; expectedOffset = root.getMyOffset(); expectedLine = root.getMyLineNumber(); }
public ITextRegionWithLineInformation getMyRegion() { return new TextRegionWithLineInformation(getMyOffset(), getMyLength(), getMyLineNumber(), getMyEndLineNumber()); }
URI generatedUriForTrace = traceURIConverter.getURIForTrace(generatedFileURI); if(sourceUriForTrace != null && generatedUriForTrace != null) result.addAll(traceRegion.invertFor(sourceUriForTrace, generatedUriForTrace)); } catch (Exception e) { log.error(e.getMessage(), e); ITextRegionWithLineInformation associated = ITextRegionWithLineInformation.EMPTY_REGION; for(AbstractTraceRegion child: result) { rootLocation = rootLocation.merge(new TextRegionWithLineInformation(child.getMyOffset(), child.getMyLength(), child.getMyLineNumber(), child.getMyEndLineNumber())); ILocationData childAssociation = child.getMergedAssociatedLocation(); if (childAssociation != null) associated = associated.merge(childAssociation); child.setParent(root);
@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; }
/** * 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 (right == null || left.equals(right)) { return getMergedLocationInResource(left); } else { URI leftToPath = left.getAssociatedPath(); URI rightToPath = right.getAssociatedPath(); if (leftToPath != null && leftToPath.equals(rightToPath) || leftToPath == rightToPath) { ITextRegionWithLineInformation leftRegion = left.getMyRegion(); ITextRegionWithLineInformation rightRegion = right.getMyRegion(); if (leftRegion.contains(rightRegion)) { return getMergedLocationInResource(left); return getMergedLocationInResource(right); } else { AbstractTraceRegion parent = left.getParent(); AbstractTraceRegion leftChild = left; while(parent != null) { if (parent.getMyRegion().contains(rightRegion)) { break; parent = parent.getParent(); while(!parent.equals(rightChild.getParent())) { rightChild = rightChild.getParent(); if (rightChild == null) { return getMergedLocationInResource(leftChild); path = leftChild.getAssociatedPath(); ITextRegionWithLineInformation merged = parent.getMergedAssociatedLocation();
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; }
@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(); }
/** * Calculate whether the given {@code region} encloses the offset. * @param region the region to be checked. May not be <code>null</code>. * @param offset the offset that should be enclosed by the region. * @param includeRegionEnd whether a region is enclosing the offset if it ends at that location. * @return <code>true</true> if the given region encloses the offset. */ public boolean encloses(AbstractTraceRegion region, int offset, boolean includeRegionEnd) { return encloses(region.getMyOffset(), region.getMyLength(), offset, includeRegionEnd); }
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(); }
Iterator<AbstractTraceRegion> iterator = traceRegion.treeIterator(); while(iterator.hasNext()) { AbstractTraceRegion region = iterator.next(); for(ILocationData location: region.getAssociatedLocations()) { URI path = location.getPath(); if (path != null) {
protected boolean isAssociatedWith(AbstractTraceRegion region, URI uri) { URI convertedUri = traceURIConverter.getURIForTrace(uri); if (convertedUri.equals(region.getAssociatedPath())) return true; return false; }
@Nullable protected AbstractTraceRegion findTraceRegionAt(int offset, boolean includeRegionEnd) { AbstractTraceRegion candidate = getRootTraceRegion(); if (candidate == null || !encloses(candidate, offset, includeRegionEnd)) { // we have an inconsistent state - no candidate matches return null; } outer: while(candidate != null) { List<? extends AbstractTraceRegion> children = candidate.getNestedRegions(); if (children.isEmpty()) { return candidate; } for(AbstractTraceRegion child: children) { if (encloses(child, offset, includeRegionEnd)) { candidate = child; continue outer; } else { if (child.getMyOffset() > offset) { return candidate; } } } return candidate; } return null; }
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; }
public boolean apply(@Nullable AbstractTraceRegion input) { if (input == null || input.equals(previous)) return false; previous = input; return true; } });
@Override protected Iterator<? extends AbstractTraceRegion> getChildren(@Nullable Object object) { if (object == null) return Iterators.emptyIterator(); AbstractTraceRegion casted = (AbstractTraceRegion) object; return casted.getNestedRegions().iterator(); } /**
@Nullable protected ILocationInResource getMergedLocationInResource(AbstractTraceRegion region) { ILocationData locationData = region.getMergedAssociatedLocation(); if (locationData != null) return createLocationInResourceFor(locationData, region); return null; }