#302 Removing Method#printMessage()

This commit is contained in:
Gunnar Morling 2014-10-12 18:47:52 +02:00
parent 6e24db8196
commit b1e184811f
8 changed files with 42 additions and 50 deletions

View File

@ -95,7 +95,7 @@ public class IterableMappingMethod extends MappingMethod {
+ "source element type into target element type.", + "source element type into target element type.",
method method
); );
method.printMessage( ctx.getMessager(), Diagnostic.Kind.ERROR, message ); ctx.getMessager().printMessage( Diagnostic.Kind.ERROR, message, method.getExecutable() );
} }
// target accessor is setter, so decorate assignment as setter // target accessor is setter, so decorate assignment as setter

View File

@ -107,7 +107,7 @@ public class MapMappingMethod extends MappingMethod {
"Can't create implementation of method %s. Found no method nor " "Can't create implementation of method %s. Found no method nor "
+ "built-in conversion for mapping source key type to target key type.", method + "built-in conversion for mapping source key type to target key type.", method
); );
method.printMessage( ctx.getMessager(), Diagnostic.Kind.ERROR, message ); ctx.getMessager().printMessage( Diagnostic.Kind.ERROR, message, method.getExecutable() );
} }
// find mapping method or conversion for value // find mapping method or conversion for value
@ -130,7 +130,7 @@ public class MapMappingMethod extends MappingMethod {
"Can't create implementation of method %s. Found no method nor " "Can't create implementation of method %s. Found no method nor "
+ "built-in conversion for mapping source value type to target value type.", method + "built-in conversion for mapping source value type to target value type.", method
); );
method.printMessage( ctx.getMessager(), Diagnostic.Kind.ERROR, message ); ctx.getMessager().printMessage( Diagnostic.Kind.ERROR, message, method.getExecutable() );
} }
FactoryMethod factoryMethod = AssignmentFactory.createFactoryMethod( method.getReturnType(), ctx ); FactoryMethod factoryMethod = AssignmentFactory.createFactoryMethod( method.getReturnType(), ctx );

View File

