diff options
author | acolyer <acolyer> | 2005-06-09 14:44:30 +0000 |
---|---|---|
committer | acolyer <acolyer> | 2005-06-09 14:44:30 +0000 |
commit | a4a4da472ba4482e67eda77e130166226ca00a09 (patch) | |
tree | c88c7b440f3b455c0fa26781ecdca29bb2ed5e79 /weaver/testsrc/org | |
parent | 376c9ac4f17462fbe4537ef9ff5b66f315901358 (diff) | |
download | aspectj-a4a4da472ba4482e67eda77e130166226ca00a09.tar.gz aspectj-a4a4da472ba4482e67eda77e130166226ca00a09.zip |
first batch of updates for generics :- largely parsing plus storage of type variable patterns, plus a few tweaks to visitor pattern
Diffstat (limited to 'weaver/testsrc/org')
4 files changed, 175 insertions, 2 deletions
diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java index 3ca01ffc0..2b80740c7 100644 --- a/weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java @@ -17,10 +17,13 @@ import junit.framework.TestCase; import org.aspectj.weaver.BcweaverTests; import org.aspectj.weaver.Shadow; +import org.aspectj.weaver.TypeX; import org.aspectj.weaver.World; import org.aspectj.weaver.bcel.BcelShadow; import org.aspectj.weaver.bcel.BcelWorld; +import sun.reflect.generics.tree.TypeVariableSignature; + /** * @author hugunin * @@ -229,6 +232,154 @@ public class ParserTestCase extends TestCase { assertEquals("@args(Foo, Goo, ANY, .., Moo)",p.toString()); } + public void testParseSimpleTypeVariable() { + PatternParser parser = new PatternParser("T"); + TypeVariable tv = parser.parseTypeVariable(); + TypeVariable expected = new TypeVariable("T"); + assertEquals("Expected simple type variable T",expected,tv); + } + + public void testParseExtendingTypeVariable() { + PatternParser parser = new PatternParser("T extends Number"); + TypeVariable tv = parser.parseTypeVariable(); + TypeVariable expected = new TypeVariable("T",new PatternParser("Number").parseTypePattern()); + assertEquals("Expected type variable T extends Number",expected,tv); + } + + public void testParseExtendingTypeVariableWithPattern() { + PatternParser parser = new PatternParser("T extends Number+"); + TypeVariable tv = parser.parseTypeVariable(); + TypeVariable expected = new TypeVariable("T",new PatternParser("Number+").parseTypePattern()); + assertEquals("Expected type variable T extends Number+",expected,tv); + } + + public void testParseExtendingTypeVariableWithInterface() { + PatternParser parser = new PatternParser("T extends Number & Comparable"); + TypeVariable tv = parser.parseTypeVariable(); + TypeVariable expected = new TypeVariable("T",new PatternParser("Number").parseTypePattern(), + new TypePattern[] {new PatternParser("Comparable").parseTypePattern()},null); + assertEquals("Expected type variable T extends Number",expected,tv); + } + + public void testParseExtendingTypeVariableWithInterfaceList() { + PatternParser parser = new PatternParser("T extends Number & Comparable & Cloneable"); + TypeVariable tv = parser.parseTypeVariable(); + TypeVariable expected = new TypeVariable("T",new PatternParser("Number").parseTypePattern(), + new TypePattern[] {new PatternParser("Comparable").parseTypePattern(), + new PatternParser("Cloneable").parseTypePattern()},null); + assertEquals("Expected type variable T extends Number",expected,tv); + } + + public void testParseTypeParameterList() { + PatternParser parser = new PatternParser("<T>"); + TypeVariablePatternList list = parser.maybeParseTypeVariableList(); + TypeVariable[] patterns = list.getTypeVariablePatterns(); + TypeVariable expected = new TypeVariable("T"); + assertEquals("Expected simple type variable T",expected,patterns[0]); + assertEquals("One pattern in list",1,patterns.length); + } + + public void testParseTypeParameterListWithSeveralTypeParameters() { + PatternParser parser = new PatternParser("<T,S extends Number, R>"); + TypeVariablePatternList list = parser.maybeParseTypeVariableList(); + TypeVariable[] patterns = list.getTypeVariablePatterns(); + TypeVariable expected0 = new TypeVariable("T"); + assertEquals("Expected simple type variable T",expected0,patterns[0]); + TypeVariable expected1 = new TypeVariable("S",new PatternParser("Number").parseTypePattern()); + assertEquals("Expected type variable S extends Number",expected1,patterns[1]); + TypeVariable expected2 = new TypeVariable("R"); + assertEquals("Expected simple type variable R",expected2,patterns[2]); + + assertEquals("3 patterns in list",3,patterns.length); + } + + + public void testParseAllowedSuperInTypeVariable() { + PatternParser parser = new PatternParser("T super Number+"); + TypeVariable tv = parser.parseTypeVariable(); + TypeVariable expected = new TypeVariable("T",new ExactTypePattern(TypeX.OBJECT,false,false),null,new PatternParser("Number+").parseTypePattern()); + assertEquals("Expected type variable T super Number+",expected,tv); + } + + public void testParseAnythingTypeVariable() { + PatternParser parser = new PatternParser("?"); + WildTypePattern tp = (WildTypePattern) parser.parseTypePattern(true,false); + assertEquals("Expected type variable ?","?",tp.maybeGetSimpleName()); + } + + public void testParseAnythingExtendsTypeVariable() { + PatternParser parser = new PatternParser("? extends Number"); + WildTypePattern tp = (WildTypePattern) parser.parseTypePattern(true,false); + assertEquals("Expected type variable ?","?",tp.maybeGetSimpleName()); + assertEquals("upper Bound of Number",new PatternParser("Number").parseTypePattern(),tp.getUpperBound()); + } + + public void testParseAnythingSuperTypeVariable() { + PatternParser parser = new PatternParser("? super Number+"); + WildTypePattern tp = (WildTypePattern) parser.parseTypePattern(true,false); + assertEquals("Expected type variable ?","?",tp.maybeGetSimpleName()); + assertEquals("lower Bound of Number+",new PatternParser("Number+").parseTypePattern(),tp.getLowerBound()); + } + + public void testParseDeclareParentsWithTypeParameterList() { + PatternParser parser = new PatternParser("declare parents : <T> Foo<T> implements IveGoneMad"); + DeclareParents decp = (DeclareParents) parser.parseDeclare(); + TypeVariablePatternList tvp = decp.getTypeParameters(); + assertEquals("one type parameter",1,tvp.getTypeVariablePatterns().length); + assertEquals("expecting T","T",tvp.getTypeVariablePatterns()[0].getName()); + } + + public void testParameterizedTypePatternsAny() { + PatternParser parser = new PatternParser("*<T,S extends Number>"); + WildTypePattern wtp = (WildTypePattern) parser.parseTypePattern(false,true); + TypePatternList tvs = wtp.getTypeParameters(); + assertEquals("2 type parameters",2,tvs.getTypePatterns().length); + assertEquals("T",new PatternParser("T").parseTypePattern(),tvs.getTypePatterns()[0]); + assertEquals("S extends Number",new PatternParser("S extends Number").parseTypePattern(false,true),tvs.getTypePatterns()[1]); + } + + public void testParameterizedTypePatternsSimple() { + PatternParser parser = new PatternParser("List<String>"); + WildTypePattern wtp = (WildTypePattern) parser.parseTypePattern(); + TypePatternList tvs = wtp.getTypeParameters(); + assertEquals("1 type parameter",1,tvs.getTypePatterns().length); + assertEquals("String",new PatternParser("String").parseTypePattern(),tvs.getTypePatterns()[0]); + assertEquals("List",wtp.getNamePatterns()[0].toString()); + } + + public void testNestedParameterizedTypePatterns() { + PatternParser parser = new PatternParser("List<List<List<String>>>"); + WildTypePattern wtp = (WildTypePattern) parser.parseTypePattern(); + TypePatternList typeParameters = wtp.getTypeParameters(); + WildTypePattern expected = (WildTypePattern) typeParameters.getTypePatterns()[0]; + assertEquals("expecting a List", "List",expected.maybeGetSimpleName()); + typeParameters = expected.getTypeParameters(); + expected = (WildTypePattern) typeParameters.getTypePatterns()[0]; + assertEquals("expecting a List", "List",expected.maybeGetSimpleName()); + typeParameters = expected.getTypeParameters(); + expected = (WildTypePattern) typeParameters.getTypePatterns()[0]; + assertEquals("expecting a String", "String",expected.maybeGetSimpleName()); + } + + public void testSimpleTypeVariableList() { + PatternParser parser = new PatternParser("<T,S,V>"); + TypeVariablePatternList tl = parser.maybeParseSimpleTypeVariableList(); + TypeVariable[] patterns = tl.getTypeVariablePatterns(); + assertEquals("3 patterns",3,patterns.length); + assertEquals("T",new TypeVariable("T"),patterns[0]); + assertEquals("S",new TypeVariable("S"),patterns[1]); + assertEquals("V",new TypeVariable("V"),patterns[2]); + } + + public void testSimpleTypeVariableListError() { + PatternParser parser = new PatternParser("<T extends Number>"); + try { + TypeVariablePatternList tl = parser.maybeParseSimpleTypeVariableList(); + } catch (ParserException ex) { + assertEquals("Expecting >",">",ex.getMessage()); + } + } + public TestScope makeSimpleScope() { TestScope s = new TestScope(new String[] {"int", "java.lang.String"}, new String[] {"a", "b"}, world); s.setImportedPrefixes(new String[]{"p."}); diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/PointcutTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/PointcutTestCase.java index 039bf89d5..857c82171 100644 --- a/weaver/testsrc/org/aspectj/weaver/patterns/PointcutTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/patterns/PointcutTestCase.java @@ -31,6 +31,10 @@ public class PointcutTestCase extends TestCase { public void testMatchJP() { Pointcut p = new Pointcut() { + public Object accept(PatternNodeVisitor visitor, Object data) { + return visitor.visit(this,data); + } + public Set couldMatchKinds() { return null; } @@ -38,6 +42,10 @@ public class PointcutTestCase extends TestCase { public FuzzyBoolean fastMatch(FastMatchInfo info) { return null; } + + public FuzzyBoolean fastMatch(Class targetClass) { + return null; + } protected FuzzyBoolean matchInternal(Shadow shadow) { return null; diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/VisitorTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/VisitorTestCase.java index b3a2a73bf..12218df8b 100644 --- a/weaver/testsrc/org/aspectj/weaver/patterns/VisitorTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/patterns/VisitorTestCase.java @@ -50,7 +50,7 @@ public class VisitorTestCase extends TestCase { for (Iterator iterator = pointcuts.iterator(); iterator.hasNext();) { String pointcut = (String) iterator.next(); try { - PointcutVisitor.DumpPointcutVisitor.check(pointcut); + PatternNodeVisitor.DumpPointcutVisitor.check(pointcut); } catch (Throwable t) { t.printStackTrace(); fail("Failed on '"+pointcut+"': " +t.toString()); @@ -66,7 +66,7 @@ public class VisitorTestCase extends TestCase { String tp = (String) iterator.next(); try { TypePattern p = new PatternParser(tp).parseTypePattern(); - PointcutVisitor.DumpPointcutVisitor.check(p, true); + PatternNodeVisitor.DumpPointcutVisitor.check(p, true); } catch (Throwable t) { fail("Failed on '"+tp+"': " +t.toString()); } diff --git a/weaver/testsrc/org/aspectj/weaver/tools/PointcutExpressionTest.java b/weaver/testsrc/org/aspectj/weaver/tools/PointcutExpressionTest.java index 411716b95..6e3e3d35e 100644 --- a/weaver/testsrc/org/aspectj/weaver/tools/PointcutExpressionTest.java +++ b/weaver/testsrc/org/aspectj/weaver/tools/PointcutExpressionTest.java @@ -468,6 +468,20 @@ public class PointcutExpressionTest extends TestCase { PointcutExpression ex = p.parsePointcutExpression("staticinitialization(*..A+)"); assertEquals("staticinitialization(*..A+)",ex.getPointcutExpression()); } + + public void testCouldMatchJoinPointsInType() { + PointcutExpression ex = p.parsePointcutExpression("execution(* org.aspectj.weaver.tools.PointcutExpressionTest.B.*(..))"); + assertFalse("Could never match String",ex.couldMatchJoinPointsInType(String.class)); + assertTrue("Will always match B",ex.couldMatchJoinPointsInType(B.class)); + assertFalse("Does not match A",ex.couldMatchJoinPointsInType(A.class)); + } + + public void testMayNeedDynamicTest() { + PointcutExpression ex = p.parsePointcutExpression("execution(* org.aspectj.weaver.tools.PointcutExpressionTest.B.*(..))"); + assertFalse("No dynamic test needed",ex.mayNeedDynamicTest()); + ex = p.parsePointcutExpression("execution(* org.aspectj.weaver.tools.PointcutExpressionTest.B.*(..)) && args(X)"); + assertTrue("Dynamic test needed",ex.mayNeedDynamicTest()); + } protected void setUp() throws Exception { super.setUp(); |