org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTSyntaxErrorPropagator.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.22 - (download) (annotate)
Sat Mar 7 01:08:09 2009 UTC (8 months, 3 weeks ago) by oliviert
Branch: MAIN
CVS Tags: v_943, v_942, v_974_R35x, v_969_R35x, v_A03, v_A02, v_A01, v_A00, v_A07, v_A06, v_A05, v_A04, v_A09, v_A08, v_968_R35x, v_958, v_959, v_950, v_951, v_952, v_953, v_954, v_955, v_956, v_957, v_971_R35x, v_978_R35x, v_961, v_960, v_963, v_962, v_964_R35x, v_977_R35x, R3_5, v_A18, v_A19, v_A14, v_A15, v_A16, v_A10, v_A11, v_A12, v_A13, v_966_R35x, v_970_R35x, v_A21, v_A20, v_A23, v_A22, v_975_R35x, v_976_R35x, v_967_R35x, v_965_R35x, v_A21d, v_A21a, jsr308_A22, v_972_R35x, v_949, v_948, v_947, v_946, v_945, v_944, R3_5_1, v_A17b, v_A17c, v_973_R35x, HEAD
Branch point for: JSR_308, R3_5_maintenance
Changes since 1.21: +1 -1 lines
HEAD - Fix copyrights
/*******************************************************************************
 * Copyright (c) 2000, 2009 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.jdt.core.dom;

import org.eclipse.jdt.core.compiler.CategorizedProblem;
import org.eclipse.jdt.core.compiler.IProblem;

/**
 * Internal AST visitor for propagating syntax errors.
 */
class ASTSyntaxErrorPropagator extends ASTVisitor {

	private CategorizedProblem[] problems;

	ASTSyntaxErrorPropagator(CategorizedProblem[] problems) {
		// visit Javadoc.tags() as well
		super(true);
		this.problems = problems;
	}

	private boolean checkAndTagAsMalformed(ASTNode node) {
		boolean tagWithErrors = false;
		search: for (int i = 0, max = this.problems.length; i < max; i++) {
			CategorizedProblem problem = this.problems[i];
			switch(problem.getID()) {
				case IProblem.ParsingErrorOnKeywordNoSuggestion :
				case IProblem.ParsingErrorOnKeyword :
				case IProblem.ParsingError :
				case IProblem.ParsingErrorNoSuggestion :
				case IProblem.ParsingErrorInsertTokenBefore :
				case IProblem.ParsingErrorInsertTokenAfter :
				case IProblem.ParsingErrorDeleteToken :
				case IProblem.ParsingErrorDeleteTokens :
				case IProblem.ParsingErrorMergeTokens :
				case IProblem.ParsingErrorInvalidToken :
				case IProblem.ParsingErrorMisplacedConstruct :
				case IProblem.ParsingErrorReplaceTokens :
				case IProblem.ParsingErrorNoSuggestionForTokens :
				case IProblem.ParsingErrorUnexpectedEOF :
				case IProblem.ParsingErrorInsertToComplete :
				case IProblem.ParsingErrorInsertToCompleteScope :
				case IProblem.ParsingErrorInsertToCompletePhrase :
				case IProblem.EndOfSource :
				case IProblem.InvalidHexa :
				case IProblem.InvalidOctal :
				case IProblem.InvalidCharacterConstant :
				case IProblem.InvalidEscape :
				case IProblem.InvalidInput :
				case IProblem.InvalidUnicodeEscape :
				case IProblem.InvalidFloat :
				case IProblem.NullSourceString :
				case IProblem.UnterminatedString :
				case IProblem.UnterminatedComment :
				case IProblem.InvalidDigit :
					break;
				default:
					continue search;
			}
			int position = problem.getSourceStart();
			int start = node.getStartPosition();
			int end = start + node.getLength();
			if ((start <= position) && (position <= end)) {
				node.setFlags(node.getFlags() | ASTNode.MALFORMED);
				// clear the bits on parent
				ASTNode currentNode = node.getParent();
				while (currentNode != null) {
					currentNode.setFlags(currentNode.getFlags() & ~ASTNode.MALFORMED);
					currentNode = currentNode.getParent();
				}
				tagWithErrors = true;
			}
		}
		return tagWithErrors;
	}

	/*
	 * Method declared on ASTVisitor.
	 */
	public boolean visit(FieldDeclaration node) {
		return checkAndTagAsMalformed(node);
	}

	/*
	 * Method declared on ASTVisitor.
	 */
	public boolean visit(MethodDeclaration node) {
		return checkAndTagAsMalformed(node);
	}

	/*
	 * Method declared on ASTVisitor.
	 */
	public boolean visit(PackageDeclaration node) {
		return checkAndTagAsMalformed(node);
	}

	/*
	 * Method declared on ASTVisitor.
	 */
	public boolean visit(ImportDeclaration node) {
		return checkAndTagAsMalformed(node);
	}

	/*
	 * Method declared on ASTVisitor.
	 */
	public boolean visit(CompilationUnit node) {
		return checkAndTagAsMalformed(node);
	}

	/*
	 * Method declared on ASTVisitor.
	 */
	public boolean visit(AnnotationTypeDeclaration node) {
		return checkAndTagAsMalformed(node);
	}

	/*
	 * Method declared on ASTVisitor.
	 */
	public boolean visit(EnumDeclaration node) {
		return checkAndTagAsMalformed(node);
	}

	/*
	 * Method declared on ASTVisitor.
	 */
	public boolean visit(TypeDeclaration node) {
		return checkAndTagAsMalformed(node);
	}

	/*
	 * Method declared on ASTVisitor.
	 */
	public boolean visit(Initializer node) {
		return checkAndTagAsMalformed(node);
	}

}