[WIP] Initial regex extraction + docgen

This commit is contained in:
Gijs de Jong
2022-09-26 13:20:30 +02:00
committed by japborst
parent d7f1fc6cff
commit d8009e9c26
47 changed files with 2465 additions and 39 deletions

162
docgen/pom.xml Normal file
View File

@@ -0,0 +1,162 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2011 The Error Prone Authors.
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>tech.picnic.error-prone-support</groupId>
<artifactId>error-prone-support</artifactId>
<version>0.2.1-SNAPSHOT</version>
</parent>
<name>Picnic :: Error Prone Support :: DocGen</name>
<artifactId>error_prone_docgen</artifactId>
<licenses>
<license>
<name>Apache 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<version>${version.auto-value}</version>
</path>
<path>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>${version.auto-service}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.mustache</include>
</includes>
</resource>
</resources>
</build>
<dependencies>
<dependency>
<groupId>${groupId.error-prone}</groupId>
<artifactId>error_prone_annotation</artifactId>
</dependency>
<dependency>
<groupId>${groupId.error-prone}</groupId>
<artifactId>error_prone_core</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>error-prone-contrib</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>tech.picnic.error-prone-support</groupId>
<artifactId>error_prone_docgen_processor</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.30</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.82</version>
</dependency>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value-annotations</artifactId>
<version>${version.auto-value}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.spullara.mustache.java</groupId>
<artifactId>compiler</artifactId>
<version>0.9.10</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.9</version>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>run-annotation-processor</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>site</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.google.errorprone.DocGenTool</mainClass>
<arguments>
<argument>
-bug_patterns=${basedir}/../error-prone-contrib/target/generated-sources/annotations/bugPatterns.txt
</argument>
<argument>-docs_repository=${basedir}/target/generated-wiki/</argument>
<argument>-explanations=${basedir}/../docs/bugpattern-temp/</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@@ -0,0 +1,168 @@
/*
* Copyright 2014 The Error Prone Authors.
*
* 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 java.nio.charset.StandardCharsets.UTF_8;
import static java.util.stream.Collectors.joining;
import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.Mustache;
import com.github.mustachejava.MustacheFactory;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.LineProcessor;
import com.google.errorprone.BugPattern.SeverityLevel;
import com.google.gson.Gson;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;
import org.yaml.snakeyaml.representer.Representer;
/**
* Reads each line of the bugpatterns.txt tab-delimited data file, and generates a GitHub Jekyll
* page for each one.
*
* @author alexeagle@google.com (Alex Eagle)
*/
class BugPatternFileGenerator implements LineProcessor<List<BugPatternInstance>> {
private final Path outputDir;
private final Path explanationDir;
private final List<BugPatternInstance> result;
private final Function<BugPatternInstance, SeverityLevel> severityRemapper;
/** The base url for links to bugpatterns. */
@Nullable private final String baseUrl;
public BugPatternFileGenerator(
Path bugpatternDir,
Path explanationDir,
String baseUrl,
Function<BugPatternInstance, SeverityLevel> severityRemapper) {
this.outputDir = bugpatternDir;
this.explanationDir = explanationDir;
this.severityRemapper = severityRemapper;
this.baseUrl = baseUrl;
result = new ArrayList<>();
}
@Override
public boolean processLine(String line) throws IOException {
BugPatternInstance pattern = new Gson().fromJson(line, BugPatternInstance.class);
pattern.severity = severityRemapper.apply(pattern);
result.add(pattern);
// replace spaces in filename with underscores
Path checkPath = Paths.get(pattern.name.replace(' ', '_') + ".md");
try (Writer writer = Files.newBufferedWriter(outputDir.resolve(checkPath), UTF_8)) {
// load side-car explanation file, if it exists
Path sidecarExplanation = explanationDir.resolve(checkPath);
if (Files.exists(sidecarExplanation)) {
if (!pattern.explanation.isEmpty()) {
throw new AssertionError(
String.format(
"%s specifies an explanation via @BugPattern and side-car", pattern.name));
}
pattern.explanation = Files.readString(sidecarExplanation).trim();
}
// Construct an appropriate page for this {@code BugPattern}. Include altNames if
// there are any, and explain the correct way to suppress.
ImmutableMap.Builder<String, Object> templateData =
ImmutableMap.<String, Object>builder()
.put(
"tags", Arrays.stream(pattern.tags).map(Style::styleTag).collect(joining("\n\n")))
.put("severity", Style.styleSeverity(pattern.severity))
.put("name", pattern.name)
.put("bugpattern", String.format("%s.java", pattern.className))
.put("className", pattern.className)
.put("summary", pattern.summary.trim())
.put("altNames", Joiner.on(", ").join(pattern.altNames))
.put("explanation", pattern.explanation.trim());
if (pattern.sampleInput != null) {
templateData.put("sampleInput", pattern.sampleInput);
}
if (pattern.sampleOutput != null) {
templateData.put("sampleOutput", pattern.sampleOutput);
}
if (baseUrl != null) {
templateData.put("baseUrl", baseUrl);
}
if (pattern.documentSuppression) {
String suppressionString;
if (pattern.suppressionAnnotations.length == 0) {
suppressionString = "This check may not be suppressed.";
} else {
suppressionString =
pattern.suppressionAnnotations.length == 1
? "Suppress false positives by adding the suppression annotation %s to the "
+ "enclosing element."
: "Suppress false positives by adding one of these suppression annotations to "
+ "the enclosing element: %s";
suppressionString =
String.format(
suppressionString,
Arrays.stream(pattern.suppressionAnnotations)
.map((String anno) -> standardizeAnnotation(anno, pattern.name))
.collect(joining(", ")));
}
templateData.put("suppression", suppressionString);
}
MustacheFactory mf = new DefaultMustacheFactory();
Mustache mustache = mf.compile("com/google/errorprone/resources/bugpattern.mustache");
mustache.execute(writer, templateData.buildOrThrow());
}
return true;
}
private String standardizeAnnotation(String fullAnnotationName, String patternName) {
String annotationName =
fullAnnotationName.endsWith(".class")
? fullAnnotationName.substring(0, fullAnnotationName.length() - ".class".length())
: fullAnnotationName;
if (annotationName.equals(SuppressWarnings.class.getName())) {
annotationName = SuppressWarnings.class.getSimpleName() + "(\"" + patternName + "\")";
}
return "`@" + annotationName + "`";
}
@Override
public List<BugPatternInstance> getResult() {
return result;
}
}

