Skip to content

Commit 38ef8eb

Browse files
committed
refactor: minor refactor in processor
1 parent eb8ae32 commit 38ef8eb

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

core/flamingock-processor/src/main/java/io/flamingock/core/processor/FlamingockAnnotationProcessor.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import java.util.HashSet;
4949
import java.util.List;
5050
import java.util.Map;
51+
import java.util.Optional;
5152
import java.util.Set;
5253

5354
/**
@@ -197,7 +198,8 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
197198
}
198199

199200
AnnotationFinder annotationFinder = new AnnotationFinder(roundEnv, logger);
200-
EnableFlamingock flamingockAnnotation = annotationFinder.getPipelineAnnotation();
201+
EnableFlamingock flamingockAnnotation = annotationFinder.getPipelineAnnotation()
202+
.orElseThrow(() -> new RuntimeException("@EnableFlamingock annotation is mandatory. Please annotate a class with @EnableFlamingock to configure the pipeline."));
201203
PreviewPipeline pipeline = getPipelineFromProcessChanges(
202204
annotationFinder.getCodedChangesMapByPackage(),
203205
flamingockAnnotation
@@ -216,26 +218,11 @@ private PreviewPipeline getPipelineFromProcessChanges(Map<String, List<AbstractP
216218
codedChangesByPackage = new HashMap<>();
217219
}
218220

219-
if (pipelineAnnotation == null) {
220-
throw new RuntimeException("@EnableFlamingock annotation is mandatory. Please annotate a class with @EnableFlamingock to configure the pipeline.");
221-
}
222-
223221
boolean hasFileInAnnotation = !pipelineAnnotation.configFile().isEmpty();
224222
boolean hasStagesInAnnotation = pipelineAnnotation.stages().length > 0;
225223

226224
// Validate mutually exclusive modes
227-
if (hasFileInAnnotation && hasStagesInAnnotation) {
228-
throw new RuntimeException("@EnableFlamingock annotation cannot have both configFile and stages configured. Choose one: either specify configFile OR stages.");
229-
}
230-
231-
if (!hasFileInAnnotation && !hasStagesInAnnotation) {
232-
throw new RuntimeException("@EnableFlamingock annotation must specify either configFile OR stages configuration.");
233-
}
234-
235-
// Validate stage type restrictions when using annotation-based configuration
236-
if (hasStagesInAnnotation) {
237-
validateStageTypes(pipelineAnnotation.stages());
238-
}
225+
validateConfiguration(pipelineAnnotation, hasFileInAnnotation, hasStagesInAnnotation);
239226

240227
if (hasFileInAnnotation) {
241228
logger.info("Reading flamingock pipeline from file specified in @EnableFlamingock annotation: '" + pipelineAnnotation.configFile() + "'");
@@ -677,4 +664,19 @@ private String processResourceLocation(String location) {
677664
: location;
678665
}
679666

667+
private void validateConfiguration(EnableFlamingock pipelineAnnotation, boolean hasFileInAnnotation, boolean hasStagesInAnnotation) {
668+
if (hasFileInAnnotation && hasStagesInAnnotation) {
669+
throw new RuntimeException("@EnableFlamingock annotation cannot have both configFile and stages configured. Choose one: either specify configFile OR stages.");
670+
}
671+
672+
if (!hasFileInAnnotation && !hasStagesInAnnotation) {
673+
throw new RuntimeException("@EnableFlamingock annotation must specify either configFile OR stages configuration.");
674+
}
675+
676+
// Validate stage type restrictions when using annotation-based configuration
677+
if (hasStagesInAnnotation) {
678+
validateStageTypes(pipelineAnnotation.stages());
679+
}
680+
}
681+
680682
}

core/flamingock-processor/src/main/java/io/flamingock/core/processor/util/AnnotationFinder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,14 @@ public Map<String, List<AbstractPreviewTask>> getCodedChangesMapByPackage() {
5656
return mapByPackage;
5757
}
5858

59-
public EnableFlamingock getPipelineAnnotation() {
59+
public Optional<EnableFlamingock> getPipelineAnnotation() {
6060
logger.info("Searching for @EnableFlamingock annotation");
6161
return roundEnv.getElementsAnnotatedWith(EnableFlamingock.class)
6262
.stream()
6363
.filter(e -> e.getKind() == ElementKind.CLASS)
6464
.map(e -> (TypeElement) e)
6565
.map(e -> e.getAnnotation(EnableFlamingock.class))
66-
.findFirst()
67-
.orElse(null);
66+
.findFirst();
6867
}
6968

7069
private Collection<CodePreviewChange> findAnnotatedChanges() {

0 commit comments

Comments
 (0)