#147 patch for JDK6 java.lang.AssertionError: isSubtype 15 problem, including some test updates

This commit is contained in:
sjaakd 2014-03-12 23:44:52 +01:00 committed by Andreas Gudian
parent 2b633211dd
commit c10a5a6e31
11 changed files with 171 additions and 21 deletions

View File

@ -123,16 +123,16 @@ public class TypeFactory {
Type implementationType = getImplementationType( mirror );
boolean isIterableType = typeUtils.isSubtype(
mirror,
iterableType
typeUtils.erasure( mirror ),
typeUtils.erasure( iterableType )
);
boolean isCollectionType = typeUtils.isSubtype(
mirror,
collectionType
typeUtils.erasure( mirror ),
typeUtils.erasure( collectionType )
);
boolean isMapType = typeUtils.isSubtype(
mirror,
mapType
typeUtils.erasure( mirror ),
typeUtils.erasure( mapType )
);
boolean isEnumType;

View File

@ -207,7 +207,8 @@ public class MethodMatcher {
}
else {
// check if types are in bound
if ( typeUtils.isSubtype( t.getLowerBound(), p ) && typeUtils.isSubtype( p, t.getUpperBound() ) ) {
if ( typeUtils.isSubtype( typeUtils.erasure( t.getLowerBound() ), typeUtils.erasure( p ) ) &&
typeUtils.isSubtype( typeUtils.erasure( p ), typeUtils.erasure( t.getUpperBound() ) ) ) {
genericTypesMap.put( t, p );
return Boolean.TRUE;
}
@ -227,7 +228,7 @@ public class MethodMatcher {
case DECLARED:
// for example method: String method(? extends String)
// isSubType checks range [subtype, type], e.g. isSubtype [Object, String]==true
return typeUtils.isSubtype( p, extendsBound );
return typeUtils.isSubtype( typeUtils.erasure( p ), extendsBound );
case TYPEVAR:
// for example method: <T extends String & Serializable> T method(? extends T)
@ -249,7 +250,8 @@ public class MethodMatcher {
// for example method: String method(? super String)
// to check super type, we can simply reverse the argument, but that would initially yield
// a result: <type, superType] (so type not included) so we need to check sameType also.
return ( typeUtils.isSubtype( superBound, p ) || typeUtils.isSameType( p, superBound ) );
return ( typeUtils.isSubtype( typeUtils.erasure( superBound ), p ) ||
typeUtils.isSameType( p, superBound ) );
case TYPEVAR:
@ -267,11 +269,9 @@ public class MethodMatcher {
// to check super type, we can simply reverse the argument, but that would initially yield
// a result: <type, superType] (so type not included) so we need to check sameType also.
TypeMirror superBoundAsDeclared = typeParameter.getBounds().get( 0 );
return ( typeUtils.isSubtype( superBoundAsDeclared, p ) || typeUtils.isSameType(
p,
superBoundAsDeclared
) );
return ( typeUtils.isSubtype( typeUtils.erasure( superBoundAsDeclared ),
typeUtils.erasure( p ) ) ||
typeUtils.isSameType( p, superBoundAsDeclared ) );
default:
// does this situation occur?
return Boolean.FALSE;
@ -310,7 +310,8 @@ public class MethodMatcher {
List<? extends TypeMirror> bounds = tpe.getBounds();
if ( t != null && bounds != null ) {
for ( TypeMirror bound : bounds ) {
if ( !( bound.getKind().equals( TypeKind.DECLARED ) && typeUtils.isSubtype( t, bound ) ) ) {
if ( !( bound.getKind().equals( TypeKind.DECLARED ) &&
typeUtils.isSubtype( typeUtils.erasure( t ), typeUtils.erasure( bound ) ) ) ) {
return false;
}
}

View File

@ -158,4 +158,18 @@ public class ConversionTest extends MapperTestBase {
})
public void shouldFailOnSuperBounds2() {
}
@Test
@WithClasses({ ErroneousSource6.class, ErroneousTarget6.class, ErroneousSourceTargetMapper6.class })
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
diagnostics = {
@Diagnostic(type = ErroneousSourceTargetMapper6.class,
kind = javax.tools.Diagnostic.Kind.ERROR,
line = 29,
messageRegExp = "Can't map property \"org.mapstruct.ap.test.conversion.generics.WildCardSuperWrapper"
+ "<java.lang.String> foo\" to"
+ " \"org.mapstruct.ap.test.conversion.generics.WildCardSuperWrapper<java.lang.Integer> foo\"")
})
public void shouldFailOnNonMatchingWildCards() {
}
}

View File

@ -0,0 +1,35 @@
/**
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.conversion.generics;
public class ErroneousSource6 {
private WildCardSuperWrapper<String> foo;
public WildCardSuperWrapper<String> getFoo() {
return foo;
}
public void setFoo(WildCardSuperWrapper<String> foo) {
this.foo = foo;
}
}

View File

@ -0,0 +1,30 @@
/**
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.conversion.generics;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper( uses = GenericTypeMapper.class )
public interface ErroneousSourceTargetMapper6 {
ErroneousSourceTargetMapper6 INSTANCE = Mappers.getMapper( ErroneousSourceTargetMapper6.class );
ErroneousTarget6 sourceToTarget(ErroneousSource6 source);
}

View File

@ -0,0 +1,32 @@
/**
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.conversion.generics;
public class ErroneousTarget6 {
private WildCardSuperWrapper<Integer> foo;
public WildCardSuperWrapper<Integer> getFoo() {
return foo;
}
public void setFoo(WildCardSuperWrapper<Integer> foo) {
this.foo = foo;
}
}

View File

@ -45,11 +45,11 @@ public class FactoryTest extends MapperTestBase {
@Diagnostic(type = BarFactory.class,
kind = javax.tools.Diagnostic.Kind.ERROR,
line = 29,
messageRegExp = "^Ambiguous factory methods: \"org\\.mapstruct\\.ap\\.test\\.erroneous\\."
messageRegExp = "Ambiguous factory methods: \"org\\.mapstruct\\.ap\\.test\\.erroneous\\."
+ "ambiguousfactorymethod\\.Bar createBar\\(\\)\" conflicts with "
+ "\"org\\.mapstruct\\.ap\\.test\\.erroneous\\.ambiguousfactorymethod\\.Bar "
+ "org\\.mapstruct\\.ap\\.test\\.erroneous\\.ambiguousfactorymethod"
+ "\\.a\\.BarFactory\\.createBar\\(\\)\"\\.$")
+ "\\.a\\.BarFactory\\.createBar\\(\\)\"\\")
}
)
public void shouldUseTwoFactoryMethods() {

View File

@ -18,6 +18,7 @@
*/
package org.mapstruct.ap.test.severalsources;
import javax.lang.model.SourceVersion;
import javax.tools.Diagnostic.Kind;
import org.mapstruct.ap.testutil.IssueKey;
@ -101,12 +102,22 @@ public class SeveralSourceParametersTest extends MapperTestBase {
@ExpectedCompilationOutcome(
value = CompilationResult.FAILED,
diagnostics = {
@Diagnostic(type = ErroneousSourceTargetMapper.class,
kind = Kind.ERROR,
line = 29,
messageRegExp = "Several possible source properties for target property \"description\".",
javaVersions = { SourceVersion.RELEASE_6 } ),
@Diagnostic(type = ErroneousSourceTargetMapper.class,
kind = Kind.ERROR,
line = 29,
messageRegExp = "Several possible source properties for target property \"zipCode\".",
javaVersions = { SourceVersion.RELEASE_6 } ),
@Diagnostic(type = ErroneousSourceTargetMapper.class,
kind = Kind.ERROR,
line = 29,
messageRegExp = "Several possible source properties for target property \"street\".")
}
)
})
public void shouldFailToGenerateMappingsForAmbigiousSourceProperty() {
}
}

View File

@ -132,7 +132,7 @@ public abstract class MapperTestBase {
diagnostics.getDiagnostics()
);
CompilationOutcomeDescriptor expectedResult = CompilationOutcomeDescriptor.forExpectedCompilationResult(
testMethod.getAnnotation( ExpectedCompilationOutcome.class )
testMethod.getAnnotation( ExpectedCompilationOutcome.class )
);
if ( expectedResult.getCompilationResult() == CompilationResult.SUCCEEDED ) {
@ -344,4 +344,8 @@ public abstract class MapperTestBase {
return o1.getMessage().compareTo( o2.getMessage() );
}
}
private boolean isJdk6() {
return ( Integer.parseInt( System.getProperty( "java.version" ).split( "\\." )[1]) == 6 );
}
}

View File

@ -19,6 +19,7 @@
package org.mapstruct.ap.testutil.compilation.annotation;
import javax.tools.Diagnostic.Kind;
import javax.lang.model.SourceVersion;
/**
* An expected diagnostic of a compilation.
@ -57,4 +58,11 @@ public @interface Diagnostic {
* diagnostic.
*/
String messageRegExp() default ".*";
/**
* The java version for which this this diagnostic is valid.
*
* @return versions for which this Diagnostic should be evaluated. Default it evaluates for all
*/
SourceVersion[] javaVersions() default { };
}

View File

@ -21,6 +21,7 @@ package org.mapstruct.ap.testutil.compilation.model;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.lang.model.SourceVersion;
import javax.tools.Diagnostic;
import javax.tools.Diagnostic.Kind;
import javax.tools.JavaFileObject;
@ -56,13 +57,27 @@ public class CompilationOutcomeDescriptor {
List<DiagnosticDescriptor> diagnosticDescriptors = new ArrayList<DiagnosticDescriptor>();
for ( org.mapstruct.ap.testutil.compilation.annotation.Diagnostic diagnostic :
expectedCompilationResult.diagnostics() ) {
diagnosticDescriptors.add( DiagnosticDescriptor.forDiagnostic( diagnostic ) );
if ( requiresEvaluation( diagnostic.javaVersions() ) ) {
diagnosticDescriptors.add( DiagnosticDescriptor.forDiagnostic( diagnostic ) );
}
}
return new CompilationOutcomeDescriptor( expectedCompilationResult.value(), diagnosticDescriptors );
}
}
private static boolean requiresEvaluation(SourceVersion[] sourceVersions) {
if ( sourceVersions.length == 0 ) {
return true;
}
for (SourceVersion sourceVersion : sourceVersions) {
if (SourceVersion.latestSupported().equals( sourceVersion ) ) {
return true;
}
}
return false;
}
public static CompilationOutcomeDescriptor forResult(String sourceDir, boolean compilationSuccessful,
List<Diagnostic<? extends JavaFileObject>> diagnostics) {
CompilationResult compilationResult =