mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#163 Raising error in case wrong decorator type is given
This commit is contained in:
parent
e0da882540
commit
c15503f47b
@ -173,6 +173,15 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
||||
|
||||
TypeElement decoratorElement = (TypeElement) typeUtils.asElement( decoratorPrism.value() );
|
||||
|
||||
if ( !typeUtils.isAssignable( decoratorElement.asType(), element.asType() ) ) {
|
||||
messager.printMessage(
|
||||
Kind.ERROR,
|
||||
String.format( "Specified decorator type is no subtype of the annotated mapper type." ),
|
||||
element,
|
||||
decoratorPrism.mirror
|
||||
);
|
||||
}
|
||||
|
||||
List<MappingMethod> mappingMethods = new ArrayList<MappingMethod>( methods.size() );
|
||||
|
||||
for ( SourceMethod mappingMethod : methods ) {
|
||||
|
@ -19,10 +19,14 @@
|
||||
package org.mapstruct.ap.test.decorator;
|
||||
|
||||
import java.util.Calendar;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.mapstruct.ap.testutil.IssueKey;
|
||||
import org.mapstruct.ap.testutil.MapperTestBase;
|
||||
import org.mapstruct.ap.testutil.WithClasses;
|
||||
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
|
||||
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
|
||||
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
@ -120,4 +124,22 @@ public class DecoratorTest extends MapperTestBase {
|
||||
assertThat( personDto.getAddress() ).isNotNull();
|
||||
assertThat( personDto.getAddress().getAddressLine() ).isEqualTo( "42 Ocean View Drive" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithClasses({
|
||||
ErroneousPersonMapper.class,
|
||||
ErroneousPersonMapperDecorator.class
|
||||
})
|
||||
@ExpectedCompilationOutcome(
|
||||
value = CompilationResult.FAILED,
|
||||
diagnostics = {
|
||||
@Diagnostic(type = ErroneousPersonMapper.class,
|
||||
kind = Kind.ERROR,
|
||||
line = 27,
|
||||
messageRegExp = "Specified decorator type is no subtype of the annotated mapper type")
|
||||
}
|
||||
)
|
||||
public void shouldRaiseErrorInCaseWrongDecoratorTypeIsGiven() {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||
* and/or other contributors as indicated by the @authors tag. See the
|
||||
* copyright.txt file in the distribution for a full listing of all
|
||||
* contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.mapstruct.ap.test.decorator;
|
||||
|
||||
import org.mapstruct.DecoratedWith;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
@DecoratedWith(ErroneousPersonMapperDecorator.class)
|
||||
public interface ErroneousPersonMapper {
|
||||
|
||||
ErroneousPersonMapper INSTANCE = Mappers.getMapper( ErroneousPersonMapper.class );
|
||||
|
||||
PersonDto personToPersonDto(Person person);
|
||||
|
||||
AddressDto addressToAddressDto(Address address);
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||
* and/or other contributors as indicated by the @authors tag. See the
|
||||
* copyright.txt file in the distribution for a full listing of all
|
||||
* contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.mapstruct.ap.test.decorator;
|
||||
|
||||
public abstract class ErroneousPersonMapperDecorator {
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user