Skip to content

Commit

Permalink
Small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Chessray committed Jan 2, 2024
1 parent 35a9174 commit 729269b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public boolean process(
}

private void writeDelegatingConverterFile(final DelegatingConverterDescriptor descriptor) {
try (final Writer outputWriter = openSourceFile(descriptor.getConverterClassName())) {
try (final Writer outputWriter = openSourceFile(descriptor::getConverterClassName)) {
delegatingConverterGenerator.writeGeneratedCodeToOutput(descriptor, outputWriter);
} catch (IOException e) {
processingEnv
Expand Down Expand Up @@ -318,22 +318,22 @@ private void writeOutputFile(

private Writer openConverterRegistrationConfigurationFile(
final ConversionServiceAdapterDescriptor descriptor) throws IOException {
return openSourceFile(descriptor.getConverterRegistrationConfigurationClassName());
return openSourceFile(descriptor::getConverterRegistrationConfigurationClassName);
}

private Writer openConverterScanFile(final ConversionServiceAdapterDescriptor descriptor)
throws IOException {
return openSourceFile(descriptor.getConverterScanClassName());
return openSourceFile(descriptor::getConverterScanClassName);
}

private Writer openConverterScansFile(final ConversionServiceAdapterDescriptor descriptor)
throws IOException {
return openSourceFile(descriptor.getConverterScansClassName());
return openSourceFile(descriptor::getConverterScansClassName);
}

private Writer openAdapterFile(final ConversionServiceAdapterDescriptor descriptor)
throws IOException {
return openSourceFile(descriptor.getAdapterClassName());
return openSourceFile(descriptor::getAdapterClassName);
}

private ClassName getAdapterClassName(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.IOException;
import java.io.Writer;
import java.util.List;
import java.util.function.Supplier;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.SourceVersion;
Expand All @@ -27,7 +28,7 @@ public final SourceVersion getSupportedSourceVersion() {
return SourceVersion.latestSupported();
}

protected final Writer openSourceFile(final ClassName className) throws IOException {
return processingEnv.getFiler().createSourceFile(className.canonicalName()).openWriter();
protected final Writer openSourceFile(final Supplier<ClassName> classNameSupplier) throws IOException {
return processingEnv.getFiler().createSourceFile(classNameSupplier.get().canonicalName()).openWriter();
}
}

0 comments on commit 729269b

Please sign in to comment.