mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#660 Fix custom package / implementation name when using componentModel="default" with abstract classes
This commit is contained in:
parent
82ab85d3bc
commit
1f091c35e2
@ -18,6 +18,13 @@
|
||||
*/
|
||||
package org.mapstruct.ap.internal.processor;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.annotation.processing.Filer;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.tools.FileObject;
|
||||
import javax.tools.StandardLocation;
|
||||
|
||||
import org.mapstruct.ap.internal.model.GeneratedType;
|
||||
import org.mapstruct.ap.internal.model.Mapper;
|
||||
import org.mapstruct.ap.internal.model.ServicesEntry;
|
||||
@ -25,12 +32,6 @@ import org.mapstruct.ap.internal.option.OptionsHelper;
|
||||
import org.mapstruct.ap.internal.util.MapperConfiguration;
|
||||
import org.mapstruct.ap.internal.writer.ModelWriter;
|
||||
|
||||
import javax.annotation.processing.Filer;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.tools.FileObject;
|
||||
import javax.tools.StandardLocation;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A {@link ModelElementProcessor} which creates files in the {@code META-INF/services}
|
||||
* hierarchy for classes with custom implementation class or package name.
|
||||
@ -77,7 +78,9 @@ public class MapperServiceProcessor implements ModelElementProcessor<Mapper, Vo
|
||||
}
|
||||
|
||||
private ServicesEntry getServicesEntry(GeneratedType model) {
|
||||
return new ServicesEntry(model.getInterfacePackage(), model.getInterfaceName(),
|
||||
String mapperName = model.getInterfaceName() != null ? model.getInterfaceName() : model.getSuperClassName();
|
||||
|
||||
return new ServicesEntry(model.getInterfacePackage(), mapperName,
|
||||
model.getPackageName(), model.getName());
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Copyright 2012-2015 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.destination;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* @author Andreas Gudian
|
||||
*/
|
||||
@Mapper(implementationName = "My<CLASS_NAME>CustomImpl")
|
||||
public abstract class AbstractDestinationClassNameMapper {
|
||||
public static final AbstractDestinationClassNameMapper INSTANCE =
|
||||
Mappers.getMapper( AbstractDestinationClassNameMapper.class );
|
||||
|
||||
public abstract String intToString(Integer source);
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Copyright 2012-2015 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.destination;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* @author Andreas Gudian
|
||||
*/
|
||||
@Mapper(implementationPackage = "<PACKAGE_NAME>.dest")
|
||||
public abstract class AbstractDestinationPackageNameMapper {
|
||||
public static final AbstractDestinationPackageNameMapper INSTANCE =
|
||||
Mappers.getMapper( AbstractDestinationPackageNameMapper.class );
|
||||
|
||||
public abstract String intToString(Integer source);
|
||||
}
|
@ -85,4 +85,18 @@ public class DestinationClassNameTest {
|
||||
assertThat( ( (DestinationClassNameMapperDecorator) instance ).delegate.getClass().getSimpleName() )
|
||||
.isEqualTo( "MyDestinationClassNameMapperDecoratedCustomImpl_" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithClasses({ AbstractDestinationClassNameMapper.class, AbstractDestinationPackageNameMapper.class })
|
||||
public void shouldWorkWithAbstractClasses() {
|
||||
AbstractDestinationClassNameMapper mapper1 = AbstractDestinationClassNameMapper.INSTANCE;
|
||||
assertThat( mapper1.getClass().getPackage().getName() )
|
||||
.isEqualTo( AbstractDestinationClassNameMapper.class.getPackage().getName() );
|
||||
assertThat( mapper1.getClass().getSimpleName() ).isEqualTo( "MyAbstractDestinationClassNameMapperCustomImpl" );
|
||||
|
||||
AbstractDestinationPackageNameMapper mapper2 = AbstractDestinationPackageNameMapper.INSTANCE;
|
||||
assertThat( mapper2.getClass().getPackage().getName() )
|
||||
.isEqualTo( AbstractDestinationPackageNameMapper.class.getPackage().getName() + ".dest" );
|
||||
assertThat( mapper2.getClass().getSimpleName() ).isEqualTo( "AbstractDestinationPackageNameMapperImpl" );
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user