diff --git a/processor/src/main/java/org/mapstruct/ap/model/DefaultMapperReference.java b/processor/src/main/java/org/mapstruct/ap/model/DefaultMapperReference.java index 9d4659b54..787b9c0fe 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/DefaultMapperReference.java +++ b/processor/src/main/java/org/mapstruct/ap/model/DefaultMapperReference.java @@ -18,7 +18,6 @@ */ package org.mapstruct.ap.model; -import java.beans.Introspector; import java.util.List; import java.util.Set; @@ -52,7 +51,7 @@ public class DefaultMapperReference extends MapperReference { } String variableName = Strings.getSaveVariableName( - Introspector.decapitalize( type.getName() ), + type.getName(), otherMapperReferences ); diff --git a/processor/src/main/java/org/mapstruct/ap/model/IterableMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/model/IterableMappingMethod.java index b4287f372..e94ef2754 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/IterableMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/model/IterableMappingMethod.java @@ -18,7 +18,6 @@ */ package org.mapstruct.ap.model; -import java.beans.Introspector; import java.util.Set; import org.mapstruct.ap.model.common.Parameter; @@ -77,12 +76,8 @@ public class IterableMappingMethod extends MappingMethod { public String getLoopVariableName() { return Strings.getSaveVariableName( - Introspector.decapitalize( - getSourceParameter().getType() - .getTypeParameters() - .get( 0 ) - .getName() - ), getParameterNames() + getSourceParameter().getType().getTypeParameters().get( 0 ).getName(), + getParameterNames() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/model/MappingMethod.java b/processor/src/main/java/org/mapstruct/ap/model/MappingMethod.java index a05497596..d313f8f98 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/MappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/model/MappingMethod.java @@ -18,7 +18,6 @@ */ package org.mapstruct.ap.model; -import java.beans.Introspector; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -75,7 +74,7 @@ public abstract class MappingMethod extends ModelElement { public String getResultName() { return targetParameter != null ? targetParameter.getName() : - Strings.getSaveVariableName( Introspector.decapitalize( getResultType().getName() ), getParameterNames() ); + Strings.getSaveVariableName( getResultType().getName(), getParameterNames() ); } public Type getReturnType() { diff --git a/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java index 1ef4251df..bbdcbbf6b 100644 --- a/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java @@ -18,7 +18,6 @@ */ package org.mapstruct.ap.processor; -import java.beans.Introspector; import java.text.MessageFormat; import java.util.ArrayList; import java.util.HashMap; @@ -27,7 +26,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; - import javax.annotation.processing.Messager; import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; @@ -601,7 +599,7 @@ public class MapperCreationProcessor implements ModelElementProcessor iterable, String separator) { @@ -118,7 +122,19 @@ public class Strings { return getSaveVariableName( name, Arrays.asList( existingVariableNames ) ); } + /** + * Returns a variable name which doesn't conflict with the given variable names existing in the same scope and the + * Java keywords. + * + * @param name the name to get a safe version for + * @param existingVariableNames the names of other variables existing in the same scope + * + * @return a variable name based on the given original name, not conflicting with any of the given other names or + * any Java keyword; starting with a lower-case letter + */ public static String getSaveVariableName(String name, Collection existingVariableNames) { + name = decapitalize( name ); + Set conflictingNames = new HashSet( KEYWORDS ); conflictingNames.addAll( existingVariableNames );