aboutsummaryrefslogtreecommitdiffstats
path: root/org.aspectj.matcher/src/org/aspectj/weaver/patterns/PatternParser.java
blob: 321f1e759b4c04abdbbb06bd7824c7cbbc00eadd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
/* *******************************************************************
 * Copyright (c) 2002,2010
 * All rights reserved. 
 * This program and the accompanying materials are made available 
 * under the terms of the Eclipse Public License v1.0 
 * which accompanies this distribution and is available at 
 * http://www.eclipse.org/legal/epl-v10.html 
 *  
 * Contributors: 
 *     PARC     initial implementation
 *     Adrian Colyer, IBM
 *     Andy Clement, IBM, SpringSource
 * ******************************************************************/

package org.aspectj.weaver.patterns;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.aspectj.weaver.ISourceContext;
import org.aspectj.weaver.Member;
import org.aspectj.weaver.MemberKind;
import org.aspectj.weaver.Shadow;
import org.aspectj.weaver.UnresolvedType;
import org.aspectj.weaver.World;
import org.aspectj.weaver.internal.tools.PointcutDesignatorHandlerBasedPointcut;
import org.aspectj.weaver.tools.ContextBasedMatcher;
import org.aspectj.weaver.tools.PointcutDesignatorHandler;

/**
 * @author PARC
 * @author Adrian Colyer
 * @author Andy Clement
 */
// XXX doesn't handle errors for extra tokens very well (sometimes ignores)
public class PatternParser {

	private ITokenSource tokenSource;
	private ISourceContext sourceContext;

	/** not thread-safe, but this class is not intended to be... */
	private boolean allowHasTypePatterns = false;

	/** extension handlers used in weaver tools API only */
	private Set<PointcutDesignatorHandler> pointcutDesignatorHandlers = Collections.emptySet();
	private World world;

	/**
	 * Constructor for PatternParser.
	 */
	public PatternParser(ITokenSource tokenSource) {
		super();
		this.tokenSource = tokenSource;
		this.sourceContext = tokenSource.getSourceContext();
	}

	/** only used by weaver tools API */
	public void setPointcutDesignatorHandlers(Set<PointcutDesignatorHandler> handlers, World world) {
		this.pointcutDesignatorHandlers = handlers;
		this.world = world;
	}

	public PerClause maybeParsePerClause() {
		IToken tok = tokenSource.peek();
		if (tok == IToken.EOF) {
			return null;
		}
		if (tok.isIdentifier()) {
			String name = tok.getString();
			if (name.equals("issingleton")) {
				return parsePerSingleton();
			} else if (name.equals("perthis")) {
				return parsePerObject(true);
			} else if (name.equals("pertarget")) {
				return parsePerObject(false);
			} else if (name.equals("percflow")) {
				return parsePerCflow(false);
			} else if (name.equals("percflowbelow")) {
				return parsePerCflow(true);
			} else if (name.equals("pertypewithin")) { // PTWIMPL Parse the pertypewithin clause
				return parsePerTypeWithin();
			} else {
				return null;
			}
		}
		return null;
	}

	private PerClause parsePerCflow(boolean isBelow) {
		parseIdentifier();
		eat("(");
		Pointcut entry = parsePointcut();
		eat(")");
		return new PerCflow(entry, isBelow);
	}

	private PerClause parsePerObject(boolean isThis) {
		parseIdentifier();
		eat("(");
		Pointcut entry = parsePointcut();
		eat(")");
		return new PerObject(entry, isThis);
	}

	private PerClause parsePerTypeWithin() {
		parseIdentifier();
		eat("(");
		TypePattern withinTypePattern = parseTypePattern();
		eat(")");
		return new PerTypeWithin(withinTypePattern);
	}

	private PerClause parsePerSingleton() {
		parseIdentifier();
		eat("(");
		eat(")");
		return new PerSingleton();
	}

	public Declare parseDeclare() {
		int startPos = tokenSource.peek().getStart();

		eatIdentifier("declare");
		String kind = parseIdentifier();
		Declare ret;
		if (kind.equals("error")) {
			eat(":");
			ret = parseErrorOrWarning(true);
		} else if (kind.equals("warning")) {
			eat(":");
			ret = parseErrorOrWarning(false);
		} else if (kind.equals("precedence")) {
			eat(":");
			ret = parseDominates();
		} else if (kind.equals("dominates")) {
			throw new ParserException("name changed to declare precedence", tokenSource.peek(-2));
		} else if (kind.equals("parents")) {
			ret = parseParents();
		} else if (kind.equals("soft")) {
			eat(":");
			ret = parseSoft();
		} else {
			throw new ParserException(
					"expected one of error, warning, parents, soft, precedence, @type, @method, @constructor, @field",
					tokenSource.peek(-1));
		}
		int endPos = tokenSource.peek(-1).getEnd();
		ret.setLocation(sourceContext, startPos, endPos);
		return ret;
	}

	public Declare parseDeclareAnnotation() {
		int startPos = tokenSource.peek().getStart();

		eatIdentifier("declare");
		eat("@");
		String kind = parseIdentifier();
		eat(":");
		Declare ret;
		if (kind.equals("type")) {
			ret = parseDeclareAtType();
		} else if (kind.equals("method")) {
			ret = parseDeclareAtMethod(true);
		} else if (kind.equals("field")) {
			ret = parseDeclareAtField();
		} else if (kind.equals("constructor")) {
			ret = parseDeclareAtMethod(false);
		} else {
			throw new ParserException("one of type, method, field, constructor", tokenSource.peek(-1));
		}
		eat(";");
		int endPos = tokenSource.peek(-1).getEnd();
		ret.setLocation(sourceContext, startPos, endPos);
		return ret;

	}

	public DeclareAnnotation parseDeclareAtType() {
		allowHasTypePatterns = true;
		TypePattern p = parseTypePattern();
		allowHasTypePatterns = false;
		return new DeclareAnnotation(DeclareAnnotation.AT_TYPE, p);
	}

	public DeclareAnnotation parseDeclareAtMethod(boolean isMethod) {
		ISignaturePattern sp = parseCompoundMethodOrConstructorSignaturePattern(isMethod);// parseMethodOrConstructorSignaturePattern();

		if (!isMethod) {
			return new DeclareAnnotation(DeclareAnnotation.AT_CONSTRUCTOR, sp);
		} else {
			return new DeclareAnnotation(DeclareAnnotation.AT_METHOD, sp);
		}
	}

	public DeclareAnnotation parseDeclareAtField() {
		ISignaturePattern compoundFieldSignaturePattern = parseCompoundFieldSignaturePattern();
		DeclareAnnotation da = new DeclareAnnotation(DeclareAnnotation.AT_FIELD, compoundFieldSignaturePattern);
		return da;
	}

	public ISignaturePattern parseCompoundFieldSignaturePattern() {
		int index = tokenSource.getIndex();
		try {
			ISignaturePattern atomicFieldSignaturePattern = parseMaybeParenthesizedFieldSignaturePattern();

			while (isEitherAndOrOr()) {
				if (maybeEat("&&")) {
					atomicFieldSignaturePattern = new AndSignaturePattern(atomicFieldSignaturePattern,
							parseMaybeParenthesizedFieldSignaturePattern());
				}
				if (maybeEat("||")) {
					atomicFieldSignaturePattern = new OrSignaturePattern(atomicFieldSignaturePattern,
							parseMaybeParenthesizedFieldSignaturePattern());
				}
			}
			return atomicFieldSignaturePattern;
		} catch (ParserException e) {
			// fallback in the case of a regular single field signature pattern that just happened to start with '('
			int nowAt = tokenSource.getIndex();
			tokenSource.setIndex(index);
			try {
				ISignaturePattern fsp = parseFieldSignaturePattern();
				return fsp;
			} catch (Exception e2) {
				tokenSource.setIndex(nowAt);
				// throw the original
				throw e;
			}
		}
	}

	private boolean isEitherAndOrOr() {
		String tokenstring = tokenSource.peek().getString();
		return tokenstring.equals("&&") || tokenstring.equals("||");
	}

