@Override public void newProbeInserted(Probe probe) { final SourceSection sourceSection = probe.getProbedSourceSection(); if (sourceSection != null && !(sourceSection instanceof NullSourceSection)) { final LineLocation lineLocation = sourceSection.getLineLocation(); if (TRACE) { trace("ADD " + lineLocation.getShortDescription() + " ==> " + probe.getShortDescription()); } Collection<Probe> probes = lineToProbesMap.get(lineLocation); if (probes == null) { probes = new ArrayList<>(2); lineToProbesMap.put(lineLocation, probes); } else { assert !probes.contains(probe); } probes.add(probe); } } }
private static String displaySourceAttribution(Node node) { final SourceSection section = node.getSourceSection(); if (section instanceof NullSourceSection) { return "source: " + section.getShortDescription(); } if (section != null) { final String srcText = section.getCode(); final StringBuilder sb = new StringBuilder(); sb.append("source:"); sb.append(" (" + section.getCharIndex() + "," + (section.getCharEndIndex() - 1) + ")"); sb.append(" line=" + section.getLineLocation().getLineNumber()); sb.append(" len=" + srcText.length()); sb.append(" text=\"" + srcText + "\""); return sb.toString(); } return ""; }
int lineNumber; try { lineNumber = sourceSection != null ? sourceSection.getLineLocation().getLineNumber() : -1; } catch (UnsupportedOperationException e) {
@Override public void probeTaggedAs(Probe probe, SyntaxTag tag, Object tagValue) { if (countingTag == tag) { final SourceSection srcSection = probe.getProbedSourceSection(); if (srcSection == null) { // TODO (mlvdv) report this? } else if (!srcSection.getSource().isTaggedAs(Tags.NO_COVERAGE)) { // Get the source line where the final LineLocation lineLocation = srcSection.getLineLocation(); CoverageRecord record = coverageMap.get(lineLocation); if (record != null) { // Another node starts on same line; count only the first (textually) if (srcSection.getCharIndex() > record.srcSection.getCharIndex()) { // Existing record, corresponds to code earlier on line return; } else { // Existing record, corresponds to code at a later position; replace it record.instrument.dispose(); } } final CoverageRecord coverage = new CoverageRecord(srcSection); final Instrument instrument = Instrument.create(coverage, CoverageTracker.class.getSimpleName()); coverage.instrument = instrument; instruments.add(instrument); probe.attach(instrument); coverageMap.put(lineLocation, coverage); } } } }
@Override public Throwable fillInStackTrace() { SourceSection sourceSection = this.getSourceSection(); Source source = sourceSection != null ? sourceSection.getSource() : null; String sourceName = source != null ? source.getName() : null; int lineNumber; try { lineNumber = sourceSection != null ? sourceSection.getLineLocation().getLineNumber() : -1; } catch (UnsupportedOperationException e) { /* * SourceSection#getLineLocation() may throw an UnsupportedOperationException. */ lineNumber = -1; } StackTraceElement[] traces = new StackTraceElement[] { new StackTraceElement(filename(sourceName), this.getMethodName(), sourceName, lineNumber) }; this.setStackTrace(traces); return this; }