1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 * Tom Tromey - patch for readTable(String) as described in http://bugs.eclipse.org/bugs/show_bug.cgi?id=32196
11 *******************************************************************************/
12 package org.eclipse.jdt.internal.compiler.parser;
15 import java.util.ArrayList;
16 import java.util.Collections;
17 import java.util.Iterator;
18 import java.util.List;
19 import java.util.Locale;
20 import java.util.MissingResourceException;
21 import java.util.ResourceBundle;
23 import org.eclipse.jdt.core.compiler.CharOperation;
24 import org.eclipse.jdt.core.compiler.InvalidInputException;
25 import org.eclipse.jdt.internal.compiler.CompilationResult;
26 import org.eclipse.jdt.internal.compiler.ast.*;
27 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
28 import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
29 import org.eclipse.jdt.internal.compiler.env.IGenericType;
30 import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
31 import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
32 import org.eclipse.jdt.internal.compiler.lookup.Binding;
33 import org.eclipse.jdt.internal.compiler.lookup.CompilerModifiers;
34 import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
35 import org.eclipse.jdt.internal.compiler.parser.diagnose.DiagnoseParser;
36 import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
37 import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
38 import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
39 import org.eclipse.jdt.internal.compiler.util.Util;
41 public class Parser implements ParserBasicInformation, TerminalTokens, CompilerModifiers, OperatorIds, TypeIds {
42 protected static final int THIS_CALL = ExplicitConstructorCall.This;
43 protected static final int SUPER_CALL = ExplicitConstructorCall.Super;
45 public static char asb[] = null;
46 public static char asr[] = null;
48 protected final static int AstStackIncrement = 100;
49 public static char base_action[] = null;
50 public static final int BracketKinds = 3;
52 public static short check_table[] = null;
53 public static final int CurlyBracket = 2;
54 // TODO remove once testing is done
55 private static final boolean DEBUG = false;
56 private static final String EOF_TOKEN = "$eof" ; //$NON-NLS-1$
57 private static final String ERROR_TOKEN = "$error" ; //$NON-NLS-1$
59 protected final static int ExpressionStackIncrement = 100;
61 protected final static int GenericsStackIncrement = 10;
63 private final static String FILEPREFIX = "parser"; //$NON-NLS-1$
64 public static char in_symb[] = null;
65 private static final String INVALID_CHARACTER = "Invalid Character" ; //$NON-NLS-1$
66 public static char lhs[] = null;
68 public static String name[] = null;
69 public static char nasb[] = null;
70 public static char nasr[] = null;
71 public static char non_terminal_index[] = null;
72 private final static String READABLE_NAMES_FILE = "readableNames"; //$NON-NLS-1$
73 private final static String READABLE_NAMES_FILE_NAME =
74 "org.eclipse.jdt.internal.compiler.parser." + READABLE_NAMES_FILE; //$NON-NLS-1$
75 public static String readableName[] = null;
77 public static byte rhs[] = null;
79 public static long rules_compliance[] = null;
81 public static final int RoundBracket = 0;
83 public static byte scope_la[] = null;
84 public static char scope_lhs[] = null;
86 public static char scope_prefix[] = null;
87 public static char scope_rhs[] = null;
88 public static char scope_state[] = null;
90 public static char scope_state_set[] = null;
91 public static char scope_suffix[] = null;
92 public static final int SquareBracket = 1;
94 //internal data for the automat
95 protected final static int StackIncrement = 255;
97 public static char term_action[] = null;
98 public static byte term_check[] = null;
100 public static char terminal_index[] = null;
102 private static final String UNEXPECTED_EOF = "Unexpected End Of File" ; //$NON-NLS-1$
103 public static boolean VERBOSE_RECOVERY = false;
107 protected int astLengthPtr;
108 protected int[] astLengthStack;
109 protected int astPtr;
110 protected ASTNode[] astStack = new ASTNode[AstStackIncrement];
111 public CompilationUnitDeclaration compilationUnit; /*the result from parse()*/
112 protected RecoveredElement currentElement;
113 public int currentToken;
114 protected boolean diet = false; //tells the scanner to jump over some parts of the code/expressions like method bodies
115 protected int dietInt = 0; // if > 0 force the none-diet-parsing mode (even if diet if requested) [field parsing with anonymous inner classes...]
116 protected int endPosition; //accurate only when used ! (the start position is pushed into intStack while the end the current one)
117 protected int endStatementPosition;
118 protected int expressionLengthPtr;
119 protected int[] expressionLengthStack;
120 protected int expressionPtr;
121 protected Expression[] expressionStack = new Expression[ExpressionStackIncrement];
122 public int firstToken ; // handle for multiple parsing goals
124 // generics management
125 protected int genericsIdentifiersLengthPtr;
126 protected int[] genericsIdentifiersLengthStack = new int[GenericsStackIncrement];
127 protected int genericsLengthPtr;
128 protected int[] genericsLengthStack = new int[GenericsStackIncrement];
129 protected int genericsPtr;
130 protected ASTNode[] genericsStack = new ASTNode[GenericsStackIncrement];
132 protected boolean hasError;
133 protected boolean hasReportedError;
136 protected int identifierLengthPtr;
137 protected int[] identifierLengthStack;
138 protected long[] identifierPositionStack;
139 protected int identifierPtr;
140 protected char[][] identifierStack;
142 protected boolean ignoreNextOpeningBrace;
143 //positions , dimensions , .... (int stacks)
144 protected int intPtr;
145 protected int[] intStack;
146 public int lastAct ; //handle for multiple parsing goals
148 //error recovery management
149 protected int lastCheckPoint;
150 protected int lastErrorEndPosition;
151 protected int lastErrorEndPositionBeforeRecovery = -1;
152 protected int lastIgnoredToken, nextIgnoredToken;
153 protected int listLength; // for recovering some incomplete list (interfaces, throws or parameters)
154 protected int listTypeParameterLength; // for recovering some incomplete list (type parameters)
155 protected int lParenPos,rParenPos; //accurate only when used !
156 protected int modifiers;
157 protected int modifiersSourceStart;
158 protected int[] nestedMethod; //the ptr is nestedType
159 protected int nestedType, dimensions;
160 ASTNode [] noAstNodes = new ASTNode[AstStackIncrement];
161 Expression [] noExpressions = new Expression[ExpressionStackIncrement];
162 //modifiers dimensions nestedType etc.......
163 protected boolean optimizeStringLiterals =true;
164 protected CompilerOptions options;
165 protected ProblemReporter problemReporter;
166 protected int rBraceStart, rBraceEnd, rBraceSuccessorStart; //accurate only when used !
167 protected int realBlockPtr;
168 protected int[] realBlockStack;
169 protected int recoveredStaticInitializerStart;
170 public ReferenceContext referenceContext;
171 public boolean reportOnlyOneSyntaxError = false;
172 public boolean reportSyntaxErrorIsRequired = true;
173 protected boolean restartRecovery;
175 public Scanner scanner;
176 protected int[] stack = new int[StackIncrement];
177 protected int stateStackTop;
178 protected int synchronizedBlockSourceStart;
179 protected int[] variablesCounter;
182 public Javadoc javadoc;
183 public JavadocParser javadocParser;
185 protected int lastJavadocEnd;
190 } catch(java.io.IOException ex){
191 throw new ExceptionInInitializerError(ex.getMessage());
194 public static int asi(int state) {
196 return asb[original_state(state)];
198 public final static short base_check(int i) {
199 return check_table[i - (NUM_RULES + 1)];
201 private final static void buildFile(String filename, List listToDump) throws java.io.IOException {
202 BufferedWriter writer = new BufferedWriter(new FileWriter(filename));
203 for (Iterator iterator = listToDump.iterator(); iterator.hasNext(); ) {
204 writer.write(String.valueOf(iterator.next()));
208 System.out.println(filename + " creation complete"); //$NON-NLS-1$
210 private final static String[] buildFileForName(String filename, String contents) throws java.io.IOException {
211 String[] result = new String[contents.length()];
215 StringBuffer buffer = new StringBuffer();
217 int start = contents.indexOf("name[]"); //$NON-NLS-1$
218 start = contents.indexOf('\"', start);
219 int end = contents.indexOf("};", start); //$NON-NLS-1$
221 contents = contents.substring(start, end);
223 boolean addLineSeparator = false;
225 StringBuffer currentToken = new StringBuffer();
226 for (int i = 0; i < contents.length(); i++) {
227 char c = contents.charAt(i);
229 if(tokenStart == -1) {
232 if(addLineSeparator) {
234 result[resultCount++] = currentToken.toString();
235 currentToken = new StringBuffer();
237 String token = contents.substring(tokenStart, i);
238 if(token.equals(ERROR_TOKEN)){
239 token = INVALID_CHARACTER;
240 } else if(token.equals(EOF_TOKEN)) {
241 token = UNEXPECTED_EOF;
243 buffer.append(token);
244 currentToken.append(token);
245 addLineSeparator = true;
249 if(tokenStart == -1 && c == '+'){
250 addLineSeparator = false;
253 if(currentToken.length() > 0) {
254 result[resultCount++] = currentToken.toString();
257 buildFileForTable(filename, buffer.toString().toCharArray());
259 System.arraycopy(result, 0, result = new String[resultCount], 0, resultCount);
262 private static void buildFileForReadableName(
265 char[] newNonTerminalIndex,
267 String[] tokens) throws java.io.IOException {
269 ArrayList entries = new ArrayList();
271 boolean[] alreadyAdded = new boolean[newName.length];
273 for (int i = 0; i < tokens.length; i = i + 3) {
274 if("1".equals(tokens[i])) { //$NON-NLS-1$
275 int index = newNonTerminalIndex[newLhs[Integer.parseInt(tokens[i + 1])]];
276 StringBuffer buffer = new StringBuffer();
277 if(!alreadyAdded[index]) {
278 alreadyAdded[index] = true;
279 buffer.append(newName[index]);
281 buffer.append(tokens[i+2].trim());
283 entries.add(String.valueOf(buffer));
288 while(!INVALID_CHARACTER.equals(newName[i])) i++;
290 for (; i < alreadyAdded.length; i++) {
291 if(!alreadyAdded[i]) {
292 System.out.println(newName[i] + " has no readable name"); //$NON-NLS-1$
295 Collections.sort(entries);
296 buildFile(file, entries);
298 private static void buildFileForCompliance(
301 String[] tokens) throws java.io.IOException {
303 byte[] result = new byte[length * 8];
305 for (int i = 0; i < tokens.length; i = i + 3) {
306 if("2".equals(tokens[i])) { //$NON-NLS-1$
307 int index = Integer.parseInt(tokens[i + 1]);
308 String token = tokens[i + 2].trim();
310 if("1.4".equals(token)) { //$NON-NLS-1$
311 compliance = ClassFileConstants.JDK1_4;
312 } else if("1.5".equals(token)) { //$NON-NLS-1$
313 compliance = ClassFileConstants.JDK1_5;
314 } else if("recovery".equals(token)) { //$NON-NLS-1$
315 compliance = ClassFileConstants.JDK_DEFERRED;
319 result[j] = (byte)(compliance >>> 56);
320 result[j + 1] = (byte)(compliance >>> 48);
321 result[j + 2] = (byte)(compliance >>> 40);
322 result[j + 3] = (byte)(compliance >>> 32);
323 result[j + 4] = (byte)(compliance >>> 24);
324 result[j + 5] = (byte)(compliance >>> 16);
325 result[j + 6] = (byte)(compliance >>> 8);
326 result[j + 7] = (byte)(compliance);
330 buildFileForTable(file, result); //$NON-NLS-1$
332 private final static void buildFileForTable(String filename, byte[] bytes) throws java.io.IOException {
333 java.io.FileOutputStream stream = new java.io.FileOutputStream(filename);
336 System.out.println(filename + " creation complete"); //$NON-NLS-1$
338 private final static void buildFileForTable(String filename, char[] chars) throws java.io.IOException {
340 byte[] bytes = new byte[chars.length * 2];
341 for (int i = 0; i < chars.length; i++) {
342 bytes[2 * i] = (byte) (chars[i] >>> 8);
343 bytes[2 * i + 1] = (byte) (chars[i] & 0xFF);
346 java.io.FileOutputStream stream = new java.io.FileOutputStream(filename);
349 System.out.println(filename + " creation complete"); //$NON-NLS-1$
351 private final static byte[] buildFileOfByteFor(String filename, String tag, String[] tokens) throws java.io.IOException {
353 //transform the String tokens into chars before dumping then into file
357 while (!tokens[i++].equals(tag)){/*empty*/}
360 byte[] bytes = new byte[tokens.length]; //can't be bigger
363 while (!(token = tokens[i++]).equals("}")) { //$NON-NLS-1$
364 int c = Integer.parseInt(token);
365 bytes[ic++] = (byte) c;
369 System.arraycopy(bytes, 0, bytes = new byte[ic], 0, ic);
371 buildFileForTable(filename, bytes);
374 private final static char[] buildFileOfIntFor(String filename, String tag, String[] tokens) throws java.io.IOException {
376 //transform the String tokens into chars before dumping then into file
380 while (!tokens[i++].equals(tag)){/*empty*/}
383 char[] chars = new char[tokens.length]; //can't be bigger
386 while (!(token = tokens[i++]).equals("}")) { //$NON-NLS-1$
387 int c = Integer.parseInt(token);
388 chars[ic++] = (char) c;
392 System.arraycopy(chars, 0, chars = new char[ic], 0, ic);
394 buildFileForTable(filename, chars);
397 private final static void buildFileOfShortFor(String filename, String tag, String[] tokens) throws java.io.IOException {
399 //transform the String tokens into chars before dumping then into file
403 while (!tokens[i++].equals(tag)){/*empty*/}
406 char[] chars = new char[tokens.length]; //can't be bigger
409 while (!(token = tokens[i++]).equals("}")) { //$NON-NLS-1$
410 int c = Integer.parseInt(token);
411 chars[ic++] = (char) (c + 32768);
415 System.arraycopy(chars, 0, chars = new char[ic], 0, ic);
417 buildFileForTable(filename, chars);
419 public final static void buildFilesFromLPG(String dataFilename, String dataFilename2) throws java.io.IOException {
421 //RUN THIS METHOD TO GENERATE PARSER*.RSC FILES
423 //build from the lpg javadcl.java files that represents the parser tables
424 //lhs check_table asb asr symbol_index
426 //[org.eclipse.jdt.internal.compiler.parser.Parser.buildFilesFromLPG("d:/leapfrog/grammar/javadcl.java")]
427 char[] contents = new char[] {};
429 contents = Util.getFileCharContent(new File(dataFilename), null);
430 } catch (IOException ex) {
431 System.out.println(Util.bind("parser.incorrectPath")); //$NON-NLS-1$
434 java.util.StringTokenizer st =
435 new java.util.StringTokenizer(new String(contents), " \t\n\r[]={,;"); //$NON-NLS-1$
436 String[] tokens = new String[st.countTokens()];
438 while (st.hasMoreTokens()) {
439 tokens[j++] = st.nextToken();
441 final String prefix = FILEPREFIX;
444 char[] newLhs = buildFileOfIntFor(prefix + (++i) + ".rsc", "lhs", tokens); //$NON-NLS-1$ //$NON-NLS-2$
445 buildFileOfShortFor(prefix + (++i) + ".rsc", "check_table", tokens); //$NON-NLS-2$ //$NON-NLS-1$
446 buildFileOfIntFor(prefix + (++i) + ".rsc", "asb", tokens); //$NON-NLS-2$ //$NON-NLS-1$
447 buildFileOfIntFor(prefix + (++i) + ".rsc", "asr", tokens); //$NON-NLS-2$ //$NON-NLS-1$
448 buildFileOfIntFor(prefix + (++i) + ".rsc", "nasb", tokens); //$NON-NLS-2$ //$NON-NLS-1$
449 buildFileOfIntFor(prefix + (++i) + ".rsc", "nasr", tokens); //$NON-NLS-2$ //$NON-NLS-1$
450 buildFileOfIntFor(prefix + (++i) + ".rsc", "terminal_index", tokens); //$NON-NLS-2$ //$NON-NLS-1$
451 char[] newNonTerminalIndex = buildFileOfIntFor(prefix + (++i) + ".rsc", "non_terminal_index", tokens); //$NON-NLS-1$ //$NON-NLS-2$
452 buildFileOfIntFor(prefix + (++i) + ".rsc", "term_action", tokens); //$NON-NLS-2$ //$NON-NLS-1$
454 buildFileOfIntFor(prefix + (++i) + ".rsc", "scope_prefix", tokens); //$NON-NLS-2$ //$NON-NLS-1$
455 buildFileOfIntFor(prefix + (++i) + ".rsc", "scope_suffix", tokens); //$NON-NLS-2$ //$NON-NLS-1$
456 buildFileOfIntFor(prefix + (++i) + ".rsc", "scope_lhs", tokens); //$NON-NLS-2$ //$NON-NLS-1$
457 buildFileOfIntFor(prefix + (++i) + ".rsc", "scope_state_set", tokens); //$NON-NLS-2$ //$NON-NLS-1$
458 buildFileOfIntFor(prefix + (++i) + ".rsc", "scope_rhs", tokens); //$NON-NLS-2$ //$NON-NLS-1$
459 buildFileOfIntFor(prefix + (++i) + ".rsc", "scope_state", tokens); //$NON-NLS-2$ //$NON-NLS-1$
460 buildFileOfIntFor(prefix + (++i) + ".rsc", "in_symb", tokens); //$NON-NLS-2$ //$NON-NLS-1$
462 byte[] newRhs = buildFileOfByteFor(prefix + (++i) + ".rsc", "rhs", tokens); //$NON-NLS-2$ //$NON-NLS-1$
463 buildFileOfByteFor(prefix + (++i) + ".rsc", "term_check", tokens); //$NON-NLS-2$ //$NON-NLS-1$
464 buildFileOfByteFor(prefix + (++i) + ".rsc", "scope_la", tokens); //$NON-NLS-2$ //$NON-NLS-1$
466 String[] newName = buildFileForName(prefix + (++i) + ".rsc", new String(contents)); //$NON-NLS-1$
468 contents = new char[] {};
470 contents = Util.getFileCharContent(new File(dataFilename2), null);
471 } catch (IOException ex) {
472 System.out.println(Util.bind("parser.incorrectPath")); //$NON-NLS-1$
475 st = new java.util.StringTokenizer(new String(contents), "\t\n\r=#"); //$NON-NLS-1$
476 tokens = new String[st.countTokens()];
478 while (st.hasMoreTokens()) {
479 tokens[j++] = st.nextToken();
482 buildFileForCompliance(prefix + (++i) + ".rsc", newRhs.length, tokens);//$NON-NLS-1$
483 buildFileForReadableName(READABLE_NAMES_FILE+".properties", newLhs, newNonTerminalIndex, newName, tokens);//$NON-NLS-1$
485 System.out.println(Util.bind("parser.moveFiles")); //$NON-NLS-1$
487 public static int in_symbol(int state) {
488 return in_symb[original_state(state)];
490 public final static void initTables() throws java.io.IOException {
492 final String prefix = FILEPREFIX;
494 lhs = readTable(prefix + (++i) + ".rsc"); //$NON-NLS-1$
495 char[] chars = readTable(prefix + (++i) + ".rsc"); //$NON-NLS-1$
496 check_table = new short[chars.length];
497 for (int c = chars.length; c-- > 0;) {
498 check_table[c] = (short) (chars[c] - 32768);
500 asb = readTable(prefix + (++i) + ".rsc"); //$NON-NLS-1$
501 asr = readTable(prefix + (++i) + ".rsc"); //$NON-NLS-1$
502 nasb = readTable(prefix + (++i) + ".rsc"); //$NON-NLS-1$
503 nasr = readTable(prefix + (++i) + ".rsc"); //$NON-NLS-1$
504 terminal_index = readTable(prefix + (++i) + ".rsc"); //$NON-NLS-1$
505 non_terminal_index = readTable(prefix + (++i) + ".rsc"); //$NON-NLS-1$
506 term_action = readTable(prefix + (++i) + ".rsc"); //$NON-NLS-1$
508 scope_prefix = readTable(prefix + (++i) + ".rsc"); //$NON-NLS-1$
509 scope_suffix = readTable(prefix + (++i) + ".rsc"); //$NON-NLS-1$
510 scope_lhs = readTable(prefix + (++i) + ".rsc"); //$NON-NLS-1$
511 scope_state_set = readTable(prefix + (++i) + ".rsc"); //$NON-NLS-1$
512 scope_rhs = readTable(prefix + (++i) + ".rsc"); //$NON-NLS-1$
513 scope_state = readTable(prefix + (++i) + ".rsc"); //$NON-NLS-1$
514 in_symb = readTable(prefix + (++i) + ".rsc"); //$NON-NLS-1$
516 rhs = readByteTable(prefix + (++i) + ".rsc"); //$NON-NLS-1$
517 term_check = readByteTable(prefix + (++i) + ".rsc"); //$NON-NLS-1$
518 scope_la = readByteTable(prefix + (++i) + ".rsc"); //$NON-NLS-1$
520 name = readNameTable(prefix + (++i) + ".rsc"); //$NON-NLS-1$
522 rules_compliance = readLongTable(prefix + (++i) + ".rsc"); //$NON-NLS-1$
524 readableName = readReadableNameTable(READABLE_NAMES_FILE_NAME);
528 public static int nasi(int state) {
529 return nasb[original_state(state)];
531 public static int ntAction(int state, int sym) {
532 return base_action[state + sym];
534 protected static int original_state(int state) {
535 return -base_check(state);
537 protected static byte[] readByteTable(String filename) throws java.io.IOException {
539 //files are located at Parser.class directory
541 InputStream stream = Parser.class.getResourceAsStream(filename);
542 if (stream == null) {
543 throw new java.io.IOException(Util.bind("parser.missingFile",filename)); //$NON-NLS-1$
547 stream = new BufferedInputStream(stream);
548 bytes = Util.getInputStreamAsByteArray(stream, -1);
552 } catch (IOException e) {
559 protected static String[] readNameTable(String filename) throws java.io.IOException {
560 char[] contents = readTable(filename);
561 char[][] nameAsChar = CharOperation.splitOn('\n', contents);
563 String[] result = new String[nameAsChar.length + 1];
565 for (int i = 0; i < nameAsChar.length; i++) {
566 result[i + 1] = new String(nameAsChar[i]);
571 protected static String[] readReadableNameTable(String filename) {
572 String[] result = new String[name.length];
574 ResourceBundle bundle;
576 bundle = ResourceBundle.getBundle(filename, Locale.getDefault());
577 } catch(MissingResourceException e) {
578 System.out.println("Missing resource : " + filename.replace('.', '/') + ".properties for locale " + Locale.getDefault()); //$NON-NLS-1$//$NON-NLS-2$
581 for (int i = 0; i < NT_OFFSET + 1; i++) {
584 for (int i = NT_OFFSET; i < name.length; i++) {
586 String n = bundle.getString(name[i]);
587 if(n != null && n.length() > 0) {
592 } catch(MissingResourceException e) {
598 protected static char[] readTable(String filename) throws java.io.IOException {
600 //files are located at Parser.class directory
602 InputStream stream = Parser.class.getResourceAsStream(filename);
603 if (stream == null) {
604 throw new java.io.IOException(Util.bind("parser.missingFile",filename)); //$NON-NLS-1$
608 stream = new BufferedInputStream(stream);
609 bytes = Util.getInputStreamAsByteArray(stream, -1);
613 } catch (IOException e) {
618 //minimal integrity check (even size expected)
619 int length = bytes.length;
621 throw new java.io.IOException(Util.bind("parser.corruptedFile",filename)); //$NON-NLS-1$
623 // convert bytes into chars
624 char[] chars = new char[length / 2];
629 chars[charIndex++] = (char) (((bytes[i++] & 0xFF) << 8) + (bytes[i++] & 0xFF));
635 protected static long[] readLongTable(String filename) throws java.io.IOException {
637 //files are located at Parser.class directory
639 InputStream stream = Parser.class.getResourceAsStream(filename);
640 if (stream == null) {
641 throw new java.io.IOException(Util.bind("parser.missingFile",filename)); //$NON-NLS-1$
645 stream = new BufferedInputStream(stream);
646 bytes = Util.getInputStreamAsByteArray(stream, -1);
650 } catch (IOException e) {
655 //minimal integrity check (even size expected)
656 int length = bytes.length;
658 throw new java.io.IOException(Util.bind("parser.corruptedFile",filename)); //$NON-NLS-1$
660 // convert bytes into longs
661 long[] longs = new long[length / 8];
667 (((long) (bytes[i++] & 0xFF)) << 56)
668 + (((long) (bytes[i++] & 0xFF)) << 48)
669 + (((long) (bytes[i++] & 0xFF)) << 40)
670 + (((long) (bytes[i++] & 0xFF)) << 32)
671 + (((long) (bytes[i++] & 0xFF)) << 24)
672 + (((long) (bytes[i++] & 0xFF)) << 16)
673 + (((long) (bytes[i++] & 0xFF)) << 8)
674 + (bytes[i++] & 0xFF);
681 public static int tAction(int state, int sym) {
682 return term_action[term_check[base_action[state]+sym] == sym ? base_action[state] + sym : base_action[state]];
685 public Parser(ProblemReporter problemReporter, boolean optimizeStringLiterals) {
687 this.problemReporter = problemReporter;
688 this.options = problemReporter.options;
689 this.optimizeStringLiterals = optimizeStringLiterals;
690 this.initializeScanner();
691 this.astLengthStack = new int[50];
692 this.expressionLengthStack = new int[30];
693 this.intStack = new int[50];
694 this.identifierStack = new char[30][];
695 this.identifierLengthStack = new int[30];
696 this.nestedMethod = new int[30];
697 this.realBlockStack = new int[30];
698 this.identifierPositionStack = new long[30];
699 this.variablesCounter = new int[30];
702 this.javadocParser = new JavadocParser(this);
704 public void arrayInitializer(int length) {
705 //length is the size of the array Initializer
706 //expressionPtr points on the last elt of the arrayInitializer,
707 // in other words, it has not been decremented yet.
709 ArrayInitializer ai = new ArrayInitializer();
711 this.expressionPtr -= length;
712 System.arraycopy(this.expressionStack, this.expressionPtr + 1, ai.expressions = new Expression[length], 0, length);
714 pushOnExpressionStack(ai);
716 ai.sourceEnd = this.endStatementPosition;
717 ai.sourceStart = this.intStack[this.intPtr--];
719 protected void blockReal() {
720 // See consumeLocalVariableDeclarationStatement in case of change: duplicated code
721 // increment the amount of declared variables for this block
722 this.realBlockStack[this.realBlockPtr]++;
725 * Build initial recovery state.
726 * Recovery state is inferred from the current state of the parser (reduced node stack).
728 public RecoveredElement buildInitialRecoveryState(){
730 /* initialize recovery by retrieving available reduced nodes
731 * also rebuild bracket balance
733 this.lastCheckPoint = 0;
734 this.lastErrorEndPositionBeforeRecovery = this.scanner.currentPosition;
736 RecoveredElement element = null;
737 if (this.referenceContext instanceof CompilationUnitDeclaration){
738 element = new RecoveredUnit(this.compilationUnit, 0, this);
740 /* ignore current stack state, since restarting from the beginnning
741 since could not trust simple brace count */
742 if (true){ // experimenting restart recovery from scratch
743 this.compilationUnit.currentPackage = null;
744 this.compilationUnit.imports = null;
745 this.compilationUnit.types = null;
746 this.currentToken = 0;
748 this.listTypeParameterLength = 0;
749 this.endPosition = 0;
750 this.endStatementPosition = 0;
753 if (this.compilationUnit.currentPackage != null){
754 this.lastCheckPoint = this.compilationUnit.currentPackage.declarationSourceEnd+1;
756 if (this.compilationUnit.imports != null){
757 this.lastCheckPoint = this.compilationUnit.imports[this.compilationUnit.imports.length -1].declarationSourceEnd+1;
760 if (this.referenceContext instanceof AbstractMethodDeclaration){
761 element = new RecoveredMethod((AbstractMethodDeclaration) this.referenceContext, null, 0, this);
762 this.lastCheckPoint = ((AbstractMethodDeclaration) this.referenceContext).bodyStart;
764 /* Initializer bodies are parsed in the context of the type declaration, we must thus search it inside */
765 if (this.referenceContext instanceof TypeDeclaration){
766 TypeDeclaration type = (TypeDeclaration) this.referenceContext;
767 for (int i = 0; i < type.fields.length; i++){
768 FieldDeclaration field = type.fields[i];
770 && field.getKind() == AbstractVariableDeclaration.INITIALIZER
771 && field.declarationSourceStart <= this.scanner.initialPosition
772 && this.scanner.initialPosition <= field.declarationSourceEnd
773 && this.scanner.eofPosition <= field.declarationSourceEnd+1){
774 element = new RecoveredInitializer(field, null, 1, this);
775 this.lastCheckPoint = field.declarationSourceStart;
783 if (element == null) return element;
785 for(int i = 0; i <= this.astPtr; i++){
786 ASTNode node = this.astStack[i];
787 if (node instanceof AbstractMethodDeclaration){
788 AbstractMethodDeclaration method = (AbstractMethodDeclaration) node;
789 if (method.declarationSourceEnd == 0){
790 element = element.add(method, 0);
791 this.lastCheckPoint = method.bodyStart;
793 element = element.add(method, 0);
794 this.lastCheckPoint = method.declarationSourceEnd + 1;
798 if (node instanceof Initializer){
799 Initializer initializer = (Initializer) node;
800 if (initializer.declarationSourceEnd == 0){
801 element = element.add(initializer, 1);
802 this.lastCheckPoint = initializer.sourceStart;
804 element = element.add(initializer, 0);
805 this.lastCheckPoint = initializer.declarationSourceEnd + 1;
809 if (node instanceof FieldDeclaration){
810 FieldDeclaration field = (FieldDeclaration) node;
811 if (field.declarationSourceEnd == 0){
812 element = element.add(field, 0);
813 if (field.initialization == null){
814 this.lastCheckPoint = field.sourceEnd + 1;
816 this.lastCheckPoint = field.initialization.sourceEnd + 1;
819 element = element.add(field, 0);
820 this.lastCheckPoint = field.declarationSourceEnd + 1;
824 if (node instanceof TypeDeclaration){
825 TypeDeclaration type = (TypeDeclaration) node;
826 if (type.declarationSourceEnd == 0){
827 element = element.add(type, 0);
828 this.lastCheckPoint = type.bodyStart;
830 element = element.add(type, 0);
831 this.lastCheckPoint = type.declarationSourceEnd + 1;
835 if (node instanceof ImportReference){
836 ImportReference importRef = (ImportReference) node;
837 element = element.add(importRef, 0);
838 this.lastCheckPoint = importRef.declarationSourceEnd + 1;
844 protected void checkAndSetModifiers(int flag){
845 /*modify the current modifiers buffer.
846 When the startPosition of the modifiers is 0
847 it means that the modifier being parsed is the first
848 of a list of several modifiers. The startPosition
849 is zeroed when a copy of modifiers-buffer is push
850 onto the this.astStack. */
852 if ((this.modifiers & flag) != 0){ // duplicate modifier
853 this.modifiers |= AccAlternateModifierProblem;
855 this.modifiers |= flag;
857 if (this.modifiersSourceStart < 0) this.modifiersSourceStart = this.scanner.startPosition;
859 public void checkComment() {
861 // discard obsolete comments while inside methods or fields initializer (see bug 74369)
862 if (!(this.diet && this.dietInt==0) && this.scanner.commentPtr >= 0) {
863 flushCommentsDefinedPriorTo(this.endStatementPosition);
866 int lastComment = this.scanner.commentPtr;
868 if (this.modifiersSourceStart >= 0) {
869 // eliminate comments located after modifierSourceStart if positionned
870 while (lastComment >= 0 && this.scanner.commentStarts[lastComment] > this.modifiersSourceStart) lastComment--;
872 if (lastComment >= 0) {
873 // consider all remaining leading comments to be part of current declaration
874 this.modifiersSourceStart = this.scanner.commentStarts[0];
876 // check deprecation in last comment if javadoc (can be followed by non-javadoc comments which are simply ignored)
877 while (lastComment >= 0 && this.scanner.commentStops[lastComment] < 0) lastComment--; // non javadoc comment have negative end positions
878 if (lastComment >= 0 && this.javadocParser != null) {
879 int commentEnd = this.scanner.commentStops[lastComment] - 1; //stop is one over,
880 // do not report problem before last parsed comment while recovering code...
881 this.javadocParser.reportProblems = this.currentElement == null || commentEnd > this.lastJavadocEnd;
882 if (this.javadocParser.checkDeprecation(this.scanner.commentStarts[lastComment], commentEnd)) {
883 checkAndSetModifiers(AccDeprecated);
885 this.javadoc = this.javadocParser.docComment; // null if check javadoc is not activated
886 if (currentElement == null) this.lastJavadocEnd = commentEnd;
890 protected void checkNonExternalizedStringLiteral() {
891 if (this.scanner.wasNonExternalizedStringLiteral) {
892 StringLiteral[] literals = this.scanner.nonNLSStrings;
893 // could not reproduce, but this is the only NPE
894 // added preventive null check see PR 9035
895 if (literals != null) {
896 for (int i = 0, max = literals.length; i < max; i++) {
897 problemReporter().nonExternalizedStringLiteral(literals[i]);
900 this.scanner.wasNonExternalizedStringLiteral = false;
903 protected void checkNonNLSAfterBodyEnd(int declarationEnd){
904 if(this.scanner.currentPosition - 1 <= declarationEnd) {
905 this.scanner.eofPosition = declarationEnd < Integer.MAX_VALUE ? declarationEnd + 1 : declarationEnd;
907 while(this.scanner.getNextToken() != TokenNameEOF){/*empty*/}
908 checkNonExternalizedStringLiteral();
909 } catch (InvalidInputException e) {
914 protected void classInstanceCreation(boolean hasClassBody) {
915 // ClassInstanceCreationExpression ::= 'new' ClassType '(' ArgumentListopt ')' ClassBodyopt
917 // ClassBodyopt produces a null item on the astStak if it produces NO class body
918 // An empty class body produces a 0 on the length stack.....
920 AllocationExpression alloc;
922 if (((length = this.astLengthStack[this.astLengthPtr--]) == 1)
923 && (this.astStack[this.astPtr] == null)) {
927 alloc = new QualifiedAllocationExpression();
929 alloc = new AllocationExpression();
931 alloc.sourceEnd = this.endPosition; //the position has been stored explicitly
933 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
934 this.expressionPtr -= length;
936 this.expressionStack,
937 this.expressionPtr + 1,
938 alloc.arguments = new Expression[length],
942 alloc.type = getTypeReference(0);
944 //the default constructor with the correct number of argument
945 //will be created and added by the TC (see createsInternalConstructorWithBinding)
946 alloc.sourceStart = this.intStack[this.intPtr--];
947 pushOnExpressionStack(alloc);
949 dispatchDeclarationInto(length);
950 TypeDeclaration anonymousTypeDeclaration = (TypeDeclaration)this.astStack[this.astPtr];
951 anonymousTypeDeclaration.declarationSourceEnd = this.endStatementPosition;
952 anonymousTypeDeclaration.bodyEnd = this.endStatementPosition;
953 if (anonymousTypeDeclaration.allocation != null) {
954 anonymousTypeDeclaration.allocation.sourceEnd = this.endStatementPosition;
956 if (length == 0 && !containsComment(anonymousTypeDeclaration.bodyStart, anonymousTypeDeclaration.bodyEnd)) {
957 anonymousTypeDeclaration.bits |= ASTNode.UndocumentedEmptyBlockMASK;
962 // mark initializers with local type mark if needed
963 markInitializersWithLocalType(anonymousTypeDeclaration);
966 protected void concatExpressionLists() {
967 this.expressionLengthStack[--this.expressionLengthPtr]++;
969 protected void concatGenericsLists() {
970 this.genericsLengthStack[this.genericsLengthPtr - 1] += this.genericsLengthStack[this.genericsLengthPtr--];
972 protected void concatNodeLists() {
974 * This is a case where you have two sublists into the this.astStack that you want
975 * to merge in one list. There is no action required on the this.astStack. The only
976 * thing you need to do is merge the two lengths specified on the astStackLength.
977 * The top two length are for example:
979 * and you want to result in a list like:
981 * This means that the p could be equals to 0 in case there is no astNode pushed
982 * on the this.astStack.
983 * Look at the InterfaceMemberDeclarations for an example.
986 this.astLengthStack[this.astLengthPtr - 1] += this.astLengthStack[this.astLengthPtr--];
988 protected void consumeAdditionalBound() {
989 pushOnGenericsStack(getTypeReference(this.intStack[this.intPtr--]));
991 protected void consumeAdditionalBound1() {
992 // nothing to be done.
993 // The reference type1 is consumed by consumeReferenceType1 method.
995 protected void consumeAdditionalBoundList() {
996 concatGenericsLists();
998 protected void consumeAdditionalBoundList1() {
999 concatGenericsLists();
1001 protected void consumeAllocationHeader() {
1002 // ClassInstanceCreationExpression ::= 'new' ClassType '(' ArgumentListopt ')' ClassBodyopt
1004 // ClassBodyopt produces a null item on the astStak if it produces NO class body
1005 // An empty class body produces a 0 on the length stack.....
1007 if (this.currentElement == null){
1008 return; // should never occur, this consumeRule is only used in recovery mode
1010 if (this.currentToken == TokenNameLBRACE){
1011 // beginning of an anonymous type
1012 TypeDeclaration anonymousType = new TypeDeclaration(this.compilationUnit.compilationResult);
1013 anonymousType.name = TypeDeclaration.ANONYMOUS_EMPTY_NAME;
1014 anonymousType.bits |= ASTNode.AnonymousAndLocalMask;
1015 anonymousType.sourceStart = this.intStack[this.intPtr--];
1016 anonymousType.sourceEnd = this.rParenPos; // closing parenthesis
1017 QualifiedAllocationExpression alloc = new QualifiedAllocationExpression(anonymousType);
1018 alloc.type = getTypeReference(0);
1019 alloc.sourceStart = anonymousType.sourceStart;
1020 alloc.sourceEnd = anonymousType.sourceEnd ;
1021 this.lastCheckPoint = anonymousType.bodyStart = this.scanner.currentPosition;
1022 this.currentElement = this.currentElement.add(anonymousType, 0);
1023 this.lastIgnoredToken = -1;
1024 this.currentToken = 0; // opening brace already taken into account
1027 this.lastCheckPoint = this.scanner.startPosition; // force to restart at this exact position
1028 this.restartRecovery = true; // request to restart from here on
1030 protected void consumeAnnotationAsModifier() {
1033 protected void consumeAnnotationName() {
1036 protected void consumeAnnotationTypeDeclaration() {
1038 if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) {
1039 //there are length declarations
1040 //dispatch according to the type of the declarations
1041 dispatchDeclarationInto(length);
1044 TypeDeclaration typeDecl = (TypeDeclaration) this.astStack[this.astPtr];
1046 // mark initializers with local type mark if needed
1047 markInitializersWithLocalType(typeDecl);
1049 //convert constructor that do not have the type's name into methods
1050 typeDecl.checkConstructors(this);
1052 //always add <clinit> (will be remove at code gen time if empty)
1053 if (this.scanner.containsAssertKeyword) {
1054 typeDecl.bits |= ASTNode.AddAssertionMASK;
1056 typeDecl.addClinit();
1057 typeDecl.bodyEnd = this.endStatementPosition;
1058 if (length == 0 && !containsComment(typeDecl.bodyStart, typeDecl.bodyEnd)) {
1059 typeDecl.bits |= ASTNode.UndocumentedEmptyBlockMASK;
1061 typeDecl.declarationSourceEnd = flushCommentsDefinedPriorTo(this.endStatementPosition);
1063 protected void consumeAnnotationTypeDeclarationHeader() {
1064 if (this.currentElement != null) {
1065 this.restartRecovery = true; // used to avoid branching back into the regular automaton
1068 protected void consumeAnnotationTypeDeclarationHeaderName() {
1069 // consumeAnnotationTypeDeclarationHeader ::= Modifiers '@' PushModifiers interface Identifier
1070 // consumeAnnotationTypeDeclarationHeader ::= '@' PushModifiers interface Identifier
1071 TypeDeclaration annotationTypeDeclaration = new TypeDeclaration(this.compilationUnit.compilationResult);
1072 if (this.nestedMethod[this.nestedType] == 0) {
1073 if (this.nestedType != 0) {
1074 annotationTypeDeclaration.bits |= ASTNode.IsMemberTypeMASK;
1077 // Record that the block has a declaration for local types
1078 annotationTypeDeclaration.bits |= ASTNode.IsLocalTypeMASK;
1079 markEnclosingMemberWithLocalType();
1083 //highlight the name of the type
1084 long pos = this.identifierPositionStack[this.identifierPtr];
1085 annotationTypeDeclaration.sourceEnd = (int) pos;
1086 annotationTypeDeclaration.sourceStart = (int) (pos >>> 32);
1087 annotationTypeDeclaration.name = this.identifierStack[this.identifierPtr--];
1088 this.identifierLengthPtr--;
1090 //compute the declaration source too
1091 // 'interface' push two int positions: the beginning of the class token and its end.
1092 // we want to keep the beginning position but get rid of the end position
1093 // it is only used for the ClassLiteralAccess positions.
1094 this.intPtr--; // remove the start position of the interface token
1095 this.intPtr--; // remove the end position of the interface token
1097 annotationTypeDeclaration.modifiersSourceStart = this.intStack[this.intPtr--];
1098 annotationTypeDeclaration.modifiers = this.intStack[this.intPtr--] | AccAnnotation | AccInterface;
1099 if (annotationTypeDeclaration.modifiersSourceStart >= 0) {
1100 annotationTypeDeclaration.declarationSourceStart = annotationTypeDeclaration.modifiersSourceStart;
1101 this.intPtr--; // remove the position of the '@' token as we have modifiers
1103 int atPosition = this.intStack[this.intPtr--];
1104 // remove the position of the '@' token as we don't have modifiers
1105 annotationTypeDeclaration.declarationSourceStart = atPosition;
1107 // consume annotations
1109 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
1111 this.expressionStack,
1112 (this.expressionPtr -= length) + 1,
1113 annotationTypeDeclaration.annotations = new Annotation[length],
1117 annotationTypeDeclaration.bodyStart = annotationTypeDeclaration.sourceEnd + 1;
1120 annotationTypeDeclaration.javadoc = this.javadoc;
1121 this.javadoc = null;
1122 pushOnAstStack(annotationTypeDeclaration);
1123 if(options.sourceLevel < ClassFileConstants.JDK1_5 &&
1124 this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
1125 this.problemReporter().invalidUsageOfAnnotationDeclarations(annotationTypeDeclaration);
1129 if (this.currentElement != null){
1130 this.lastCheckPoint = annotationTypeDeclaration.bodyStart;
1131 this.currentElement = this.currentElement.add(annotationTypeDeclaration, 0);
1132 this.lastIgnoredToken = -1;
1135 protected void consumeAnnotationTypeMemberDeclaration() {
1136 // AnnotationTypeMemberDeclaration ::= AnnotationTypeMemberDeclarationHeader AnnotationTypeMemberHeaderExtendedDims DefaultValueopt ';'
1137 AnnotationMethodDeclaration annotationTypeMemberDeclaration = (AnnotationMethodDeclaration) this.astStack[this.astPtr];
1138 annotationTypeMemberDeclaration.modifiers |= AccSemicolonBody;
1139 // store the this.endPosition (position just before the '}') in case there is
1140 // a trailing comment behind the end of the method
1141 int declarationEndPosition = flushCommentsDefinedPriorTo(this.endStatementPosition);
1142 annotationTypeMemberDeclaration.bodyStart = this.endStatementPosition;
1143 annotationTypeMemberDeclaration.bodyEnd = declarationEndPosition;
1144 annotationTypeMemberDeclaration.declarationSourceEnd = declarationEndPosition;
1146 protected void consumeAnnotationTypeMemberDeclarations() {
1147 // AnnotationTypeMemberDeclarations ::= AnnotationTypeMemberDeclarations AnnotationTypeMemberDeclaration
1150 protected void consumeArgumentList() {
1151 // ArgumentList ::= ArgumentList ',' Expression
1152 concatExpressionLists();
1154 protected void consumeArguments() {
1155 // Arguments ::= '(' ArgumentListopt ')'
1156 // nothing to do, the expression stack is already updated
1158 protected void consumeArrayAccess(boolean unspecifiedReference) {
1159 // ArrayAccess ::= Name '[' Expression ']' ==> true
1160 // ArrayAccess ::= PrimaryNoNewArray '[' Expression ']' ==> false
1165 if (unspecifiedReference) {
1167 this.expressionStack[this.expressionPtr] =
1169 getUnspecifiedReferenceOptimized(),
1170 this.expressionStack[this.expressionPtr]);
1172 this.expressionPtr--;
1173 this.expressionLengthPtr--;
1175 this.expressionStack[this.expressionPtr] =
1177 this.expressionStack[this.expressionPtr],
1178 this.expressionStack[this.expressionPtr + 1]);
1180 exp.sourceEnd = this.endPosition;
1182 protected void consumeArrayCreationExpressionWithInitializer() {
1183 // ArrayCreationWithArrayInitializer ::= 'new' PrimitiveType DimWithOrWithOutExprs ArrayInitializer
1184 // ArrayCreationWithArrayInitializer ::= 'new' ClassOrInterfaceType DimWithOrWithOutExprs ArrayInitializer
1187 ArrayAllocationExpression aae = new ArrayAllocationExpression();
1188 this.expressionLengthPtr -- ;
1189 aae.initializer = (ArrayInitializer) this.expressionStack[this.expressionPtr--];
1191 aae.type = getTypeReference(0);
1192 length = (this.expressionLengthStack[this.expressionLengthPtr--]);
1193 this.expressionPtr -= length ;
1195 this.expressionStack,
1196 this.expressionPtr+1,
1197 aae.dimensions = new Expression[length],
1200 aae.sourceStart = this.intStack[this.intPtr--];
1201 if (aae.initializer == null) {
1202 aae.sourceEnd = this.endPosition;
1204 aae.sourceEnd = aae.initializer.sourceEnd ;
1206 pushOnExpressionStack(aae);
1208 protected void consumeArrayCreationExpressionWithoutInitializer() {
1209 // ArrayCreationWithoutArrayInitializer ::= 'new' ClassOrInterfaceType DimWithOrWithOutExprs
1210 // ArrayCreationWithoutArrayInitializer ::= 'new' PrimitiveType DimWithOrWithOutExprs
1213 ArrayAllocationExpression aae = new ArrayAllocationExpression();
1214 aae.type = getTypeReference(0);
1215 length = (this.expressionLengthStack[this.expressionLengthPtr--]);
1216 this.expressionPtr -= length ;
1218 this.expressionStack,
1219 this.expressionPtr+1,
1220 aae.dimensions = new Expression[length],
1223 aae.sourceStart = this.intStack[this.intPtr--];
1224 if (aae.initializer == null) {
1225 aae.sourceEnd = this.endPosition;
1227 aae.sourceEnd = aae.initializer.sourceEnd ;
1229 pushOnExpressionStack(aae);
1231 protected void consumeArrayCreationHeader() {
1234 protected void consumeArrayInitializer() {
1235 // ArrayInitializer ::= '{' VariableInitializers '}'
1236 // ArrayInitializer ::= '{' VariableInitializers , '}'
1238 arrayInitializer(this.expressionLengthStack[this.expressionLengthPtr--]);
1240 protected void consumeArrayTypeWithTypeArgumentsName() {
1241 this.intStack[this.intPtr] += this.identifierLengthStack[this.identifierLengthPtr];
1243 protected void consumeAssertStatement() {
1244 // AssertStatement ::= 'assert' Expression ':' Expression ';'
1245 this.expressionLengthPtr-=2;
1246 pushOnAstStack(new AssertStatement(this.expressionStack[this.expressionPtr--], this.expressionStack[this.expressionPtr--], this.intStack[this.intPtr--]));
1248 protected void consumeAssignment() {
1249 // Assignment ::= LeftHandSide AssignmentOperator AssignmentExpression
1250 //optimize the push/pop
1252 int op = this.intStack[this.intPtr--] ; //<--the encoded operator
1254 this.expressionPtr -- ; this.expressionLengthPtr -- ;
1255 this.expressionStack[this.expressionPtr] =
1257 new CompoundAssignment(
1258 this.expressionStack[this.expressionPtr] ,
1259 this.expressionStack[this.expressionPtr+1],
1261 this.scanner.startPosition - 1) :
1263 this.expressionStack[this.expressionPtr] ,
1264 this.expressionStack[this.expressionPtr+1],
1265 this.scanner.startPosition - 1);
1267 protected void consumeAssignmentOperator(int pos) {
1268 // AssignmentOperator ::= '='
1269 // AssignmentOperator ::= '*='
1270 // AssignmentOperator ::= '/='
1271 // AssignmentOperator ::= '%='
1272 // AssignmentOperator ::= '+='
1273 // AssignmentOperator ::= '-='
1274 // AssignmentOperator ::= '<<='
1275 // AssignmentOperator ::= '>>='
1276 // AssignmentOperator ::= '>>>='
1277 // AssignmentOperator ::= '&='
1278 // AssignmentOperator ::= '^='
1279 // AssignmentOperator ::= '|='
1281 pushOnIntStack(pos);
1283 protected void consumeBinaryExpression(int op) {
1284 // MultiplicativeExpression ::= MultiplicativeExpression '*' UnaryExpression
1285 // MultiplicativeExpression ::= MultiplicativeExpression '/' UnaryExpression
1286 // MultiplicativeExpression ::= MultiplicativeExpression '%' UnaryExpression
1287 // AdditiveExpression ::= AdditiveExpression '+' MultiplicativeExpression
1288 // AdditiveExpression ::= AdditiveExpression '-' MultiplicativeExpression
1289 // ShiftExpression ::= ShiftExpression '<<' AdditiveExpression
1290 // ShiftExpression ::= ShiftExpression '>>' AdditiveExpression
1291 // ShiftExpression ::= ShiftExpression '>>>' AdditiveExpression
1292 // RelationalExpression ::= RelationalExpression '<' ShiftExpression
1293 // RelationalExpression ::= RelationalExpression '>' ShiftExpression
1294 // RelationalExpression ::= RelationalExpression '<=' ShiftExpression
1295 // RelationalExpression ::= RelationalExpression '>=' ShiftExpression
1296 // AndExpression ::= AndExpression '&' EqualityExpression
1297 // ExclusiveOrExpression ::= ExclusiveOrExpression '^' AndExpression
1298 // InclusiveOrExpression ::= InclusiveOrExpression '|' ExclusiveOrExpression
1299 // ConditionalAndExpression ::= ConditionalAndExpression '&&' InclusiveOrExpression
1300 // ConditionalOrExpression ::= ConditionalOrExpression '||' ConditionalAndExpression
1302 //optimize the push/pop
1304 this.expressionPtr--;
1305 this.expressionLengthPtr--;
1306 Expression expr1 = this.expressionStack[this.expressionPtr];
1307 Expression expr2 = this.expressionStack[this.expressionPtr + 1];
1310 this.expressionStack[this.expressionPtr] =
1311 new OR_OR_Expression(
1317 this.expressionStack[this.expressionPtr] =
1318 new AND_AND_Expression(
1324 // look for "string1" + "string2"
1325 if (this.optimizeStringLiterals) {
1326 if (expr1 instanceof StringLiteral) {
1327 if (expr2 instanceof CharLiteral) { // string+char
1328 this.expressionStack[this.expressionPtr] =
1329 ((StringLiteral) expr1).extendWith((CharLiteral) expr2);
1330 } else if (expr2 instanceof StringLiteral) { //string+string
1331 this.expressionStack[this.expressionPtr] =
1332 ((StringLiteral) expr1).extendWith((StringLiteral) expr2);
1334 this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, PLUS);
1337 this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, PLUS);
1339 } else if (expr1 instanceof StringLiteral) {
1340 if (expr2 instanceof StringLiteral) {
1342 this.expressionStack[this.expressionPtr] =
1343 ((StringLiteral) expr1).extendsWith((StringLiteral) expr2);
1345 this.expressionStack[this.expressionPtr] =
1346 new BinaryExpression(
1352 this.expressionStack[this.expressionPtr] =
1353 new BinaryExpression(
1361 this.expressionStack[this.expressionPtr] =
1362 new BinaryExpression(
1368 this.expressionStack[this.expressionPtr] =
1369 new BinaryExpression(
1376 * @param op binary operator
1378 protected void consumeBinaryExpressionWithName(int op) {
1379 pushOnExpressionStack(getUnspecifiedReferenceOptimized());
1380 this.expressionPtr--;
1381 this.expressionLengthPtr--;
1384 this.expressionStack[this.expressionPtr] =
1385 new OR_OR_Expression(
1386 this.expressionStack[this.expressionPtr + 1],
1387 this.expressionStack[this.expressionPtr],
1390 if (op == AND_AND) {
1391 this.expressionStack[this.expressionPtr] =
1392 new AND_AND_Expression(
1393 this.expressionStack[this.expressionPtr + 1],
1394 this.expressionStack[this.expressionPtr],
1397 // look for "string1" + "string2"
1398 if ((op == PLUS) && this.optimizeStringLiterals) {
1399 Expression expr1, expr2;
1400 expr1 = this.expressionStack[this.expressionPtr + 1];
1401 expr2 = this.expressionStack[this.expressionPtr];
1402 if (expr1 instanceof StringLiteral) {
1403 if (expr2 instanceof CharLiteral) { // string+char
1404 this.expressionStack[this.expressionPtr] =
1405 ((StringLiteral) expr1).extendWith((CharLiteral) expr2);
1406 } else if (expr2 instanceof StringLiteral) { //string+string
1407 this.expressionStack[this.expressionPtr] =
1408 ((StringLiteral) expr1).extendWith((StringLiteral) expr2);
1410 this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, PLUS);
1413 this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, PLUS);
1416 this.expressionStack[this.expressionPtr] =
1417 new BinaryExpression(
1418 this.expressionStack[this.expressionPtr + 1],
1419 this.expressionStack[this.expressionPtr],
1425 Expression expr1 = this.expressionStack[this.expressionPtr + 1];
1426 Expression expr2 = this.expressionStack[this.expressionPtr];
1429 this.expressionStack[this.expressionPtr] =
1430 new OR_OR_Expression(
1436 this.expressionStack[this.expressionPtr] =
1437 new AND_AND_Expression(
1443 // look for "string1" + "string2"
1444 if (this.optimizeStringLiterals) {
1445 if (expr1 instanceof StringLiteral) {
1446 if (expr2 instanceof CharLiteral) { // string+char
1447 this.expressionStack[this.expressionPtr] =
1448 ((StringLiteral) expr1).extendWith((CharLiteral) expr2);
1449 } else if (expr2 instanceof StringLiteral) { //string+string
1450 this.expressionStack[this.expressionPtr] =
1451 ((StringLiteral) expr1).extendWith((StringLiteral) expr2);
1453 this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, PLUS);
1456 this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, PLUS);
1458 } else if (expr1 instanceof StringLiteral) {
1459 if (expr2 instanceof StringLiteral) {
1461 this.expressionStack[this.expressionPtr] =
1462 ((StringLiteral) expr1).extendsWith((StringLiteral) expr2);
1464 this.expressionStack[this.expressionPtr] =
1465 new BinaryExpression(
1471 this.expressionStack[this.expressionPtr] =
1472 new BinaryExpression(
1480 this.expressionStack[this.expressionPtr] =
1481 new BinaryExpression(
1487 this.expressionStack[this.expressionPtr] =
1488 new BinaryExpression(
1494 protected void consumeBlock() {
1495 // Block ::= OpenBlock '{' BlockStatementsopt '}'
1496 // simpler action for empty blocks
1498 int statementsLength = this.astLengthStack[this.astLengthPtr--];
1500 if (statementsLength == 0) { // empty block
1501 block = new Block(0);
1502 block.sourceStart = this.intStack[this.intPtr--];
1503 block.sourceEnd = this.endStatementPosition;
1504 // check whether this block at least contains some comment in it
1505 if (!containsComment(block.sourceStart, block.sourceEnd)) {
1506 block.bits |= ASTNode.UndocumentedEmptyBlockMASK;
1508 this.realBlockPtr--; // still need to pop the block variable counter
1510 block = new Block(this.realBlockStack[this.realBlockPtr--]);
1511 this.astPtr -= statementsLength;
1515 block.statements = new Statement[statementsLength],
1518 block.sourceStart = this.intStack[this.intPtr--];
1519 block.sourceEnd = this.endStatementPosition;
1521 pushOnAstStack(block);
1523 protected void consumeBlockStatements() {
1524 // BlockStatements ::= BlockStatements BlockStatement
1527 protected void consumeCaseLabel() {
1528 // SwitchLabel ::= 'case' ConstantExpression ':'
1529 this.expressionLengthPtr--;
1530 Expression expression = this.expressionStack[this.expressionPtr--];
1531 pushOnAstStack(new CaseStatement(expression, expression.sourceEnd, this.intStack[this.intPtr--]));
1533 protected void consumeCastExpressionLL1() {
1534 //CastExpression ::= '(' Expression ')' InsideCastExpressionLL1 UnaryExpressionNotPlusMinus
1535 // Expression is used in order to make the grammar LL1
1539 Expression cast,exp;
1540 this.expressionPtr--;
1541 this.expressionStack[this.expressionPtr] =
1542 cast = new CastExpression(
1543 exp=this.expressionStack[this.expressionPtr+1] ,
1544 getTypeReference(this.expressionStack[this.expressionPtr]));
1545 this.expressionLengthPtr -- ;
1546 updateSourcePosition(cast);
1547 cast.sourceEnd=exp.sourceEnd;
1549 protected void consumeCastExpressionWithGenericsArray() {
1550 // CastExpression ::= PushLPAREN Name TypeArguments Dims PushRPAREN InsideCastExpression UnaryExpressionNotPlusMinus
1552 Expression exp, cast, castType;
1553 int end = this.intStack[this.intPtr--];
1555 int dim = this.intStack[this.intPtr--];
1556 pushOnGenericsIdentifiersLengthStack(this.identifierLengthStack[this.identifierLengthPtr]);
1558 this.expressionStack[this.expressionPtr] = cast = new CastExpression(exp = this.expressionStack[this.expressionPtr], castType = getTypeReference(dim));
1560 castType.sourceEnd = end - 1;
1561 castType.sourceStart = (cast.sourceStart = this.intStack[this.intPtr--]) + 1;
1562 cast.sourceEnd = exp.sourceEnd;
1564 protected void consumeCastExpressionWithNameArray() {
1565 // CastExpression ::= PushLPAREN Name Dims PushRPAREN InsideCastExpression UnaryExpressionNotPlusMinus
1567 Expression exp, cast, castType;
1568 int end = this.intStack[this.intPtr--];
1570 // handle type arguments
1571 pushOnGenericsLengthStack(0);
1572 pushOnGenericsIdentifiersLengthStack(this.identifierLengthStack[this.identifierLengthPtr]);
1574 this.expressionStack[this.expressionPtr] = cast = new CastExpression(exp = this.expressionStack[this.expressionPtr], castType = getTypeReference(this.intStack[this.intPtr--]));
1575 castType.sourceEnd = end - 1;
1576 castType.sourceStart = (cast.sourceStart = this.intStack[this.intPtr--]) + 1;
1577 cast.sourceEnd = exp.sourceEnd;
1579 protected void consumeCastExpressionWithPrimitiveType() {
1580 // CastExpression ::= PushLPAREN PrimitiveType Dimsopt PushRPAREN InsideCastExpression UnaryExpression
1582 //this.intStack : posOfLeftParen dim posOfRightParen
1584 //optimize the push/pop
1586 Expression exp, cast, castType;
1587 int end = this.intStack[this.intPtr--];
1588 this.expressionStack[this.expressionPtr] = cast = new CastExpression(exp = this.expressionStack[this.expressionPtr], castType = getTypeReference(this.intStack[this.intPtr--]));
1589 castType.sourceEnd = end - 1;
1590 castType.sourceStart = (cast.sourceStart = this.intStack[this.intPtr--]) + 1;
1591 cast.sourceEnd = exp.sourceEnd;
1593 protected ParameterizedQualifiedTypeReference computeQualifiedGenericsFromRightSide(TypeReference rightSide, int dim) {
1594 int nameSize = this.identifierLengthStack[this.identifierLengthPtr];
1595 int tokensSize = nameSize;
1596 if (rightSide instanceof ParameterizedSingleTypeReference) {
1598 } else if (rightSide instanceof SingleTypeReference) {
1600 } else if (rightSide instanceof ParameterizedQualifiedTypeReference) {
1601 tokensSize += ((QualifiedTypeReference) rightSide).tokens.length;
1602 } else if (rightSide instanceof QualifiedTypeReference) {
1603 tokensSize += ((QualifiedTypeReference) rightSide).tokens.length;
1605 TypeReference[][] typeArguments = new TypeReference[tokensSize][];
1606 char[][] tokens = new char[tokensSize][];
1607 long[] positions = new long[tokensSize];
1608 if (rightSide instanceof ParameterizedSingleTypeReference) {
1609 ParameterizedSingleTypeReference singleParameterizedTypeReference = (ParameterizedSingleTypeReference) rightSide;
1610 tokens[nameSize] = singleParameterizedTypeReference.token;
1611 positions[nameSize] = (((long) singleParameterizedTypeReference.sourceStart) << 32) + singleParameterizedTypeReference.sourceEnd;
1612 typeArguments[nameSize] = singleParameterizedTypeReference.typeArguments;
1613 } else if (rightSide instanceof SingleTypeReference) {
1614 SingleTypeReference singleTypeReference = (SingleTypeReference) rightSide;
1615 tokens[nameSize] = singleTypeReference.token;
1616 positions[nameSize] = (((long) singleTypeReference.sourceStart) << 32) + singleTypeReference.sourceEnd;
1617 } else if (rightSide instanceof ParameterizedQualifiedTypeReference) {
1618 ParameterizedQualifiedTypeReference parameterizedTypeReference = (ParameterizedQualifiedTypeReference) rightSide;
1619 TypeReference[][] rightSideTypeArguments = parameterizedTypeReference.typeArguments;
1620 System.arraycopy(rightSideTypeArguments, 0, typeArguments, nameSize, rightSideTypeArguments.length);
1621 char[][] rightSideTokens = parameterizedTypeReference.tokens;
1622 System.arraycopy(rightSideTokens, 0, tokens, nameSize, rightSideTokens.length);
1623 long[] rightSidePositions = parameterizedTypeReference.sourcePositions;
1624 System.arraycopy(rightSidePositions, 0, positions, nameSize, rightSidePositions.length);
1625 } else if (rightSide instanceof QualifiedTypeReference) {
1626 QualifiedTypeReference qualifiedTypeReference = (QualifiedTypeReference) rightSide;
1627 char[][] rightSideTokens = qualifiedTypeReference.tokens;
1628 System.arraycopy(rightSideTokens, 0, tokens, nameSize, rightSideTokens.length);
1629 long[] rightSidePositions = qualifiedTypeReference.sourcePositions;
1630 System.arraycopy(rightSidePositions, 0, positions, nameSize, rightSidePositions.length);
1633 int currentTypeArgumentsLength = this.genericsLengthStack[this.genericsLengthPtr--];
1634 TypeReference[] currentTypeArguments = new TypeReference[currentTypeArgumentsLength];
1635 this.genericsPtr -= currentTypeArgumentsLength;
1636 System.arraycopy(this.genericsStack, this.genericsPtr + 1, currentTypeArguments, 0, currentTypeArgumentsLength);
1638 if (nameSize == 1) {
1639 tokens[0] = this.identifierStack[this.identifierPtr];
1640 positions[0] = this.identifierPositionStack[this.identifierPtr--];
1641 typeArguments[0] = currentTypeArguments;
1643 this.identifierPtr -= nameSize;
1644 System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, nameSize);
1645 System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, nameSize);
1646 typeArguments[nameSize - 1] = currentTypeArguments;
1648 this.identifierLengthPtr--;
1649 return new ParameterizedQualifiedTypeReference(tokens, typeArguments, dim, positions);
1651 protected void consumeCastExpressionWithQualifiedGenericsArray() {
1652 // CastExpression ::= PushLPAREN Name OnlyTypeArguments '.' ClassOrInterfaceType Dims PushRPAREN InsideCastExpression UnaryExpressionNotPlusMinus
1653 Expression exp, cast, castType;
1654 int end = this.intStack[this.intPtr--];
1656 int dim = this.intStack[this.intPtr--];
1657 TypeReference rightSide = getTypeReference(0);
1659 ParameterizedQualifiedTypeReference qualifiedParameterizedTypeReference = computeQualifiedGenericsFromRightSide(rightSide, dim);
1661 this.expressionStack[this.expressionPtr] = cast = new CastExpression(exp = this.expressionStack[this.expressionPtr], castType = qualifiedParameterizedTypeReference);
1662 castType.sourceEnd = end - 1;
1663 castType.sourceStart = (cast.sourceStart = this.intStack[this.intPtr--]) + 1;
1664 cast.sourceEnd = exp.sourceEnd;
1666 protected void consumeCatches() {
1667 // Catches ::= Catches CatchClause
1668 optimizedConcatNodeLists();
1670 protected void consumeCatchHeader() {
1671 // CatchDeclaration ::= 'catch' '(' FormalParameter ')' '{'
1673 if (this.currentElement == null){
1674 return; // should never occur, this consumeRule is only used in recovery mode
1676 // current element should be a block due to the presence of the opening brace
1677 if (!(this.currentElement instanceof RecoveredBlock)){
1678 if(!(this.currentElement instanceof RecoveredMethod)) {
1681 RecoveredMethod rMethod = (RecoveredMethod) this.currentElement;
1682 if(!(rMethod.methodBody == null && rMethod.bracketBalance > 0)) {
1687 Argument arg = (Argument)this.astStack[this.astPtr--];
1688 // convert argument to local variable
1689 LocalDeclaration localDeclaration = new LocalDeclaration(arg.name, arg.sourceStart, arg.sourceEnd);
1690 localDeclaration.type = arg.type;
1691 localDeclaration.declarationSourceStart = arg.declarationSourceStart;
1692 localDeclaration.declarationSourceEnd = arg.declarationSourceEnd;
1694 this.currentElement = this.currentElement.add(localDeclaration, 0);
1695 this.lastCheckPoint = this.scanner.startPosition; // force to restart at this exact position
1696 this.restartRecovery = true; // request to restart from here on
1697 this.lastIgnoredToken = -1;
1699 protected void consumeClassBodyDeclaration() {
1700 // ClassBodyDeclaration ::= Diet Block
1701 //push an Initializer
1702 //optimize the push/pop
1703 this.nestedMethod[this.nestedType]--;
1704 Block block = (Block) this.astStack[this.astPtr];
1705 if (this.diet) block.bits &= ~ASTNode.UndocumentedEmptyBlockMASK; // clear bit since was diet
1706 Initializer initializer = new Initializer(block, 0);
1707 this.intPtr--; // pop sourcestart left on the stack by consumeNestedMethod.
1708 initializer.bodyStart = this.intStack[this.intPtr--];
1709 this.realBlockPtr--; // pop the block variable counter left on the stack by consumeNestedMethod
1710 int javadocCommentStart = this.intStack[this.intPtr--];
1711 if (javadocCommentStart != -1) {
1712 initializer.declarationSourceStart = javadocCommentStart;
1713 initializer.javadoc = this.javadoc;
1714 this.javadoc = null;
1716 this.astStack[this.astPtr] = initializer;
1717 initializer.bodyEnd = this.endPosition;
1718 initializer.sourceEnd = this.endStatementPosition;
1719 initializer.declarationSourceEnd = flushCommentsDefinedPriorTo(this.endStatementPosition);
1721 protected void consumeClassBodyDeclarations() {
1722 // ClassBodyDeclarations ::= ClassBodyDeclarations ClassBodyDeclaration
1725 protected void consumeClassBodyDeclarationsopt() {
1726 // ClassBodyDeclarationsopt ::= NestedType ClassBodyDeclarations
1729 protected void consumeClassBodyopt() {
1730 // ClassBodyopt ::= $empty
1731 pushOnAstStack(null);
1732 this.endPosition = this.rParenPos;
1734 protected void consumeClassDeclaration() {
1735 // ClassDeclaration ::= ClassHeader ClassBody
1738 if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) {
1739 //there are length declarations
1740 //dispatch according to the type of the declarations
1741 dispatchDeclarationInto(length);
1744 TypeDeclaration typeDecl = (TypeDeclaration) this.astStack[this.astPtr];
1746 // mark initializers with local type mark if needed
1747 markInitializersWithLocalType(typeDecl);
1749 //convert constructor that do not have the type's name into methods
1750 boolean hasConstructor = typeDecl.checkConstructors(this);
1752 //add the default constructor when needed (interface don't have it)
1753 if (!hasConstructor) {
1754 switch(typeDecl.kind()) {
1755 case IGenericType.CLASS_DECL :
1756 case IGenericType.ENUM_DECL :
1757 boolean insideFieldInitializer = false;
1759 for (int i = this.nestedType; i > 0; i--){
1760 if (this.variablesCounter[i] > 0) {
1761 insideFieldInitializer = true;
1766 typeDecl.createDefaultConstructor(!this.diet || insideFieldInitializer, true);
1769 //always add <clinit> (will be remove at code gen time if empty)
1770 if (this.scanner.containsAssertKeyword) {
1771 typeDecl.bits |= ASTNode.AddAssertionMASK;
1773 typeDecl.addClinit();
1774 typeDecl.bodyEnd = this.endStatementPosition;
1775 if (length == 0 && !containsComment(typeDecl.bodyStart, typeDecl.bodyEnd)) {
1776 typeDecl.bits |= ASTNode.UndocumentedEmptyBlockMASK;
1779 typeDecl.declarationSourceEnd = flushCommentsDefinedPriorTo(this.endStatementPosition);
1781 protected void consumeClassHeader() {
1782 // ClassHeader ::= ClassHeaderName ClassHeaderExtendsopt ClassHeaderImplementsopt
1784 TypeDeclaration typeDecl = (TypeDeclaration) this.astStack[this.astPtr];
1785 if (this.currentToken == TokenNameLBRACE) {
1786 typeDecl.bodyStart = this.scanner.currentPosition;
1788 if (this.currentElement != null) {
1789 this.restartRecovery = true; // used to avoid branching back into the regular automaton
1791 // flush the comments related to the class header
1792 this.scanner.commentPtr = -1;
1794 protected void consumeClassHeaderExtends() {
1795 // ClassHeaderExtends ::= 'extends' ClassType
1797 TypeReference superClass = getTypeReference(0);
1798 // There is a class declaration on the top of stack
1799 TypeDeclaration typeDecl = (TypeDeclaration) this.astStack[this.astPtr];
1800 typeDecl.superclass = superClass;
1801 superClass.bits |= ASTNode.IsSuperType;
1802 typeDecl.bodyStart = typeDecl.superclass.sourceEnd + 1;
1804 if (this.currentElement != null){
1805 this.lastCheckPoint = typeDecl.bodyStart;
1808 protected void consumeClassHeaderImplements() {
1809 // ClassHeaderImplements ::= 'implements' InterfaceTypeList
1810 int length = this.astLengthStack[this.astLengthPtr--];
1812 this.astPtr -= length;
1813 // There is a class declaration on the top of stack
1814 TypeDeclaration typeDecl = (TypeDeclaration) this.astStack[this.astPtr];
1818 typeDecl.superInterfaces = new TypeReference[length],
1821 for (int i = 0, max = typeDecl.superInterfaces.length; i < max; i++) {
1822 typeDecl.superInterfaces[i].bits |= ASTNode.IsSuperType;
1824 typeDecl.bodyStart = typeDecl.superInterfaces[length-1].sourceEnd + 1;
1825 this.listLength = 0; // reset after having read super-interfaces
1827 if (this.currentElement != null) { // is recovering
1828 this.lastCheckPoint = typeDecl.bodyStart;
1831 protected void consumeClassHeaderName1() {
1832 // ClassHeaderName1 ::= Modifiersopt 'class' 'Identifier'
1833 TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
1834 if (this.nestedMethod[this.nestedType] == 0) {
1835 if (this.nestedType != 0) {
1836 typeDecl.bits |= ASTNode.IsMemberTypeMASK;
1839 // Record that the block has a declaration for local types
1840 typeDecl.bits |= ASTNode.IsLocalTypeMASK;
1841 markEnclosingMemberWithLocalType();
1845 //highlight the name of the type
1846 long pos = this.identifierPositionStack[this.identifierPtr];
1847 typeDecl.sourceEnd = (int) pos;
1848 typeDecl.sourceStart = (int) (pos >>> 32);
1849 typeDecl.name = this.identifierStack[this.identifierPtr--];
1850 this.identifierLengthPtr--;
1852 //compute the declaration source too
1853 // 'class' and 'interface' push two int positions: the beginning of the class token and its end.
1854 // we want to keep the beginning position but get rid of the end position
1855 // it is only used for the ClassLiteralAccess positions.
1856 typeDecl.declarationSourceStart = this.intStack[this.intPtr--];
1857 this.intPtr--; // remove the end position of the class token
1859 typeDecl.modifiersSourceStart = this.intStack[this.intPtr--];
1860 typeDecl.modifiers = this.intStack[this.intPtr--];
1861 if (typeDecl.modifiersSourceStart >= 0) {
1862 typeDecl.declarationSourceStart = typeDecl.modifiersSourceStart;
1864 // consume annotations
1866 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
1868 this.expressionStack,
1869 (this.expressionPtr -= length) + 1,
1870 typeDecl.annotations = new Annotation[length],
1874 typeDecl.bodyStart = typeDecl.sourceEnd + 1;
1875 pushOnAstStack(typeDecl);
1877 this.listLength = 0; // will be updated when reading super-interfaces
1879 if (this.currentElement != null){
1880 this.lastCheckPoint = typeDecl.bodyStart;
1881 this.currentElement = this.currentElement.add(typeDecl, 0);
1882 this.lastIgnoredToken = -1;
1885 typeDecl.javadoc = this.javadoc;
1886 this.javadoc = null;
1888 protected void consumeTypeHeaderNameWithTypeParameters() {
1889 // ClassHeaderName ::= ClassHeaderName1 TypeParameters
1890 // InterfaceHeaderName ::= InterfaceHeaderName1 TypeParameters
1891 TypeDeclaration typeDecl = (TypeDeclaration)this.astStack[this.astPtr];
1893 // consume type parameters
1894 int length = this.genericsLengthStack[this.genericsLengthPtr--];
1895 this.genericsPtr -= length;
1896 System.arraycopy(this.genericsStack, this.genericsPtr + 1, typeDecl.typeParameters = new TypeParameter[length], 0, length);
1898 typeDecl.bodyStart = typeDecl.typeParameters[length-1].declarationSourceEnd + 1;
1900 this.listTypeParameterLength = 0;
1902 if (this.currentElement != null) { // is recovering
1903 this.lastCheckPoint = typeDecl.bodyStart;
1906 protected void consumeClassInstanceCreationExpression() {
1907 // ClassInstanceCreationExpression ::= 'new' ClassType '(' ArgumentListopt ')' ClassBodyopt
1908 classInstanceCreation(false);
1910 protected void consumeClassInstanceCreationExpressionName() {
1911 // ClassInstanceCreationExpressionName ::= Name '.'
1912 pushOnExpressionStack(getUnspecifiedReferenceOptimized());
1914 protected void consumeClassInstanceCreationExpressionQualified() {
1915 // ClassInstanceCreationExpression ::= Primary '.' 'new' SimpleName '(' ArgumentListopt ')' ClassBodyopt
1916 // ClassInstanceCreationExpression ::= ClassInstanceCreationExpressionName 'new' SimpleName '(' ArgumentListopt ')' ClassBodyopt
1917 classInstanceCreation(true);
1919 this.expressionLengthPtr--;
1920 QualifiedAllocationExpression qae =
1921 (QualifiedAllocationExpression) this.expressionStack[this.expressionPtr--];
1922 qae.enclosingInstance = this.expressionStack[this.expressionPtr];
1923 this.expressionStack[this.expressionPtr] = qae;
1924 qae.sourceStart = qae.enclosingInstance.sourceStart;
1926 protected void consumeClassInstanceCreationExpressionQualifiedWithTypeArguments() {
1927 // ClassInstanceCreationExpression ::= Primary '.' 'new' TypeArguments SimpleName '(' ArgumentListopt ')' ClassBodyopt
1928 // ClassInstanceCreationExpression ::= ClassInstanceCreationExpressionName 'new' TypeArguments SimpleName '(' ArgumentListopt ')' ClassBodyopt
1930 QualifiedAllocationExpression alloc;
1932 if (((length = this.astLengthStack[this.astLengthPtr--]) == 1) && (this.astStack[this.astPtr] == null)) {
1935 alloc = new QualifiedAllocationExpression();
1936 alloc.sourceEnd = this.endPosition; //the position has been stored explicitly
1938 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
1939 this.expressionPtr -= length;
1941 this.expressionStack,
1942 this.expressionPtr + 1,
1943 alloc.arguments = new Expression[length],
1947 alloc.type = getTypeReference(0);
1949 length = this.genericsLengthStack[this.genericsLengthPtr--];
1950 this.genericsPtr -= length;
1951 System.arraycopy(this.genericsStack, this.genericsPtr + 1, alloc.typeArguments = new TypeReference[length], 0, length);
1954 //the default constructor with the correct number of argument
1955 //will be created and added by the TC (see createsInternalConstructorWithBinding)
1956 alloc.sourceStart = this.intStack[this.intPtr--];
1957 pushOnExpressionStack(alloc);
1959 dispatchDeclarationInto(length);
1960 TypeDeclaration anonymousTypeDeclaration = (TypeDeclaration)this.astStack[this.astPtr];
1961 anonymousTypeDeclaration.declarationSourceEnd = this.endStatementPosition;
1962 anonymousTypeDeclaration.bodyEnd = this.endStatementPosition;
1963 if (length == 0 && !containsComment(anonymousTypeDeclaration.bodyStart, anonymousTypeDeclaration.bodyEnd)) {
1964 anonymousTypeDeclaration.bits |= ASTNode.UndocumentedEmptyBlockMASK;
1967 this.astLengthPtr--;
1969 QualifiedAllocationExpression allocationExpression = anonymousTypeDeclaration.allocation;
1970 if (allocationExpression != null) {
1971 allocationExpression.sourceEnd = this.endStatementPosition;
1972 // handle type arguments
1973 length = this.genericsLengthStack[this.genericsLengthPtr--];
1974 this.genericsPtr -= length;
1975 System.arraycopy(this.genericsStack, this.genericsPtr + 1, allocationExpression.typeArguments = new TypeReference[length], 0, length);
1976 allocationExpression.sourceStart = intStack[intPtr--];
1979 // mark initializers with local type mark if needed
1980 markInitializersWithLocalType(anonymousTypeDeclaration);
1983 this.expressionLengthPtr--;
1984 QualifiedAllocationExpression qae =
1985 (QualifiedAllocationExpression) this.expressionStack[this.expressionPtr--];
1986 qae.enclosingInstance = this.expressionStack[this.expressionPtr];
1987 this.expressionStack[this.expressionPtr] = qae;
1988 qae.sourceStart = qae.enclosingInstance.sourceStart;
1990 protected void consumeClassInstanceCreationExpressionWithTypeArguments() {
1991 // ClassInstanceCreationExpression ::= 'new' TypeArguments ClassType '(' ArgumentListopt ')' ClassBodyopt
1992 AllocationExpression alloc;
1994 if (((length = this.astLengthStack[this.astLengthPtr--]) == 1)
1995 && (this.astStack[this.astPtr] == null)) {
1998 alloc = new AllocationExpression();
1999 alloc.sourceEnd = this.endPosition; //the position has been stored explicitly
2001 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
2002 this.expressionPtr -= length;
2004 this.expressionStack,
2005 this.expressionPtr + 1,
2006 alloc.arguments = new Expression[length],
2010 alloc.type = getTypeReference(0);
2012 length = this.genericsLengthStack[this.genericsLengthPtr--];
2013 this.genericsPtr -= length;
2014 System.arraycopy(this.genericsStack, this.genericsPtr + 1, alloc.typeArguments = new TypeReference[length], 0, length);
2017 //the default constructor with the correct number of argument
2018 //will be created and added by the TC (see createsInternalConstructorWithBinding)
2019 alloc.sourceStart = this.intStack[this.intPtr--];
2020 pushOnExpressionStack(alloc);
2022 dispatchDeclarationInto(length);
2023 TypeDeclaration anonymousTypeDeclaration = (TypeDeclaration)this.astStack[this.astPtr];
2024 anonymousTypeDeclaration.declarationSourceEnd = this.endStatementPosition;
2025 anonymousTypeDeclaration.bodyEnd = this.endStatementPosition;
2026 if (length == 0 && !containsComment(anonymousTypeDeclaration.bodyStart, anonymousTypeDeclaration.bodyEnd)) {
2027 anonymousTypeDeclaration.bits |= ASTNode.UndocumentedEmptyBlockMASK;
2030 this.astLengthPtr--;
2032 QualifiedAllocationExpression allocationExpression = anonymousTypeDeclaration.allocation;
2033 if (allocationExpression != null) {
2034 allocationExpression.sourceEnd = this.endStatementPosition;
2035 // handle type arguments
2036 length = this.genericsLengthStack[this.genericsLengthPtr--];
2037 this.genericsPtr -= length;
2038 System.arraycopy(this.genericsStack, this.genericsPtr + 1, allocationExpression.typeArguments = new TypeReference[length], 0, length);
2039 allocationExpression.sourceStart = intStack[intPtr--];
2042 // mark initializers with local type mark if needed
2043 markInitializersWithLocalType(anonymousTypeDeclaration);
2046 protected void consumeClassOrInterface() {
2047 this.genericsIdentifiersLengthStack[this.genericsIdentifiersLengthPtr] += this.identifierLengthStack[this.identifierLengthPtr];
2048 pushOnGenericsLengthStack(0); // handle type arguments
2050 protected void consumeClassOrInterfaceName() {
2051 pushOnGenericsIdentifiersLengthStack(this.identifierLengthStack[this.identifierLengthPtr]);
2052 pushOnGenericsLengthStack(0); // handle type arguments
2054 protected void consumeClassTypeElt() {
2055 // ClassTypeElt ::= ClassType
2056 pushOnAstStack(getTypeReference(0));
2057 /* if incomplete thrown exception list, this.listLength counter will not have been reset,
2058 indicating that some items are available on the stack */
2061 protected void consumeClassTypeList() {
2062 // ClassTypeList ::= ClassTypeList ',' ClassTypeElt
2063 optimizedConcatNodeLists();
2065 protected void consumeCompilationUnit() {
2066 // CompilationUnit ::= EnterCompilationUnit InternalCompilationUnit
2067 // do nothing by default
2069 protected void consumeConditionalExpression(int op) {
2070 // ConditionalExpression ::= ConditionalOrExpression '?' Expression ':' ConditionalExpression
2071 //optimize the push/pop
2072 this.intPtr -= 2;//consume position of the question mark
2073 this.expressionPtr -= 2;
2074 this.expressionLengthPtr -= 2;
2075 this.expressionStack[this.expressionPtr] =
2076 new ConditionalExpression(
2077 this.expressionStack[this.expressionPtr],
2078 this.expressionStack[this.expressionPtr + 1],
2079 this.expressionStack[this.expressionPtr + 2]);
2084 protected void consumeConditionalExpressionWithName(int op) {
2085 // ConditionalExpression ::= Name '?' Expression ':' ConditionalExpression
2086 this.intPtr -= 2;//consume position of the question mark
2087 pushOnExpressionStack(getUnspecifiedReferenceOptimized());
2088 this.expressionPtr -= 2;
2089 this.expressionLengthPtr -= 2;
2090 this.expressionStack[this.expressionPtr] =
2091 new ConditionalExpression(
2092 this.expressionStack[this.expressionPtr + 2],
2093 this.expressionStack[this.expressionPtr],
2094 this.expressionStack[this.expressionPtr + 1]);
2096 protected void consumeConstructorBlockStatements() {
2097 // ConstructorBody ::= NestedMethod '{' ExplicitConstructorInvocation BlockStatements '}'
2098 concatNodeLists(); // explictly add the first statement into the list of statements
2100 protected void consumeConstructorBody() {
2101 // ConstructorBody ::= NestedMethod '{' BlockStatementsopt '}'
2102 // ConstructorBody ::= NestedMethod '{' ExplicitConstructorInvocation '}'
2103 this.nestedMethod[this.nestedType] --;
2105 protected void consumeConstructorDeclaration() {
2106 // ConstructorDeclaration ::= ConstructorHeader ConstructorBody
2109 this.astStack : MethodDeclaration statements
2110 this.identifierStack : name
2112 this.astStack : MethodDeclaration
2113 this.identifierStack :
2116 //must provide a default constructor call when needed
2120 // pop the position of the { (body of the method) pushed in block decl
2125 this.realBlockPtr--;
2126 ExplicitConstructorCall constructorCall = null;
2127 Statement[] statements = null;
2128 if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) {
2129 this.astPtr -= length;
2130 if (this.astStack[this.astPtr + 1] instanceof ExplicitConstructorCall) {
2131 //avoid a isSomeThing that would only be used here BUT what is faster between two alternatives ?
2135 statements = new Statement[length - 1],
2138 constructorCall = (ExplicitConstructorCall) this.astStack[this.astPtr + 1];
2139 } else { //need to add explicitly the super();
2143 statements = new Statement[length],
2146 constructorCall = SuperReference.implicitSuperConstructorCall();
2149 boolean insideFieldInitializer = false;
2151 for (int i = this.nestedType; i > 0; i--){
2152 if (this.variablesCounter[i] > 0) {
2153 insideFieldInitializer = true;
2159 if (!this.diet || insideFieldInitializer){
2160 // add it only in non-diet mode, if diet_bodies, then constructor call will be added elsewhere.
2161 constructorCall = SuperReference.implicitSuperConstructorCall();
2165 // now we know that the top of stack is a constructorDeclaration
2166 ConstructorDeclaration cd = (ConstructorDeclaration) this.astStack[this.astPtr];
2167 cd.constructorCall = constructorCall;
2168 cd.statements = statements;
2170 //highlight of the implicit call on the method name
2171 if (constructorCall != null && cd.constructorCall.sourceEnd == 0) {
2172 cd.constructorCall.sourceEnd = cd.sourceEnd;
2173 cd.constructorCall.sourceStart = cd.sourceStart;
2176 if (!this.diet && (statements == null && constructorCall.isImplicitSuper())) {
2177 if (!containsComment(cd.bodyStart, this.endPosition)) {
2178 cd.bits |= ASTNode.UndocumentedEmptyBlockMASK;
2182 //watch for } that could be given as a unicode ! ( u007D is '}' )
2183 // store the this.endPosition (position just before the '}') in case there is
2184 // a trailing comment behind the end of the method
2185 cd.bodyEnd = this.endPosition;
2186 cd.declarationSourceEnd = flushCommentsDefinedPriorTo(this.endStatementPosition);
2188 protected void consumeConstructorHeader() {
2189 // ConstructorHeader ::= ConstructorHeaderName MethodHeaderParameters MethodHeaderThrowsClauseopt
2191 AbstractMethodDeclaration method = (AbstractMethodDeclaration)this.astStack[this.astPtr];
2193 if (this.currentToken == TokenNameLBRACE){
2194 method.bodyStart = this.scanner.currentPosition;
2197 if (this.currentElement != null){
2198 if (this.currentToken == TokenNameSEMICOLON){ // for invalid constructors
2199 method.modifiers |= AccSemicolonBody;
2200 method.declarationSourceEnd = this.scanner.currentPosition-1;
2201 method.bodyEnd = this.scanner.currentPosition-1;
2202 if (this.currentElement.parseTree() == method && this.currentElement.parent != null) {
2203 this.currentElement = this.currentElement.parent;
2206 this.restartRecovery = true; // used to avoid branching back into the regular automaton
2209 protected void consumeConstructorHeaderName() {
2211 /* recovering - might be an empty message send */
2212 if (this.currentElement != null){
2213 if (this.lastIgnoredToken == TokenNamenew){ // was an allocation expression
2214 this.lastCheckPoint = this.scanner.startPosition; // force to restart at this exact position
2215 this.restartRecovery = true;
2220 // ConstructorHeaderName ::= Modifiersopt 'Identifier' '('
2221 ConstructorDeclaration cd = new ConstructorDeclaration(this.compilationUnit.compilationResult);
2223 //name -- this is not really revelant but we do .....
2224 cd.selector = this.identifierStack[this.identifierPtr];
2225 long selectorSource = this.identifierPositionStack[this.identifierPtr--];
2226 this.identifierLengthPtr--;
2229 cd.declarationSourceStart = this.intStack[this.intPtr--];
2230 cd.modifiers = this.intStack[this.intPtr--];
2231 // consume annotations
2233 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
2235 this.expressionStack,
2236 (this.expressionPtr -= length) + 1,
2237 cd.annotations = new Annotation[length],
2242 cd.javadoc = this.javadoc;
2243 this.javadoc = null;
2245 //highlight starts at the selector starts
2246 cd.sourceStart = (int) (selectorSource >>> 32);
2248 cd.sourceEnd = this.lParenPos;
2249 cd.bodyStart = this.lParenPos+1;
2250 this.listLength = 0; // initialize this.listLength before reading parameters/throws
2253 if (this.currentElement != null){
2254 this.lastCheckPoint = cd.bodyStart;
2255 if ((this.currentElement instanceof RecoveredType && this.lastIgnoredToken != TokenNameDOT)
2256 || cd.modifiers != 0){
2257 this.currentElement = this.currentElement.add(cd, 0);
2258 this.lastIgnoredToken = -1;
2262 protected void consumeConstructorHeaderNameWithTypeParameters() {
2264 /* recovering - might be an empty message send */
2265 if (this.currentElement != null){
2266 if (this.lastIgnoredToken == TokenNamenew){ // was an allocation expression
2267 this.lastCheckPoint = this.scanner.startPosition; // force to restart at this exact position
2268 this.restartRecovery = true;
2273 // ConstructorHeaderName ::= Modifiersopt TypeParameters 'Identifier' '('
2274 ConstructorDeclaration cd = new ConstructorDeclaration(this.compilationUnit.compilationResult);
2276 //name -- this is not really revelant but we do .....
2277 cd.selector = this.identifierStack[this.identifierPtr];
2278 long selectorSource = this.identifierPositionStack[this.identifierPtr--];
2279 this.identifierLengthPtr--;
2281 // consume type parameters
2282 int length = this.genericsLengthStack[this.genericsLengthPtr--];
2283 this.genericsPtr -= length;
2284 System.arraycopy(this.genericsStack, this.genericsPtr + 1, cd.typeParameters = new TypeParameter[length], 0, length);
2287 cd.declarationSourceStart = this.intStack[this.intPtr--];
2288 cd.modifiers = this.intStack[this.intPtr--];
2289 // consume annotations
2290 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
2292 this.expressionStack,
2293 (this.expressionPtr -= length) + 1,
2294 cd.annotations = new Annotation[length],
2299 cd.javadoc = this.javadoc;
2300 this.javadoc = null;
2302 //highlight starts at the selector starts
2303 cd.sourceStart = (int) (selectorSource >>> 32);
2305 cd.sourceEnd = this.lParenPos;
2306 cd.bodyStart = this.lParenPos+1;
2307 this.listLength = 0; // initialize this.listLength before reading parameters/throws
2310 if (this.currentElement != null){
2311 this.lastCheckPoint = cd.bodyStart;
2312 if ((this.currentElement instanceof RecoveredType && this.lastIgnoredToken != TokenNameDOT)
2313 || cd.modifiers != 0){
2314 this.currentElement = this.currentElement.add(cd, 0);
2315 this.lastIgnoredToken = -1;
2319 protected void consumeDefaultLabel() {
2320 // SwitchLabel ::= 'default' ':'
2321 pushOnAstStack(new CaseStatement(null, this.intStack[this.intPtr--], this.intStack[this.intPtr--]));
2323 protected void consumeDefaultModifiers() {
2324 checkComment(); // might update modifiers with AccDeprecated
2325 pushOnIntStack(this.modifiers); // modifiers
2327 this.modifiersSourceStart >= 0 ? this.modifiersSourceStart : this.scanner.startPosition);
2329 pushOnExpressionStackLengthStack(0); // no annotation
2331 protected void consumeDiet() {
2334 pushOnIntStack(this.modifiersSourceStart); // push the start position of a javadoc comment if there is one
2336 jumpOverMethodBody();
2338 protected void consumeDims() {
2339 // Dims ::= DimsLoop
2340 pushOnIntStack(this.dimensions);
2341 this.dimensions = 0;
2343 protected void consumeDimWithOrWithOutExpr() {
2344 // DimWithOrWithOutExpr ::= '[' ']'
2345 pushOnExpressionStack(null);
2347 if(this.currentElement != null && this.currentToken == TokenNameLBRACE) {
2348 this.ignoreNextOpeningBrace = true;
2349 this.currentElement.bracketBalance++;
2352 protected void consumeDimWithOrWithOutExprs() {
2353 // DimWithOrWithOutExprs ::= DimWithOrWithOutExprs DimWithOrWithOutExpr
2354 concatExpressionLists();
2356 protected void consumeEmptyAnnotationTypeMemberDeclarationsopt() {
2357 // AnnotationTypeMemberDeclarationsopt ::= $empty
2358 pushOnAstLengthStack(0);
2360 protected void consumeEmptyArgumentListopt() {
2361 // ArgumentListopt ::= $empty
2362 pushOnExpressionStackLengthStack(0);
2364 protected void consumeEmptyArguments() {
2365 // Argumentsopt ::= $empty
2366 pushOnExpressionStackLengthStack(0);
2368 protected void consumeEmptyArrayInitializer() {
2369 // ArrayInitializer ::= '{' ,opt '}'
2370 arrayInitializer(0);
2372 protected void consumeEmptyArrayInitializeropt() {
2373 // ArrayInitializeropt ::= $empty
2374 pushOnExpressionStackLengthStack(0);
2376 protected void consumeEmptyBlockStatementsopt() {
2377 // BlockStatementsopt ::= $empty
2378 pushOnAstLengthStack(0);
2380 protected void consumeEmptyCatchesopt() {
2381 // Catchesopt ::= $empty
2382 pushOnAstLengthStack(0);
2384 protected void consumeEmptyClassBodyDeclarationsopt() {
2385 // ClassBodyDeclarationsopt ::= $empty
2386 pushOnAstLengthStack(0);
2388 protected void consumeEmptyClassMemberDeclaration() {
2389 // ClassMemberDeclaration ::= ';'
2390 pushOnAstLengthStack(0);
2391 problemReporter().superfluousSemicolon(this.endPosition+1, this.endStatementPosition);
2392 flushCommentsDefinedPriorTo(this.endStatementPosition);
2394 protected void consumeEmptyMethodHeaderDefaultValue() {
2395 // DefaultValueopt ::= $empty
2396 AbstractMethodDeclaration method = (AbstractMethodDeclaration)this.astStack[this.astPtr];
2397 if(method.isAnnotationMethod()) { //'method' can be a MethodDeclaration when recovery is started
2398 pushOnExpressionStackLengthStack(0);
2401 protected void consumeEmptyDimsopt() {
2402 // Dimsopt ::= $empty
2405 protected void consumeEmptyEnumDeclarations() {
2406 // EnumBodyDeclarationsopt ::= $empty
2407 pushOnAstLengthStack(0);
2409 protected void consumeEmptyExpression() {
2410 // Expressionopt ::= $empty
2411 pushOnExpressionStackLengthStack(0);
2413 protected void consumeEmptyForInitopt() {
2414 // ForInitopt ::= $empty
2415 pushOnAstLengthStack(0);
2417 protected void consumeEmptyForUpdateopt() {
2418 // ForUpdateopt ::= $empty
2419 pushOnExpressionStackLengthStack(0);
2421 protected void consumeEmptyInterfaceMemberDeclaration() {
2422 // InterfaceMemberDeclaration ::= ';'
2423 pushOnAstLengthStack(0);
2425 protected void consumeEmptyInterfaceMemberDeclarationsopt() {
2426 // InterfaceMemberDeclarationsopt ::= $empty
2427 pushOnAstLengthStack(0);
2429 protected void consumeEmptyInternalCompilationUnit() {
2430 // InternalCompilationUnit ::= $empty
2431 // nothing to do by default
2433 protected void consumeEmptyMemberValuePairsopt() {
2434 // MemberValuePairsopt ::= $empty
2435 pushOnAstLengthStack(0);
2437 protected void consumeEmptyMemberValueArrayInitializer() {
2438 // MemberValueArrayInitializer ::= '{' ',' '}'
2439 // MemberValueArrayInitializer ::= '{' '}'
2440 arrayInitializer(0);
2442 protected void consumeEmptyStatement() {
2443 // EmptyStatement ::= ';'
2444 if (this.scanner.source[this.endStatementPosition] == ';') {
2445 pushOnAstStack(new EmptyStatement(this.endStatementPosition, this.endStatementPosition));
2447 // we have a Unicode for the ';' (/u003B)
2448 pushOnAstStack(new EmptyStatement(this.endStatementPosition - 5, this.endStatementPosition));
2451 protected void consumeEmptySwitchBlock() {
2452 // SwitchBlock ::= '{' '}'
2453 pushOnAstLengthStack(0);
2455 protected void consumeEmptyTypeDeclaration() {
2456 // TypeDeclaration ::= ';'
2457 pushOnAstLengthStack(0);
2458 problemReporter().superfluousSemicolon(this.endPosition+1, this.endStatementPosition);
2459 flushCommentsDefinedPriorTo(this.endStatementPosition);
2461 protected void consumeEnhancedForStatementHeader(boolean hasModifiers){
2462 // EnhancedForStatementHeader ::= 'for' '(' Type PushModifiers Identifier Dimsopt ':' Expression ')'
2463 // EnhancedForStatementHeader ::= 'for' '(' Modifiers Type PushRealModifiers Identifier Dimsopt ':' Expression ')'
2466 char[] identifierName = this.identifierStack[this.identifierPtr];
2467 long namePosition = this.identifierPositionStack[this.identifierPtr];
2469 LocalDeclaration localDeclaration = createLocalDeclaration(identifierName, (int) (namePosition >>> 32), (int) namePosition);
2470 localDeclaration.declarationSourceEnd = localDeclaration.declarationEnd;
2472 int extraDims = this.intStack[this.intPtr--];
2473 this.identifierPtr--;
2474 this.identifierLengthPtr--;
2475 // remove fake modifiers/modifiers start
2476 int declarationSourceStart = 0;
2477 int modifiersValue = 0;
2479 declarationSourceStart = this.intStack[this.intPtr--];
2480 modifiersValue = this.intStack[this.intPtr--];
2485 //updates are on the expression stack
2486 this.expressionLengthPtr--;
2487 Expression collection = this.expressionStack[this.expressionPtr--];
2489 type = getTypeReference(this.intStack[this.intPtr--] + extraDims); // type dimension
2491 // consume annotations
2493 if ((length = this.expressionLengthStack[this.expressionLengthPtr--])!= 0) {
2495 this.expressionStack,
2496 (this.expressionPtr -= length) + 1,
2497 localDeclaration.annotations = new Annotation[length],
2502 localDeclaration.declarationSourceStart = declarationSourceStart;
2503 localDeclaration.modifiers = modifiersValue;
2505 localDeclaration.declarationSourceStart = type.sourceStart;
2507 localDeclaration.type = type;
2509 ForeachStatement iteratorForStatement =
2510 new ForeachStatement(
2513 this.intStack[this.intPtr--]);
2514 pushOnAstStack(iteratorForStatement);
2516 if(options.sourceLevel < ClassFileConstants.JDK1_5 &&
2517 this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
2518 this.problemReporter().invalidUsageOfForeachStatements(localDeclaration, collection);
2521 protected void consumeEnhancedForStatement() {
2522 // EnhancedForStatement ::= EnhancedForStatementHeader Statement
2523 // EnhancedForStatementNoShortIf ::= EnhancedForStatementHeader StatementNoShortIf
2526 this.astLengthPtr--;
2527 Statement statement = (Statement) this.astStack[this.astPtr--];
2529 // foreach statement is on the ast stack
2530 ForeachStatement foreachStatement = (ForeachStatement) this.astStack[this.astPtr];
2531 foreachStatement.action = statement;
2532 // remember useful empty statement
2533 if (statement instanceof EmptyStatement) statement.bits |= ASTNode.IsUsefulEmptyStatementMASK;
2535 foreachStatement.sourceEnd = this.endStatementPosition;
2537 protected void consumeEnterAnonymousClassBody() {
2538 // EnterAnonymousClassBody ::= $empty
2539 TypeReference typeReference = getTypeReference(0);
2541 TypeDeclaration anonymousType = new TypeDeclaration(this.compilationUnit.compilationResult);
2542 anonymousType.name = TypeDeclaration.ANONYMOUS_EMPTY_NAME;
2543 anonymousType.bits |= ASTNode.AnonymousAndLocalMask;
2544 QualifiedAllocationExpression alloc = new QualifiedAllocationExpression(anonymousType);
2545 markEnclosingMemberWithLocalType();
2546 pushOnAstStack(anonymousType);
2548 alloc.sourceEnd = this.rParenPos; //the position has been stored explicitly
2550 if ((argumentLength = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
2551 this.expressionPtr -= argumentLength;
2553 this.expressionStack,
2554 this.expressionPtr + 1,
2555 alloc.arguments = new Expression[argumentLength],
2559 alloc.type = typeReference;
2561 anonymousType.sourceEnd = alloc.sourceEnd;
2562 //position at the type while it impacts the anonymous declaration
2563 anonymousType.sourceStart = anonymousType.declarationSourceStart = alloc.type.sourceStart;
2564 alloc.sourceStart = this.intStack[this.intPtr--];
2565 pushOnExpressionStack(alloc);
2567 anonymousType.bodyStart = this.scanner.currentPosition;
2568 this.listLength = 0; // will be updated when reading super-interfaces
2570 if (this.currentElement != null){
2571 this.lastCheckPoint = anonymousType.bodyStart;
2572 this.currentElement = this.currentElement.add(anonymousType, 0);
2573 this.currentToken = 0; // opening brace already taken into account
2574 this.lastIgnoredToken = -1;
2577 protected void consumeEnterAnonymousClassBodySimpleName() {
2578 // EnterAnonymousClassBody ::= $empty
2579 pushOnGenericsLengthStack(0);
2580 pushOnGenericsIdentifiersLengthStack(this.identifierLengthStack[this.identifierLengthPtr]);
2581 TypeReference typeReference = getTypeReference(0);
2583 TypeDeclaration anonymousType = new TypeDeclaration(this.compilationUnit.compilationResult);
2584 anonymousType.name = TypeDeclaration.ANONYMOUS_EMPTY_NAME;
2585 anonymousType.bits |= ASTNode.AnonymousAndLocalMask;
2586 QualifiedAllocationExpression alloc = new QualifiedAllocationExpression(anonymousType);
2587 markEnclosingMemberWithLocalType();
2588 pushOnAstStack(anonymousType);
2590 alloc.sourceEnd = this.rParenPos; //the position has been stored explicitly
2592 if ((argumentLength = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
2593 this.expressionPtr -= argumentLength;
2595 this.expressionStack,
2596 this.expressionPtr + 1,
2597 alloc.arguments = new Expression[argumentLength],
2601 alloc.type = typeReference;
2603 anonymousType.sourceEnd = alloc.sourceEnd;
2604 //position at the type while it impacts the anonymous declaration
2605 anonymousType.sourceStart = anonymousType.declarationSourceStart = alloc.type.sourceStart;
2606 alloc.sourceStart = this.intStack[this.intPtr--];
2607 pushOnExpressionStack(alloc);
2609 anonymousType.bodyStart = this.scanner.currentPosition;
2610 this.listLength = 0; // will be updated when reading super-interfaces
2612 if (this.currentElement != null){
2613 this.lastCheckPoint = anonymousType.bodyStart;
2614 this.currentElement = this.currentElement.add(anonymousType, 0);
2615 this.currentToken = 0; // opening brace already taken into account
2616 this.lastIgnoredToken = -1;
2619 protected void consumeEnterCompilationUnit() {
2620 // EnterCompilationUnit ::= $empty
2621 // do nothing by default
2623 protected void consumeEnterVariable() {
2624 // EnterVariable ::= $empty
2625 // do nothing by default
2627 char[] identifierName = this.identifierStack[this.identifierPtr];
2628 long namePosition = this.identifierPositionStack[this.identifierPtr];
2629 int extendedDimension = this.intStack[this.intPtr--];
2630 AbstractVariableDeclaration declaration;
2631 // create the ast node
2632 boolean isLocalDeclaration = this.nestedMethod[this.nestedType] != 0;
2633 if (isLocalDeclaration) {
2634 // create the local variable declarations
2636 this.createLocalDeclaration(identifierName, (int) (namePosition >>> 32), (int) namePosition);
2638 // create the field declaration
2640 this.createFieldDeclaration(identifierName, (int) (namePosition >>> 32), (int) namePosition);
2643 this.identifierPtr--;
2644 this.identifierLengthPtr--;
2646 int variableIndex = this.variablesCounter[this.nestedType];
2648 if (variableIndex == 0) {
2649 // first variable of the declaration (FieldDeclaration or LocalDeclaration)
2650 if (isLocalDeclaration) {
2651 declaration.declarationSourceStart = this.intStack[this.intPtr--];
2652 declaration.modifiers = this.intStack[this.intPtr--];
2653 // consume annotations
2655 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
2657 this.expressionStack,
2658 (this.expressionPtr -= length) + 1,
2659 declaration.annotations = new Annotation[length],
2663 type = getTypeReference(typeDim = this.intStack[this.intPtr--]); // type dimension
2664 if (declaration.declarationSourceStart == -1) {
2665 // this is true if there is no modifiers for the local variable declaration
2666 declaration.declarationSourceStart = type.sourceStart;
2668 pushOnAstStack(type);
2670 type = getTypeReference(typeDim = this.intStack[this.intPtr--]); // type dimension
2671 pushOnAstStack(type);
2672 declaration.declarationSourceStart = this.intStack[this.intPtr--];
2673 declaration.modifiers = this.intStack[this.intPtr--];
2674 // consume annotations
2676 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
2678 this.expressionStack,
2679 (this.expressionPtr -= length) + 1,
2680 declaration.annotations = new Annotation[length],
2684 // Store javadoc only on first declaration as it is the same for all ones
2685 FieldDeclaration fieldDeclaration = (FieldDeclaration) declaration;
2686 fieldDeclaration.javadoc = this.javadoc;
2687 this.javadoc = null;
2690 type = (TypeReference) this.astStack[this.astPtr - variableIndex];
2691 typeDim = type.dimensions();
2692 AbstractVariableDeclaration previousVariable =
2693 (AbstractVariableDeclaration) this.astStack[this.astPtr];
2694 declaration.declarationSourceStart = previousVariable.declarationSourceStart;
2695 declaration.modifiers = previousVariable.modifiers;
2698 if (extendedDimension == 0) {
2699 declaration.type = type;
2701 int dimension = typeDim + extendedDimension;
2702 //on the this.identifierLengthStack there is the information about the type....
2704 if ((baseType = this.identifierLengthStack[this.identifierLengthPtr + 1]) < 0) {
2706 int typeSourceStart = type.sourceStart;
2707 int typeSourceEnd = type.sourceEnd;
2708 type = TypeReference.baseTypeReference(-baseType, dimension);
2709 type.sourceStart = typeSourceStart;
2710 type.sourceEnd = typeSourceEnd;
2711 declaration.type = type;
2713 declaration.type = this.copyDims(type, dimension);
2716 this.variablesCounter[this.nestedType]++;
2717 pushOnAstStack(declaration);
2719 if (this.currentElement != null) {
2720 if (!(this.currentElement instanceof RecoveredType)
2721 && (this.currentToken == TokenNameDOT
2722 //|| declaration.modifiers != 0
2723 || (this.scanner.getLineNumber(declaration.type.sourceStart)
2724 != this.scanner.getLineNumber((int) (namePosition >>> 32))))){
2725 this.lastCheckPoint = (int) (namePosition >>> 32);
2726 this.restartRecovery = true;
2729 if (isLocalDeclaration){
2730 LocalDeclaration localDecl = (LocalDeclaration) this.astStack[this.astPtr];
2731 this.lastCheckPoint = localDecl.sourceEnd + 1;
2732 this.currentElement = this.currentElement.add(localDecl, 0);
2734 FieldDeclaration fieldDecl = (FieldDeclaration) this.astStack[this.astPtr];
2735 this.lastCheckPoint = fieldDecl.sourceEnd + 1;
2736 this.currentElement = this.currentElement.add(fieldDecl, 0);
2738 this.lastIgnoredToken = -1;
2741 protected void consumeEnumBodyNoConstants() {
2743 // The 0 on the astLengthStack has been pushed by EnumBodyDeclarationsopt
2745 protected void consumeEnumBodyWithConstants() {
2746 // merge the constants values with the class body
2749 protected void consumeEnumConstantHeaderName() {
2750 if (this.currentElement != null) {
2751 if (!(this.currentElement instanceof RecoveredType
2752 || (this.currentElement instanceof RecoveredField && ((RecoveredField)currentElement).fieldDeclaration.type == null))
2753 || (this.lastIgnoredToken == TokenNameDOT)) {
2754 this.lastCheckPoint = this.scanner.startPosition;
2755 this.restartRecovery = true;
2759 long namePosition = this.identifierPositionStack[this.identifierPtr];
2760 char[] constantName = this.identifierStack[this.identifierPtr--];
2761 final int sourceEnd = (int) namePosition;
2762 FieldDeclaration enumConstant = createFieldDeclaration(constantName, (int) (namePosition >>> 32), sourceEnd);
2763 this.identifierLengthPtr--;
2764 enumConstant.modifiersSourceStart = this.intStack[this.intPtr--];
2765 enumConstant.modifiers = this.intStack[this.intPtr--];
2766 enumConstant.declarationSourceStart = enumConstant.modifiersSourceStart;
2767 // consume annotations
2769 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
2771 this.expressionStack,
2772 (this.expressionPtr -= length) + 1,
2773 enumConstant.annotations = new Annotation[length],
2777 pushOnAstStack(enumConstant);
2778 if (this.currentElement != null){
2779 this.lastCheckPoint = enumConstant.sourceEnd + 1;
2780 this.currentElement = this.currentElement.add(enumConstant, 0);
2783 enumConstant.javadoc = this.javadoc;
2784 this.javadoc = null;
2786 protected void consumeEnumConstantHeader() {
2787 FieldDeclaration enumConstant = (FieldDeclaration) this.astStack[this.astPtr];
2788 boolean foundOpeningBrace = this.currentToken == TokenNameLBRACE;
2789 if (foundOpeningBrace){
2790 // qualified allocation expression
2791 TypeDeclaration anonymousType = new TypeDeclaration(this.compilationUnit.compilationResult);
2792 anonymousType.name = TypeDeclaration.ANONYMOUS_EMPTY_NAME;
2793 anonymousType.bits |= ASTNode.AnonymousAndLocalMask;
2794 final int start = this.scanner.startPosition;
2795 anonymousType.declarationSourceStart = start;
2796 anonymousType.sourceStart = start;
2797 anonymousType.sourceEnd = start; // closing parenthesis
2798 anonymousType.modifiers = 0;
2799 anonymousType.bodyStart = this.scanner.currentPosition;
2800 markEnclosingMemberWithLocalType();
2801 pushOnAstStack(anonymousType);
2802 QualifiedAllocationExpression allocationExpression = new QualifiedAllocationExpression(anonymousType);
2803 allocationExpression.enumConstant = enumConstant;
2805 // fill arguments if needed
2807 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
2808 this.expressionPtr -= length;
2810 this.expressionStack,
2811 this.expressionPtr + 1,
2812 allocationExpression.arguments = new Expression[length],
2816 enumConstant.initialization = allocationExpression;
2818 AllocationExpression allocationExpression = new AllocationExpression();
2819 allocationExpression.enumConstant = enumConstant;
2820 // fill arguments if needed
2822 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
2823 this.expressionPtr -= length;
2825 this.expressionStack,
2826 this.expressionPtr + 1,
2827 allocationExpression.arguments = new Expression[length],
2831 enumConstant.initialization = allocationExpression;
2835 if (this.currentElement != null) {
2836 if(foundOpeningBrace) {
2837 TypeDeclaration anonymousType = (TypeDeclaration) this.astStack[this.astPtr];
2838 this.currentElement = this.currentElement.add(anonymousType, 0);
2839 this.lastCheckPoint = anonymousType.bodyStart;
2840 this.lastIgnoredToken = -1;
2841 this.currentToken = 0; // opening brace already taken into account
2843 if(this.currentToken == TokenNameSEMICOLON) {
2844 RecoveredType currentType = this.currentRecoveryType();
2845 if(currentType != null) {
2846 currentType.insideEnumConstantPart = false;
2849 if (!(this.currentElement instanceof RecoveredType)
2850 && (this.currentToken == TokenNameDOT)){
2851 this.lastCheckPoint = enumConstant.sourceStart;
2852 this.restartRecovery = true;
2855 this.lastCheckPoint = this.scanner.startPosition; // force to restart at this exact position
2856 this.lastIgnoredToken = -1;
2857 this.restartRecovery = true;
2861 protected void consumeEnumConstantNoClassBody() {
2862 // set declarationEnd and declarationSourceEnd
2863 final FieldDeclaration fieldDeclaration = (FieldDeclaration) this.astStack[this.astPtr];
2864 int declarationEnd = fieldDeclaration.sourceEnd;
2865 if (declarationEnd > rParenPos) {
2866 fieldDeclaration.declarationEnd = declarationEnd;
2867 fieldDeclaration.declarationSourceEnd = flushCommentsDefinedPriorTo(declarationEnd);
2869 fieldDeclaration.declarationEnd = rParenPos;
2870 fieldDeclaration.declarationSourceEnd = flushCommentsDefinedPriorTo(rParenPos);
2873 protected void consumeEnumConstants() {
2876 protected void consumeEnumConstantWithClassBody() {
2877 dispatchDeclarationInto(this.astLengthStack[this.astLengthPtr--]);
2878 TypeDeclaration anonymousType = (TypeDeclaration) this.astStack[this.astPtr--]; // pop type
2879 this.astLengthPtr--;
2880 anonymousType.bodyEnd = this.endPosition;
2881 anonymousType.declarationSourceEnd = flushCommentsDefinedPriorTo(this.endStatementPosition);
2882 final FieldDeclaration fieldDeclaration = ((FieldDeclaration) this.astStack[this.astPtr]);
2883 fieldDeclaration.declarationEnd = this.endStatementPosition;
2884 fieldDeclaration.declarationSourceEnd = anonymousType.declarationSourceEnd;
2886 protected void consumeEnumDeclaration() {
2887 // EnumDeclaration ::= EnumHeader ClassHeaderImplementsopt EnumBody
2889 if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) {
2890 //there are length declarations
2891 //dispatch according to the type of the declarations
2892 dispatchDeclarationIntoEnumDeclaration(length);
2895 TypeDeclaration enumDeclaration = (TypeDeclaration) this.astStack[this.astPtr];
2897 // mark initializers with local type mark if needed
2898 markInitializersWithLocalType(enumDeclaration);
2900 //convert constructor that do not have the type's name into methods
2901 boolean hasConstructor = enumDeclaration.checkConstructors(this);
2903 //add the default constructor when needed
2904 if (!hasConstructor) {
2905 boolean insideFieldInitializer = false;
2907 for (int i = this.nestedType; i > 0; i--){
2908 if (this.variablesCounter[i] > 0) {
2909 insideFieldInitializer = true;
2914 enumDeclaration.createDefaultConstructor(!this.diet || insideFieldInitializer, true);
2917 //always add <clinit> (will be remove at code gen time if empty)
2918 if (this.scanner.containsAssertKeyword) {
2919 enumDeclaration.bits |= ASTNode.AddAssertionMASK;
2921 enumDeclaration.addClinit();
2922 enumDeclaration.bodyEnd = this.endStatementPosition;
2923 if (length == 0 && !containsComment(enumDeclaration.bodyStart, enumDeclaration.bodyEnd)) {
2924 enumDeclaration.bits |= ASTNode.UndocumentedEmptyBlockMASK;
2927 enumDeclaration.declarationSourceEnd = flushCommentsDefinedPriorTo(this.endStatementPosition);
2929 protected void consumeEnumDeclarations() {
2930 // Do nothing by default
2932 protected void consumeEnumHeader() {
2933 TypeDeclaration typeDecl = (TypeDeclaration) this.astStack[this.astPtr];
2934 if (this.currentToken == TokenNameLBRACE) {
2935 typeDecl.bodyStart = this.scanner.currentPosition;
2938 if (this.currentElement != null) {
2939 this.restartRecovery = true; // used to avoid branching back into the regular automaton
2942 // flush the comments related to the enum header
2943 this.scanner.commentPtr = -1;
2945 protected void consumeEnumHeaderName() {
2946 // EnumHeaderName ::= Modifiersopt 'enum' Identifier
2947 TypeDeclaration enumDeclaration = new TypeDeclaration(this.compilationUnit.compilationResult);
2948 if (this.nestedMethod[this.nestedType] == 0) {
2949 if (this.nestedType != 0) {
2950 enumDeclaration.bits |= ASTNode.IsMemberTypeMASK;
2953 // Record that the block has a declaration for local types
2954 // markEnclosingMemberWithLocalType();
2957 //highlight the name of the type
2958 long pos = this.identifierPositionStack[this.identifierPtr];
2959 enumDeclaration.sourceEnd = (int) pos;
2960 enumDeclaration.sourceStart = (int) (pos >>> 32);
2961 enumDeclaration.name = this.identifierStack[this.identifierPtr--];
2962 this.identifierLengthPtr--;
2964 //compute the declaration source too
2965 // 'class' and 'interface' push two int positions: the beginning of the class token and its end.
2966 // we want to keep the beginning position but get rid of the end position
2967 // it is only used for the ClassLiteralAccess positions.
2968 enumDeclaration.declarationSourceStart = this.intStack[this.intPtr--];
2969 this.intPtr--; // remove the end position of the class token
2971 enumDeclaration.modifiersSourceStart = this.intStack[this.intPtr--];
2972 enumDeclaration.modifiers = this.intStack[this.intPtr--] | AccEnum;
2973 if (enumDeclaration.modifiersSourceStart >= 0) {
2974 enumDeclaration.declarationSourceStart = enumDeclaration.modifiersSourceStart;
2976 // consume annotations
2978 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
2980 this.expressionStack,
2981 (this.expressionPtr -= length) + 1,
2982 enumDeclaration.annotations = new Annotation[length],
2986 // if (this.currentToken == TokenNameLBRACE) {
2987 // enumDeclaration.bodyStart = this.scanner.currentPosition;
2989 enumDeclaration.bodyStart = enumDeclaration.sourceEnd + 1;
2990 pushOnAstStack(enumDeclaration);
2992 this.listLength = 0; // will be updated when reading super-interfaces
2994 if(options.sourceLevel < ClassFileConstants.JDK1_5 &&
2995 this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
2996 //TODO this code will be never run while 'enum' is an identifier in 1.3 scanner
2997 this.problemReporter().invalidUsageOfEnumDeclarations(enumDeclaration);
3001 if (this.currentElement != null){
3002 this.lastCheckPoint = enumDeclaration.bodyStart;
3003 this.currentElement = this.currentElement.add(enumDeclaration, 0);
3004 this.lastIgnoredToken = -1;
3007 enumDeclaration.javadoc = this.javadoc;
3008 this.javadoc = null;
3010 protected void consumeEqualityExpression(int op) {
3011 // EqualityExpression ::= EqualityExpression '==' RelationalExpression
3012 // EqualityExpression ::= EqualityExpression '!=' RelationalExpression
3014 //optimize the push/pop
3016 this.expressionPtr--;
3017 this.expressionLengthPtr--;
3018 this.expressionStack[this.expressionPtr] =
3019 new EqualExpression(
3020 this.expressionStack[this.expressionPtr],
3021 this.expressionStack[this.expressionPtr + 1],
3027 protected void consumeEqualityExpressionWithName(int op) {
3028 // EqualityExpression ::= Name '==' RelationalExpression
3029 // EqualityExpression ::= Name '!=' RelationalExpression
3030 pushOnExpressionStack(getUnspecifiedReferenceOptimized());
3031 this.expressionPtr--;
3032 this.expressionLengthPtr--;
3033 this.expressionStack[this.expressionPtr] =
3034 new EqualExpression(
3035 this.expressionStack[this.expressionPtr + 1],
3036 this.expressionStack[this.expressionPtr],
3039 protected void consumeExitTryBlock() {
3040 //ExitTryBlock ::= $empty
3041 if(this.currentElement != null) {
3042 this.restartRecovery = true;
3045 protected void consumeExitVariableWithInitialization() {
3046 // ExitVariableWithInitialization ::= $empty
3047 // do nothing by default
3048 this.expressionLengthPtr--;
3049 AbstractVariableDeclaration variableDecl = (AbstractVariableDeclaration) this.astStack[this.astPtr];
3050 variableDecl.initialization = this.expressionStack[this.expressionPtr--];
3051 // we need to update the declarationSourceEnd of the local variable declaration to the
3052 // source end position of the initialization expression
3053 variableDecl.declarationSourceEnd = variableDecl.initialization.sourceEnd;
3054 variableDecl.declarationEnd = variableDecl.initialization.sourceEnd;
3056 this.recoveryExitFromVariable();
3058 protected void consumeExitVariableWithoutInitialization() {
3059 // ExitVariableWithoutInitialization ::= $empty
3060 // do nothing by default
3062 AbstractVariableDeclaration variableDecl = (AbstractVariableDeclaration) this.astStack[this.astPtr];
3063 variableDecl.declarationSourceEnd = variableDecl.declarationEnd;
3064 if(this.currentElement != null && this.currentElement instanceof RecoveredField) {
3065 if(this.endStatementPosition > variableDecl.sourceEnd) {
3066 this.currentElement.updateSourceEndIfNecessary(this.endStatementPosition);
3069 this.recoveryExitFromVariable();
3071 protected void consumeExplicitConstructorInvocation(int flag, int recFlag) {
3073 /* flag allows to distinguish 3 cases :
3075 ExplicitConstructorInvocation ::= 'this' '(' ArgumentListopt ')' ';'
3076 ExplicitConstructorInvocation ::= 'super' '(' ArgumentListopt ')' ';'
3078 ExplicitConstructorInvocation ::= Primary '.' 'super' '(' ArgumentListopt ')' ';'
3079 ExplicitConstructorInvocation ::= Primary '.' 'this' '(' ArgumentListopt ')' ';'
3081 ExplicitConstructorInvocation ::= Name '.' 'super' '(' ArgumentListopt ')' ';'
3082 ExplicitConstructorInvocation ::= Name '.' 'this' '(' ArgumentListopt ')' ';'
3084 int startPosition = this.intStack[this.intPtr--];
3085 ExplicitConstructorCall ecc = new ExplicitConstructorCall(recFlag);
3087 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
3088 this.expressionPtr -= length;
3089 System.arraycopy(this.expressionStack, this.expressionPtr + 1, ecc.arguments = new Expression[length], 0, length);
3093 ecc.sourceStart = startPosition;
3096 this.expressionLengthPtr--;
3097 ecc.sourceStart = (ecc.qualification = this.expressionStack[this.expressionPtr--]).sourceStart;
3100 ecc.sourceStart = (ecc.qualification = getUnspecifiedReferenceOptimized()).sourceStart;
3103 pushOnAstStack(ecc);
3104 ecc.sourceEnd = this.endPosition;
3106 protected void consumeExplicitConstructorInvocationWithTypeArguments(int flag, int recFlag) {
3108 /* flag allows to distinguish 3 cases :
3110 ExplicitConstructorInvocation ::= TypeArguments 'this' '(' ArgumentListopt ')' ';'
3111 ExplicitConstructorInvocation ::= TypeArguments 'super' '(' ArgumentListopt ')' ';'
3113 ExplicitConstructorInvocation ::= Primary '.' TypeArguments 'super' '(' ArgumentListopt ')' ';'
3114 ExplicitConstructorInvocation ::= Primary '.' TypeArguments 'this' '(' ArgumentListopt ')' ';'
3116 ExplicitConstructorInvocation ::= Name '.' TypeArguments 'super' '(' ArgumentListopt ')' ';'
3117 ExplicitConstructorInvocation ::= Name '.' TypeArguments 'this' '(' ArgumentListopt ')' ';'
3119 int startPosition = this.intStack[this.intPtr--];
3120 ExplicitConstructorCall ecc = new ExplicitConstructorCall(recFlag);
3122 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
3123 this.expressionPtr -= length;
3124 System.arraycopy(this.expressionStack, this.expressionPtr + 1, ecc.arguments = new Expression[length], 0, length);
3126 length = this.genericsLengthStack[this.genericsLengthPtr--];
3127 this.genericsPtr -= length;
3128 System.arraycopy(this.genericsStack, this.genericsPtr + 1, ecc.typeArguments = new TypeReference[length], 0, length);
3129 ecc.typeArgumentsSourceStart = this.intStack[intPtr--];
3133 ecc.sourceStart = startPosition;
3136 this.expressionLengthPtr--;
3137 ecc.sourceStart = (ecc.qualification = this.expressionStack[this.expressionPtr--]).sourceStart;
3140 ecc.sourceStart = (ecc.qualification = getUnspecifiedReferenceOptimized()).sourceStart;
3144 pushOnAstStack(ecc);
3145 ecc.sourceEnd = this.endPosition;
3147 protected void consumeExpressionStatement() {
3148 // ExpressionStatement ::= StatementExpression ';'
3149 this.expressionLengthPtr--;
3150 pushOnAstStack(this.expressionStack[this.expressionPtr--]);
3152 protected void consumeFieldAccess(boolean isSuperAccess) {
3153 // FieldAccess ::= Primary '.' 'Identifier'
3154 // FieldAccess ::= 'super' '.' 'Identifier'
3158 this.identifierStack[this.identifierPtr],
3159 this.identifierPositionStack[this.identifierPtr--]);
3160 this.identifierLengthPtr--;
3161 if (isSuperAccess) {
3162 //considerates the fieldReference beginning at the 'super' ....
3163 fr.sourceStart = this.intStack[this.intPtr--];
3164 fr.receiver = new SuperReference(fr.sourceStart, this.endPosition);
3165 pushOnExpressionStack(fr);
3168 if ((fr.receiver = this.expressionStack[this.expressionPtr]).isThis()) {
3169 //fieldreference begins at the this
3170 fr.sourceStart = fr.receiver.sourceStart;
3172 this.expressionStack[this.expressionPtr] = fr;
3175 protected void consumeFieldDeclaration() {
3176 // See consumeLocalVariableDeclarationDefaultModifier() in case of change: duplicated code
3177 // FieldDeclaration ::= Modifiersopt Type VariableDeclarators ';'
3181 this.expressionStack: Expression Expression ...... Expression
3182 this.identifierStack : type identifier identifier ...... identifier
3183 this.intStack : typeDim dim dim dim
3185 this.astStack : FieldDeclaration FieldDeclaration ...... FieldDeclaration
3186 this.expressionStack :
3187 this.identifierStack :
3191 int variableDeclaratorsCounter = this.astLengthStack[this.astLengthPtr];
3193 for (int i = variableDeclaratorsCounter - 1; i >= 0; i--) {
3194 FieldDeclaration fieldDeclaration = (FieldDeclaration) this.astStack[this.astPtr - i];
3195 fieldDeclaration.declarationSourceEnd = this.endStatementPosition;
3196 fieldDeclaration.declarationEnd = this.endStatementPosition; // semi-colon included
3199 updateSourceDeclarationParts(variableDeclaratorsCounter);
3200 int endPos = flushCommentsDefinedPriorTo(this.endStatementPosition);
3201 if (endPos != this.endStatementPosition) {
3202 for (int i = 0; i < variableDeclaratorsCounter; i++) {
3203 FieldDeclaration fieldDeclaration = (FieldDeclaration) this.astStack[this.astPtr - i];
3204 fieldDeclaration.declarationSourceEnd = endPos;
3207 // update the this.astStack, this.astPtr and this.astLengthStack
3208 int startIndex = this.astPtr - this.variablesCounter[this.nestedType] + 1;
3214 variableDeclaratorsCounter);
3215 this.astPtr--; // remove the type reference
3216 this.astLengthStack[--this.astLengthPtr] = variableDeclaratorsCounter;
3219 if (this.currentElement != null) {
3220 this.lastCheckPoint = endPos + 1;
3221 if (this.currentElement.parent != null && this.currentElement instanceof RecoveredField){
3222 if (!(this.currentElement instanceof RecoveredInitializer)) {
3223 this.currentElement = this.currentElement.parent;
3226 this.restartRecovery = true;
3228 this.variablesCounter[this.nestedType] = 0;
3230 protected void consumeForceNoDiet() {
3231 // ForceNoDiet ::= $empty
3234 protected void consumeForInit() {
3235 // ForInit ::= StatementExpressionList
3236 pushOnAstLengthStack(-1);
3238 protected void consumeFormalParameter(boolean isVarArgs) {
3239 // FormalParameter ::= Type VariableDeclaratorId ==> false
3240 // FormalParameter ::= Modifiers Type VariableDeclaratorId ==> true
3243 this.identifierStack : type identifier
3244 this.intStack : dim dim
3246 this.astStack : Argument
3247 this.identifierStack :
3251 this.identifierLengthPtr--;
3252 char[] identifierName = this.identifierStack[this.identifierPtr];
3253 long namePositions = this.identifierPositionStack[this.identifierPtr--];
3254 int extendedDimensions = this.intStack[this.intPtr--];
3255 int endOfEllipsis = 0;
3257 endOfEllipsis = this.intStack[this.intPtr--];
3259 int firstDimensions = this.intStack[this.intPtr--];
3260 final int typeDimensions = firstDimensions + extendedDimensions;
3261 TypeReference type = getTypeReference(typeDimensions);
3263 type = type.copyDims(typeDimensions + 1);
3264 if (extendedDimensions == 0) {
3265 type.sourceEnd = endOfEllipsis;
3267 type.bits |= ASTNode.IsVarArgs; // set isVarArgs
3269 int modifierPositions = this.intStack[this.intPtr--];
3276 this.intStack[this.intPtr + 1] & ~AccDeprecated); // modifiers
3277 arg.declarationSourceStart = modifierPositions;
3278 // consume annotations
3280 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
3282 this.expressionStack,
3283 (this.expressionPtr -= length) + 1,
3284 arg.annotations = new Annotation[length],
3288 pushOnAstStack(arg);
3290 /* if incomplete method header, this.listLength counter will not have been reset,
3291 indicating that some arguments are available on the stack */
3295 if (options.sourceLevel < ClassFileConstants.JDK1_5 &&
3296 this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
3297 this.problemReporter().invalidUsageOfVarargs(arg);
3298 } else if (extendedDimensions > 0) {
3299 this.problemReporter().illegalExtendedDimensions(arg);
3303 protected void consumeFormalParameterList() {
3304 // FormalParameterList ::= FormalParameterList ',' FormalParameter
3305 optimizedConcatNodeLists();
3307 protected void consumeFormalParameterListopt() {
3308 // FormalParameterListopt ::= $empty
3309 pushOnAstLengthStack(0);
3311 protected void consumeGenericType() {
3313 // Will be consume by a getTypeRefence call
3315 protected void consumeGenericTypeArrayType() {
3317 // Will be consume by a getTypeRefence call
3319 protected void consumeGenericTypeNameArrayType() {
3320 pushOnGenericsLengthStack(0); // handle type arguments
3322 protected void consumeImportDeclaration() {
3323 // SingleTypeImportDeclaration ::= SingleTypeImportDeclarationName ';'
3324 ImportReference impt = (ImportReference) this.astStack[this.astPtr];
3325 // flush annotations defined prior to import statements
3326 impt.declarationEnd = this.endStatementPosition;
3327 impt.declarationSourceEnd =
3328 this.flushCommentsDefinedPriorTo(impt.declarationSourceEnd);
3331 if (this.currentElement != null) {
3332 this.lastCheckPoint = impt.declarationSourceEnd + 1;
3333 this.currentElement = this.currentElement.add(impt, 0);
3334 this.lastIgnoredToken = -1;
3335 this.restartRecovery = true;
3336 // used to avoid branching back into the regular automaton
3339 protected void consumeImportDeclarations() {
3340 // ImportDeclarations ::= ImportDeclarations ImportDeclaration
3341 optimizedConcatNodeLists();
3343 protected void consumeInsideCastExpression() {
3344 // InsideCastExpression ::= $empty
3346 protected void consumeInsideCastExpressionLL1() {
3347 // InsideCastExpressionLL1 ::= $empty
3348 pushOnExpressionStack(getUnspecifiedReferenceOptimized());
3350 protected void consumeInsideCastExpressionWithQualifiedGenerics() {
3351 // InsideCastExpressionWithQualifiedGenerics ::= $empty
3353 protected void consumeInstanceOfExpression(int op) {
3354 // RelationalExpression ::= RelationalExpression 'instanceof' ReferenceType
3355 //optimize the push/pop
3357 //by construction, no base type may be used in getTypeReference
3359 this.expressionStack[this.expressionPtr] = exp =
3360 new InstanceOfExpression(
3361 this.expressionStack[this.expressionPtr],
3362 getTypeReference(this.intStack[this.intPtr--]),
3364 if (exp.sourceEnd == 0) {
3365 //array on base type....
3366 exp.sourceEnd = this.scanner.startPosition - 1;
3368 //the scanner is on the next token already....
3373 protected void consumeInstanceOfExpressionWithName(int op) {
3374 // RelationalExpression_NotName ::= Name instanceof ReferenceType
3375 //optimize the push/pop
3377 //by construction, no base type may be used in getTypeReference
3378 TypeReference reference = getTypeReference(this.intStack[this.intPtr--]);
3379 pushOnExpressionStack(getUnspecifiedReferenceOptimized());
3381 this.expressionStack[this.expressionPtr] = exp =
3382 new InstanceOfExpression(
3383 this.expressionStack[this.expressionPtr],
3386 if (exp.sourceEnd == 0) {
3387 //array on base type....
3388 exp.sourceEnd = this.scanner.startPosition - 1;
3390 //the scanner is on the next token already....
3392 protected void consumeInterfaceDeclaration() {
3393 // see consumeClassDeclaration in case of changes: duplicated code
3394 // InterfaceDeclaration ::= InterfaceHeader InterfaceBody
3396 if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) {
3397 //there are length declarations
3398 //dispatch.....according to the type of the declarations
3399 dispatchDeclarationInto(length);
3402 TypeDeclaration typeDecl = (TypeDeclaration) this.astStack[this.astPtr];
3404 // mark initializers with local type mark if needed
3405 markInitializersWithLocalType(typeDecl);
3407 //convert constructor that do not have the type's name into methods
3408 typeDecl.checkConstructors(this);
3410 //always add <clinit> (will be remove at code gen time if empty)
3411 if (this.scanner.containsAssertKeyword) {
3412 typeDecl.bits |= ASTNode.AddAssertionMASK;
3414 typeDecl.addClinit();
3415 typeDecl.bodyEnd = this.endStatementPosition;
3416 if (length == 0 && !containsComment(typeDecl.bodyStart, typeDecl.bodyEnd)) {
3417 typeDecl.bits |= ASTNode.UndocumentedEmptyBlockMASK;
3419 typeDecl.declarationSourceEnd = flushCommentsDefinedPriorTo(this.endStatementPosition);
3421 protected void consumeInterfaceHeader() {
3422 // InterfaceHeader ::= InterfaceHeaderName InterfaceHeaderExtendsopt
3424 TypeDeclaration typeDecl = (TypeDeclaration) this.astStack[this.astPtr];
3425 if (this.currentToken == TokenNameLBRACE){
3426 typeDecl.bodyStart = this.scanner.currentPosition;
3428 if (this.currentElement != null){
3429 this.restartRecovery = true; // used to avoid branching back into the regular automaton
3431 // flush the comments related to the interface header
3432 this.scanner.commentPtr = -1;
3434 protected void consumeInterfaceHeaderExtends() {
3435 // InterfaceHeaderExtends ::= 'extends' InterfaceTypeList
3436 int length = this.astLengthStack[this.astLengthPtr--];
3438 this.astPtr -= length;
3439 TypeDeclaration typeDecl = (TypeDeclaration) this.astStack[this.astPtr];
3443 typeDecl.superInterfaces = new TypeReference[length],
3446 for (int i = 0, max = typeDecl.superInterfaces.length; i < max; i++) {
3447 typeDecl.superInterfaces[i].bits |= ASTNode.IsSuperType;
3449 typeDecl.bodyStart = typeDecl.superInterfaces[length-1].sourceEnd + 1;
3450 this.listLength = 0; // reset after having read super-interfaces
3452 if (this.currentElement != null) {
3453 this.lastCheckPoint = typeDecl.bodyStart;
3456 protected void consumeInterfaceHeaderName1() {
3457 // InterfaceHeaderName ::= Modifiersopt 'interface' 'Identifier'
3458 TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
3460 if (this.nestedMethod[this.nestedType] == 0) {
3461 if (this.nestedType != 0) {
3462 typeDecl.bits |= ASTNode.IsMemberTypeMASK;
3465 // Record that the block has a declaration for local types
3466 typeDecl.bits |= ASTNode.IsLocalTypeMASK;
3467 markEnclosingMemberWithLocalType();
3471 //highlight the name of the type
3472 long pos = this.identifierPositionStack[this.identifierPtr];
3473 typeDecl.sourceEnd = (int) pos;
3474 typeDecl.sourceStart = (int) (pos >>> 32);
3475 typeDecl.name = this.identifierStack[this.identifierPtr--];
3476 this.identifierLengthPtr--;
3478 //compute the declaration source too
3479 // 'class' and 'interface' push two int positions: the beginning of the class token and its end.
3480 // we want to keep the beginning position but get rid of the end position
3481 // it is only used for the ClassLiteralAccess positions.
3482 typeDecl.declarationSourceStart = this.intStack[this.intPtr--];
3483 this.intPtr--; // remove the end position of the class token
3484 typeDecl.modifiersSourceStart = this.intStack[this.intPtr--];
3485 typeDecl.modifiers = this.intStack[this.intPtr--] | AccInterface;
3486 if (typeDecl.modifiersSourceStart >= 0) {
3487 typeDecl.declarationSourceStart = typeDecl.modifiersSourceStart;
3489 // consume annotations
3491 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
3493 this.expressionStack,
3494 (this.expressionPtr -= length) + 1,
3495 typeDecl.annotations = new Annotation[length],
3499 typeDecl.bodyStart = typeDecl.sourceEnd + 1;
3500 pushOnAstStack(typeDecl);
3501 this.listLength = 0; // will be updated when reading super-interfaces
3503 if (this.currentElement != null){ // is recovering
3504 this.lastCheckPoint = typeDecl.bodyStart;
3505 this.currentElement = this.currentElement.add(typeDecl, 0);
3506 this.lastIgnoredToken = -1;
3509 typeDecl.javadoc = this.javadoc;
3510 this.javadoc = null;
3512 protected void consumeInterfaceMemberDeclarations() {
3513 // InterfaceMemberDeclarations ::= InterfaceMemberDeclarations InterfaceMemberDeclaration
3516 protected void consumeInterfaceMemberDeclarationsopt() {
3517 // InterfaceMemberDeclarationsopt ::= NestedType InterfaceMemberDeclarations
3520 protected void consumeInterfaceType() {
3521 // InterfaceType ::= ClassOrInterfaceType
3522 pushOnAstStack(getTypeReference(0));
3523 /* if incomplete type header, this.listLength counter will not have been reset,
3524 indicating that some interfaces are available on the stack */
3527 protected void consumeInterfaceTypeList() {
3528 // InterfaceTypeList ::= InterfaceTypeList ',' InterfaceType
3529 optimizedConcatNodeLists();
3531 protected void consumeInternalCompilationUnit() {
3532 // InternalCompilationUnit ::= PackageDeclaration
3533 // InternalCompilationUnit ::= PackageDeclaration ImportDeclarations ReduceImports
3534 // InternalCompilationUnit ::= ImportDeclarations ReduceImports
3536 protected void consumeInternalCompilationUnitWithTypes() {
3537 // InternalCompilationUnit ::= PackageDeclaration ImportDeclarations ReduceImports TypeDeclarations
3538 // InternalCompilationUnit ::= PackageDeclaration TypeDeclarations
3539 // InternalCompilationUnit ::= TypeDeclarations
3540 // InternalCompilationUnit ::= ImportDeclarations ReduceImports TypeDeclarations
3541 // consume type declarations
3543 if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) {
3544 this.astPtr -= length;
3545 System.arraycopy(this.astStack, this.astPtr + 1, this.compilationUnit.types = new TypeDeclaration[length], 0, length);
3548 protected void consumeInvalidConstructorDeclaration() {
3549 // ConstructorDeclaration ::= ConstructorHeader ';'
3550 // now we know that the top of stack is a constructorDeclaration
3551 ConstructorDeclaration cd = (ConstructorDeclaration) this.astStack[this.astPtr];
3553 cd.bodyEnd = this.endPosition; // position just before the trailing semi-colon
3554 cd.declarationSourceEnd = flushCommentsDefinedPriorTo(this.endStatementPosition);
3555 // report the problem and continue the parsing - narrowing the problem onto the method
3557 cd.modifiers |= AccSemicolonBody; // remember semi-colon body
3559 protected void consumeLeftParen() {
3560 // PushLPAREN ::= '('
3561 pushOnIntStack(this.lParenPos);
3563 protected void consumeLocalVariableDeclaration() {
3564 // LocalVariableDeclaration ::= Modifiers Type VariableDeclarators ';'
3568 this.expressionStack: Expression Expression ...... Expression
3569 this.identifierStack : type identifier identifier ...... identifier
3570 this.intStack : typeDim dim dim dim
3572 this.astStack : FieldDeclaration FieldDeclaration ...... FieldDeclaration
3573 this.expressionStack :
3574 this.identifierStack :
3578 int variableDeclaratorsCounter = this.astLengthStack[this.astLengthPtr];
3580 // update the this.astStack, this.astPtr and this.astLengthStack
3581 int startIndex = this.astPtr - this.variablesCounter[this.nestedType] + 1;
3587 variableDeclaratorsCounter);
3588 this.astPtr--; // remove the type reference
3589 this.astLengthStack[--this.astLengthPtr] = variableDeclaratorsCounter;
3590 this.variablesCounter[this.nestedType] = 0;
3592 protected void consumeLocalVariableDeclarationStatement() {
3593 // LocalVariableDeclarationStatement ::= LocalVariableDeclaration ';'
3594 // see blockReal in case of change: duplicated code
3595 // increment the amount of declared variables for this block
3596 this.realBlockStack[this.realBlockPtr]++;
3598 // update source end to include the semi-colon
3599 int variableDeclaratorsCounter = this.astLengthStack[this.astLengthPtr];
3600 for (int i = variableDeclaratorsCounter - 1; i >= 0; i--) {
3601 LocalDeclaration localDeclaration = (LocalDeclaration) this.astStack[this.astPtr - i];
3602 localDeclaration.declarationSourceEnd = this.endStatementPosition;
3603 localDeclaration.declarationEnd = this.endStatementPosition; // semi-colon included
3607 protected void consumeMarkerAnnotation() {
3608 // MarkerAnnotation ::= '@' Name
3609 MarkerAnnotation markerAnnotation = null;
3610 int length = this.identifierLengthStack[this.identifierLengthPtr--];
3611 TypeReference typeReference;
3613 typeReference = new SingleTypeReference(
3614 this.identifierStack[this.identifierPtr],
3615 this.identifierPositionStack[this.identifierPtr--]);
3617 char[][] tokens = new char[length][];
3618 this.identifierPtr -= length;
3619 long[] positions = new long[length];
3620 System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
3622 this.identifierPositionStack,
3623 this.identifierPtr + 1,
3627 typeReference = new QualifiedTypeReference(tokens, positions);
3629 markerAnnotation = new MarkerAnnotation(typeReference, this.intStack[this.intPtr--]);
3630 int sourceStart = markerAnnotation.sourceStart;
3631 if (this.modifiersSourceStart < 0) {
3632 this.modifiersSourceStart = sourceStart;
3633 } else if (this.modifiersSourceStart > sourceStart) {
3634 this.modifiersSourceStart = sourceStart;
3636 markerAnnotation.declarationSourceEnd = markerAnnotation.sourceEnd;
3637 pushOnExpressionStack(markerAnnotation);
3638 if(options.sourceLevel < ClassFileConstants.JDK1_5 &&
3639 this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
3640 this.problemReporter().invalidUsageOfAnnotation(markerAnnotation);
3643 protected void consumeMemberValueArrayInitializer() {
3644 // MemberValueArrayInitializer ::= '{' MemberValues ',' '}'
3645 // MemberValueArrayInitializer ::= '{' MemberValues '}'
3646 arrayInitializer(this.expressionLengthStack[this.expressionLengthPtr--]);
3648 protected void consumeMemberValueAsName() {
3649 pushOnExpressionStack(getUnspecifiedReferenceOptimized());
3651 protected void consumeMemberValuePair() {
3652 // MemberValuePair ::= SimpleName '=' MemberValue
3653 char[] simpleName = this.identifierStack[this.identifierPtr];
3654 long position = this.identifierPositionStack[this.identifierPtr--];
3655 this.identifierLengthPtr--;
3656 int end = (int) position;
3657 int start = (int) (position >>> 32);
3658 Expression value = this.expressionStack[this.expressionPtr--];
3659 this.expressionLengthPtr--;
3660 MemberValuePair memberValuePair = new MemberValuePair(simpleName, start, end, value);
3661 pushOnAstStack(memberValuePair);
3663 protected void consumeMemberValuePairs() {
3664 // MemberValuePairs ::= MemberValuePairs ',' MemberValuePair
3667 protected void consumeMemberValues() {
3668 // MemberValues ::= MemberValues ',' MemberValue
3669 concatExpressionLists();
3671 protected void consumeMethodBody() {
3672 // MethodBody ::= NestedMethod '{' BlockStatementsopt '}'
3673 this.nestedMethod[this.nestedType] --;
3675 protected void consumeMethodDeclaration(boolean isNotAbstract) {
3676 // MethodDeclaration ::= MethodHeader MethodBody
3677 // AbstractMethodDeclaration ::= MethodHeader ';'
3680 this.astStack : modifiers arguments throws statements
3681 this.identifierStack : type name
3682 this.intStack : dim dim dim
3684 this.astStack : MethodDeclaration
3685 this.identifierStack :
3690 if (isNotAbstract) {
3691 // pop the position of the { (body of the method) pushed in block decl
3696 int explicitDeclarations = 0;
3697 Statement[] statements = null;
3698 if (isNotAbstract) {
3700 explicitDeclarations = this.realBlockStack[this.realBlockPtr--];
3701 if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) {
3704 (this.astPtr -= length) + 1,
3705 statements = new Statement[length],
3711 // now we know that we have a method declaration at the top of the ast stack
3712 MethodDeclaration md = (MethodDeclaration) this.astStack[this.astPtr];
3713 md.statements = statements;
3714 md.explicitDeclarations = explicitDeclarations;
3716 // cannot be done in consumeMethodHeader because we have no idea whether or not there
3717 // is a body when we reduce the method header
3718 if (!isNotAbstract) { //remember the fact that the method has a semicolon body
3719 md.modifiers |= AccSemicolonBody;
3721 if (!this.diet && statements == null) {
3722 if (!containsComment(md.bodyStart, this.endPosition)) {
3723 md.bits |= ASTNode.UndocumentedEmptyBlockMASK;
3727 // store the this.endPosition (position just before the '}') in case there is
3728 // a trailing comment behind the end of the method
3729 md.bodyEnd = this.endPosition;
3730 md.declarationSourceEnd = flushCommentsDefinedPriorTo(this.endStatementPosition);
3732 protected void consumeMethodHeader() {
3733 // MethodHeader ::= MethodHeaderName MethodHeaderParameters MethodHeaderExtendedDims ThrowsClauseopt
3734 // AnnotationMethodHeader ::= AnnotationMethodHeaderName FormalParameterListopt MethodHeaderRightParen MethodHeaderExtendedDims AnnotationMethodHeaderDefaultValueopt
3735 // RecoveryMethodHeader ::= RecoveryMethodHeaderName FormalParameterListopt MethodHeaderRightParen MethodHeaderExtendedDims AnnotationMethodHeaderDefaultValueopt
3736 // RecoveryMethodHeader ::= RecoveryMethodHeaderName FormalParameterListopt MethodHeaderRightParen MethodHeaderExtendedDims MethodHeaderThrowsClause
3738 // retrieve end position of method declarator
3739 AbstractMethodDeclaration method = (AbstractMethodDeclaration)this.astStack[this.astPtr];
3741 if (this.currentToken == TokenNameLBRACE){
3742 method.bodyStart = this.scanner.currentPosition;
3745 if (this.currentElement != null){
3746 // if(method.isAnnotationMethod()) {
3747 // method.modifiers |= AccSemicolonBody;
3748 // method.declarationSourceEnd = this.scanner.currentPosition-1;
3749 // method.bodyEnd = this.scanner.currentPosition-1;
3750 // this.currentElement = this.currentElement.parent;
3752 if (this.currentToken == TokenNameSEMICOLON /*&& !method.isAnnotationMethod()*/){
3753 method.modifiers |= AccSemicolonBody;
3754 method.declarationSourceEnd = this.scanner.currentPosition-1;
3755 method.bodyEnd = this.scanner.currentPosition-1;
3756 if (this.currentElement.parseTree() == method && this.currentElement.parent != null) {
3757 this.currentElement = this.currentElement.parent;
3760 this.restartRecovery = true; // used to avoid branching back into the regular automaton
3763 protected void consumeMethodHeaderDefaultValue() {
3764 // MethodHeaderDefaultValue ::= DefaultValue
3765 MethodDeclaration md = (MethodDeclaration) this.astStack[this.astPtr];
3768 int length = this.expressionLengthStack[this.expressionLengthPtr--];
3770 intPtr--; // we get rid of the position of the default keyword
3771 intPtr--; // we get rid of the position of the default keyword
3772 if(md.isAnnotationMethod()) {
3773 ((AnnotationMethodDeclaration)md).defaultValue = this.expressionStack[this.expressionPtr];
3774 md.modifiers |= AccAnnotationDefault;
3776 this.expressionPtr--;
3779 if(this.currentElement != null) {
3780 if(md.isAnnotationMethod()) {
3781 this.currentElement.updateSourceEndIfNecessary(((AnnotationMethodDeclaration)md).defaultValue.sourceEnd);
3785 protected void consumeMethodHeaderExtendedDims() {
3786 // MethodHeaderExtendedDims ::= Dimsopt
3787 // now we update the returnType of the method
3788 MethodDeclaration md = (MethodDeclaration) this.astStack[this.astPtr];
3789 int extendedDims = this.intStack[this.intPtr--];
3790 if(md.isAnnotationMethod()) {
3791 ((AnnotationMethodDeclaration)md).extendedDimensions = extendedDims;
3793 if (extendedDims != 0) {
3794 TypeReference returnType = md.returnType;
3795 md.sourceEnd = this.endPosition;
3796 int dims = returnType.dimensions() + extendedDims;
3798 if ((baseType = this.identifierLengthStack[this.identifierLengthPtr + 1]) < 0) {
3800 int sourceStart = returnType.sourceStart;
3801 int sourceEnd = returnType.sourceEnd;
3802 returnType = TypeReference.baseTypeReference(-baseType, dims);
3803 returnType.sourceStart = sourceStart;
3804 returnType.sourceEnd = sourceEnd;
3805 md.returnType = returnType;
3807 md.returnType = this.copyDims(md.returnType, dims);
3809 if (this.currentToken == TokenNameLBRACE){
3810 md.bodyStart = this.endPosition + 1;
3813 if (this.currentElement != null){
3814 this.lastCheckPoint = md.bodyStart;
3818 protected void consumeMethodHeaderName(boolean isAnnotationMethod) {
3819 // MethodHeaderName ::= Modifiersopt Type 'Identifier' '('
3820 // AnnotationMethodHeaderName ::= Modifiersopt Type 'Identifier' '('
3821 // RecoveryMethodHeaderName ::= Modifiersopt Type 'Identifier' '('
3822 MethodDeclaration md = null;
3823 if(isAnnotationMethod) {
3824 md = new AnnotationMethodDeclaration(this.compilationUnit.compilationResult);
3826 md = new MethodDeclaration(this.compilationUnit.compilationResult);
3830 md.selector = this.identifierStack[this.identifierPtr];
3831 long selectorSource = this.identifierPositionStack[this.identifierPtr--];
3832 this.identifierLengthPtr--;
3834 md.returnType = getTypeReference(this.intStack[this.intPtr--]);
3836 md.declarationSourceStart = this.intStack[this.intPtr--];
3837 md.modifiers = this.intStack[this.intPtr--];
3838 // consume annotations
3840 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
3842 this.expressionStack,
3843 (this.expressionPtr -= length) + 1,
3844 md.annotations = new Annotation[length],
3849 md.javadoc = this.javadoc;
3850 this.javadoc = null;
3852 //highlight starts at selector start
3853 md.sourceStart = (int) (selectorSource >>> 32);
3855 md.sourceEnd = this.lParenPos;
3856 md.bodyStart = this.lParenPos+1;
3857 this.listLength = 0; // initialize this.listLength before reading parameters/throws
3860 if (this.currentElement != null){
3861 if (this.currentElement instanceof RecoveredType
3862 //|| md.modifiers != 0
3863 || (this.scanner.getLineNumber(md.returnType.sourceStart)
3864 == this.scanner.getLineNumber(md.sourceStart))){
3865 this.lastCheckPoint = md.bodyStart;
3866 this.currentElement = this.currentElement.add(md, 0);
3867 this.lastIgnoredToken = -1;
3869 this.lastCheckPoint = md.sourceStart;
3870 this.restartRecovery = true;
3874 protected void consumeMethodHeaderNameWithTypeParameters(boolean isAnnotationMethod) {
3875 // MethodHeaderName ::= Modifiersopt TypeParameters Type 'Identifier' '('
3876 // AnnotationMethodHeaderName ::= Modifiersopt TypeParameters Type 'Identifier' '('
3877 // RecoveryMethodHeaderName ::= Modifiersopt TypeParameters Type 'Identifier' '('
3878 MethodDeclaration md = null;
3879 if(isAnnotationMethod) {
3880 md = new AnnotationMethodDeclaration(this.compilationUnit.compilationResult);
3882 md = new MethodDeclaration(this.compilationUnit.compilationResult);
3886 md.selector = this.identifierStack[this.identifierPtr];
3887 long selectorSource = this.identifierPositionStack[this.identifierPtr--];
3888 this.identifierLengthPtr--;
3890 md.returnType = getTypeReference(this.intStack[this.intPtr--]);
3892 // consume type parameters
3893 int length = this.genericsLengthStack[this.genericsLengthPtr--];
3894 this.genericsPtr -= length;
3895 System.arraycopy(this.genericsStack, this.genericsPtr + 1, md.typeParameters = new TypeParameter[length], 0, length);
3898 md.declarationSourceStart = this.intStack[this.intPtr--];
3899 md.modifiers = this.intStack[this.intPtr--];
3900 // consume annotations
3901 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
3903 this.expressionStack,
3904 (this.expressionPtr -= length) + 1,
3905 md.annotations = new Annotation[length],
3910 md.javadoc = this.javadoc;
3911 this.javadoc = null;
3913 //highlight starts at selector start
3914 md.sourceStart = (int) (selectorSource >>> 32);
3916 md.sourceEnd = this.lParenPos;
3917 md.bodyStart = this.lParenPos+1;
3918 this.listLength = 0; // initialize this.listLength before reading parameters/throws
3921 if (this.currentElement != null){
3922 if (this.currentElement instanceof RecoveredType
3923 //|| md.modifiers != 0
3924 || (this.scanner.getLineNumber(md.returnType.sourceStart)
3925 == this.scanner.getLineNumber(md.sourceStart))){
3926 this.lastCheckPoint = md.bodyStart;
3927 this.currentElement = this.currentElement.add(md, 0);
3928 this.lastIgnoredToken = -1;
3930 this.lastCheckPoint = md.sourceStart;
3931 this.restartRecovery = true;
3935 protected void consumeMethodHeaderRightParen() {
3936 // MethodHeaderParameters ::= FormalParameterListopt ')'
3937 int length = this.astLengthStack[this.astLengthPtr--];
3938 this.astPtr -= length;
3939 AbstractMethodDeclaration md = (AbstractMethodDeclaration) this.astStack[this.astPtr];
3940 md.sourceEnd = this.rParenPos;
3946 md.arguments = new Argument[length],
3950 md.bodyStart = this.rParenPos+1;
3951 this.listLength = 0; // reset this.listLength after having read all parameters
3953 if (this.currentElement != null){
3954 this.lastCheckPoint = md.bodyStart;
3955 if (this.currentElement.parseTree() == md) return;
3957 // might not have been attached yet - in some constructor scenarii
3958 if (md.isConstructor()){
3960 || (this.currentToken == TokenNameLBRACE)
3961 || (this.currentToken == TokenNamethrows)){
3962 this.currentElement = this.currentElement.add(md, 0);
3963 this.lastIgnoredToken = -1;
3968 protected void consumeMethodHeaderThrowsClause() {
3969 // MethodHeaderThrowsClause ::= 'throws' ClassTypeList
3970 int length = this.astLengthStack[this.astLengthPtr--];
3971 this.astPtr -= length;
3972 AbstractMethodDeclaration md = (AbstractMethodDeclaration) this.astStack[this.astPtr];
3976 md.thrownExceptions = new TypeReference[length],
3979 md.sourceEnd = md.thrownExceptions[length-1].sourceEnd;
3980 md.bodyStart = md.thrownExceptions[length-1].sourceEnd + 1;
3981 this.listLength = 0; // reset this.listLength after having read all thrown exceptions
3983 if (this.currentElement != null){
3984 this.lastCheckPoint = md.bodyStart;
3987 protected void consumeMethodInvocationName() {
3988 // MethodInvocation ::= Name '(' ArgumentListopt ')'
3990 // when the name is only an identifier...we have a message send to "this" (implicit)
3992 MessageSend m = newMessageSend();
3993 m.sourceEnd = this.rParenPos;
3995 (int) ((m.nameSourcePosition = this.identifierPositionStack[this.identifierPtr]) >>> 32);
3996 m.selector = this.identifierStack[this.identifierPtr--];
3997 if (this.identifierLengthStack[this.identifierLengthPtr] == 1) {
3998 m.receiver = ThisReference.implicitThis();
3999 this.identifierLengthPtr--;
4001 this.identifierLengthStack[this.identifierLengthPtr]--;
4002 m.receiver = getUnspecifiedReference();
4003 m.sourceStart = m.receiver.sourceStart;
4005 pushOnExpressionStack(m);
4007 protected void consumeMethodInvocationNameWithTypeArguments() {
4008 // MethodInvocation ::= Name '.' TypeArguments 'Identifier' '(' ArgumentListopt ')'
4010 // when the name is only an identifier...we have a message send to "this" (implicit)
4012 MessageSend m = newMessageSendWithTypeArguments();
4013 m.sourceEnd = this.rParenPos;
4015 (int) ((m.nameSourcePosition = this.identifierPositionStack[this.identifierPtr]) >>> 32);
4016 m.selector = this.identifierStack[this.identifierPtr--];
4017 this.identifierLengthPtr--;
4019 // handle type arguments
4020 int length = this.genericsLengthStack[this.genericsLengthPtr--];
4021 this.genericsPtr -= length;
4022 System.arraycopy(this.genericsStack, this.genericsPtr + 1, m.typeArguments = new TypeReference[length], 0, length);
4025 m.receiver = getUnspecifiedReference();
4026 m.sourceStart = m.receiver.sourceStart;
4027 pushOnExpressionStack(m);
4029 protected void consumeMethodInvocationPrimary() {
4030 //optimize the push/pop
4031 //MethodInvocation ::= Primary '.' 'Identifier' '(' ArgumentListopt ')'
4033 MessageSend m = newMessageSend();
4035 (int) ((m.nameSourcePosition = this.identifierPositionStack[this.identifierPtr]) >>> 32);
4036 m.selector = this.identifierStack[this.identifierPtr--];
4037 this.identifierLengthPtr--;
4038 m.receiver = this.expressionStack[this.expressionPtr];
4039 m.sourceStart = m.receiver.sourceStart;
4040 m.sourceEnd = this.rParenPos;
4041 this.expressionStack[this.expressionPtr] = m;
4043 protected void consumeMethodInvocationPrimaryWithTypeArguments() {
4044 //optimize the push/pop
4045 //MethodInvocation ::= Primary '.' TypeArguments 'Identifier' '(' ArgumentListopt ')'
4047 MessageSend m = newMessageSendWithTypeArguments();
4049 (int) ((m.nameSourcePosition = this.identifierPositionStack[this.identifierPtr]) >>> 32);
4050 m.selector = this.identifierStack[this.identifierPtr--];
4051 this.identifierLengthPtr--;
4053 // handle type arguments
4054 int length = this.genericsLengthStack[this.genericsLengthPtr--];
4055 this.genericsPtr -= length;
4056 System.arraycopy(this.genericsStack, this.genericsPtr + 1, m.typeArguments = new TypeReference[length], 0, length);
4059 m.receiver = this.expressionStack[this.expressionPtr];
4060 m.sourceStart = m.receiver.sourceStart;
4061 m.sourceEnd = this.rParenPos;
4062 this.expressionStack[this.expressionPtr] = m;
4064 protected void consumeMethodInvocationSuper() {
4065 // MethodInvocation ::= 'super' '.' 'Identifier' '(' ArgumentListopt ')'
4067 MessageSend m = newMessageSend();
4068 m.sourceStart = this.intStack[this.intPtr--];
4069 m.sourceEnd = this.rParenPos;
4070 m.nameSourcePosition = this.identifierPositionStack[this.identifierPtr];
4071 m.selector = this.identifierStack[this.identifierPtr--];
4072 this.identifierLengthPtr--;
4073 m.receiver = new SuperReference(m.sourceStart, this.endPosition);
4074 pushOnExpressionStack(m);
4076 protected void consumeMethodInvocationSuperWithTypeArguments() {
4077 // MethodInvocation ::= 'super' '.' TypeArguments 'Identifier' '(' ArgumentListopt ')'
4079 MessageSend m = newMessageSendWithTypeArguments();
4080 m.sourceStart = this.intStack[this.intPtr--];
4081 m.sourceEnd = this.rParenPos;
4082 m.nameSourcePosition = this.identifierPositionStack[this.identifierPtr];
4083 m.selector = this.identifierStack[this.identifierPtr--];
4084 this.identifierLengthPtr--;
4086 // handle type arguments
4087 int length = this.genericsLengthStack[this.genericsLengthPtr--];
4088 this.genericsPtr -= length;
4089 System.arraycopy(this.genericsStack, this.genericsPtr + 1, m.typeArguments = new TypeReference[length], 0, length);
4092 m.receiver = new SuperReference(m.sourceStart, this.endPosition);
4093 pushOnExpressionStack(m);
4095 protected void consumeModifiers() {
4096 int savedModifiersSourceStart = this.modifiersSourceStart;
4097 checkComment(); // might update modifiers with AccDeprecated
4098 pushOnIntStack(this.modifiers); // modifiers
4099 if (this.modifiersSourceStart >= savedModifiersSourceStart) {
4100 this.modifiersSourceStart = savedModifiersSourceStart;
4102 pushOnIntStack(this.modifiersSourceStart);
4105 protected void consumeModifiers2() {
4106 this.expressionLengthStack[this.expressionLengthPtr - 1] += this.expressionLengthStack[this.expressionLengthPtr--];
4108 protected void consumeNameArrayType() {
4109 pushOnGenericsLengthStack(0); // handle type arguments
4110 pushOnGenericsIdentifiersLengthStack(this.identifierLengthStack[this.identifierLengthPtr]);
4112 protected void consumeNestedMethod() {
4113 // NestedMethod ::= $empty
4114 jumpOverMethodBody();
4115 this.nestedMethod[this.nestedType] ++;
4116 pushOnIntStack(this.scanner.currentPosition);
4119 protected void consumeNestedType() {
4120 // NestedType ::= $empty
4121 int length = this.nestedMethod.length;
4122 if (++this.nestedType >= length) {
4124 this.nestedMethod, 0,
4125 this.nestedMethod = new int[length + 30], 0,
4127 // increase the size of the variablesCounter as well. It has to be consistent with the size of the nestedMethod collection
4129 this.variablesCounter, 0,
4130 this.variablesCounter = new int[length + 30], 0,
4133 this.nestedMethod[this.nestedType] = 0;
4134 this.variablesCounter[this.nestedType] = 0;
4136 protected void consumeNormalAnnotation() {
4137 // NormalAnnotation ::= '@' Name '(' MemberValuePairsopt ')'
4138 NormalAnnotation normalAnnotation = null;
4139 int length = this.identifierLengthStack[this.identifierLengthPtr--];
4140 TypeReference typeReference;
4142 typeReference = new SingleTypeReference(
4143 this.identifierStack[this.identifierPtr],
4144 this.identifierPositionStack[this.identifierPtr--]);
4146 char[][] tokens = new char[length][];
4147 this.identifierPtr -= length;
4148 long[] positions = new long[length];
4149 System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
4151 this.identifierPositionStack,
4152 this.identifierPtr + 1,
4156 typeReference = new QualifiedTypeReference(tokens, positions);
4158 normalAnnotation = new NormalAnnotation(typeReference, this.intStack[this.intPtr--]);
4159 if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) {
4162 (this.astPtr -= length) + 1,
4163 normalAnnotation.memberValuePairs = new MemberValuePair[length],
4167 int sourceStart = normalAnnotation.sourceStart;
4168 if (this.modifiersSourceStart < 0) {
4169 this.modifiersSourceStart = sourceStart;
4170 } else if (this.modifiersSourceStart > sourceStart) {
4171 this.modifiersSourceStart = sourceStart;
4173 normalAnnotation.declarationSourceEnd = this.rParenPos;
4174 pushOnExpressionStack(normalAnnotation);
4175 if(options.sourceLevel < ClassFileConstants.JDK1_5 &&
4176 this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
4177 this.problemReporter().invalidUsageOfAnnotation(normalAnnotation);
4180 protected void consumeOneDimLoop() {
4181 // OneDimLoop ::= '[' ']'
4184 protected void consumeOnlySynchronized() {
4185 // OnlySynchronized ::= 'synchronized'
4186 pushOnIntStack(this.synchronizedBlockSourceStart);
4188 this.expressionLengthPtr--;
4190 protected void consumeOnlyTypeArguments() {
4191 if(options.sourceLevel < ClassFileConstants.JDK1_5 &&
4192 this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
4193 int length = this.genericsLengthStack[this.genericsLengthPtr];
4194 this.problemReporter().invalidUsageOfTypeArguments(
4195 (TypeReference)this.genericsStack[this.genericsPtr - length + 1],
4196 (TypeReference)this.genericsStack[this.genericsPtr]);
4199 protected void consumeOnlyTypeArgumentsForCastExpression() {
4200 // OnlyTypeArgumentsForCastExpression ::= OnlyTypeArguments
4202 protected void consumeOpenBlock() {
4203 // OpenBlock ::= $empty
4205 pushOnIntStack(this.scanner.startPosition);
4206 int stackLength = this.realBlockStack.length;
4207 if (++this.realBlockPtr >= stackLength) {
4209 this.realBlockStack, 0,
4210 this.realBlockStack = new int[stackLength + StackIncrement], 0,
4213 this.realBlockStack[this.realBlockPtr] = 0;
4215 protected void consumePackageDeclaration() {
4216 // PackageDeclaration ::= 'package' Name ';'
4217 /* build an ImportRef build from the last name
4218 stored in the identifier stack. */
4220 ImportReference impt = this.compilationUnit.currentPackage;
4221 // flush comments defined prior to import statements
4222 impt.declarationEnd = this.endStatementPosition;
4223 impt.declarationSourceEnd = this.flushCommentsDefinedPriorTo(impt.declarationSourceEnd);
4225 protected void consumePackageDeclarationName() {
4226 // PackageDeclarationName ::= 'package' Name
4227 /* build an ImportRef build from the last name
4228 stored in the identifier stack. */
4230 ImportReference impt;
4233 new char[length = this.identifierLengthStack[this.identifierLengthPtr--]][];
4234 this.identifierPtr -= length;
4235 long[] positions = new long[length];
4236 System.arraycopy(this.identifierStack, ++this.identifierPtr, tokens, 0, length);
4238 this.identifierPositionStack,
4239 this.identifierPtr--,
4244 impt = new ImportReference(tokens, positions, true, AccDefault);
4245 this.compilationUnit.currentPackage = impt;
4247 if (this.currentToken == TokenNameSEMICOLON){
4248 impt.declarationSourceEnd = this.scanner.currentPosition - 1;
4250 impt.declarationSourceEnd = impt.sourceEnd;
4252 impt.declarationEnd = impt.declarationSourceEnd;
4253 //this.endPosition is just before the ;
4254 impt.declarationSourceStart = this.intStack[this.intPtr--];
4257 if (this.currentElement != null){
4258 this.lastCheckPoint = impt.declarationSourceEnd+1;
4259 this.restartRecovery = true; // used to avoid branching back into the regular automaton
4262 protected void consumePackageDeclarationNameWithModifiers() {
4263 // PackageDeclarationName ::= Modifiers 'package' Name
4264 /* build an ImportRef build from the last name
4265 stored in the identifier stack. */
4267 ImportReference impt;
4270 new char[length = this.identifierLengthStack[this.identifierLengthPtr--]][];
4271 this.identifierPtr -= length;
4272 long[] positions = new long[length];
4273 System.arraycopy(this.identifierStack, ++this.identifierPtr, tokens, 0, length);
4275 this.identifierPositionStack,
4276 this.identifierPtr--,
4281 int packageModifiersSourceStart = this.intStack[this.intPtr--]; // we don't need the modifiers start
4282 int packageModifiers = this.intStack[this.intPtr--];
4284 impt = new ImportReference(tokens, positions, true, packageModifiers);
4285 this.compilationUnit.currentPackage = impt;
4286 // consume annotations
4287 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
4289 this.expressionStack,
4290 (this.expressionPtr -= length) + 1,
4291 impt.annotations = new Annotation[length],
4294 impt.declarationSourceStart = packageModifiersSourceStart;
4295 intPtr--; // we don't need the position of the 'package keyword
4297 impt.declarationSourceStart = this.intStack[this.intPtr--];
4300 if (this.currentToken == TokenNameSEMICOLON){
4301 impt.declarationSourceEnd = this.scanner.currentPosition - 1;
4303 impt.declarationSourceEnd = impt.sourceEnd;
4305 impt.declarationEnd = impt.declarationSourceEnd;
4308 if (this.currentElement != null){
4309 this.lastCheckPoint = impt.declarationSourceEnd+1;
4310 this.restartRecovery = true; // used to avoid branching back into the regular automaton
4313 protected void consumePostfixExpression() {
4314 // PostfixExpression ::= Name
4315 pushOnExpressionStack(getUnspecifiedReferenceOptimized());
4317 protected void consumePrimaryNoNewArray() {
4318 // PrimaryNoNewArray ::= PushLPAREN Expression PushRPAREN
4319 final Expression parenthesizedExpression = this.expressionStack[this.expressionPtr];
4320 updateSourcePosition(parenthesizedExpression);
4321 int numberOfParenthesis = (parenthesizedExpression.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT;
4322 parenthesizedExpression.bits &= ~ASTNode.ParenthesizedMASK;
4323 parenthesizedExpression.bits |= (numberOfParenthesis + 1) << ASTNode.ParenthesizedSHIFT;
4325 protected void consumePrimaryNoNewArrayArrayType() {
4326 // PrimaryNoNewArray ::= Name Dims '.' 'class'
4327 this.intPtr--; // remove the class start position
4329 pushOnGenericsIdentifiersLengthStack(this.identifierLengthStack[this.identifierLengthPtr]);
4330 pushOnGenericsLengthStack(0);
4332 pushOnExpressionStack(
4333 new ClassLiteralAccess(this.intStack[this.intPtr--], getTypeReference(this.intStack[this.intPtr--])));
4335 protected void consumePrimaryNoNewArrayName() {
4336 // PrimaryNoNewArray ::= Name '.' 'class'
4337 this.intPtr--; // remove the class start position
4339 // handle type arguments
4340 pushOnGenericsIdentifiersLengthStack(this.identifierLengthStack[this.identifierLengthPtr]);
4341 pushOnGenericsLengthStack(0);
4342 TypeReference typeReference = getTypeReference(0);
4344 pushOnExpressionStack(
4345 new ClassLiteralAccess(this.intStack[this.intPtr--], typeReference));
4347 protected void consumePrimaryNoNewArrayNameSuper() {
4348 // PrimaryNoNewArray ::= Name '.' 'super'
4349 // handle type arguments
4350 pushOnGenericsIdentifiersLengthStack(this.identifierLengthStack[this.identifierLengthPtr]);
4351 pushOnGenericsLengthStack(0);
4352 TypeReference typeReference = getTypeReference(0);
4354 pushOnExpressionStack(
4355 new QualifiedSuperReference(
4357 this.intStack[this.intPtr--],
4360 protected void consumePrimaryNoNewArrayNameThis() {
4361 // PrimaryNoNewArray ::= Name '.' 'this'
4362 // handle type arguments
4363 pushOnGenericsIdentifiersLengthStack(this.identifierLengthStack[this.identifierLengthPtr]);
4364 pushOnGenericsLengthStack(0); // handle type arguments
4366 TypeReference typeReference = getTypeReference(0);
4368 pushOnExpressionStack(
4369 new QualifiedThisReference(
4371 this.intStack[this.intPtr--],
4374 protected void consumePrimaryNoNewArrayPrimitiveArrayType() {
4375 // PrimaryNoNewArray ::= PrimitiveType Dims '.' 'class'
4376 this.intPtr--; // remove the class start position
4377 pushOnExpressionStack(
4378 new ClassLiteralAccess(this.intStack[this.intPtr--], getTypeReference(this.intStack[this.intPtr--])));
4380 protected void consumePrimaryNoNewArrayPrimitiveType() {
4381 // PrimaryNoNewArray ::= PrimitiveType '.' 'class'
4382 this.intPtr--; // remove the class start position
4383 pushOnExpressionStack(
4384 new ClassLiteralAccess(this.intStack[this.intPtr--], getTypeReference(0)));
4386 protected void consumePrimaryNoNewArrayThis() {
4387 // PrimaryNoNewArray ::= 'this'
4388 pushOnExpressionStack(new ThisReference(this.intStack[this.intPtr--], this.endPosition));
4390 protected void consumePrimaryNoNewArrayWithName() {
4391 // PrimaryNoNewArray ::= PushLPAREN Expression PushRPAREN
4392 pushOnExpressionStack(getUnspecifiedReferenceOptimized());
4393 final Expression parenthesizedExpression = this.expressionStack[this.expressionPtr];
4394 updateSourcePosition(parenthesizedExpression);
4395 int numberOfParenthesis = (parenthesizedExpression.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT;
4396 parenthesizedExpression.bits &= ~ASTNode.ParenthesizedMASK;
4397 parenthesizedExpression.bits |= (numberOfParenthesis + 1) << ASTNode.ParenthesizedSHIFT;
4399 protected void consumePrimitiveArrayType() {
4401 // Will be consume by a getTypeRefence call
4403 protected void consumePrimitiveType() {
4404 // Type ::= PrimitiveType
4407 protected void consumePushLeftBrace() {
4408 pushOnIntStack(this.endPosition); // modifiers
4410 protected void consumePushRealModifiers() {
4411 checkComment(); // might update modifiers with AccDeprecated
4412 pushOnIntStack(this.modifiers); // modifiers
4413 pushOnIntStack(this.modifiersSourceStart);
4416 protected void consumePushModifiers() {
4417 pushOnIntStack(this.modifiers); // modifiers
4418 pushOnIntStack(this.modifiersSourceStart);
4420 pushOnExpressionStackLengthStack(0);
4422 protected void consumePushModifiersForHeader() {
4423 checkComment(); // might update modifiers with AccDeprecated
4424 pushOnIntStack(this.modifiers); // modifiers
4425 pushOnIntStack(this.modifiersSourceStart);
4427 pushOnExpressionStackLengthStack(0);
4429 protected void consumePushPosition() {
4430 // for source managment purpose
4431 // PushPosition ::= $empty
4432 pushOnIntStack(this.endPosition);
4434 protected void consumeQualifiedName() {
4435 // QualifiedName ::= Name '.' SimpleName
4436 /*back from the recursive loop of QualifiedName.
4437 Updates identifier length into the length stack*/
4439 this.identifierLengthStack[--this.identifierLengthPtr]++;
4441 protected void consumeRecoveryMethodHeaderName() {
4442 // this method is call only inside recovery
4443 boolean isAnnotationMethod = false;
4444 if(this.currentElement instanceof RecoveredType) {
4445 isAnnotationMethod = (((RecoveredType)this.currentElement).typeDeclaration.modifiers & AccAnnotation) != 0;
4447 RecoveredType recoveredType = this.currentElement.enclosingType();
4448 if(recoveredType != null) {
4449 isAnnotationMethod = (recoveredType.typeDeclaration.modifiers & AccAnnotation) != 0;
4452 this.consumeMethodHeaderName(isAnnotationMethod);
4454 protected void consumeRecoveryMethodHeaderNameWithTypeParameters() {
4455 // this method is call only inside recovery
4456 boolean isAnnotationMethod = false;
4457 if(this.currentElement instanceof RecoveredType) {
4458 isAnnotationMethod = (((RecoveredType)this.currentElement).typeDeclaration.modifiers & AccAnnotation) != 0;
4460 RecoveredType recoveredType = this.currentElement.enclosingType();
4461 if(recoveredType != null) {
4462 isAnnotationMethod = (recoveredType.typeDeclaration.modifiers & AccAnnotation) != 0;
4465 this.consumeMethodHeaderNameWithTypeParameters(isAnnotationMethod);
4467 protected void consumeReduceImports() {
4470 if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) {
4471 this.astPtr -= length;
4475 this.compilationUnit.imports = new ImportReference[length],
4480 protected void consumeReferenceType() {
4481 pushOnIntStack(0); // handle array type
4483 protected void consumeReferenceType1() {
4484 pushOnGenericsStack(getTypeReference(this.intStack[this.intPtr--]));
4486 protected void consumeReferenceType2() {
4487 pushOnGenericsStack(getTypeReference(this.intStack[this.intPtr--]));
4489 protected void consumeReferenceType3() {
4490 pushOnGenericsStack(getTypeReference(this.intStack[this.intPtr--]));
4492 protected void consumeRestoreDiet() {
4493 // RestoreDiet ::= $empty
4496 protected void consumeRightParen() {
4497 // PushRPAREN ::= ')'
4498 pushOnIntStack(this.rParenPos);
4500 // This method is part of an automatic generation : do NOT edit-modify
4501 protected void consumeRule(int act) {
4503 case 29 : if (DEBUG) { System.out.println("Type ::= PrimitiveType"); } //$NON-NLS-1$
4504 consumePrimitiveType();
4507 case 43 : if (DEBUG) { System.out.println("ReferenceType ::= ClassOrInterfaceType"); } //$NON-NLS-1$
4508 consumeReferenceType();
4511 case 47 : if (DEBUG) { System.out.println("ClassOrInterface ::= Name"); } //$NON-NLS-1$
4512 consumeClassOrInterfaceName();
4515 case 48 : if (DEBUG) { System.out.println("ClassOrInterface ::= GenericType DOT Name"); } //$NON-NLS-1$
4516 consumeClassOrInterface();
4519 case 49 : if (DEBUG) { System.out.println("GenericType ::= ClassOrInterface TypeArguments"); } //$NON-NLS-1$
4520 consumeGenericType();
4523 case 50 : if (DEBUG) { System.out.println("ArrayTypeWithTypeArgumentsName ::= GenericType DOT Name"); } //$NON-NLS-1$
4524 consumeArrayTypeWithTypeArgumentsName();
4527 case 51 : if (DEBUG) { System.out.println("ArrayType ::= PrimitiveType Dims"); } //$NON-NLS-1$
4528 consumePrimitiveArrayType();
4531 case 52 : if (DEBUG) { System.out.println("ArrayType ::= Name Dims"); } //$NON-NLS-1$
4532 consumeNameArrayType();
4535 case 53 : if (DEBUG) { System.out.println("ArrayType ::= ArrayTypeWithTypeArgumentsName Dims"); } //$NON-NLS-1$
4536 consumeGenericTypeNameArrayType();
4539 case 54 : if (DEBUG) { System.out.println("ArrayType ::= GenericType Dims"); } //$NON-NLS-1$
4540 consumeGenericTypeArrayType();
4543 case 59 : if (DEBUG) { System.out.println("QualifiedName ::= Name DOT SimpleName"); } //$NON-NLS-1$
4544 consumeQualifiedName();
4547 case 60 : if (DEBUG) { System.out.println("CompilationUnit ::= EnterCompilationUnit..."); } //$NON-NLS-1$
4548 consumeCompilationUnit();
4551 case 61 : if (DEBUG) { System.out.println("InternalCompilationUnit ::= PackageDeclaration"); } //$NON-NLS-1$
4552 consumeInternalCompilationUnit();
4555 case 62 : if (DEBUG) { System.out.println("InternalCompilationUnit ::= PackageDeclaration..."); } //$NON-NLS-1$
4556 consumeInternalCompilationUnit();
4559 case 63 : if (DEBUG) { System.out.println("InternalCompilationUnit ::= PackageDeclaration..."); } //$NON-NLS-1$
4560 consumeInternalCompilationUnitWithTypes();
4563 case 64 : if (DEBUG) { System.out.println("InternalCompilationUnit ::= PackageDeclaration..."); } //$NON-NLS-1$
4564 consumeInternalCompilationUnitWithTypes();
4567 case 65 : if (DEBUG) { System.out.println("InternalCompilationUnit ::= ImportDeclarations..."); } //$NON-NLS-1$
4568 consumeInternalCompilationUnit();
4571 case 66 : if (DEBUG) { System.out.println("InternalCompilationUnit ::= TypeDeclarations"); } //$NON-NLS-1$
4572 consumeInternalCompilationUnitWithTypes();
4575 case 67 : if (DEBUG) { System.out.println("InternalCompilationUnit ::= ImportDeclarations..."); } //$NON-NLS-1$
4576 consumeInternalCompilationUnitWithTypes();
4579 case 68 : if (DEBUG) { System.out.println("InternalCompilationUnit ::="); } //$NON-NLS-1$
4580 consumeEmptyInternalCompilationUnit();
4583 case 69 : if (DEBUG) { System.out.println("ReduceImports ::="); } //$NON-NLS-1$
4584 consumeReduceImports();
4587 case 70 : if (DEBUG) { System.out.println("EnterCompilationUnit ::="); } //$NON-NLS-1$
4588 consumeEnterCompilationUnit();
4591 case 86 : if (DEBUG) { System.out.println("CatchHeader ::= catch LPAREN FormalParameter RPAREN..."); } //$NON-NLS-1$
4592 consumeCatchHeader();
4595 case 88 : if (DEBUG) { System.out.println("ImportDeclarations ::= ImportDeclarations..."); } //$NON-NLS-1$
4596 consumeImportDeclarations();
4599 case 90 : if (DEBUG) { System.out.println("TypeDeclarations ::= TypeDeclarations TypeDeclaration"); } //$NON-NLS-1$
4600 consumeTypeDeclarations();
4603 case 91 : if (DEBUG) { System.out.println("PackageDeclaration ::= PackageDeclarationName SEMICOLON"); } //$NON-NLS-1$
4604 consumePackageDeclaration();
4607 case 92 : if (DEBUG) { System.out.println("PackageDeclarationName ::= Modifiers package..."); } //$NON-NLS-1$
4608 consumePackageDeclarationNameWithModifiers();
4611 case 93 : if (DEBUG) { System.out.println("PackageDeclarationName ::= package Name"); } //$NON-NLS-1$
4612 consumePackageDeclarationName();
4615 case 98 : if (DEBUG) { System.out.println("SingleTypeImportDeclaration ::=..."); } //$NON-NLS-1$
4616 consumeImportDeclaration();
4619 case 99 : if (DEBUG) { System.out.println("SingleTypeImportDeclarationName ::= import Name"); } //$NON-NLS-1$
4620 consumeSingleTypeImportDeclarationName();
4623 case 100 : if (DEBUG) { System.out.println("TypeImportOnDemandDeclaration ::=..."); } //$NON-NLS-1$
4624 consumeImportDeclaration();
4627 case 101 : if (DEBUG) { System.out.println("TypeImportOnDemandDeclarationName ::= import Name DOT..."); } //$NON-NLS-1$
4628 consumeTypeImportOnDemandDeclarationName();
4631 case 104 : if (DEBUG) { System.out.println("TypeDeclaration ::= SEMICOLON"); } //$NON-NLS-1$
4632 consumeEmptyTypeDeclaration();
4635 case 108 : if (DEBUG) { System.out.println("Modifiers ::= Modifiers Modifier"); } //$NON-NLS-1$
4636 consumeModifiers2();
4639 case 120 : if (DEBUG) { System.out.println("Modifier ::= Annotation"); } //$NON-NLS-1$
4640 consumeAnnotationAsModifier();
4643 case 121 : if (DEBUG) { System.out.println("ClassDeclaration ::= ClassHeader ClassBody"); } //$NON-NLS-1$
4644 consumeClassDeclaration();
4647 case 122 : if (DEBUG) { System.out.println("ClassHeader ::= ClassHeaderName ClassHeaderExtendsopt..."); } //$NON-NLS-1$
4648 consumeClassHeader();
4651 case 123 : if (DEBUG) { System.out.println("ClassHeaderName ::= ClassHeaderName1 TypeParameters"); } //$NON-NLS-1$
4652 consumeTypeHeaderNameWithTypeParameters();
4655 case 125 : if (DEBUG) { System.out.println("ClassHeaderName1 ::= Modifiersopt class Identifier"); } //$NON-NLS-1$
4656 consumeClassHeaderName1();
4659 case 126 : if (DEBUG) { System.out.println("ClassHeaderExtends ::= extends ClassType"); } //$NON-NLS-1$
4660 consumeClassHeaderExtends();
4663 case 127 : if (DEBUG) { System.out.println("ClassHeaderImplements ::= implements InterfaceTypeList"); } //$NON-NLS-1$
4664 consumeClassHeaderImplements();
4667 case 129 : if (DEBUG) { System.out.println("InterfaceTypeList ::= InterfaceTypeList COMMA..."); } //$NON-NLS-1$
4668 consumeInterfaceTypeList();
4671 case 130 : if (DEBUG) { System.out.println("InterfaceType ::= ClassOrInterfaceType"); } //$NON-NLS-1$
4672 consumeInterfaceType();
4675 case 133 : if (DEBUG) { System.out.println("ClassBodyDeclarations ::= ClassBodyDeclarations..."); } //$NON-NLS-1$
4676 consumeClassBodyDeclarations();
4679 case 137 : if (DEBUG) { System.out.println("ClassBodyDeclaration ::= Diet NestedMethod Block"); } //$NON-NLS-1$
4680 consumeClassBodyDeclaration();
4683 case 138 : if (DEBUG) { System.out.println("Diet ::="); } //$NON-NLS-1$
4687 case 139 : if (DEBUG) { System.out.println("Initializer ::= Diet NestedMethod Block"); } //$NON-NLS-1$
4688 consumeClassBodyDeclaration();
4691 case 146 : if (DEBUG) { System.out.println("ClassMemberDeclaration ::= SEMICOLON"); } //$NON-NLS-1$
4692 consumeEmptyClassMemberDeclaration();
4695 case 149 : if (DEBUG) { System.out.println("FieldDeclaration ::= Modifiersopt Type..."); } //$NON-NLS-1$
4696 consumeFieldDeclaration();
4699 case 151 : if (DEBUG) { System.out.println("VariableDeclarators ::= VariableDeclarators COMMA..."); } //$NON-NLS-1$
4700 consumeVariableDeclarators();
4703 case 154 : if (DEBUG) { System.out.println("EnterVariable ::="); } //$NON-NLS-1$
4704 consumeEnterVariable();
4707 case 155 : if (DEBUG) { System.out.println("ExitVariableWithInitialization ::="); } //$NON-NLS-1$
4708 consumeExitVariableWithInitialization();
4711 case 156 : if (DEBUG) { System.out.println("ExitVariableWithoutInitialization ::="); } //$NON-NLS-1$
4712 consumeExitVariableWithoutInitialization();
4715 case 157 : if (DEBUG) { System.out.println("ForceNoDiet ::="); } //$NON-NLS-1$
4716 consumeForceNoDiet();
4719 case 158 : if (DEBUG) { System.out.println("RestoreDiet ::="); } //$NON-NLS-1$
4720 consumeRestoreDiet();
4723 case 163 : if (DEBUG) { System.out.println("MethodDeclaration ::= MethodHeader MethodBody"); } //$NON-NLS-1$
4724 // set to true to consume a method with a body
4725 consumeMethodDeclaration(true);
4728 case 164 : if (DEBUG) { System.out.println("AbstractMethodDeclaration ::= MethodHeader SEMICOLON"); } //$NON-NLS-1$
4729 // set to false to consume a method without body
4730 consumeMethodDeclaration(false);
4733 case 165 : if (DEBUG) { System.out.println("MethodHeader ::= MethodHeaderName FormalParameterListopt"); } //$NON-NLS-1$
4734 consumeMethodHeader();
4737 case 166 : if (DEBUG) { System.out.println("MethodHeaderName ::= Modifiersopt TypeParameters Type..."); } //$NON-NLS-1$
4738 consumeMethodHeaderNameWithTypeParameters(false);
4741 case 167 : if (DEBUG) { System.out.println("MethodHeaderName ::= Modifiersopt Type Identifier LPAREN"); } //$NON-NLS-1$
4742 consumeMethodHeaderName(false);
4745 case 168 : if (DEBUG) { System.out.println("MethodHeaderRightParen ::= RPAREN"); } //$NON-NLS-1$
4746 consumeMethodHeaderRightParen();
4749 case 169 : if (DEBUG) { System.out.println("MethodHeaderExtendedDims ::= Dimsopt"); } //$NON-NLS-1$
4750 consumeMethodHeaderExtendedDims();
4753 case 170 : if (DEBUG) { System.out.println("MethodHeaderThrowsClause ::= throws ClassTypeList"); } //$NON-NLS-1$
4754 consumeMethodHeaderThrowsClause();
4757 case 171 : if (DEBUG) { System.out.println("ConstructorHeader ::= ConstructorHeaderName..."); } //$NON-NLS-1$
4758 consumeConstructorHeader();
4761 case 172 : if (DEBUG) { System.out.println("ConstructorHeaderName ::= Modifiersopt TypeParameters..."); } //$NON-NLS-1$
4762 consumeConstructorHeaderNameWithTypeParameters();
4765 case 173 : if (DEBUG) { System.out.println("ConstructorHeaderName ::= Modifiersopt Identifier LPAREN"); } //$NON-NLS-1$
4766 consumeConstructorHeaderName();
4769 case 175 : if (DEBUG) { System.out.println("FormalParameterList ::= FormalParameterList COMMA..."); } //$NON-NLS-1$
4770 consumeFormalParameterList();
4773 case 176 : if (DEBUG) { System.out.println("FormalParameter ::= Modifiersopt Type..."); } //$NON-NLS-1$
4774 consumeFormalParameter(false);
4777 case 177 : if (DEBUG) { System.out.println("FormalParameter ::= Modifiersopt Type ELLIPSIS..."); } //$NON-NLS-1$
4778 consumeFormalParameter(true);
4781 case 179 : if (DEBUG) { System.out.println("ClassTypeList ::= ClassTypeList COMMA ClassTypeElt"); } //$NON-NLS-1$
4782 consumeClassTypeList();
4785 case 180 : if (DEBUG) { System.out.println("ClassTypeElt ::= ClassType"); } //$NON-NLS-1$
4786 consumeClassTypeElt();
4789 case 181 : if (DEBUG) { System.out.println("MethodBody ::= NestedMethod LBRACE BlockStatementsopt..."); } //$NON-NLS-1$
4790 consumeMethodBody();
4793 case 182 : if (DEBUG) { System.out.println("NestedMethod ::="); } //$NON-NLS-1$
4794 consumeNestedMethod();
4797 case 183 : if (DEBUG) { System.out.println("StaticInitializer ::= StaticOnly Block"); } //$NON-NLS-1$
4798 consumeStaticInitializer();
4801 case 184 : if (DEBUG) { System.out.println("StaticOnly ::= static"); } //$NON-NLS-1$
4802 consumeStaticOnly();
4805 case 185 : if (DEBUG) { System.out.println("ConstructorDeclaration ::= ConstructorHeader MethodBody"); } //$NON-NLS-1$
4806 consumeConstructorDeclaration() ;
4809 case 186 : if (DEBUG) { System.out.println("ConstructorDeclaration ::= ConstructorHeader SEMICOLON"); } //$NON-NLS-1$
4810 consumeInvalidConstructorDeclaration() ;
4813 case 187 : if (DEBUG) { System.out.println("ExplicitConstructorInvocation ::= this LPAREN..."); } //$NON-NLS-1$
4814 consumeExplicitConstructorInvocation(0, THIS_CALL);
4817 case 188 : if (DEBUG) { System.out.println("ExplicitConstructorInvocation ::= OnlyTypeArguments this"); } //$NON-NLS-1$
4818 consumeExplicitConstructorInvocationWithTypeArguments(0,THIS_CALL);
4821 case 189 : if (DEBUG) { System.out.println("ExplicitConstructorInvocation ::= super LPAREN..."); } //$NON-NLS-1$
4822 consumeExplicitConstructorInvocation(0,SUPER_CALL);
4825 case 190 : if (DEBUG) { System.out.println("ExplicitConstructorInvocation ::= OnlyTypeArguments..."); } //$NON-NLS-1$
4826 consumeExplicitConstructorInvocationWithTypeArguments(0,SUPER_CALL);
4829 case 191 : if (DEBUG) { System.out.println("ExplicitConstructorInvocation ::= Primary DOT super..."); } //$NON-NLS-1$
4830 consumeExplicitConstructorInvocation(1, SUPER_CALL);
4833 case 192 : if (DEBUG) { System.out.println("ExplicitConstructorInvocation ::= Primary DOT..."); } //$NON-NLS-1$
4834 consumeExplicitConstructorInvocationWithTypeArguments(1, SUPER_CALL);
4837 case 193 : if (DEBUG) { System.out.println("ExplicitConstructorInvocation ::= Name DOT super LPAREN"); } //$NON-NLS-1$
4838 consumeExplicitConstructorInvocation(2, SUPER_CALL);
4841 case 194 : if (DEBUG) { System.out.println("ExplicitConstructorInvocation ::= Name DOT..."); } //$NON-NLS-1$
4842 consumeExplicitConstructorInvocationWithTypeArguments(2, SUPER_CALL);
4845 case 195 : if (DEBUG) { System.out.println("ExplicitConstructorInvocation ::= Primary DOT this..."); } //$NON-NLS-1$
4846 consumeExplicitConstructorInvocation(1, THIS_CALL);
4849 case 196 : if (DEBUG) { System.out.println("ExplicitConstructorInvocation ::= Primary DOT..."); } //$NON-NLS-1$
4850 consumeExplicitConstructorInvocationWithTypeArguments(1, THIS_CALL);
4853 case 197 : if (DEBUG) { System.out.println("ExplicitConstructorInvocation ::= Name DOT this LPAREN"); } //$NON-NLS-1$
4854 consumeExplicitConstructorInvocation(2, THIS_CALL);
4857 case 198 : if (DEBUG) { System.out.println("ExplicitConstructorInvocation ::= Name DOT..."); } //$NON-NLS-1$
4858 consumeExplicitConstructorInvocationWithTypeArguments(2, THIS_CALL);
4861 case 199 : if (DEBUG) { System.out.println("InterfaceDeclaration ::= InterfaceHeader InterfaceBody"); } //$NON-NLS-1$
4862 consumeInterfaceDeclaration();
4865 case 200 : if (DEBUG) { System.out.println("InterfaceHeader ::= InterfaceHeaderName..."); } //$NON-NLS-1$
4866 consumeInterfaceHeader();
4869 case 201 : if (DEBUG) { System.out.println("InterfaceHeaderName ::= InterfaceHeaderName1..."); } //$NON-NLS-1$
4870 consumeTypeHeaderNameWithTypeParameters();
4873 case 203 : if (DEBUG) { System.out.println("InterfaceHeaderName1 ::= Modifiersopt interface..."); } //$NON-NLS-1$
4874 consumeInterfaceHeaderName1();
4877 case 205 : if (DEBUG) { System.out.println("InterfaceHeaderExtends ::= extends InterfaceTypeList"); } //$NON-NLS-1$
4878 consumeInterfaceHeaderExtends();
4881 case 208 : if (DEBUG) { System.out.println("InterfaceMemberDeclarations ::=..."); } //$NON-NLS-1$
4882 consumeInterfaceMemberDeclarations();
4885 case 209 : if (DEBUG) { System.out.println("InterfaceMemberDeclaration ::= SEMICOLON"); } //$NON-NLS-1$
4886 consumeEmptyInterfaceMemberDeclaration();
4889 case 212 : if (DEBUG) { System.out.println("InterfaceMemberDeclaration ::= InvalidMethodDeclaration"); } //$NON-NLS-1$
4893 case 213 : if (DEBUG) { System.out.println("InvalidConstructorDeclaration ::= ConstructorHeader..."); } //$NON-NLS-1$
4894 ignoreInvalidConstructorDeclaration(true);
4897 case 214 : if (DEBUG) { System.out.println("InvalidConstructorDeclaration ::= ConstructorHeader..."); } //$NON-NLS-1$
4898 ignoreInvalidConstructorDeclaration(false);
4901 case 222 : if (DEBUG) { System.out.println("PushLeftBrace ::="); } //$NON-NLS-1$
4902 consumePushLeftBrace();
4905 case 223 : if (DEBUG) { System.out.println("ArrayInitializer ::= LBRACE PushLeftBrace ,opt RBRACE"); } //$NON-NLS-1$
4906 consumeEmptyArrayInitializer();
4909 case 224 : if (DEBUG) { System.out.println("ArrayInitializer ::= LBRACE PushLeftBrace..."); } //$NON-NLS-1$
4910 consumeArrayInitializer();
4913 case 225 : if (DEBUG) { System.out.println("ArrayInitializer ::= LBRACE PushLeftBrace..."); } //$NON-NLS-1$
4914 consumeArrayInitializer();
4917 case 227 : if (DEBUG) { System.out.println("VariableInitializers ::= VariableInitializers COMMA..."); } //$NON-NLS-1$
4918 consumeVariableInitializers();
4921 case 228 : if (DEBUG) { System.out.println("Block ::= OpenBlock LBRACE BlockStatementsopt RBRACE"); } //$NON-NLS-1$
4925 case 229 : if (DEBUG) { System.out.println("OpenBlock ::="); } //$NON-NLS-1$
4926 consumeOpenBlock() ;
4929 case 231 : if (DEBUG) { System.out.println("BlockStatements ::= BlockStatements BlockStatement"); } //$NON-NLS-1$
4930 consumeBlockStatements() ;
4933 case 235 : if (DEBUG) { System.out.println("BlockStatement ::= InvalidInterfaceDeclaration"); } //$NON-NLS-1$
4934 ignoreInterfaceDeclaration();
4937 case 236 : if (DEBUG) { System.out.println("LocalVariableDeclarationStatement ::=..."); } //$NON-NLS-1$
4938 consumeLocalVariableDeclarationStatement();
4941 case 237 : if (DEBUG) { System.out.println("LocalVariableDeclaration ::= Type PushModifiers..."); } //$NON-NLS-1$
4942 consumeLocalVariableDeclaration();
4945 case 238 : if (DEBUG) { System.out.println("LocalVariableDeclaration ::= Modifiers Type..."); } //$NON-NLS-1$
4946 consumeLocalVariableDeclaration();
4949 case 239 : if (DEBUG) { System.out.println("PushModifiers ::="); } //$NON-NLS-1$
4950 consumePushModifiers();
4953 case 240 : if (DEBUG) { System.out.println("PushModifiersForHeader ::="); } //$NON-NLS-1$
4954 consumePushModifiersForHeader();
4957 case 241 : if (DEBUG) { System.out.println("PushRealModifiers ::="); } //$NON-NLS-1$
4958 consumePushRealModifiers();
4961 case 267 : if (DEBUG) { System.out.println("EmptyStatement ::= SEMICOLON"); } //$NON-NLS-1$
4962 consumeEmptyStatement();
4965 case 268 : if (DEBUG) { System.out.println("LabeledStatement ::= Identifier COLON Statement"); } //$NON-NLS-1$
4966 consumeStatementLabel() ;
4969 case 269 : if (DEBUG) { System.out.println("LabeledStatementNoShortIf ::= Identifier COLON..."); } //$NON-NLS-1$
4970 consumeStatementLabel() ;
4973 case 270 : if (DEBUG) { System.out.println("ExpressionStatement ::= StatementExpression SEMICOLON"); } //$NON-NLS-1$
4974 consumeExpressionStatement();
4977 case 279 : if (DEBUG) { System.out.println("IfThenStatement ::= if LPAREN Expression RPAREN..."); } //$NON-NLS-1$
4978 consumeStatementIfNoElse();
4981 case 280 : if (DEBUG) { System.out.println("IfThenElseStatement ::= if LPAREN Expression RPAREN..."); } //$NON-NLS-1$
4982 consumeStatementIfWithElse();
4985 case 281 : if (DEBUG) { System.out.println("IfThenElseStatementNoShortIf ::= if LPAREN Expression..."); } //$NON-NLS-1$
4986 consumeStatementIfWithElse();
4989 case 282 : if (DEBUG) { System.out.println("SwitchStatement ::= switch LPAREN Expression RPAREN..."); } //$NON-NLS-1$
4990 consumeStatementSwitch() ;
4993 case 283 : if (DEBUG) { System.out.println("SwitchBlock ::= LBRACE RBRACE"); } //$NON-NLS-1$
4994 consumeEmptySwitchBlock() ;
4997 case 286 : if (DEBUG) { System.out.println("SwitchBlock ::= LBRACE SwitchBlockStatements..."); } //$NON-NLS-1$
4998 consumeSwitchBlock() ;
5001 case 288 : if (DEBUG) { System.out.println("SwitchBlockStatements ::= SwitchBlockStatements..."); } //$NON-NLS-1$
5002 consumeSwitchBlockStatements() ;
5005 case 289 : if (DEBUG) { System.out.println("SwitchBlockStatement ::= SwitchLabels BlockStatements"); } //$NON-NLS-1$
5006 consumeSwitchBlockStatement() ;
5009 case 291 : if (DEBUG) { System.out.println("SwitchLabels ::= SwitchLabels SwitchLabel"); } //$NON-NLS-1$
5010 consumeSwitchLabels() ;
5013 case 292 : if (DEBUG) { System.out.println("SwitchLabel ::= case ConstantExpression COLON"); } //$NON-NLS-1$
5017 case 293 : if (DEBUG) { System.out.println("SwitchLabel ::= default COLON"); } //$NON-NLS-1$
5018 consumeDefaultLabel();
5021 case 294 : if (DEBUG) { System.out.println("WhileStatement ::= while LPAREN Expression RPAREN..."); } //$NON-NLS-1$
5022 consumeStatementWhile() ;
5025 case 295 : if (DEBUG) { System.out.println("WhileStatementNoShortIf ::= while LPAREN Expression..."); } //$NON-NLS-1$
5026 consumeStatementWhile() ;
5029 case 296 : if (DEBUG) { System.out.println("DoStatement ::= do Statement while LPAREN Expression..."); } //$NON-NLS-1$
5030 consumeStatementDo() ;
5033 case 297 : if (DEBUG) { System.out.println("ForStatement ::= for LPAREN ForInitopt SEMICOLON..."); } //$NON-NLS-1$
5034 consumeStatementFor() ;
5037 case 298 : if (DEBUG) { System.out.println("ForStatementNoShortIf ::= for LPAREN ForInitopt..."); } //$NON-NLS-1$
5038 consumeStatementFor() ;
5041 case 299 : if (DEBUG) { System.out.println("ForInit ::= StatementExpressionList"); } //$NON-NLS-1$
5045 case 303 : if (DEBUG) { System.out.println("StatementExpressionList ::= StatementExpressionList..."); } //$NON-NLS-1$
5046 consumeStatementExpressionList() ;
5049 case 304 : if (DEBUG) { System.out.println("AssertStatement ::= assert Expression SEMICOLON"); } //$NON-NLS-1$
5050 consumeSimpleAssertStatement() ;
5053 case 305 : if (DEBUG) { System.out.println("AssertStatement ::= assert Expression COLON Expression"); } //$NON-NLS-1$
5054 consumeAssertStatement() ;
5057 case 306 : if (DEBUG) { System.out.println("BreakStatement ::= break SEMICOLON"); } //$NON-NLS-1$
5058 consumeStatementBreak() ;
5061 case 307 : if (DEBUG) { System.out.println("BreakStatement ::= break Identifier SEMICOLON"); } //$NON-NLS-1$
5062 consumeStatementBreakWithLabel() ;
5065 case 308 : if (DEBUG) { System.out.println("ContinueStatement ::= continue SEMICOLON"); } //$NON-NLS-1$
5066 consumeStatementContinue() ;
5069 case 309 : if (DEBUG) { System.out.println("ContinueStatement ::= continue Identifier SEMICOLON"); } //$NON-NLS-1$
5070 consumeStatementContinueWithLabel() ;
5073 case 310 : if (DEBUG) { System.out.println("ReturnStatement ::= return Expressionopt SEMICOLON"); } //$NON-NLS-1$
5074 consumeStatementReturn() ;
5077 case 311 : if (DEBUG) { System.out.println("ThrowStatement ::= throw Expression SEMICOLON"); } //$NON-NLS-1$
5078 consumeStatementThrow();
5081 case 312 : if (DEBUG) { System.out.println("SynchronizedStatement ::= OnlySynchronized LPAREN..."); } //$NON-NLS-1$
5082 consumeStatementSynchronized();
5085 case 313 : if (DEBUG) { System.out.println("OnlySynchronized ::= synchronized"); } //$NON-NLS-1$
5086 consumeOnlySynchronized();
5089 case 314 : if (DEBUG) { System.out.println("TryStatement ::= try TryBlock Catches"); } //$NON-NLS-1$
5090 consumeStatementTry(false);
5093 case 315 : if (DEBUG) { System.out.println("TryStatement ::= try TryBlock Catchesopt Finally"); } //$NON-NLS-1$
5094 consumeStatementTry(true);
5097 case 317 : if (DEBUG) { System.out.println("ExitTryBlock ::="); } //$NON-NLS-1$
5098 consumeExitTryBlock();
5101 case 319 : if (DEBUG) { System.out.println("Catches ::= Catches CatchClause"); } //$NON-NLS-1$
5105 case 320 : if (DEBUG) { System.out.println("CatchClause ::= catch LPAREN FormalParameter RPAREN..."); } //$NON-NLS-1$
5106 consumeStatementCatch() ;
5109 case 322 : if (DEBUG) { System.out.println("PushLPAREN ::= LPAREN"); } //$NON-NLS-1$
5113 case 323 : if (DEBUG) { System.out.println("PushRPAREN ::= RPAREN"); } //$NON-NLS-1$
5114 consumeRightParen();
5117 case 328 : if (DEBUG) { System.out.println("PrimaryNoNewArray ::= this"); } //$NON-NLS-1$
5118 consumePrimaryNoNewArrayThis();
5121 case 329 : if (DEBUG) { System.out.println("PrimaryNoNewArray ::= PushLPAREN Expression_NotName..."); } //$NON-NLS-1$
5122 consumePrimaryNoNewArray();
5125 case 330 : if (DEBUG) { System.out.println("PrimaryNoNewArray ::= PushLPAREN Name PushRPAREN"); } //$NON-NLS-1$
5126 consumePrimaryNoNewArrayWithName();
5129 case 333 : if (DEBUG) { System.out.println("PrimaryNoNewArray ::= Name DOT this"); } //$NON-NLS-1$
5130 consumePrimaryNoNewArrayNameThis();
5133 case 334 : if (DEBUG) { System.out.println("PrimaryNoNewArray ::= Name DOT super"); } //$NON-NLS-1$
5134 consumePrimaryNoNewArrayNameSuper();
5137 case 335 : if (DEBUG) { System.out.println("PrimaryNoNewArray ::= Name DOT class"); } //$NON-NLS-1$
5138 consumePrimaryNoNewArrayName();
5141 case 336 : if (DEBUG) { System.out.println("PrimaryNoNewArray ::= Name Dims DOT class"); } //$NON-NLS-1$
5142 consumePrimaryNoNewArrayArrayType();
5145 case 337 : if (DEBUG) { System.out.println("PrimaryNoNewArray ::= PrimitiveType Dims DOT class"); } //$NON-NLS-1$
5146 consumePrimaryNoNewArrayPrimitiveArrayType();
5149 case 338 : if (DEBUG) { System.out.println("PrimaryNoNewArray ::= PrimitiveType DOT class"); } //$NON-NLS-1$
5150 consumePrimaryNoNewArrayPrimitiveType();
5153 case 341 : if (DEBUG) { System.out.println("AllocationHeader ::= new ClassType LPAREN..."); } //$NON-NLS-1$
5154 consumeAllocationHeader();
5157 case 342 : if (DEBUG) { System.out.println("ClassInstanceCreationExpression ::= new..."); } //$NON-NLS-1$
5158 consumeClassInstanceCreationExpressionWithTypeArguments();
5161 case 343 : if (DEBUG) { System.out.println("ClassInstanceCreationExpression ::= new ClassType LPAREN"); } //$NON-NLS-1$
5162 consumeClassInstanceCreationExpression();
5165 case 344 : if (DEBUG) { System.out.println("ClassInstanceCreationExpression ::= Primary DOT new..."); } //$NON-NLS-1$
5166 consumeClassInstanceCreationExpressionQualifiedWithTypeArguments() ;
5169 case 345 : if (DEBUG) { System.out.println("ClassInstanceCreationExpression ::= Primary DOT new..."); } //$NON-NLS-1$
5170 consumeClassInstanceCreationExpressionQualified() ;
5173 case 346 : if (DEBUG) { System.out.println("ClassInstanceCreationExpression ::=..."); } //$NON-NLS-1$
5174 consumeClassInstanceCreationExpressionQualified() ;
5177 case 347 : if (DEBUG) { System.out.println("ClassInstanceCreationExpression ::=..."); } //$NON-NLS-1$
5178 consumeClassInstanceCreationExpressionQualifiedWithTypeArguments() ;
5181 case 348 : if (DEBUG) { System.out.println("ClassInstanceCreationExpressionName ::= Name DOT"); } //$NON-NLS-1$
5182 consumeClassInstanceCreationExpressionName() ;
5185 case 349 : if (DEBUG) { System.out.println("ClassBodyopt ::="); } //$NON-NLS-1$
5186 consumeClassBodyopt();
5189 case 351 : if (DEBUG) { System.out.println("ClassBodySimpleNameopt ::="); } //$NON-NLS-1$
5190 consumeClassBodyopt();
5193 case 353 : if (DEBUG) { System.out.println("EnterAnonymousClassBodySimpleName ::="); } //$NON-NLS-1$
5194 consumeEnterAnonymousClassBodySimpleName();
5197 case 354 : if (DEBUG) { System.out.println("EnterAnonymousClassBody ::="); } //$NON-NLS-1$
5198 consumeEnterAnonymousClassBody();
5201 case 356 : if (DEBUG) { System.out.println("ArgumentList ::= ArgumentList COMMA Expression"); } //$NON-NLS-1$
5202 consumeArgumentList();
5205 case 357 : if (DEBUG) { System.out.println("ArrayCreationHeader ::= new PrimitiveType..."); } //$NON-NLS-1$
5206 consumeArrayCreationHeader();
5209 case 358 : if (DEBUG) { System.out.println("ArrayCreationHeader ::= new ClassOrInterfaceType..."); } //$NON-NLS-1$
5210 consumeArrayCreationHeader();
5213 case 359 : if (DEBUG) { System.out.println("ArrayCreationWithoutArrayInitializer ::= new..."); } //$NON-NLS-1$
5214 consumeArrayCreationExpressionWithoutInitializer();
5217 case 360 : if (DEBUG) { System.out.println("ArrayCreationWithArrayInitializer ::= new PrimitiveType"); } //$NON-NLS-1$
5218 consumeArrayCreationExpressionWithInitializer();
5221 case 361 : if (DEBUG) { System.out.println("ArrayCreationWithoutArrayInitializer ::= new..."); } //$NON-NLS-1$
5222 consumeArrayCreationExpressionWithoutInitializer();
5225 case 362 : if (DEBUG) { System.out.println("ArrayCreationWithArrayInitializer ::= new..."); } //$NON-NLS-1$
5226 consumeArrayCreationExpressionWithInitializer();
5229 case 364 : if (DEBUG) { System.out.println("DimWithOrWithOutExprs ::= DimWithOrWithOutExprs..."); } //$NON-NLS-1$
5230 consumeDimWithOrWithOutExprs();
5233 case 366 : if (DEBUG) { System.out.println("DimWithOrWithOutExpr ::= LBRACKET RBRACKET"); } //$NON-NLS-1$
5234 consumeDimWithOrWithOutExpr();
5237 case 367 : if (DEBUG) { System.out.println("Dims ::= DimsLoop"); } //$NON-NLS-1$
5241 case 370 : if (DEBUG) { System.out.println("OneDimLoop ::= LBRACKET RBRACKET"); } //$NON-NLS-1$
5242 consumeOneDimLoop();
5245 case 371 : if (DEBUG) { System.out.println("FieldAccess ::= Primary DOT Identifier"); } //$NON-NLS-1$
5246 consumeFieldAccess(false);
5249 case 372 : if (DEBUG) { System.out.println("FieldAccess ::= super DOT Identifier"); } //$NON-NLS-1$
5250 consumeFieldAccess(true);
5253 case 373 : if (DEBUG) { System.out.println("MethodInvocation ::= Name LPAREN ArgumentListopt RPAREN"); } //$NON-NLS-1$
5254 consumeMethodInvocationName();
5257 case 374 : if (DEBUG) { System.out.println("MethodInvocation ::= Name DOT OnlyTypeArguments..."); } //$NON-NLS-1$
5258 consumeMethodInvocationNameWithTypeArguments();
5261 case 375 : if (DEBUG) { System.out.println("MethodInvocation ::= Primary DOT OnlyTypeArguments..."); } //$NON-NLS-1$
5262 consumeMethodInvocationPrimaryWithTypeArguments();
5265 case 376 : if (DEBUG) { System.out.println("MethodInvocation ::= Primary DOT Identifier LPAREN..."); } //$NON-NLS-1$
5266 consumeMethodInvocationPrimary();
5269 case 377 : if (DEBUG) { System.out.println("MethodInvocation ::= super DOT OnlyTypeArguments..."); } //$NON-NLS-1$
5270 consumeMethodInvocationSuperWithTypeArguments();
5273 case 378 : if (DEBUG) { System.out.println("MethodInvocation ::= super DOT Identifier LPAREN..."); } //$NON-NLS-1$
5274 consumeMethodInvocationSuper();
5277 case 379 : if (DEBUG) { System.out.println("ArrayAccess ::= Name LBRACKET Expression RBRACKET"); } //$NON-NLS-1$
5278 consumeArrayAccess(true);
5281 case 380 : if (DEBUG) { System.out.println("ArrayAccess ::= PrimaryNoNewArray LBRACKET Expression..."); } //$NON-NLS-1$
5282 consumeArrayAccess(false);
5285 case 381 : if (DEBUG) { System.out.println("ArrayAccess ::= ArrayCreationWithArrayInitializer..."); } //$NON-NLS-1$
5286 consumeArrayAccess(false);
5289 case 383 : if (DEBUG) { System.out.println("PostfixExpression ::= Name"); } //$NON-NLS-1$
5290 consumePostfixExpression();
5293 case 386 : if (DEBUG) { System.out.println("PostIncrementExpression ::= PostfixExpression PLUS_PLUS"); } //$NON-NLS-1$
5294 consumeUnaryExpression(OperatorIds.PLUS,true);
5297 case 387 : if (DEBUG) { System.out.println("PostDecrementExpression ::= PostfixExpression..."); } //$NON-NLS-1$
5298 consumeUnaryExpression(OperatorIds.MINUS,true);
5301 case 388 : if (DEBUG) { System.out.println("PushPosition ::="); } //$NON-NLS-1$
5302 consumePushPosition();
5305 case 391 : if (DEBUG) { System.out.println("UnaryExpression ::= PLUS PushPosition UnaryExpression"); } //$NON-NLS-1$
5306 consumeUnaryExpression(OperatorIds.PLUS);
5309 case 392 : if (DEBUG) { System.out.println("UnaryExpression ::= MINUS PushPosition UnaryExpression"); } //$NON-NLS-1$
5310 consumeUnaryExpression(OperatorIds.MINUS);
5313 case 394 : if (DEBUG) { System.out.println("PreIncrementExpression ::= PLUS_PLUS PushPosition..."); } //$NON-NLS-1$
5314 consumeUnaryExpression(OperatorIds.PLUS,false);
5317 case 395 : if (DEBUG) { System.out.println("PreDecrementExpression ::= MINUS_MINUS PushPosition..."); } //$NON-NLS-1$
5318 consumeUnaryExpression(OperatorIds.MINUS,false);
5321 case 397 : if (DEBUG) { System.out.println("UnaryExpressionNotPlusMinus ::= TWIDDLE PushPosition..."); } //$NON-NLS-1$
5322 consumeUnaryExpression(OperatorIds.TWIDDLE);
5325 case 398 : if (DEBUG) { System.out.println("UnaryExpressionNotPlusMinus ::= NOT PushPosition..."); } //$NON-NLS-1$
5326 consumeUnaryExpression(OperatorIds.NOT);
5329 case 400 : if (DEBUG) { System.out.println("CastExpression ::= PushLPAREN PrimitiveType Dimsopt..."); } //$NON-NLS-1$
5330 consumeCastExpressionWithPrimitiveType();
5333 case 401 : if (DEBUG) { System.out.println("CastExpression ::= PushLPAREN Name..."); } //$NON-NLS-1$
5334 consumeCastExpressionWithGenericsArray();
5337 case 402 : if (DEBUG) { System.out.println("CastExpression ::= PushLPAREN Name..."); } //$NON-NLS-1$
5338 consumeCastExpressionWithQualifiedGenericsArray();
5341 case 403 : if (DEBUG) { System.out.println("CastExpression ::= PushLPAREN Name PushRPAREN..."); } //$NON-NLS-1$
5342 consumeCastExpressionLL1();
5345 case 404 : if (DEBUG) { System.out.println("CastExpression ::= PushLPAREN Name Dims PushRPAREN..."); } //$NON-NLS-1$
5346 consumeCastExpressionWithNameArray();
5349 case 405 : if (DEBUG) { System.out.println("OnlyTypeArgumentsForCastExpression ::= OnlyTypeArguments"); } //$NON-NLS-1$
5350 consumeOnlyTypeArgumentsForCastExpression();
5353 case 406 : if (DEBUG) { System.out.println("InsideCastExpression ::="); } //$NON-NLS-1$
5354 consumeInsideCastExpression();
5357 case 407 : if (DEBUG) { System.out.println("InsideCastExpressionLL1 ::="); } //$NON-NLS-1$
5358 consumeInsideCastExpressionLL1();
5361 case 408 : if (DEBUG) { System.out.println("InsideCastExpressionWithQualifiedGenerics ::="); } //$NON-NLS-1$
5362 consumeInsideCastExpressionWithQualifiedGenerics();
5365 case 410 : if (DEBUG) { System.out.println("MultiplicativeExpression ::= MultiplicativeExpression..."); } //$NON-NLS-1$
5366 consumeBinaryExpression(OperatorIds.MULTIPLY);
5369 case 411 : if (DEBUG) { System.out.println("MultiplicativeExpression ::= MultiplicativeExpression..."); } //$NON-NLS-1$
5370 consumeBinaryExpression(OperatorIds.DIVIDE);
5373 case 412 : if (DEBUG) { System.out.println("MultiplicativeExpression ::= MultiplicativeExpression..."); } //$NON-NLS-1$
5374 consumeBinaryExpression(OperatorIds.REMAINDER);
5377 case 414 : if (DEBUG) { System.out.println("AdditiveExpression ::= AdditiveExpression PLUS..."); } //$NON-NLS-1$
5378 consumeBinaryExpression(OperatorIds.PLUS);
5381 case 415 : if (DEBUG) { System.out.println("AdditiveExpression ::= AdditiveExpression MINUS..."); } //$NON-NLS-1$
5382 consumeBinaryExpression(OperatorIds.MINUS);
5385 case 417 : if (DEBUG) { System.out.println("ShiftExpression ::= ShiftExpression LEFT_SHIFT..."); } //$NON-NLS-1$
5386 consumeBinaryExpression(OperatorIds.LEFT_SHIFT);
5389 case 418 : if (DEBUG) { System.out.println("ShiftExpression ::= ShiftExpression RIGHT_SHIFT..."); } //$NON-NLS-1$
5390 consumeBinaryExpression(OperatorIds.RIGHT_SHIFT);
5393 case 419 : if (DEBUG) { System.out.println("ShiftExpression ::= ShiftExpression UNSIGNED_RIGHT_SHIFT"); } //$NON-NLS-1$
5394 consumeBinaryExpression(OperatorIds.UNSIGNED_RIGHT_SHIFT);
5397 case 421 : if (DEBUG) { System.out.println("RelationalExpression ::= RelationalExpression LESS..."); } //$NON-NLS-1$
5398 consumeBinaryExpression(OperatorIds.LESS);
5401 case 422 : if (DEBUG) { System.out.println("RelationalExpression ::= RelationalExpression GREATER..."); } //$NON-NLS-1$
5402 consumeBinaryExpression(OperatorIds.GREATER);
5405 case 423 : if (DEBUG) { System.out.println("RelationalExpression ::= RelationalExpression LESS_EQUAL"); } //$NON-NLS-1$
5406 consumeBinaryExpression(OperatorIds.LESS_EQUAL);
5409 case 424 : if (DEBUG) { System.out.println("RelationalExpression ::= RelationalExpression..."); } //$NON-NLS-1$
5410 consumeBinaryExpression(OperatorIds.GREATER_EQUAL);
5413 case 426 : if (DEBUG) { System.out.println("InstanceofExpression ::= InstanceofExpression instanceof"); } //$NON-NLS-1$
5414 consumeInstanceOfExpression(OperatorIds.INSTANCEOF);
5417 case 428 : if (DEBUG) { System.out.println("EqualityExpression ::= EqualityExpression EQUAL_EQUAL..."); } //$NON-NLS-1$
5418 consumeEqualityExpression(OperatorIds.EQUAL_EQUAL);
5421 case 429 : if (DEBUG) { System.out.println("EqualityExpression ::= EqualityExpression NOT_EQUAL..."); } //$NON-NLS-1$
5422 consumeEqualityExpression(OperatorIds.NOT_EQUAL);
5425 case 431 : if (DEBUG) { System.out.println("AndExpression ::= AndExpression AND EqualityExpression"); } //$NON-NLS-1$
5426 consumeBinaryExpression(OperatorIds.AND);
5429 case 433 : if (DEBUG) { System.out.println("ExclusiveOrExpression ::= ExclusiveOrExpression XOR..."); } //$NON-NLS-1$
5430 consumeBinaryExpression(OperatorIds.XOR);
5433 case 435 : if (DEBUG) { System.out.println("InclusiveOrExpression ::= InclusiveOrExpression OR..."); } //$NON-NLS-1$
5434 consumeBinaryExpression(OperatorIds.OR);
5437 case 437 : if (DEBUG) { System.out.println("ConditionalAndExpression ::= ConditionalAndExpression..."); } //$NON-NLS-1$
5438 consumeBinaryExpression(OperatorIds.AND_AND);
5441 case 439 : if (DEBUG) { System.out.println("ConditionalOrExpression ::= ConditionalOrExpression..."); } //$NON-NLS-1$
5442 consumeBinaryExpression(OperatorIds.OR_OR);
5445 case 441 : if (DEBUG) { System.out.println("ConditionalExpression ::= ConditionalOrExpression..."); } //$NON-NLS-1$
5446 consumeConditionalExpression(OperatorIds.QUESTIONCOLON) ;
5449 case 444 : if (DEBUG) { System.out.println("Assignment ::= PostfixExpression AssignmentOperator..."); } //$NON-NLS-1$
5450 consumeAssignment();
5453 case 446 : if (DEBUG) { System.out.println("Assignment ::= InvalidArrayInitializerAssignement"); } //$NON-NLS-1$
5454 ignoreExpressionAssignment();
5457 case 447 : if (DEBUG) { System.out.println("AssignmentOperator ::= EQUAL"); } //$NON-NLS-1$
5458 consumeAssignmentOperator(EQUAL);
5461 case 448 : if (DEBUG) { System.out.println("AssignmentOperator ::= MULTIPLY_EQUAL"); } //$NON-NLS-1$
5462 consumeAssignmentOperator(MULTIPLY);
5465 case 449 : if (DEBUG) { System.out.println("AssignmentOperator ::= DIVIDE_EQUAL"); } //$NON-NLS-1$
5466 consumeAssignmentOperator(DIVIDE);
5469 case 450 : if (DEBUG) { System.out.println("AssignmentOperator ::= REMAINDER_EQUAL"); } //$NON-NLS-1$
5470 consumeAssignmentOperator(REMAINDER);
5473 case 451 : if (DEBUG) { System.out.println("AssignmentOperator ::= PLUS_EQUAL"); } //$NON-NLS-1$
5474 consumeAssignmentOperator(PLUS);
5477 case 452 : if (DEBUG) { System.out.println("AssignmentOperator ::= MINUS_EQUAL"); } //$NON-NLS-1$
5478 consumeAssignmentOperator(MINUS);
5481 case 453 : if (DEBUG) { System.out.println("AssignmentOperator ::= LEFT_SHIFT_EQUAL"); } //$NON-NLS-1$
5482 consumeAssignmentOperator(LEFT_SHIFT);
5485 case 454 : if (DEBUG) { System.out.println("AssignmentOperator ::= RIGHT_SHIFT_EQUAL"); } //$NON-NLS-1$
5486 consumeAssignmentOperator(RIGHT_SHIFT);
5489 case 455 : if (DEBUG) { System.out.println("AssignmentOperator ::= UNSIGNED_RIGHT_SHIFT_EQUAL"); } //$NON-NLS-1$
5490 consumeAssignmentOperator(UNSIGNED_RIGHT_SHIFT);
5493 case 456 : if (DEBUG) { System.out.println("AssignmentOperator ::= AND_EQUAL"); } //$NON-NLS-1$
5494 consumeAssignmentOperator(AND);
5497 case 457 : if (DEBUG) { System.out.println("AssignmentOperator ::= XOR_EQUAL"); } //$NON-NLS-1$
5498 consumeAssignmentOperator(XOR);
5501 case 458 : if (DEBUG) { System.out.println("AssignmentOperator ::= OR_EQUAL"); } //$NON-NLS-1$
5502 consumeAssignmentOperator(OR);
5505 case 462 : if (DEBUG) { System.out.println("Expressionopt ::="); } //$NON-NLS-1$
5506 consumeEmptyExpression();
5509 case 467 : if (DEBUG) { System.out.println("ClassBodyDeclarationsopt ::="); } //$NON-NLS-1$
5510 consumeEmptyClassBodyDeclarationsopt();
5513 case 468 : if (DEBUG) { System.out.println("ClassBodyDeclarationsopt ::= NestedType..."); } //$NON-NLS-1$
5514 consumeClassBodyDeclarationsopt();
5517 case 469 : if (DEBUG) { System.out.println("Modifiersopt ::="); } //$NON-NLS-1$
5518 consumeDefaultModifiers();
5521 case 470 : if (DEBUG) { System.out.println("Modifiersopt ::= Modifiers"); } //$NON-NLS-1$
5525 case 471 : if (DEBUG) { System.out.println("BlockStatementsopt ::="); } //$NON-NLS-1$
5526 consumeEmptyBlockStatementsopt();
5529 case 473 : if (DEBUG) { System.out.println("Dimsopt ::="); } //$NON-NLS-1$
5530 consumeEmptyDimsopt();
5533 case 475 : if (DEBUG) { System.out.println("ArgumentListopt ::="); } //$NON-NLS-1$
5534 consumeEmptyArgumentListopt();
5537 case 479 : if (DEBUG) { System.out.println("FormalParameterListopt ::="); } //$NON-NLS-1$
5538 consumeFormalParameterListopt();
5541 case 483 : if (DEBUG) { System.out.println("InterfaceMemberDeclarationsopt ::="); } //$NON-NLS-1$
5542 consumeEmptyInterfaceMemberDeclarationsopt();
5545 case 484 : if (DEBUG) { System.out.println("InterfaceMemberDeclarationsopt ::= NestedType..."); } //$NON-NLS-1$
5546 consumeInterfaceMemberDeclarationsopt();
5549 case 485 : if (DEBUG) { System.out.println("NestedType ::="); } //$NON-NLS-1$
5550 consumeNestedType();
5553 case 486 : if (DEBUG) { System.out.println("ForInitopt ::="); } //$NON-NLS-1$
5554 consumeEmptyForInitopt();
5557 case 488 : if (DEBUG) { System.out.println("ForUpdateopt ::="); } //$NON-NLS-1$
5558 consumeEmptyForUpdateopt();
5561 case 492 : if (DEBUG) { System.out.println("Catchesopt ::="); } //$NON-NLS-1$
5562 consumeEmptyCatchesopt();
5565 case 494 : if (DEBUG) { System.out.println("EnumDeclaration ::= EnumHeader EnumBody"); } //$NON-NLS-1$
5566 consumeEnumDeclaration();
5569 case 495 : if (DEBUG) { System.out.println("EnumHeader ::= EnumHeaderName ClassHeaderImplementsopt"); } //$NON-NLS-1$
5570 consumeEnumHeader();
5573 case 496 : if (DEBUG) { System.out.println("EnumHeaderName ::= Modifiersopt enum Identifier"); } //$NON-NLS-1$
5574 consumeEnumHeaderName();
5577 case 497 : if (DEBUG) { System.out.println("EnumBody ::= LBRACE EnumBodyDeclarationsopt RBRACE"); } //$NON-NLS-1$
5578 consumeEnumBodyNoConstants();
5581 case 498 : if (DEBUG) { System.out.println("EnumBody ::= LBRACE COMMA EnumBodyDeclarationsopt..."); } //$NON-NLS-1$
5582 consumeEnumBodyNoConstants();
5585 case 499 : if (DEBUG) { System.out.println("EnumBody ::= LBRACE EnumConstants COMMA..."); } //$NON-NLS-1$
5586 consumeEnumBodyWithConstants();
5589 case 500 : if (DEBUG) { System.out.println("EnumBody ::= LBRACE EnumConstants..."); } //$NON-NLS-1$
5590 consumeEnumBodyWithConstants();
5593 case 502 : if (DEBUG) { System.out.println("EnumConstants ::= EnumConstants COMMA EnumConstant"); } //$NON-NLS-1$
5594 consumeEnumConstants();
5597 case 503 : if (DEBUG) { System.out.println("EnumConstantHeaderName ::= Modifiersopt Identifier"); } //$NON-NLS-1$
5598 consumeEnumConstantHeaderName();
5601 case 504 : if (DEBUG) { System.out.println("EnumConstantHeader ::= EnumConstantHeaderName..."); } //$NON-NLS-1$
5602 consumeEnumConstantHeader();
5605 case 505 : if (DEBUG) { System.out.println("EnumConstant ::= EnumConstantHeader ForceNoDiet..."); } //$NON-NLS-1$
5606 consumeEnumConstantWithClassBody();
5609 case 506 : if (DEBUG) { System.out.println("EnumConstant ::= EnumConstantHeader"); } //$NON-NLS-1$
5610 consumeEnumConstantNoClassBody();
5613 case 507 : if (DEBUG) { System.out.println("Arguments ::= LPAREN ArgumentListopt RPAREN"); } //$NON-NLS-1$
5617 case 508 : if (DEBUG) { System.out.println("Argumentsopt ::="); } //$NON-NLS-1$
5618 consumeEmptyArguments();
5621 case 510 : if (DEBUG) { System.out.println("EnumDeclarations ::= SEMICOLON ClassBodyDeclarationsopt"); } //$NON-NLS-1$
5622 consumeEnumDeclarations();
5625 case 511 : if (DEBUG) { System.out.println("EnumBodyDeclarationsopt ::="); } //$NON-NLS-1$
5626 consumeEmptyEnumDeclarations();
5629 case 513 : if (DEBUG) { System.out.println("EnhancedForStatement ::= EnhancedForStatementHeader..."); } //$NON-NLS-1$
5630 consumeEnhancedForStatement();
5633 case 514 : if (DEBUG) { System.out.println("EnhancedForStatementNoShortIf ::=..."); } //$NON-NLS-1$
5634 consumeEnhancedForStatement();
5637 case 515 : if (DEBUG) { System.out.println("EnhancedForStatementHeader ::= for LPAREN Type..."); } //$NON-NLS-1$
5638 consumeEnhancedForStatementHeader(false);
5641 case 516 : if (DEBUG) { System.out.println("EnhancedForStatementHeader ::= for LPAREN Modifiers Type"); } //$NON-NLS-1$
5642 consumeEnhancedForStatementHeader(true);
5645 case 517 : if (DEBUG) { System.out.println("SingleStaticImportDeclaration ::=..."); } //$NON-NLS-1$
5646 consumeImportDeclaration();
5649 case 518 : if (DEBUG) { System.out.println("SingleStaticImportDeclarationName ::= import static Name"); } //$NON-NLS-1$
5650 consumeSingleStaticImportDeclarationName();
5653 case 519 : if (DEBUG) { System.out.println("StaticImportOnDemandDeclaration ::=..."); } //$NON-NLS-1$
5654 consumeImportDeclaration();
5657 case 520 : if (DEBUG) { System.out.println("StaticImportOnDemandDeclarationName ::= import static..."); } //$NON-NLS-1$
5658 consumeStaticImportOnDemandDeclarationName();
5661 case 521 : if (DEBUG) { System.out.println("TypeArguments ::= LESS TypeArgumentList1"); } //$NON-NLS-1$
5662 consumeTypeArguments();
5665 case 522 : if (DEBUG) { System.out.println("OnlyTypeArguments ::= LESS TypeArgumentList1"); } //$NON-NLS-1$
5666 consumeOnlyTypeArguments();
5669 case 524 : if (DEBUG) { System.out.println("TypeArgumentList1 ::= TypeArgumentList COMMA..."); } //$NON-NLS-1$
5670 consumeTypeArgumentList1();
5673 case 526 : if (DEBUG) { System.out.println("TypeArgumentList ::= TypeArgumentList COMMA TypeArgument"); } //$NON-NLS-1$
5674 consumeTypeArgumentList();
5677 case 527 : if (DEBUG) { System.out.println("TypeArgument ::= ReferenceType"); } //$NON-NLS-1$
5678 consumeTypeArgument();
5681 case 531 : if (DEBUG) { System.out.println("ReferenceType1 ::= ReferenceType GREATER"); } //$NON-NLS-1$
5682 consumeReferenceType1();
5685 case 532 : if (DEBUG) { System.out.println("ReferenceType1 ::= ClassOrInterface LESS..."); } //$NON-NLS-1$
5686 consumeTypeArgumentReferenceType1();
5689 case 534 : if (DEBUG) { System.out.println("TypeArgumentList2 ::= TypeArgumentList COMMA..."); } //$NON-NLS-1$
5690 consumeTypeArgumentList2();
5693 case 537 : if (DEBUG) { System.out.println("ReferenceType2 ::= ReferenceType RIGHT_SHIFT"); } //$NON-NLS-1$
5694 consumeReferenceType2();
5697 case 538 : if (DEBUG) { System.out.println("ReferenceType2 ::= ClassOrInterface LESS..."); } //$NON-NLS-1$
5698 consumeTypeArgumentReferenceType2();
5701 case 540 : if (DEBUG) { System.out.println("TypeArgumentList3 ::= TypeArgumentList COMMA..."); } //$NON-NLS-1$
5702 consumeTypeArgumentList3();
5705 case 543 : if (DEBUG) { System.out.println("ReferenceType3 ::= ReferenceType UNSIGNED_RIGHT_SHIFT"); } //$NON-NLS-1$
5706 consumeReferenceType3();
5709 case 544 : if (DEBUG) { System.out.println("Wildcard ::= QUESTION"); } //$NON-NLS-1$
5713 case 545 : if (DEBUG) { System.out.println("Wildcard ::= QUESTION WildcardBounds"); } //$NON-NLS-1$
5714 consumeWildcardWithBounds();
5717 case 546 : if (DEBUG) { System.out.println("WildcardBounds ::= extends ReferenceType"); } //$NON-NLS-1$
5718 consumeWildcardBoundsExtends();
5721 case 547 : if (DEBUG) { System.out.println("WildcardBounds ::= super ReferenceType"); } //$NON-NLS-1$
5722 consumeWildcardBoundsSuper();
5725 case 548 : if (DEBUG) { System.out.println("Wildcard1 ::= QUESTION GREATER"); } //$NON-NLS-1$
5729 case 549 : if (DEBUG) { System.out.println("Wildcard1 ::= QUESTION WildcardBounds1"); } //$NON-NLS-1$
5730 consumeWildcard1WithBounds();
5733 case 550 : if (DEBUG) { System.out.println("WildcardBounds1 ::= extends ReferenceType1"); } //$NON-NLS-1$
5734 consumeWildcardBounds1Extends();
5737 case 551 : if (DEBUG) { System.out.println("WildcardBounds1 ::= super ReferenceType1"); } //$NON-NLS-1$
5738 consumeWildcardBounds1Super();
5741 case 552 : if (DEBUG) { System.out.println("Wildcard2 ::= QUESTION RIGHT_SHIFT"); } //$NON-NLS-1$
5745 case 553 : if (DEBUG) { System.out.println("Wildcard2 ::= QUESTION WildcardBounds2"); } //$NON-NLS-1$
5746 consumeWildcard2WithBounds();
5749 case 554 : if (DEBUG) { System.out.println("WildcardBounds2 ::= extends ReferenceType2"); } //$NON-NLS-1$
5750 consumeWildcardBounds2Extends();
5753 case 555 : if (DEBUG) { System.out.println("WildcardBounds2 ::= super ReferenceType2"); } //$NON-NLS-1$
5754 consumeWildcardBounds2Super();
5757 case 556 : if (DEBUG) { System.out.println("Wildcard3 ::= QUESTION UNSIGNED_RIGHT_SHIFT"); } //$NON-NLS-1$
5761 case 557 : if (DEBUG) { System.out.println("Wildcard3 ::= QUESTION WildcardBounds3"); } //$NON-NLS-1$
5762 consumeWildcard3WithBounds();
5765 case 558 : if (DEBUG) { System.out.println("WildcardBounds3 ::= extends ReferenceType3"); } //$NON-NLS-1$
5766 consumeWildcardBounds3Extends();
5769 case 559 : if (DEBUG) { System.out.println("WildcardBounds3 ::= super ReferenceType3"); } //$NON-NLS-1$
5770 consumeWildcardBounds3Super();
5773 case 560 : if (DEBUG) { System.out.println("TypeParameterHeader ::= Identifier"); } //$NON-NLS-1$
5774 consumeTypeParameterHeader();
5777 case 561 : if (DEBUG) { System.out.println("TypeParameters ::= LESS TypeParameterList1"); } //$NON-NLS-1$
5778 consumeTypeParameters();
5781 case 563 : if (DEBUG) { System.out.println("TypeParameterList ::= TypeParameterList COMMA..."); } //$NON-NLS-1$
5782 consumeTypeParameterList();
5785 case 565 : if (DEBUG) { System.out.println("TypeParameter ::= TypeParameterHeader extends..."); } //$NON-NLS-1$
5786 consumeTypeParameterWithExtends();
5789 case 566 : if (DEBUG) { System.out.println("TypeParameter ::= TypeParameterHeader extends..."); } //$NON-NLS-1$
5790 consumeTypeParameterWithExtendsAndBounds();
5793 case 568 : if (DEBUG) { System.out.println("AdditionalBoundList ::= AdditionalBoundList..."); } //$NON-NLS-1$
5794 consumeAdditionalBoundList();
5797 case 569 : if (DEBUG) { System.out.println("AdditionalBound ::= AND ReferenceType"); } //$NON-NLS-1$
5798 consumeAdditionalBound();
5801 case 571 : if (DEBUG) { System.out.println("TypeParameterList1 ::= TypeParameterList COMMA..."); } //$NON-NLS-1$
5802 consumeTypeParameterList1();
5805 case 572 : if (DEBUG) { System.out.println("TypeParameter1 ::= TypeParameterHeader GREATER"); } //$NON-NLS-1$
5806 consumeTypeParameter1();
5809 case 573 : if (DEBUG) { System.out.println("TypeParameter1 ::= TypeParameterHeader extends..."); } //$NON-NLS-1$
5810 consumeTypeParameter1WithExtends();
5813 case 574 : if (DEBUG) { System.out.println("TypeParameter1 ::= TypeParameterHeader extends..."); } //$NON-NLS-1$
5814 consumeTypeParameter1WithExtendsAndBounds();
5817 case 576 : if (DEBUG) { System.out.println("AdditionalBoundList1 ::= AdditionalBoundList..."); } //$NON-NLS-1$
5818 consumeAdditionalBoundList1();
5821 case 577 : if (DEBUG) { System.out.println("AdditionalBound1 ::= AND ReferenceType1"); } //$NON-NLS-1$
5822 consumeAdditionalBound1();
5825 case 583 : if (DEBUG) { System.out.println("UnaryExpression_NotName ::= PLUS PushPosition..."); } //$NON-NLS-1$
5826 consumeUnaryExpression(OperatorIds.PLUS);
5829 case 584 : if (DEBUG) { System.out.println("UnaryExpression_NotName ::= MINUS PushPosition..."); } //$NON-NLS-1$
5830 consumeUnaryExpression(OperatorIds.MINUS);
5833 case 587 : if (DEBUG) { System.out.println("UnaryExpressionNotPlusMinus_NotName ::= TWIDDLE..."); } //$NON-NLS-1$
5834 consumeUnaryExpression(OperatorIds.TWIDDLE);
5837 case 588 : if (DEBUG) { System.out.println("UnaryExpressionNotPlusMinus_NotName ::= NOT PushPosition"); } //$NON-NLS-1$
5838 consumeUnaryExpression(OperatorIds.NOT);
5841 case 591 : if (DEBUG) { System.out.println("MultiplicativeExpression_NotName ::=..."); } //$NON-NLS-1$
5842 consumeBinaryExpression(OperatorIds.MULTIPLY);
5845 case 592 : if (DEBUG) { System.out.println("MultiplicativeExpression_NotName ::= Name MULTIPLY..."); } //$NON-NLS-1$
5846 consumeBinaryExpressionWithName(OperatorIds.MULTIPLY);
5849 case 593 : if (DEBUG) { System.out.println("MultiplicativeExpression_NotName ::=..."); } //$NON-NLS-1$
5850 consumeBinaryExpression(OperatorIds.DIVIDE);
5853 case 594 : if (DEBUG) { System.out.println("MultiplicativeExpression_NotName ::= Name DIVIDE..."); } //$NON-NLS-1$
5854 consumeBinaryExpressionWithName(OperatorIds.DIVIDE);
5857 case 595 : if (DEBUG) { System.out.println("MultiplicativeExpression_NotName ::=..."); } //$NON-NLS-1$
5858 consumeBinaryExpression(OperatorIds.REMAINDER);
5861 case 596 : if (DEBUG) { System.out.println("MultiplicativeExpression_NotName ::= Name REMAINDER..."); } //$NON-NLS-1$
5862 consumeBinaryExpressionWithName(OperatorIds.REMAINDER);
5865 case 598 : if (DEBUG) { System.out.println("AdditiveExpression_NotName ::=..."); } //$NON-NLS-1$
5866 consumeBinaryExpression(OperatorIds.PLUS);
5869 case 599 : if (DEBUG) { System.out.println("AdditiveExpression_NotName ::= Name PLUS..."); } //$NON-NLS-1$
5870 consumeBinaryExpressionWithName(OperatorIds.PLUS);
5873 case 600 : if (DEBUG) { System.out.println("AdditiveExpression_NotName ::=..."); } //$NON-NLS-1$
5874 consumeBinaryExpression(OperatorIds.MINUS);
5877 case 601 : if (DEBUG) { System.out.println("AdditiveExpression_NotName ::= Name MINUS..."); } //$NON-NLS-1$
5878 consumeBinaryExpressionWithName(OperatorIds.MINUS);
5881 case 603 : if (DEBUG) { System.out.println("ShiftExpression_NotName ::= ShiftExpression_NotName..."); } //$NON-NLS-1$
5882 consumeBinaryExpression(OperatorIds.LEFT_SHIFT);
5885 case 604 : if (DEBUG) { System.out.println("ShiftExpression_NotName ::= Name LEFT_SHIFT..."); } //$NON-NLS-1$
5886 consumeBinaryExpressionWithName(OperatorIds.LEFT_SHIFT);
5889 case 605 : if (DEBUG) { System.out.println("ShiftExpression_NotName ::= ShiftExpression_NotName..."); } //$NON-NLS-1$
5890 consumeBinaryExpression(OperatorIds.RIGHT_SHIFT);
5893 case 606 : if (DEBUG) { System.out.println("ShiftExpression_NotName ::= Name RIGHT_SHIFT..."); } //$NON-NLS-1$
5894 consumeBinaryExpressionWithName(OperatorIds.RIGHT_SHIFT);
5897 case 607 : if (DEBUG) { System.out.println("ShiftExpression_NotName ::= ShiftExpression_NotName..."); } //$NON-NLS-1$
5898 consumeBinaryExpression(OperatorIds.UNSIGNED_RIGHT_SHIFT);
5901 case 608 : if (DEBUG) { System.out.println("ShiftExpression_NotName ::= Name UNSIGNED_RIGHT_SHIFT..."); } //$NON-NLS-1$
5902 consumeBinaryExpressionWithName(OperatorIds.UNSIGNED_RIGHT_SHIFT);
5905 case 610 : if (DEBUG) { System.out.println("RelationalExpression_NotName ::= ShiftExpression_NotName"); } //$NON-NLS-1$
5906 consumeBinaryExpression(OperatorIds.LESS);
5909 case 611 : if (DEBUG) { System.out.println("RelationalExpression_NotName ::= Name LESS..."); } //$NON-NLS-1$
5910 consumeBinaryExpressionWithName(OperatorIds.LESS);
5913 case 612 : if (DEBUG) { System.out.println("RelationalExpression_NotName ::= ShiftExpression_NotName"); } //$NON-NLS-1$
5914 consumeBinaryExpression(OperatorIds.GREATER);
5917 case 613 : if (DEBUG) { System.out.println("RelationalExpression_NotName ::= Name GREATER..."); } //$NON-NLS-1$
5918 consumeBinaryExpressionWithName(OperatorIds.GREATER);
5921 case 614 : if (DEBUG) { System.out.println("RelationalExpression_NotName ::=..."); } //$NON-NLS-1$
5922 consumeBinaryExpression(OperatorIds.LESS_EQUAL);
5925 case 615 : if (DEBUG) { System.out.println("RelationalExpression_NotName ::= Name LESS_EQUAL..."); } //$NON-NLS-1$
5926 consumeBinaryExpressionWithName(OperatorIds.LESS_EQUAL);
5929 case 616 : if (DEBUG) { System.out.println("RelationalExpression_NotName ::=..."); } //$NON-NLS-1$
5930 consumeBinaryExpression(OperatorIds.GREATER_EQUAL);
5933 case 617 : if (DEBUG) { System.out.println("RelationalExpression_NotName ::= Name GREATER_EQUAL..."); } //$NON-NLS-1$
5934 consumeBinaryExpressionWithName(OperatorIds.GREATER_EQUAL);
5937 case 619 : if (DEBUG) { System.out.println("InstanceofExpression_NotName ::= Name instanceof..."); } //$NON-NLS-1$
5938 consumeInstanceOfExpressionWithName(OperatorIds.INSTANCEOF);
5941 case 620 : if (DEBUG) { System.out.println("InstanceofExpression_NotName ::=..."); } //$NON-NLS-1$
5942 consumeInstanceOfExpression(OperatorIds.INSTANCEOF);
5945 case 622 : if (DEBUG) { System.out.println("EqualityExpression_NotName ::=..."); } //$NON-NLS-1$
5946 consumeEqualityExpression(OperatorIds.EQUAL_EQUAL);
5949 case 623 : if (DEBUG) { System.out.println("EqualityExpression_NotName ::= Name EQUAL_EQUAL..."); } //$NON-NLS-1$
5950 consumeEqualityExpressionWithName(OperatorIds.EQUAL_EQUAL);
5953 case 624 : if (DEBUG) { System.out.println("EqualityExpression_NotName ::=..."); } //$NON-NLS-1$
5954 consumeEqualityExpression(OperatorIds.NOT_EQUAL);
5957 case 625 : if (DEBUG) { System.out.println("EqualityExpression_NotName ::= Name NOT_EQUAL..."); } //$NON-NLS-1$
5958 consumeEqualityExpressionWithName(OperatorIds.NOT_EQUAL);
5961 case 627 : if (DEBUG) { System.out.println("AndExpression_NotName ::= AndExpression_NotName AND..."); } //$NON-NLS-1$
5962 consumeBinaryExpression(OperatorIds.AND);
5965 case 628 : if (DEBUG) { System.out.println("AndExpression_NotName ::= Name AND EqualityExpression"); } //$NON-NLS-1$
5966 consumeBinaryExpressionWithName(OperatorIds.AND);
5969 case 630 : if (DEBUG) { System.out.println("ExclusiveOrExpression_NotName ::=..."); } //$NON-NLS-1$
5970 consumeBinaryExpression(OperatorIds.XOR);
5973 case 631 : if (DEBUG) { System.out.println("ExclusiveOrExpression_NotName ::= Name XOR AndExpression"); } //$NON-NLS-1$
5974 consumeBinaryExpressionWithName(OperatorIds.XOR);
5977 case 633 : if (DEBUG) { System.out.println("InclusiveOrExpression_NotName ::=..."); } //$NON-NLS-1$
5978 consumeBinaryExpression(OperatorIds.OR);
5981 case 634 : if (DEBUG) { System.out.println("InclusiveOrExpression_NotName ::= Name OR..."); } //$NON-NLS-1$
5982 consumeBinaryExpressionWithName(OperatorIds.OR);
5985 case 636 : if (DEBUG) { System.out.println("ConditionalAndExpression_NotName ::=..."); } //$NON-NLS-1$
5986 consumeBinaryExpression(OperatorIds.AND_AND);
5989 case 637 : if (DEBUG) { System.out.println("ConditionalAndExpression_NotName ::= Name AND_AND..."); } //$NON-NLS-1$
5990 consumeBinaryExpressionWithName(OperatorIds.AND_AND);
5993 case 639 : if (DEBUG) { System.out.println("ConditionalOrExpression_NotName ::=..."); } //$NON-NLS-1$
5994 consumeBinaryExpression(OperatorIds.OR_OR);
5997 case 640 : if (DEBUG) { System.out.println("ConditionalOrExpression_NotName ::= Name OR_OR..."); } //$NON-NLS-1$
5998 consumeBinaryExpressionWithName(OperatorIds.OR_OR);
6001 case 642 : if (DEBUG) { System.out.println("ConditionalExpression_NotName ::=..."); } //$NON-NLS-1$
6002 consumeConditionalExpression(OperatorIds.QUESTIONCOLON) ;
6005 case 643 : if (DEBUG) { System.out.println("ConditionalExpression_NotName ::= Name QUESTION..."); } //$NON-NLS-1$
6006 consumeConditionalExpressionWithName(OperatorIds.QUESTIONCOLON) ;
6009 case 647 : if (DEBUG) { System.out.println("AnnotationTypeDeclarationHeaderName ::= Modifiers AT..."); } //$NON-NLS-1$
6010 consumeAnnotationTypeDeclarationHeaderName() ;
6013 case 648 : if (DEBUG) { System.out.println("AnnotationTypeDeclarationHeaderName ::= AT..."); } //$NON-NLS-1$
6014 consumeAnnotationTypeDeclarationHeaderName() ;
6017 case 649 : if (DEBUG) { System.out.println("AnnotationTypeDeclarationHeader ::=..."); } //$NON-NLS-1$
6018 consumeAnnotationTypeDeclarationHeader() ;
6021 case 650 : if (DEBUG) { System.out.println("AnnotationTypeDeclaration ::=..."); } //$NON-NLS-1$
6022 consumeAnnotationTypeDeclaration() ;
6025 case 652 : if (DEBUG) { System.out.println("AnnotationTypeMemberDeclarationsopt ::="); } //$NON-NLS-1$
6026 consumeEmptyAnnotationTypeMemberDeclarationsopt() ;
6029 case 655 : if (DEBUG) { System.out.println("AnnotationTypeMemberDeclarations ::=..."); } //$NON-NLS-1$
6030 consumeAnnotationTypeMemberDeclarations() ;
6033 case 656 : if (DEBUG) { System.out.println("AnnotationMethodHeaderName ::= Modifiersopt..."); } //$NON-NLS-1$
6034 consumeMethodHeaderNameWithTypeParameters(true);
6037 case 657 : if (DEBUG) { System.out.println("AnnotationMethodHeaderName ::= Modifiersopt Type..."); } //$NON-NLS-1$
6038 consumeMethodHeaderName(true);
6041 case 658 : if (DEBUG) { System.out.println("AnnotationMethodHeaderDefaultValueopt ::="); } //$NON-NLS-1$
6042 consumeEmptyMethodHeaderDefaultValue() ;
6045 case 659 : if (DEBUG) { System.out.println("AnnotationMethodHeaderDefaultValueopt ::= DefaultValue"); } //$NON-NLS-1$
6046 consumeMethodHeaderDefaultValue();
6049 case 660 : if (DEBUG) { System.out.println("AnnotationMethodHeader ::= AnnotationMethodHeaderName..."); } //$NON-NLS-1$
6050 consumeMethodHeader();
6053 case 661 : if (DEBUG) { System.out.println("AnnotationTypeMemberDeclaration ::=..."); } //$NON-NLS-1$
6054 consumeAnnotationTypeMemberDeclaration() ;
6057 case 669 : if (DEBUG) { System.out.println("AnnotationName ::= AT Name"); } //$NON-NLS-1$
6058 consumeAnnotationName() ;
6061 case 670 : if (DEBUG) { System.out.println("NormalAnnotation ::= AnnotationName LPAREN..."); } //$NON-NLS-1$
6062 consumeNormalAnnotation() ;
6065 case 671 : if (DEBUG) { System.out.println("MemberValuePairsopt ::="); } //$NON-NLS-1$
6066 consumeEmptyMemberValuePairsopt() ;
6069 case 674 : if (DEBUG) { System.out.println("MemberValuePairs ::= MemberValuePairs COMMA..."); } //$NON-NLS-1$
6070 consumeMemberValuePairs() ;
6073 case 675 : if (DEBUG) { System.out.println("MemberValuePair ::= SimpleName EQUAL MemberValue"); } //$NON-NLS-1$
6074 consumeMemberValuePair() ;
6077 case 677 : if (DEBUG) { System.out.println("MemberValue ::= Name"); } //$NON-NLS-1$
6078 consumeMemberValueAsName() ;
6081 case 680 : if (DEBUG) { System.out.println("MemberValueArrayInitializer ::= LBRACE PushLeftBrace..."); } //$NON-NLS-1$
6082 consumeMemberValueArrayInitializer() ;
6085 case 681 : if (DEBUG) { System.out.println("MemberValueArrayInitializer ::= LBRACE PushLeftBrace..."); } //$NON-NLS-1$
6086 consumeMemberValueArrayInitializer() ;
6089 case 682 : if (DEBUG) { System.out.println("MemberValueArrayInitializer ::= LBRACE PushLeftBrace..."); } //$NON-NLS-1$
6090 consumeEmptyMemberValueArrayInitializer() ;
6093 case 683 : if (DEBUG) { System.out.println("MemberValueArrayInitializer ::= LBRACE PushLeftBrace..."); } //$NON-NLS-1$
6094 consumeEmptyMemberValueArrayInitializer() ;
6097 case 685 : if (DEBUG) { System.out.println("MemberValues ::= MemberValues COMMA MemberValue"); } //$NON-NLS-1$
6098 consumeMemberValues() ;
6101 case 686 : if (DEBUG) { System.out.println("MarkerAnnotation ::= AnnotationName"); } //$NON-NLS-1$
6102 consumeMarkerAnnotation() ;
6105 case 687 : if (DEBUG) { System.out.println("SingleMemberAnnotation ::= AnnotationName LPAREN..."); } //$NON-NLS-1$
6106 consumeSingleMemberAnnotation() ;
6109 case 688 : if (DEBUG) { System.out.println("RecoveryMethodHeaderName ::= Modifiersopt TypeParameters"); } //$NON-NLS-1$
6110 consumeRecoveryMethodHeaderNameWithTypeParameters();
6113 case 689 : if (DEBUG) { System.out.println("RecoveryMethodHeaderName ::= Modifiersopt Type..."); } //$NON-NLS-1$
6114 consumeRecoveryMethodHeaderName();
6117 case 690 : if (DEBUG) { System.out.println("RecoveryMethodHeader ::= RecoveryMethodHeaderName..."); } //$NON-NLS-1$
6118 consumeMethodHeader();
6121 case 691 : if (DEBUG) { System.out.println("RecoveryMethodHeader ::= RecoveryMethodHeaderName..."); } //$NON-NLS-1$
6122 consumeMethodHeader();
6127 protected void consumeSimpleAssertStatement() {
6128 // AssertStatement ::= 'assert' Expression ';'
6129 this.expressionLengthPtr--;
6130 pushOnAstStack(new AssertStatement(this.expressionStack[this.expressionPtr--], this.intStack[this.intPtr--]));
6132 protected void consumeSingleMemberAnnotation() {
6133 // SingleMemberAnnotation ::= '@' Name '(' MemberValue ')'
6134 SingleMemberAnnotation singleMemberAnnotation = null;
6135 int length = this.identifierLengthStack[this.identifierLengthPtr--];
6136 TypeReference typeReference;
6138 typeReference = new SingleTypeReference(
6139 this.identifierStack[this.identifierPtr],
6140 this.identifierPositionStack[this.identifierPtr--]);
6142 char[][] tokens = new char[length][];
6143 this.identifierPtr -= length;
6144 long[] positions = new long[length];
6145 System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
6147 this.identifierPositionStack,
6148 this.identifierPtr + 1,
6152 typeReference = new QualifiedTypeReference(tokens, positions);
6154 singleMemberAnnotation = new SingleMemberAnnotation(typeReference, this.intStack[this.intPtr--]);
6155 singleMemberAnnotation.memberValue = this.expressionStack[this.expressionPtr--];
6156 this.expressionLengthPtr--;
6157 int sourceStart = singleMemberAnnotation.sourceStart;
6158 if (this.modifiersSourceStart < 0) {
6159 this.modifiersSourceStart = sourceStart;
6160 } else if (this.modifiersSourceStart > sourceStart) {
6161 this.modifiersSourceStart = sourceStart;
6163 singleMemberAnnotation.declarationSourceEnd = this.rParenPos;
6164 pushOnExpressionStack(singleMemberAnnotation);
6165 if(options.sourceLevel < ClassFileConstants.JDK1_5 &&
6166 this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
6167 this.problemReporter().invalidUsageOfAnnotation(singleMemberAnnotation);
6170 protected void consumeSingleStaticImportDeclarationName() {
6171 // SingleTypeImportDeclarationName ::= 'import' 'static' Name
6172 /* push an ImportRef build from the last name
6173 stored in the identifier stack. */
6175 ImportReference impt;
6177 char[][] tokens = new char[length = this.identifierLengthStack[this.identifierLengthPtr--]][];
6178 this.identifierPtr -= length;
6179 long[] positions = new long[length];
6180 System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
6181 System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
6182 pushOnAstStack(impt = new ImportReference(tokens, positions, false, AccStatic));
6184 this.modifiers = AccDefault;
6185 this.modifiersSourceStart = -1; // <-- see comment into modifiersFlag(int)
6187 if (this.currentToken == TokenNameSEMICOLON){
6188 impt.declarationSourceEnd = this.scanner.currentPosition - 1;
6190 impt.declarationSourceEnd = impt.sourceEnd;
6192 impt.declarationEnd = impt.declarationSourceEnd;
6193 //this.endPosition is just before the ;
6194 impt.declarationSourceStart = this.intStack[this.intPtr--];
6196 if(this.options.sourceLevel < ClassFileConstants.JDK1_5 &&
6197 this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
6198 impt.modifiers = AccDefault; // convert the static import reference to a non-static importe reference
6199 this.problemReporter().invalidUsageOfStaticImports(impt);
6203 if (this.currentElement != null){
6204 this.lastCheckPoint = impt.declarationSourceEnd+1;
6205 this.currentElement = this.currentElement.add(impt, 0);
6206 this.lastIgnoredToken = -1;
6207 this.restartRecovery = true; // used to avoid branching back into the regular automaton
6210 protected void consumeSingleTypeImportDeclarationName() {
6211 // SingleTypeImportDeclarationName ::= 'import' Name
6212 /* push an ImportRef build from the last name
6213 stored in the identifier stack. */
6215 ImportReference impt;
6217 char[][] tokens = new char[length = this.identifierLengthStack[this.identifierLengthPtr--]][];
6218 this.identifierPtr -= length;
6219 long[] positions = new long[length];
6220 System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
6221 System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
6222 pushOnAstStack(impt = new ImportReference(tokens, positions, false, AccDefault));
6224 if (this.currentToken == TokenNameSEMICOLON){
6225 impt.declarationSourceEnd = this.scanner.currentPosition - 1;
6227 impt.declarationSourceEnd = impt.sourceEnd;
6229 impt.declarationEnd = impt.declarationSourceEnd;
6230 //this.endPosition is just before the ;
6231 impt.declarationSourceStart = this.intStack[this.intPtr--];
6234 if (this.currentElement != null){
6235 this.lastCheckPoint = impt.declarationSourceEnd+1;
6236 this.currentElement = this.currentElement.add(impt, 0);
6237 this.lastIgnoredToken = -1;
6238 this.restartRecovery = true; // used to avoid branching back into the regular automaton
6241 protected void consumeStatementBreak() {
6242 // BreakStatement ::= 'break' ';'
6243 // break pushs a position on this.intStack in case there is no label
6245 pushOnAstStack(new BreakStatement(null, this.intStack[this.intPtr--], this.endPosition));
6247 protected void consumeStatementBreakWithLabel() {
6248 // BreakStatement ::= 'break' Identifier ';'
6249 // break pushs a position on this.intStack in case there is no label
6253 this.identifierStack[this.identifierPtr--],
6254 this.intStack[this.intPtr--],
6256 this.identifierLengthPtr--;
6258 protected void consumeStatementCatch() {
6259 // CatchClause ::= 'catch' '(' FormalParameter ')' Block
6261 //catch are stored directly into the Try
6262 //has they always comes two by two....
6263 //we remove one entry from the astlengthPtr.
6264 //The construction of the try statement must
6265 //then fetch the catches using 2*i and 2*i + 1
6267 this.astLengthPtr--;
6268 this.listLength = 0; // reset formalParameter counter (incremented for catch variable)
6270 protected void consumeStatementContinue() {
6271 // ContinueStatement ::= 'continue' ';'
6272 // continue pushs a position on this.intStack in case there is no label
6275 new ContinueStatement(
6277 this.intStack[this.intPtr--],
6280 protected void consumeStatementContinueWithLabel() {
6281 // ContinueStatement ::= 'continue' Identifier ';'
6282 // continue pushs a position on this.intStack in case there is no label
6285 new ContinueStatement(
6286 this.identifierStack[this.identifierPtr--],
6287 this.intStack[this.intPtr--],
6289 this.identifierLengthPtr--;
6291 protected void consumeStatementDo() {
6292 // DoStatement ::= 'do' Statement 'while' '(' Expression ')' ';'
6294 //the 'while' pushes a value on this.intStack that we need to remove
6297 Statement statement = (Statement) this.astStack[this.astPtr];
6298 this.expressionLengthPtr--;
6299 this.astStack[this.astPtr] =
6301 this.expressionStack[this.expressionPtr--],
6303 this.intStack[this.intPtr--],
6306 protected void consumeStatementExpressionList() {
6307 // StatementExpressionList ::= StatementExpressionList ',' StatementExpression
6308 concatExpressionLists();
6310 protected void consumeStatementFor() {
6311 // ForStatement ::= 'for' '(' ForInitopt ';' Expressionopt ';' ForUpdateopt ')' Statement
6312 // ForStatementNoShortIf ::= 'for' '(' ForInitopt ';' Expressionopt ';' ForUpdateopt ')' StatementNoShortIf
6315 Expression cond = null;
6316 Statement[] inits, updates;
6317 boolean scope = true;
6320 this.astLengthPtr--;
6321 Statement statement = (Statement) this.astStack[this.astPtr--];
6323 //updates are on the expresion stack
6324 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) == 0) {
6327 this.expressionPtr -= length;
6329 this.expressionStack,
6330 this.expressionPtr + 1,
6331 updates = new Statement[length],
6336 if (this.expressionLengthStack[this.expressionLengthPtr--] != 0)
6337 cond = this.expressionStack[this.expressionPtr--];
6339 //inits may be on two different stacks
6340 if ((length = this.astLengthStack[this.astLengthPtr--]) == 0) {
6344 if (length == -1) { //on this.expressionStack
6346 length = this.expressionLengthStack[this.expressionLengthPtr--];
6347 this.expressionPtr -= length;
6349 this.expressionStack,
6350 this.expressionPtr + 1,
6351 inits = new Statement[length],
6354 } else { //on this.astStack
6355 this.astPtr -= length;
6359 inits = new Statement[length],
6371 this.intStack[this.intPtr--],
6372 this.endStatementPosition));
6374 protected void consumeStatementIfNoElse() {
6375 // IfThenStatement ::= 'if' '(' Expression ')' Statement
6377 //optimize the push/pop
6378 this.expressionLengthPtr--;
6379 Statement thenStatement = (Statement) this.astStack[this.astPtr];
6380 this.astStack[this.astPtr] =
6382 this.expressionStack[this.expressionPtr--],
6384 this.intStack[this.intPtr--],
6385 this.endStatementPosition);
6387 protected void consumeStatementIfWithElse() {
6388 // IfThenElseStatement ::= 'if' '(' Expression ')' StatementNoShortIf 'else' Statement
6389 // IfThenElseStatementNoShortIf ::= 'if' '(' Expression ')' StatementNoShortIf 'else' StatementNoShortIf
6391 this.expressionLengthPtr--;
6393 // optimized {..., Then, Else } ==> {..., If }
6394 this.astLengthPtr--;
6396 //optimize the push/pop
6397 this.astStack[--this.astPtr] =
6399 this.expressionStack[this.expressionPtr--],
6400 (Statement) this.astStack[this.astPtr],
6401 (Statement) this.astStack[this.astPtr + 1],
6402 this.intStack[this.intPtr--],
6403 this.endStatementPosition);
6405 protected void consumeStatementLabel() {
6406 // LabeledStatement ::= 'Identifier' ':' Statement
6407 // LabeledStatementNoShortIf ::= 'Identifier' ':' StatementNoShortIf
6410 Statement stmt = (Statement) this.astStack[this.astPtr];
6411 this.astStack[this.astPtr] =
6412 new LabeledStatement(
6413 this.identifierStack[this.identifierPtr],
6415 (int) (this.identifierPositionStack[this.identifierPtr--] >>> 32),
6416 this.endStatementPosition);
6417 this.identifierLengthPtr--;
6419 protected void consumeStatementReturn() {
6420 // ReturnStatement ::= 'return' Expressionopt ';'
6421 // return pushs a position on this.intStack in case there is no expression
6423 if (this.expressionLengthStack[this.expressionLengthPtr--] != 0) {
6425 new ReturnStatement(
6426 this.expressionStack[this.expressionPtr--],
6427 this.intStack[this.intPtr--],
6431 pushOnAstStack(new ReturnStatement(null, this.intStack[this.intPtr--], this.endPosition));
6434 protected void consumeStatementSwitch() {
6435 // SwitchStatement ::= 'switch' OpenBlock '(' Expression ')' SwitchBlock
6437 //OpenBlock just makes the semantic action blockStart()
6438 //the block is inlined but a scope need to be created
6439 //if some declaration occurs.
6442 SwitchStatement switchStatement = new SwitchStatement();
6443 this.expressionLengthPtr--;
6444 switchStatement.expression = this.expressionStack[this.expressionPtr--];
6445 if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) {
6446 this.astPtr -= length;
6450 switchStatement.statements = new Statement[length],
6454 switchStatement.explicitDeclarations = this.realBlockStack[this.realBlockPtr--];
6455 pushOnAstStack(switchStatement);
6456 switchStatement.blockStart = this.intStack[this.intPtr--];
6457 switchStatement.sourceStart = this.intStack[this.intPtr--];
6458 switchStatement.sourceEnd = this.endStatementPosition;
6459 if (length == 0 && !containsComment(switchStatement.blockStart, switchStatement.sourceEnd)) {
6460 switchStatement.bits |= ASTNode.UndocumentedEmptyBlockMASK;
6463 protected void consumeStatementSynchronized() {
6464 // SynchronizedStatement ::= OnlySynchronized '(' Expression ')' Block
6465 //optimize the push/pop
6467 if (this.astLengthStack[this.astLengthPtr] == 0) {
6468 this.astLengthStack[this.astLengthPtr] = 1;
6469 this.expressionLengthPtr--;
6470 this.astStack[++this.astPtr] =
6471 new SynchronizedStatement(
6472 this.expressionStack[this.expressionPtr--],
6474 this.intStack[this.intPtr--],
6475 this.endStatementPosition);
6477 this.expressionLengthPtr--;
6478 this.astStack[this.astPtr] =
6479 new SynchronizedStatement(
6480 this.expressionStack[this.expressionPtr--],
6481 (Block) this.astStack[this.astPtr],
6482 this.intStack[this.intPtr--],
6483 this.endStatementPosition);
6487 protected void consumeStatementThrow() {
6488 // ThrowStatement ::= 'throw' Expression ';'
6489 this.expressionLengthPtr--;
6490 pushOnAstStack(new ThrowStatement(this.expressionStack[this.expressionPtr--], this.intStack[this.intPtr--]));
6492 protected void consumeStatementTry(boolean withFinally) {
6493 //TryStatement ::= 'try' Block Catches
6494 //TryStatement ::= 'try' Block Catchesopt Finally
6497 TryStatement tryStmt = new TryStatement();
6500 this.astLengthPtr--;
6501 tryStmt.finallyBlock = (Block) this.astStack[this.astPtr--];
6503 //catches are handle by two <argument-block> [see statementCatch]
6504 if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) {
6506 tryStmt.catchBlocks = new Block[] {(Block) this.astStack[this.astPtr--]};
6507 tryStmt.catchArguments = new Argument[] {(Argument) this.astStack[this.astPtr--]};
6509 Block[] bks = (tryStmt.catchBlocks = new Block[length]);
6510 Argument[] args = (tryStmt.catchArguments = new Argument[length]);
6511 while (length-- > 0) {
6512 bks[length] = (Block) this.astStack[this.astPtr--];
6513 args[length] = (Argument) this.astStack[this.astPtr--];
6518 this.astLengthPtr--;
6519 tryStmt.tryBlock = (Block) this.astStack[this.astPtr--];
6522 tryStmt.sourceEnd = this.endStatementPosition;
6523 tryStmt.sourceStart = this.intStack[this.intPtr--];
6524 pushOnAstStack(tryStmt);
6526 protected void consumeStatementWhile() {
6527 // WhileStatement ::= 'while' '(' Expression ')' Statement
6528 // WhileStatementNoShortIf ::= 'while' '(' Expression ')' StatementNoShortIf
6530 this.expressionLengthPtr--;
6531 Statement statement = (Statement) this.astStack[this.astPtr];
6532 this.astStack[this.astPtr] =
6534 this.expressionStack[this.expressionPtr--],
6536 this.intStack[this.intPtr--],
6537 this.endStatementPosition);
6539 protected void consumeStaticImportOnDemandDeclarationName() {
6540 // TypeImportOnDemandDeclarationName ::= 'import' 'static' Name '.' '*'
6541 /* push an ImportRef build from the last name
6542 stored in the identifier stack. */
6544 ImportReference impt;
6546 char[][] tokens = new char[length = this.identifierLengthStack[this.identifierLengthPtr--]][];
6547 this.identifierPtr -= length;
6548 long[] positions = new long[length];
6549 System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
6550 System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
6551 pushOnAstStack(impt = new ImportReference(tokens, positions, true, AccStatic));
6553 this.modifiers = AccDefault;
6554 this.modifiersSourceStart = -1; // <-- see comment into modifiersFlag(int)
6556 if (this.currentToken == TokenNameSEMICOLON){
6557 impt.declarationSourceEnd = this.scanner.currentPosition - 1;
6559 impt.declarationSourceEnd = impt.sourceEnd;
6561 impt.declarationEnd = impt.declarationSourceEnd;
6562 //this.endPosition is just before the ;
6563 impt.declarationSourceStart = this.intStack[this.intPtr--];
6565 if(options.sourceLevel < ClassFileConstants.JDK1_5 &&
6566 this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
6567 impt.modifiers = AccDefault; // convert the static import reference to a non-static importe reference
6568 this.problemReporter().invalidUsageOfStaticImports(impt);
6572 if (this.currentElement != null){
6573 this.lastCheckPoint = impt.declarationSourceEnd+1;
6574 this.currentElement = this.currentElement.add(impt, 0);
6575 this.lastIgnoredToken = -1;
6576 this.restartRecovery = true; // used to avoid branching back into the regular automaton
6579 protected void consumeStaticInitializer() {
6580 // StaticInitializer ::= StaticOnly Block
6581 //push an Initializer
6582 //optimize the push/pop
6583 Block block = (Block) this.astStack[this.astPtr];
6584 if (this.diet) block.bits &= ~ASTNode.UndocumentedEmptyBlockMASK; // clear bit set since was diet
6585 Initializer initializer = new Initializer(block, AccStatic);
6586 this.astStack[this.astPtr] = initializer;
6587 initializer.sourceEnd = this.endStatementPosition;
6588 initializer.declarationSourceEnd = flushCommentsDefinedPriorTo(this.endStatementPosition);
6589 this.nestedMethod[this.nestedType] --;
6590 initializer.declarationSourceStart = this.intStack[this.intPtr--];
6591 initializer.bodyStart = this.intStack[this.intPtr--];
6592 initializer.bodyEnd = this.endPosition;
6594 initializer.javadoc = this.javadoc;
6595 this.javadoc = null;
6598 if (this.currentElement != null){
6599 this.lastCheckPoint = initializer.declarationSourceEnd;
6600 this.currentElement = this.currentElement.add(initializer, 0);
6601 this.lastIgnoredToken = -1;
6604 protected void consumeStaticOnly() {
6605 // StaticOnly ::= 'static'
6606 int savedModifiersSourceStart = this.modifiersSourceStart;
6607 checkComment(); // might update declaration source start
6608 if (this.modifiersSourceStart >= savedModifiersSourceStart) {
6609 this.modifiersSourceStart = savedModifiersSourceStart;
6611 pushOnIntStack(this.scanner.currentPosition);
6613 this.modifiersSourceStart >= 0 ? this.modifiersSourceStart : this.scanner.startPosition);
6614 jumpOverMethodBody();
6615 this.nestedMethod[this.nestedType]++;
6619 if (this.currentElement != null){
6620 this.recoveredStaticInitializerStart = this.intStack[this.intPtr]; // remember start position only for static initializers
6623 protected void consumeSwitchBlock() {
6624 // SwitchBlock ::= '{' SwitchBlockStatements SwitchLabels '}'
6627 protected void consumeSwitchBlockStatement() {
6628 // SwitchBlockStatement ::= SwitchLabels BlockStatements
6631 protected void consumeSwitchBlockStatements() {
6632 // SwitchBlockStatements ::= SwitchBlockStatements SwitchBlockStatement
6635 protected void consumeSwitchLabels() {
6636 // SwitchLabels ::= SwitchLabels SwitchLabel
6637 optimizedConcatNodeLists();
6639 protected void consumeToken(int type) {
6640 /* remember the last consumed value */
6641 /* try to minimize the number of build values */
6642 checkNonExternalizedStringLiteral();
6643 // // clear the commentPtr of the scanner in case we read something different from a modifier
6645 // case TokenNameabstract :
6646 // case TokenNamestrictfp :
6647 // case TokenNamefinal :
6648 // case TokenNamenative :
6649 // case TokenNameprivate :
6650 // case TokenNameprotected :
6651 // case TokenNamepublic :
6652 // case TokenNametransient :
6653 // case TokenNamevolatile :
6654 // case TokenNamestatic :
6655 // case TokenNamesynchronized :
6658 // this.scanner.commentPtr = -1;
6660 //System.out.println(this.scanner.toStringAction(type));
6662 case TokenNameIdentifier :
6664 if (this.scanner.useAssertAsAnIndentifier &&
6665 this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
6666 long positions = this.identifierPositionStack[this.identifierPtr];
6667 problemReporter().useAssertAsAnIdentifier((int) (positions >>> 32), (int) positions);
6669 if (this.scanner.useEnumAsAnIndentifier &&
6670 this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
6671 long positions = this.identifierPositionStack[this.identifierPtr];
6672 problemReporter().useEnumAsAnIdentifier((int) (positions >>> 32), (int) positions);
6675 case TokenNameinterface :
6676 //'class' is pushing two int (positions) on the stack ==> 'interface' needs to do it too....
6677 pushOnIntStack(this.scanner.currentPosition - 1);
6678 pushOnIntStack(this.scanner.startPosition);
6680 case TokenNameabstract :
6681 checkAndSetModifiers(AccAbstract);
6682 pushOnExpressionStackLengthStack(0);
6684 case TokenNamestrictfp :
6685 checkAndSetModifiers(AccStrictfp);
6686 pushOnExpressionStackLengthStack(0);
6688 case TokenNamefinal :
6689 checkAndSetModifiers(AccFinal);
6690 pushOnExpressionStackLengthStack(0);
6692 case TokenNamenative :
6693 checkAndSetModifiers(AccNative);
6694 pushOnExpressionStackLengthStack(0);
6696 case TokenNameprivate :
6697 checkAndSetModifiers(AccPrivate);
6698 pushOnExpressionStackLengthStack(0);
6700 case TokenNameprotected :
6701 checkAndSetModifiers(AccProtected);
6702 pushOnExpressionStackLengthStack(0);
6704 case TokenNamepublic :
6705 checkAndSetModifiers(AccPublic);
6706 pushOnExpressionStackLengthStack(0);
6708 case TokenNametransient :
6709 checkAndSetModifiers(AccTransient);
6710 pushOnExpressionStackLengthStack(0);
6712 case TokenNamevolatile :
6713 checkAndSetModifiers(AccVolatile);
6714 pushOnExpressionStackLengthStack(0);
6716 case TokenNamestatic :
6717 checkAndSetModifiers(AccStatic);
6718 pushOnExpressionStackLengthStack(0);
6720 case TokenNamesynchronized :
6721 this.synchronizedBlockSourceStart = this.scanner.startPosition;
6722 checkAndSetModifiers(AccSynchronized);
6723 pushOnExpressionStackLengthStack(0);
6725 //==============================
6726 case TokenNamevoid :
6727 pushIdentifier(-T_void);
6728 pushOnIntStack(this.scanner.currentPosition - 1);
6729 pushOnIntStack(this.scanner.startPosition);
6731 //push a default dimension while void is not part of the primitive
6732 //declaration baseType and so takes the place of a type without getting into
6733 //regular type parsing that generates a dimension on this.intStack
6734 case TokenNameboolean :
6735 pushIdentifier(-T_boolean);
6736 pushOnIntStack(this.scanner.currentPosition - 1);
6737 pushOnIntStack(this.scanner.startPosition);
6739 case TokenNamebyte :
6740 pushIdentifier(-T_byte);
6741 pushOnIntStack(this.scanner.currentPosition - 1);
6742 pushOnIntStack(this.scanner.startPosition);
6744 case TokenNamechar :
6745 pushIdentifier(-T_char);
6746 pushOnIntStack(this.scanner.currentPosition - 1);
6747 pushOnIntStack(this.scanner.startPosition);
6749 case TokenNamedouble :
6750 pushIdentifier(-T_double);
6751 pushOnIntStack(this.scanner.currentPosition - 1);
6752 pushOnIntStack(this.scanner.startPosition);
6754 case TokenNamefloat :
6755 pushIdentifier(-T_float);
6756 pushOnIntStack(this.scanner.currentPosition - 1);
6757 pushOnIntStack(this.scanner.startPosition);
6760 pushIdentifier(-T_int);
6761 pushOnIntStack(this.scanner.currentPosition - 1);
6762 pushOnIntStack(this.scanner.startPosition);
6764 case TokenNamelong :
6765 pushIdentifier(-T_long);
6766 pushOnIntStack(this.scanner.currentPosition - 1);
6767 pushOnIntStack(this.scanner.startPosition);
6769 case TokenNameshort :
6770 pushIdentifier(-T_short);
6771 pushOnIntStack(this.scanner.currentPosition - 1);
6772 pushOnIntStack(this.scanner.startPosition);
6774 //==============================
6775 case TokenNameIntegerLiteral :
6776 pushOnExpressionStack(
6778 this.scanner.getCurrentTokenSource(),
6779 this.scanner.startPosition,
6780 this.scanner.currentPosition - 1));
6782 case TokenNameLongLiteral :
6783 pushOnExpressionStack(
6785 this.scanner.getCurrentTokenSource(),
6786 this.scanner.startPosition,
6787 this.scanner.currentPosition - 1));
6789 case TokenNameFloatingPointLiteral :
6790 pushOnExpressionStack(
6792 this.scanner.getCurrentTokenSource(),
6793 this.scanner.startPosition,
6794 this.scanner.currentPosition - 1));
6796 case TokenNameDoubleLiteral :
6797 pushOnExpressionStack(
6799 this.scanner.getCurrentTokenSource(),
6800 this.scanner.startPosition,
6801 this.scanner.currentPosition - 1));
6803 case TokenNameCharacterLiteral :
6804 pushOnExpressionStack(
6806 this.scanner.getCurrentTokenSource(),
6807 this.scanner.startPosition,
6808 this.scanner.currentPosition - 1));
6810 case TokenNameStringLiteral :
6811 StringLiteral stringLiteral = new StringLiteral(
6812 this.scanner.getCurrentTokenSourceString(),
6813 this.scanner.startPosition,
6814 this.scanner.currentPosition - 1);
6815 pushOnExpressionStack(stringLiteral);
6817 case TokenNamefalse :
6818 pushOnExpressionStack(
6819 new FalseLiteral(this.scanner.startPosition, this.scanner.currentPosition - 1));
6821 case TokenNametrue :
6822 pushOnExpressionStack(
6823 new TrueLiteral(this.scanner.startPosition, this.scanner.currentPosition - 1));
6825 case TokenNamenull :
6826 pushOnExpressionStack(
6827 new NullLiteral(this.scanner.startPosition, this.scanner.currentPosition - 1));
6829 //============================
6830 case TokenNamesuper :
6831 case TokenNamethis :
6832 this.endPosition = this.scanner.currentPosition - 1;
6833 pushOnIntStack(this.scanner.startPosition);
6835 case TokenNameassert :
6836 case TokenNameimport :
6837 case TokenNamepackage :
6838 case TokenNamethrow :
6842 case TokenNameswitch :
6844 case TokenNamewhile :
6845 case TokenNamebreak :
6846 case TokenNamecontinue :
6847 case TokenNamereturn :
6848 case TokenNamecase :
6849 pushOnIntStack(this.scanner.startPosition);
6852 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=40954
6854 pushOnIntStack(this.scanner.startPosition);
6856 case TokenNameclass :
6857 pushOnIntStack(this.scanner.currentPosition - 1);
6858 pushOnIntStack(this.scanner.startPosition);
6860 case TokenNameenum :
6861 pushOnIntStack(this.scanner.currentPosition - 1);
6862 pushOnIntStack(this.scanner.startPosition);
6864 case TokenNamedefault :
6865 pushOnIntStack(this.scanner.startPosition);
6866 pushOnIntStack(this.scanner.currentPosition - 1);
6868 //let extra semantic action decide when to push
6869 case TokenNameRBRACKET :
6870 this.endPosition = this.scanner.startPosition;
6871 this.endStatementPosition = this.scanner.currentPosition - 1;
6873 case TokenNamePLUS :
6874 case TokenNameMINUS :
6876 case TokenNameTWIDDLE :
6877 case TokenNameLBRACE :
6878 this.endPosition = this.scanner.startPosition;
6880 case TokenNamePLUS_PLUS :
6881 case TokenNameMINUS_MINUS :
6882 this.endPosition = this.scanner.startPosition;
6883 this.endStatementPosition = this.scanner.currentPosition - 1;
6885 case TokenNameRBRACE:
6886 case TokenNameSEMICOLON :
6887 this.endStatementPosition = this.scanner.currentPosition - 1;
6888 this.endPosition = this.scanner.startPosition - 1;
6889 //the item is not part of the potential futur expression/statement
6891 case TokenNameRPAREN :
6892 // in order to handle ( expression) ////// (cast)expression///// foo(x)
6893 this.rParenPos = this.scanner.currentPosition - 1; // position of the end of right parenthesis (in case of unicode \u0029) lex00101
6895 case TokenNameLPAREN :
6896 this.lParenPos = this.scanner.startPosition;
6899 pushOnIntStack(this.scanner.startPosition);
6901 case TokenNameQUESTION :
6902 pushOnIntStack(this.scanner.startPosition);
6903 pushOnIntStack(this.scanner.currentPosition - 1);
6905 case TokenNameLESS :
6906 pushOnIntStack(this.scanner.startPosition);
6908 case TokenNameELLIPSIS :
6909 pushOnIntStack(this.scanner.currentPosition - 1);
6911 // case TokenNameCOMMA :
6912 // case TokenNameCOLON :
6913 // case TokenNameEQUAL :
6914 // case TokenNameLBRACKET :
6915 // case TokenNameDOT :
6916 // case TokenNameERROR :
6917 // case TokenNameEOF :
6918 // case TokenNamecase :
6919 // case TokenNamecatch :
6920 // case TokenNameelse :
6921 // case TokenNameextends :
6922 // case TokenNamefinally :
6923 // case TokenNameimplements :
6924 // case TokenNamethrows :
6925 // case TokenNameinstanceof :
6926 // case TokenNameEQUAL_EQUAL :
6927 // case TokenNameLESS_EQUAL :
6928 // case TokenNameGREATER_EQUAL :
6929 // case TokenNameNOT_EQUAL :
6930 // case TokenNameLEFT_SHIFT :
6931 // case TokenNameRIGHT_SHIFT :
6932 // case TokenNameUNSIGNED_RIGHT_SHIFT :
6933 // case TokenNamePLUS_EQUAL :
6934 // case TokenNameMINUS_EQUAL :
6935 // case TokenNameMULTIPLY_EQUAL :
6936 // case TokenNameDIVIDE_EQUAL :
6937 // case TokenNameAND_EQUAL :
6938 // case TokenNameOR_EQUAL :
6939 // case TokenNameXOR_EQUAL :
6940 // case TokenNameREMAINDER_EQUAL :
6941 // case TokenNameLEFT_SHIFT_EQUAL :
6942 // case TokenNameRIGHT_SHIFT_EQUAL :
6943 // case TokenNameUNSIGNED_RIGHT_SHIFT_EQUAL :
6944 // case TokenNameOR_OR :
6945 // case TokenNameAND_AND :
6946 // case TokenNameREMAINDER :
6947 // case TokenNameXOR :
6948 // case TokenNameAND :
6949 // case TokenNameMULTIPLY :
6950 // case TokenNameOR :
6951 // case TokenNameDIVIDE :
6952 // case TokenNameGREATER :
6955 protected void consumeTypeArgument() {
6956 pushOnGenericsStack(getTypeReference(this.intStack[this.intPtr--]));
6958 protected void consumeTypeArgumentList() {
6959 concatGenericsLists();
6961 protected void consumeTypeArgumentList1() {
6962 concatGenericsLists();
6964 protected void consumeTypeArgumentList2() {
6965 concatGenericsLists();
6967 protected void consumeTypeArgumentList3() {
6968 concatGenericsLists();
6970 protected void consumeTypeArgumentReferenceType1() {
6971 concatGenericsLists();
6972 pushOnGenericsStack(getTypeReference(0));
6975 protected void consumeTypeArgumentReferenceType2() {
6976 concatGenericsLists();
6977 pushOnGenericsStack(getTypeReference(0));
6980 protected void consumeTypeArguments() {
6981 concatGenericsLists();
6984 if(options.sourceLevel < ClassFileConstants.JDK1_5 &&
6985 this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
6986 int length = this.genericsLengthStack[this.genericsLengthPtr];
6987 this.problemReporter().invalidUsageOfTypeArguments(
6988 (TypeReference)this.genericsStack[this.genericsPtr - length + 1],
6989 (TypeReference)this.genericsStack[this.genericsPtr]);
6992 protected void consumeTypeDeclarations() {
6993 // TypeDeclarations ::= TypeDeclarations TypeDeclaration
6996 protected void consumeTypeImportOnDemandDeclarationName() {
6997 // TypeImportOnDemandDeclarationName ::= 'import' Name '.' '*'
6998 /* push an ImportRef build from the last name
6999 stored in the identifier stack. */
7001 ImportReference impt;
7003 char[][] tokens = new char[length = this.identifierLengthStack[this.identifierLengthPtr--]][];
7004 this.identifierPtr -= length;
7005 long[] positions = new long[length];
7006 System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
7007 System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
7008 pushOnAstStack(impt = new ImportReference(tokens, positions, true, AccDefault));
7010 if (this.currentToken == TokenNameSEMICOLON){
7011 impt.declarationSourceEnd = this.scanner.currentPosition - 1;
7013 impt.declarationSourceEnd = impt.sourceEnd;
7015 impt.declarationEnd = impt.declarationSourceEnd;
7016 //this.endPosition is just before the ;
7017 impt.declarationSourceStart = this.intStack[this.intPtr--];
7020 if (this.currentElement != null){
7021 this.lastCheckPoint = impt.declarationSourceEnd+1;
7022 this.currentElement = this.currentElement.add(impt, 0);
7023 this.lastIgnoredToken = -1;
7024 this.restartRecovery = true; // used to avoid branching back into the regular automaton
7027 protected void consumeTypeParameterHeader() {
7028 //TypeParameterHeader ::= Identifier
7029 TypeParameter typeParameter = new TypeParameter();
7030 long pos = this.identifierPositionStack[this.identifierPtr];
7031 final int end = (int) pos;
7032 typeParameter.declarationSourceEnd = end;
7033 typeParameter.sourceEnd = end;
7034 final int start = (int) (pos >>> 32);
7035 typeParameter.declarationSourceStart = start;
7036 typeParameter.sourceStart = start;
7037 typeParameter.name = this.identifierStack[this.identifierPtr--];
7038 this.identifierLengthPtr--;
7039 pushOnGenericsStack(typeParameter);
7041 this.listTypeParameterLength++;
7043 protected void consumeTypeParameter1() {
7046 protected void consumeTypeParameter1WithExtends() {
7047 //TypeParameter1 ::= TypeParameterHeader 'extends' ReferenceType1
7048 TypeReference superType = (TypeReference) this.genericsStack[this.genericsPtr--];
7049 this.genericsLengthPtr--;
7050 TypeParameter typeParameter = (TypeParameter) this.genericsStack[this.genericsPtr];
7051 typeParameter.declarationSourceEnd = superType.sourceEnd;
7052 typeParameter.type = superType;
7053 superType.bits |= ASTNode.IsSuperType;
7054 this.genericsStack[this.genericsPtr] = typeParameter;
7056 protected void consumeTypeParameter1WithExtendsAndBounds() {
7057 //TypeParameter1 ::= TypeParameterHeader 'extends' ReferenceType AdditionalBoundList1
7058 int additionalBoundsLength = this.genericsLengthStack[this.genericsLengthPtr--];
7059 TypeReference[] bounds = new TypeReference[additionalBoundsLength];
7060 this.genericsPtr -= additionalBoundsLength;
7061 System.arraycopy(this.genericsStack, this.genericsPtr + 1, bounds, 0, additionalBoundsLength);
7062 TypeReference superType = getTypeReference(this.intStack[this.intPtr--]);
7063 TypeParameter typeParameter = (TypeParameter) this.genericsStack[this.genericsPtr];
7064 typeParameter.declarationSourceEnd = bounds[additionalBoundsLength - 1].sourceEnd;
7065 typeParameter.type = superType;
7066 superType.bits |= ASTNode.IsSuperType;
7067 typeParameter.bounds = bounds;
7068 for (int i = 0, max = bounds.length; i < max; i++) {
7069 bounds[i].bits |= ASTNode.IsSuperType;
7072 protected void consumeTypeParameterList() {
7073 //TypeParameterList ::= TypeParameterList ',' TypeParameter
7074 concatGenericsLists();
7076 protected void consumeTypeParameterList1() {
7077 //TypeParameterList1 ::= TypeParameterList ',' TypeParameter1
7078 concatGenericsLists();
7080 protected void consumeTypeParameters() {
7082 if(options.sourceLevel < ClassFileConstants.JDK1_5&&
7083 this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
7084 int length = this.genericsLengthStack[this.genericsLengthPtr];
7085 this.problemReporter().invalidUsageOfTypeParameters(
7086 (TypeParameter) this.genericsStack[genericsPtr - length + 1],
7087 (TypeParameter) this.genericsStack[genericsPtr]);
7090 protected void consumeTypeParameterWithExtends() {
7091 //TypeParameter ::= TypeParameterHeader 'extends' ReferenceType
7092 TypeReference superType = getTypeReference(this.intStack[this.intPtr--]);
7093 TypeParameter typeParameter = (TypeParameter) this.genericsStack[this.genericsPtr];
7094 typeParameter.declarationSourceEnd = superType.sourceEnd;
7095 typeParameter.type = superType;
7096 superType.bits |= ASTNode.IsSuperType;
7098 protected void consumeTypeParameterWithExtendsAndBounds() {
7099 //TypeParameter ::= TypeParameterHeader 'extends' ReferenceType AdditionalBoundList
7100 int additionalBoundsLength = this.genericsLengthStack[this.genericsLengthPtr--];
7101 TypeReference[] bounds = new TypeReference[additionalBoundsLength];
7102 this.genericsPtr -= additionalBoundsLength;
7103 System.arraycopy(this.genericsStack, this.genericsPtr + 1, bounds, 0, additionalBoundsLength);
7104 TypeReference superType = getTypeReference(this.intStack[this.intPtr--]);
7105 TypeParameter typeParameter = (TypeParameter) this.genericsStack[this.genericsPtr];
7106 typeParameter.type = superType;
7107 superType.bits |= ASTNode.IsSuperType;
7108 typeParameter.bounds = bounds;
7109 typeParameter.declarationSourceEnd = bounds[additionalBoundsLength - 1].sourceEnd;
7110 for (int i = 0, max = bounds.length; i < max; i++) {
7111 bounds[i].bits |= ASTNode.IsSuperType;
7114 protected void consumeUnaryExpression(int op) {
7115 // UnaryExpression ::= '+' PushPosition UnaryExpression
7116 // UnaryExpression ::= '-' PushPosition UnaryExpression
7117 // UnaryExpressionNotPlusMinus ::= '~' PushPosition UnaryExpression
7118 // UnaryExpressionNotPlusMinus ::= '!' PushPosition UnaryExpression
7120 //optimize the push/pop
7122 //handle manually the -2147483648 while it is not a real
7123 //computation of an - and 2147483648 (notice that 2147483648
7124 //is Integer.MAX_VALUE+1.....)
7125 //Same for -9223372036854775808L ............
7127 //this.intStack have the position of the operator
7129 Expression r, exp = this.expressionStack[this.expressionPtr];
7131 if ((exp instanceof IntLiteral) && (((IntLiteral) exp).mayRepresentMIN_VALUE())) {
7132 r = this.expressionStack[this.expressionPtr] = new IntLiteralMinValue();
7134 if ((exp instanceof LongLiteral) && (((LongLiteral) exp).mayRepresentMIN_VALUE())) {
7135 r = this.expressionStack[this.expressionPtr] = new LongLiteralMinValue();
7137 r = this.expressionStack[this.expressionPtr] = new UnaryExpression(exp, op);
7141 r = this.expressionStack[this.expressionPtr] = new UnaryExpression(exp, op);
7143 r.sourceStart = this.intStack[this.intPtr--];
7144 r.sourceEnd = exp.sourceEnd;
7146 protected void consumeUnaryExpression(int op, boolean post) {
7147 // PreIncrementExpression ::= '++' PushPosition UnaryExpression
7148 // PreDecrementExpression ::= '--' PushPosition UnaryExpression
7150 // ++ and -- operators
7151 //optimize the push/pop
7153 //this.intStack has the position of the operator when prefix
7155 Expression leftHandSide = this.expressionStack[this.expressionPtr];
7156 if (leftHandSide instanceof Reference) {
7157 // ++foo()++ is unvalid
7159 this.expressionStack[this.expressionPtr] =
7160 new PostfixExpression(
7164 this.endStatementPosition);
7166 this.expressionStack[this.expressionPtr] =
7167 new PrefixExpression(
7171 this.intStack[this.intPtr--]);
7174 //the ++ or the -- is NOT taken into account if code gen proceeds
7178 problemReporter().invalidUnaryExpression(leftHandSide);
7181 protected void consumeVariableDeclarators() {
7182 // VariableDeclarators ::= VariableDeclarators ',' VariableDeclarator
7183 optimizedConcatNodeLists();
7185 protected void consumeVariableInitializers() {
7186 // VariableInitializers ::= VariableInitializers ',' VariableInitializer
7187 concatExpressionLists();
7189 protected void consumeWildcard() {
7190 final Wildcard wildcard = new Wildcard(Wildcard.UNBOUND);
7191 wildcard.sourceEnd = this.intStack[this.intPtr--];
7192 wildcard.sourceStart = this.intStack[this.intPtr--];
7193 pushOnGenericsStack(wildcard);
7195 protected void consumeWildcard1() {
7196 final Wildcard wildcard = new Wildcard(Wildcard.UNBOUND);
7197 wildcard.sourceEnd = this.intStack[this.intPtr--];
7198 wildcard.sourceStart = this.intStack[this.intPtr--];
7199 pushOnGenericsStack(wildcard);
7201 protected void consumeWildcard1WithBounds() {
7203 // The wildcard is created by the consumeWildcardBounds1Extends or by consumeWildcardBounds1Super
7205 protected void consumeWildcard2() {
7206 final Wildcard wildcard = new Wildcard(Wildcard.UNBOUND);
7207 wildcard.sourceEnd = this.intStack[this.intPtr--];
7208 wildcard.sourceStart = this.intStack[this.intPtr--];
7209 pushOnGenericsStack(wildcard);
7211 protected void consumeWildcard2WithBounds() {
7213 // The wildcard is created by the consumeWildcardBounds2Extends or by consumeWildcardBounds2Super
7215 protected void consumeWildcard3() {
7216 final Wildcard wildcard = new Wildcard(Wildcard.UNBOUND);
7217 wildcard.sourceEnd = this.intStack[this.intPtr--];
7218 wildcard.sourceStart = this.intStack[this.intPtr--];
7219 pushOnGenericsStack(wildcard);
7221 protected void consumeWildcard3WithBounds() {
7223 // The wildcard is created by the consumeWildcardBounds3Extends or by consumeWildcardBounds3Super
7225 protected void consumeWildcardBounds1Extends() {
7226 Wildcard wildcard = new Wildcard(Wildcard.EXTENDS);
7227 wildcard.bound = (TypeReference) this.genericsStack[this.genericsPtr];
7228 wildcard.sourceEnd = wildcard.bound.sourceEnd;
7229 this.intPtr--; // remove end position of the '?'
7230 wildcard.sourceStart = this.intStack[this.intPtr--];
7231 this.genericsStack[this.genericsPtr] = wildcard;
7233 protected void consumeWildcardBounds1Super() {
7234 Wildcard wildcard = new Wildcard(Wildcard.SUPER);
7235 wildcard.bound = (TypeReference) this.genericsStack[this.genericsPtr];
7236 this.intPtr--; // remove the starting position of the super keyword
7237 wildcard.sourceEnd = wildcard.bound.sourceEnd;
7238 this.intPtr--; // remove end position of the '?'
7239 wildcard.sourceStart = this.intStack[this.intPtr--];
7240 this.genericsStack[this.genericsPtr] = wildcard;
7242 protected void consumeWildcardBounds2Extends() {
7243 Wildcard wildcard = new Wildcard(Wildcard.EXTENDS);
7244 wildcard.bound = (TypeReference) this.genericsStack[this.genericsPtr];
7245 wildcard.sourceEnd = wildcard.bound.sourceEnd;
7246 this.intPtr--; // remove end position of the '?'
7247 wildcard.sourceStart = this.intStack[this.intPtr--];
7248 this.genericsStack[this.genericsPtr] = wildcard;
7250 protected void consumeWildcardBounds2Super() {
7251 Wildcard wildcard = new Wildcard(Wildcard.SUPER);
7252 wildcard.bound = (TypeReference) this.genericsStack[this.genericsPtr];
7253 this.intPtr--; // remove the starting position of the super keyword
7254 wildcard.sourceEnd = wildcard.bound.sourceEnd;
7255 this.intPtr--; // remove end position of the '?'
7256 wildcard.sourceStart = this.intStack[this.intPtr--];
7257 this.genericsStack[this.genericsPtr] = wildcard;
7259 protected void consumeWildcardBounds3Extends() {
7260 Wildcard wildcard = new Wildcard(Wildcard.EXTENDS);
7261 wildcard.bound = (TypeReference) this.genericsStack[this.genericsPtr];
7262 wildcard.sourceEnd = wildcard.bound.sourceEnd;
7263 this.intPtr--; // remove end position of the '?'
7264 wildcard.sourceStart = this.intStack[this.intPtr--];
7265 this.genericsStack[this.genericsPtr] = wildcard;
7267 protected void consumeWildcardBounds3Super() {
7268 Wildcard wildcard = new Wildcard(Wildcard.SUPER);
7269 wildcard.bound = (TypeReference) this.genericsStack[this.genericsPtr];
7270 this.intPtr--; // remove the starting position of the super keyword
7271 wildcard.sourceEnd = wildcard.bound.sourceEnd;
7272 this.intPtr--; // remove end position of the '?'
7273 wildcard.sourceStart = this.intStack[this.intPtr--];
7274 this.genericsStack[this.genericsPtr] = wildcard;
7276 protected void consumeWildcardBoundsExtends() {
7277 Wildcard wildcard = new Wildcard(Wildcard.EXTENDS);
7278 wildcard.bound = getTypeReference(this.intStack[this.intPtr--]);
7279 wildcard.sourceEnd = wildcard.bound.sourceEnd;
7280 this.intPtr--; // remove end position of the '?'
7281 wildcard.sourceStart = this.intStack[this.intPtr--];
7282 pushOnGenericsStack(wildcard);
7284 protected void consumeWildcardBoundsSuper() {
7285 Wildcard wildcard = new Wildcard(Wildcard.SUPER);
7286 wildcard.bound = getTypeReference(this.intStack[this.intPtr--]);
7287 this.intPtr--; // remove the starting position of the super keyword
7288 wildcard.sourceEnd = wildcard.bound.sourceEnd;
7289 this.intPtr--; // remove end position of the '?'
7290 wildcard.sourceStart = this.intStack[this.intPtr--];
7291 pushOnGenericsStack(wildcard);
7293 protected void consumeWildcardWithBounds() {
7295 // The wildcard is created by the consumeWildcardBoundsExtends or by consumeWildcardBoundsSuper
7298 * Given the current comment stack, answer whether some comment is available in a certain exclusive range
7300 * @param sourceStart int
7301 * @param sourceEnd int
7304 public boolean containsComment(int sourceStart, int sourceEnd) {
7305 int iComment = this.scanner.commentPtr;
7306 for (; iComment >= 0; iComment--) {
7307 int commentStart = this.scanner.commentStarts[iComment];
7308 // ignore comments before start
7309 if (commentStart < sourceStart) continue;
7310 // ignore comments after end
7311 if (commentStart > sourceEnd) continue;
7316 public MethodDeclaration convertToMethodDeclaration(ConstructorDeclaration c, CompilationResult compilationResult) {
7317 MethodDeclaration m = new MethodDeclaration(compilationResult);
7318 m.typeParameters = c.typeParameters;
7319 m.sourceStart = c.sourceStart;
7320 m.sourceEnd = c.sourceEnd;
7321 m.bodyStart = c.bodyStart;
7322 m.bodyEnd = c.bodyEnd;
7323 m.declarationSourceEnd = c.declarationSourceEnd;
7324 m.declarationSourceStart = c.declarationSourceStart;
7325 m.selector = c.selector;
7326 m.statements = c.statements;
7327 m.modifiers = c.modifiers;
7328 m.annotations = c.annotations;
7329 m.arguments = c.arguments;
7330 m.thrownExceptions = c.thrownExceptions;
7331 m.explicitDeclarations = c.explicitDeclarations;
7332 m.returnType = null;
7335 protected TypeReference copyDims(TypeReference typeRef, int dim) {
7336 return typeRef.copyDims(dim);
7338 protected FieldDeclaration createFieldDeclaration(char[] fieldDeclarationName, int sourceStart, int sourceEnd) {
7339 return new FieldDeclaration(fieldDeclarationName, sourceStart, sourceEnd);
7342 protected LocalDeclaration createLocalDeclaration(char[] localDeclarationName, int sourceStart, int sourceEnd) {
7343 return new LocalDeclaration(localDeclarationName, sourceStart, sourceEnd);
7345 protected RecoveredType currentRecoveryType() {
7346 if(this.currentElement != null) {
7347 if(this.currentElement instanceof RecoveredType) {
7348 return (RecoveredType) this.currentElement;
7350 return this.currentElement.enclosingType();
7355 public CompilationUnitDeclaration dietParse(ICompilationUnit sourceUnit, CompilationResult compilationResult) {
7357 CompilationUnitDeclaration parsedUnit;
7358 boolean old = this.diet;
7361 parsedUnit = parse(sourceUnit, compilationResult);
7368 protected void dispatchDeclarationInto(int length) {
7369 /* they are length on this.astStack that should go into
7370 methods fields constructors lists of the typeDecl
7372 Return if there is a constructor declaration in the methods declaration */
7375 // Looks for the size of each array .
7379 int[] flag = new int[length + 1]; //plus one -- see <HERE>
7380 int size1 = 0, size2 = 0, size3 = 0;
7381 boolean hasAbstractMethods = false;
7382 for (int i = length - 1; i >= 0; i--) {
7383 ASTNode astNode = this.astStack[this.astPtr--];
7384 if (astNode instanceof AbstractMethodDeclaration) {
7385 //methods and constructors have been regrouped into one single list
7388 if (((AbstractMethodDeclaration) astNode).isAbstract()) {
7389 hasAbstractMethods = true;
7391 } else if (astNode instanceof TypeDeclaration) {
7402 TypeDeclaration typeDecl = (TypeDeclaration) this.astStack[this.astPtr];
7404 typeDecl.fields = new FieldDeclaration[size1];
7407 typeDecl.methods = new AbstractMethodDeclaration[size2];
7408 if (hasAbstractMethods) typeDecl.bits |= ASTNode.HasAbstractMethods;
7411 typeDecl.memberTypes = new TypeDeclaration[size3];
7415 size1 = size2 = size3 = 0;
7416 int flagI = flag[0], start = 0;
7418 for (int end = 0; end <= length; end++) //<HERE> the plus one allows to
7420 if (flagI != flag[end]) //treat the last element as a ended flag.....
7424 size1 += (length2 = end - start);
7427 this.astPtr + start + 1,
7433 size2 += (length2 = end - start);
7436 this.astPtr + start + 1,
7442 size3 += (length2 = end - start);
7445 this.astPtr + start + 1,
7446 typeDecl.memberTypes,
7451 flagI = flag[start = end];
7455 if (typeDecl.memberTypes != null) {
7456 for (int i = typeDecl.memberTypes.length - 1; i >= 0; i--) {
7457 typeDecl.memberTypes[i].enclosingType = typeDecl;
7461 protected void dispatchDeclarationIntoEnumDeclaration(int length) {
7465 int[] flag = new int[length + 1]; //plus one -- see <HERE>
7466 int size1 = 0, size2 = 0, size3 = 0;
7467 TypeDeclaration enumDeclaration = (TypeDeclaration) this.astStack[this.astPtr - length];
7468 boolean hasAbstractMethods = false;
7469 for (int i = length - 1; i >= 0; i--) {
7470 ASTNode astNode = this.astStack[this.astPtr--];
7471 if (astNode instanceof AbstractMethodDeclaration) {
7472 //methods and constructors have been regrouped into one single list
7475 if (((AbstractMethodDeclaration) astNode).isAbstract()) {
7476 hasAbstractMethods = true;
7478 } else if (astNode instanceof TypeDeclaration) {
7481 } else if (astNode instanceof FieldDeclaration) {
7484 // if(astNode instanceof EnumConstant) {
7485 // EnumConstant constant = (EnumConstant) astNode;
7486 // ((AllocationExpression)constant.initialization).type = new SingleTypeReference(enumDeclaration.name,
7487 // (((long) enumDeclaration.sourceStart) << 32) + enumDeclaration.sourceEnd);
7494 enumDeclaration.fields = new FieldDeclaration[size1];
7497 enumDeclaration.methods = new AbstractMethodDeclaration[size2];
7498 if (hasAbstractMethods) enumDeclaration.bits |= ASTNode.HasAbstractMethods;
7501 enumDeclaration.memberTypes = new TypeDeclaration[size3];
7505 size1 = size2 = size3 = 0;
7506 int flagI = flag[0], start = 0;
7508 for (int end = 0; end <= length; end++) //<HERE> the plus one allows to
7510 if (flagI != flag[end]) //treat the last element as a ended flag.....
7514 size1 += (length2 = end - start);
7517 this.astPtr + start + 1,
7518 enumDeclaration.fields,
7523 size2 += (length2 = end - start);
7526 this.astPtr + start + 1,
7527 enumDeclaration.methods,
7532 size3 += (length2 = end - start);
7535 this.astPtr + start + 1,
7536 enumDeclaration.memberTypes,
7541 flagI = flag[start = end];
7545 if (enumDeclaration.memberTypes != null) {
7546 for (int i = enumDeclaration.memberTypes.length - 1; i >= 0; i--) {
7547 enumDeclaration.memberTypes[i].enclosingType = enumDeclaration;
7550 protected CompilationUnitDeclaration endParse(int act) {
7554 if (this.currentElement != null){
7555 this.currentElement.topElement().updateParseTree();
7556 if (VERBOSE_RECOVERY){
7557 System.out.print(Util.bind("parser.syntaxRecovery")); //$NON-NLS-1$
7558 System.out.println("--------------------------"); //$NON-NLS-1$
7559 System.out.println(this.compilationUnit);
7560 System.out.println("----------------------------------"); //$NON-NLS-1$
7563 if (this.diet & VERBOSE_RECOVERY){
7564 System.out.print(Util.bind("parser.regularParse")); //$NON-NLS-1$
7565 System.out.println("--------------------------"); //$NON-NLS-1$
7566 System.out.println(this.compilationUnit);
7567 System.out.println("----------------------------------"); //$NON-NLS-1$
7570 persistLineSeparatorPositions();
7571 for (int i = 0; i < this.scanner.foundTaskCount; i++){
7572 problemReporter().task(
7573 new String(this.scanner.foundTaskTags[i]),
7574 new String(this.scanner.foundTaskMessages[i]),
7575 this.scanner.foundTaskPriorities[i] == null ? null : new String(this.scanner.foundTaskPriorities[i]),
7576 this.scanner.foundTaskPositions[i][0],
7577 this.scanner.foundTaskPositions[i][1]);
7579 return this.compilationUnit;
7582 * Flush comments defined prior to a given positions.
7584 * Note: comments are stacked in syntactical order
7586 * Either answer given <position>, or the end position of a comment line
7587 * immediately following the <position> (same line)
7591 * } // end of method foo
7594 public int flushCommentsDefinedPriorTo(int position) {
7596 int lastCommentIndex = this.scanner.commentPtr;
7597 if (lastCommentIndex < 0) return position; // no comment
7599 // compute the index of the first obsolete comment
7600 int index = lastCommentIndex;
7603 int commentEnd = this.scanner.commentStops[index];
7604 if (commentEnd < 0) commentEnd = -commentEnd; // negative end position for non-javadoc comments
7605 if (commentEnd <= position){
7611 // if the source at <position> is immediately followed by a line comment, then
7612 // flush this comment and shift <position> to the comment end.
7613 if (validCount > 0){
7614 int immediateCommentEnd = -this.scanner.commentStops[index+1]; //non-javadoc comment end positions are negative
7615 if (immediateCommentEnd > 0){ // only tolerating non-javadoc comments
7616 // is there any line break until the end of the immediate comment ? (thus only tolerating line comment)
7617 immediateCommentEnd--; // comment end in one char too far
7618 if (this.scanner.getLineNumber(position) == this.scanner.getLineNumber(immediateCommentEnd)){
7619 position = immediateCommentEnd;
7620 validCount--; // flush this comment
7626 if (index < 0) return position; // no obsolete comment
7628 if (validCount > 0){ // move valid comment infos, overriding obsolete comment infos
7629 System.arraycopy(this.scanner.commentStarts, index + 1, this.scanner.commentStarts, 0, validCount);
7630 System.arraycopy(this.scanner.commentStops, index + 1, this.scanner.commentStops, 0, validCount);
7632 this.scanner.commentPtr = validCount - 1;
7635 public int getFirstToken() {
7636 // the first token is a virtual token that
7637 // allows the parser to parse several goals
7638 // even if they aren't LALR(1)....
7639 // Goal ::= '++' CompilationUnit
7640 // Goal ::= '--' MethodBody
7641 // Goal ::= '==' ConstructorBody
7643 // Goal ::= '>>' StaticInitializer
7644 // Goal ::= '>>' Block
7645 // -- error recovery
7646 // Goal ::= '>>>' Headers
7647 // Goal ::= '*' BlockStatements
7648 // Goal ::= '*' MethodPushModifiersHeader
7650 // Goal ::= '&&' FieldDeclaration
7651 // Goal ::= '||' ImportDeclaration
7652 // Goal ::= '?' PackageDeclaration
7653 // Goal ::= '+' TypeDeclaration
7654 // Goal ::= '/' GenericMethodDeclaration
7655 // Goal ::= '&' ClassBodyDeclaration
7657 // Goal ::= '%' Expression
7658 // -- completion parser
7659 // Goal ::= '!' ConstructorBlockStatementsopt
7660 // Goal ::= '~' BlockStatementsopt
7662 return this.firstToken;
7665 * Answer back an array of sourceStart/sourceEnd positions of the available JavaDoc comments.
7666 * The array is a flattened structure: 2*n entries with consecutives start and end positions.
7668 * If no JavaDoc is available, then null is answered instead of an empty array.
7670 * e.g. { 10, 20, 25, 45 } --> javadoc1 from 10 to 20, javadoc2 from 25 to 45
7672 public int[] getJavaDocPositions() {
7674 int javadocCount = 0;
7675 for (int i = 0, max = this.scanner.commentPtr; i <= max; i++){
7676 // javadoc only (non javadoc comment have negative end positions.)
7677 if (this.scanner.commentStops[i] > 0){
7681 if (javadocCount == 0) return null;
7683 int[] positions = new int[2*javadocCount];
7685 for (int i = 0, max = this.scanner.commentPtr; i <= max; i++){
7686 // javadoc only (non javadoc comment have negative end positions.)
7687 if (this.scanner.commentStops[i] > 0){
7688 positions[index++] = this.scanner.commentStarts[i];
7689 positions[index++] = this.scanner.commentStops[i]-1; //stop is one over
7694 public void getMethodBodies(CompilationUnitDeclaration unit) {
7695 //fill the methods bodies in order for the code to be generated
7697 if (unit == null) return;
7699 if (unit.ignoreMethodBodies) {
7700 unit.ignoreFurtherInvestigation = true;
7702 // if initial diet parse did not work, no need to dig into method bodies.
7705 if ((unit.bits & ASTNode.HasAllMethodBodies) != 0)
7706 return; //work already done ...
7708 // save existing values to restore them at the end of the parsing process
7709 // see bug 47079 for more details
7710 int[] oldLineEnds = this.scanner.lineEnds;
7711 int oldLinePtr = this.scanner.linePtr;
7713 //real parse of the method....
7714 CompilationResult compilationResult = unit.compilationResult;
7715 this.scanner.setSource(compilationResult);
7717 if (this.javadocParser != null && this.javadocParser.checkDocComment) {
7718 char[] contents = compilationResult.compilationUnit.getContents();
7719 this.javadocParser.scanner.setSource(contents);
7721 if (unit.types != null) {
7722 for (int i = unit.types.length; --i >= 0;)
7723 unit.types[i].parseMethod(this, unit);
7726 // tag unit has having read bodies
7727 unit.bits |= ASTNode.HasAllMethodBodies;
7729 // this is done to prevent any side effects on the compilation unit result
7730 // line separator positions array.
7731 this.scanner.lineEnds = oldLineEnds;
7732 this.scanner.linePtr = oldLinePtr;
7734 protected char getNextCharacter(char[] comment, int[] index) {
7735 char nextCharacter = comment[index[0]++];
7736 switch(nextCharacter) {
7740 while (comment[index[0]] == 'u') index[0]++;
7741 if (!(((c1 = Character.getNumericValue(comment[index[0]++])) > 15
7743 || ((c2 = Character.getNumericValue(comment[index[0]++])) > 15 || c2 < 0)
7744 || ((c3 = Character.getNumericValue(comment[index[0]++])) > 15 || c3 < 0)
7745 || ((c4 = Character.getNumericValue(comment[index[0]++])) > 15 || c4 < 0))) {
7746 nextCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
7750 return nextCharacter;
7752 protected Expression getTypeReference(Expression exp) {
7754 exp.bits &= ~ASTNode.RestrictiveFlagMASK;
7755 exp.bits |= Binding.TYPE;
7758 protected TypeReference getTypeReference(int dim) {
7759 /* build a Reference on a variable that may be qualified or not
7760 This variable is a type reference and dim will be its dimensions*/
7763 int length = this.identifierLengthStack[this.identifierLengthPtr--];
7764 if (length < 0) { //flag for precompiled type reference on base types
7765 ref = TypeReference.baseTypeReference(-length, dim);
7766 ref.sourceStart = this.intStack[this.intPtr--];
7768 ref.sourceEnd = this.intStack[this.intPtr--];
7771 ref.sourceEnd = this.endPosition;
7774 int numberOfIdentifiers = this.genericsIdentifiersLengthStack[this.genericsIdentifiersLengthPtr--];
7775 if (length != numberOfIdentifiers || this.genericsLengthStack[this.genericsLengthPtr] != 0) {
7777 ref = getTypeReferenceForGenericType(dim, length, numberOfIdentifiers);
7778 } else if (length == 1) {
7779 // single variable reference
7780 this.genericsLengthPtr--; // pop the 0
7783 new SingleTypeReference(
7784 this.identifierStack[this.identifierPtr],
7785 this.identifierPositionStack[this.identifierPtr--]);
7788 new ArrayTypeReference(
7789 this.identifierStack[this.identifierPtr],
7791 this.identifierPositionStack[this.identifierPtr--]);
7792 ref.sourceEnd = this.endPosition;
7795 this.genericsLengthPtr--;
7796 //Qualified variable reference
7797 char[][] tokens = new char[length][];
7798 this.identifierPtr -= length;
7799 long[] positions = new long[length];
7800 System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
7802 this.identifierPositionStack,
7803 this.identifierPtr + 1,
7808 ref = new QualifiedTypeReference(tokens, positions);
7810 ref = new ArrayQualifiedTypeReference(tokens, dim, positions);
7811 ref.sourceEnd = this.endPosition;
7817 protected TypeReference getTypeReferenceForGenericType(int dim, int identifierLength, int numberOfIdentifiers) {
7818 if (identifierLength == 1 && numberOfIdentifiers == 1) {
7819 int currentTypeArgumentsLength = this.genericsLengthStack[this.genericsLengthPtr--];
7820 TypeReference[] typeArguments = new TypeReference[currentTypeArgumentsLength];
7821 this.genericsPtr -= currentTypeArgumentsLength;
7822 System.arraycopy(this.genericsStack, this.genericsPtr + 1, typeArguments, 0, currentTypeArgumentsLength);
7823 ParameterizedSingleTypeReference parameterizedSingleTypeReference = new ParameterizedSingleTypeReference(this.identifierStack[this.identifierPtr], typeArguments, dim, this.identifierPositionStack[this.identifierPtr--]);
7825 parameterizedSingleTypeReference.sourceEnd = this.endPosition;
7827 return parameterizedSingleTypeReference;
7829 TypeReference[][] typeArguments = new TypeReference[numberOfIdentifiers][];
7830 char[][] tokens = new char[numberOfIdentifiers][];
7831 long[] positions = new long[numberOfIdentifiers];
7832 int index = numberOfIdentifiers;
7833 int currentIdentifiersLength = identifierLength;
7835 int currentTypeArgumentsLength = this.genericsLengthStack[this.genericsLengthPtr--];
7836 if (currentTypeArgumentsLength != 0) {
7837 this.genericsPtr -= currentTypeArgumentsLength;
7838 System.arraycopy(this.genericsStack, this.genericsPtr + 1, typeArguments[index - 1] = new TypeReference[currentTypeArgumentsLength], 0, currentTypeArgumentsLength);
7840 switch(currentIdentifiersLength) {
7842 // we are in a case A<B>.C<D> or A<B>.C<D>
7843 tokens[index - 1] = this.identifierStack[this.identifierPtr];
7844 positions[index - 1] = this.identifierPositionStack[this.identifierPtr--];
7847 // we are in a case A.B.C<B>.C<D> or A.B.C<B>...
7848 this.identifierPtr -= currentIdentifiersLength;
7849 System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, index - currentIdentifiersLength, currentIdentifiersLength);
7850 System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, index - currentIdentifiersLength, currentIdentifiersLength);
7852 index -= currentIdentifiersLength;
7854 currentIdentifiersLength = this.identifierLengthStack[this.identifierLengthPtr--];
7857 return new ParameterizedQualifiedTypeReference(tokens, typeArguments, dim, positions);
7860 protected NameReference getUnspecifiedReference() {
7861 /* build a (unspecified) NameReference which may be qualified*/
7865 if ((length = this.identifierLengthStack[this.identifierLengthPtr--]) == 1)
7866 // single variable reference
7868 new SingleNameReference(
7869 this.identifierStack[this.identifierPtr],
7870 this.identifierPositionStack[this.identifierPtr--]);
7872 //Qualified variable reference
7874 char[][] tokens = new char[length][];
7875 this.identifierPtr -= length;
7876 System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
7877 long[] positions = new long[length];
7878 System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
7880 new QualifiedNameReference(tokens,
7882 (int) (this.identifierPositionStack[this.identifierPtr + 1] >> 32), // sourceStart
7883 (int) this.identifierPositionStack[this.identifierPtr + length]); // sourceEnd
7887 protected NameReference getUnspecifiedReferenceOptimized() {
7888 /* build a (unspecified) NameReference which may be qualified
7889 The optimization occurs for qualified reference while we are
7890 certain in this case the last item of the qualified name is
7891 a field access. This optimization is IMPORTANT while it results
7892 that when a NameReference is build, the type checker should always
7893 look for that it is not a type reference */
7897 if ((length = this.identifierLengthStack[this.identifierLengthPtr--]) == 1) {
7898 // single variable reference
7900 new SingleNameReference(
7901 this.identifierStack[this.identifierPtr],
7902 this.identifierPositionStack[this.identifierPtr--]);
7903 ref.bits &= ~ASTNode.RestrictiveFlagMASK;
7904 ref.bits |= Binding.LOCAL | Binding.FIELD;
7908 //Qualified-variable-reference
7909 //In fact it is variable-reference DOT field-ref , but it would result in a type
7910 //conflict tha can be only reduce by making a superclass (or inetrface ) between
7911 //nameReference and FiledReference or putting FieldReference under NameReference
7912 //or else..........This optimisation is not really relevant so just leave as it is
7914 char[][] tokens = new char[length][];
7915 this.identifierPtr -= length;
7916 System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
7917 long[] positions = new long[length];
7918 System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
7919 ref = new QualifiedNameReference(
7922 (int) (this.identifierPositionStack[this.identifierPtr + 1] >> 32), // sourceStart
7923 (int) this.identifierPositionStack[this.identifierPtr + length]); // sourceEnd
7924 ref.bits &= ~ASTNode.RestrictiveFlagMASK;
7925 ref.bits |= Binding.LOCAL | Binding.FIELD;
7928 public void goForBlockStatementsopt() {
7929 //tells the scanner to go for block statements opt parsing
7931 this.firstToken = TokenNameTWIDDLE;
7932 this.scanner.recordLineSeparator = false;
7934 public void goForBlockStatementsOrCatchHeader() {
7935 //tells the scanner to go for block statements or method headers parsing
7937 this.firstToken = TokenNameMULTIPLY;
7938 this.scanner.recordLineSeparator = false;
7940 public void goForClassBodyDeclarations() {
7941 //tells the scanner to go for any body declarations parsing
7943 this.firstToken = TokenNameAND;
7944 this.scanner.recordLineSeparator = true;
7946 public void goForCompilationUnit(){
7947 //tells the scanner to go for compilation unit parsing
7949 this.firstToken = TokenNamePLUS_PLUS ;
7950 this.scanner.foundTaskCount = 0;
7951 this.scanner.recordLineSeparator = true;
7952 this.scanner.currentLine= null;
7954 public void goForExpression() {
7955 //tells the scanner to go for an expression parsing
7957 this.firstToken = TokenNameREMAINDER;
7958 this.scanner.recordLineSeparator = true; // recovery goals must record line separators
7960 public void goForFieldDeclaration(){
7961 //tells the scanner to go for field declaration parsing
7963 this.firstToken = TokenNameAND_AND ;
7964 this.scanner.recordLineSeparator = true;
7966 public void goForGenericMethodDeclaration(){
7967 //tells the scanner to go for generic method declarations parsing
7969 this.firstToken = TokenNameDIVIDE;
7970 this.scanner.recordLineSeparator = true;
7972 public void goForHeaders(){
7973 //tells the scanner to go for headers only parsing
7974 RecoveredType currentType = this.currentRecoveryType();
7975 if(currentType != null && currentType.insideEnumConstantPart) {
7976 this.firstToken = TokenNameNOT;
7978 this.firstToken = TokenNameUNSIGNED_RIGHT_SHIFT;
7980 this.scanner.recordLineSeparator = true; // recovery goals must record line separators
7982 public void goForImportDeclaration(){
7983 //tells the scanner to go for import declaration parsing
7985 this.firstToken = TokenNameOR_OR ;
7986 this.scanner.recordLineSeparator = true;
7988 public void goForInitializer(){
7989 //tells the scanner to go for initializer parsing
7991 this.firstToken = TokenNameRIGHT_SHIFT ;
7992 this.scanner.recordLineSeparator = false;
7994 public void goForMemberValue() {
7995 //tells the scanner to go for a memeber value parsing
7997 this.firstToken = TokenNameOR_OR;
7998 this.scanner.recordLineSeparator = true; // recovery goals must record line separators
8000 public void goForMethodBody(){
8001 //tells the scanner to go for method body parsing
8003 this.firstToken = TokenNameMINUS_MINUS ;
8004 this.scanner.recordLineSeparator = false;
8006 public void goForPackageDeclaration() {
8007 //tells the scanner to go for package declaration parsing
8009 this.firstToken = TokenNameQUESTION;
8010 this.scanner.recordLineSeparator = true;
8012 public void goForTypeDeclaration() {
8013 //tells the scanner to go for type (interface or class) declaration parsing
8015 this.firstToken = TokenNamePLUS;
8016 this.scanner.recordLineSeparator = true;
8018 protected void ignoreExpressionAssignment() {
8019 // Assignment ::= InvalidArrayInitializerAssignement
8020 // encoded operator would be: this.intStack[this.intPtr]
8022 ArrayInitializer arrayInitializer = (ArrayInitializer) this.expressionStack[this.expressionPtr--];
8023 this.expressionLengthPtr -- ;
8024 // report a syntax error and abort parsing
8025 problemReporter().arrayConstantsOnlyInArrayInitializers(arrayInitializer.sourceStart, arrayInitializer.sourceEnd);
8027 protected void ignoreInterfaceDeclaration() {
8028 // BlockStatement ::= InvalidInterfaceDeclaration
8029 //InterfaceDeclaration ::= Modifiersopt 'interface' 'Identifier' ExtendsInterfacesopt InterfaceHeader InterfaceBody
8031 // length declarations
8033 if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) {
8034 //there are length declarations
8035 //dispatch according to the type of the declarations
8036 dispatchDeclarationInto(length);
8039 flushCommentsDefinedPriorTo(this.endStatementPosition);
8041 // report the problem and continue parsing
8042 TypeDeclaration typeDecl = (TypeDeclaration) this.astStack[this.astPtr];
8043 typeDecl.bodyEnd = this.endStatementPosition;
8044 problemReporter().cannotDeclareLocalInterface(typeDecl.name, typeDecl.sourceStart, typeDecl.sourceEnd);
8046 // mark initializers with local type mark if needed
8047 markInitializersWithLocalType(typeDecl);
8049 // remove the ast node created in interface header
8051 pushOnAstLengthStack(-1);
8054 protected void ignoreInvalidConstructorDeclaration(boolean hasBody) {
8055 // InvalidConstructorDeclaration ::= ConstructorHeader ConstructorBody ==> true
8056 // InvalidConstructorDeclaration ::= ConstructorHeader ';' ==> false
8059 this.astStack : modifiers arguments throws statements
8060 this.identifierStack : name
8062 this.astStack : MethodDeclaration
8063 this.identifierStack :
8066 // pop the position of the { (body of the method) pushed in block decl
8072 this.realBlockPtr--;
8076 if (hasBody && ((length = this.astLengthStack[this.astLengthPtr--]) != 0)) {
8077 this.astPtr -= length;
8079 ConstructorDeclaration constructorDeclaration = (ConstructorDeclaration) this.astStack[this.astPtr];
8080 constructorDeclaration.bodyEnd = this.endStatementPosition;
8081 constructorDeclaration.declarationSourceEnd = flushCommentsDefinedPriorTo(this.endStatementPosition);
8083 constructorDeclaration.modifiers |= AccSemicolonBody;
8086 protected void ignoreMethodBody() {
8087 // InterfaceMemberDeclaration ::= InvalidMethodDeclaration
8090 this.astStack : modifiers arguments throws statements
8091 this.identifierStack : type name
8092 this.intStack : dim dim dim
8094 this.astStack : MethodDeclaration
8095 this.identifierStack :
8099 // pop the position of the { (body of the method) pushed in block decl
8101 // retrieve end position of method declarator
8104 this.realBlockPtr--;
8106 if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) {
8107 this.astPtr -= length;
8110 //watch for } that could be given as a unicode ! ( u007D is '}' )
8111 MethodDeclaration md = (MethodDeclaration) this.astStack[this.astPtr];
8112 md.bodyEnd = this.endPosition;
8113 md.declarationSourceEnd = flushCommentsDefinedPriorTo(this.endStatementPosition);
8115 // report the problem and continue the parsing - narrowing the problem onto the method
8116 problemReporter().abstractMethodNeedingNoBody(md);
8118 public void initialize() {
8119 //positionning the parser for a new compilation unit
8120 //avoiding stack reallocation and all that....
8122 this.astLengthPtr = -1;
8123 this.expressionPtr = -1;
8124 this.expressionLengthPtr = -1;
8125 this.identifierPtr = -1;
8126 this.identifierLengthPtr = -1;
8128 this.nestedMethod[this.nestedType = 0] = 0; // need to reset for further reuse
8129 this.variablesCounter[this.nestedType] = 0;
8130 this.dimensions = 0 ;
8131 this.realBlockPtr = -1;
8132 this.compilationUnit = null;
8133 this.referenceContext = null;
8134 this.endStatementPosition = 0;
8136 //remove objects from stack too, while the same parser/compiler couple is
8137 //re-used between two compilations ....
8139 int astLength = this.astStack.length;
8140 if (this.noAstNodes.length < astLength){
8141 this.noAstNodes = new ASTNode[astLength];
8142 //System.out.println("Resized AST stacks : "+ astLength);
8145 System.arraycopy(this.noAstNodes, 0, this.astStack, 0, astLength);
8147 int expressionLength = this.expressionStack.length;
8148 if (this.noExpressions.length < expressionLength){
8149 this.noExpressions = new Expression[expressionLength];
8150 //System.out.println("Resized EXPR stacks : "+ expressionLength);
8152 System.arraycopy(this.noExpressions, 0, this.expressionStack, 0, expressionLength);
8154 // reset this.scanner state
8155 this.scanner.commentPtr = -1;
8156 this.scanner.foundTaskCount = 0;
8157 this.scanner.eofPosition = Integer.MAX_VALUE;
8158 this.scanner.wasNonExternalizedStringLiteral = false;
8159 this.scanner.nonNLSStrings = null;
8160 this.scanner.currentLine = null;
8165 this.lastCheckPoint = -1;
8166 this.currentElement = null;
8167 this.restartRecovery = false;
8168 this.hasReportedError = false;
8169 this.recoveredStaticInitializerStart = 0;
8170 this.lastIgnoredToken = -1;
8171 this.lastErrorEndPosition = -1;
8172 this.lastErrorEndPositionBeforeRecovery = -1;
8173 this.lastJavadocEnd = -1;
8174 this.listLength = 0;
8175 this.listTypeParameterLength = 0;
8177 this.rBraceStart = 0;
8179 this.rBraceSuccessorStart = 0;
8181 this.genericsIdentifiersLengthPtr = -1;
8182 this.genericsLengthPtr = -1;
8183 this.genericsPtr = -1;
8185 public void initializeScanner(){
8186 this.scanner = new Scanner(
8188 false /*whitespace*/,
8189 this.options.getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /*nls*/,
8190 this.options.sourceLevel /*sourceLevel*/,
8191 this.options.taskTags/*taskTags*/,
8192 this.options.taskPriorites/*taskPriorities*/,
8193 this.options.isTaskCaseSensitive/*taskCaseSensitive*/);
8195 public void jumpOverMethodBody() {
8196 //on diet parsing.....do not buffer method statements
8198 //the scanner.diet is reinitialized to false
8199 //automatically by the scanner once it has jumped over
8202 if (this.diet && (this.dietInt == 0))
8203 this.scanner.diet = true;
8205 protected void markEnclosingMemberWithLocalType() {
8206 if (this.currentElement != null) return; // this is already done in the recovery code
8207 for (int i = this.astPtr; i >= 0; i--) {
8208 ASTNode node = this.astStack[i];
8209 if (node instanceof AbstractMethodDeclaration
8210 || node instanceof FieldDeclaration
8211 || node instanceof TypeDeclaration) { // mark type for now: all initializers will be marked when added to this type
8212 node.bits |= ASTNode.HasLocalTypeMASK;
8216 // default to reference context (case of parse method body)
8217 if (this.referenceContext instanceof AbstractMethodDeclaration
8218 || this.referenceContext instanceof TypeDeclaration) {
8219 ((ASTNode)this.referenceContext).bits |= ASTNode.HasLocalTypeMASK;
8222 protected void markInitializersWithLocalType(TypeDeclaration type) {
8223 if (type.fields == null || (type.bits & ASTNode.HasLocalTypeMASK) == 0) return;
8224 for (int i = 0, length = type.fields.length; i < length; i++) {
8225 FieldDeclaration field = type.fields[i];
8226 if (field instanceof Initializer) {
8227 field.bits |= ASTNode.HasLocalTypeMASK;
8232 * Move checkpoint location (current implementation is moving it by one token)
8234 * Answers true if successfully moved checkpoint (in other words, it did not attempt to move it
8235 * beyond end of file).
8237 protected boolean moveRecoveryCheckpoint() {
8239 int pos = this.lastCheckPoint;
8240 /* reset this.scanner, and move checkpoint by one token */
8241 this.scanner.startPosition = pos;
8242 this.scanner.currentPosition = pos;
8243 this.scanner.diet = false; // quit jumping over method bodies
8245 /* if about to restart, then no need to shift token */
8246 if (this.restartRecovery){
8247 this.lastIgnoredToken = -1;
8248 this.scanner.currentLine = null;
8252 /* protect against shifting on an invalid token */
8253 this.lastIgnoredToken = this.nextIgnoredToken;
8254 this.nextIgnoredToken = -1;
8257 this.nextIgnoredToken = this.scanner.getNextToken();
8258 if(this.scanner.currentPosition == this.scanner.startPosition){
8259 this.scanner.currentPosition++; // on fake completion identifier
8260 this.nextIgnoredToken = -1;
8263 } catch(InvalidInputException e){
8264 pos = this.scanner.currentPosition;
8266 } while (this.nextIgnoredToken < 0);
8268 if (this.nextIgnoredToken == TokenNameEOF) { // no more recovery after this point
8269 if (this.currentToken == TokenNameEOF) { // already tried one iteration on EOF
8270 this.scanner.currentLine = null;
8274 this.lastCheckPoint = this.scanner.currentPosition;
8276 /* reset this.scanner again to previous checkpoint location*/
8277 this.scanner.startPosition = pos;
8278 this.scanner.currentPosition = pos;
8279 this.scanner.commentPtr = -1;
8280 this.scanner.foundTaskCount = 0;
8281 this.scanner.currentLine = null;
8286 The following implementation moves the checkpoint location by one line:
8288 int pos = this.lastCheckPoint;
8289 // reset this.scanner, and move checkpoint by one token
8290 this.scanner.startPosition = pos;
8291 this.scanner.currentPosition = pos;
8292 this.scanner.diet = false; // quit jumping over method bodies
8294 // if about to restart, then no need to shift token
8295 if (this.restartRecovery){
8296 this.lastIgnoredToken = -1;
8300 // protect against shifting on an invalid token
8301 this.lastIgnoredToken = this.nextIgnoredToken;
8302 this.nextIgnoredToken = -1;
8304 boolean wasTokenizingWhiteSpace = this.scanner.tokenizeWhiteSpace;
8305 this.scanner.tokenizeWhiteSpace = true;
8309 this.nextIgnoredToken = this.scanner.getNextToken();
8310 switch(this.nextIgnoredToken){
8311 case Scanner.TokenNameWHITESPACE :
8312 if(this.scanner.getLineNumber(this.scanner.startPosition)
8313 == this.scanner.getLineNumber(this.scanner.currentPosition)){
8314 this.nextIgnoredToken = -1;
8317 case TokenNameSEMICOLON :
8318 case TokenNameLBRACE :
8319 case TokenNameRBRACE :
8321 case TokenNameIdentifier :
8322 if(this.scanner.currentPosition == this.scanner.startPosition){
8323 this.scanner.currentPosition++; // on fake completion identifier
8326 this.nextIgnoredToken = -1;
8329 break checkpointMove;
8331 } catch(InvalidInputException e){
8332 pos = this.scanner.currentPosition;
8334 } while (this.nextIgnoredToken < 0);
8335 this.scanner.tokenizeWhiteSpace = wasTokenizingWhiteSpace;
8337 if (this.nextIgnoredToken == TokenNameEOF) { // no more recovery after this point
8338 if (this.currentToken == TokenNameEOF) { // already tried one iteration on EOF
8342 this.lastCheckPoint = this.scanner.currentPosition;
8344 // reset this.scanner again to previous checkpoint location
8345 this.scanner.startPosition = pos;
8346 this.scanner.currentPosition = pos;
8347 this.scanner.commentPtr = -1;
8352 protected MessageSend newMessageSend() {
8353 // '(' ArgumentListopt ')'
8354 // the arguments are on the expression stack
8356 MessageSend m = new MessageSend();
8358 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
8359 this.expressionPtr -= length;
8361 this.expressionStack,
8362 this.expressionPtr + 1,
8363 m.arguments = new Expression[length],
8369 protected MessageSend newMessageSendWithTypeArguments() {
8370 MessageSend m = new MessageSend();
8372 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
8373 this.expressionPtr -= length;
8375 this.expressionStack,
8376 this.expressionPtr + 1,
8377 m.arguments = new Expression[length],
8383 protected void optimizedConcatNodeLists() {
8384 /*back from a recursive loop. Virtualy group the
8385 astNode into an array using this.astLengthStack*/
8388 * This is a case where you have two sublists into the this.astStack that you want
8389 * to merge in one list. There is no action required on the this.astStack. The only
8390 * thing you need to do is merge the two lengths specified on the astStackLength.
8391 * The top two length are for example:
8393 * and you want to result in a list like:
8395 * This means that the p could be equals to 0 in case there is no astNode pushed
8396 * on the this.astStack.
8397 * Look at the InterfaceMemberDeclarations for an example.
8398 * This case optimizes the fact that p == 1.
8401 this.astLengthStack[--this.astLengthPtr]++;
8403 /*main loop of the automat
8404 When a rule is reduced, the method consumeRule(int) is called with the number
8405 of the consumed rule. When a terminal is consumed, the method consumeToken(int) is
8406 called in order to remember (when needed) the consumed token */
8407 // (int)asr[asi(act)]
8408 // name[symbol_index[currentKind]]
8409 protected void parse() {
8410 if (DEBUG) System.out.println("-- ENTER INSIDE PARSE METHOD --"); //$NON-NLS-1$
8411 boolean isDietParse = this.diet;
8412 int oldFirstToken = getFirstToken();
8413 this.hasError = false;
8415 this.hasReportedError = false;
8416 int act = START_STATE;
8417 this.stateStackTop = -1;
8418 this.currentToken = getFirstToken();
8419 ProcessTerminals : for (;;) {
8420 int stackLength = this.stack.length;
8421 if (++this.stateStackTop >= stackLength) {
8424 this.stack = new int[stackLength + StackIncrement], 0,
8427 this.stack[this.stateStackTop] = act;
8429 act = tAction(act, this.currentToken);
8430 if (act == ERROR_ACTION || this.restartRecovery) {
8431 int errorPos = this.scanner.currentPosition;
8432 if (!this.hasReportedError) {
8433 this.hasError = true;
8435 if (resumeOnSyntaxError()) {
8436 if (act == ERROR_ACTION) this.lastErrorEndPosition = errorPos;
8438 this.stateStackTop = -1;
8439 this.currentToken = getFirstToken();
8440 continue ProcessTerminals;
8443 break ProcessTerminals;
8445 if (act <= NUM_RULES) {
8446 this.stateStackTop--;
8448 } else if (act > ERROR_ACTION) { /* shift-reduce */
8449 consumeToken(this.currentToken);
8450 if (this.currentElement != null) this.recoveryTokenCheck();
8452 this.currentToken = this.scanner.getNextToken();
8453 } catch(InvalidInputException e){
8454 if (!this.hasReportedError){
8455 this.problemReporter().scannerError(this, e.getMessage());
8456 this.hasReportedError = true;
8458 this.lastCheckPoint = this.scanner.currentPosition;
8459 this.restartRecovery = true;
8461 act -= ERROR_ACTION;
8464 if (act < ACCEPT_ACTION) { /* shift */
8465 consumeToken(this.currentToken);
8466 if (this.currentElement != null) this.recoveryTokenCheck();
8468 this.currentToken = this.scanner.getNextToken();
8469 } catch(InvalidInputException e){
8470 if (!this.hasReportedError){
8471 this.problemReporter().scannerError(this, e.getMessage());
8472 this.hasReportedError = true;
8474 this.lastCheckPoint = this.scanner.currentPosition;
8475 this.restartRecovery = true;
8477 continue ProcessTerminals;
8479 break ProcessTerminals;
8482 ProcessNonTerminals : do { /* reduce */
8484 this.stateStackTop -= (rhs[act] - 1);
8485 act = ntAction(this.stack[this.stateStackTop], lhs[act]);
8486 } while (act <= NUM_RULES);
8490 if (this.reportSyntaxErrorIsRequired && this.hasError) {
8491 reportSyntaxErrors(isDietParse, oldFirstToken);
8493 if (DEBUG) System.out.println("-- EXIT FROM PARSE METHOD --"); //$NON-NLS-1$
8495 public void parse(ConstructorDeclaration cd, CompilationUnitDeclaration unit) {
8496 parse(cd, unit, false);
8498 public void parse(ConstructorDeclaration cd, CompilationUnitDeclaration unit, boolean recordLineSeparator) {
8499 //only parse the method body of cd
8500 //fill out its statements
8502 //convert bugs into parse error
8505 goForBlockStatementsopt();
8506 if (recordLineSeparator) {
8507 this.scanner.recordLineSeparator = true;
8509 this.nestedMethod[this.nestedType]++;
8510 pushOnRealBlockStack(0);
8512 this.referenceContext = cd;
8513 this.compilationUnit = unit;
8515 this.scanner.resetTo(cd.bodyStart, cd.bodyEnd);
8518 } catch (AbortCompilation ex) {
8519 this.lastAct = ERROR_ACTION;
8521 this.nestedMethod[this.nestedType]--;
8524 checkNonNLSAfterBodyEnd(cd.declarationSourceEnd);
8526 if (this.lastAct == ERROR_ACTION) {
8532 cd.explicitDeclarations = this.realBlockStack[this.realBlockPtr--];
8534 if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) {
8535 this.astPtr -= length;
8536 if (this.astStack[this.astPtr + 1] instanceof ExplicitConstructorCall)
8537 //avoid a isSomeThing that would only be used here BUT what is faster between two alternatives ?
8542 cd.statements = new Statement[length - 1],
8545 cd.constructorCall = (ExplicitConstructorCall) this.astStack[this.astPtr + 1];
8546 } else { //need to add explicitly the super();
8550 cd.statements = new Statement[length],
8553 cd.constructorCall = SuperReference.implicitSuperConstructorCall();
8556 cd.constructorCall = SuperReference.implicitSuperConstructorCall();
8557 if (!containsComment(cd.bodyStart, cd.bodyEnd)) {
8558 cd.bits |= ASTNode.UndocumentedEmptyBlockMASK;
8562 if (cd.constructorCall.sourceEnd == 0) {
8563 cd.constructorCall.sourceEnd = cd.sourceEnd;
8564 cd.constructorCall.sourceStart = cd.sourceStart;
8570 FieldDeclaration field,
8571 TypeDeclaration type,
8572 CompilationUnitDeclaration unit,
8573 char[] initializationSource) {
8574 //only parse the initializationSource of the given field
8576 //convert bugs into parse error
8580 this.nestedMethod[this.nestedType]++;
8582 this.referenceContext = type;
8583 this.compilationUnit = unit;
8585 this.scanner.setSource(initializationSource);
8586 this.scanner.resetTo(0, initializationSource.length-1);
8589 } catch (AbortCompilation ex) {
8590 this.lastAct = ERROR_ACTION;
8592 this.nestedMethod[this.nestedType]--;
8595 if (this.lastAct == ERROR_ACTION) {
8599 field.initialization = this.expressionStack[this.expressionPtr];
8601 // mark field with local type if one was found during parsing
8602 if ((type.bits & ASTNode.HasLocalTypeMASK) != 0) {
8603 field.bits |= ASTNode.HasLocalTypeMASK;
8608 public CompilationUnitDeclaration parse(
8609 ICompilationUnit sourceUnit,
8610 CompilationResult compilationResult) {
8611 // parses a compilation unit and manages error handling (even bugs....)
8613 return parse(sourceUnit, compilationResult, -1, -1/*parse without reseting the scanner*/);
8617 public CompilationUnitDeclaration parse(
8618 ICompilationUnit sourceUnit,
8619 CompilationResult compilationResult,
8622 // parses a compilation unit and manages error handling (even bugs....)
8624 CompilationUnitDeclaration unit;
8626 /* automaton initialization */
8628 goForCompilationUnit();
8630 /* scanners initialization */
8631 char[] contents = sourceUnit.getContents();
8632 this.scanner.setSource(contents);
8633 if (end != -1) this.scanner.resetTo(start, end);
8634 if (this.javadocParser != null && this.javadocParser.checkDocComment) {
8635 this.javadocParser.scanner.setSource(contents);
8637 this.javadocParser.scanner.resetTo(start, end);
8641 this.referenceContext =
8642 this.compilationUnit =
8643 new CompilationUnitDeclaration(
8644 this.problemReporter,
8646 this.scanner.source.length);
8650 unit = this.compilationUnit;
8651 this.compilationUnit = null; // reset parser
8652 // tag unit has having read bodies
8653 if (!this.diet) unit.bits |= ASTNode.HasAllMethodBodies;
8660 Initializer initializer,
8661 TypeDeclaration type,
8662 CompilationUnitDeclaration unit) {
8663 //only parse the method body of md
8664 //fill out method statements
8666 //convert bugs into parse error
8669 goForBlockStatementsopt();
8670 this.nestedMethod[this.nestedType]++;
8671 pushOnRealBlockStack(0);
8673 this.referenceContext = type;
8674 this.compilationUnit = unit;
8676 this.scanner.resetTo(initializer.bodyStart, initializer.bodyEnd); // just on the beginning {
8679 } catch (AbortCompilation ex) {
8680 this.lastAct = ERROR_ACTION;
8682 this.nestedMethod[this.nestedType]--;
8685 checkNonNLSAfterBodyEnd(initializer.declarationSourceEnd);
8687 if (this.lastAct == ERROR_ACTION) {
8692 initializer.block.explicitDeclarations = this.realBlockStack[this.realBlockPtr--];
8694 if ((length = this.astLengthStack[this.astLengthPtr--]) > 0) {
8695 System.arraycopy(this.astStack, (this.astPtr -= length) + 1, initializer.block.statements = new Statement[length], 0, length);
8697 // check whether this block at least contains some comment in it
8698 if (!containsComment(initializer.block.sourceStart, initializer.block.sourceEnd)) {
8699 initializer.block.bits |= ASTNode.UndocumentedEmptyBlockMASK;
8703 // mark initializer with local type if one was found during parsing
8704 if ((type.bits & ASTNode.HasLocalTypeMASK) != 0) {
8705 initializer.bits |= ASTNode.HasLocalTypeMASK;
8710 public void parse(MethodDeclaration md, CompilationUnitDeclaration unit) {
8711 //only parse the method body of md
8712 //fill out method statements
8714 //convert bugs into parse error
8716 if (md.isAbstract())
8720 if ((md.modifiers & AccSemicolonBody) != 0)
8724 goForBlockStatementsopt();
8725 this.nestedMethod[this.nestedType]++;
8726 pushOnRealBlockStack(0);
8728 this.referenceContext = md;
8729 this.compilationUnit = unit;
8731 this.scanner.resetTo(md.bodyStart, md.bodyEnd);
8732 // reset the scanner to parser from { down to }
8735 } catch (AbortCompilation ex) {
8736 this.lastAct = ERROR_ACTION;
8738 this.nestedMethod[this.nestedType]--;
8741 checkNonNLSAfterBodyEnd(md.declarationSourceEnd);
8743 if (this.lastAct == ERROR_ACTION) {
8748 md.explicitDeclarations = this.realBlockStack[this.realBlockPtr--];
8750 if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) {
8753 (this.astPtr -= length) + 1,
8754 md.statements = new Statement[length],
8758 if (!containsComment(md.bodyStart, md.bodyEnd)) {
8759 md.bits |= ASTNode.UndocumentedEmptyBlockMASK;
8763 public ASTNode[] parseClassBodyDeclarations(char[] source, int offset, int length, CompilationUnitDeclaration unit) {
8764 /* automaton initialization */
8766 goForClassBodyDeclarations();
8767 /* scanner initialization */
8768 this.scanner.setSource(source);
8769 this.scanner.resetTo(offset, offset + length - 1);
8770 if (this.javadocParser != null && this.javadocParser.checkDocComment) {
8771 this.javadocParser.scanner.setSource(source);
8772 this.javadocParser.scanner.resetTo(offset, offset + length - 1);
8775 /* type declaration should be parsed as member type declaration */
8776 this.nestedType = 1;
8779 this.referenceContext = unit;
8780 this.compilationUnit = unit;
8785 } catch (AbortCompilation ex) {
8786 this.lastAct = ERROR_ACTION;
8789 if (this.lastAct == ERROR_ACTION) {
8793 if ((astLength = this.astLengthStack[this.astLengthPtr--]) != 0) {
8794 ASTNode[] result = new ASTNode[astLength];
8795 this.astPtr -= astLength;
8796 System.arraycopy(this.astStack, this.astPtr + 1, result, 0, astLength);
8801 public Expression parseExpression(char[] source, int offset, int length, CompilationUnitDeclaration unit) {
8805 this.nestedMethod[this.nestedType]++;
8807 this.referenceContext = unit;
8808 this.compilationUnit = unit;
8810 this.scanner.setSource(source);
8811 this.scanner.resetTo(offset, offset + length - 1);
8814 } catch (AbortCompilation ex) {
8815 this.lastAct = ERROR_ACTION;
8817 this.nestedMethod[this.nestedType]--;
8820 if (this.lastAct == ERROR_ACTION) {
8824 return this.expressionStack[this.expressionPtr];
8826 public Expression parseMemberValue(char[] source, int offset, int length, CompilationUnitDeclaration unit) {
8830 this.nestedMethod[this.nestedType]++;
8832 this.referenceContext = unit;
8833 this.compilationUnit = unit;
8835 this.scanner.setSource(source);
8836 this.scanner.resetTo(offset, offset + length - 1);
8839 } catch (AbortCompilation ex) {
8840 this.lastAct = ERROR_ACTION;
8842 this.nestedMethod[this.nestedType]--;
8845 if (this.lastAct == ERROR_ACTION) {
8849 return this.expressionStack[this.expressionPtr];
8851 public void persistLineSeparatorPositions() {
8852 if (this.scanner.recordLineSeparator) {
8853 this.compilationUnit.compilationResult.lineSeparatorPositions = this.scanner.getLineEnds();
8857 * Returns this parser's problem reporter initialized with its reference context.
8858 * Also it is assumed that a problem is going to be reported, so initializes
8859 * the compilation result's line positions.
8861 * @return ProblemReporter
8863 public ProblemReporter problemReporter(){
8864 if (this.scanner.recordLineSeparator) {
8865 this.compilationUnit.compilationResult.lineSeparatorPositions = this.scanner.getLineEnds();
8867 this.problemReporter.referenceContext = this.referenceContext;
8868 return this.problemReporter;
8870 protected void pushIdentifier() {
8871 /*push the consumeToken on the identifier stack.
8872 Increase the total number of identifier in the stack.
8873 identifierPtr points on the next top */
8875 int stackLength = this.identifierStack.length;
8876 if (++this.identifierPtr >= stackLength) {
8878 this.identifierStack, 0,
8879 this.identifierStack = new char[stackLength + 20][], 0,
8882 this.identifierPositionStack, 0,
8883 this.identifierPositionStack = new long[stackLength + 20], 0,
8886 this.identifierStack[this.identifierPtr] = this.scanner.getCurrentIdentifierSource();
8887 this.identifierPositionStack[this.identifierPtr] =
8888 (((long) this.scanner.startPosition) << 32) + (this.scanner.currentPosition - 1);
8890 stackLength = this.identifierLengthStack.length;
8891 if (++this.identifierLengthPtr >= stackLength) {
8893 this.identifierLengthStack, 0,
8894 this.identifierLengthStack = new int[stackLength + 10], 0,
8897 this.identifierLengthStack[this.identifierLengthPtr] = 1;
8899 protected void pushIdentifier(int flag) {
8900 /*push a special flag on the stack :
8901 -zero stands for optional Name
8902 -negative number for direct ref to base types.
8903 identifierLengthPtr points on the top */
8905 int stackLength = this.identifierLengthStack.length;
8906 if (++this.identifierLengthPtr >= stackLength) {
8908 this.identifierLengthStack, 0,
8909 this.identifierLengthStack = new int[stackLength + 10], 0,
8912 this.identifierLengthStack[this.identifierLengthPtr] = flag;
8914 protected void pushOnAstLengthStack(int pos) {
8916 int stackLength = this.astLengthStack.length;
8917 if (++this.astLengthPtr >= stackLength) {
8919 this.astLengthStack, 0,
8920 this.astLengthStack = new int[stackLength + StackIncrement], 0,
8923 this.astLengthStack[this.astLengthPtr] = pos;
8925 protected void pushOnAstStack(ASTNode node) {
8926 /*add a new obj on top of the ast stack
8927 astPtr points on the top*/
8929 int stackLength = this.astStack.length;
8930 if (++this.astPtr >= stackLength) {
8933 this.astStack = new ASTNode[stackLength + AstStackIncrement], 0,
8935 this.astPtr = stackLength;
8937 this.astStack[this.astPtr] = node;
8939 stackLength = this.astLengthStack.length;
8940 if (++this.astLengthPtr >= stackLength) {
8942 this.astLengthStack, 0,
8943 this.astLengthStack = new int[stackLength + AstStackIncrement], 0,
8946 this.astLengthStack[this.astLengthPtr] = 1;
8948 protected void pushOnExpressionStack(Expression expr) {
8950 int stackLength = this.expressionStack.length;
8951 if (++this.expressionPtr >= stackLength) {
8953 this.expressionStack, 0,
8954 this.expressionStack = new Expression[stackLength + ExpressionStackIncrement], 0,
8957 this.expressionStack[this.expressionPtr] = expr;
8959 stackLength = this.expressionLengthStack.length;
8960 if (++this.expressionLengthPtr >= stackLength) {
8962 this.expressionLengthStack, 0,
8963 this.expressionLengthStack = new int[stackLength + ExpressionStackIncrement], 0,
8966 this.expressionLengthStack[this.expressionLengthPtr] = 1;
8968 protected void pushOnExpressionStackLengthStack(int pos) {
8970 int stackLength = this.expressionLengthStack.length;
8971 if (++this.expressionLengthPtr >= stackLength) {
8973 this.expressionLengthStack, 0,
8974 this.expressionLengthStack = new int[stackLength + StackIncrement], 0,
8977 this.expressionLengthStack[this.expressionLengthPtr] = pos;
8979 protected void pushOnGenericsStack(ASTNode node) {
8980 /*add a new obj on top of the generics stack
8981 genericsPtr points on the top*/
8983 int stackLength = this.genericsStack.length;
8984 if (++this.genericsPtr >= stackLength) {
8986 this.genericsStack, 0,
8987 this.genericsStack = new ASTNode[stackLength + GenericsStackIncrement], 0,
8990 this.genericsStack[this.genericsPtr] = node;
8992 stackLength = this.genericsLengthStack.length;
8993 if (++this.genericsLengthPtr >= stackLength) {
8995 this.genericsLengthStack, 0,
8996 this.genericsLengthStack = new int[stackLength + GenericsStackIncrement], 0,
8999 this.genericsLengthStack[this.genericsLengthPtr] = 1;
9001 protected void pushOnGenericsIdentifiersLengthStack(int pos) {
9002 int stackLength = this.genericsIdentifiersLengthStack.length;
9003 if (++this.genericsIdentifiersLengthPtr >= stackLength) {
9005 this.genericsIdentifiersLengthStack, 0,
9006 this.genericsIdentifiersLengthStack = new int[stackLength + GenericsStackIncrement], 0,
9009 this.genericsIdentifiersLengthStack[this.genericsIdentifiersLengthPtr] = pos;
9011 protected void pushOnGenericsLengthStack(int pos) {
9012 int stackLength = this.genericsLengthStack.length;
9013 if (++this.genericsLengthPtr >= stackLength) {
9015 this.genericsLengthStack, 0,
9016 this.genericsLengthStack = new int[stackLength + GenericsStackIncrement], 0,
9019 this.genericsLengthStack[this.genericsLengthPtr] = pos;
9021 protected void pushOnIntStack(int pos) {
9023 int stackLength = this.intStack.length;
9024 if (++this.intPtr >= stackLength) {
9027 this.intStack = new int[stackLength + StackIncrement], 0,
9030 this.intStack[this.intPtr] = pos;
9032 protected void pushOnRealBlockStack(int i){
9034 int stackLength = this.realBlockStack.length;
9035 if (++this.realBlockPtr >= stackLength) {
9037 this.realBlockStack, 0,
9038 this.realBlockStack = new int[stackLength + StackIncrement], 0,
9041 this.realBlockStack[this.realBlockPtr] = i;
9043 public void recoveryExitFromVariable() {
9044 if(this.currentElement != null && this.currentElement.parent != null) {
9045 if(this.currentElement instanceof RecoveredLocalVariable) {
9047 int end = ((RecoveredLocalVariable)this.currentElement).localDeclaration.sourceEnd;
9048 this.currentElement.updateSourceEndIfNecessary(end);
9049 this.currentElement = this.currentElement.parent;
9050 } else if(this.currentElement instanceof RecoveredField
9051 && !(this.currentElement instanceof RecoveredInitializer)) {
9053 int end = ((RecoveredField)this.currentElement).fieldDeclaration.sourceEnd;
9054 this.currentElement.updateSourceEndIfNecessary(end);
9055 this.currentElement = this.currentElement.parent;
9059 /* Token check performed on every token shift once having entered
9062 public void recoveryTokenCheck() {
9063 switch (this.currentToken) {
9064 case TokenNameLBRACE :
9065 RecoveredElement newElement = null;
9066 if(!this.ignoreNextOpeningBrace) {
9067 newElement = this.currentElement.updateOnOpeningBrace(this.scanner.startPosition - 1, this.scanner.currentPosition - 1);
9069 this.lastCheckPoint = this.scanner.currentPosition;
9070 if (newElement != null){ // null means nothing happened
9071 this.restartRecovery = true; // opening brace detected
9072 this.currentElement = newElement;
9076 case TokenNameRBRACE :
9077 this.rBraceStart = this.scanner.startPosition - 1;
9078 this.rBraceEnd = this.scanner.currentPosition - 1;
9079 this.endPosition = this.flushCommentsDefinedPriorTo(this.rBraceEnd);
9081 this.currentElement.updateOnClosingBrace(this.scanner.startPosition, this.rBraceEnd);
9082 this.lastCheckPoint = this.scanner.currentPosition;
9083 if (newElement != this.currentElement){
9084 this.currentElement = newElement;
9085 // if (newElement instanceof RecoveredField && this.dietInt <= 0) {
9086 // if (((RecoveredField)newElement).fieldDeclaration.type == null) { // enum constant
9087 // this.isInsideEnumConstantPart = true; // restore status
9092 case TokenNameSEMICOLON :
9093 this.endStatementPosition = this.scanner.currentPosition - 1;
9094 this.endPosition = this.scanner.startPosition - 1;
9095 RecoveredType currentType = this.currentRecoveryType();
9096 if(currentType != null) {
9097 currentType.insideEnumConstantPart = false;
9101 if (this.rBraceEnd > this.rBraceSuccessorStart && this.scanner.currentPosition != this.scanner.startPosition){
9102 this.rBraceSuccessorStart = this.scanner.startPosition;
9107 this.ignoreNextOpeningBrace = false;
9110 protected void reportSyntaxErrors(boolean isDietParse, int oldFirstToken) {
9111 if(this.referenceContext instanceof MethodDeclaration) {
9112 MethodDeclaration methodDeclaration = (MethodDeclaration) this.referenceContext;
9113 if(methodDeclaration.errorInSignature){
9117 this.compilationUnit.compilationResult.lineSeparatorPositions = this.scanner.getLineEnds();
9118 this.scanner.recordLineSeparator = false;
9120 int start = this.scanner.initialPosition;
9121 int end = this.scanner.eofPosition <= Integer.MAX_VALUE ? this.scanner.eofPosition - 1 : this.scanner.eofPosition;
9123 TypeDeclaration[] types = this.compilationUnit.types;
9125 int[][] intervalToSkip = org.eclipse.jdt.internal.compiler.parser.diagnose.RangeUtil.computeDietRange(types);
9126 DiagnoseParser diagnoseParser = new DiagnoseParser(this, oldFirstToken, start, end, intervalToSkip[0], intervalToSkip[1], intervalToSkip[2], this.options);
9127 diagnoseParser.diagnoseParse();
9129 reportSyntaxErrorsForSkippedMethod(types);
9130 this.scanner.resetTo(start, end);
9132 DiagnoseParser diagnoseParser = new DiagnoseParser(this, oldFirstToken, start, end, this.options);
9133 diagnoseParser.diagnoseParse();
9136 private void reportSyntaxErrorsForSkippedMethod(TypeDeclaration[] types){
9138 for (int i = 0; i < types.length; i++) {
9139 TypeDeclaration[] memberTypes = types[i].memberTypes;
9140 if(memberTypes != null) {
9141 reportSyntaxErrorsForSkippedMethod(memberTypes);
9144 AbstractMethodDeclaration[] methods = types[i].methods;
9145 if(methods != null) {
9146 for (int j = 0; j < methods.length; j++) {
9147 AbstractMethodDeclaration method = methods[j];
9148 if(method.errorInSignature) {
9149 if(method.isAnnotationMethod()) {
9150 DiagnoseParser diagnoseParser = new DiagnoseParser(this, TokenNameQUESTION, method.declarationSourceStart, method.declarationSourceEnd, this.options);
9151 diagnoseParser.diagnoseParse();
9153 DiagnoseParser diagnoseParser = new DiagnoseParser(this, TokenNameDIVIDE, method.declarationSourceStart, method.declarationSourceEnd, this.options);
9154 diagnoseParser.diagnoseParse();
9161 FieldDeclaration[] fields = types[i].fields;
9162 if (fields != null) {
9163 int length = fields.length;
9164 for (int j = 0; j < length; j++) {
9165 if (fields[j] instanceof Initializer) {
9166 Initializer initializer = (Initializer)fields[j];
9167 if(initializer.errorInSignature){
9168 DiagnoseParser diagnoseParser = new DiagnoseParser(this, TokenNameRIGHT_SHIFT, initializer.declarationSourceStart, initializer.declarationSourceEnd, this.options);
9169 diagnoseParser.diagnoseParse();
9177 protected void resetModifiers() {
9178 this.modifiers = AccDefault;
9179 this.modifiersSourceStart = -1; // <-- see comment into modifiersFlag(int)
9180 this.scanner.commentPtr = -1;
9183 * Reset context so as to resume to regular parse loop
9185 protected void resetStacks() {
9188 this.astLengthPtr = -1;
9189 this.expressionPtr = -1;
9190 this.expressionLengthPtr = -1;
9191 this.identifierPtr = -1;
9192 this.identifierLengthPtr = -1;
9194 this.nestedMethod[this.nestedType = 0] = 0; // need to reset for further reuse
9195 this.variablesCounter[this.nestedType] = 0;
9196 this.dimensions = 0 ;
9197 this.realBlockStack[this.realBlockPtr = 0] = 0;
9198 this.recoveredStaticInitializerStart = 0;
9199 this.listLength = 0;
9200 this.listTypeParameterLength = 0;
9201 // Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=29365
9202 if (this.scanner != null) this.scanner.currentLine = null;
9204 this.genericsIdentifiersLengthPtr = -1;
9205 this.genericsLengthPtr = -1;
9206 this.genericsPtr = -1;
9209 * Reset context so as to resume to regular parse loop
9210 * If unable to reset for resuming, answers false.
9212 * Move checkpoint location, reset internal stacks and
9213 * decide which grammar goal is activated.
9215 protected boolean resumeAfterRecovery() {
9217 // reset internal stacks
9219 this.resetModifiers();
9221 /* attempt to move checkpoint location */
9222 if (!this.moveRecoveryCheckpoint()) {
9226 // only look for headers
9227 if (this.referenceContext instanceof CompilationUnitDeclaration){
9229 this.diet = true; // passed this point, will not consider method bodies
9232 // does not know how to restart
9235 protected boolean resumeOnSyntaxError() {
9237 /* request recovery initialization */
9238 if (this.currentElement == null){
9239 // Reset javadoc before restart parsing after recovery
9240 this.javadoc = null;
9242 // build some recovered elements
9243 this.currentElement = buildInitialRecoveryState();
9245 /* do not investigate deeper in recovery when no recovered element */
9246 if (this.currentElement == null) return false;
9248 /* manual forced recovery restart - after headers */
9249 if (this.restartRecovery){
9250 this.restartRecovery = false;
9252 /* update recovery state with current error state of the parser */
9253 this.updateRecoveryState();
9255 /* attempt to reset state in order to resume to parse loop */
9256 return this.resumeAfterRecovery();
9258 public String toString() {
9261 String s = "lastCheckpoint : int = " + String.valueOf(this.lastCheckPoint) + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
9262 s = s + "identifierStack : char["+(this.identifierPtr + 1)+"][] = {"; //$NON-NLS-1$ //$NON-NLS-2$
9263 for (int i = 0; i <= this.identifierPtr; i++) {
9264 s = s + "\"" + String.valueOf(this.identifierStack[i]) + "\","; //$NON-NLS-1$ //$NON-NLS-2$
9266 s = s + "}\n"; //$NON-NLS-1$
9268 s = s + "identifierLengthStack : int["+(this.identifierLengthPtr + 1)+"] = {"; //$NON-NLS-1$ //$NON-NLS-2$
9269 for (int i = 0; i <= this.identifierLengthPtr; i++) {
9270 s = s + this.identifierLengthStack[i] + ","; //$NON-NLS-1$
9272 s = s + "}\n"; //$NON-NLS-1$
9274 s = s + "astLengthStack : int["+(this.astLengthPtr + 1)+"] = {"; //$NON-NLS-1$ //$NON-NLS-2$
9275 for (int i = 0; i <= this.astLengthPtr; i++) {
9276 s = s + this.astLengthStack[i] + ","; //$NON-NLS-1$
9278 s = s + "}\n"; //$NON-NLS-1$
9279 s = s + "astPtr : int = " + String.valueOf(this.astPtr) + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
9281 s = s + "intStack : int["+(this.intPtr + 1)+"] = {"; //$NON-NLS-1$ //$NON-NLS-2$
9282 for (int i = 0; i <= this.intPtr; i++) {
9283 s = s + this.intStack[i] + ","; //$NON-NLS-1$
9285 s = s + "}\n"; //$NON-NLS-1$
9287 s = s + "expressionLengthStack : int["+(this.expressionLengthPtr + 1)+"] = {"; //$NON-NLS-1$ //$NON-NLS-2$
9288 for (int i = 0; i <= this.expressionLengthPtr; i++) {
9289 s = s + this.expressionLengthStack[i] + ","; //$NON-NLS-1$
9291 s = s + "}\n"; //$NON-NLS-1$
9293 s = s + "expressionPtr : int = " + String.valueOf(this.expressionPtr) + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
9295 s = s + "genericsIdentifiersLengthStack : int["+(this.genericsIdentifiersLengthPtr + 1)+"] = {"; //$NON-NLS-1$ //$NON-NLS-2$
9296 for (int i = 0; i <= this.genericsIdentifiersLengthPtr; i++) {
9297 s = s + this.genericsIdentifiersLengthStack[i] + ","; //$NON-NLS-1$
9299 s = s + "}\n"; //$NON-NLS-1$
9301 s = s + "genericsLengthStack : int["+(this.genericsLengthPtr + 1)+"] = {"; //$NON-NLS-1$ //$NON-NLS-2$
9302 for (int i = 0; i <= this.genericsLengthPtr; i++) {
9303 s = s + this.genericsLengthStack[i] + ","; //$NON-NLS-1$
9305 s = s + "}\n"; //$NON-NLS-1$
9307 s = s + "genericsPtr : int = " + String.valueOf(this.genericsPtr) + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
9309 s = s + "\n\n\n----------------Scanner--------------\n" + this.scanner.toString(); //$NON-NLS-1$
9314 * Update recovery state based on current parser/scanner state
9316 protected void updateRecoveryState() {
9318 /* expose parser state to recovery state */
9319 this.currentElement.updateFromParserState();
9321 /* check and update recovered state based on current token,
9322 this action is also performed when shifting token after recovery
9325 this.recoveryTokenCheck();
9327 protected void updateSourceDeclarationParts(int variableDeclaratorsCounter) {
9328 //fields is a definition of fields that are grouped together like in
9329 //public int[] a, b[], c
9330 //which results into 3 fields.
9332 FieldDeclaration field;
9333 int endTypeDeclarationPosition =
9334 -1 + this.astStack[this.astPtr - variableDeclaratorsCounter + 1].sourceStart;
9335 for (int i = 0; i < variableDeclaratorsCounter - 1; i++) {
9336 //last one is special(see below)
9337 field = (FieldDeclaration) this.astStack[this.astPtr - i - 1];
9338 field.endPart1Position = endTypeDeclarationPosition;
9339 field.endPart2Position = -1 + this.astStack[this.astPtr - i].sourceStart;
9342 (field = (FieldDeclaration) this.astStack[this.astPtr]).endPart1Position =
9343 endTypeDeclarationPosition;
9344 field.endPart2Position = field.declarationSourceEnd;
9347 protected void updateSourcePosition(Expression exp) {
9348 //update the source Position of the expression
9350 //this.intStack : int int
9354 exp.sourceEnd = this.intStack[this.intPtr--];
9355 exp.sourceStart = this.intStack[this.intPtr--];