	public ISignaturePattern parseCompoundMethodOrConstructorSignaturePattern(boolean isMethod) {
		ISignaturePattern atomicMethodCtorSignaturePattern = parseMaybeParenthesizedMethodOrConstructorSignaturePattern(isMethod);

		while (isEitherAndOrOr()) {
			if (maybeEat("&&")) {
				atomicMethodCtorSignaturePattern = new AndSignaturePattern(atomicMethodCtorSignaturePattern,
						parseMaybeParenthesizedMethodOrConstructorSignaturePattern(isMethod));
			}
			if (maybeEat("||")) {
				atomicMethodCtorSignaturePattern = new OrSignaturePattern(atomicMethodCtorSignaturePattern,
						parseMaybeParenthesizedMethodOrConstructorSignaturePattern(isMethod));
			}
		}
		return atomicMethodCtorSignaturePattern;
	}

	public DeclarePrecedence parseDominates() {
		List<TypePattern> l = new ArrayList<TypePattern>();
		do {
			l.add(parseTypePattern());
		} while (maybeEat(","));

		return new DeclarePrecedence(l);
	}

	private Declare parseParents() {
		/*
		 * simplified design requires use of raw types for declare parents, no generic spec. allowed String[] typeParameters =
		 * maybeParseSimpleTypeVariableList();
		 */
		eat(":");
		allowHasTypePatterns = true;
		TypePattern p = parseTypePattern(false, false);
		allowHasTypePatterns = false;
		IToken t = tokenSource.next();
		if (!(t.getString().equals("extends") || t.getString().equals("implements"))) {
			throw new ParserException("extends or implements", t);
		}
		boolean isExtends = t.getString().equals("extends");

		List<TypePattern> l = new ArrayList<TypePattern>();
		do {
			l.add(parseTypePattern());
		} while (maybeEat(","));

		// XXX somewhere in the chain we need to enforce that we have only ExactTypePatterns

		DeclareParents decp = new DeclareParents(p, l, isExtends);
		return decp;
	}

	private Declare parseSoft() {
		TypePattern p = parseTypePattern();
		eat(":");
		Pointcut pointcut = parsePointcut();
		return new DeclareSoft(p, pointcut);
	}

	/**
	 * Attempt to parse a pointcut, if that fails then try again for a type pattern.
	 * 
	 * @param isError true if it is declare error rather than declare warning
	 * @return the new declare
	 */
	private Declare parseErrorOrWarning(boolean isError) {
		Pointcut pointcut = null;
		int index = tokenSource.getIndex();
		try {
			pointcut = parsePointcut();
		} catch (ParserException pe) {
			try {
				tokenSource.setIndex(index);
				boolean oldValue = allowHasTypePatterns;
				TypePattern typePattern = null;
				try {
					allowHasTypePatterns = true;
					typePattern = parseTypePattern();
				} finally {
					allowHasTypePatterns = oldValue;
				}
				eat(":");
				String message = parsePossibleStringSequence(true);
				return new DeclareTypeErrorOrWarning(isError, typePattern, message);
			} catch (ParserException pe2) {
				// deliberately throw the original problem
				throw pe;
			}
		}
		eat(":");
		String message = parsePossibleStringSequence(true);
		return new DeclareErrorOrWarning(isError, pointcut, message);
	}

	public Pointcut parsePointcut() {
		Pointcut p = parseAtomicPointcut();
		if (maybeEat("&&")) {
			p = new AndPointcut(p, parseNotOrPointcut());
		}

		if (maybeEat("||")) {
			p = new OrPointcut(p, parsePointcut());
		}

		return p;
	}

	private Pointcut parseNotOrPointcut() {
		Pointcut p = parseAtomicPointcut();
		if (maybeEat("&&")) {
			p = new AndPointcut(p, parseNotOrPointcut());
		}
		return p;
	}

	private Pointcut parseAtomicPointcut() {
		if (maybeEat("!")) {
			int startPos = tokenSource.peek(-1).getStart();
			Pointcut p = new NotPointcut(parseAtomicPointcut(), startPos);
			return p;
		}
		if (maybeEat("(")) {
			Pointcut p = parsePointcut();
			eat(")");
			return p;
		}
		if (maybeEat("@")) {
			int startPos = tokenSource.peek().getStart();
			Pointcut p = parseAnnotationPointcut();
			int endPos = tokenSource.peek(-1).getEnd();
			p.setLocation(sourceContext, startPos, endPos);
			return p;
		}
		int startPos = tokenSource.peek().getStart();
		Pointcut p = parseSinglePointcut();
		int endPos = tokenSource.peek(-1).getEnd();
		p.setLocation(sourceContext, startPos, endPos);
		return p;
	}

	public Pointcut parseSinglePointcut() {
		int start = tokenSource.getIndex();
		IToken t = tokenSource.peek();
		Pointcut p = t.maybeGetParsedPointcut();
		if (p != null) {
			tokenSource.next();
			return p;
		}

		String kind = parseIdentifier();
		// IToken possibleTypeVariableToken = tokenSource.peek();
		// String[] typeVariables = maybeParseSimpleTypeVariableList();
		if (kind.equals("execution") || kind.equals("call") || kind.equals("get") || kind.equals("set")) {
			p = parseKindedPointcut(kind);
		} else if (kind.equals("args")) {
			p = parseArgsPointcut();
		} else if (kind.equals("this")) {
			p = parseThisOrTargetPointcut(kind);
		} else if (kind.equals("target")) {
			p = parseThisOrTargetPointcut(kind);
		} else if (kind.equals("within")) {
			p = parseWithinPointcut();
		} else if (kind.equals("withincode")) {
			p = parseWithinCodePointcut();
		} else if (kind.equals("cflow")) {
			p = parseCflowPointcut(false);
		} else if (kind.equals("cflowbelow")) {
			p = parseCflowPointcut(true);
		} else if (kind.equals("adviceexecution")) {
			eat("(");
			eat(")");
			p = new KindedPointcut(Shadow.AdviceExecution, new SignaturePattern(Member.ADVICE, ModifiersPattern.ANY,
					TypePattern.ANY, TypePattern.ANY, NamePattern.ANY, TypePatternList.ANY, ThrowsPattern.ANY,
					AnnotationTypePattern.ANY));
		} else if (kind.equals("handler")) {
			eat("(");
			TypePattern typePat = parseTypePattern(false, false);
			eat(")");
			p = new HandlerPointcut(typePat);
		} else if (kind.equals("lock") || kind.equals("unlock")) {
			p = parseMonitorPointcut(kind);
		} else if (kind.equals("initialization")) {
			eat("(");
			SignaturePattern sig = parseConstructorSignaturePattern();
			eat(")");
			p = new KindedPointcut(Shadow.Initialization, sig);
		} else if (kind.equals("staticinitialization")) {
			eat("(");
			TypePattern typePat = parseTypePattern(false, false);
			eat(")");
			p = new KindedPointcut(Shadow.StaticInitialization, new SignaturePattern(Member.STATIC_INITIALIZATION,
					ModifiersPattern.ANY, TypePattern.ANY, typePat, NamePattern.ANY, TypePatternList.EMPTY, ThrowsPattern.ANY,
					AnnotationTypePattern.ANY));
		} else if (kind.equals("preinitialization")) {
			eat("(");
			SignaturePattern sig = parseConstructorSignaturePattern();
			eat(")");
			p = new KindedPointcut(Shadow.PreInitialization, sig);
		} else if (kind.equals("if")) {
			// - annotation style only allows if(), if(true) or if(false)
			// - if() means the body of the annotated method represents the if expression
			// - anything else is an error because code cannot be put into the if()
			// - code style will already have been processed and the call to maybeGetParsedPointcut()
			// at the top of this method will have succeeded.
			eat("(");
			if (maybeEatIdentifier("true")) {
				eat(")");
				p = new IfPointcut.IfTruePointcut();
			} else if (maybeEatIdentifier("false")) {
				eat(")");
				p = new IfPointcut.IfFalsePointcut();
			} else {
				if (!maybeEat(")")) {
					throw new ParserException(
							"in annotation style, if(...) pointcuts cannot contain code. Use if() and put the code in the annotated method",
							t);
				}
				// TODO - Alex has some token stuff going on here to get a readable name in place of ""...
				p = new IfPointcut("");
			}
		} else {
			boolean matchedByExtensionDesignator = false;
			// see if a registered handler wants to parse it, otherwise
			// treat as a reference pointcut
			for (PointcutDesignatorHandler pcd : pointcutDesignatorHandlers) {
				if (pcd.getDesignatorName().equals(kind)) {
					p = parseDesignatorPointcut(pcd);
					matchedByExtensionDesignator = true;
				}

			}
			if (!matchedByExtensionDesignator) {
				tokenSource.setIndex(start);
				p = parseReferencePointcut();
			}
		}
		return p;
	}

