
com.google.errorprone.BugPatternIndexWriter Maven / Gradle / Ivy
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.errorprone;
import static com.google.common.collect.Multimaps.index;
import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Ordering;
import com.google.errorprone.DocGenTool.Target;
import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.Mustache;
import com.github.mustachejava.MustacheFactory;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
/**
* @author [email protected] (Alex Eagle)
*/
public class BugPatternIndexWriter {
void dump(Collection patterns, Writer w, Target target) throws IOException {
Map>> data = new TreeMap<>(Ordering.natural().reverse());
ListMultimap index =
index(
patterns,
new Function() {
@Override
public String apply(BugPatternInstance input) {
return (input.maturity.description + " : " + input.severity).replace("_", "\\_");
}
});
for (Entry> entry : index.asMap().entrySet()) {
data.put(
entry.getKey(),
FluentIterable.from(entry.getValue())
.transform(
new Function>() {
@Override
public Map apply(BugPatternInstance input) {
return ImmutableMap.of("name", input.name, "summary", input.summary);
}
})
.toSortedList(
new Ordering
© 2015 - 2025 Weber Informatics LLC | Privacy Policy