Skip to content

Commit

Permalink
Migrate from soon-to-be-deprecated propagateIfPossible to equivalen…
Browse files Browse the repository at this point in the history
…t `throwIfInstanceOf` and `throwIfUnchecked` calls.

This migration makes clearer that the existing call is not doing much, so I've simplified further from there.

RELNOTES=n/a
PiperOrigin-RevId: 613322217
  • Loading branch information
cpovirk authored and Dagger Team committed Mar 6, 2024
1 parent 922ff50 commit 3fa9a8a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 26 deletions.
23 changes: 4 additions & 19 deletions java/dagger/internal/codegen/base/SourceFileGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import androidx.room.compiler.processing.XFiler;
import androidx.room.compiler.processing.XMessager;
import androidx.room.compiler.processing.XProcessingEnv;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.squareup.javapoet.AnnotationSpec;
Expand Down Expand Up @@ -61,29 +60,15 @@ public SourceFileGenerator(SourceFileGenerator<T> delegate) {
this(delegate.filer, delegate.processingEnv);
}

/**
* Generates a source file to be compiled for {@code T}. Writes any generation exception to {@code
* messager} and does not throw.
*/
/** Generates a source file to be compiled for {@code T}. */
public void generate(T input, XMessager messager) {
try {
generate(input);
} catch (SourceFileGenerationException e) {
e.printMessageTo(messager);
}
generate(input);
}

/** Generates a source file to be compiled for {@code T}. */
public void generate(T input) throws SourceFileGenerationException {
public void generate(T input) {
for (TypeSpec.Builder type : topLevelTypes(input)) {
try {
filer.write(buildJavaFile(input, type), XFiler.Mode.Isolating);
} catch (RuntimeException e) {
// if the code above threw a SFGE, use that
Throwables.propagateIfPossible(e, SourceFileGenerationException.class);
// otherwise, throw a new one
throw new SourceFileGenerationException(Optional.empty(), e, originatingElement(input));
}
filer.write(buildJavaFile(input, type), XFiler.Mode.Isolating);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import com.squareup.javapoet.ParameterizedTypeName;
import com.squareup.javapoet.TypeName;
import com.squareup.javapoet.TypeSpec;
import dagger.internal.codegen.base.SourceFileGenerationException;
import dagger.internal.codegen.base.SourceFileGenerator;
import dagger.internal.codegen.binding.AssistedInjectionAnnotations;
import dagger.internal.codegen.binding.AssistedInjectionAnnotations.AssistedFactoryMetadata;
Expand Down Expand Up @@ -110,12 +109,8 @@ protected void process(XTypeElement factory, ImmutableSet<ClassName> annotations
ValidationReport report = new AssistedFactoryValidator().validate(factory);
report.printMessagesTo(messager);
if (report.isClean()) {
try {
ProvisionBinding binding = bindingFactory.assistedFactoryBinding(factory, Optional.empty());
new AssistedFactoryImplGenerator().generate(binding);
} catch (SourceFileGenerationException e) {
e.printMessageTo(messager);
}
ProvisionBinding binding = bindingFactory.assistedFactoryBinding(factory, Optional.empty());
new AssistedFactoryImplGenerator().generate(binding);
}
}

Expand Down

0 comments on commit 3fa9a8a

Please sign in to comment.