	private void assertNoTypeVariables(String[] tvs, String errorMessage, IToken token) {
		if (tvs != null) {
			throw new ParserException(errorMessage, token);
		}
	}

	public Pointcut parseAnnotationPointcut() {
		int start = tokenSource.getIndex();
		IToken t = tokenSource.peek();
		String kind = parseIdentifier();
		IToken possibleTypeVariableToken = tokenSource.peek();
		String[] typeVariables = maybeParseSimpleTypeVariableList();
		if (typeVariables != null) {
			String message = "(";
			assertNoTypeVariables(typeVariables, message, possibleTypeVariableToken);
		}
		tokenSource.setIndex(start);
		if (kind.equals("annotation")) {
			return parseAtAnnotationPointcut();
		} else if (kind.equals("args")) {
			return parseArgsAnnotationPointcut();
		} else if (kind.equals("this") || kind.equals("target")) {
			return parseThisOrTargetAnnotationPointcut();
		} else if (kind.equals("within")) {
			return parseWithinAnnotationPointcut();
		} else if (kind.equals("withincode")) {
			return parseWithinCodeAnnotationPointcut();
		}
		throw new ParserException("pointcut name", t);
	}

	private Pointcut parseAtAnnotationPointcut() {
		parseIdentifier();
		eat("(");
		if (maybeEat(")")) {
			throw new ParserException("@AnnotationName or parameter", tokenSource.peek());
		}
		ExactAnnotationTypePattern type = parseAnnotationNameOrVarTypePattern();
		eat(")");
		return new AnnotationPointcut(type);
	}

	private SignaturePattern parseConstructorSignaturePattern() {
		SignaturePattern ret = parseMethodOrConstructorSignaturePattern();
		if (ret.getKind() == Member.CONSTRUCTOR) {
			return ret;
		}

		throw new ParserException("constructor pattern required, found method pattern", ret);
	}

	private Pointcut parseWithinCodePointcut() {
		// parseIdentifier();
		eat("(");
		SignaturePattern sig = parseMethodOrConstructorSignaturePattern();
		eat(")");
		return new WithincodePointcut(sig);
	}

	private Pointcut parseCflowPointcut(boolean isBelow) {
		// parseIdentifier();
		eat("(");
		Pointcut entry = parsePointcut();
		eat(")");
		return new CflowPointcut(entry, isBelow, null);
	}

	/**
	 * Method parseWithinPointcut.
	 * 
	 * @return Pointcut
	 */
	private Pointcut parseWithinPointcut() {
		// parseIdentifier();
		eat("(");
		TypePattern type = parseTypePattern();
		eat(")");
		return new WithinPointcut(type);
	}

	/**
	 * Method parseThisOrTargetPointcut.
	 * 
	 * @return Pointcut
	 */
	private Pointcut parseThisOrTargetPointcut(String kind) {
		eat("(");
		TypePattern type = parseTypePattern();
		eat(")");
		return new ThisOrTargetPointcut(kind.equals("this"), type);
	}

	private Pointcut parseThisOrTargetAnnotationPointcut() {
		String kind = parseIdentifier();
		eat("(");
		if (maybeEat(")")) {
			throw new ParserException("expecting @AnnotationName or parameter, but found ')'", tokenSource.peek());
		}
		ExactAnnotationTypePattern type = parseAnnotationNameOrVarTypePattern();
		eat(")");
		return new ThisOrTargetAnnotationPointcut(kind.equals("this"), type);
	}

	private Pointcut parseWithinAnnotationPointcut() {
		/* String kind = */parseIdentifier();
		eat("(");
		if (maybeEat(")")) {
			throw new ParserException("expecting @AnnotationName or parameter, but found ')'", tokenSource.peek());
		}
		AnnotationTypePattern type = parseAnnotationNameOrVarTypePattern();
		eat(")");
		return new WithinAnnotationPointcut(type);
	}

	private Pointcut parseWithinCodeAnnotationPointcut() {
		/* String kind = */parseIdentifier();
		eat("(");
		if (maybeEat(")")) {
			throw new ParserException("expecting @AnnotationName or parameter, but found ')'", tokenSource.peek());
		}
		ExactAnnotationTypePattern type = parseAnnotationNameOrVarTypePattern();
		eat(")");
		return new WithinCodeAnnotationPointcut(type);
	}

	/**
	 * Method parseArgsPointcut.
	 * 
	 * @return Pointcut
	 */
	private Pointcut parseArgsPointcut() {
		// parseIdentifier();
		TypePatternList arguments = parseArgumentsPattern(false);
		return new ArgsPointcut(arguments);
	}

	private Pointcut parseArgsAnnotationPointcut() {
		parseIdentifier();
		AnnotationPatternList arguments = parseArgumentsAnnotationPattern();
		return new ArgsAnnotationPointcut(arguments);
	}

	private Pointcut parseReferencePointcut() {
		TypePattern onType = parseTypePattern();
		NamePattern name = null;
		if (onType.typeParameters.size() > 0) {
			eat(".");
			name = parseNamePattern();
		} else {
			name = tryToExtractName(onType);
		}
		if (name == null) {
			throw new ParserException("name pattern", tokenSource.peek());
		}
		if (onType.toString().equals("")) {
			onType = null;
		}

		String simpleName = name.maybeGetSimpleName();
		if (simpleName == null) {
			throw new ParserException("(", tokenSource.peek(-1));
		}

		TypePatternList arguments = parseArgumentsPattern(false);
		return new ReferencePointcut(onType, simpleName, arguments);
	}

	private Pointcut parseDesignatorPointcut(PointcutDesignatorHandler pcdHandler) {
		eat("(");
		int parenCount = 1;
		StringBuffer pointcutBody = new StringBuffer();
		while (parenCount > 0) {
			if (maybeEat("(")) {
				parenCount++;
				pointcutBody.append("(");
			} else if (maybeEat(")")) {
				parenCount--;
				if (parenCount > 0) {
					pointcutBody.append(")");
				}
			} else {
				pointcutBody.append(nextToken().getString());
			}
		}
		ContextBasedMatcher pcExpr = pcdHandler.parse(pointcutBody.toString());
		return new PointcutDesignatorHandlerBasedPointcut(pcExpr, world);
	}

	public List<String> parseDottedIdentifier() {
		List<String> ret = new ArrayList<String>();
		ret.add(parseIdentifier());
		while (maybeEat(".")) {
			ret.add(parseIdentifier());
		}
		return ret;
	}

	private KindedPointcut parseKindedPointcut(String kind) {
		eat("(");
		SignaturePattern sig;

		Shadow.Kind shadowKind = null;
		if (kind.equals("execution")) {
			sig = parseMethodOrConstructorSignaturePattern();
			if (sig.getKind() == Member.METHOD) {
				shadowKind = Shadow.MethodExecution;
			} else if (sig.getKind() == Member.CONSTRUCTOR) {
				shadowKind = Shadow.ConstructorExecution;
			}
		} else if (kind.equals("call")) {
			sig = parseMethodOrConstructorSignaturePattern();
			if (sig.getKind() == Member.METHOD) {
				shadowKind = Shadow.MethodCall;
			} else if (sig.getKind() == Member.CONSTRUCTOR) {
				shadowKind = Shadow.ConstructorCall;
			}
		} else if (kind.equals("get")) {
			sig = parseFieldSignaturePattern();
			shadowKind = Shadow.FieldGet;
		} else if (kind.equals("set")) {
			sig = parseFieldSignaturePattern();
			shadowKind = Shadow.FieldSet;
		} else {
			throw new ParserException("bad kind: " + kind, tokenSource.peek());
		}
		eat(")");
		return new KindedPointcut(shadowKind, sig);
	}

