#327 Improving method name; Formatting

This commit is contained in:
Gunnar Morling 2014-11-18 22:10:25 +01:00
parent 03535ecb18
commit bcda1d25b7
14 changed files with 30 additions and 40 deletions

View File

@ -24,7 +24,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
@ -288,7 +287,7 @@ public class Type extends ModelElement implements Comparable<Type> {
private List<ExecutableElement> getAllExecutables() {
if ( allExecutables == null ) {
allExecutables = Executables.getAllEnclosingExecutableElements( elementUtils, typeElement );
allExecutables = Executables.getAllEnclosedExecutableElements( elementUtils, typeElement );
}
return allExecutables;

View File

@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.processing.Messager;
import javax.lang.model.element.ExecutableElement;
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.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
@ -90,7 +89,7 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis
private List<SourceMethod> retrieveMethods(TypeElement usedMapper, TypeElement mapperToImplement) {
List<SourceMethod> methods = new ArrayList<SourceMethod>();
for ( ExecutableElement executable : getAllEnclosingExecutableElements( elementUtils, usedMapper ) ) {
for ( ExecutableElement executable : getAllEnclosedExecutableElements( elementUtils, usedMapper ) ) {
SourceMethod method = getMethod( usedMapper, executable, mapperToImplement );
if ( method != null ) {
methods.add( method );

View File

@ -23,7 +23,6 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
@ -168,6 +167,7 @@ public class Executables {
/**
* @param mirror the type mirror
*
* @return the corresponding type element
*/
private static TypeElement asTypeElement(TypeMirror mirror) {
@ -181,21 +181,18 @@ public class Executables {
*
* @param elementUtils element helper
* @param element the element to inspect
*
* @return the executable elements usable in the type
*/
public static List<ExecutableElement> getAllEnclosingExecutableElements(
Elements elementUtils, TypeElement element) {
public static List<ExecutableElement> getAllEnclosedExecutableElements(Elements elementUtils, TypeElement element) {
List<ExecutableElement> enclosedElements = new ArrayList<ExecutableElement>();
addEnclosingElementsIncludingSuper( elementUtils, enclosedElements, element );
return enclosedElements;
}
private static void addEnclosingElementsIncludingSuper(Elements elementUtils,
List<ExecutableElement> alreadyAdded,
private static void addEnclosingElementsIncludingSuper(Elements elementUtils, List<ExecutableElement> alreadyAdded,
TypeElement element) {
addNotYetOverridden( elementUtils, alreadyAdded, methodsIn( element.getEnclosedElements() ) );
if ( hasNonObjectSuperclass( element ) ) {
@ -215,7 +212,6 @@ public class Executables {
*/
private static void addNotYetOverridden(Elements elementUtils, List<ExecutableElement> alreadyCollected,
List<ExecutableElement> methodsToAdd) {
List<ExecutableElement> safeToAdd = new ArrayList<ExecutableElement>( methodsToAdd.size() );
for ( ExecutableElement toAdd : methodsToAdd ) {
if ( isNotObjectEquals( toAdd ) && wasNotYetOverridden( elementUtils, alreadyCollected, toAdd ) ) {
@ -228,13 +224,15 @@ public class Executables {
/**
* @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
*/
private static boolean isNotObjectEquals(ExecutableElement executable) {
if ( executable.getSimpleName().contentEquals( "equals" ) && executable.getParameters().size() == 1
&& asTypeElement( executable.getParameters().get( 0 ).asType() ).getQualifiedName().contentEquals(
"java.lang.Object" ) ) {
"java.lang.Object"
) ) {
return false;
}
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
* super-types)
* @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,
ExecutableElement executable) {
@ -261,11 +260,11 @@ public class Executables {
/**
* @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) {
return element.getSuperclass().getKind() == TypeKind.DECLARED
&& asTypeElement( element.getSuperclass() ).getSuperclass().getKind() == TypeKind.DECLARED;
}
}

View File

@ -20,7 +20,6 @@ package org.mapstruct.ap.test.abstractclass;
/**
* @author Andreas Gudian
*
*/
public abstract class AbstractBaseMapper implements BaseMapperInterface {
public abstract Target sourceToTargetFromBaseMapper(Source source);

View File

@ -31,19 +31,21 @@ import static org.fest.assertions.Assertions.assertThat;
*
* @author Gunnar Morling
*/
@WithClasses( { Source.class, Target.class, SourceTargetMapper.class, AbstractBaseMapper.class,
@WithClasses({
Source.class, Target.class, SourceTargetMapper.class, AbstractBaseMapper.class,
BaseMapperInterface.class,
ReferencedMapper.class,
AbstractReferencedMapper.class,
ReferencedMapperInterface.class,
AbstractDto.class,
Identifiable.class,
Measurable.class } )
@RunWith( AnnotationProcessorTestRunner.class )
Measurable.class
})
@RunWith(AnnotationProcessorTestRunner.class)
public class AbstractClassTest {
@Test
@IssueKey( "64" )
@IssueKey("64")
public void shouldCreateImplementationOfAbstractMethod() {
Source source = new Source();
@ -51,7 +53,7 @@ public class AbstractClassTest {
}
@Test
@IssueKey( "165" )
@IssueKey("165")
public void shouldCreateImplementationOfMethodFromSuper() {
Source source = new Source();
@ -59,7 +61,7 @@ public class AbstractClassTest {
}
@Test
@IssueKey( "165" )
@IssueKey("165")
public void shouldCreateImplementationOfMethodFromInterface() {
Source source = new Source();

View File

@ -20,7 +20,6 @@ package org.mapstruct.ap.test.abstractclass;
/**
* @author Andreas Gudian
*
*/
public class AbstractDto implements Identifiable {
private Long id = 1L;

View File

@ -22,7 +22,6 @@ import javax.xml.ws.Holder;
/**
* @author Andreas Gudian
*
*/
public abstract class AbstractReferencedMapper implements ReferencedMapperInterface {
@Override

View File

@ -20,7 +20,6 @@ package org.mapstruct.ap.test.abstractclass;
/**
* @author Andreas Gudian
*
*/
public interface BaseMapperInterface {
Target sourceToTargetFromBaseMapperInterface(Source source);

View File

@ -20,7 +20,6 @@ package org.mapstruct.ap.test.abstractclass;
/**
* @author Andreas Gudian
*
*/
public interface Identifiable {
Long getId();

View File

@ -20,7 +20,6 @@ package org.mapstruct.ap.test.abstractclass;
/**
* @author Andreas Gudian
*
*/
public interface Measurable {
int getSize();

View File

@ -22,7 +22,6 @@ import javax.xml.ws.Holder;
/**
* @author Andreas Gudian
*
*/
public class ReferencedMapper extends AbstractReferencedMapper {
@Override

View File

@ -22,7 +22,6 @@ import javax.xml.ws.Holder;
/**
* @author Andreas Gudian
*
*/
public interface ReferencedMapperInterface {
int holderToInt(Holder<String> holder);

View File

@ -19,7 +19,6 @@
package org.mapstruct.ap.test.abstractclass;
import java.util.Calendar;
import javax.xml.ws.Holder;
public class Source extends AbstractDto {
@ -27,7 +26,7 @@ public class Source extends AbstractDto {
private final int size;
private final Calendar birthday;
private final String notAttractingEqualsMethod = "no way";
private final Holder<String> manuallyConverted = new Holder<String>("What is the answer?");
private final Holder<String> manuallyConverted = new Holder<String>( "What is the answer?" );
public Source() {
size = 181;

View File

@ -25,7 +25,7 @@ import java.util.Calendar;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper( uses = ReferencedMapper.class )
@Mapper(uses = ReferencedMapper.class)
public abstract class SourceTargetMapper extends AbstractBaseMapper {
public static final SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );