/** * Extract the lines of all the locations in the specified component. All the flows and secondary locations * are taken into account. The lines present in multiple flows and locations are kept * duplicated. Ordering of results is not guaranteed. * <p> * TODO should be a method of DefaultIssue, as soon as it's no * longer in sonar-core and can access sonar-db-dao. */ public static IntStream allLinesFor(DefaultIssue issue, String componentId) { DbIssues.Locations locations = issue.getLocations(); if (locations == null) { return IntStream.empty(); } Stream<DbCommons.TextRange> textRanges = Stream.concat( locations.hasTextRange() ? Stream.of(locations.getTextRange()) : Stream.empty(), locations.getFlowList().stream() .flatMap(f -> f.getLocationList().stream()) .filter(l -> Objects.equals(componentIdOf(issue, l), componentId)) .map(DbIssues.Location::getTextRange)); return textRanges.flatMapToInt(range -> IntStream.rangeClosed(range.getStartLine(), range.getEndLine())); }
private static void addLines(Set<Integer> involvedLines, TextRange range) { IntStream.rangeClosed(range.getStartLine(), range.getEndLine()).forEach(involvedLines::add); }
public Builder mergeFrom(org.sonar.db.protobuf.DbCommons.TextRange other) { if (other == org.sonar.db.protobuf.DbCommons.TextRange.getDefaultInstance()) return this; if (other.hasStartLine()) { setStartLine(other.getStartLine()); } if (other.hasEndLine()) { setEndLine(other.getEndLine()); } if (other.hasStartOffset()) { setStartOffset(other.getStartOffset()); } if (other.hasEndOffset()) { setEndOffset(other.getEndOffset()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
private static Common.TextRange.Builder convertTextRange(DbCommons.TextRange sourceRange) { Common.TextRange.Builder targetRange = Common.TextRange.newBuilder(); if (sourceRange.hasStartLine()) { targetRange.setStartLine(sourceRange.getStartLine()); } if (sourceRange.hasStartOffset()) { targetRange.setStartOffset(sourceRange.getStartOffset()); } if (sourceRange.hasEndLine()) { targetRange.setEndLine(sourceRange.getEndLine()); } if (sourceRange.hasEndOffset()) { targetRange.setEndOffset(sourceRange.getEndOffset()); } return targetRange; }
private static Common.TextRange.Builder convertTextRange(DbCommons.TextRange sourceRange) { Common.TextRange.Builder targetRange = Common.TextRange.newBuilder(); if (sourceRange.hasStartLine()) { targetRange.setStartLine(sourceRange.getStartLine()); } if (sourceRange.hasStartOffset()) { targetRange.setStartOffset(sourceRange.getStartOffset()); } if (sourceRange.hasEndLine()) { targetRange.setEndLine(sourceRange.getEndLine()); } if (sourceRange.hasEndOffset()) { targetRange.setEndOffset(sourceRange.getEndOffset()); } return targetRange; }