	/** Covers the 'lock()' and 'unlock()' pointcuts */
	private KindedPointcut parseMonitorPointcut(String kind) {
		eat("(");
		// TypePattern type = TypePattern.ANY;
		eat(")");

		if (kind.equals("lock")) {
			return new KindedPointcut(Shadow.SynchronizationLock, new SignaturePattern(Member.MONITORENTER, ModifiersPattern.ANY,
					TypePattern.ANY, TypePattern.ANY,
					// type,
					NamePattern.ANY, TypePatternList.ANY, ThrowsPattern.ANY, AnnotationTypePattern.ANY));
		} else {
			return new KindedPointcut(Shadow.SynchronizationUnlock, new SignaturePattern(Member.MONITORENTER, ModifiersPattern.ANY,
					TypePattern.ANY, TypePattern.ANY,
					// type,
					NamePattern.ANY, TypePatternList.ANY, ThrowsPattern.ANY, AnnotationTypePattern.ANY));
		}
	}

	public TypePattern parseTypePattern() {
		return parseTypePattern(false, false);
	}

	public TypePattern parseTypePattern(boolean insideTypeParameters, boolean parameterAnnotationsPossible) {
		TypePattern p = parseAtomicTypePattern(insideTypeParameters, parameterAnnotationsPossible);
		if (maybeEat("&&")) {
			p = new AndTypePattern(p, parseNotOrTypePattern(insideTypeParameters, parameterAnnotationsPossible));
		}

		if (maybeEat("||")) {
			p = new OrTypePattern(p, parseTypePattern(insideTypeParameters, parameterAnnotationsPossible));
		}
		return p;
	}

	private TypePattern parseNotOrTypePattern(boolean insideTypeParameters, boolean parameterAnnotationsPossible) {
		TypePattern p = parseAtomicTypePattern(insideTypeParameters, parameterAnnotationsPossible);
		if (maybeEat("&&")) {
			p = new AndTypePattern(p, parseTypePattern(insideTypeParameters, parameterAnnotationsPossible));
		}
		return p;
	}

	// Need to differentiate in here between two kinds of annotation pattern - depending on where the ( is

