KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > core > dom > ASTSyntaxErrorPropagator


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jdt.core.dom;
13
14 import org.eclipse.jdt.core.compiler.IProblem;
15
16 /**
17  * Internal AST visitor for propagating syntax errors.
18  */

19 class ASTSyntaxErrorPropagator extends ASTVisitor {
20
21     private IProblem[] problems;
22     
23     ASTSyntaxErrorPropagator(IProblem[] problems) {
24         // visit Javadoc.tags() as well
25
super(true);
26         this.problems = problems;
27     }
28
29     private boolean checkAndTagAsMalformed(ASTNode node) {
30         boolean tagWithErrors = false;
31         search: for (int i = 0, max = this.problems.length; i < max; i++) {
32             IProblem problem = this.problems[i];
33             switch(problem.getID()) {
34                 case IProblem.ParsingErrorOnKeywordNoSuggestion :
35                 case IProblem.ParsingErrorOnKeyword :
36                 case IProblem.ParsingError :
37                 case IProblem.ParsingErrorNoSuggestion :
38                 case IProblem.ParsingErrorInsertTokenBefore :
39                 case IProblem.ParsingErrorInsertTokenAfter :
40                 case IProblem.ParsingErrorDeleteToken :
41                 case IProblem.ParsingErrorDeleteTokens :
42                 case IProblem.ParsingErrorMergeTokens :
43                 case IProblem.ParsingErrorInvalidToken :
44                 case IProblem.ParsingErrorMisplacedConstruct :
45                 case IProblem.ParsingErrorReplaceTokens :
46                 case IProblem.ParsingErrorNoSuggestionForTokens :
47                 case IProblem.ParsingErrorUnexpectedEOF :
48                 case IProblem.ParsingErrorInsertToComplete :
49                 case IProblem.ParsingErrorInsertToCompleteScope :
50                 case IProblem.ParsingErrorInsertToCompletePhrase :
51                 case IProblem.EndOfSource :
52                 case IProblem.InvalidHexa :
53                 case IProblem.InvalidOctal :
54                 case IProblem.InvalidCharacterConstant :
55                 case IProblem.InvalidEscape :
56                 case IProblem.InvalidInput :
57                 case IProblem.InvalidUnicodeEscape :
58                 case IProblem.InvalidFloat :
59                 case IProblem.NullSourceString :
60                 case IProblem.UnterminatedString :
61                 case IProblem.UnterminatedComment :
62                 case IProblem.InvalidDigit :
63                     break;
64                 default:
65                     continue search;
66             }
67             int position = problem.getSourceStart();
68             int start = node.getStartPosition();
69             int end = start + node.getLength();
70             if ((start <= position) && (position <= end)) {
71                 node.setFlags(node.getFlags() | ASTNode.MALFORMED);
72                 // clear the bits on parent
73
ASTNode currentNode = node.getParent();
74                 while (currentNode != null) {
75                     currentNode.setFlags(currentNode.getFlags() & ~ASTNode.MALFORMED);
76                     currentNode = currentNode.getParent();
77                 }
78                 tagWithErrors = true;
79             }
80         }
81         return tagWithErrors;
82     }
83
84     /*
85      * Method declared on ASTVisitor.
86      */

87     public boolean visit(FieldDeclaration node) {
88         return checkAndTagAsMalformed(node);
89     }
90
91     /*
92      * Method declared on ASTVisitor.
93      */

94     public boolean visit(MethodDeclaration node) {
95         return checkAndTagAsMalformed(node);
96     }
97
98     /*
99      * Method declared on ASTVisitor.
100      */

101     public boolean visit(PackageDeclaration node) {
102         return checkAndTagAsMalformed(node);
103     }
104
105     /*
106      * Method declared on ASTVisitor.
107      */

108     public boolean visit(ImportDeclaration node) {
109         return checkAndTagAsMalformed(node);
110     }
111
112     /*
113      * Method declared on ASTVisitor.
114      */

115     public boolean visit(CompilationUnit node) {
116         return checkAndTagAsMalformed(node);
117     }
118
119     /*
120      * Method declared on ASTVisitor.
121      */

122     public boolean visit(Initializer node) {
123         return checkAndTagAsMalformed(node);
124     }
125
126 }
127
Popular Tags