#513, source code naming consistence exceptionTypes == thrownTypes

This commit is contained in:
sjaakd 2015-05-17 11:35:24 +02:00
parent b4c514d479
commit b98644cfeb
18 changed files with 78 additions and 79 deletions

View File

@ -49,7 +49,7 @@ public class Direct extends ModelElement implements Assignment {
} }
@Override @Override
public List<Type> getExceptionTypes() { public List<Type> getThrownTypes() {
return Collections.emptyList(); return Collections.emptyList();
} }

View File

@ -123,7 +123,7 @@ public class IterableMappingMethod extends MappingMethod {
else { else {
if ( method instanceof ForgedMethod ) { if ( method instanceof ForgedMethod ) {
ForgedMethod forgedMethod = (ForgedMethod) method; ForgedMethod forgedMethod = (ForgedMethod) method;
forgedMethod.addThrownTypes( assignment.getExceptionTypes() ); forgedMethod.addThrownTypes( assignment.getThrownTypes() );
} }
} }
// target accessor is setter, so decorate assignment as setter // target accessor is setter, so decorate assignment as setter

View File

@ -154,10 +154,10 @@ public class MapMappingMethod extends MappingMethod {
if ( method instanceof ForgedMethod ) { if ( method instanceof ForgedMethod ) {
ForgedMethod forgedMethod = (ForgedMethod) method; ForgedMethod forgedMethod = (ForgedMethod) method;
if ( keyAssignment != null ) { if ( keyAssignment != null ) {
forgedMethod.addThrownTypes( keyAssignment.getExceptionTypes() ); forgedMethod.addThrownTypes( keyAssignment.getThrownTypes() );
} }
if ( valueAssignment != null ) { if ( valueAssignment != null ) {
forgedMethod.addThrownTypes( valueAssignment.getExceptionTypes() ); forgedMethod.addThrownTypes( valueAssignment.getThrownTypes() );
} }
} }

View File

@ -41,7 +41,7 @@ public class MethodReference extends MappingMethod implements Assignment {
private final MapperReference declaringMapper; private final MapperReference declaringMapper;
private final Set<Type> importTypes; private final Set<Type> importTypes;
private final List<Type> exceptionTypes; private final List<Type> thrownTypes;
private final boolean isUpdateMethod; private final boolean isUpdateMethod;
/** /**
@ -78,7 +78,7 @@ public class MethodReference extends MappingMethod implements Assignment {
imported.add( targetType ); imported.add( targetType );
} }
this.importTypes = Collections.<Type>unmodifiableSet( imported ); this.importTypes = Collections.<Type>unmodifiableSet( imported );
this.exceptionTypes = method.getThrownTypes(); this.thrownTypes = method.getThrownTypes();
this.isUpdateMethod = method.getMappingTargetParameter() != null; this.isUpdateMethod = method.getMappingTargetParameter() != null;
} }
@ -87,7 +87,7 @@ public class MethodReference extends MappingMethod implements Assignment {
this.declaringMapper = null; this.declaringMapper = null;
this.contextParam = method.getContextParameter( contextParam ); this.contextParam = method.getContextParameter( contextParam );
this.importTypes = Collections.emptySet(); this.importTypes = Collections.emptySet();
this.exceptionTypes = Collections.emptyList(); this.thrownTypes = Collections.emptyList();
this.isUpdateMethod = method.getMappingTargetParameter() != null; this.isUpdateMethod = method.getMappingTargetParameter() != null;
} }
@ -139,11 +139,11 @@ public class MethodReference extends MappingMethod implements Assignment {
} }
@Override @Override
public List<Type> getExceptionTypes() { public List<Type> getThrownTypes() {
List<Type> exceptions = new ArrayList<Type>(); List<Type> exceptions = new ArrayList<Type>();
exceptions.addAll( exceptionTypes ); exceptions.addAll( thrownTypes );
if ( assignment != null ) { if ( assignment != null ) {
exceptions.addAll( assignment.getExceptionTypes() ); exceptions.addAll( assignment.getThrownTypes() );
} }
return exceptions; return exceptions;
} }

View File

@ -36,7 +36,7 @@ public class TypeConversion extends ModelElement implements Assignment {
private static final String SOURCE_REFERENCE_PATTERN = "<SOURCE>"; private static final String SOURCE_REFERENCE_PATTERN = "<SOURCE>";
private final Set<Type> importTypes; private final Set<Type> importTypes;
private final List<Type> exceptionTypes; private final List<Type> thrownTypes;
private final String openExpression; private final String openExpression;
private final String closeExpression; private final String closeExpression;
@ -52,7 +52,7 @@ public class TypeConversion extends ModelElement implements Assignment {
String expression ) { String expression ) {
this.importTypes = new HashSet<Type>( importTypes ); this.importTypes = new HashSet<Type>( importTypes );
this.importTypes.addAll( exceptionTypes ); this.importTypes.addAll( exceptionTypes );
this.exceptionTypes = exceptionTypes; this.thrownTypes = exceptionTypes;
int patternIndex = expression.indexOf( SOURCE_REFERENCE_PATTERN ); int patternIndex = expression.indexOf( SOURCE_REFERENCE_PATTERN );
this.openExpression = expression.substring( 0, patternIndex ); this.openExpression = expression.substring( 0, patternIndex );
@ -65,8 +65,8 @@ public class TypeConversion extends ModelElement implements Assignment {
} }
@Override @Override
public List<Type> getExceptionTypes() { public List<Type> getThrownTypes() {
return exceptionTypes; return thrownTypes;
} }
public String getOpenExpression() { public String getOpenExpression() {

View File

@ -32,28 +32,28 @@ import org.mapstruct.ap.model.common.Type;
*/ */
public class AdderWrapper extends AssignmentWrapper { public class AdderWrapper extends AssignmentWrapper {
private final List<Type> exceptionTypesToExclude; private final List<Type> thrownTypesToExclude;
private final String sourceReference; private final String sourceReference;
private final Type sourceType; private final Type sourceType;
public AdderWrapper( public AdderWrapper(
Assignment decoratedAssignment, Assignment decoratedAssignment,
List<Type> exceptionTypesToExclude, List<Type> thrownTypesToExclude,
String sourceReference, String sourceReference,
Type sourceType) { Type sourceType) {
super( decoratedAssignment ); super( decoratedAssignment );
this.exceptionTypesToExclude = exceptionTypesToExclude; this.thrownTypesToExclude = thrownTypesToExclude;
this.sourceReference = sourceReference; this.sourceReference = sourceReference;
this.sourceType = sourceType; this.sourceType = sourceType;
} }
@Override @Override
public List<Type> getExceptionTypes() { public List<Type> getThrownTypes() {
List<Type> parentExceptionTypes = super.getExceptionTypes(); List<Type> parentThrownTypes = super.getThrownTypes();
List<Type> result = new ArrayList<Type>( parentExceptionTypes ); List<Type> result = new ArrayList<Type>( parentThrownTypes );
for ( Type exceptionTypeToExclude : exceptionTypesToExclude ) { for ( Type thrownTypeToExclude : thrownTypesToExclude ) {
for ( Type parentExceptionType : parentExceptionTypes ) { for ( Type parentExceptionType : parentThrownTypes ) {
if ( parentExceptionType.isAssignableTo( exceptionTypeToExclude ) ) { if ( parentExceptionType.isAssignableTo( thrownTypeToExclude ) ) {
result.remove( parentExceptionType ); result.remove( parentExceptionType );
} }
} }

View File

@ -57,7 +57,7 @@ public interface Assignment {
* *
* @return exceptions thrown * @return exceptions thrown
*/ */
List<Type> getExceptionTypes(); List<Type> getThrownTypes();
/** /**
* An assignment in itself can wrap another assignment. E.g.: * An assignment in itself can wrap another assignment. E.g.:

View File

@ -42,8 +42,8 @@ public abstract class AssignmentWrapper extends ModelElement implements Assignme
} }
@Override @Override
public List<Type> getExceptionTypes() { public List<Type> getThrownTypes() {
return decoratedAssignment.getExceptionTypes(); return decoratedAssignment.getThrownTypes();
} }
@Override @Override

View File

@ -42,28 +42,28 @@ import org.mapstruct.ap.util.Strings;
*/ */
public class GetterWrapperForCollectionsAndMaps extends AssignmentWrapper { public class GetterWrapperForCollectionsAndMaps extends AssignmentWrapper {
private final List<Type> exceptionTypesToExclude; private final List<Type> thrownTypesToExclude;
private final Type localVarType; private final Type localVarType;
private final String localVarName; private final String localVarName;
public GetterWrapperForCollectionsAndMaps(Assignment decoratedAssignment, List<Type> exceptionTypesToExclude, public GetterWrapperForCollectionsAndMaps(Assignment decoratedAssignment, List<Type> thrownTypesToExclude,
Type localVarType, Collection<String> existingVariableNames) { Type localVarType, Collection<String> existingVariableNames) {
super( decoratedAssignment ); super( decoratedAssignment );
this.exceptionTypesToExclude = exceptionTypesToExclude; this.thrownTypesToExclude = thrownTypesToExclude;
this.localVarType = localVarType; this.localVarType = localVarType;
this.localVarName = Strings.getSaveVariableName( "target" + localVarType.getName(), existingVariableNames ); this.localVarName = Strings.getSaveVariableName( "target" + localVarType.getName(), existingVariableNames );
existingVariableNames.add( localVarName ); existingVariableNames.add( localVarName );
} }
@Override @Override
public List<Type> getExceptionTypes() { public List<Type> getThrownTypes() {
List<Type> parentExceptionTypes = super.getExceptionTypes(); List<Type> parentThrownTypes = super.getThrownTypes();
List<Type> result = new ArrayList<Type>( parentExceptionTypes ); List<Type> result = new ArrayList<Type>( parentThrownTypes );
for ( Type exceptionTypeToExclude : exceptionTypesToExclude ) { for ( Type thrownTypeToExclude : thrownTypesToExclude ) {
for ( Type parentExceptionType : parentExceptionTypes ) { for ( Type parentThrownType : parentThrownTypes ) {
if ( parentExceptionType.isAssignableTo( exceptionTypeToExclude ) ) { if ( parentThrownType.isAssignableTo( thrownTypeToExclude ) ) {
result.remove( parentExceptionType ); result.remove( parentThrownType );
} }
} }
} }

View File

@ -29,21 +29,21 @@ import org.mapstruct.ap.model.common.Type;
*/ */
public class LocalVarWrapper extends AssignmentWrapper { public class LocalVarWrapper extends AssignmentWrapper {
private final List<Type> exceptionTypesToExclude; private final List<Type> thrownTypesToExclude;
public LocalVarWrapper( Assignment decoratedAssignment, List<Type> exceptionTypesToExclude ) { public LocalVarWrapper( Assignment decoratedAssignment, List<Type> thrownTypesToExclude ) {
super( decoratedAssignment ); super( decoratedAssignment );
this.exceptionTypesToExclude = exceptionTypesToExclude; this.thrownTypesToExclude = thrownTypesToExclude;
} }
@Override @Override
public List<Type> getExceptionTypes() { public List<Type> getThrownTypes() {
List<Type> parentExceptionTypes = super.getExceptionTypes(); List<Type> parentThrownTypes = super.getThrownTypes();
List<Type> result = new ArrayList<Type>( parentExceptionTypes ); List<Type> result = new ArrayList<Type>( parentThrownTypes );
for ( Type exceptionTypeToExclude : exceptionTypesToExclude ) { for ( Type thrownTypeToExclude : thrownTypesToExclude ) {
for ( Type parentExceptionType : parentExceptionTypes ) { for ( Type parentThrownType : parentThrownTypes ) {
if ( parentExceptionType.isAssignableTo( exceptionTypeToExclude ) ) { if ( parentThrownType.isAssignableTo( thrownTypeToExclude ) ) {
result.remove( parentExceptionType ); result.remove( parentThrownType );
} }
} }
} }

View File

@ -29,21 +29,21 @@ import org.mapstruct.ap.model.common.Type;
*/ */
public class SetterWrapper extends AssignmentWrapper { public class SetterWrapper extends AssignmentWrapper {
private final List<Type> exceptionTypesToExclude; private final List<Type> thrownTypesToExclude;
public SetterWrapper( Assignment decoratedAssignment, List<Type> exceptionTypesToExclude ) { public SetterWrapper( Assignment decoratedAssignment, List<Type> thrownTypesToExclude ) {
super( decoratedAssignment ); super( decoratedAssignment );
this.exceptionTypesToExclude = exceptionTypesToExclude; this.thrownTypesToExclude = thrownTypesToExclude;
} }
@Override @Override
public List<Type> getExceptionTypes() { public List<Type> getThrownTypes() {
List<Type> parentExceptionTypes = super.getExceptionTypes(); List<Type> parentThrownTypes = super.getThrownTypes();
List<Type> result = new ArrayList<Type>( parentExceptionTypes ); List<Type> result = new ArrayList<Type>( parentThrownTypes );
for ( Type exceptionTypeToExclude : exceptionTypesToExclude ) { for ( Type thrownTypeToExclude : thrownTypesToExclude ) {
for ( Type parentExceptionType : parentExceptionTypes ) { for ( Type parentThrownType : parentThrownTypes ) {
if ( parentExceptionType.isAssignableTo( exceptionTypeToExclude ) ) { if ( parentThrownType.isAssignableTo( thrownTypeToExclude ) ) {
result.remove( parentExceptionType ); result.remove( parentThrownType );
} }
} }
} }

View File

@ -29,24 +29,23 @@ import org.mapstruct.ap.model.common.Type;
*/ */
public class UpdateWrapper extends AssignmentWrapper { public class UpdateWrapper extends AssignmentWrapper {
private final List<Type> exceptionTypesToExclude; private final List<Type> thrownTypesToExclude;
private final Assignment factoryMethod; private final Assignment factoryMethod;
public UpdateWrapper(Assignment decoratedAssignment, List<Type> exceptionTypesToExclude, public UpdateWrapper(Assignment decoratedAssignment, List<Type> thrownTypesToExclude, Assignment factoryMethod ) {
Assignment factoryMethod ) {
super( decoratedAssignment ); super( decoratedAssignment );
this.exceptionTypesToExclude = exceptionTypesToExclude; this.thrownTypesToExclude = thrownTypesToExclude;
this.factoryMethod = factoryMethod; this.factoryMethod = factoryMethod;
} }
@Override @Override
public List<Type> getExceptionTypes() { public List<Type> getThrownTypes() {
List<Type> parentExceptionTypes = super.getExceptionTypes(); List<Type> parentThrownTypes = super.getThrownTypes();
List<Type> result = new ArrayList<Type>( parentExceptionTypes ); List<Type> result = new ArrayList<Type>( parentThrownTypes );
for ( Type exceptionTypeToExclude : exceptionTypesToExclude ) { for ( Type thrownTypeToExclude : thrownTypesToExclude ) {
for ( Type parentExceptionType : parentExceptionTypes ) { for ( Type parentThrownType : parentThrownTypes ) {
if ( parentExceptionType.isAssignableTo( exceptionTypeToExclude ) ) { if ( parentThrownType.isAssignableTo( thrownTypeToExclude ) ) {
result.remove( parentExceptionType ); result.remove( parentThrownType );
} }
} }
} }

View File

@ -18,7 +18,7 @@
limitations under the License. limitations under the License.
--> -->
<#if (exceptionTypes?size == 0) > <#if (thrownTypes?size == 0) >
for ( <@includeModel object=sourceType/> ${iteratorReference} : ${sourceReference} ) { for ( <@includeModel object=sourceType/> ${iteratorReference} : ${sourceReference} ) {
${ext.targetBeanName}.${ext.targetWriteAccessorName}( <@includeModel object=assignment ${ext.targetBeanName}.${ext.targetWriteAccessorName}( <@includeModel object=assignment
targetBeanName=ext.targetBeanName targetBeanName=ext.targetBeanName
@ -38,7 +38,7 @@
targetType=ext.targetType/> ); targetType=ext.targetType/> );
} }
} }
<#list exceptionTypes as exceptionType> <#list thrownTypes as exceptionType>
catch ( <@includeModel object=exceptionType/> e ) { catch ( <@includeModel object=exceptionType/> e ) {
throw new RuntimeException( e ); throw new RuntimeException( e );
} }

View File

@ -18,7 +18,7 @@
limitations under the License. limitations under the License.
--> -->
<#if (exceptionTypes?size == 0) > <#if (thrownTypes?size == 0) >
<@includeModel object=ext.targetType/> ${localVarName} = <@_assignment/>; <@includeModel object=ext.targetType/> ${localVarName} = <@_assignment/>;
${ext.targetBeanName}.${ext.targetWriteAccessorName}( Arrays.copyOf( ${localVarName}, ${localVarName}.length ) ); ${ext.targetBeanName}.${ext.targetWriteAccessorName}( Arrays.copyOf( ${localVarName}, ${localVarName}.length ) );
<#else> <#else>
@ -26,7 +26,7 @@
<@includeModel object=ext.targetType/> ${localVarName} = <@_assignment/>; <@includeModel object=ext.targetType/> ${localVarName} = <@_assignment/>;
${ext.targetBeanName}.${ext.targetWriteAccessorName}( Arrays.copyOf( ${localVarName}, ${localVarName}.length ) ); ${ext.targetBeanName}.${ext.targetWriteAccessorName}( Arrays.copyOf( ${localVarName}, ${localVarName}.length ) );
} }
<#list exceptionTypes as exceptionType> <#list thrownTypes as exceptionType>
catch ( <@includeModel object=exceptionType/> e ) { catch ( <@includeModel object=exceptionType/> e ) {
throw new RuntimeException( e ); throw new RuntimeException( e );
} }

View File

@ -22,13 +22,13 @@ if ( ${ext.targetBeanName}.${ext.targetWriteAccessorName}() != null ) {
<#if ext.existingInstanceMapping> <#if ext.existingInstanceMapping>
${ext.targetBeanName}.${ext.targetWriteAccessorName}().clear(); ${ext.targetBeanName}.${ext.targetWriteAccessorName}().clear();
</#if> </#if>
<#if (exceptionTypes?size == 0) > <#if (thrownTypes?size == 0) >
<@_assignmentLine/> <@_assignmentLine/>
<#else> <#else>
try { try {
<@_assignmentLine/> <@_assignmentLine/>
} }
<#list exceptionTypes as exceptionType> <#list thrownTypes as exceptionType>
catch ( <@includeModel object=exceptionType/> e ) { catch ( <@includeModel object=exceptionType/> e ) {
throw new RuntimeException( e ); throw new RuntimeException( e );
} }

View File

@ -18,14 +18,14 @@
limitations under the License. limitations under the License.
--> -->
<#if (exceptionTypes?size == 0) > <#if (thrownTypes?size == 0) >
<#if !ext.isTargetDefined?? ><@includeModel object=ext.targetType/></#if> ${ext.targetWriteAccessorName} = <@_assignment/>; <#if !ext.isTargetDefined?? ><@includeModel object=ext.targetType/></#if> ${ext.targetWriteAccessorName} = <@_assignment/>;
<#else> <#else>
<#if !ext.isTargetDefined?? ><@includeModel object=ext.targetType/> ${ext.targetWriteAccessorName};</#if> <#if !ext.isTargetDefined?? ><@includeModel object=ext.targetType/> ${ext.targetWriteAccessorName};</#if>
try { try {
${ext.targetWriteAccessorName} = <@_assignment/>; ${ext.targetWriteAccessorName} = <@_assignment/>;
} }
<#list exceptionTypes as exceptionType> <#list thrownTypes as exceptionType>
catch ( <@includeModel object=exceptionType/> e ) { catch ( <@includeModel object=exceptionType/> e ) {
throw new RuntimeException( e ); throw new RuntimeException( e );
} }

View File

@ -18,13 +18,13 @@
limitations under the License. limitations under the License.
--> -->
<#if (exceptionTypes?size == 0) > <#if (thrownTypes?size == 0) >
${ext.targetBeanName}.${ext.targetWriteAccessorName}( <@_assignment/> ); ${ext.targetBeanName}.${ext.targetWriteAccessorName}( <@_assignment/> );
<#else> <#else>
try { try {
${ext.targetBeanName}.${ext.targetWriteAccessorName}( <@_assignment/> ); ${ext.targetBeanName}.${ext.targetWriteAccessorName}( <@_assignment/> );
} }
<#list exceptionTypes as exceptionType> <#list thrownTypes as exceptionType>
catch ( <@includeModel object=exceptionType/> e ) { catch ( <@includeModel object=exceptionType/> e ) {
throw new RuntimeException( e ); throw new RuntimeException( e );
} }

View File

@ -18,13 +18,13 @@
limitations under the License. limitations under the License.
--> -->
<#if (exceptionTypes?size == 0) > <#if (thrownTypes?size == 0) >
<@_assignment/>; <@_assignment/>;
<#else> <#else>
try { try {
<@_assignment/>; <@_assignment/>;
} }
<#list exceptionTypes as exceptionType> <#list thrownTypes as exceptionType>
catch ( <@includeModel object=exceptionType/> e ) { catch ( <@includeModel object=exceptionType/> e ) {
throw new RuntimeException( e ); throw new RuntimeException( e );
} }