	private TypePattern parseAtomicTypePattern(boolean insideTypeParameters, boolean parameterAnnotationsPossible) {
		AnnotationTypePattern ap = maybeParseAnnotationPattern(); // might be parameter annotation pattern or type annotation
		// pattern
		if (maybeEat("!")) {
			// int startPos = tokenSource.peek(-1).getStart();
			// ??? we lose source location for true start of !type

			// An annotation, if processed, is outside of the Not - so here we have to build
			// an And pattern containing the annotation and the not as left and right children
			// *unless* the annotation pattern was just 'Any' then we can skip building the
			// And and just return the Not directly (pr228980)
			TypePattern p = null;
			TypePattern tp = parseAtomicTypePattern(insideTypeParameters, parameterAnnotationsPossible);
			if (!(ap instanceof AnyAnnotationTypePattern)) {
				p = new NotTypePattern(tp);
				p = new AndTypePattern(setAnnotationPatternForTypePattern(TypePattern.ANY, ap, false), p);
			} else {
				p = new NotTypePattern(tp);
			}
			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
				// considered as part of the not, it is outside the not (pr228980)
				TypePattern tp = setAnnotationPatternForTypePattern(TypePattern.ANY, ap, parameterAnnotationsPossible);
				p = new AndTypePattern(tp, p);
			} else {
				p = setAnnotationPatternForTypePattern(p, ap, parameterAnnotationsPossible);
			}
			eat(")");
			int closeParenPos = tokenSource.peek(-1).getStart();
			boolean isVarArgs = maybeEat("...");
			if (isVarArgs) {
				p.setIsVarArgs(isVarArgs);
			}
			boolean isIncludeSubtypes = maybeEat("+");
			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);
		p.setLocation(sourceContext, startPos, endPos);
		return p;
	}

	private TypePattern setAnnotationPatternForTypePattern(TypePattern t, AnnotationTypePattern ap,
			boolean parameterAnnotationsPattern) {
		TypePattern ret = t;
		if (parameterAnnotationsPattern) {
			ap.setForParameterAnnotationMatch();
		}
		if (ap != AnnotationTypePattern.ANY) {
			if (t == TypePattern.ANY) {
				if (t.annotationPattern == AnnotationTypePattern.ANY) {
					return new AnyWithAnnotationTypePattern(ap);
				} else {
					return new AnyWithAnnotationTypePattern(new AndAnnotationTypePattern(ap, t.annotationPattern));
				}
				// ret = new WildTypePattern(new NamePattern[] { NamePattern.ANY }, false, 0, false, null);
			}
			if (t.annotationPattern == AnnotationTypePattern.ANY) {
				ret.setAnnotationTypePattern(ap);
			} else {
				ret.setAnnotationTypePattern(new AndAnnotationTypePattern(ap, t.annotationPattern)); // ???
			}
		}
		return ret;
	}

	public AnnotationTypePattern maybeParseAnnotationPattern() {
		AnnotationTypePattern ret = AnnotationTypePattern.ANY;
		AnnotationTypePattern nextPattern = null;
		while ((nextPattern = maybeParseSingleAnnotationPattern()) != null) {
			if (ret == AnnotationTypePattern.ANY) {
				ret = nextPattern;
			} else {
				ret = new AndAnnotationTypePattern(ret, nextPattern);
			}
		}
		return ret;
	}

	// PVAL cope with annotation values at other places in this code
	public AnnotationTypePattern maybeParseSingleAnnotationPattern() {
		AnnotationTypePattern ret = null;
		Map<String, String> values = null;
		// LALR(2) - fix by making "!@" a single token
		int startIndex = tokenSource.getIndex();
		if (maybeEat("!")) {
			if (maybeEat("@")) {
				if (maybeEat("(")) {
					TypePattern p = parseTypePattern();
					ret = new NotAnnotationTypePattern(new WildAnnotationTypePattern(p));
					eat(")");
					return ret;
				} else {
					TypePattern p = parseSingleTypePattern();
					if (maybeEatAdjacent("(")) {
						values = parseAnnotationValues();
						eat(")");
						ret = new NotAnnotationTypePattern(new WildAnnotationTypePattern(p, values));
					} else {
						ret = new NotAnnotationTypePattern(new WildAnnotationTypePattern(p));
					}
					return ret;
				}
			} else {
				tokenSource.setIndex(startIndex); // not for us!
				return ret;
			}
		}
		if (maybeEat("@")) {
			if (maybeEat("(")) {
				TypePattern p = parseTypePattern();
				ret = new WildAnnotationTypePattern(p);
				eat(")");
				return ret;
			} else {
				int atPos = tokenSource.peek(-1).getStart();
				TypePattern p = parseSingleTypePattern();
				if (maybeEatAdjacent("(")) {
					values = parseAnnotationValues();
					eat(")");
					ret = new WildAnnotationTypePattern(p, values);
				} else {
					ret = new WildAnnotationTypePattern(p);
				}
				ret.start = atPos;
				return ret;
			}
		} else {
			tokenSource.setIndex(startIndex); // not for us!
			return ret;
		}
	}

	// Parse annotation values. In an expression in @A(a=b,c=d) this method will be
	// parsing the a=b,c=d.)
	public Map<String, String> parseAnnotationValues() {
		Map<String, String> values = new HashMap<String, String>();
		boolean seenDefaultValue = false;
		do {
			String possibleKeyString = parseAnnotationNameValuePattern();
			if (possibleKeyString == null) {
				throw new ParserException("expecting simple literal ", tokenSource.peek(-1));
			}
			// did they specify just a single entry 'v' or a keyvalue pair 'k=v'
			if (maybeEat("=")) {
				// it was a key!
				String valueString = parseAnnotationNameValuePattern();
				if (valueString == null) {
					throw new ParserException("expecting simple literal ", tokenSource.peek(-1));
				}
				values.put(possibleKeyString, valueString);
			} else if (maybeEat("!=")) {
				// it was a key, with a !=
				String valueString = parseAnnotationNameValuePattern();
				if (valueString == null) {
					throw new ParserException("expecting simple literal ", tokenSource.peek(-1));
				}
				// negation is captured by adding a trailing ! to the key name
				values.put(possibleKeyString + "!", valueString);
			} else {
				if (seenDefaultValue) {
					throw new ParserException("cannot specify two default values", tokenSource.peek(-1));
				}
				seenDefaultValue = true;
				values.put("value", possibleKeyString);
			}
		} while (maybeEat(",")); // keep going whilst there are ','
		return values;
	}

	public TypePattern parseSingleTypePattern() {
		return parseSingleTypePattern(false);
	}

	public TypePattern parseSingleTypePattern(boolean insideTypeParameters) {
		if (insideTypeParameters && maybeEat("?")) {
			return parseGenericsWildcardTypePattern();
		}
		if (allowHasTypePatterns) {
			if (maybeEatIdentifier("hasmethod")) {
				return parseHasMethodTypePattern();
			}
			if (maybeEatIdentifier("hasfield")) {
				return parseHasFieldTypePattern();
			}
		}

		// // Check for a type category
		// IToken token = tokenSource.peek();
		// if (token.isIdentifier()) {
		// String category = token.getString();
		// TypeCategoryTypePattern typeIsPattern = null;
		// if (category.equals("isClass")) {
		// typeIsPattern = new TypeCategoryTypePattern(TypeCategoryTypePattern.CLASS);
		// } else if (category.equals("isAspect")) {
		// typeIsPattern = new TypeCategoryTypePattern(TypeCategoryTypePattern.ASPECT);
		// } else if (category.equals("isInterface")) {
		// typeIsPattern = new TypeCategoryTypePattern(TypeCategoryTypePattern.INTERFACE);
		// } else if (category.equals("isInner")) {
		// typeIsPattern = new TypeCategoryTypePattern(TypeCategoryTypePattern.INNER);
		// } else if (category.equals("isAnonymous")) {
		// typeIsPattern = new TypeCategoryTypePattern(TypeCategoryTypePattern.ANONYMOUS);
		// } else if (category.equals("isEnum")) {
		// typeIsPattern = new TypeCategoryTypePattern(TypeCategoryTypePattern.ENUM);
		// } else if (category.equals("isAnnotation")) {
		// typeIsPattern = new TypeCategoryTypePattern(TypeCategoryTypePattern.ANNOTATION);
		// }
		// if (typeIsPattern != null) {
		// tokenSource.next();
		// typeIsPattern.setLocation(tokenSource.getSourceContext(), token.getStart(), token.getEnd());
		// return typeIsPattern;
		// }
		// }
		if (maybeEatIdentifier("is")) {
			int pos = tokenSource.getIndex() - 1;
			TypePattern typeIsPattern = parseIsTypePattern();
			if (typeIsPattern != null) {
				return typeIsPattern;
			}
			// rewind as if we never tried to parse it as a typeIs
			tokenSource.setIndex(pos);
		}

		List<NamePattern> names = parseDottedNamePattern();

		int dim = 0;
		while (maybeEat("[")) {
			eat("]");
			dim++;
		}

		TypePatternList typeParameters = maybeParseTypeParameterList();
		int endPos = tokenSource.peek(-1).getEnd();

		boolean includeSubtypes = maybeEat("+");

		// TODO do we need to associate the + with either the type or the array?
		while (maybeEat("[")) {
			eat("]");
			dim++;
		}

		boolean isVarArgs = maybeEat("...");

		// ??? what about the source location of any's????
		if (names.size() == 1 && names.get(0).isAny() && dim == 0 && !isVarArgs && typeParameters == null) {
			return TypePattern.ANY;
		}

		// Notice we increase the dimensions if varargs is set. this is to allow type matching to
		// succeed later: The actual signature at runtime of a method declared varargs is an array type of
		// the original declared type (so Integer... becomes Integer[] in the bytecode). So, here for the
		// pattern 'Integer...' we create a WildTypePattern 'Integer[]' with varargs set. If this matches
		// during shadow matching, we confirm that the varargs flags match up before calling it a successful
		// match.
		return new WildTypePattern(names, includeSubtypes, dim + (isVarArgs ? 1 : 0), endPos, isVarArgs, typeParameters);
	}

	public TypePattern parseHasMethodTypePattern() {
		int startPos = tokenSource.peek(-1).getStart();
		eat("(");
		SignaturePattern sp = parseMethodOrConstructorSignaturePattern();
		eat(")");
		int endPos = tokenSource.peek(-1).getEnd();
		HasMemberTypePattern ret = new HasMemberTypePattern(sp);
		ret.setLocation(sourceContext, startPos, endPos);
		return ret;
	}

	/**
	 * Attempt to parse a typeIs(<category>) construct. If it cannot be parsed we just return null and that should cause the caller
	 * to reset their position and attempt to consume it in another way. This means we won't have problems here: execution(*
	 * typeIs(..)) because someone has decided to call a method the same as our construct.
	 * 
	 * @return a TypeIsTypePattern or null if could not be parsed
	 */
	public TypePattern parseIsTypePattern() {
		int startPos = tokenSource.peek(-1).getStart(); // that will be the start of the 'typeIs'
		if (!maybeEatAdjacent("(")) {
			return null;
		}
		IToken token = tokenSource.next();
		TypeCategoryTypePattern typeIsPattern = null;
		if (token.isIdentifier()) {
			String category = token.getString();
			if (category.equals("ClassType")) {
				typeIsPattern = new TypeCategoryTypePattern(TypeCategoryTypePattern.CLASS);
			} else if (category.equals("AspectType")) {
				typeIsPattern = new TypeCategoryTypePattern(TypeCategoryTypePattern.ASPECT);
			} else if (category.equals("InterfaceType")) {
				typeIsPattern = new TypeCategoryTypePattern(TypeCategoryTypePattern.INTERFACE);
			} else if (category.equals("InnerType")) {
				typeIsPattern = new TypeCategoryTypePattern(TypeCategoryTypePattern.INNER);
			} else if (category.equals("AnonymousType")) {
				typeIsPattern = new TypeCategoryTypePattern(TypeCategoryTypePattern.ANONYMOUS);
			} else if (category.equals("EnumType")) {
				typeIsPattern = new TypeCategoryTypePattern(TypeCategoryTypePattern.ENUM);
			} else if (category.equals("AnnotationType")) {
				typeIsPattern = new TypeCategoryTypePattern(TypeCategoryTypePattern.ANNOTATION);
			}
		}
		if (typeIsPattern == null) {
			return null;
		}
		if (!maybeEat(")")) {
			throw new ParserException(")", tokenSource.peek());
		}
		int endPos = tokenSource.peek(-1).getEnd();
		typeIsPattern.setLocation(tokenSource.getSourceContext(), startPos, endPos);
		return typeIsPattern;
	}

	// if (names.size() == 1 && !names.get(0).isAny()) {
	// if (maybeEatAdjacent("(")) {
	// if (maybeEat(")")) {
	// // likely to be one of isClass()/isInterface()/isInner()/isAnonymous()/isAspect()
	// if (names.size() == 1) {
	// NamePattern np = names.get(0);
	// String simpleName = np.maybeGetSimpleName();
	// if (simpleName != null) {

	// return new TypeCategoryTypePattern(TypeCategoryTypePattern.ANNOTATION, np);
	// } else {
	// throw new ParserException(
	// "not a supported type category, supported are isClass/isInterface/isEnum/isAnnotation/isInner/isAnonymous",
	// tokenSource.peek(-3));
	// }
	// }
	// int stop = 1;
	// // return new WildTypePattern(names, includeSubtypes, dim + (isVarArgs ? 1 : 0), endPos, isVarArgs,
	// // typeParameters);
	// }
	// } else {
	// throw new ParserException("category type pattern is missing closing parentheses", tokenSource.peek(-2));
	// }
	// }
	// }

	public TypePattern parseHasFieldTypePattern() {
		int startPos = tokenSource.peek(-1).getStart();
		eat("(");
		SignaturePattern sp = parseFieldSignaturePattern();
		eat(")");
		int endPos = tokenSource.peek(-1).getEnd();
		HasMemberTypePattern ret = new HasMemberTypePattern(sp);
		ret.setLocation(sourceContext, startPos, endPos);
		return ret;
	}

	public TypePattern parseGenericsWildcardTypePattern() {
		List<NamePattern> names = new ArrayList<NamePattern>();
		names.add(new NamePattern("?"));
		TypePattern upperBound = null;
		TypePattern[] additionalInterfaceBounds = new TypePattern[0];
		TypePattern lowerBound = null;
		if (maybeEatIdentifier("extends")) {
			upperBound = parseTypePattern(false, false);
			additionalInterfaceBounds = maybeParseAdditionalInterfaceBounds();
		}
		if (maybeEatIdentifier("super")) {
			lowerBound = parseTypePattern(false, false);
		}
		int endPos = tokenSource.peek(-1).getEnd();
		return new WildTypePattern(names, false, 0, endPos, false, null, upperBound, additionalInterfaceBounds, lowerBound);
	}

	// private AnnotationTypePattern completeAnnotationPattern(AnnotationTypePattern p) {
	// if (maybeEat("&&")) {
	// return new AndAnnotationTypePattern(p,parseNotOrAnnotationPattern());
	// }
	// if (maybeEat("||")) {
	// return new OrAnnotationTypePattern(p,parseAnnotationTypePattern());
	// }
	// return p;
	// }
	//
	// protected AnnotationTypePattern parseAnnotationTypePattern() {
	// AnnotationTypePattern ap = parseAtomicAnnotationPattern();
	// if (maybeEat("&&")) {
	// ap = new AndAnnotationTypePattern(ap, parseNotOrAnnotationPattern());
	// }
	//
	// if (maybeEat("||")) {
	// ap = new OrAnnotationTypePattern(ap, parseAnnotationTypePattern());
	// }
	// return ap;
	// }
	//
	// private AnnotationTypePattern parseNotOrAnnotationPattern() {
	// AnnotationTypePattern p = parseAtomicAnnotationPattern();
	// if (maybeEat("&&")) {
	// p = new AndAnnotationTypePattern(p,parseAnnotationTypePattern());
	// }
	// return p;
	// }

	protected ExactAnnotationTypePattern parseAnnotationNameOrVarTypePattern() {
		ExactAnnotationTypePattern p = null;
		int startPos = tokenSource.peek().getStart();
		if (maybeEat("@")) {
			throw new ParserException("@Foo form was deprecated in AspectJ 5 M2: annotation name or var ", tokenSource.peek(-1));
		}
		p = parseSimpleAnnotationName();
		int endPos = tokenSource.peek(-1).getEnd();
		p.setLocation(sourceContext, startPos, endPos);
		// For optimized syntax that allows binding directly to annotation values (pr234943)
		if (maybeEat("(")) {
			String formalName = parseIdentifier();
			p = new ExactAnnotationFieldTypePattern(p, formalName);
			eat(")");
		}
		return p;
	}

	/**
	 * @return
	 */
	private ExactAnnotationTypePattern parseSimpleAnnotationName() {
		// the @ has already been eaten...
		ExactAnnotationTypePattern p;
		StringBuffer annotationName = new StringBuffer();
		annotationName.append(parseIdentifier());
		while (maybeEat(".")) {
			annotationName.append('.');
			annotationName.append(parseIdentifier());
		}
		UnresolvedType type = UnresolvedType.forName(annotationName.toString());
		p = new ExactAnnotationTypePattern(type, null);
		return p;
	}

	// private AnnotationTypePattern parseAtomicAnnotationPattern() {
	// if (maybeEat("!")) {
	// //int startPos = tokenSource.peek(-1).getStart();
	// //??? we lose source location for true start of !type
	// AnnotationTypePattern p = new NotAnnotationTypePattern(parseAtomicAnnotationPattern());
	// return p;
	// }
	// if (maybeEat("(")) {
	// AnnotationTypePattern p = parseAnnotationTypePattern();
	// eat(")");
	// return p;
	// }
	// int startPos = tokenSource.peek().getStart();
	// eat("@");
	// StringBuffer annotationName = new StringBuffer();
	// annotationName.append(parseIdentifier());
	// while (maybeEat(".")) {
	// annotationName.append('.');
	// annotationName.append(parseIdentifier());
	// }
	// UnresolvedType type = UnresolvedType.forName(annotationName.toString());
	// AnnotationTypePattern p = new ExactAnnotationTypePattern(type);
	// int endPos = tokenSource.peek(-1).getEnd();
	// p.setLocation(sourceContext, startPos, endPos);
	// return p;
	// }

	public List<NamePattern> parseDottedNamePattern() {
		List<NamePattern> names = new ArrayList<NamePattern>();
		StringBuffer buf = new StringBuffer();
		IToken previous = null;
		boolean justProcessedEllipsis = false; // Remember if we just dealt with an ellipsis (PR61536)
		boolean justProcessedDot = false;
		boolean onADot = false;

		while (true) {
			IToken tok = null;
			int startPos = tokenSource.peek().getStart();
			String afterDot = null;
			while (true) {
				if (previous != null && previous.getString().equals(".")) {
					justProcessedDot = true;
				}
				tok = tokenSource.peek();
				onADot = (tok.getString().equals("."));
				if (previous != null) {
					if (!isAdjacent(previous, tok)) {
						break;
					}
				}
				if (tok.getString() == "*" || (tok.isIdentifier() && tok.getString() != "...")) {
					buf.append(tok.getString());
				} else if (tok.getString() == "...") {
					break;
				} else if (tok.getLiteralKind() != null) {
					// System.err.println("literal kind: " + tok.getString());
					String s = tok.getString();
					int dot = s.indexOf('.');
					if (dot != -1) {
						buf.append(s.substring(0, dot));
						afterDot = s.substring(dot + 1);
						previous = tokenSource.next();
						break;
					}
					buf.append(s); // ??? so-so
				} else {
					break;
				}
				previous = tokenSource.next();
				// XXX need to handle floats and other fun stuff
			}
			int endPos = tokenSource.peek(-1).getEnd();
			if (buf.length() == 0 && names.isEmpty()) {
				throw new ParserException("name pattern", tok);
			}

			if (buf.length() == 0 && justProcessedEllipsis) {
				throw new ParserException("name pattern cannot finish with ..", tok);
			}
			if (buf.length() == 0 && justProcessedDot && !onADot) {
				throw new ParserException("name pattern cannot finish with .", tok);
			}

			if (buf.length() == 0) {
				names.add(NamePattern.ELLIPSIS);
				justProcessedEllipsis = true;
			} else {
				checkLegalName(buf.toString(), previous);
				NamePattern ret = new NamePattern(buf.toString());
				ret.setLocation(sourceContext, startPos, endPos);
				names.add(ret);
				justProcessedEllipsis = false;
			}

			if (afterDot == null) {
				buf.setLength(0);
				// no elipsis or dotted name part
				if (!maybeEat(".")) {
					break;
					// go on
				} else {
					previous = tokenSource.peek(-1);
				}
			} else {
				buf.setLength(0);
				buf.append(afterDot);
				afterDot = null;
			}
		}
		// System.err.println("parsed: " + names);
		return names;
	}

	// supported form 'a.b.c.d' or just 'a'
	public String parseAnnotationNameValuePattern() {
		StringBuffer buf = new StringBuffer();
		IToken tok;
		// int startPos =
		tokenSource.peek().getStart();
		boolean dotOK = false;
		int depth = 0;
		while (true) {
			tok = tokenSource.peek();
			// keep going until we hit ')' or '=' or ','
			if (tok.getString() == ")" && depth == 0) {
				break;
			}
			if (tok.getString() == "!=" && depth == 0) {
				break;
			}
			if (tok.getString() == "=" && depth == 0) {
				break;
			}
			if (tok.getString() == "," && depth == 0) {
				break;
			}

			// keep track of nested brackets
			if (tok.getString() == "(") {
				depth++;
			}
			if (tok.getString() == ")") {
				depth--;
			}
			if (tok.getString() == "{") {
				depth++;
			}
			if (tok.getString() == "}") {
				depth--;
			}

			if (tok.getString() == "." && !dotOK) {
				throw new ParserException("dot not expected", tok);
			}
			buf.append(tok.getString());
			tokenSource.next();
			dotOK = true;
		}
		return buf.toString();
	}

	public NamePattern parseNamePattern() {
		StringBuffer buf = new StringBuffer();
		IToken previous = null;
		IToken tok;
		int startPos = tokenSource.peek().getStart();
		while (true) {
			tok = tokenSource.peek();
			if (previous != null) {
				if (!isAdjacent(previous, tok)) {
					break;
				}
			}
			if (tok.getString() == "*" || tok.isIdentifier()) {
				buf.append(tok.getString());
			} else if (tok.getLiteralKind() != null) {
				// System.err.println("literal kind: " + tok.getString());
				String s = tok.getString();
				if (s.indexOf('.') != -1) {
					break;
				}
				buf.append(s); // ??? so-so
			} else {
				break;
			}
			previous = tokenSource.next();
			// XXX need to handle floats and other fun stuff
		}
		int endPos = tokenSource.peek(-1).getEnd();
		if (buf.length() == 0) {
			throw new ParserException("name pattern", tok);
		}

		checkLegalName(buf.toString(), previous);
		NamePattern ret = new NamePattern(buf.toString());
		ret.setLocation(sourceContext, startPos, endPos);
		return ret;
	}

	private void checkLegalName(String s, IToken tok) {
		char ch = s.charAt(0);
		if (!(ch == '*' || Character.isJavaIdentifierStart(ch))) {
			throw new ParserException("illegal identifier start (" + ch + ")", tok);
		}

		for (int i = 1, len = s.length(); i < len; i++) {
			ch = s.charAt(i);
			if (!(ch == '*' || Character.isJavaIdentifierPart(ch))) {
				throw new ParserException("illegal identifier character (" + ch + ")", tok);
			}
		}

	}

	private boolean isAdjacent(IToken first, IToken second) {
		return first.getEnd() == second.getStart() - 1;
	}

	public ModifiersPattern parseModifiersPattern() {
		int requiredFlags = 0;
		int forbiddenFlags = 0;
		int start;
		while (true) {
			start = tokenSource.getIndex();
			boolean isForbidden = false;
			isForbidden = maybeEat("!");
			IToken t = tokenSource.next();
			int flag = ModifiersPattern.getModifierFlag(t.getString());
			if (flag == -1) {
				break;
			}
			if (isForbidden) {
				forbiddenFlags |= flag;
			} else {
				requiredFlags |= flag;
			}
		}

		tokenSource.setIndex(start);
		if (requiredFlags == 0 && forbiddenFlags == 0) {
			return ModifiersPattern.ANY;
		} else {
			return new ModifiersPattern(requiredFlags, forbiddenFlags);
		}
	}

	public TypePatternList parseArgumentsPattern(boolean parameterAnnotationsPossible) {
		List<TypePattern> patterns = new ArrayList<TypePattern>();
		eat("(");

		// ()
		if (maybeEat(")")) {
			return new TypePatternList();
		}

		do {
			if (maybeEat(".")) { // ..
				eat(".");
				patterns.add(TypePattern.ELLIPSIS);
			} else {
				patterns.add(parseTypePattern(false, parameterAnnotationsPossible));
			}
		} while (maybeEat(","));
		eat(")");
		return new TypePatternList(patterns);
	}

	public AnnotationPatternList parseArgumentsAnnotationPattern() {
		List<AnnotationTypePattern> patterns = new ArrayList<AnnotationTypePattern>();
		eat("(");
		if (maybeEat(")")) {
			return new AnnotationPatternList();
		}

		do {
			if (maybeEat(".")) {
				eat(".");
				patterns.add(AnnotationTypePattern.ELLIPSIS);
			} else if (maybeEat("*")) {
				patterns.add(AnnotationTypePattern.ANY);
			} else {
				patterns.add(parseAnnotationNameOrVarTypePattern());
			}
		} while (maybeEat(","));
		eat(")");
		return new AnnotationPatternList(patterns);
	}

	public ThrowsPattern parseOptionalThrowsPattern() {
		IToken t = tokenSource.peek();
		if (t.isIdentifier() && t.getString().equals("throws")) {
			tokenSource.next();
			List<TypePattern> required = new ArrayList<TypePattern>();
			List<TypePattern> forbidden = new ArrayList<TypePattern>();
			do {
				boolean isForbidden = maybeEat("!");
				// ???might want an error for a second ! without a paren
				TypePattern p = parseTypePattern();
				if (isForbidden) {
					forbidden.add(p);
				} else {
					required.add(p);
				}
			} while (maybeEat(","));
			return new ThrowsPattern(new TypePatternList(required), new TypePatternList(forbidden));
		}
		return ThrowsPattern.ANY;
	}

	public SignaturePattern parseMethodOrConstructorSignaturePattern() {
		int startPos = tokenSource.peek().getStart();
		AnnotationTypePattern annotationPattern = maybeParseAnnotationPattern();
		ModifiersPattern modifiers = parseModifiersPattern();
		TypePattern returnType = parseTypePattern(false, false);

		TypePattern declaringType;
		NamePattern name = null;
		MemberKind kind;
		// here we can check for 'new'
		if (maybeEatNew(returnType)) {
			kind = Member.CONSTRUCTOR;
			if (returnType.toString().length() == 0) {
				declaringType = TypePattern.ANY;
			} else {
				declaringType = returnType;
			}
			returnType = TypePattern.ANY;
			name = NamePattern.ANY;
		} else {
			kind = Member.METHOD;
			IToken nameToken = tokenSource.peek();
			declaringType = parseTypePattern(false, false);
			if (maybeEat(".")) {
				nameToken = tokenSource.peek();
				name = parseNamePattern();
			} else {
				name = tryToExtractName(declaringType);
				if (declaringType.toString().equals("")) {
					declaringType = TypePattern.ANY;
				}
			}
			if (name == null) {
				throw new ParserException("name pattern", tokenSource.peek());
			}
			String simpleName = name.maybeGetSimpleName();
			// XXX should add check for any Java keywords
			if (simpleName != null && simpleName.equals("new")) {
				throw new ParserException("method name (not constructor)", nameToken);
			}
		}

		TypePatternList parameterTypes = parseArgumentsPattern(true);

		ThrowsPattern throwsPattern = parseOptionalThrowsPattern();
		SignaturePattern ret = new SignaturePattern(kind, modifiers, returnType, declaringType, name, parameterTypes,
				throwsPattern, annotationPattern);
		int endPos = tokenSource.peek(-1).getEnd();
		ret.setLocation(sourceContext, startPos, endPos);
		return ret;
	}

	private boolean maybeEatNew(TypePattern returnType) {
		if (returnType instanceof WildTypePattern) {
			WildTypePattern p = (WildTypePattern) returnType;
			if (p.maybeExtractName("new")) {
				return true;
			}
		}
		int start = tokenSource.getIndex();
		if (maybeEat(".")) {
			String id = maybeEatIdentifier();
			if (id != null && id.equals("new")) {
				return true;
			}
			tokenSource.setIndex(start);
		}

		return false;
	}

	public ISignaturePattern parseMaybeParenthesizedFieldSignaturePattern() {
		boolean negated = tokenSource.peek().getString().equals("!") && tokenSource.peek(1).getString().equals("(");
		if (negated) {
			eat("!");
		}
		ISignaturePattern result = null;
		if (maybeEat("(")) {
			result = parseCompoundFieldSignaturePattern();
			eat(")", "missing ')' - unbalanced parentheses around field signature pattern in declare @field");
			if (negated) {
				result = new NotSignaturePattern(result);
			}
		} else {
			result = parseFieldSignaturePattern();
		}
		return result;
	}

	public ISignaturePattern parseMaybeParenthesizedMethodOrConstructorSignaturePattern(boolean isMethod) {
		boolean negated = tokenSource.peek().getString().equals("!") && tokenSource.peek(1).getString().equals("(");
		if (negated) {
			eat("!");
		}
		ISignaturePattern result = null;
		if (maybeEat("(")) {
			result = parseCompoundMethodOrConstructorSignaturePattern(isMethod);
			eat(")", "missing ')' - unbalanced parentheses around method/ctor signature pattern in declare annotation");
			if (negated) {
				result = new NotSignaturePattern(result);
			}
		} else {
			SignaturePattern sp = parseMethodOrConstructorSignaturePattern();
			boolean isConstructorPattern = (sp.getKind() == Member.CONSTRUCTOR);
			if (isMethod && isConstructorPattern) {
				throw new ParserException("method signature pattern", tokenSource.peek(-1));
			}
			if (!isMethod && !isConstructorPattern) {
				throw new ParserException("constructor signature pattern", tokenSource.peek(-1));
			}
			result = sp;
		}

		return result;
	}

	public SignaturePattern parseFieldSignaturePattern() {
		int startPos = tokenSource.peek().getStart();

		// TypePatternList followMe = TypePatternList.ANY;

		AnnotationTypePattern annotationPattern = maybeParseAnnotationPattern();
		ModifiersPattern modifiers = parseModifiersPattern();
		TypePattern returnType = parseTypePattern();
		TypePattern declaringType = parseTypePattern();
		NamePattern name;
		// System.err.println("parsed field: " + declaringType.toString());
		if (maybeEat(".")) {
			name = parseNamePattern();
		} else {
			name = tryToExtractName(declaringType);
			if (name == null) {
				throw new ParserException("name pattern", tokenSource.peek());
			}
			if (declaringType.toString().equals("")) {
				declaringType = TypePattern.ANY;
			}
		}
		SignaturePattern ret = new SignaturePattern(Member.FIELD, modifiers, returnType, declaringType, name, TypePatternList.ANY,
				ThrowsPattern.ANY, annotationPattern);

		int endPos = tokenSource.peek(-1).getEnd();
		ret.setLocation(sourceContext, startPos, endPos);
		return ret;
	}

	private NamePattern tryToExtractName(TypePattern nextType) {
		if (nextType == TypePattern.ANY) {
			return NamePattern.ANY;
		} else if (nextType instanceof WildTypePattern) {
			WildTypePattern p = (WildTypePattern) nextType;
			return p.extractName();
		} else {
			return null;
		}
	}

	/**
	 * Parse type variable declarations for a generic method or at the start of a signature pointcut to identify type variable names
	 * in a generic type.
	 * 
	 * @param includeParameterizedTypes
	 * @return
	 */
	public TypeVariablePatternList maybeParseTypeVariableList() {
		if (!maybeEat("<")) {
			return null;
		}
		List<TypeVariablePattern> typeVars = new ArrayList<TypeVariablePattern>();
		TypeVariablePattern t = parseTypeVariable();
		typeVars.add(t);
		while (maybeEat(",")) {
			TypeVariablePattern nextT = parseTypeVariable();
			typeVars.add(nextT);
		}
		eat(">");
		TypeVariablePattern[] tvs = new TypeVariablePattern[typeVars.size()];
		typeVars.toArray(tvs);
		return new TypeVariablePatternList(tvs);
	}

	// of the form execution<T,S,V> - allows identifiers only
	public String[] maybeParseSimpleTypeVariableList() {
		if (!maybeEat("<")) {
			return null;
		}
		List<String> typeVarNames = new ArrayList<String>();
		do {
			typeVarNames.add(parseIdentifier());
		} while (maybeEat(","));
		eat(">", "',' or '>'");
		String[] tvs = new String[typeVarNames.size()];
		typeVarNames.toArray(tvs);
		return tvs;
	}

	public TypePatternList maybeParseTypeParameterList() {
		if (!maybeEat("<")) {
			return null;
		}
		List<TypePattern> typePats = new ArrayList<TypePattern>();
		do {
			TypePattern tp = parseTypePattern(true, false);
			typePats.add(tp);
		} while (maybeEat(","));
		eat(">");
		TypePattern[] tps = new TypePattern[typePats.size()];
		typePats.toArray(tps);
		return new TypePatternList(tps);
	}

	public TypeVariablePattern parseTypeVariable() {
		TypePattern upperBound = null;
		TypePattern[] additionalInterfaceBounds = null;
		TypePattern lowerBound = null;
		String typeVariableName = parseIdentifier();
		if (maybeEatIdentifier("extends")) {
			upperBound = parseTypePattern();
			additionalInterfaceBounds = maybeParseAdditionalInterfaceBounds();
		} else if (maybeEatIdentifier("super")) {
			lowerBound = parseTypePattern();
		}
		return new TypeVariablePattern(typeVariableName, upperBound, additionalInterfaceBounds, lowerBound);
	}

	private TypePattern[] maybeParseAdditionalInterfaceBounds() {
		List<TypePattern> boundsList = new ArrayList<TypePattern>();
		while (maybeEat("&")) {
			TypePattern tp = parseTypePattern();
			boundsList.add(tp);
		}
		if (boundsList.size() == 0) {
			return null;
		}
		TypePattern[] ret = new TypePattern[boundsList.size()];
		boundsList.toArray(ret);
		return ret;
	}

	public String parsePossibleStringSequence(boolean shouldEnd) {
		StringBuffer result = new StringBuffer();

		IToken token = tokenSource.next();
		if (token.getLiteralKind() == null) {
			throw new ParserException("string", token);
		}
		while (token.getLiteralKind().equals("string")) {
			result.append(token.getString());
			boolean plus = maybeEat("+");
			if (!plus) {
				break;
			}
			token = tokenSource.next();
			if (token.getLiteralKind() == null) {
				throw new ParserException("string", token);
			}
		}
		eatIdentifier(";");
		IToken t = tokenSource.next();
		if (shouldEnd && t != IToken.EOF) {
			throw new ParserException("<string>;", token);
		}
		// bug 125027: since we've eaten the ";" we need to set the index
		// to be one less otherwise the end position isn't set correctly.
		int currentIndex = tokenSource.getIndex();
		tokenSource.setIndex(currentIndex - 1);

		return result.toString();

	}

	public String parseStringLiteral() {
		IToken token = tokenSource.next();
		String literalKind = token.getLiteralKind();
		if (literalKind == "string") {
			return token.getString();
		}

		throw new ParserException("string", token);
	}

	public String parseIdentifier() {
		IToken token = tokenSource.next();
		if (token.isIdentifier()) {
			return token.getString();
		}
		throw new ParserException("identifier", token);
	}

	public void eatIdentifier(String expectedValue) {
		IToken next = tokenSource.next();
		if (!next.getString().equals(expectedValue)) {
			throw new ParserException(expectedValue, next);
		}
	}

	public boolean maybeEatIdentifier(String expectedValue) {
		IToken next = tokenSource.peek();
		if (next.getString().equals(expectedValue)) {
			tokenSource.next();
			return true;
		} else {
			return false;
		}
	}

	public void eat(String expectedValue) {
		eat(expectedValue, expectedValue);
	}

	private void eat(String expectedValue, String expectedMessage) {
		IToken next = nextToken();
		if (next.getString() != expectedValue) {
			if (expectedValue.equals(">") && next.getString().startsWith(">")) {
				// handle problem of >> and >>> being lexed as single tokens
				pendingRightArrows = BasicToken.makeLiteral(next.getString().substring(1).intern(), "string", next.getStart() + 1,
						next.getEnd());
				return;
			}
			throw new ParserException(expectedMessage, next);
		}
	}

	private IToken pendingRightArrows;

	private IToken nextToken() {
		if (pendingRightArrows != null) {
			IToken ret = pendingRightArrows;
			pendingRightArrows = null;
			return ret;
		} else {
			return tokenSource.next();
		}
	}

	public boolean maybeEatAdjacent(String token) {
		IToken next = tokenSource.peek();
		if (next.getString() == token) {
			if (isAdjacent(tokenSource.peek(-1), next)) {
				tokenSource.next();
				return true;
			}
		}
		return false;
	}

	public boolean maybeEat(String token) {
		IToken next = tokenSource.peek();
		if (next.getString() == token) {
			tokenSource.next();
			return true;
		} else {
			return false;
		}
	}

	public String maybeEatIdentifier() {
		IToken next = tokenSource.peek();
		if (next.isIdentifier()) {
			tokenSource.next();
			return next.getString();
		} else {
			return null;
		}
	}

	public boolean peek(String token) {
		IToken next = tokenSource.peek();
		return next.getString() == token;
	}

	public void checkEof() {
		IToken last = tokenSource.next();
		if (last != IToken.EOF) {
			throw new ParserException("unexpected pointcut element: " + last.toString(), last);
		}
	}

	public PatternParser(String data) {
		this(BasicTokenSource.makeTokenSource(data, null));
	}

	public PatternParser(String data, ISourceContext context) {
		this(BasicTokenSource.makeTokenSource(data, context));
	}
}