Skip to content

Commit 2d1d222

Browse files
authored
add compile warning for http valid (#672)
1 parent 53aabd2 commit 2d1d222

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

http-generator-core/src/main/java/io/avaje/http/generator/core/BaseProcessor.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import javax.annotation.processing.SupportedOptions;
2020
import javax.lang.model.SourceVersion;
2121
import javax.lang.model.element.Element;
22-
import javax.lang.model.element.ExecutableElement;
2322
import javax.lang.model.element.Modifier;
2423
import javax.lang.model.element.TypeElement;
2524
import javax.lang.model.util.ElementFilter;
@@ -54,11 +53,12 @@ public SourceVersion getSupportedSourceVersion() {
5453
@Override
5554
public Set<String> getSupportedAnnotationTypes() {
5655
return Set.of(
57-
PathPrism.PRISM_TYPE,
58-
ControllerPrism.PRISM_TYPE,
59-
OpenAPIDefinitionPrism.PRISM_TYPE,
60-
MappedParamPrism.PRISM_TYPE,
61-
MapImportPrism.PRISM_TYPE);
56+
PathPrism.PRISM_TYPE,
57+
ControllerPrism.PRISM_TYPE,
58+
OpenAPIDefinitionPrism.PRISM_TYPE,
59+
MappedParamPrism.PRISM_TYPE,
60+
MapImportPrism.PRISM_TYPE,
61+
HttpValidPrism.PRISM_TYPE);
6262
}
6363

6464
@Override
@@ -91,7 +91,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
9191
if (round.errorRaised()) {
9292
return false;
9393
}
94-
94+
getElements(round, HttpValidPrism.PRISM_TYPE).forEach(this::warnValid);
9595
for (final var type : ElementFilter.typesIn(getElements(round, MappedParamPrism.PRISM_TYPE))) {
9696
var prism = MappedParamPrism.getInstanceOn(type);
9797
registerParamMapping(type, prism.factoryMethod());
@@ -148,6 +148,12 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
148148
return false;
149149
}
150150

151+
private void warnValid(Element e) {
152+
if (!ControllerPrism.isPresent(e) && !ControllerPrism.isPresent(e.getEnclosingElement())) {
153+
logWarn(e, "%s should only be used in Controller Classes", HttpValidPrism.PRISM_TYPE);
154+
}
155+
}
156+
151157
private Set<? extends Element> getElements(RoundEnvironment round, String name) {
152158
return Optional.ofNullable(typeElement(name))
153159
.map(round::getElementsAnnotatedWith)

0 commit comments

Comments
 (0)