From: aclement Date: Fri, 20 Aug 2010 00:16:11 +0000 (+0000) Subject: improvements to the positions for a type pattern - more to do here no doubt X-Git-Tag: V1_6_10RC1~21 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bc0c22604c3c1e273f071c0ae1afa06bd835d1b5;p=aspectj.git improvements to the positions for a type pattern - more to do here no doubt --- diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/patterns/PatternParser.java b/org.aspectj.matcher/src/org/aspectj/weaver/patterns/PatternParser.java index 2cc6d2036..7bb8593a4 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/patterns/PatternParser.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/patterns/PatternParser.java @@ -756,6 +756,7 @@ public class PatternParser { return p; } if (maybeEat("(")) { + int openParenPos = tokenSource.peek(-1).getStart(); TypePattern p = parseTypePattern(insideTypeParameters, false); if ((p instanceof NotTypePattern) && !(ap instanceof AnyAnnotationTypePattern)) { // dont set the annotation on it, we don't want the annotation to be @@ -766,6 +767,7 @@ public class PatternParser { p = setAnnotationPatternForTypePattern(p, ap, parameterAnnotationsPossible); } eat(")"); + int closeParenPos = tokenSource.peek(-1).getStart(); boolean isVarArgs = maybeEat("..."); if (isVarArgs) { p.setIsVarArgs(isVarArgs); @@ -774,9 +776,14 @@ public class PatternParser { if (isIncludeSubtypes) { p.includeSubtypes = true; // need the test because (A+) should not set subtypes to false! } + p.start = openParenPos; + p.end = closeParenPos; return p; } int startPos = tokenSource.peek().getStart(); + if (ap.start!=-1) { + startPos = ap.start; + } TypePattern p = parseSingleTypePattern(insideTypeParameters); int endPos = tokenSource.peek(-1).getEnd(); p = setAnnotationPatternForTypePattern(p, ap, false); @@ -857,6 +864,7 @@ public class PatternParser { eat(")"); return ret; } else { + int atPos = tokenSource.peek(-1).getStart(); TypePattern p = parseSingleTypePattern(); if (maybeEatAdjacent("(")) { values = parseAnnotationValues(); @@ -865,6 +873,7 @@ public class PatternParser { } else { ret = new WildAnnotationTypePattern(p); } + ret.start = atPos; return ret; } } else { diff --git a/org.aspectj.matcher/testsrc/org/aspectj/weaver/patterns/NamePatternParserTestCase.java b/org.aspectj.matcher/testsrc/org/aspectj/weaver/patterns/NamePatternParserTestCase.java index f224b1737..fe3b0f2d4 100644 --- a/org.aspectj.matcher/testsrc/org/aspectj/weaver/patterns/NamePatternParserTestCase.java +++ b/org.aspectj.matcher/testsrc/org/aspectj/weaver/patterns/NamePatternParserTestCase.java @@ -17,8 +17,10 @@ import junit.framework.TestCase; /** * @author hugunin * - * To change this generated comment edit the template variable "typecomment": Window>Preferences>Java>Templates. To enable - * and disable the creation of type comments go to Window>Preferences>Java>Code Generation. + * To change this generated comment edit the template variable + * "typecomment": Window>Preferences>Java>Templates. To enable and + * disable the creation of type comments go to + * Window>Preferences>Java>Code Generation. */ public class NamePatternParserTestCase extends TestCase { /** @@ -39,11 +41,15 @@ public class NamePatternParserTestCase extends TestCase { assertEquals(new NamePattern("abc"), p); } - // public void testTypePattern() { - // TypePattern tp = new PatternParser(" (@Ann *) ").parseTypePattern(); - // assertEquals(2, tp.start); - // assertEquals(9, tp.end); - // } + public void testTypePattern() { + TypePattern tp = null; + tp = new PatternParser(" @Ann * ").parseTypePattern(); + assertEquals(1, tp.start); + assertEquals(6, tp.end); + tp = new PatternParser(" (@Ann *) ").parseTypePattern(); + assertEquals(2, tp.start); + assertEquals(9, tp.end); + } /** * Method checkMatch. @@ -55,7 +61,8 @@ public class NamePatternParserTestCase extends TestCase { private void checkMatch(String[] patterns) { for (int i = 0, len = patterns.length; i < len; i++) { String pattern = patterns[i]; - ITokenSource tokenSource = BasicTokenSource.makeTokenSource(pattern, null); + ITokenSource tokenSource = BasicTokenSource.makeTokenSource( + pattern, null); NamePattern p1 = new PatternParser(tokenSource).parseNamePattern(); NamePattern p2 = new NamePattern(pattern); assertEquals("pattern: " + pattern, p2, p1);