Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
refactor: replace nested control structures with pipeline
  • Loading branch information
mtodorov-dl committed Sep 27, 2026
commit 56f8ef5cb8645a08189f2dc020e250e6e6536577
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
package org.mapstruct.ap.spi;

import java.util.Optional;
import java.util.regex.Pattern;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.Name;
Expand Down Expand Up @@ -64,19 +64,16 @@ protected BuilderInfo findBuilderInfoForImmutables(TypeElement typeElement) {

protected BuilderInfo findBuilderInfoForImmutables(TypeElement typeElement,
TypeElement immutableAnnotation) {
for ( AnnotationMirror annotationMirror : elementUtils.getAllAnnotationMirrors( typeElement ) ) {
if ( typeUtils.isSameType( annotationMirror.getAnnotationType(), immutableAnnotation.asType() ) ) {
TypeElement immutableElement = asImmutableElement( typeElement );
if ( immutableElement != null ) {
return super.findBuilderInfo( immutableElement, false );
}
else {
// Immutables processor has not run yet. Trigger a postpone to the next round for MapStruct
throw new TypeHierarchyErroneousException( typeElement );
}
}
}
return null;
return elementUtils.getAllAnnotationMirrors( typeElement )
.stream()
.filter( annotationMirror -> typeUtils.isSameType(
annotationMirror.getAnnotationType(),
immutableAnnotation.asType() ) )
.findFirst()
.map( annotationMirror -> Optional.ofNullable( asImmutableElement( typeElement ) )
.orElseThrow( () -> new TypeHierarchyErroneousException( typeElement ) ) )
.map( immutableElement -> super.findBuilderInfo( immutableElement, false ) )
.orElse( null );
}

protected TypeElement asImmutableElement(TypeElement typeElement) {
Expand Down