View File

@@ -0,0 +1,112 @@
/*
* Copyright 2015 The Error Prone Authors.
*
* 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.ImmutableSet.toImmutableSet;
import static com.google.common.io.Files.asCharSource;
import static com.google.errorprone.scanner.BuiltInCheckerSuppliers.ENABLED_ERRORS;
import static com.google.errorprone.scanner.BuiltInCheckerSuppliers.ENABLED_WARNINGS;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.beust.jcommander.IStringConverter;
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.google.common.base.Ascii;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import java.io.IOException;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.StreamSupport;
/**
* Utility main which consumes the same tab-delimited text file and generates GitHub pages for the
* BugPatterns.
*/
public final class DocGenTool {
@Parameters(separators = "=")
static class Options {
@Parameter(names = "-bug_patterns", description = "Path to bugPatterns.txt", required = true)
private String bugPatterns;
@Parameter(
names = "-explanations",
description = "Path to side-car explanations",
required = true)
private String explanations;
@Parameter(names = "-docs_repository", description = "Path to docs repository", required = true)
private String docsRepository;
@Parameter(
names = "-base_url",
description = "The base url for links to bugpatterns",
arity = 1)
private String baseUrl = null;
}
public static void main(String[] args) throws IOException {
Options options = new Options();
new JCommander(options).parse(args);
Path bugPatterns = Paths.get(options.bugPatterns);
if (!Files.exists(bugPatterns)) {
usage("Cannot find bugPatterns file: " + options.bugPatterns);
}
Path explanationDir = Paths.get(options.explanations);
if (!Files.exists(explanationDir)) {
usage("Cannot find explanations dir: " + options.explanations);
}
Path wikiDir = Paths.get(options.docsRepository);
Files.createDirectories(wikiDir);
Path bugpatternDir = wikiDir.resolve("bugpatterns");
if (!Files.exists(bugpatternDir)) {
Files.createDirectories(bugpatternDir);
}
BugPatternFileGenerator generator =
new BugPatternFileGenerator(
bugpatternDir,
explanationDir,
options.baseUrl,
input -> input.severity);
try (Writer w =
Files.newBufferedWriter(wikiDir.resolve("bugpatterns.md"), StandardCharsets.UTF_8)) {
List<BugPatternInstance> patterns =
asCharSource(bugPatterns.toFile(), UTF_8).readLines(generator);
}
}
private static ImmutableSet<String> enabledCheckNames() {
return StreamSupport.stream(
Iterables.concat(ENABLED_ERRORS, ENABLED_WARNINGS).spliterator(), false)
.map(BugCheckerInfo::canonicalName)
.collect(toImmutableSet());
}
private static void usage(String err) {
System.err.println(err);
System.exit(1);
}
private DocGenTool() {}
}

View File

@@ -0,0 +1,27 @@
package com.google.errorprone;
import com.google.errorprone.BugPattern.SeverityLevel;
public final class Style {
public static String styleSeverity (SeverityLevel severityLevel) {
return String.format("%s\n {: .label .label-%s}", severityLevel.toString(), getSeverityLabelColour(severityLevel));
}
private static String getSeverityLabelColour (SeverityLevel severityLevel) {
switch (severityLevel) {
case ERROR:
return "red";
case WARNING:
return "yellow";
case SUGGESTION:
return "green";
default:
return "blue";
}
}
public static String styleTag (String tagName) {
return String.format("%s\n {: .label }", tagName);
}
}

View File

