Skip to content

Commit

Permalink
Rollback since this was an unintended effect on the deps of the release.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 353057330
  • Loading branch information
Chang-Eric authored and Dagger Team committed Jan 21, 2021
1 parent 7caf468 commit 850274b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 28 deletions.
8 changes: 4 additions & 4 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ maven_install(
artifacts = [
"androidx.annotation:annotation:1.1.0",
"androidx.appcompat:appcompat:1.2.0",
"androidx.activity:activity:1.2.0-rc01",
"androidx.fragment:fragment:1.3.0-rc01",
"androidx.lifecycle:lifecycle-viewmodel:2.3.0-rc01",
"androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.0-rc01",
"androidx.activity:activity:1.1.0",
"androidx.fragment:fragment:1.2.5",
"androidx.lifecycle:lifecycle-viewmodel:2.2.0",
"androidx.lifecycle:lifecycle-viewmodel-savedstate:2.2.0",
"androidx.multidex:multidex:2.0.1",
"androidx.savedstate:savedstate:1.0.0",
"androidx.test:monitor:1.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

/** Generates an Hilt Activity class for the @AndroidEntryPoint annotated class. */
public final class ActivityGenerator {

private final ProcessingEnvironment env;
private final AndroidEntryPointMetadata metadata;
private final ClassName generatedClassName;
Expand All @@ -51,14 +50,12 @@ public void generate() throws IOException {
TypeSpec.classBuilder(generatedClassName.simpleName())
.addOriginatingElement(metadata.element())
.superclass(metadata.baseClassName())
.addModifiers(metadata.generatedClassModifiers());
.addModifiers(metadata.generatedClassModifiers())
.addMethod(onCreate());

Generators.addGeneratedBaseClassJavadoc(builder, AndroidClassNames.ANDROID_ENTRY_POINT);
Processors.addGeneratedAnnotation(builder, env, getClass());

Generators.copyConstructors(metadata.baseElement(), builder);
builder.addMethod(onCreate());

Generators.copyConstructors(metadata.baseElement(), builder);

metadata.baseElement().getTypeParameters().stream()
.map(TypeVariableName::get)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,22 @@ static void addGeneratedBaseClassJavadoc(TypeSpec.Builder builder, ClassName ann
}

/**
* Copies all constructors with arguments to the builder.
* Copies all constructors with arguments to the builder, if the base class is abstract.
* Otherwise throws an exception.
*/
static void copyConstructors(TypeElement baseClass, TypeSpec.Builder builder) {
copyConstructors(baseClass, CodeBlock.builder().build(), builder);
}

/**
* Copies all constructors with arguments along with an appended body to the builder.
*/
static void copyConstructors(TypeElement baseClass, CodeBlock body, TypeSpec.Builder builder) {
List<ExecutableElement> constructors =
ElementFilter.constructorsIn(baseClass.getEnclosedElements())
.stream()
.filter(constructor -> !constructor.getModifiers().contains(PRIVATE))
.collect(Collectors.toList());

if (constructors.size() == 1
&& getOnlyElement(constructors).getParameters().isEmpty()
&& body.isEmpty()) {
if (constructors.size() == 1 && getOnlyElement(constructors).getParameters().isEmpty()) {
// No need to copy the constructor if the default constructor will handle it.
return;
}

constructors.forEach(constructor -> builder.addMethod(copyConstructor(constructor, body)));
constructors.forEach(constructor -> builder.addMethod(copyConstructor(constructor)));
}

/** Returns Optional with AnnotationSpec for Nullable if found on element, empty otherwise. */
Expand Down Expand Up @@ -117,10 +109,6 @@ private static ParameterSpec getParameterSpecWithNullable(VariableElement parame
// super(param1, param2);
// }
static MethodSpec copyConstructor(ExecutableElement constructor) {
return copyConstructor(constructor, CodeBlock.builder().build());
}

private static MethodSpec copyConstructor(ExecutableElement constructor, CodeBlock body) {
List<ParameterSpec> params =
constructor.getParameters().stream()
.map(parameter -> getParameterSpecWithNullable(parameter))
Expand All @@ -131,8 +119,7 @@ private static MethodSpec copyConstructor(ExecutableElement constructor, CodeBlo
.addParameters(params)
.addStatement(
"super($L)",
params.stream().map(param -> param.name).collect(Collectors.joining(", ")))
.addCode(body);
params.stream().map(param -> param.name).collect(Collectors.joining(", ")));

constructor.getAnnotationMirrors().stream()
.filter(a -> Processors.hasAnnotation(a, AndroidClassNames.TARGET_API))
Expand Down

0 comments on commit 850274b

Please sign in to comment.