diff --git a/http-generator-core/src/main/java/io/avaje/http/generator/core/BaseProcessor.java b/http-generator-core/src/main/java/io/avaje/http/generator/core/BaseProcessor.java index 3cb1e347..9ead2db8 100644 --- a/http-generator-core/src/main/java/io/avaje/http/generator/core/BaseProcessor.java +++ b/http-generator-core/src/main/java/io/avaje/http/generator/core/BaseProcessor.java @@ -19,7 +19,6 @@ import javax.annotation.processing.SupportedOptions; import javax.lang.model.SourceVersion; import javax.lang.model.element.Element; -import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; import javax.lang.model.element.TypeElement; import javax.lang.model.util.ElementFilter; @@ -54,11 +53,12 @@ public SourceVersion getSupportedSourceVersion() { @Override public Set getSupportedAnnotationTypes() { return Set.of( - PathPrism.PRISM_TYPE, - ControllerPrism.PRISM_TYPE, - OpenAPIDefinitionPrism.PRISM_TYPE, - MappedParamPrism.PRISM_TYPE, - MapImportPrism.PRISM_TYPE); + PathPrism.PRISM_TYPE, + ControllerPrism.PRISM_TYPE, + OpenAPIDefinitionPrism.PRISM_TYPE, + MappedParamPrism.PRISM_TYPE, + MapImportPrism.PRISM_TYPE, + HttpValidPrism.PRISM_TYPE); } @Override @@ -91,7 +91,7 @@ public boolean process(Set annotations, RoundEnvironment if (round.errorRaised()) { return false; } - + getElements(round, HttpValidPrism.PRISM_TYPE).forEach(this::warnValid); for (final var type : ElementFilter.typesIn(getElements(round, MappedParamPrism.PRISM_TYPE))) { var prism = MappedParamPrism.getInstanceOn(type); registerParamMapping(type, prism.factoryMethod()); @@ -148,6 +148,12 @@ public boolean process(Set annotations, RoundEnvironment return false; } + private void warnValid(Element e) { + if (!ControllerPrism.isPresent(e) && !ControllerPrism.isPresent(e.getEnclosingElement())) { + logWarn(e, "%s should only be used in Controller Classes", HttpValidPrism.PRISM_TYPE); + } + } + private Set getElements(RoundEnvironment round, String name) { return Optional.ofNullable(typeElement(name)) .map(round::getElementsAnnotatedWith)