Skip to content

Fix BeanParam imports #209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public ServerContext(Object request, Object response) {
* @return The request
*/
@SuppressWarnings("unchecked")
<T> T request() {
public <T> T request() {
return (T) request;
}

Expand All @@ -29,7 +29,7 @@ <T> T request() {
* @return The request
*/
@SuppressWarnings("unchecked")
<T> T response() {
public <T> T response() {
return (T) response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class BeanParamReader {
private final Map<String, FieldReader> fieldMap = new LinkedHashMap<>();
private final List<ExecutableElement> constructors = new ArrayList<>();
private final Map<String, ExecutableElement> methodMap = new LinkedHashMap<>();
private final Set<String> imports = new HashSet<>();

public BeanParamReader(TypeElement beanType, String beanVarName, String beanShortType, ParamType defaultParamType) {
this.beanType = beanType;
Expand All @@ -23,6 +24,10 @@ public BeanParamReader(TypeElement beanType, String beanVarName, String beanShor
read();
}

public Collection<String> imports() {
return imports;
}

private void read() {
for (Element enclosedElement : beanType.getEnclosedElements()) {
switch (enclosedElement.getKind()) {
Expand All @@ -45,6 +50,8 @@ private void readField(Element enclosedElement) {
}
FieldReader field = new FieldReader(enclosedElement, defaultParamType);
fieldMap.put(field.varName(), field);

imports.addAll(UType.parse(field.element.element().asType()).importTypes());
}

private void readMethod(ExecutableElement enclosedElement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ public class ElementReader {
paramType = ParamType.CONTEXT;
useValidation = false;
}
if (ParamType.FORM == paramType || ParamType.BEANPARAM == paramType) {
beanParamImports(rawType);
}
}

private void beanParamImports(String rawType) {
typeElement(rawType).getEnclosedElements().stream()
.filter(e -> e.getKind() == ElementKind.FIELD)
.filter(f -> !IgnorePrism.isPresent(f))
.map(Element::asType)
.map(UType::parse)
.flatMap(u -> u.importTypes().stream())
.forEach(imports::add);
}

TypeHandler initTypeHandler() {
Expand Down