diff options
author | aclement <aclement> | 2008-10-20 18:31:30 +0000 |
---|---|---|
committer | aclement <aclement> | 2008-10-20 18:31:30 +0000 |
commit | 83fad50ca5effa81e73b6fa8f159d175fcaab599 (patch) | |
tree | 76768c9c3e941eb81a74351ad13068812c2154cc /weaver/testsrc | |
parent | f479c18ec097f4d3d1dcbfcd5e1881678425b820 (diff) | |
download | aspectj-83fad50ca5effa81e73b6fa8f159d175fcaab599.tar.gz aspectj-83fad50ca5effa81e73b6fa8f159d175fcaab599.zip |
246125: promoted generic sig parsing code to util
Diffstat (limited to 'weaver/testsrc')
3 files changed, 131 insertions, 50 deletions
diff --git a/weaver/testsrc/org/aspectj/weaver/BcweaverModuleTests.java b/weaver/testsrc/org/aspectj/weaver/BcweaverModuleTests.java index 84853ac33..2090ed446 100644 --- a/weaver/testsrc/org/aspectj/weaver/BcweaverModuleTests.java +++ b/weaver/testsrc/org/aspectj/weaver/BcweaverModuleTests.java @@ -1,4 +1,5 @@ package org.aspectj.weaver; + /* ******************************************************************* * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). * All rights reserved. @@ -12,7 +13,6 @@ package org.aspectj.weaver; * ******************************************************************/ // default package - import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; @@ -21,16 +21,19 @@ import org.aspectj.weaver.tools.ToolsTests; public class BcweaverModuleTests extends TestCase { - public static Test suite() { - TestSuite suite = new TestSuite(BcweaverModuleTests.class.getName()); - suite.addTest(org.aspectj.weaver.bcel.BcelTests.suite()); - suite.addTest(org.aspectj.weaver.BcweaverTests.suite()); - suite.addTest(org.aspectj.weaver.patterns.PatternsTests.suite()); - suite.addTestSuite(LocaleTest.class); - suite.addTest(ToolsTests.suite()); - return suite; - } + public static Test suite() { + TestSuite suite = new TestSuite(BcweaverModuleTests.class.getName()); + suite.addTest(org.aspectj.weaver.bcel.BcelTests.suite()); + suite.addTest(org.aspectj.weaver.BcweaverTests.suite()); + suite.addTest(org.aspectj.weaver.patterns.PatternsTests.suite()); + suite.addTestSuite(LocaleTest.class); + suite.addTestSuite(GenericSignatureParserTest.class); + suite.addTest(ToolsTests.suite()); + return suite; + } - public BcweaverModuleTests(String name) { super(name); } + public BcweaverModuleTests(String name) { + super(name); + } -} +} diff --git a/weaver/testsrc/org/aspectj/weaver/GenericSignatureParserTest.java b/weaver/testsrc/org/aspectj/weaver/GenericSignatureParserTest.java new file mode 100644 index 000000000..e5948eb40 --- /dev/null +++ b/weaver/testsrc/org/aspectj/weaver/GenericSignatureParserTest.java @@ -0,0 +1,63 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * ******************************************************************/ + package org.aspectj.weaver; + +import junit.framework.TestCase; + +import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.classfile.Method; +import org.aspectj.apache.bcel.util.SyntheticRepository; +import org.aspectj.util.GenericSignatureParser; + +/** + * @author Adrian Colyer + * @author Andy Clement + */ +public class GenericSignatureParserTest extends TestCase { + + GenericSignatureParser parser; + + protected void setUp() throws Exception { + super.setUp(); + parser = new GenericSignatureParser(); + } + + public void testClassSignatureParsingInJDK() throws Exception { + SyntheticRepository repository = SyntheticRepository.getInstance(); + String[] testClasses = new String[] { "java.lang.Comparable", "java.lang.Iterable", "java.lang.Class", "java.lang.Enum", + "java.lang.InheritableThreadLocal", "java.lang.ThreadLocal", "java.util.Collection", "java.util.Comparator", + "java.util.Enumeration", "java.util.Iterator", "java.util.List", "java.util.ListIterator", "java.util.Map", + "java.util.Map$Entry", "java.util.Queue", "java.util.Set", "java.util.SortedMap", "java.util.SortedSet" }; + for (int i = 0; i < testClasses.length; i++) { + JavaClass jc = repository.loadClass(testClasses[i]); + String sig = jc.getGenericSignature(); + parser.parseAsClassSignature(sig); + } + } + + public void testMethodSignatureParsingInJDK() throws Exception { + SyntheticRepository repository = SyntheticRepository.getInstance(); + String[] testClasses = new String[] { "java.lang.Comparable", "java.lang.Iterable", "java.lang.Class", "java.lang.Enum", + "java.lang.InheritableThreadLocal", "java.lang.ThreadLocal", "java.util.Collection", "java.util.Comparator", + "java.util.Enumeration", "java.util.Iterator", "java.util.List", "java.util.ListIterator", "java.util.Map", + "java.util.Map$Entry", "java.util.Queue", "java.util.Set", "java.util.SortedMap", "java.util.SortedSet" }; + for (int i = 0; i < testClasses.length; i++) { + JavaClass jc = repository.loadClass(testClasses[i]); + Method[] methods = jc.getMethods(); + for (int j = 0; j < methods.length; j++) { + String sig = methods[j].getGenericSignature(); + if (sig != null) + parser.parseAsMethodSignature(sig); + } + } + } + +} diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/BcelGenericSignatureToTypeXTestCase.java b/weaver/testsrc/org/aspectj/weaver/bcel/BcelGenericSignatureToTypeXTestCase.java index 168400e91..9ba0b1943 100644 --- a/weaver/testsrc/org/aspectj/weaver/bcel/BcelGenericSignatureToTypeXTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/bcel/BcelGenericSignatureToTypeXTestCase.java @@ -14,59 +14,74 @@ package org.aspectj.weaver.bcel; import junit.framework.TestCase; import org.aspectj.apache.bcel.Repository; -import org.aspectj.apache.bcel.classfile.GenericSignatureParser; import org.aspectj.apache.bcel.classfile.JavaClass; import org.aspectj.apache.bcel.classfile.Signature; +import org.aspectj.util.GenericSignature; +import org.aspectj.util.GenericSignatureParser; +import org.aspectj.util.GenericSignature.ClassSignature; import org.aspectj.weaver.UnresolvedType; /** * @author colyer - * + * */ public class BcelGenericSignatureToTypeXTestCase extends TestCase { + public final GenericSignature.ClassSignature getGenericClassTypeSignature(JavaClass jClass) { + Signature sig = jClass.getSignatureAttribute(); + if (sig != null) { + GenericSignatureParser parser = new GenericSignatureParser(); + ClassSignature classSig = parser.parseAsClassSignature(sig.getSignature()); + return classSig; + } + return null; + } + + // public final GenericSignature.MethodTypeSignature getGenericMethodTypeSignature(JavaClass jClass) { + // Signature sig = jClass.getSignatureAttribute(); + // if (sig != null) { + // GenericSignatureParser parser = new GenericSignatureParser(); + // MethodTypeSignature mSig = parser.parseAsMethodSignature(sig); + // return mSig; + // } + // return null; + // } + + // public FieldTypeSignature asFieldTypeSignature() { + // if (fieldSig == null) { + // GenericSignatureParser parser = new GenericSignatureParser(); + // fieldSig = parser.parseAsFieldSignature(getSignature()); + // } + // return fieldSig; + // } + public void testEnumFromHell() throws Exception { BcelWorld world = new BcelWorld(); JavaClass javaLangEnum = Repository.lookupClass("java/lang/Enum"); - Signature.ClassSignature cSig = javaLangEnum.getGenericClassTypeSignature(); - UnresolvedType superclass = - BcelGenericSignatureToTypeXConverter.classTypeSignature2TypeX( - cSig.superclassSignature, - cSig.formalTypeParameters, - world - ); - assertEquals("Ljava/lang/Object;",superclass.getSignature()); - assertEquals("2 superinterfaces",2,cSig.superInterfaceSignatures.length); - UnresolvedType comparable = - BcelGenericSignatureToTypeXConverter.classTypeSignature2TypeX( - cSig.superInterfaceSignatures[0], - cSig.formalTypeParameters, - world - ); - assertEquals("Pjava/lang/Comparable<TE;>;",comparable.getSignature()); - UnresolvedType serializable = - BcelGenericSignatureToTypeXConverter.classTypeSignature2TypeX( - cSig.superInterfaceSignatures[1], - cSig.formalTypeParameters, - world - ); - assertEquals("Ljava/io/Serializable;",serializable.getSignature()); + GenericSignature.ClassSignature cSig = getGenericClassTypeSignature(javaLangEnum); + UnresolvedType superclass = BcelGenericSignatureToTypeXConverter.classTypeSignature2TypeX(cSig.superclassSignature, + cSig.formalTypeParameters, world); + assertEquals("Ljava/lang/Object;", superclass.getSignature()); + assertEquals("2 superinterfaces", 2, cSig.superInterfaceSignatures.length); + UnresolvedType comparable = BcelGenericSignatureToTypeXConverter.classTypeSignature2TypeX(cSig.superInterfaceSignatures[0], + cSig.formalTypeParameters, world); + assertEquals("Pjava/lang/Comparable<TE;>;", comparable.getSignature()); + UnresolvedType serializable = BcelGenericSignatureToTypeXConverter.classTypeSignature2TypeX( + cSig.superInterfaceSignatures[1], cSig.formalTypeParameters, world); + assertEquals("Ljava/io/Serializable;", serializable.getSignature()); } - + public void testColonColon() throws Exception { BcelWorld world = new BcelWorld(); - Signature.ClassSignature cSig = new GenericSignatureParser().parseAsClassSignature("<T::Ljava/io/Serializable;>Ljava/lang/Object;Ljava/lang/Comparable<TT;>;"); - UnresolvedType resolved = BcelGenericSignatureToTypeXConverter.classTypeSignature2TypeX( - cSig.superclassSignature, - cSig.formalTypeParameters, - world); - assertEquals("Ljava/lang/Object;",resolved.getSignature()); -// UnresolvedType resolvedInt = - BcelGenericSignatureToTypeXConverter.classTypeSignature2TypeX( - cSig.superInterfaceSignatures[0], - cSig.formalTypeParameters, + GenericSignature.ClassSignature cSig = new GenericSignatureParser() + .parseAsClassSignature("<T::Ljava/io/Serializable;>Ljava/lang/Object;Ljava/lang/Comparable<TT;>;"); + UnresolvedType resolved = BcelGenericSignatureToTypeXConverter.classTypeSignature2TypeX(cSig.superclassSignature, + cSig.formalTypeParameters, world); + assertEquals("Ljava/lang/Object;", resolved.getSignature()); + // UnresolvedType resolvedInt = + BcelGenericSignatureToTypeXConverter.classTypeSignature2TypeX(cSig.superInterfaceSignatures[0], cSig.formalTypeParameters, world); - + } - + } |