Skip to content
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

Document assumptions about types of current processing round #7072

Merged
merged 1 commit into from
Jun 25, 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 @@ -168,8 +168,13 @@ private static boolean correctType(TypeName knownType, TypeName processingType)
if (processingType.packageName().isEmpty()) {
if (processingType.className().equals("<any>")) {
// cannot be resolved as this is part of our round, good faith it is a correct parameter
// this type name is used for types that are part of this round and that have a generic declaration
// such as BuilderBase<?, ?>, also compilation will fail with a correct exception if the type is wrong
// it will just fail on the generated class
return true;
}
// the type name is known, but package could not be determined as the type is generated as part of this
// annotation processing round - if the class name is correct, assume we have the right type
return knownType.className().equals(processingType.className())
&& knownType.enclosingNames().equals(processingType.enclosingNames());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,10 @@ static FactoryMethods create(ProcessingContext processingContext,

return new FactoryMethods(targetFactory,
configFactory,
builder(processingContext, blueprint, typeHandler, configObjectCandidates));
builder(processingContext, typeHandler, configObjectCandidates));
}

private static Optional<FactoryMethod> builder(ProcessingContext processingContext,
TypeInfo blueprint,
TypeHandler typeHandler,
Set<TypeName> builderCandidates) {
if (typeHandler.actualType().equals(OBJECT)) {
Expand All @@ -92,7 +91,6 @@ private static Optional<FactoryMethod> builder(ProcessingContext processingConte
for (TypeName builderCandidate : builderCandidates) {
if (typeHandler.actualType().primitive()) {
// primitive methods do not have builders
found = null;
continue;
}
TypeInfo typeInfo = processingContext.toTypeInfo(builderCandidate.genericTypeName()).orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ public static Optional<TypeName> createTypeName(TypeMirror typeMirror) {
case TYPEVAR -> {
return Optional.of(createFromGenericDeclaration(typeMirror.toString()));
}
case WILDCARD -> {
case WILDCARD, ERROR -> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we have a unit test for these returns?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get a TypeMirror instance in a unit test? These methods did not have unit tests before, so I guess you investigated this?

return Optional.of(TypeName.create(typeMirror.toString()));
}
// this is most likely a type that is code generated as part of this round, best effort
case NONE -> {
return Optional.empty();
}
Expand Down