From 89756cdfe58319d4e8e29b88de6fd8810d84244d Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Wed, 15 Feb 2012 14:25:02 -0800 Subject: [PATCH] 371684 - wildcard generics unpacking --- .../src/org/aspectj/weaver/TypeFactory.java | 17 +++++++- .../systemtest/ajc170/Ajc170Tests.java | 39 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/TypeFactory.java b/org.aspectj.matcher/src/org/aspectj/weaver/TypeFactory.java index 19baaacb0..f22d14a0f 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/TypeFactory.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/TypeFactory.java @@ -144,7 +144,7 @@ public class TypeFactory { return new UnresolvedType(signature, signatureErasure, typeParams); } // can't replace above with convertSigToType - leads to stackoverflow - } else if ((firstChar == '?' || firstChar == '*') && signature.length() == 1) { + } else if ((firstChar == '?' || firstChar == '*') && signature.length()==1) { return WildcardedUnresolvedType.QUESTIONMARK; } else if (firstChar == '+') { // ? extends ... @@ -297,6 +297,21 @@ public class TypeFactory { case '>': anglies--; break; + case '*': + if (anglies==0) { + int nextCharPos = endOfSig+1; + if (nextCharPos>=remainingToProcess.length()) { + sigFound=true; + } else { + char nextChar = remainingToProcess.charAt(nextCharPos); + if (!(nextChar=='+' || nextChar=='-')) { + // dont need to set endOfSig as the loop will increment + // it to the right place before it exits + sigFound=true; + } + } + } + break; case '[': if (anglies == 0) { // the next char might be a [ or a primitive type ref (BCDFIJSZ) diff --git a/tests/src/org/aspectj/systemtest/ajc170/Ajc170Tests.java b/tests/src/org/aspectj/systemtest/ajc170/Ajc170Tests.java index a6102fd08..4e40d4162 100644 --- a/tests/src/org/aspectj/systemtest/ajc170/Ajc170Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc170/Ajc170Tests.java @@ -11,16 +11,55 @@ package org.aspectj.systemtest.ajc170; import java.io.File; +import java.util.List; import junit.framework.Test; +import org.aspectj.apache.bcel.util.ClassPath; import org.aspectj.testing.XMLBasedAjcTestCase; +import org.aspectj.weaver.CrosscuttingMembers; +import org.aspectj.weaver.ReferenceType; +import org.aspectj.weaver.ResolvedMember; +import org.aspectj.weaver.ResolvedType; +import org.aspectj.weaver.TypeFactory; +import org.aspectj.weaver.TypeVariable; +import org.aspectj.weaver.UnresolvedType; +import org.aspectj.weaver.World; +import org.aspectj.weaver.bcel.BcelWorld; /** * @author Andy Clement */ public class Ajc170Tests extends org.aspectj.testing.XMLBasedAjcTestCase { + public void testGenericsWithTwoTypeParamsOneWildcard() { + UnresolvedType ut; + + ut = TypeFactory.createTypeFromSignature("LFoo<**>;"); + assertEquals(2,ut.getTypeParameters().length); + + ut = TypeFactory.createTypeFromSignature("LFoo<***>;"); + assertEquals(3,ut.getTypeParameters().length); + + ut = TypeFactory.createTypeFromSignature("LFoo;"); + assertEquals(2,ut.getTypeParameters().length); + + ut = TypeFactory.createTypeFromSignature("LFoo<*+Ljava/lang/String;TP;>;"); + assertEquals(2,ut.getTypeParameters().length); + + ut = TypeFactory.createTypeFromSignature("LFoo<*+Ljava/lang/String;TP;>;"); + assertEquals(2,ut.getTypeParameters().length); + + ut = TypeFactory.createTypeFromSignature("LFoo<*TT;>;"); + assertEquals(2,ut.getTypeParameters().length); + + ut = TypeFactory.createTypeFromSignature("LFoo<[I>;"); + assertEquals(1,ut.getTypeParameters().length); + + ut = TypeFactory.createTypeFromSignature("LFoo<[I[Z>;"); + assertEquals(2,ut.getTypeParameters().length); + } + public void testPerThis() { runTest("perthis"); } -- 2.39.5