~ubuntu-branches/ubuntu/trusty/aspectj/trusty

« back to all changes in this revision

Viewing changes to org.aspectj/modules/org.aspectj.matcher/src/org/aspectj/weaver/patterns/PatternParser.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2011-03-15 23:54:31 UTC
  • mfrom: (1.1.5 upstream) (7.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110315235431-7d8cs3gvs4tnqx7t
Tags: 1.6.11+dfsg-1
* New upstream release.
* Updated Standards-Version to 3.9.1 (no changes needed).
* Fix local Javadoc links:
  - d/patches/07_javadoc_links.diff: Use locally installed
   javadoc packages and hyperlink with them.
  - d/control: Add B-D on default-java-doc and libasm3-java-doc.
* d/control: Drop B-D on itself (our new bootstrap infrastructure doesn't need
  that anymore).
* Split packages into :
  - aspectj: only contains CLI tools.
  - libaspectj-java: JAR librairies for /usr/share/java.
  - libaspectj-java-doc: 4 API's Javadoc.
  - aspectj-doc: Programming Guides and SDK Documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* *******************************************************************
2
 
 * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
3
 
 *               2005 Contributors
 
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 
9
8
 *  
10
9
 * Contributors: 
11
10
 *     PARC     initial implementation
12
 
 *     Adrian Colyer many updates since.... 
 
11
 *     Adrian Colyer, IBM
 
12
 *     Andy Clement, IBM, SpringSource
13
13
 * ******************************************************************/
14
14
 
15
15
package org.aspectj.weaver.patterns;
31
31
import org.aspectj.weaver.tools.ContextBasedMatcher;
32
32
import org.aspectj.weaver.tools.PointcutDesignatorHandler;
33
33
 
34
 
//XXX doesn't handle errors for extra tokens very well (sometimes ignores)
 
34
/**
 
35
 * @author PARC
 
36
 * @author Adrian Colyer
 
37
 * @author Andy Clement
 
38
 */
 
39
// XXX doesn't handle errors for extra tokens very well (sometimes ignores)
35
40
public class PatternParser {
36
41
 
37
42
        private ITokenSource tokenSource;
140
145
                        ret = parseSoft();
141
146
                } else {
142
147
                        throw new ParserException(
143
 
                                        "expected one of error, warning, parents, soft, precedence, @type, @method, @constructor, @field", tokenSource
144
 
                                                        .peek(-1));
 
148
                                        "expected one of error, warning, parents, soft, precedence, @type, @method, @constructor, @field",
 
149
                                        tokenSource.peek(-1));
145
150
                }
146
151
                int endPos = tokenSource.peek(-1).getEnd();
147
152
                ret.setLocation(sourceContext, startPos, endPos);
193
198
 
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);
 
202
                return da;
197
203
        }
198
204
 
199
205
        public ISignaturePattern parseCompoundFieldSignaturePattern() {
200
 
                ISignaturePattern atomicFieldSignaturePattern = parseMaybeParenthesizedFieldSignaturePattern();
 
206
                int index = tokenSource.getIndex();
 
207
                try {
 
208
                        ISignaturePattern atomicFieldSignaturePattern = parseMaybeParenthesizedFieldSignaturePattern();
201
209
 
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());
 
214
                                }
 
215
                                if (maybeEat("||")) {
 
216
                                        atomicFieldSignaturePattern = new OrSignaturePattern(atomicFieldSignaturePattern,
 
217
                                                        parseMaybeParenthesizedFieldSignaturePattern());
 
218
                                }
206
219
                        }
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);
 
225
                        try {
 
226
                                ISignaturePattern fsp = parseFieldSignaturePattern();
 
227
                                return fsp;
 
228
                        } catch (Exception e2) {
 
229
                                tokenSource.setIndex(nowAt);
 
230
                                // throw the original
 
231
                                throw e;
210
232
                        }
211
233
                }
212
 
                return atomicFieldSignaturePattern;
213
234
        }
214
235
 
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());
330
351
                }
331
352
                return p;
332
353
        }
751
772
                        return p;
752
773
                }
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);
762
784
                        }
763
785
                        eat(")");
 
786
                        int closeParenPos = tokenSource.peek(-1).getStart();
764
787
                        boolean isVarArgs = maybeEat("...");
765
788
                        if (isVarArgs) {
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!
771
794
                        }
 
795
                        p.start = openParenPos;
 
796
                        p.end = closeParenPos;
772
797
                        return p;
773
798
                }
774
799
                int startPos = tokenSource.peek().getStart();
 
800
                if (ap.start != -1) {
 
801
                        startPos = ap.start;
 
802
                }
775
803
                TypePattern p = parseSingleTypePattern(insideTypeParameters);
776
804
                int endPos = tokenSource.peek(-1).getEnd();
777
805
                p = setAnnotationPatternForTypePattern(p, ap, false);
852
880
                                eat(")");
853
881
                                return ret;
854
882
                        } else {
 
883
                                int atPos = tokenSource.peek(-1).getStart();
855
884
                                TypePattern p = parseSingleTypePattern();
856
885
                                if (maybeEatAdjacent("(")) {
857
886
                                        values = parseAnnotationValues();
860
889
                                } else {
861
890
                                        ret = new WildAnnotationTypePattern(p);
862
891
                                }
 
892
                                ret.start = atPos;
863
893
                                return ret;
864
894
                        }
865
895
                } else {
1108
1138
        // if (maybeEat("&&")) {
1109
1139
        // ap = new AndAnnotationTypePattern(ap, parseNotOrAnnotationPattern());
1110
1140
        // }
1111
 
        //              
 
1141
        //
1112
1142
        // if (maybeEat("||")) {
1113
1143
        // ap = new OrAnnotationTypePattern(ap, parseAnnotationTypePattern());
1114
1144
        // }