Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 130235 Details for
Bug 270148
ASTParser cannot parse K_CLASS_BODY_DECLARATIONS with syntax errors
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix
patch_270148.txt (text/plain), 28.38 KB, created by
Olivier Thomann
on 2009-03-30 08:48:20 EDT
(
hide
)
Description:
Proposed fix
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2009-03-30 08:48:20 EDT
Size:
28.38 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: model/org/eclipse/jdt/internal/core/util/CodeSnippetParsingUtil.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/CodeSnippetParsingUtil.java,v >retrieving revision 1.18 >diff -u -r1.18 CodeSnippetParsingUtil.java >--- model/org/eclipse/jdt/internal/core/util/CodeSnippetParsingUtil.java 27 Jun 2008 16:03:57 -0000 1.18 >+++ model/org/eclipse/jdt/internal/core/util/CodeSnippetParsingUtil.java 28 Mar 2009 02:29:14 -0000 >@@ -33,7 +33,7 @@ > > public RecordedParsingInformation recordedParsingInformation; > >- private RecordedParsingInformation getRecordedParsingInformation(CompilationResult compilationResult, CommentRecorderParser parser) { >+ private RecordedParsingInformation getRecordedParsingInformation(CompilationResult compilationResult, int[][] commentPositions) { > int problemsCount = compilationResult.problemCount; > CategorizedProblem[] problems = null; > if (problemsCount != 0) { >@@ -44,14 +44,20 @@ > System.arraycopy(compilationResultProblems, 0, (problems = new CategorizedProblem[problemsCount]), 0, problemsCount); > } > } >- return new RecordedParsingInformation(problems, compilationResult.getLineSeparatorPositions(), parser.getCommentsPositions()); >+ return new RecordedParsingInformation(problems, compilationResult.getLineSeparatorPositions(), commentPositions); > } > > public ASTNode[] parseClassBodyDeclarations(char[] source, Map settings, boolean recordParsingInformation) { >- return parseClassBodyDeclarations(source, 0, source.length, settings, recordParsingInformation); >+ return parseClassBodyDeclarations(source, 0, source.length, settings, recordParsingInformation, false); > } > >- public ASTNode[] parseClassBodyDeclarations(char[] source, int offset, int length, Map settings, boolean recordParsingInformation) { >+ public ASTNode[] parseClassBodyDeclarations( >+ char[] source, >+ int offset, >+ int length, >+ Map settings, >+ boolean recordParsingInformation, >+ boolean enabledStatementRecovery) { > if (source == null) { > throw new IllegalArgumentException(); > } >@@ -63,7 +69,7 @@ > > CommentRecorderParser parser = new CommentRecorderParser(problemReporter, false); > parser.setMethodsFullRecovery(false); >- parser.setStatementsRecovery(false); >+ parser.setStatementsRecovery(enabledStatementRecovery); > > ICompilationUnit sourceUnit = > new CompilationUnit( >@@ -76,7 +82,7 @@ > ASTNode[] result = parser.parseClassBodyDeclarations(source, offset, length, compilationUnitDeclaration); > > if (recordParsingInformation) { >- this.recordedParsingInformation = getRecordedParsingInformation(compilationResult, parser); >+ this.recordedParsingInformation = getRecordedParsingInformation(compilationResult, compilationUnitDeclaration.comments); > } > return result; > } >@@ -103,7 +109,7 @@ > CompilationUnitDeclaration compilationUnitDeclaration = parser.dietParse(sourceUnit, compilationResult); > > if (recordParsingInformation) { >- this.recordedParsingInformation = getRecordedParsingInformation(compilationResult, parser); >+ this.recordedParsingInformation = getRecordedParsingInformation(compilationResult, compilationUnitDeclaration.comments); > } > > if (compilationUnitDeclaration.ignoreMethodBodies) { >@@ -152,10 +158,11 @@ > compilerOptions.defaultEncoding); > > CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, compilerOptions.maxProblemsPerUnit); >- Expression result = parser.parseExpression(source, offset, length, new CompilationUnitDeclaration(problemReporter, compilationResult, source.length)); >+ CompilationUnitDeclaration unit = new CompilationUnitDeclaration(problemReporter, compilationResult, source.length); >+ Expression result = parser.parseExpression(source, offset, length, unit); > > if (recordParsingInformation) { >- this.recordedParsingInformation = getRecordedParsingInformation(compilationResult, parser); >+ this.recordedParsingInformation = getRecordedParsingInformation(compilationResult, unit.comments); > } > return result; > } >@@ -164,7 +171,13 @@ > return parseStatements(source, 0, source.length, settings, recordParsingInformation, enabledStatementRecovery); > } > >- public ConstructorDeclaration parseStatements(char[] source, int offset, int length, Map settings, boolean recordParsingInformation, boolean enabledStatementRecovery) { >+ public ConstructorDeclaration parseStatements( >+ char[] source, >+ int offset, >+ int length, >+ Map settings, >+ boolean recordParsingInformation, >+ boolean enabledStatementRecovery) { > if (source == null) { > throw new IllegalArgumentException(); > } >@@ -197,7 +210,7 @@ > parser.parse(constructorDeclaration, compilationUnitDeclaration, true); > > if (recordParsingInformation) { >- this.recordedParsingInformation = getRecordedParsingInformation(compilationResult, parser); >+ this.recordedParsingInformation = getRecordedParsingInformation(compilationResult, compilationUnitDeclaration.comments); > } > return constructorDeclaration; > } >Index: compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java,v >retrieving revision 1.400 >diff -u -r1.400 Parser.java >--- compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 7 Mar 2009 00:58:59 -0000 1.400 >+++ compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 28 Mar 2009 02:29:11 -0000 >@@ -9670,6 +9670,7 @@ > } > } > public ASTNode[] parseClassBodyDeclarations(char[] source, int offset, int length, CompilationUnitDeclaration unit) { >+ boolean oldDiet = this.diet; > /* automaton initialization */ > initialize(); > goForClassBodyDeclarations(); >@@ -9685,27 +9686,103 @@ > this.nestedType = 1; > > /* unit creation */ >- this.referenceContext = unit; >+ TypeDeclaration referenceContextTypeDeclaration = new TypeDeclaration(unit.compilationResult); >+ referenceContextTypeDeclaration.name = Util.EMPTY_STRING.toCharArray(); >+ referenceContextTypeDeclaration.fields = new FieldDeclaration[0]; > this.compilationUnit = unit; >+ unit.types = new TypeDeclaration[1]; >+ unit.types[0] = referenceContextTypeDeclaration; >+ this.referenceContext = unit; > > /* run automaton */ > try { >+ this.diet = true; > parse(); > } catch (AbortCompilation ex) { > this.lastAct = ERROR_ACTION; >+ } finally { >+ this.diet = oldDiet; > } > >+ ASTNode[] result = null; > if (this.lastAct == ERROR_ACTION) { >- return null; >+ if (!this.options.performMethodsFullRecovery && !this.options.performStatementsRecovery) { >+ return null; >+ } >+ // collect all body declaration inside the compilation unit except the default constructor >+ final List bodyDeclarations = new ArrayList(); >+ ASTVisitor visitor = new ASTVisitor() { >+ public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) { >+ if (!methodDeclaration.isDefaultConstructor()) { >+ bodyDeclarations.add(methodDeclaration); >+ } >+ return false; >+ } >+ public boolean visit(FieldDeclaration fieldDeclaration, MethodScope scope) { >+ bodyDeclarations.add(fieldDeclaration); >+ return false; >+ } >+ public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope scope) { >+ bodyDeclarations.add(memberTypeDeclaration); >+ return false; >+ } >+ }; >+ unit.ignoreFurtherInvestigation = false; >+ unit.traverse(visitor, unit.scope); >+ unit.ignoreFurtherInvestigation = true; >+ result = (ASTNode[]) bodyDeclarations.toArray(new ASTNode[bodyDeclarations.size()]); >+ } else { >+ int astLength; >+ if (this.astLengthPtr > -1 && (astLength = this.astLengthStack[this.astLengthPtr--]) != 0) { >+ result = new ASTNode[astLength]; >+ this.astPtr -= astLength; >+ System.arraycopy(this.astStack, this.astPtr + 1, result, 0, astLength); >+ } >+ } >+ boolean containsInitializers = false; >+ TypeDeclaration typeDeclaration = null; >+ for (int i = 0, max = result.length; i< max; i++) { >+ // parse each class body declaration >+ ASTNode node = result[i]; >+ if (node instanceof TypeDeclaration) { >+ ((TypeDeclaration) node).parseMethods(this, unit); >+ } else if (node instanceof AbstractMethodDeclaration) { >+ ((AbstractMethodDeclaration) node).parseStatements(this, unit); >+ } else if (node instanceof FieldDeclaration) { >+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node; >+ switch(fieldDeclaration.getKind()) { >+ case AbstractVariableDeclaration.INITIALIZER: >+ containsInitializers = true; >+ if (typeDeclaration == null) { >+ typeDeclaration = referenceContextTypeDeclaration; >+ } >+ if (typeDeclaration.fields == null) { >+ typeDeclaration.fields = new FieldDeclaration[1]; >+ typeDeclaration.fields[0] = fieldDeclaration; >+ } else { >+ int length2 = typeDeclaration.fields.length; >+ FieldDeclaration[] temp = new FieldDeclaration[length2 + 1]; >+ System.arraycopy(typeDeclaration.fields, 0, temp, 0, length2); >+ temp[length2] = fieldDeclaration; >+ typeDeclaration.fields = temp; >+ } >+ break; >+ } >+ } >+ if (this.lastAct == ERROR_ACTION && (!this.options.performMethodsFullRecovery && !this.options.performStatementsRecovery)) { >+ return null; >+ } > } >- int astLength; >- if (this.astLengthPtr > -1 && (astLength = this.astLengthStack[this.astLengthPtr--]) != 0) { >- ASTNode[] result = new ASTNode[astLength]; >- this.astPtr -= astLength; >- System.arraycopy(this.astStack, this.astPtr + 1, result, 0, astLength); >- return result; >+ if (containsInitializers) { >+ FieldDeclaration[] fieldDeclarations = typeDeclaration.fields; >+ for (int i = 0, max = fieldDeclarations.length; i < max; i++) { >+ ((Initializer) fieldDeclarations[i]).parseStatements(this, typeDeclaration , unit); >+ if (this.lastAct == ERROR_ACTION && (!this.options.performMethodsFullRecovery && !this.options.performStatementsRecovery)) { >+ return null; >+ } >+ } > } >- return null; >+ return result; > } > public Expression parseExpression(char[] source, int offset, int length, CompilationUnitDeclaration unit) { > >@@ -10414,6 +10491,13 @@ > } > /* update recovery state with current error state of the parser */ > updateRecoveryState(); >+ if (getFirstToken() == TokenNameAND) { >+ if (this.referenceContext instanceof CompilationUnitDeclaration) { >+ TypeDeclaration typeDeclaration = new TypeDeclaration(this.referenceContext.compilationResult()); >+ typeDeclaration.name = Util.EMPTY_STRING.toCharArray(); >+ this.currentElement = this.currentElement.add(typeDeclaration, 0); >+ } >+ } > > if (this.lastPosistion < this.scanner.currentPosition) { > this.lastPosistion = this.scanner.currentPosition; >Index: dom/org/eclipse/jdt/core/dom/ASTParser.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java,v >retrieving revision 1.85 >diff -u -r1.85 ASTParser.java >--- dom/org/eclipse/jdt/core/dom/ASTParser.java 7 Mar 2009 00:59:01 -0000 1.85 >+++ dom/org/eclipse/jdt/core/dom/ASTParser.java 28 Mar 2009 02:29:14 -0000 >@@ -1099,29 +1099,19 @@ > 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); >+ final org.eclipse.jdt.internal.compiler.ast.ASTNode[] nodes = codeSnippetParsingUtil.parseClassBodyDeclarations(this.rawSource, this.sourceOffset, this.sourceLength, this.compilerOptions, true, this.statementsRecovery); > recordedParsingInformation = codeSnippetParsingUtil.recordedParsingInformation; > comments = recordedParsingInformation.commentPositions; > if (comments != null) { > converter.buildCommentsTable(compilationUnit, comments); > } > compilationUnit.setLineEndTable(recordedParsingInformation.lineEnds); >- if (nodes != null) { >- TypeDeclaration typeDeclaration = converter.convert(nodes); >- typeDeclaration.setSourceRange(this.sourceOffset, this.sourceOffset + this.sourceLength); >- rootNodeToCompilationUnit(typeDeclaration.getAST(), compilationUnit, typeDeclaration, codeSnippetParsingUtil.recordedParsingInformation, null); >- ast.setDefaultNodeFlag(0); >- ast.setOriginalModificationCount(ast.modificationCount()); >- return typeDeclaration; >- } else { >- CategorizedProblem[] problems = recordedParsingInformation.problems; >- if (problems != null) { >- compilationUnit.setProblems(problems); >- } >- ast.setDefaultNodeFlag(0); >- ast.setOriginalModificationCount(ast.modificationCount()); >- return compilationUnit; >- } >+ TypeDeclaration typeDeclaration = converter.convert(nodes); >+ typeDeclaration.setSourceRange(this.sourceOffset, this.sourceOffset + this.sourceLength); >+ rootNodeToCompilationUnit(typeDeclaration.getAST(), compilationUnit, typeDeclaration, codeSnippetParsingUtil.recordedParsingInformation, null); >+ ast.setDefaultNodeFlag(0); >+ ast.setOriginalModificationCount(ast.modificationCount()); >+ return typeDeclaration; > } > throw new IllegalStateException(); > } >Index: dom/org/eclipse/jdt/core/dom/ASTConverter.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java,v >retrieving revision 1.266 >diff -u -r1.266 ASTConverter.java >--- dom/org/eclipse/jdt/core/dom/ASTConverter.java 7 Mar 2009 00:59:01 -0000 1.266 >+++ dom/org/eclipse/jdt/core/dom/ASTConverter.java 28 Mar 2009 02:29:14 -0000 >@@ -938,7 +938,7 @@ > public TypeDeclaration convert(org.eclipse.jdt.internal.compiler.ast.ASTNode[] nodes) { > final TypeDeclaration typeDecl = new TypeDeclaration(this.ast); > typeDecl.setInterface(false); >- int nodesLength = nodes.length; >+ int nodesLength = nodes == null ? 0 : nodes.length; > for (int i = 0; i < nodesLength; i++) { > org.eclipse.jdt.internal.compiler.ast.ASTNode node = nodes[i]; > if (node instanceof org.eclipse.jdt.internal.compiler.ast.Initializer) { >Index: model/org/eclipse/jdt/internal/core/CreateTypeMemberOperation.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CreateTypeMemberOperation.java,v >retrieving revision 1.39 >diff -u -r1.39 CreateTypeMemberOperation.java >--- model/org/eclipse/jdt/internal/core/CreateTypeMemberOperation.java 28 Aug 2008 13:19:33 -0000 1.39 >+++ model/org/eclipse/jdt/internal/core/CreateTypeMemberOperation.java 28 Mar 2009 02:29:14 -0000 >@@ -90,14 +90,17 @@ > } else { > TypeDeclaration typeDeclaration = (TypeDeclaration) node; > if ((typeDeclaration.getFlags() & ASTNode.MALFORMED) != 0) { >- throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_CONTENTS)); >- } >- List bodyDeclarations = typeDeclaration.bodyDeclarations(); >- if (bodyDeclarations.size() == 0) { >- throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_CONTENTS)); >+ createdNodeSource = generateSyntaxIncorrectAST(); >+ if (this.createdNode == null) >+ throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_CONTENTS)); >+ } else { >+ List bodyDeclarations = typeDeclaration.bodyDeclarations(); >+ if (bodyDeclarations.size() == 0) { >+ throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_CONTENTS)); >+ } >+ this.createdNode = (ASTNode) bodyDeclarations.iterator().next(); >+ createdNodeSource = this.source; > } >- this.createdNode = (ASTNode) bodyDeclarations.iterator().next(); >- createdNodeSource = this.source; > } > if (this.alteredName != null) { > SimpleName newName = this.createdNode.getAST().newSimpleName(this.alteredName); >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java,v >retrieving revision 1.156 >diff -u -r1.156 ASTConverterTestAST3_2.java >--- src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java 18 Feb 2009 03:04:18 -0000 1.156 >+++ src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java 28 Mar 2009 02:29:26 -0000 >@@ -122,7 +122,7 @@ > static { > // TESTS_NAMES = new String[] {"test0602"}; > // TESTS_RANGE = new int[] { 670, -1 }; >-// TESTS_NUMBERS = new int[] { 702 }; >+// TESTS_NUMBERS = new int[] { 708 }; > } > public static Test suite() { > return buildModelTestSuite(ASTConverterTestAST3_2.class); >@@ -4115,8 +4115,8 @@ > parser.setCompilerOptions(JavaCore.getOptions()); > ASTNode result2 = parser.createAST(null); > assertNotNull("No node", result2); >- assertTrue("not a compilation unit", result2.getNodeType() == ASTNode.COMPILATION_UNIT); >- CompilationUnit compilationUnit = (CompilationUnit) result2; >+ assertTrue("not a type declaration", result2.getNodeType() == ASTNode.TYPE_DECLARATION); >+ CompilationUnit compilationUnit = (CompilationUnit) ((TypeDeclaration) result2).getParent(); > assertEquals("wrong problem size", 1, compilationUnit.getProblems().length); > } > /** >@@ -4140,8 +4140,8 @@ > parser.setCompilerOptions(JavaCore.getOptions()); > ASTNode result2 = parser.createAST(null); > assertNotNull("No node", result2); >- assertTrue("not a compilation unit", result2.getNodeType() == ASTNode.COMPILATION_UNIT); >- CompilationUnit compilationUnit = (CompilationUnit) result2; >+ assertTrue("not a type declaration", result2.getNodeType() == ASTNode.TYPE_DECLARATION); >+ CompilationUnit compilationUnit = (CompilationUnit) ((TypeDeclaration) result2).getParent(); > assertEquals("wrong problem size", 1, compilationUnit.getProblems().length); > } > /** >@@ -4165,8 +4165,8 @@ > parser.setCompilerOptions(JavaCore.getOptions()); > ASTNode result2 = parser.createAST(null); > assertNotNull("No node", result2); >- assertTrue("not a compilation unit", result2.getNodeType() == ASTNode.COMPILATION_UNIT); >- CompilationUnit compilationUnit = (CompilationUnit) result2; >+ assertTrue("not a type declaration", result2.getNodeType() == ASTNode.TYPE_DECLARATION); >+ CompilationUnit compilationUnit = (CompilationUnit) ((TypeDeclaration) result2).getParent(); > assertEquals("wrong problem size", 1, compilationUnit.getProblems().length); > } > /** >@@ -10104,17 +10104,151 @@ > } > } > /** >- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=264590 >+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=270148 > */ >- public void _test0702() throws JavaModelException { >+ public void test0702() throws JavaModelException { >+ final char[] source = ("void foo() {\n" + >+ " Integer I = new ${cursor}\n" + >+ "}").toCharArray(); > ASTParser parser = ASTParser.newParser(AST.JLS3); >- parser.setKind(ASTParser.K_EXPRESSION); >- String commentsText = "/**\n * @generated\n */\n"; >- char[] source = commentsText.toCharArray(); >+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS); >+ parser.setStatementsRecovery(true); > parser.setSource(source); >- parser.setSourceRange(0, source.length); >- parser.setCompilerOptions(JavaCore.getOptions()); >- ASTNode result = parser.createAST(null); >- assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); >+ ASTNode root = parser.createAST(null); >+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, root.getNodeType()); >+ TypeDeclaration typeDeclaration = (TypeDeclaration) root; >+ List bodyDeclarations = typeDeclaration.bodyDeclarations(); >+ assertEquals("Wrong size", 1, bodyDeclarations.size()); >+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0); >+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, bodyDeclaration.getNodeType()); >+ MethodDeclaration declaration = (MethodDeclaration) bodyDeclaration; >+ // check if there is a body with one statement in it >+ assertEquals("No statement found", 1, declaration.getBody().statements().size()); >+ } >+ /** >+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=270148 >+ */ >+ public void test0703() throws JavaModelException { >+ final char[] source = ("public class Try {\n" + >+ " void foo() {\n" + >+ " Integer I = new ${cursor}\n" + >+ " }\n" + >+ "}").toCharArray(); >+ ASTParser parser = ASTParser.newParser(AST.JLS3); >+ parser.setKind(ASTParser.K_COMPILATION_UNIT); >+ parser.setStatementsRecovery(true); >+ parser.setSource(source); >+ ASTNode root = parser.createAST(null); >+ assertEquals("Not a compilation declaration", ASTNode.COMPILATION_UNIT, root.getNodeType()); >+ TypeDeclaration typeDeclaration = (TypeDeclaration) ((CompilationUnit) root).types().get(0); >+ List bodyDeclarations = typeDeclaration.bodyDeclarations(); >+ assertEquals("Wrong size", 1, bodyDeclarations.size()); >+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0); >+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, bodyDeclaration.getNodeType()); >+ MethodDeclaration declaration = (MethodDeclaration) bodyDeclaration; >+ // check if there is a body with one statement in it >+ assertEquals("No statement found", 1, declaration.getBody().statements().size()); >+ } >+ /** >+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=270148 >+ */ >+ public void test0704() throws JavaModelException { >+ final char[] source = ("{\n" + >+ " Integer I = new ${cursor}\n" + >+ "}").toCharArray(); >+ ASTParser parser = ASTParser.newParser(AST.JLS3); >+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS); >+ parser.setStatementsRecovery(true); >+ parser.setSource(source); >+ ASTNode root = parser.createAST(null); >+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, root.getNodeType()); >+ TypeDeclaration typeDeclaration = (TypeDeclaration) root; >+ List bodyDeclarations = typeDeclaration.bodyDeclarations(); >+ assertEquals("Wrong size", 1, bodyDeclarations.size()); >+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0); >+ assertEquals("Not an initializer", ASTNode.INITIALIZER, bodyDeclaration.getNodeType()); >+ Initializer initializer = (Initializer) bodyDeclaration; >+ // check if there is a body with one statement in it >+ assertEquals("No statement found", 1, initializer.getBody().statements().size()); >+ } >+ /** >+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=270148 >+ */ >+ public void test0705() throws JavaModelException { >+ final char[] source = ("{\n" + >+ " Integer I = new ${cursor}\n" + >+ "}\n" + >+ "{\n" + >+ " Integer I = new ${cursor}\n" + >+ "}").toCharArray(); >+ ASTParser parser = ASTParser.newParser(AST.JLS3); >+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS); >+ parser.setStatementsRecovery(true); >+ parser.setSource(source); >+ ASTNode root = parser.createAST(null); >+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, root.getNodeType()); >+ TypeDeclaration typeDeclaration = (TypeDeclaration) root; >+ List bodyDeclarations = typeDeclaration.bodyDeclarations(); >+ assertEquals("Wrong size", 2, bodyDeclarations.size()); >+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0); >+ assertEquals("Not an initializer", ASTNode.INITIALIZER, bodyDeclaration.getNodeType()); >+ Initializer initializer = (Initializer) bodyDeclaration; >+ // check if there is a body with one statement in it >+ assertEquals("No statement found", 1, initializer.getBody().statements().size()); >+ bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(1); >+ assertEquals("Not an initializer", ASTNode.INITIALIZER, bodyDeclaration.getNodeType()); >+ initializer = (Initializer) bodyDeclaration; >+ // check if there is a body with one statement in it >+ assertEquals("No statement found", 1, initializer.getBody().statements().size()); >+ } >+ /** >+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=270148 >+ */ >+ public void test0706() throws JavaModelException { >+ final char[] source = ("public class Try {\n" + >+ " Integer i = new Integer() {\n" + >+ " Integer I = new ${cursor}\n" + >+ " };\"\n" + >+ "}").toCharArray(); >+ ASTParser parser = ASTParser.newParser(AST.JLS3); >+ parser.setKind(ASTParser.K_COMPILATION_UNIT); >+ parser.setStatementsRecovery(true); >+ parser.setSource(source); >+ ASTNode root = parser.createAST(null); >+ assertEquals("Not a compilation declaration", ASTNode.COMPILATION_UNIT, root.getNodeType()); >+ TypeDeclaration typeDeclaration = (TypeDeclaration) ((CompilationUnit) root).types().get(0); >+ List bodyDeclarations = typeDeclaration.bodyDeclarations(); >+ assertEquals("Wrong size", 1, bodyDeclarations.size()); >+ } >+ /** >+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=270148 >+ */ >+ public void test0707() throws JavaModelException { >+ final char[] source = ("Integer i = new Integer() {\n" + >+ " Integer I = new ${cursor}\n" + >+ "};").toCharArray(); >+ ASTParser parser = ASTParser.newParser(AST.JLS3); >+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS); >+ parser.setStatementsRecovery(true); >+ parser.setSource(source); >+ ASTNode root = parser.createAST(null); >+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, root.getNodeType()); >+ List bodyDeclarations = ((TypeDeclaration) root).bodyDeclarations(); >+ assertEquals("Wrong size", 1, bodyDeclarations.size()); >+ } >+ /** >+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=270148 >+ */ >+ public void test0708() throws JavaModelException { >+ final char[] source = ("System.out.println()\nint i;\n").toCharArray(); >+ ASTParser parser = ASTParser.newParser(AST.JLS3); >+ parser.setKind(ASTParser.K_STATEMENTS); >+ parser.setStatementsRecovery(true); >+ parser.setSource(source); >+ ASTNode root = parser.createAST(null); >+ assertEquals("Not a block", ASTNode.BLOCK, root.getNodeType()); >+ Block block = (Block) root; >+ List statements = block.statements(); >+ assertEquals("Wrong size", 2, statements.size()); > } > } >Index: src/org/eclipse/jdt/core/tests/dom/ASTConverterTest2.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest2.java,v >retrieving revision 1.193 >diff -u -r1.193 ASTConverterTest2.java >--- src/org/eclipse/jdt/core/tests/dom/ASTConverterTest2.java 29 Nov 2008 22:35:14 -0000 1.193 >+++ src/org/eclipse/jdt/core/tests/dom/ASTConverterTest2.java 28 Mar 2009 02:29:20 -0000 >@@ -4042,8 +4042,8 @@ > parser.setCompilerOptions(JavaCore.getOptions()); > ASTNode result2 = parser.createAST(null); > assertNotNull("No node", result2); >- assertTrue("not a compilation unit", result2.getNodeType() == ASTNode.COMPILATION_UNIT); >- CompilationUnit compilationUnit = (CompilationUnit) result2; >+ assertTrue("not a type declaration", result2.getNodeType() == ASTNode.TYPE_DECLARATION); >+ CompilationUnit compilationUnit = (CompilationUnit) ((TypeDeclaration) result2).getParent(); > assertEquals("wrong problem size", 1, compilationUnit.getProblems().length); > } > /** >@@ -4067,8 +4067,8 @@ > parser.setCompilerOptions(JavaCore.getOptions()); > ASTNode result2 = parser.createAST(null); > assertNotNull("No node", result2); >- assertTrue("not a compilation unit", result2.getNodeType() == ASTNode.COMPILATION_UNIT); >- CompilationUnit compilationUnit = (CompilationUnit) result2; >+ assertTrue("not a type declaration", result2.getNodeType() == ASTNode.TYPE_DECLARATION); >+ CompilationUnit compilationUnit = (CompilationUnit) ((TypeDeclaration) result2).getParent(); > assertEquals("wrong problem size", 1, compilationUnit.getProblems().length); > } > /** >@@ -4092,8 +4092,8 @@ > parser.setCompilerOptions(JavaCore.getOptions()); > ASTNode result2 = parser.createAST(null); > assertNotNull("No node", result2); >- assertTrue("not a compilation unit", result2.getNodeType() == ASTNode.COMPILATION_UNIT); >- CompilationUnit compilationUnit = (CompilationUnit) result2; >+ assertTrue("not a type declaration", result2.getNodeType() == ASTNode.TYPE_DECLARATION); >+ CompilationUnit compilationUnit = (CompilationUnit) ((TypeDeclaration) result2).getParent(); > assertEquals("wrong problem size", 1, compilationUnit.getProblems().length); > } > /**
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 270148
: 130235