1
1
/* *******************************************************************
2
* Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
2
* Copyright (c) 2002,2010
4
3
* All rights reserved.
5
4
* This program and the accompanying materials are made available
6
5
* under the terms of the Eclipse Public License v1.0
11
10
* PARC initial implementation
12
* Adrian Colyer many updates since....
12
* Andy Clement, IBM, SpringSource
13
13
* ******************************************************************/
15
15
package org.aspectj.weaver.patterns;
31
31
import org.aspectj.weaver.tools.ContextBasedMatcher;
32
32
import org.aspectj.weaver.tools.PointcutDesignatorHandler;
34
//XXX doesn't handle errors for extra tokens very well (sometimes ignores)
36
* @author Adrian Colyer
37
* @author Andy Clement
39
// XXX doesn't handle errors for extra tokens very well (sometimes ignores)
35
40
public class PatternParser {
37
42
private ITokenSource tokenSource;
140
145
ret = parseSoft();
142
147
throw new ParserException(
143
"expected one of error, warning, parents, soft, precedence, @type, @method, @constructor, @field", tokenSource
148
"expected one of error, warning, parents, soft, precedence, @type, @method, @constructor, @field",
149
tokenSource.peek(-1));
146
151
int endPos = tokenSource.peek(-1).getEnd();
147
152
ret.setLocation(sourceContext, startPos, endPos);
194
199
public DeclareAnnotation parseDeclareAtField() {
195
200
ISignaturePattern compoundFieldSignaturePattern = parseCompoundFieldSignaturePattern();
196
return new DeclareAnnotation(DeclareAnnotation.AT_FIELD, compoundFieldSignaturePattern);
201
DeclareAnnotation da = new DeclareAnnotation(DeclareAnnotation.AT_FIELD, compoundFieldSignaturePattern);
199
205
public ISignaturePattern parseCompoundFieldSignaturePattern() {
200
ISignaturePattern atomicFieldSignaturePattern = parseMaybeParenthesizedFieldSignaturePattern();
206
int index = tokenSource.getIndex();
208
ISignaturePattern atomicFieldSignaturePattern = parseMaybeParenthesizedFieldSignaturePattern();
202
while (isEitherAndOrOr()) {
203
if (maybeEat("&&")) {
204
atomicFieldSignaturePattern = new AndSignaturePattern(atomicFieldSignaturePattern,
205
parseMaybeParenthesizedFieldSignaturePattern());
210
while (isEitherAndOrOr()) {
211
if (maybeEat("&&")) {
212
atomicFieldSignaturePattern = new AndSignaturePattern(atomicFieldSignaturePattern,
213
parseMaybeParenthesizedFieldSignaturePattern());
215
if (maybeEat("||")) {
216
atomicFieldSignaturePattern = new OrSignaturePattern(atomicFieldSignaturePattern,
217
parseMaybeParenthesizedFieldSignaturePattern());
207
if (maybeEat("||")) {
208
atomicFieldSignaturePattern = new OrSignaturePattern(atomicFieldSignaturePattern,
209
parseMaybeParenthesizedFieldSignaturePattern());
220
return atomicFieldSignaturePattern;
221
} catch (ParserException e) {
222
// fallback in the case of a regular single field signature pattern that just happened to start with '('
223
int nowAt = tokenSource.getIndex();
224
tokenSource.setIndex(index);
226
ISignaturePattern fsp = parseFieldSignaturePattern();
228
} catch (Exception e2) {
229
tokenSource.setIndex(nowAt);
230
// throw the original
212
return atomicFieldSignaturePattern;
215
236
private boolean isEitherAndOrOr() {
326
347
private Pointcut parseNotOrPointcut() {
327
348
Pointcut p = parseAtomicPointcut();
328
349
if (maybeEat("&&")) {
329
p = new AndPointcut(p, parsePointcut());
350
p = new AndPointcut(p, parseNotOrPointcut());
753
774
if (maybeEat("(")) {
775
int openParenPos = tokenSource.peek(-1).getStart();
754
776
TypePattern p = parseTypePattern(insideTypeParameters, false);
755
777
if ((p instanceof NotTypePattern) && !(ap instanceof AnyAnnotationTypePattern)) {
756
778
// dont set the annotation on it, we don't want the annotation to be
761
783
p = setAnnotationPatternForTypePattern(p, ap, parameterAnnotationsPossible);
786
int closeParenPos = tokenSource.peek(-1).getStart();
764
787
boolean isVarArgs = maybeEat("...");
766
789
p.setIsVarArgs(isVarArgs);
769
792
if (isIncludeSubtypes) {
770
793
p.includeSubtypes = true; // need the test because (A+) should not set subtypes to false!
795
p.start = openParenPos;
796
p.end = closeParenPos;
774
799
int startPos = tokenSource.peek().getStart();
800
if (ap.start != -1) {
775
803
TypePattern p = parseSingleTypePattern(insideTypeParameters);
776
804
int endPos = tokenSource.peek(-1).getEnd();
777
805
p = setAnnotationPatternForTypePattern(p, ap, false);