1 /*******************************************************************************
2 * Copyright (c) 2000, 2006 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package net.sourceforge.phpdt.core.dom;
14 import org.eclipse.jdt.core.compiler.CategorizedProblem;
15 import net.sourceforge.phpdt.core.compiler.IProblem;
18 * Internal AST visitor for propagating syntax errors.
20 class ASTSyntaxErrorPropagator extends ASTVisitor {
22 private CategorizedProblem[] problems;
24 ASTSyntaxErrorPropagator(CategorizedProblem[] problems) {
25 // visit Javadoc.tags() as well
27 this.problems = problems;
30 private boolean checkAndTagAsMalformed(ASTNode node) {
31 boolean tagWithErrors = false;
32 search: for (int i = 0, max = this.problems.length; i < max; i++) {
33 CategorizedProblem problem = this.problems[i];
34 switch(problem.getID()) {
35 case IProblem.ParsingErrorOnKeywordNoSuggestion :
36 case IProblem.ParsingErrorOnKeyword :
37 case IProblem.ParsingError :
38 case IProblem.ParsingErrorNoSuggestion :
39 case IProblem.ParsingErrorInsertTokenBefore :
40 case IProblem.ParsingErrorInsertTokenAfter :
41 case IProblem.ParsingErrorDeleteToken :
42 case IProblem.ParsingErrorDeleteTokens :
43 case IProblem.ParsingErrorMergeTokens :
44 case IProblem.ParsingErrorInvalidToken :
45 case IProblem.ParsingErrorMisplacedConstruct :
46 case IProblem.ParsingErrorReplaceTokens :
47 case IProblem.ParsingErrorNoSuggestionForTokens :
48 case IProblem.ParsingErrorUnexpectedEOF :
49 case IProblem.ParsingErrorInsertToComplete :
50 case IProblem.ParsingErrorInsertToCompleteScope :
51 case IProblem.ParsingErrorInsertToCompletePhrase :
52 case IProblem.EndOfSource :
53 case IProblem.InvalidHexa :
54 case IProblem.InvalidOctal :
55 case IProblem.InvalidCharacterConstant :
56 case IProblem.InvalidEscape :
57 case IProblem.InvalidInput :
58 case IProblem.InvalidUnicodeEscape :
59 case IProblem.InvalidFloat :
60 case IProblem.NullSourceString :
61 case IProblem.UnterminatedString :
62 case IProblem.UnterminatedComment :
63 case IProblem.InvalidDigit :
68 int position = problem.getSourceStart();
69 int start = node.getStartPosition();
70 int end = start + node.getLength();
71 if ((start <= position) && (position <= end)) {
72 node.setFlags(node.getFlags() | ASTNode.MALFORMED);
73 // clear the bits on parent
74 ASTNode currentNode = node.getParent();
75 while (currentNode != null) {
76 currentNode.setFlags(currentNode.getFlags() & ~ASTNode.MALFORMED);
77 currentNode = currentNode.getParent();
86 * Method declared on ASTVisitor.
88 public boolean visit(FieldDeclaration node) {
89 return checkAndTagAsMalformed(node);
93 * Method declared on ASTVisitor.
95 public boolean visit(MethodDeclaration node) {
96 return checkAndTagAsMalformed(node);
100 * Method declared on ASTVisitor.
102 public boolean visit(PackageDeclaration node) {
103 return checkAndTagAsMalformed(node);
107 * Method declared on ASTVisitor.
109 public boolean visit(ImportDeclaration node) {
110 return checkAndTagAsMalformed(node);
114 * Method declared on ASTVisitor.
116 public boolean visit(CompilationUnit node) {
117 return checkAndTagAsMalformed(node);
121 * Method declared on ASTVisitor.
123 public boolean visit(AnnotationTypeDeclaration node) {
124 return checkAndTagAsMalformed(node);
128 * Method declared on ASTVisitor.
130 public boolean visit(EnumDeclaration node) {
131 return checkAndTagAsMalformed(node);
135 * Method declared on ASTVisitor.
137 public boolean visit(TypeDeclaration node) {
138 return checkAndTagAsMalformed(node);
142 * Method declared on ASTVisitor.
144 public boolean visit(Initializer node) {
145 return checkAndTagAsMalformed(node);