/** * 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())); }
public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000001) == 0x00000001)) { output.writeMessage(1, getTextRange()); } for (int i = 0; i < flow_.size(); i++) { output.writeMessage(2, flow_.get(i)); } unknownFields.writeTo(output); }
public int getSerializedSize() { int size = memoizedSize; if (size != -1) return size; size = 0; if (((bitField0_ & 0x00000001) == 0x00000001)) { size += com.google.protobuf.CodedOutputStream .computeMessageSize(1, getTextRange()); } for (int i = 0; i < flow_.size(); i++) { size += com.google.protobuf.CodedOutputStream .computeMessageSize(2, flow_.get(i)); } size += unknownFields.getSerializedSize(); memoizedSize = size; return size; }
public Builder mergeFrom(org.sonar.db.protobuf.DbIssues.Locations other) { if (other == org.sonar.db.protobuf.DbIssues.Locations.getDefaultInstance()) return this; if (other.hasTextRange()) { mergeTextRange(other.getTextRange());
private static Optional<Changeset> getChangeset(Component component, ScmInfo scmInfo, DefaultIssue issue) { Set<Integer> involvedLines = new HashSet<>(); DbIssues.Locations locations = issue.getLocations(); if (locations != null) { if (locations.hasTextRange()) { addLines(involvedLines, locations.getTextRange()); } for (Flow f : locations.getFlowList()) { for (Location l : f.getLocationList()) { if (Objects.equals(l.getComponentId(), component.getUuid())) { // Ignore locations in other files, since it is currently not very common, and this is hard to load SCM by component UUID. addLines(involvedLines, l.getTextRange()); } } } if (!involvedLines.isEmpty()) { return involvedLines.stream() .filter(scmInfo::hasChangesetForLine) .map(scmInfo::getChangesetForLine) .max(Comparator.comparingLong(Changeset::getDate)); } } return Optional.of(scmInfo.getLatestChangeset()); }
private static void completeIssueLocations(IssueDto dto, Issue.Builder issueBuilder, SearchResponseData data) { DbIssues.Locations locations = dto.parseLocations(); if (locations == null) { return; } if (locations.hasTextRange()) { DbCommons.TextRange textRange = locations.getTextRange(); issueBuilder.setTextRange(convertTextRange(textRange)); } for (DbIssues.Flow flow : locations.getFlowList()) { Flow.Builder targetFlow = Flow.newBuilder(); for (DbIssues.Location flowLocation : flow.getLocationList()) { targetFlow.addLocations(convertLocation(issueBuilder, flowLocation, data)); } issueBuilder.addFlows(targetFlow); } }
private static void completeIssueLocations(IssueDto dto, Issue.Builder issueBuilder, SearchResponseData data) { DbIssues.Locations locations = dto.parseLocations(); if (locations == null) { return; } if (locations.hasTextRange()) { DbCommons.TextRange textRange = locations.getTextRange(); issueBuilder.setTextRange(convertTextRange(textRange)); } for (DbIssues.Flow flow : locations.getFlowList()) { Flow.Builder targetFlow = Flow.newBuilder(); for (DbIssues.Location flowLocation : flow.getLocationList()) { targetFlow.addLocations(convertLocation(issueBuilder, flowLocation, data)); } issueBuilder.addFlows(targetFlow); } }