]> source.dussan.org Git - aspectj.git/commitdiff
improvements to the positions for a type pattern - more to do here no doubt
authoraclement <aclement>
Fri, 20 Aug 2010 00:16:11 +0000 (00:16 +0000)
committeraclement <aclement>
Fri, 20 Aug 2010 00:16:11 +0000 (00:16 +0000)
org.aspectj.matcher/src/org/aspectj/weaver/patterns/PatternParser.java
org.aspectj.matcher/testsrc/org/aspectj/weaver/patterns/NamePatternParserTestCase.java

index 2cc6d20369ab989ef9db78e3913273438e8f7f81..7bb8593a4b9e45e6ed8ee75cc6c6bc3997a4db3b 100644 (file)
@@ -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 {
index f224b1737d961eb95cfc16ae0250dc9ab5b13dc8..fe3b0f2d4537a7bb4f7d8f9db59757f7b8b45c5e 100644 (file)
@@ -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);