@ -18,23 +18,24 @@
*/ */
package org.mapstruct.ap.model; package org.mapstruct.ap.model;
import org.mapstruct.ap.model.assignment.Assignment;
import java.util.List;
import java.util.Set;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic;
import static org.mapstruct.ap.model.assignment.Assignment.AssignmentType.DIRECT; import static org.mapstruct.ap.model.assignment.Assignment.AssignmentType.DIRECT;
import static org.mapstruct.ap.model.assignment.Assignment.AssignmentType.TYPE_CONVERTED; import static org.mapstruct.ap.model.assignment.Assignment.AssignmentType.TYPE_CONVERTED;
import static org.mapstruct.ap.model.assignment.Assignment.AssignmentType.TYPE_CONVERTED_MAPPED; import static org.mapstruct.ap.model.assignment.Assignment.AssignmentType.TYPE_CONVERTED_MAPPED;
import java.util.List;
import java.util.Set;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic;
import org.mapstruct.ap.model.assignment.AdderWrapper; import org.mapstruct.ap.model.assignment.AdderWrapper;
import org.mapstruct.ap.model.assignment.Assignment;
import org.mapstruct.ap.model.assignment.GetterCollectionOrMapWrapper; import org.mapstruct.ap.model.assignment.GetterCollectionOrMapWrapper;
import org.mapstruct.ap.model.assignment.NewCollectionOrMapWrapper; import org.mapstruct.ap.model.assignment.NewCollectionOrMapWrapper;
import org.mapstruct.ap.model.assignment.NullCheckWrapper; import org.mapstruct.ap.model.assignment.NullCheckWrapper;
import org.mapstruct.ap.model.assignment.SetterCollectionOrMapWrapper; import org.mapstruct.ap.model.assignment.SetterCollectionOrMapWrapper;
import org.mapstruct.ap.model.assignment.SetterWrapper; import org.mapstruct.ap.model.assignment.SetterWrapper;
import org.mapstruct.ap.model.common.ModelElement; import org.mapstruct.ap.model.common.ModelElement;
import org.mapstruct.ap.model.common.Parameter; import org.mapstruct.ap.model.common.Parameter;
import org.mapstruct.ap.model.common.Type; import org.mapstruct.ap.model.common.Type;
@ -278,7 +279,8 @@ public class PropertyMapping extends ModelElement {
); );
} }
private Assignment forgeMapping( Type sourceType, Type targetType, String sourceReference, Element element ) { private Assignment forgeMapping(Type sourceType, Type targetType, String sourceReference,
ExecutableElement element) {
Assignment assignment = null; Assignment assignment = null;
if ( sourceType.isCollectionType() && targetType.isCollectionType() ) { if ( sourceType.isCollectionType() && targetType.isCollectionType() ) {

View File

@ -21,9 +21,9 @@ package org.mapstruct.ap.model.source;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import javax.annotation.processing.Messager;
import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement;
import javax.tools.Diagnostic;
import org.mapstruct.ap.model.common.Accessibility; import org.mapstruct.ap.model.common.Accessibility;
import org.mapstruct.ap.model.common.Parameter; import org.mapstruct.ap.model.common.Parameter;
import org.mapstruct.ap.model.common.Type; import org.mapstruct.ap.model.common.Type;
@ -41,9 +41,9 @@ public class ForgedMethod implements Method {
private final List<Parameter> parameters; private final List<Parameter> parameters;
private final Type returnType; private final Type returnType;
private final String name; private final String name;
private final Element positionHintElement; private final ExecutableElement positionHintElement;
public ForgedMethod( Type sourceType, Type targetType, Element positionHintElement ) { public ForgedMethod( Type sourceType, Type targetType, ExecutableElement positionHintElement ) {
this.parameters = Arrays.asList( new Parameter("source", sourceType) ); this.parameters = Arrays.asList( new Parameter("source", sourceType) );
this.returnType = targetType; this.returnType = targetType;
@ -122,11 +122,6 @@ public class ForgedMethod implements Method {
return Collections.<Type>emptyList(); return Collections.<Type>emptyList();
} }
@Override
public void printMessage( Messager messager, Diagnostic.Kind kind, String message ) {
messager.printMessage( kind, message, positionHintElement );
}
@Override @Override
public Type getResultType() { public Type getResultType() {
return returnType; return returnType;
@ -142,6 +137,11 @@ public class ForgedMethod implements Method {
return false; return false;
} }
@Override
public ExecutableElement getExecutable() {
return positionHintElement;
}
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder( returnType.toString() ); StringBuilder sb = new StringBuilder( returnType.toString() );

View File

@ -20,8 +20,9 @@
package org.mapstruct.ap.model.source; package org.mapstruct.ap.model.source;
import java.util.List; import java.util.List;
import javax.annotation.processing.Messager;
import javax.tools.Diagnostic.Kind; import javax.lang.model.element.ExecutableElement;
import org.mapstruct.ap.model.common.Accessibility; import org.mapstruct.ap.model.common.Accessibility;
import org.mapstruct.ap.model.common.Parameter; import org.mapstruct.ap.model.common.Parameter;
import org.mapstruct.ap.model.common.Type; import org.mapstruct.ap.model.common.Type;
@ -105,15 +106,6 @@ public interface Method {
*/ */
List<Type> getThrownTypes(); List<Type> getThrownTypes();
/**
* Prints a message to the provided messager. Uses
*
* @param messager the messager
* @param kind error, warning, etc.
* @param message message to print
*/
void printMessage( Messager messager, Kind kind, String message );
/** /**
* Returns the type of the result. * Returns the type of the result.
* *
@ -137,4 +129,6 @@ public interface Method {
* @return true when an abstract method is overridden. * @return true when an abstract method is overridden.
*/ */
boolean overridesMethod(); boolean overridesMethod();
ExecutableElement getExecutable();
} }

View File

@ -22,11 +22,11 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
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;
import javax.lang.model.util.Types; import javax.lang.model.util.Types;
import javax.tools.Diagnostic.Kind;
import org.mapstruct.ap.model.common.Accessibility; import org.mapstruct.ap.model.common.Accessibility;
import org.mapstruct.ap.model.common.Parameter; import org.mapstruct.ap.model.common.Parameter;
import org.mapstruct.ap.model.common.Type; import org.mapstruct.ap.model.common.Type;
@ -358,10 +358,4 @@ public class SourceMethod implements Method {
public List<Type> getThrownTypes() { public List<Type> getThrownTypes() {
return exceptionTypes; return exceptionTypes;
} }
@Override
public void printMessage( Messager messager, Kind kind, String message ) {
messager.printMessage( kind, message, executable );
}
} }

View File

@ -23,8 +23,9 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import javax.annotation.processing.Messager;
import javax.tools.Diagnostic.Kind; import javax.lang.model.element.ExecutableElement;
import org.mapstruct.ap.conversion.SimpleConversion; import org.mapstruct.ap.conversion.SimpleConversion;
import org.mapstruct.ap.model.common.Accessibility; import org.mapstruct.ap.model.common.Accessibility;
import org.mapstruct.ap.model.common.ConversionContext; import org.mapstruct.ap.model.common.ConversionContext;
@ -197,11 +198,6 @@ public abstract class BuiltInMethod implements Method {
return Collections.emptyList(); return Collections.emptyList();
} }
@Override
public void printMessage( Messager messager, Kind kind, String message ) {
messager.printMessage( kind, message );
}
@Override @Override
public Type getResultType() { public Type getResultType() {
return getReturnType(); return getReturnType();
@ -221,4 +217,9 @@ public abstract class BuiltInMethod implements Method {
public boolean overridesMethod() { public boolean overridesMethod() {
return false; return false;
} }
@Override
public ExecutableElement getExecutable() {
return null;
}
} }

View File

@ -22,11 +22,12 @@ 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.annotation.processing.Messager; import javax.annotation.processing.Messager;
import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements; import javax.lang.model.util.Elements;
import javax.lang.model.util.Types; import javax.lang.model.util.Types;
import javax.tools.Diagnostic.Kind; import javax.tools.Diagnostic;
import org.mapstruct.ap.conversion.ConversionProvider; import org.mapstruct.ap.conversion.ConversionProvider;
import org.mapstruct.ap.conversion.Conversions; import org.mapstruct.ap.conversion.Conversions;
@ -417,7 +418,7 @@ public class MappingResolverImpl implements MappingResolver {
Strings.join( candidates, ", " ) Strings.join( candidates, ", " )
); );
mappingMethod.printMessage( messager, Kind.ERROR, errorMsg ); messager.printMessage( Diagnostic.Kind.ERROR, errorMsg, mappingMethod.getExecutable() );
} }
if ( !candidates.isEmpty() ) { if ( !candidates.isEmpty() ) {