Skip to content

Commit

Permalink
Update Dagger's XProcessing jars.
Browse files Browse the repository at this point in the history
The changes in the latest jars fix a couple of behavioral issues in XProcessing, so I've updated Dagger to reflect those fixes.

RELNOTES=N/A
PiperOrigin-RevId: 487289040
  • Loading branch information
bcorso authored and Dagger Team committed Nov 9, 2022
1 parent 127df43 commit 776f877
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 33 deletions.
24 changes: 3 additions & 21 deletions java/dagger/internal/codegen/base/DaggerSuperficialValidation.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import com.google.common.collect.ImmutableList;
import com.google.devtools.ksp.symbol.ClassKind;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.TypeName;
import dagger.Reusable;
import dagger.internal.codegen.compileroption.CompilerOptions;
import dagger.internal.codegen.xprocessing.XAnnotationValues;
Expand All @@ -68,10 +67,8 @@
import dagger.internal.codegen.xprocessing.XTypes;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import javax.inject.Inject;

/**
Expand Down Expand Up @@ -315,23 +312,9 @@ private void validateType(String desc, XType type) {
// "$" even after the type has been resolved. Thus, we try to resolve the type as early as
// possible to prevent using/caching the incorrect TypeName.
XTypes.resolveIfNeeded(type);
validateTypeInternal(desc, type, new HashSet<>());
}

private void validateTypeInternal(String desc, XType type, Set<TypeName> visitedTypeNames) {
checkNotNull(type);
try {
// TODO(b/247846778): Due to a bug in XProcessing, KSP typenames sometimes incorrectly have
// recursive types, e.g. a wildcard type of `? extends Foo` will have a bounds of
// `? extends Foo` instead of `Foo`, leading to infinite loops. Thus, we skip validation if
// the type name has already been validated for the given type. This condition can be removed
// once the corresponding bug is fixed.
if (processingEnv.getBackend() == Backend.KSP && !visitedTypeNames.add(type.getTypeName())) {
return;
}
if (isArray(type)) {
validateTypeInternal(
"array component type", asArray(type).getComponentType(), visitedTypeNames);
validateType("array component type", asArray(type).getComponentType());
} else if (isDeclared(type)) {
if (isStrictValidationEnabled) {
// There's a bug in TypeVisitor which will visit the visitDeclared() method rather than
Expand All @@ -341,11 +324,10 @@ private void validateTypeInternal(String desc, XType type, Set<TypeName> visited
throw new ValidationException.KnownErrorType(type);
}
}
type.getTypeArguments()
.forEach(typeArg -> validateTypeInternal("type argument", typeArg, visitedTypeNames));
type.getTypeArguments().forEach(typeArg -> validateType("type argument", typeArg));
} else if (isWildcard(type)) {
if (type.extendsBound() != null) {
validateTypeInternal("extends bound type", type.extendsBound(), visitedTypeNames);
validateType("extends bound type", type.extendsBound());
}
} else if (isErrorKind(type)) {
throw new ValidationException.KnownErrorType(type);
Expand Down
2 changes: 1 addition & 1 deletion java/dagger/internal/codegen/xprocessing/JavaPoetExt.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static TypeSpec.Builder avoidClashesWithNestedClasses(
.getEnclosedTypeElements()
.forEach(nestedTypeElement -> builder.alwaysQualify(getSimpleName(nestedTypeElement)));

typeElement.getSuperTypes().stream()
typeElement.getType().getSuperTypes().stream()
.filter(XTypes::isDeclared)
.map(XType::getTypeElement)
.forEach(superType -> avoidClashesWithNestedClasses(builder, superType));
Expand Down
Binary file modified java/dagger/internal/codegen/xprocessing/xprocessing.jar
Binary file not shown.
12 changes: 4 additions & 8 deletions javatests/dagger/internal/codegen/BindsMethodValidationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,9 @@ public void bindsMissingTypeInParameterHierarchy() {
+ "\n => element (METHOD): bindObject(test.Child<java.lang.String>)"
+ "\n => element (PARAMETER): child"
+ "\n => type (DECLARED parameter): test.Child<java.lang.String>"
+ "\n => type (DECLARED supertype): test.Parent<%2$s>"
+ "\n => type (DECLARED supertype): test.Parent<java.lang.String>"
+ "\n => type (ERROR supertype): %1$s",
isJavac ? "MissingType" : "error.NonExistentClass",
// TODO(b/249816631): KSP returns unresolved supertypes.
isJavac ? "java.lang.String" : "T"));
isJavac ? "MissingType" : "error.NonExistentClass"));
});
}

Expand Down Expand Up @@ -274,11 +272,9 @@ public void bindsMissingTypeInReturnTypeHierarchy() {
+ "\n => element (INTERFACE): test.TestModule"
+ "\n => element (METHOD): bindChild(java.lang.String)"
+ "\n => type (DECLARED return type): test.Child<java.lang.String>"
+ "\n => type (DECLARED supertype): test.Parent<%2$s>"
+ "\n => type (DECLARED supertype): test.Parent<java.lang.String>"
+ "\n => type (ERROR supertype): %1$s",
isJavac ? "MissingType" : "error.NonExistentClass",
// TODO(b/249816631): KSP returns unresolved supertypes.
isJavac ? "java.lang.String" : "T"));
isJavac ? "MissingType" : "error.NonExistentClass"));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,10 +554,8 @@ void runAssertions(
" => element (METHOD): getChild()",
" => type (DECLARED return type): "
+ "test.Outer.Child<java.lang.Long>",
" => type (DECLARED supertype): test.Outer.Parent<%s>",
" => type (DECLARED supertype): test.Outer.Parent<java.lang.Long>",
" => type (ERROR supertype): %s"),
// TODO(b/249816631): KSP returns unresolved supertypes.
isJavac ? "java.lang.Long" : "T",
isJavac ? "MissingType<T>" : "error.NonExistentClass"));
}
})
Expand Down

0 comments on commit 776f877

Please sign in to comment.