1 11 12 package org.eclipse.jdt.core.dom; 13 14 import org.eclipse.jdt.core.compiler.IProblem; 15 16 19 class ASTSyntaxErrorPropagator extends ASTVisitor { 20 21 private IProblem[] problems; 22 23 ASTSyntaxErrorPropagator(IProblem[] problems) { 24 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 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 87 public boolean visit(FieldDeclaration node) { 88 return checkAndTagAsMalformed(node); 89 } 90 91 94 public boolean visit(MethodDeclaration node) { 95 return checkAndTagAsMalformed(node); 96 } 97 98 101 public boolean visit(PackageDeclaration node) { 102 return checkAndTagAsMalformed(node); 103 } 104 105 108 public boolean visit(ImportDeclaration node) { 109 return checkAndTagAsMalformed(node); 110 } 111 112 115 public boolean visit(CompilationUnit node) { 116 return checkAndTagAsMalformed(node); 117 } 118 119 122 public boolean visit(Initializer node) { 123 return checkAndTagAsMalformed(node); 124 } 125 126 } 127 | Popular Tags |