Skip to content

Commit

Permalink
Get rid of all the old annotation processor code
Browse files Browse the repository at this point in the history
Also port some of the tests to the new infrastructure.
  • Loading branch information
gsmet committed Aug 6, 2024
1 parent ebbb6e1 commit ab0cee2
Show file tree
Hide file tree
Showing 38 changed files with 515 additions and 4,704 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
import io.quarkus.annotation.processor.documentation.config.model.Extension;
import io.quarkus.annotation.processor.documentation.config.util.Types;
import io.quarkus.annotation.processor.extension.ExtensionBuildProcessor;
import io.quarkus.annotation.processor.generate_doc.LegacyConfigDocExtensionProcessor;
import io.quarkus.annotation.processor.util.Config;
import io.quarkus.annotation.processor.util.Utils;

@SupportedOptions({ Options.LEGACY_CONFIG_ROOT, Options.GENERATE_DOC, Options.GENERATE_LEGACY_CONFIG_DOC })
@SupportedOptions({ Options.LEGACY_CONFIG_ROOT, Options.GENERATE_DOC })
public class ExtensionAnnotationProcessor extends AbstractProcessor {

private static final String DEBUG = "debug-extension-annotation-processor";
Expand All @@ -48,10 +47,6 @@ public synchronized void init(ProcessingEnvironment processingEnv) {
// for now, we generate the old config doc by default but we will change this behavior soon
if (generateDoc) {
extensionProcessors.add(new ConfigDocExtensionProcessor());

if (!"false".equals(processingEnv.getOptions().get(Options.GENERATE_LEGACY_CONFIG_DOC))) {
extensionProcessors.add(new LegacyConfigDocExtensionProcessor());
}
}

this.extensionProcessors = Collections.unmodifiableList(extensionProcessors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
public final class Options {

public static final String LEGACY_CONFIG_ROOT = "legacyConfigRoot";
public static final String GENERATE_LEGACY_CONFIG_DOC = "generateLegacyConfigDoc";
public static final String GENERATE_DOC = "generateDoc";
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.annotation.processor.documentation.config.discovery;

public record ParsedJavadocSection(String title, String description) {
public record ParsedJavadocSection(String title, String details) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public final class JavadocToAsciidocTransformer {
private static final Pattern REPLACE_MACOS_EOL = Pattern.compile("\r");
private static final Pattern STARTING_SPACE = Pattern.compile("^ +");

private static final String EMPTY = "";
private static final String DOT = ".";

private static final String BACKTICK = "`";
Expand Down Expand Up @@ -112,12 +111,16 @@ public ParsedJavadoc parseConfigItemJavadoc(String rawJavadoc) {
.map(JavadocDescription::toText)
.findFirst();

if (description != null && description.isBlank()) {
description = null;
}

return new ParsedJavadoc(description, since.isPresent() ? since.get() : null, originalFormat);
}

public ParsedJavadocSection parseConfigSectionJavadoc(String javadocComment) {
if (javadocComment == null || javadocComment.trim().isEmpty()) {
return new ParsedJavadocSection(EMPTY, EMPTY);
return new ParsedJavadocSection(null, null);
}

// the parser expects all the lines to start with "* "
Expand All @@ -133,19 +136,28 @@ public ParsedJavadocSection parseConfigSectionJavadoc(String javadocComment) {
}

if (asciidoc == null || asciidoc.isBlank()) {
return new ParsedJavadocSection(EMPTY, EMPTY);
return new ParsedJavadocSection(null, null);
}

final int newLineIndex = asciidoc.indexOf(NEW_LINE);
final int dotIndex = asciidoc.indexOf(DOT);

final int endOfTitleIndex;
if (newLineIndex > 0 && newLineIndex < dotIndex) {
endOfTitleIndex = newLineIndex;
} else {
endOfTitleIndex = dotIndex;
}

final int endOfTitleIndex = asciidoc.indexOf(DOT);
if (endOfTitleIndex == -1) {
final String title = asciidoc.replaceAll("^([^\\w])+", EMPTY).trim();
final String title = asciidoc.replaceAll("^([^\\w])+", "").trim();

return new ParsedJavadocSection(title, EMPTY);
return new ParsedJavadocSection(title, null);
} else {
final String title = asciidoc.substring(0, endOfTitleIndex).replaceAll("^([^\\w])+", EMPTY).trim();
final String title = asciidoc.substring(0, endOfTitleIndex).replaceAll("^([^\\w])+", "").trim();
final String details = asciidoc.substring(endOfTitleIndex + 1).trim();

return new ParsedJavadocSection(title, details);
return new ParsedJavadocSection(title, details.isBlank() ? null : details);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static String getRootPrefix(String prefix, String name, String simpleClas
return rootPrefix;
}

private static String deriveConfigRootName(String simpleClassName, String prefix, ConfigPhase configPhase) {
static String deriveConfigRootName(String simpleClassName, String prefix, ConfigPhase configPhase) {
String simpleNameInLowerCase = simpleClassName.toLowerCase();
int length = simpleNameInLowerCase.length();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

public final class JavadocUtil {

private static final String VERTX_JAVA_DOC_SITE = "https://vertx.io/docs/apidocs/";
private static final String OFFICIAL_JAVA_DOC_BASE_LINK = "https://docs.oracle.com/en/java/javase/17/docs/api/";
private static final String AGROAL_API_JAVA_DOC_SITE = "https://javadoc.io/doc/io.agroal/agroal-api/latest/";
private static final String LOG_LEVEL_REDIRECT_URL = "https://javadoc.io/doc/org.jboss.logmanager/jboss-logmanager/latest/org/jboss/logmanager/Level.html";
static final String VERTX_JAVA_DOC_SITE = "https://vertx.io/docs/apidocs/";
static final String OFFICIAL_JAVA_DOC_BASE_LINK = "https://docs.oracle.com/en/java/javase/17/docs/api/";
static final String AGROAL_API_JAVA_DOC_SITE = "https://javadoc.io/doc/io.agroal/agroal-api/latest/";
static final String LOG_LEVEL_REDIRECT_URL = "https://javadoc.io/doc/org.jboss.logmanager/jboss-logmanager/latest/org/jboss/logmanager/Level.html";

private static final Pattern PACKAGE_PATTERN = Pattern.compile("^(\\w+)\\.(\\w+)\\..*$");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import io.quarkus.annotation.processor.ExtensionProcessor;
import io.quarkus.annotation.processor.Outputs;
import io.quarkus.annotation.processor.documentation.config.util.Types;
import io.quarkus.annotation.processor.generate_doc.Constants;
import io.quarkus.annotation.processor.util.Config;
import io.quarkus.annotation.processor.util.Utils;

Expand Down Expand Up @@ -51,15 +50,15 @@ public void process(Set<? extends TypeElement> annotations, RoundEnvironment rou
processBuildStep(roundEnv, annotation);
break;
case Types.ANNOTATION_RECORDER:
trackAnnotationUsed(Constants.ANNOTATION_RECORDER);
trackAnnotationUsed(Types.ANNOTATION_RECORDER);
processRecorder(roundEnv, annotation);
break;
case Types.ANNOTATION_CONFIG_ROOT:
trackAnnotationUsed(Constants.ANNOTATION_CONFIG_ROOT);
trackAnnotationUsed(Types.ANNOTATION_CONFIG_ROOT);
processConfigRoot(roundEnv, annotation);
break;
case Types.ANNOTATION_CONFIG_GROUP:
trackAnnotationUsed(Constants.ANNOTATION_CONFIG_GROUP);
trackAnnotationUsed(Types.ANNOTATION_CONFIG_GROUP);
processConfigGroup(roundEnv, annotation);
break;
}
Expand Down Expand Up @@ -103,10 +102,10 @@ private void validateRecordBuildSteps(TypeElement clazz) {
continue;
}
ExecutableElement ex = (ExecutableElement) e;
if (!utils.element().isAnnotationPresent(ex, Constants.ANNOTATION_BUILD_STEP)) {
if (!utils.element().isAnnotationPresent(ex, Types.ANNOTATION_BUILD_STEP)) {
continue;
}
if (!utils.element().isAnnotationPresent(ex, Constants.ANNOTATION_RECORD)) {
if (!utils.element().isAnnotationPresent(ex, Types.ANNOTATION_RECORD)) {
continue;
}

Expand All @@ -118,7 +117,7 @@ private void validateRecordBuildSteps(TypeElement clazz) {
if (parameterTypeElement == null) {
allTypesResolvable = false;
} else {
if (utils.element().isAnnotationPresent(parameterTypeElement, Constants.ANNOTATION_RECORDER)) {
if (utils.element().isAnnotationPresent(parameterTypeElement, Types.ANNOTATION_RECORDER)) {
if (parameterTypeElement.getModifiers().contains(Modifier.FINAL)) {
utils.processingEnv().getMessager().printMessage(Diagnostic.Kind.ERROR,
"Class '" + parameterTypeElement.getQualifiedName()
Expand Down Expand Up @@ -176,7 +175,7 @@ private void processConfigGroup(RoundEnvironment roundEnv, TypeElement annotatio
}

private void validateAnnotationUsage() {
if (isAnnotationUsed(Constants.ANNOTATION_BUILD_STEP) && isAnnotationUsed(Constants.ANNOTATION_RECORDER)) {
if (isAnnotationUsed(Types.ANNOTATION_BUILD_STEP) && isAnnotationUsed(Types.ANNOTATION_RECORDER)) {
utils.processingEnv().getMessager().printMessage(Diagnostic.Kind.ERROR,
"Detected use of @Recorder annotation in 'deployment' module. Classes annotated with @Recorder must be part of the extension's 'runtime' module");
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit ab0cee2

Please sign in to comment.