Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,22 @@ private Decorator(TypeFactory typeFactory, String packageName, String name, Type
@Override
public SortedSet<Type> getImportTypes() {
SortedSet<Type> importTypes = super.getImportTypes();
addIfImportRequired( importTypes, decoratorType );
// DecoratorType needs special handling in case it is nested
// calling addIfImportRequired is not the most correct approach since it would
// lead to checking if the type is to be imported and that would be false
// since the Decorator is a nested class within the Mapper.
// However, when generating the Decorator this is not needed,
// because the Decorator is a top level class itself
// In a nutshell creating the Decorator should have its own ProcessorContext, but it doesn't
if ( decoratorType.getPackageName().equalsIgnoreCase( getPackageName() ) ) {
if ( decoratorType.getTypeElement() != null &&
decoratorType.getTypeElement().getNestingKind().isNested() ) {
importTypes.add( decoratorType );
}
}
else {
importTypes.add( decoratorType );
}
return importTypes;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._2021;

import org.mapstruct.DecoratedWith;
import org.mapstruct.Mapper;

/**
* @author Filip Hrisafov
*/
@Mapper
@DecoratedWith(Issue2021Mapper.Decorator.class)
public interface Issue2021Mapper {

abstract class Decorator implements Issue2021Mapper {

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._2021;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;

/**
* @author Filip Hrisafov
*/
@IssueKey("2021")
@RunWith(AnnotationProcessorTestRunner.class)
@WithClasses({
Issue2021Mapper.class
})
public class Issue2021Test {

@Test
public void shouldCompile() {

}
}