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
p = setAnnotationPatternForTypePattern(p, ap, parameterAnnotationsPossible);
}
eat(")");
+ int closeParenPos = tokenSource.peek(-1).getStart();
boolean isVarArgs = maybeEat("...");
if (isVarArgs) {
p.setIsVarArgs(isVarArgs);
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);
eat(")");
return ret;
} else {
+ int atPos = tokenSource.peek(-1).getStart();
TypePattern p = parseSingleTypePattern();
if (maybeEatAdjacent("(")) {
values = parseAnnotationValues();
} else {
ret = new WildAnnotationTypePattern(p);
}
+ ret.start = atPos;
return ret;
}
} else {
/**
* @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 {
/**
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.
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);