@@ -0,0 +1,51 @@
---
layout: default
title: {{name}}
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# {{name}}
{{{severity}}}
{{{tags}}}
{{{summary}}}
{{#suppression}}
## Suppression
{{{suppression}}}
{{/suppression}}
## Samples
### Input
```java
{{#sampleInput}}
{{{sampleInput}}}
{{/sampleInput}}
{{^sampleInput}}
public static void sample() {}
{{/sampleInput}}
```
### Output
```java
{{#sampleOutput}}
{{{sampleOutput}}}
{{/sampleOutput}}
{{^sampleOutput}}
public static void sample() {}
{{/sampleOutput}}
```
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${bugpattern}" class="fs-3 btn external"
target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title">
<use xlink:href="#svg-external-link"></use>
</svg>
</a>

View File

@@ -0,0 +1,159 @@
/*
* Copyright 2014 The Error Prone Authors.
*
* 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.truth.Truth.assertThat;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.io.CharStreams;
import com.google.errorprone.BugPattern.SeverityLevel;
import com.google.gson.Gson;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class BugPatternFileGeneratorTest {
@Rule public TemporaryFolder tmpfolder = new TemporaryFolder();
private Path wikiDir;
private Path explanationDirBase;
@Before
public void setUp() throws Exception {
wikiDir = tmpfolder.newFolder("wiki").toPath();
explanationDirBase = tmpfolder.newFolder("explanations").toPath();
}
private static BugPatternInstance deadExceptionTestInfo() {
BugPatternInstance instance = new BugPatternInstance();
instance.className = "com.google.errorprone.bugpatterns.DeadException";
instance.name = "DeadException";
instance.summary = "Exception created but not thrown";
instance.explanation =
"The exception is created with new, but is not thrown, and the reference is lost.";
instance.altNames = new String[] {"ThrowableInstanceNeverThrown"};
instance.tags = new String[] {"LikelyError"};
instance.severity = SeverityLevel.ERROR;
instance.suppressionAnnotations = new String[] {"java.lang.SuppressWarnings.class"};
return instance;
}
private static final String BUGPATTERN_LINE;
static {
BugPatternInstance instance = deadExceptionTestInfo();
BUGPATTERN_LINE = new Gson().toJson(instance);
}
private static final String BUGPATTERN_LINE_SIDECAR;
static {
BugPatternInstance instance = deadExceptionTestInfo();
instance.explanation = "";
BUGPATTERN_LINE_SIDECAR = new Gson().toJson(instance);
}
// Assert that the generator produces the same output it did before.
// This is brittle, but you can open the golden file
// src/test/resources/com/google/errorprone/DeadException.md
// in the same Jekyll environment you use for prod, and verify it looks good.
@Test
public void regressionTest_frontmatter_pygments() throws Exception {
BugPatternFileGenerator generator =
new BugPatternFileGenerator(
wikiDir, explanationDirBase, null, input -> input.severity);
generator.processLine(BUGPATTERN_LINE);
String expected =
CharStreams.toString(
new InputStreamReader(
getClass().getResourceAsStream("testdata/DeadException_frontmatter_pygments.md"),
UTF_8));
String actual =
CharStreams.toString(Files.newBufferedReader(wikiDir.resolve("DeadException.md"), UTF_8));
assertThat(actual.trim()).isEqualTo(expected.trim());
}
@Test
public void regressionTest_nofrontmatter_gfm() throws Exception {
BugPatternFileGenerator generator =
new BugPatternFileGenerator(
wikiDir, explanationDirBase, null, input -> input.severity);
generator.processLine(BUGPATTERN_LINE);
String expected =
CharStreams.toString(
new InputStreamReader(
getClass().getResourceAsStream("testdata/DeadException_nofrontmatter_gfm.md"),
UTF_8));
String actual = new String(Files.readAllBytes(wikiDir.resolve("DeadException.md")), UTF_8);
assertThat(actual.trim()).isEqualTo(expected.trim());
}
@Test
public void regressionTest_sidecar() throws Exception {
BugPatternFileGenerator generator =
new BugPatternFileGenerator(
wikiDir, explanationDirBase, null, input -> input.severity);
Files.write(
explanationDirBase.resolve("DeadException.md"),
Arrays.asList(
"The exception is created with new, but is not thrown, and the reference is lost."),
UTF_8);
generator.processLine(BUGPATTERN_LINE_SIDECAR);
String expected =
CharStreams.toString(
new InputStreamReader(
getClass().getResourceAsStream("testdata/DeadException_nofrontmatter_gfm.md"),
UTF_8));
String actual = new String(Files.readAllBytes(wikiDir.resolve("DeadException.md")), UTF_8);
assertThat(actual.trim()).isEqualTo(expected.trim());
}
@Test
public void testEscapeAngleBracketsInSummary() throws Exception {
// Create a BugPattern with angle brackets in the summary
BugPatternInstance instance = new BugPatternInstance();
instance.className = "com.google.errorprone.bugpatterns.DontDoThis";
instance.name = "DontDoThis";
instance.summary = "Don't do this; do List<Foo> instead";
instance.explanation = "This is a bad idea, you want `List<Foo>` instead";
instance.altNames = new String[0];
instance.tags = new String[] {"LikelyError"};
instance.severity = SeverityLevel.ERROR;
instance.suppressionAnnotations = new String[] {"java.lang.SuppressWarnings.class"};
// Write markdown file
BugPatternFileGenerator generator =
new BugPatternFileGenerator(
wikiDir, explanationDirBase, null, input -> input.severity);
generator.processLine(new Gson().toJson(instance));
String expected =
CharStreams.toString(
new InputStreamReader(
getClass().getResourceAsStream("testdata/DontDoThis_nofrontmatter_gfm.md"), UTF_8));
String actual = new String(Files.readAllBytes(wikiDir.resolve("DontDoThis.md")), UTF_8);
assertThat(actual.trim()).isEqualTo(expected.trim());
}
}

View File

@@ -0,0 +1,20 @@
---
title: DeadException
summary: Exception created but not thrown
layout: bugpattern
tags: LikelyError
severity: ERROR
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
_Alternate names: ThrowableInstanceNeverThrown_
## The problem
The exception is created with new, but is not thrown, and the reference is lost.
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("DeadException")` to the enclosing element.

View File

@@ -0,0 +1,21 @@
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# DeadException
__Exception created but not thrown__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>ERROR</td></tr>
<tr><td>Tags</td><td>LikelyError</td></tr>
</table></div>
_Alternate names: ThrowableInstanceNeverThrown_
## The problem
The exception is created with new, but is not thrown, and the reference is lost.
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("DeadException")` to the enclosing element.

View File

@@ -0,0 +1,20 @@
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# DontDoThis
__Don&#39;t do this; do List&lt;Foo&gt; instead__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>ERROR</td></tr>
<tr><td>Tags</td><td>LikelyError</td></tr>
</table></div>
## The problem
This is a bad idea, you want `List<Foo>` instead
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("DontDoThis")` to the enclosing element.

89
docgen_processor/pom.xml Normal file
View File

@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2011 The Error Prone Authors.
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>tech.picnic.error-prone-support</groupId>
<artifactId>error-prone-support</artifactId>
<version>0.2.1-SNAPSHOT</version>
</parent>
<name>Picnic :: Error Prone Support :: DocGen Processor</name>
<artifactId>error_prone_docgen_processor</artifactId>
<licenses>
<license>
<name>Apache 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<dependencies>
<dependency>
<groupId>${groupId.error-prone}</groupId>
<artifactId>error_prone_annotation</artifactId>
</dependency>
<dependency>
<groupId>${groupId.error-prone}</groupId>
<artifactId>error_prone_core</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service-annotations</artifactId>
<version>${version.auto-service}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.9</version>
</dependency>
<dependency>
<groupId>com.google.googlejavaformat</groupId>
<artifactId>google-java-format</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>${version.auto-service}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,134 @@
/*
* Copyright 2015 The Error Prone Authors.
*
* 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 java.util.stream.Collectors.joining;
import com.google.common.base.Preconditions;
import com.google.errorprone.BugPattern.SeverityLevel;
import com.google.googlejavaformat.java.Formatter;
import com.google.googlejavaformat.java.FormatterException;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import org.eclipse.jgit.util.IO;
/** A serialization-friendly POJO of the information in a {@link BugPattern}. */
public final class BugPatternInstance {
private static final Formatter FORMATTER = new Formatter();
public String className;
public String name;
public String summary;
public String explanation;
public String[] altNames;
public String category;
public String[] tags;
public SeverityLevel severity;
public String[] suppressionAnnotations;
public boolean documentSuppression = true;
public String testContent;
public String sampleInput;
public String sampleOutput;
public static BugPatternInstance fromElement(Element element) {
BugPatternInstance instance = new BugPatternInstance();
instance.className = element.toString();
BugPattern annotation = element.getAnnotation(BugPattern.class);
instance.name =
annotation.name().isEmpty() ? element.getSimpleName().toString() : annotation.name();
instance.altNames = annotation.altNames();
instance.tags = annotation.tags();
instance.severity = annotation.severity();
instance.summary = annotation.summary();
instance.explanation = annotation.explanation();
instance.documentSuppression = annotation.documentSuppression();
Map<String, Object> keyValues = getAnnotation(element, BugPattern.class.getName());
Object suppression = keyValues.get("suppressionAnnotations");
if (suppression == null) {
instance.suppressionAnnotations = new String[] {SuppressWarnings.class.getName()};
} else {
Preconditions.checkState(suppression instanceof List);
@SuppressWarnings("unchecked") // Always List<? extends AnnotationValue>, see above.
List<? extends AnnotationValue> resultList = (List<? extends AnnotationValue>) suppression;
instance.suppressionAnnotations =
resultList.stream().map(AnnotationValue::toString).toArray(String[]::new);
}
Path testPath =
Path.of(
"error-prone-contrib/src/test/java/"
+ instance.className.replace(".", "/")
+ "Test.java");
System.out.println("test class for " + instance.name + " = " + testPath.toAbsolutePath());
try {
Pattern inputPattern =
Pattern.compile("\\.addInputLines\\((\\n.*?\".*?\",)\\n(.*?)\\)\\n", Pattern.DOTALL);
instance.testContent = String.join("\n", Files.readAllLines(testPath));
Matcher inputMatch = inputPattern.matcher(instance.testContent);
if (inputMatch.find()) {
String inputSrc =
inputMatch
.group(2) + ",\n";
System.out.println(inputSrc);
inputSrc = inputSrc.replaceAll("\\s*\"(.*?)\"(,\\n)", "$1\n");
System.out.println(inputSrc);
inputSrc = inputSrc
.replaceAll("\\\\\"(.*?)\\\\\"", "\"$1\"");
System.out.println(inputSrc);
instance.sampleInput = FORMATTER.formatSource(inputSrc);
}
} catch (IOException | IllegalStateException | FormatterException e) {
e.printStackTrace();
}
return instance;
}
private static Map<String, Object> getAnnotation(Element element, String name) {
for (AnnotationMirror mirror : element.getAnnotationMirrors()) {
if (mirror.getAnnotationType().toString().equals(name)) {
return annotationKeyValues(mirror);
}
}
throw new IllegalArgumentException(String.format("%s has no annotation %s", element, name));
}
private static Map<String, Object> annotationKeyValues(AnnotationMirror mirror) {
Map<String, Object> result = new LinkedHashMap<>();
for (ExecutableElement key : mirror.getElementValues().keySet()) {
result.put(key.getSimpleName().toString(), mirror.getElementValues().get(key).getValue());
}
return result;
}
}

View File

@@ -0,0 +1,93 @@
/*
* Copyright 2011 The Error Prone Authors.
*
* 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 java.nio.charset.StandardCharsets.UTF_8;
import com.google.auto.service.AutoService;
import com.google.googlejavaformat.java.Formatter;
import com.google.gson.Gson;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.Processor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.tools.FileObject;
import javax.tools.StandardLocation;
/**
* Annotation processor which visits all classes that have a {@code BugPattern} annotation, and
* writes a tab-delimited text file dumping the data found.
*
* @author eaftan@google.com (Eddie Aftandilian)
* @author alexeagle@google.com (Alex Eagle)
*/
@AutoService(Processor.class)
@SupportedAnnotationTypes("com.google.errorprone.BugPattern")
public class DocGenProcessor extends AbstractProcessor {
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
private final Gson gson = new Gson();
private PrintWriter pw;
/** {@inheritDoc} */
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
try {
FileObject manifest =
processingEnv
.getFiler()
.createResource(StandardLocation.SOURCE_OUTPUT, "", "bugPatterns.txt");
pw = new PrintWriter(new OutputStreamWriter(manifest.openOutputStream(), UTF_8), true);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
/** {@inheritDoc} */
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (Element element : roundEnv.getElementsAnnotatedWith(BugPattern.class)) {
System.out.println("[DOCGEN] HANDLING: " + element.getSimpleName());
gson.toJson(BugPatternInstance.fromElement(element), pw);
pw.println();
}
if (roundEnv.processingOver()) {
// this was the last round, do cleanup
cleanup();
}
return false;
}
/** Perform cleanup after last round of annotation processing. */
private void cleanup() {
pw.close();
}
}

View File

@@ -0,0 +1,90 @@
package tech.picnic.errorprone.docgen;
import static java.util.stream.Collectors.joining;
import com.google.googlejavaformat.java.Formatter;
import com.google.googlejavaformat.java.FormatterException;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
class ExampleExtractorTest {
private static final String INPUT =
String.join("\n",
"@Test",
"void replacementFirstSuggestedFix() {",
" refactoringTestHelper",
" .addInputLines(",
" \"A.java\",",
" \"import static java.util.stream.Collectors.toList;\",",
" \"import static java.util.stream.Collectors.toMap;\",",
" \"import static java.util.stream.Collectors.toSet;\",",
" \"\",",
" \"import java.util.stream.Collectors;\",",
" \"import java.util.stream.Stream;\",",
" \"import reactor.core.publisher.Flux;\",",
" \"\",",
" \"class A {\",",
" \" void m() {\",",
" \" Flux.just(1).collect(Collectors.toList());\",",
" \" Flux.just(2).collect(toList());\",",
" \"\",",
" \" Stream.of(\"foo\").collect(Collectors.toMap(String::getBytes, String::length));\",",
" \" Stream.of(\"bar\").collect(toMap(String::getBytes, String::length));\",",
" \" Flux.just(\"baz\").collect(Collectors.toMap(String::getBytes, String::length, (a, b) -> b));\",",
" \" Flux.just(\"qux\").collect(toMap(String::getBytes, String::length, (a, b) -> b));\",",
" \"\",",
" \" Stream.of(1).collect(Collectors.toSet());\",",
" \" Stream.of(2).collect(toSet());\",",
" \" }\",",
" \"}\")",
" .addOutputLines(",
" \"A.java\",",
" \"import static com.google.common.collect.ImmutableList.toImmutableList;\",",
" \"import static com.google.common.collect.ImmutableMap.toImmutableMap;\",",
" \"import static com.google.common.collect.ImmutableSet.toImmutableSet;\",",
" \"import static java.util.stream.Collectors.toList;\",",
" \"import static java.util.stream.Collectors.toMap;\",",
" \"import static java.util.stream.Collectors.toSet;\",",
" \"\",",
" \"import java.util.stream.Collectors;\",",
" \"import java.util.stream.Stream;\",",
" \"import reactor.core.publisher.Flux;\",",
" \"\",",
" \"class A {\",",
" \" void m() {\",",
" \" Flux.just(1).collect(toImmutableList());\",",
" \" Flux.just(2).collect(toImmutableList());\",",
" \"\",",
" \" Stream.of(\"foo\").collect(toImmutableMap(String::getBytes, String::length));\",",
" \" Stream.of(\"bar\").collect(toImmutableMap(String::getBytes, String::length));\",",
" \" Flux.just(\"baz\").collect(toImmutableMap(String::getBytes, String::length, (a, b) -> b));\",",
" \" Flux.just(\"qux\").collect(toImmutableMap(String::getBytes, String::length, (a, b) -> b));\",",
" \"\",",
" \" Stream.of(1).collect(toImmutableSet());\",",
" \" Stream.of(2).collect(toImmutableSet());\",",
" \" }\",",
" \"}\")",
" .doTest(TestMode.TEXT_MATCH);",
"}");
@Test
void regexTest() throws FormatterException {
final Formatter FORMATTER = new Formatter();
Pattern pattern =
Pattern.compile("\\.addInputLines\\((\n.*?\".*?\",)\n(.*?)\\)\n", Pattern.DOTALL);
Matcher matcher = pattern.matcher(INPUT);
int count = matcher.groupCount();
if(!matcher.find()) {
System.out.println("no match!");
return;
}
String src = matcher.group(2);
System.out.println("\\\"foo\\\"".replaceAll("\\\\\"(.*?)\\\\\"", "\"$1\""));
}
}

View File

@@ -0,0 +1,42 @@
---
layout: default
title: AmbiguousJsonCreator
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# AmbiguousJsonCreator
LikelyError
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# AmbiguousJsonCreator
__&#96;JsonCreator.Mode&#96; should be set for single-argument creators__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>WARNING</td></tr>
<tr><td>Tags</td><td>LikelyError</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("AmbiguousJsonCreator")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: AssertJIsNull
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# AssertJIsNull
Simplification
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# AssertJIsNull
__Prefer &#96;.isNull()&#96; over &#96;.isEqualTo(null)&#96;__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>SUGGESTION</td></tr>
<tr><td>Tags</td><td>Simplification</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("AssertJIsNull")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: AutowiredConstructor
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# AutowiredConstructor
Simplification
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# AutowiredConstructor
__Omit &#96;@Autowired&#96; on a class&#39; sole constructor, as it is redundant__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>SUGGESTION</td></tr>
<tr><td>Tags</td><td>Simplification</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("AutowiredConstructor")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: CanonicalAnnotationSyntax
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# CanonicalAnnotationSyntax
Simplification
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# CanonicalAnnotationSyntax
__Omit redundant syntax from annotation declarations__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>SUGGESTION</td></tr>
<tr><td>Tags</td><td>Simplification</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("CanonicalAnnotationSyntax")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: CollectorMutability
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# CollectorMutability
FragileCode
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# CollectorMutability
__Avoid &#96;Collectors.to{List,Map,Set}&#96; in favour of alternatives that emphasize (im)mutability__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>WARNING</td></tr>
<tr><td>Tags</td><td>FragileCode</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("CollectorMutability")` to the enclosing element.

View File

@@ -1 +1,42 @@
There's not much use to keep empty methods.
---
layout: default
title: EmptyMethod
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# EmptyMethod
Simplification
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# EmptyMethod
__Empty method can likely be deleted__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>SUGGESTION</td></tr>
<tr><td>Tags</td><td>Simplification</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("EmptyMethod")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: ErrorProneTestHelperSourceFormat
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# ErrorProneTestHelperSourceFormat
Style
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# ErrorProneTestHelperSourceFormat
__Test code should follow the Google Java style__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>SUGGESTION</td></tr>
<tr><td>Tags</td><td>Style</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("ErrorProneTestHelperSourceFormat")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: ExplicitEnumOrdering
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# ExplicitEnumOrdering
FragileCode
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# ExplicitEnumOrdering
__Make sure &#96;Ordering#explicit&#96; lists all of an enum&#39;s values__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>WARNING</td></tr>
<tr><td>Tags</td><td>FragileCode</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("ExplicitEnumOrdering")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: FluxFlatMapUsage
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# FluxFlatMapUsage
LikelyError
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# FluxFlatMapUsage
__&#96;Flux#flatMap&#96; and &#96;Flux#flatMapSequential&#96; have subtle semantics; please use &#96;Flux#concatMap&#96; or explicitly specify the desired amount of concurrency__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>ERROR</td></tr>
<tr><td>Tags</td><td>LikelyError</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("FluxFlatMapUsage")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: FormatStringConcatenation
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# FormatStringConcatenation
Simplification
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# FormatStringConcatenation
__Defer string concatenation to the invoked method__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>WARNING</td></tr>
<tr><td>Tags</td><td>Simplification</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("FormatStringConcatenation")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: IdentityConversion
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# IdentityConversion
Simplification
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# IdentityConversion
__Avoid or clarify identity conversions__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>WARNING</td></tr>
<tr><td>Tags</td><td>Simplification</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("IdentityConversion")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: ImmutablesSortedSetComparator
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# ImmutablesSortedSetComparator
LikelyError
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# ImmutablesSortedSetComparator
__&#96;SortedSet&#96; properties of a &#96;@Value.Immutable&#96; or &#96;@Value.Modifiable&#96; type must be annotated with &#96;@Value.NaturalOrder&#96; or &#96;@Value.ReverseOrder&#96;__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>ERROR</td></tr>
<tr><td>Tags</td><td>LikelyError</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("ImmutablesSortedSetComparator")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: JUnitMethodDeclaration
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# JUnitMethodDeclaration
Simplification
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# JUnitMethodDeclaration
__JUnit method declaration can likely be improved__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>SUGGESTION</td></tr>
<tr><td>Tags</td><td>Simplification</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("JUnitMethodDeclaration")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: LexicographicalAnnotationAttributeListing
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# LexicographicalAnnotationAttributeListing
Style
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# LexicographicalAnnotationAttributeListing
__Where possible, sort annotation array attributes lexicographically__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>SUGGESTION</td></tr>
<tr><td>Tags</td><td>Style</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("LexicographicalAnnotationAttributeListing")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: LexicographicalAnnotationListing
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# LexicographicalAnnotationListing
Style
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# LexicographicalAnnotationListing
__Sort annotations lexicographically where possible__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>SUGGESTION</td></tr>
<tr><td>Tags</td><td>Style</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("LexicographicalAnnotationListing")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: MethodReferenceUsage
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# MethodReferenceUsage
Style
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# MethodReferenceUsage
__Prefer method references over lambda expressions__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>SUGGESTION</td></tr>
<tr><td>Tags</td><td>Style</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("MethodReferenceUsage")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: MissingRefasterAnnotation
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# MissingRefasterAnnotation
LikelyError
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# MissingRefasterAnnotation
__The Refaster template contains a method without any Refaster annotations__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>WARNING</td></tr>
<tr><td>Tags</td><td>LikelyError</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("MissingRefasterAnnotation")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: MockitoStubbing
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# MockitoStubbing
Simplification
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# MockitoStubbing
__Don&#39;t unnecessarily use Mockito&#39;s &#96;eq(...)&#96;__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>SUGGESTION</td></tr>
<tr><td>Tags</td><td>Simplification</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("MockitoStubbing")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: NestedOptionals
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# NestedOptionals
FragileCode
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# NestedOptionals
__Avoid nesting &#96;Optional&#96;s inside &#96;Optional&#96;s; the resultant code is hard to reason about__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>WARNING</td></tr>
<tr><td>Tags</td><td>FragileCode</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("NestedOptionals")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: NonEmptyMono
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# NonEmptyMono
Simplification
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# NonEmptyMono
__Avoid vacuous operations on known non-empty &#96;Mono&#96;s__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>WARNING</td></tr>
<tr><td>Tags</td><td>Simplification</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("NonEmptyMono")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: PrimitiveComparison
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# PrimitiveComparison
Performance
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# PrimitiveComparison
__Ensure invocations of &#96;Comparator#comparing{,Double,Int,Long}&#96; match the return type of the provided function__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>WARNING</td></tr>
<tr><td>Tags</td><td>Performance</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("PrimitiveComparison")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: RedundantStringConversion
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# RedundantStringConversion
Simplification
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# RedundantStringConversion
__Avoid redundant string conversions when possible__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>SUGGESTION</td></tr>
<tr><td>Tags</td><td>Simplification</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("RedundantStringConversion")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: RefasterAnyOfUsage
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# RefasterAnyOfUsage
Simplification
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# RefasterAnyOfUsage
__&#96;Refaster#anyOf&#96; should be passed at least two parameters__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>SUGGESTION</td></tr>
<tr><td>Tags</td><td>Simplification</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("RefasterAnyOfUsage")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: RequestMappingAnnotation
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# RequestMappingAnnotation
LikelyError
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# RequestMappingAnnotation
__Make sure all &#96;@RequestMapping&#96; method parameters are annotated__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>WARNING</td></tr>
<tr><td>Tags</td><td>LikelyError</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("RequestMappingAnnotation")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: RequestParamType
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# RequestParamType
LikelyError
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# RequestParamType
__&#96;@RequestParam&#96; does not support &#96;ImmutableCollection&#96; and &#96;ImmutableMap&#96; subtypes__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>ERROR</td></tr>
<tr><td>Tags</td><td>LikelyError</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("RequestParamType")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: ScheduledTransactionTrace
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# ScheduledTransactionTrace
LikelyError
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# ScheduledTransactionTrace
__Scheduled operation must start a new New Relic transaction__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>ERROR</td></tr>
<tr><td>Tags</td><td>LikelyError</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("ScheduledTransactionTrace")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: Slf4jLogStatement
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# Slf4jLogStatement
LikelyError
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# Slf4jLogStatement
__Make sure SLF4J log statements contain proper placeholders with matching arguments__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>WARNING</td></tr>
<tr><td>Tags</td><td>LikelyError</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("Slf4jLogStatement")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: SpringMvcAnnotation
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# SpringMvcAnnotation
Simplification
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# SpringMvcAnnotation
__Prefer the conciseness of &#96;@{Get,Put,Post,Delete,Patch}Mapping&#96; over &#96;@RequestMapping&#96;__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>SUGGESTION</td></tr>
<tr><td>Tags</td><td>Simplification</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("SpringMvcAnnotation")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: StaticImport
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# StaticImport
Simplification
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# StaticImport
__Identifier should be statically imported__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>SUGGESTION</td></tr>
<tr><td>Tags</td><td>Simplification</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("StaticImport")` to the enclosing element.

View File

@@ -0,0 +1,42 @@
---
layout: default
title: TimeZoneUsage
parent: Bug Patterns
nav_order: 1
---
<!--
*** AUTO-GENERATED, DO NOT MODIFY ***
To make changes, edit the @BugPattern annotation or the explanation in docs/bugpattern.
-->
# TimeZoneUsage
FragileCode
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
# TimeZoneUsage
__Derive the current time from an existing &#96;Clock&#96; Spring bean, and don&#39;t rely on a &#96;Clock&#96;&#39;s time zone__
<div style="float:right;"><table id="metadata">
<tr><td>Severity</td><td>WARNING</td></tr>
<tr><td>Tags</td><td>FragileCode</td></tr>
</table></div>
## Suppression
Suppress false positives by adding the suppression annotation `@SuppressWarnings("TimeZoneUsage")` to the enclosing element.

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@@ -231,11 +232,57 @@
<ignoredUnusedDeclaredDependencies>
<!-- XXX: Figure out why the plugin thinks this
dependency is unused. -->
<ignoredUnusedDeclaredDependency>${project.groupId}:refaster-support</ignoredUnusedDeclaredDependency>
<ignoredUnusedDeclaredDependency>${project.groupId}:refaster-support
</ignoredUnusedDeclaredDependency>
</ignoredUnusedDeclaredDependencies>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<!-- run annotation processor -->
<profile>
<id>run-annotation-processor</id>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>error_prone_docgen_processor</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<version>${version.auto-value}</version>
</path>
<path>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>${version.auto-service}</version>
</path>
<path>
<groupId>${project.groupId}</groupId>
<artifactId>error_prone_docgen_processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@@ -39,44 +39,15 @@ EOF
}
generate_bugpattern_docs() {
BUGPATTERNS=$(find error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns -type f -iname "*.java" ! -iname "package-info.java")
for BUGPATTERN in $BUGPATTERNS; do
NAME=$(basename "${BUGPATTERN}" ".java")
FILENAME="${BUGPATTERN_FOLDER}/${NAME}.md"
# The "mvn clean" is necessary since the wiki docs are generated by an
# annotation processor that also compiles the code. If Maven thinks the code
# does not need to be recompiled, the wiki docs will not be generated either.
mvn clean
EXTRA_DOCS=$(cat "${BUGPATTERN_DOCS_FOLDER}/${NAME}.md" 2>/dev/null)
# This will create markdown files for each bug pattern in `docgen/target/generated-wiki/bugpatterns`
mvn -P run-annotation-processor compile site -Dverification.skip
echo "Generating ${FILENAME}"
cat > "${FILENAME}" << EOF
---
layout: default
title: ${NAME}
parent: Bug Patterns
nav_order: 1
---
# ${NAME}
Simplification
{: .label .label-blue }
Suggestion
{: .label .label-yellow }
${EXTRA_DOCS}
## Samples
\`\`\`java
public static void sample() {}
\`\`\`
<a href="https://github.com/PicnicSupermarket/error-prone-support/blob/master/${BUGPATTERN}" class="fs-3 btn external" target="_blank">
View source code on GitHub
<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>
</a>
EOF
done
cp -R docgen/target/generated-wiki/bugpatterns/ website/
}
generate_refaster_docs() {

View File

@@ -39,6 +39,8 @@
</developers>
<modules>
<module>docgen</module>
<module>docgen_processor</module>
<module>error-prone-contrib</module>
<module>refaster-compiler</module>
<module>refaster-runner</module>

View File

@@ -1,3 +1,4 @@
source "https://rubygems.org"
gem "github-pages", "~> 227"
gem "rake", "~> 13.0" # Required for "just-the-docs" theme
gem "webrick", "~> 1.7"