ast.setBindingResolver(new BindingResolver());
if ((this.bits & CompilationUnitResolver.STATEMENT_RECOVERY) != 0) {
ast.setFlag(ICompilationUnit.ENABLE_STATEMENTS_RECOVERY);
}
converter.setAST(ast);
CodeSnippetParsingUtil codeSnippetParsingUtil = new CodeSnippetParsingUtil((this.bits & CompilationUnitResolver.IGNORE_METHOD_BODIES) != 0);
CompilationUnit compilationUnit = ast.newCompilationUnit();
if (this.sourceLength == -1) {
this.sourceLength = this.rawSource.length;
}
switch(this.astKind) {
case K_STATEMENTS :
ConstructorDeclaration constructorDeclaration = codeSnippetParsingUtil.parseStatements(
this.rawSource,
this.sourceOffset,
this.sourceLength,
this.compilerOptions,
true,
(this.bits & CompilationUnitResolver.STATEMENT_RECOVERY) != 0);
RecoveryScannerData data = constructorDeclaration.compilationResult.recoveryScannerData;
if(data != null) {
Scanner scanner = converter.scanner;
converter.scanner = new RecoveryScanner(scanner, data.removeUnused());
converter.docParser.scanner = converter.scanner;
converter.scanner.setSource(scanner.source);
compilationUnit.setStatementsRecoveryData(data);
}
RecordedParsingInformation recordedParsingInformation = codeSnippetParsingUtil.recordedParsingInformation;
int[][] comments = recordedParsingInformation.commentPositions;
if (comments != null) {
converter.buildCommentsTable(compilationUnit, comments);
}
compilationUnit.setLineEndTable(recordedParsingInformation.lineEnds);
Block block = ast.newBlock();
block.setSourceRange(this.sourceOffset, this.sourceOffset + this.sourceLength);
org.eclipse.jdt.internal.compiler.ast.Statement[] statements = constructorDeclaration.statements;
if (statements != null) {
int statementsLength = statements.length;
for (int i = 0; i < statementsLength; i++) {
if (statements[i] instanceof org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) {
converter.checkAndAddMultipleLocalDeclaration(statements, i, block.statements());
} else {
Statement statement = converter.convert(statements[i]);
if (statement != null) {
block.statements().add(statement);
}
}
}
}
rootNodeToCompilationUnit(ast, compilationUnit, block, recordedParsingInformation, data);
ast.setDefaultNodeFlag(0);
ast.setOriginalModificationCount(ast.modificationCount());
return block;
case K_EXPRESSION :
org.eclipse.jdt.internal.compiler.ast.Expression expression = codeSnippetParsingUtil.parseExpression(this.rawSource, this.sourceOffset, this.sourceLength, this.compilerOptions, true);
recordedParsingInformation = codeSnippetParsingUtil.recordedParsingInformation;
comments = recordedParsingInformation.commentPositions;
if (comments != null) {
converter.buildCommentsTable(compilationUnit, comments);
}
compilationUnit.setLineEndTable(recordedParsingInformation.lineEnds);
if (expression != null) {
Expression expression2 = converter.convert(expression);
rootNodeToCompilationUnit(expression2.getAST(), compilationUnit, expression2, codeSnippetParsingUtil.recordedParsingInformation, null);
ast.setDefaultNodeFlag(0);
ast.setOriginalModificationCount(ast.modificationCount());
return expression2;
} else {
CategorizedProblem[] problems = recordedParsingInformation.problems;
if (problems != null) {
compilationUnit.setProblems(problems);
}
ast.setDefaultNodeFlag(0);
ast.setOriginalModificationCount(ast.modificationCount());
return compilationUnit;
}
case K_CLASS_BODY_DECLARATIONS :
final org.eclipse.jdt.internal.compiler.ast.ASTNode[] nodes =
codeSnippetParsingUtil.parseClassBodyDeclarations(
this.rawSource,
this.sourceOffset,
this.sourceLength,
this.compilerOptions,
true,