mirror of
https://github.com/jlengrand/error-prone-support.git
synced 2026-03-10 08:11:25 +00:00
Introduce RefasterTemplateCollectionData and other improvements
This commit is contained in:
committed by
Pieter Dirk Soels
parent
4ff7dadcc3
commit
af9f3f7ff6
@@ -5,6 +5,7 @@ import static com.google.errorprone.matchers.Matchers.hasAnnotation;
|
||||
import static com.google.errorprone.matchers.Matchers.instanceMethod;
|
||||
|
||||
import com.google.errorprone.VisitorState;
|
||||
import com.google.errorprone.annotations.Var;
|
||||
import com.google.errorprone.matchers.Matcher;
|
||||
import com.google.errorprone.util.ASTHelpers;
|
||||
import com.sun.source.tree.ClassTree;
|
||||
@@ -21,7 +22,7 @@ import tech.picnic.errorprone.plugin.models.BugPatternTestData;
|
||||
/** XXX: Write this. */
|
||||
// XXX: Take into account `expectUnchanged()`.
|
||||
public final class BugPatternTestsExtractor implements DocExtractor<BugPatternTestData> {
|
||||
private static final Matcher<MethodTree> BUG_PATTERN_TEST =
|
||||
private static final Matcher<MethodTree> JUNIT_TEST_METHOD =
|
||||
allOf(hasAnnotation("org.junit.jupiter.api.Test"));
|
||||
private static final Matcher<ExpressionTree> IDENTIFICATION_SOURCE_LINES =
|
||||
instanceMethod()
|
||||
@@ -44,7 +45,7 @@ public final class BugPatternTestsExtractor implements DocExtractor<BugPatternTe
|
||||
tree.getMembers().stream()
|
||||
.filter(MethodTree.class::isInstance)
|
||||
.map(MethodTree.class::cast)
|
||||
.filter(m -> BUG_PATTERN_TEST.matches(m, state))
|
||||
.filter(m -> JUNIT_TEST_METHOD.matches(m, state))
|
||||
.forEach(m -> scanner.scan(m, null));
|
||||
|
||||
return BugPatternTestData.create(
|
||||
@@ -53,11 +54,11 @@ public final class BugPatternTestsExtractor implements DocExtractor<BugPatternTe
|
||||
|
||||
private static final class ScanBugCheckerTestData extends TreeScanner<Void, Void> {
|
||||
private final VisitorState state;
|
||||
|
||||
private final List<String> identificationTests = new ArrayList<>();
|
||||
private final List<BugPatternReplacementTestData> replacementTests = new ArrayList<>();
|
||||
|
||||
// XXX: Using this output field is a bit hacky. Come up with a better solution.
|
||||
private String output;
|
||||
@Var private String output;
|
||||
|
||||
ScanBugCheckerTestData(VisitorState state) {
|
||||
this.state = state;
|
||||
|
||||
@@ -3,22 +3,23 @@ package tech.picnic.errorprone.plugin;
|
||||
public enum DocType {
|
||||
BUG_PATTERN("bug-pattern", new BugPatternExtractor()),
|
||||
BUG_PATTERN_TEST("bug-pattern-test", new BugPatternTestsExtractor()),
|
||||
// REFASTER("refaster", new RefasterExtractor()),
|
||||
REFASTER_TEMPLATE_TEST_INPUT("refaster-test-input", new RefasterTestExtractor()),
|
||||
REFASTER_TEMPLATE_TEST_OUTPUT("refaster-test-output", new RefasterTestExtractor());
|
||||
|
||||
private final String outputFileNamePrefix;
|
||||
private final DocExtractor<?> extractor;
|
||||
private final DocExtractor<?> docExtractor;
|
||||
|
||||
DocType(String outputFileNamePrefix, DocExtractor<?> extractor) {
|
||||
DocType(String outputFileNamePrefix, DocExtractor<?> docExtractor) {
|
||||
this.outputFileNamePrefix = outputFileNamePrefix;
|
||||
this.extractor = extractor;
|
||||
this.docExtractor = docExtractor;
|
||||
}
|
||||
|
||||
public String getOutputFileNamePrefix() {
|
||||
return outputFileNamePrefix;
|
||||
}
|
||||
|
||||
public DocExtractor<?> getExtractor() {
|
||||
return extractor;
|
||||
public DocExtractor<?> getDocExtractor() {
|
||||
return docExtractor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ final class DocgenTaskListener implements TaskListener {
|
||||
this.basePath = path.substring(path.indexOf('=') + 1) + "/docs";
|
||||
this.state = VisitorState.createForUtilityPurposes(context);
|
||||
|
||||
// XXX: Move this somewhere else?
|
||||
try {
|
||||
Files.createDirectories(Paths.get(basePath));
|
||||
} catch (IOException e) {
|
||||
@@ -66,7 +67,7 @@ final class DocgenTaskListener implements TaskListener {
|
||||
.ifPresent(
|
||||
docType ->
|
||||
writeToFile(
|
||||
docType.getExtractor().extractData(tree, taskEvent, state),
|
||||
docType.getDocExtractor().extractData(tree, taskEvent, state),
|
||||
docType.getOutputFileNamePrefix(),
|
||||
getSimpleClassName(sourceFile.getName())));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package tech.picnic.errorprone.plugin.models;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Object containing all data related to a Refaster template collection. This is solely used for
|
||||
* serialization.
|
||||
*/
|
||||
@AutoValue
|
||||
public abstract class RefasterTemplateCollectionData {
|
||||
public static RefasterTemplateCollectionData create(
|
||||
String name, String description, String link, List<RefasterTemplateData> templates) {
|
||||
return new AutoValue_RefasterTemplateCollectionData(name, description, link, templates);
|
||||
}
|
||||
|
||||
abstract String name();
|
||||
|
||||
abstract String description();
|
||||
|
||||
abstract String link();
|
||||
|
||||
abstract List<RefasterTemplateData> templates();
|
||||
}
|
||||
Reference in New Issue
Block a user