context, COL_LINES, new FileLines(filename, lineNums)));
@Nonnull @VisibleForTesting static Row getAggregateRow( WarningTriplet triplet, Map<String, SortedSet<Integer>> filelines, Map<String, ColumnMetadata> columnMetadataMap) { return Row.builder(columnMetadataMap) .put( COL_FILELINES, filelines.entrySet().stream() .map(e -> new FileLines(e.getKey(), e.getValue())) .collect(ImmutableList.toImmutableList())) .put(COL_TEXT, triplet._text) .put(COL_PARSER_CONTEXT, triplet._parserContext) .put(COL_COMMENT, firstNonNull(triplet._comment, "(not provided)")) .build(); }
@VisibleForTesting // Entry is: filename -> struct type -> struct name -> defined structure info static List<Row> processEntryToRows( Entry<String, SortedMap<String, SortedMap<String, DefinedStructureInfo>>> e) { List<Row> rows = new ArrayList<>(); String filename = e.getKey(); for (Entry<String, SortedMap<String, DefinedStructureInfo>> e1 : e.getValue().entrySet()) { String structType = e1.getKey(); for (Entry<String, DefinedStructureInfo> e2 : e1.getValue().entrySet()) { String name = e2.getKey(); DefinedStructureInfo info = e2.getValue(); if (info.getNumReferrers() == 0) { rows.add( Row.builder(COLUMN_METADATA_MAP) .put(COL_STRUCTURE_TYPE, structType) .put(COL_STRUCTURE_NAME, name) .put(COL_SOURCE_LINES, new FileLines(filename, info.getDefinitionLines())) .build()); } } } return rows; }
context, COL_SOURCE_LINES, new FileLines(filename, lineNums))); }); });
private static Row toRow(DefinedStructureRow info) { return Row.builder(COLUMN_METADATA_MAP) .put(COL_STRUCTURE_NAME, info.getStructName()) .put(COL_STRUCT_TYPE, info.getStructType()) .put(COL_SOURCE_LINES, new FileLines(info.getFilename(), info.getDefinitionLines())) .build(); } }
@Test public void testProcessMultipleEntries() { Map<String, SortedMap<String, SortedMap<String, DefinedStructureInfo>>> refsMap = ImmutableMap.of( "f", ImmutableSortedMap.of( "t", ImmutableSortedMap.of( "n", new DefinedStructureInfo(ImmutableSortedSet.of(1), 0), "n2", new DefinedStructureInfo(ImmutableSortedSet.of(2, 3), 0)))); List<Row> expected = ImmutableList.of( BASIC_ROW, Row.of( COL_STRUCTURE_TYPE, "t", COL_STRUCTURE_NAME, "n2", COL_SOURCE_LINES, new FileLines("f", ImmutableSortedSet.of(2, 3)))); List<Row> rows = UnusedStructuresAnswerer.processEntryToRows(refsMap.entrySet().iterator().next()); assertThat(rows, equalTo(expected)); }
@Test public void testAggregateRow() { Row row = getAggregateRow( new WarningTriplet("dup", "[configuration]", null), ImmutableMap.of("f1", ImmutableSortedSet.of(3, 4), "f2", ImmutableSortedSet.of(23)), createMetadata(new ParseWarningQuestion(true)).toColumnMap()); Row expected = Row.of( COL_FILELINES, ImmutableList.of( new FileLines("f1", ImmutableSortedSet.of(3, 4)), new FileLines("f2", ImmutableSortedSet.of(23))), COL_TEXT, "dup", COL_PARSER_CONTEXT, "[configuration]", COL_COMMENT, "(not provided)"); assertThat(row, equalTo(expected)); }
"c2", COL_LINES, new FileLines("f", ImmutableSortedSet.of(2, 3))));