mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#327 Improving method name; Formatting
This commit is contained in:
parent
03535ecb18
commit
bcda1d25b7
@ -24,7 +24,6 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.lang.model.element.AnnotationMirror;
|
import javax.lang.model.element.AnnotationMirror;
|
||||||
import javax.lang.model.element.Element;
|
import javax.lang.model.element.Element;
|
||||||
import javax.lang.model.element.ElementKind;
|
import javax.lang.model.element.ElementKind;
|
||||||
@ -288,7 +287,7 @@ public class Type extends ModelElement implements Comparable<Type> {
|
|||||||
|
|
||||||
private List<ExecutableElement> getAllExecutables() {
|
private List<ExecutableElement> getAllExecutables() {
|
||||||
if ( allExecutables == null ) {
|
if ( allExecutables == null ) {
|
||||||
allExecutables = Executables.getAllEnclosingExecutableElements( elementUtils, typeElement );
|
allExecutables = Executables.getAllEnclosedExecutableElements( elementUtils, typeElement );
|
||||||
}
|
}
|
||||||
|
|
||||||
return allExecutables;
|
return allExecutables;
|
||||||
|
@ -22,7 +22,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.annotation.processing.Messager;
|
import javax.annotation.processing.Messager;
|
||||||
import javax.lang.model.element.ExecutableElement;
|
import javax.lang.model.element.ExecutableElement;
|
||||||
import javax.lang.model.element.Modifier;
|
import javax.lang.model.element.Modifier;
|
||||||
@ -48,7 +47,7 @@ import org.mapstruct.ap.prism.MappingsPrism;
|
|||||||
import org.mapstruct.ap.util.AnnotationProcessingException;
|
import org.mapstruct.ap.util.AnnotationProcessingException;
|
||||||
import org.mapstruct.ap.util.MapperConfig;
|
import org.mapstruct.ap.util.MapperConfig;
|
||||||
|
|
||||||
import static org.mapstruct.ap.util.Executables.getAllEnclosingExecutableElements;
|
import static org.mapstruct.ap.util.Executables.getAllEnclosedExecutableElements;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link ModelElementProcessor} which retrieves a list of {@link SourceMethod}s
|
* A {@link ModelElementProcessor} which retrieves a list of {@link SourceMethod}s
|
||||||
@ -90,7 +89,7 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis
|
|||||||
private List<SourceMethod> retrieveMethods(TypeElement usedMapper, TypeElement mapperToImplement) {
|
private List<SourceMethod> retrieveMethods(TypeElement usedMapper, TypeElement mapperToImplement) {
|
||||||
List<SourceMethod> methods = new ArrayList<SourceMethod>();
|
List<SourceMethod> methods = new ArrayList<SourceMethod>();
|
||||||
|
|
||||||
for ( ExecutableElement executable : getAllEnclosingExecutableElements( elementUtils, usedMapper ) ) {
|
for ( ExecutableElement executable : getAllEnclosedExecutableElements( elementUtils, usedMapper ) ) {
|
||||||
SourceMethod method = getMethod( usedMapper, executable, mapperToImplement );
|
SourceMethod method = getMethod( usedMapper, executable, mapperToImplement );
|
||||||
if ( method != null ) {
|
if ( method != null ) {
|
||||||
methods.add( method );
|
methods.add( method );
|
||||||
|
@ -23,7 +23,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.lang.model.element.ExecutableElement;
|
import javax.lang.model.element.ExecutableElement;
|
||||||
import javax.lang.model.element.Modifier;
|
import javax.lang.model.element.Modifier;
|
||||||
import javax.lang.model.element.TypeElement;
|
import javax.lang.model.element.TypeElement;
|
||||||
@ -168,6 +167,7 @@ public class Executables {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mirror the type mirror
|
* @param mirror the type mirror
|
||||||
|
*
|
||||||
* @return the corresponding type element
|
* @return the corresponding type element
|
||||||
*/
|
*/
|
||||||
private static TypeElement asTypeElement(TypeMirror mirror) {
|
private static TypeElement asTypeElement(TypeMirror mirror) {
|
||||||
@ -181,21 +181,18 @@ public class Executables {
|
|||||||
*
|
*
|
||||||
* @param elementUtils element helper
|
* @param elementUtils element helper
|
||||||
* @param element the element to inspect
|
* @param element the element to inspect
|
||||||
|
*
|
||||||
* @return the executable elements usable in the type
|
* @return the executable elements usable in the type
|
||||||
*/
|
*/
|
||||||
public static List<ExecutableElement> getAllEnclosingExecutableElements(
|
public static List<ExecutableElement> getAllEnclosedExecutableElements(Elements elementUtils, TypeElement element) {
|
||||||
Elements elementUtils, TypeElement element) {
|
|
||||||
List<ExecutableElement> enclosedElements = new ArrayList<ExecutableElement>();
|
List<ExecutableElement> enclosedElements = new ArrayList<ExecutableElement>();
|
||||||
|
|
||||||
addEnclosingElementsIncludingSuper( elementUtils, enclosedElements, element );
|
addEnclosingElementsIncludingSuper( elementUtils, enclosedElements, element );
|
||||||
|
|
||||||
return enclosedElements;
|
return enclosedElements;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addEnclosingElementsIncludingSuper(Elements elementUtils,
|
private static void addEnclosingElementsIncludingSuper(Elements elementUtils, List<ExecutableElement> alreadyAdded,
|
||||||
List<ExecutableElement> alreadyAdded,
|
|
||||||
TypeElement element) {
|
TypeElement element) {
|
||||||
|
|
||||||
addNotYetOverridden( elementUtils, alreadyAdded, methodsIn( element.getEnclosedElements() ) );
|
addNotYetOverridden( elementUtils, alreadyAdded, methodsIn( element.getEnclosedElements() ) );
|
||||||
|
|
||||||
if ( hasNonObjectSuperclass( element ) ) {
|
if ( hasNonObjectSuperclass( element ) ) {
|
||||||
@ -215,7 +212,6 @@ public class Executables {
|
|||||||
*/
|
*/
|
||||||
private static void addNotYetOverridden(Elements elementUtils, List<ExecutableElement> alreadyCollected,
|
private static void addNotYetOverridden(Elements elementUtils, List<ExecutableElement> alreadyCollected,
|
||||||
List<ExecutableElement> methodsToAdd) {
|
List<ExecutableElement> methodsToAdd) {
|
||||||
|
|
||||||
List<ExecutableElement> safeToAdd = new ArrayList<ExecutableElement>( methodsToAdd.size() );
|
List<ExecutableElement> safeToAdd = new ArrayList<ExecutableElement>( methodsToAdd.size() );
|
||||||
for ( ExecutableElement toAdd : methodsToAdd ) {
|
for ( ExecutableElement toAdd : methodsToAdd ) {
|
||||||
if ( isNotObjectEquals( toAdd ) && wasNotYetOverridden( elementUtils, alreadyCollected, toAdd ) ) {
|
if ( isNotObjectEquals( toAdd ) && wasNotYetOverridden( elementUtils, alreadyCollected, toAdd ) ) {
|
||||||
@ -228,13 +224,15 @@ public class Executables {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param executable the executable to check
|
* @param executable the executable to check
|
||||||
* @return <code>true</code>, iff the executable does not represent {@link java.lang.Object#equals(Object)} or an
|
*
|
||||||
|
* @return {@code true}, iff the executable does not represent {@link java.lang.Object#equals(Object)} or an
|
||||||
* overridden version of it
|
* overridden version of it
|
||||||
*/
|
*/
|
||||||
private static boolean isNotObjectEquals(ExecutableElement executable) {
|
private static boolean isNotObjectEquals(ExecutableElement executable) {
|
||||||
if ( executable.getSimpleName().contentEquals( "equals" ) && executable.getParameters().size() == 1
|
if ( executable.getSimpleName().contentEquals( "equals" ) && executable.getParameters().size() == 1
|
||||||
&& asTypeElement( executable.getParameters().get( 0 ).asType() ).getQualifiedName().contentEquals(
|
&& asTypeElement( executable.getParameters().get( 0 ).asType() ).getQualifiedName().contentEquals(
|
||||||
"java.lang.Object" ) ) {
|
"java.lang.Object"
|
||||||
|
) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -245,7 +243,8 @@ public class Executables {
|
|||||||
* @param methods the list of already collected methods of one type hierarchy (order is from sub-types to
|
* @param methods the list of already collected methods of one type hierarchy (order is from sub-types to
|
||||||
* super-types)
|
* super-types)
|
||||||
* @param executable the method to check
|
* @param executable the method to check
|
||||||
* @return <code>true</code>, iff the given executable was not yet overridden by a method in the given list.
|
*
|
||||||
|
* @return {@code true}, iff the given executable was not yet overridden by a method in the given list.
|
||||||
*/
|
*/
|
||||||
private static boolean wasNotYetOverridden(Elements elementUtils, List<ExecutableElement> alreadyAdded,
|
private static boolean wasNotYetOverridden(Elements elementUtils, List<ExecutableElement> alreadyAdded,
|
||||||
ExecutableElement executable) {
|
ExecutableElement executable) {
|
||||||
@ -261,11 +260,11 @@ public class Executables {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param element the type element to check
|
* @param element the type element to check
|
||||||
* @return <code>true</code>, iff the type has a super-class that is not java.lang.Object
|
*
|
||||||
|
* @return {@code true}, iff the type has a super-class that is not java.lang.Object
|
||||||
*/
|
*/
|
||||||
private static boolean hasNonObjectSuperclass(TypeElement element) {
|
private static boolean hasNonObjectSuperclass(TypeElement element) {
|
||||||
return element.getSuperclass().getKind() == TypeKind.DECLARED
|
return element.getSuperclass().getKind() == TypeKind.DECLARED
|
||||||
&& asTypeElement( element.getSuperclass() ).getSuperclass().getKind() == TypeKind.DECLARED;
|
&& asTypeElement( element.getSuperclass() ).getSuperclass().getKind() == TypeKind.DECLARED;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ package org.mapstruct.ap.test.abstractclass;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andreas Gudian
|
* @author Andreas Gudian
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractBaseMapper implements BaseMapperInterface {
|
public abstract class AbstractBaseMapper implements BaseMapperInterface {
|
||||||
public abstract Target sourceToTargetFromBaseMapper(Source source);
|
public abstract Target sourceToTargetFromBaseMapper(Source source);
|
||||||
|
@ -31,14 +31,16 @@ import static org.fest.assertions.Assertions.assertThat;
|
|||||||
*
|
*
|
||||||
* @author Gunnar Morling
|
* @author Gunnar Morling
|
||||||
*/
|
*/
|
||||||
@WithClasses( { Source.class, Target.class, SourceTargetMapper.class, AbstractBaseMapper.class,
|
@WithClasses({
|
||||||
|
Source.class, Target.class, SourceTargetMapper.class, AbstractBaseMapper.class,
|
||||||
BaseMapperInterface.class,
|
BaseMapperInterface.class,
|
||||||
ReferencedMapper.class,
|
ReferencedMapper.class,
|
||||||
AbstractReferencedMapper.class,
|
AbstractReferencedMapper.class,
|
||||||
ReferencedMapperInterface.class,
|
ReferencedMapperInterface.class,
|
||||||
AbstractDto.class,
|
AbstractDto.class,
|
||||||
Identifiable.class,
|
Identifiable.class,
|
||||||
Measurable.class } )
|
Measurable.class
|
||||||
|
})
|
||||||
@RunWith(AnnotationProcessorTestRunner.class)
|
@RunWith(AnnotationProcessorTestRunner.class)
|
||||||
public class AbstractClassTest {
|
public class AbstractClassTest {
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ package org.mapstruct.ap.test.abstractclass;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andreas Gudian
|
* @author Andreas Gudian
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class AbstractDto implements Identifiable {
|
public class AbstractDto implements Identifiable {
|
||||||
private Long id = 1L;
|
private Long id = 1L;
|
||||||
|
@ -22,7 +22,6 @@ import javax.xml.ws.Holder;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andreas Gudian
|
* @author Andreas Gudian
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractReferencedMapper implements ReferencedMapperInterface {
|
public abstract class AbstractReferencedMapper implements ReferencedMapperInterface {
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,7 +20,6 @@ package org.mapstruct.ap.test.abstractclass;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andreas Gudian
|
* @author Andreas Gudian
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface BaseMapperInterface {
|
public interface BaseMapperInterface {
|
||||||
Target sourceToTargetFromBaseMapperInterface(Source source);
|
Target sourceToTargetFromBaseMapperInterface(Source source);
|
||||||
|
@ -20,7 +20,6 @@ package org.mapstruct.ap.test.abstractclass;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andreas Gudian
|
* @author Andreas Gudian
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface Identifiable {
|
public interface Identifiable {
|
||||||
Long getId();
|
Long getId();
|
||||||
|
@ -20,7 +20,6 @@ package org.mapstruct.ap.test.abstractclass;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andreas Gudian
|
* @author Andreas Gudian
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface Measurable {
|
public interface Measurable {
|
||||||
int getSize();
|
int getSize();
|
||||||
|
@ -22,7 +22,6 @@ import javax.xml.ws.Holder;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andreas Gudian
|
* @author Andreas Gudian
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class ReferencedMapper extends AbstractReferencedMapper {
|
public class ReferencedMapper extends AbstractReferencedMapper {
|
||||||
@Override
|
@Override
|
||||||
|
@ -22,7 +22,6 @@ import javax.xml.ws.Holder;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andreas Gudian
|
* @author Andreas Gudian
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface ReferencedMapperInterface {
|
public interface ReferencedMapperInterface {
|
||||||
int holderToInt(Holder<String> holder);
|
int holderToInt(Holder<String> holder);
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
package org.mapstruct.ap.test.abstractclass;
|
package org.mapstruct.ap.test.abstractclass;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
|
||||||
import javax.xml.ws.Holder;
|
import javax.xml.ws.Holder;
|
||||||
|
|
||||||
public class Source extends AbstractDto {
|
public class Source extends AbstractDto {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user