Java Code Examples for org.eclipse.jdt.core.compiler.CategorizedProblem#getSourceStart()

The following examples show how to use org.eclipse.jdt.core.compiler.CategorizedProblem#getSourceStart() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompilationUnitDeclaration.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean isSuppressed(CategorizedProblem problem) {
	if (this.suppressWarningsCount == 0) return false;
	int irritant = ProblemReporter.getIrritant(problem.getID());
	if (irritant == 0) return false;
	int start = problem.getSourceStart();
	int end = problem.getSourceEnd();
	nextSuppress: for (int iSuppress = 0, suppressCount = this.suppressWarningsCount; iSuppress < suppressCount; iSuppress++) {
		long position = this.suppressWarningScopePositions[iSuppress];
		int startSuppress = (int) (position >>> 32);
		int endSuppress = (int) position;
		if (start < startSuppress) continue nextSuppress;
		if (end > endSuppress) continue nextSuppress;
		if (this.suppressWarningIrritants[iSuppress].isSet(irritant))
			return true;
	}
	return false;
}
 
Example 2
Source File: Main.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void logXmlExtraProblem(CategorizedProblem problem, int globalErrorCount, int localErrorCount) {
	final int sourceStart = problem.getSourceStart();
	final int sourceEnd = problem.getSourceEnd();
	boolean isError = problem.isError();
	this.parameters.put(Logger.PROBLEM_SEVERITY, isError ? Logger.ERROR : Logger.WARNING);
	this.parameters.put(Logger.PROBLEM_LINE, new Integer(problem.getSourceLineNumber()));
	this.parameters.put(Logger.PROBLEM_SOURCE_START, new Integer(sourceStart));
	this.parameters.put(Logger.PROBLEM_SOURCE_END, new Integer(sourceEnd));
	printTag(Logger.EXTRA_PROBLEM_TAG, this.parameters, true, false);
	this.parameters.put(Logger.VALUE, problem.getMessage());
	printTag(Logger.PROBLEM_MESSAGE, this.parameters, true, true);
	extractContext(problem, null);
	endTag(Logger.EXTRA_PROBLEM_TAG);
}
 
Example 3
Source File: Main.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param problem
 *            the given problem to log
 * @param unitSource
 *            the given unit source
 */
private void logXmlProblem(CategorizedProblem problem, char[] unitSource) {
	final int sourceStart = problem.getSourceStart();
	final int sourceEnd = problem.getSourceEnd();
	final int id = problem.getID();
	this.parameters.put(Logger.ID, getFieldName(id)); // ID as field name
	this.parameters.put(Logger.PROBLEM_ID, new Integer(id)); // ID as numeric value
	boolean isError = problem.isError();
	int severity = isError ? ProblemSeverities.Error : ProblemSeverities.Warning;
	this.parameters.put(Logger.PROBLEM_SEVERITY, isError ? Logger.ERROR : Logger.WARNING);
	this.parameters.put(Logger.PROBLEM_LINE, new Integer(problem.getSourceLineNumber()));
	this.parameters.put(Logger.PROBLEM_SOURCE_START, new Integer(sourceStart));
	this.parameters.put(Logger.PROBLEM_SOURCE_END, new Integer(sourceEnd));
	String problemOptionKey = getProblemOptionKey(id);
	if (problemOptionKey != null) {
		this.parameters.put(Logger.PROBLEM_OPTION_KEY, problemOptionKey);
	}
	int categoryID = ProblemReporter.getProblemCategory(severity, id);
	this.parameters.put(Logger.PROBLEM_CATEGORY_ID, new Integer(categoryID));
	printTag(Logger.PROBLEM_TAG, this.parameters, true, false);
	this.parameters.put(Logger.VALUE, problem.getMessage());
	printTag(Logger.PROBLEM_MESSAGE, this.parameters, true, true);
	extractContext(problem, unitSource);
	String[] arguments = problem.getArguments();
	final int length = arguments.length;
	if (length != 0) {
		printTag(Logger.PROBLEM_ARGUMENTS, null, true, false);
		for (int i = 0; i < length; i++) {
			this.parameters.put(Logger.PROBLEM_ARGUMENT_VALUE, arguments[i]);
			printTag(Logger.PROBLEM_ARGUMENT, this.parameters, true, true);
		}
		endTag(Logger.PROBLEM_ARGUMENTS);
	}
	endTag(Logger.PROBLEM_TAG);
}
 
Example 4
Source File: ASTRecoveryPropagator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private boolean markIncludedProblems(int start, int end) {
	boolean foundProblems = false;
	next: for (int i = 0, max = this.problems.length; i < max; i++) {
		CategorizedProblem problem = this.problems[i];

		if(this.usedOrIrrelevantProblems[i]) continue next;

		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:
				this.usedOrIrrelevantProblems[i] = true;
				continue next;

		}

		int problemStart = problem.getSourceStart();
		int problemEnd = problem.getSourceEnd();
		if ((start <= problemStart) && (problemStart <= end) ||
				(start <= problemEnd) && (problemEnd <= end)) {
			this.usedOrIrrelevantProblems[i] = true;
			foundProblems = true;
		}
	}
	return foundProblems;
}
 
Example 5
Source File: ASTSyntaxErrorPropagator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
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;
}
 
Example 6
Source File: Main.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private String errorReportSource(CategorizedProblem problem, char[] unitSource, int bits) {
	//extra from the source the innacurate     token
	//and "highlight" it using some underneath ^^^^^
	//put some context around too.

	//this code assumes that the font used in the console is fixed size

	//sanity .....
	int startPosition = problem.getSourceStart();
	int endPosition = problem.getSourceEnd();
	if (unitSource == null) {
		if (problem.getOriginatingFileName() != null) {
			try {
				unitSource = Util.getFileCharContent(new File(new String(problem.getOriginatingFileName())), null);
			} catch (IOException e) {
				// ignore;
			}
		}
	}
	int length;
	if ((startPosition > endPosition)
		|| ((startPosition < 0) && (endPosition < 0))
		|| (unitSource == null)
		|| (length = unitSource.length) == 0)
		return Messages.problem_noSourceInformation;

	StringBuffer errorBuffer = new StringBuffer();
	if ((bits & Main.Logger.EMACS) == 0) {
		errorBuffer.append(' ').append(Messages.bind(Messages.problem_atLine, String.valueOf(problem.getSourceLineNumber())));
		errorBuffer.append(Util.LINE_SEPARATOR);
	}
	errorBuffer.append('\t');

	char c;
	final char SPACE = '\u0020';
	final char MARK = '^';
	final char TAB = '\t';
	//the next code tries to underline the token.....
	//it assumes (for a good display) that token source does not
	//contain any \r \n. This is false on statements !
	//(the code still works but the display is not optimal !)

	// expand to line limits
	int begin;
	int end;
	for (begin = startPosition >= length ? length - 1 : startPosition; begin > 0; begin--) {
		if ((c = unitSource[begin - 1]) == '\n' || c == '\r') break;
	}
	for (end = endPosition >= length ? length - 1 : endPosition ; end+1 < length; end++) {
		if ((c = unitSource[end + 1]) == '\r' || c == '\n') break;
	}

	// trim left and right spaces/tabs
	while ((c = unitSource[begin]) == ' ' || c == '\t') begin++;
	//while ((c = unitSource[end]) == ' ' || c == '\t') end--; TODO (philippe) should also trim right, but all tests are to be updated

	// copy source
	errorBuffer.append(unitSource, begin, end-begin+1);
	errorBuffer.append(Util.LINE_SEPARATOR).append("\t"); //$NON-NLS-1$

	// compute underline
	for (int i = begin; i <startPosition; i++) {
		errorBuffer.append((unitSource[i] == TAB) ? TAB : SPACE);
	}
	for (int i = startPosition; i <= (endPosition >= length ? length - 1 : endPosition); i++) {
		errorBuffer.append(MARK);
	}
	return errorBuffer.toString();
}
 
Example 7
Source File: Main.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void extractContext(CategorizedProblem problem, char[] unitSource) {
	//sanity .....
	int startPosition = problem.getSourceStart();
	int endPosition = problem.getSourceEnd();
	if (unitSource == null) {
		if (problem.getOriginatingFileName() != null) {
			try {
				unitSource = Util.getFileCharContent(new File(new String(problem.getOriginatingFileName())), null);
			} catch(IOException e) {
				// ignore
			}
		}
	}
	int length;
	if ((startPosition > endPosition)
			|| ((startPosition < 0) && (endPosition < 0))
			|| (unitSource == null)
			|| ((length = unitSource.length) <= 0)
			|| (endPosition > length)) {
		this.parameters.put(Logger.VALUE, Messages.problem_noSourceInformation);
		this.parameters.put(Logger.SOURCE_START, "-1"); //$NON-NLS-1$
		this.parameters.put(Logger.SOURCE_END, "-1"); //$NON-NLS-1$
		printTag(Logger.SOURCE_CONTEXT, this.parameters, true, true);
		return;
	}

	char c;
	//the next code tries to underline the token.....
	//it assumes (for a good display) that token source does not
	//contain any \r \n. This is false on statements !
	//(the code still works but the display is not optimal !)

	// expand to line limits
	int begin, end;
	for (begin = startPosition >= length ? length - 1 : startPosition; begin > 0; begin--) {
		if ((c = unitSource[begin - 1]) == '\n' || c == '\r') break;
	}
	for (end = endPosition >= length ? length - 1 : endPosition ; end+1 < length; end++) {
		if ((c = unitSource[end + 1]) == '\r' || c == '\n') break;
	}

	// trim left and right spaces/tabs
	while ((c = unitSource[begin]) == ' ' || c == '\t') begin++;
	while ((c = unitSource[end]) == ' ' || c == '\t') end--;

	// copy source
	StringBuffer buffer = new StringBuffer();
	buffer.append(unitSource, begin, end - begin + 1);

	this.parameters.put(Logger.VALUE, String.valueOf(buffer));
	this.parameters.put(Logger.SOURCE_START, Integer.toString(startPosition - begin));
	this.parameters.put(Logger.SOURCE_END, Integer.toString(endPosition - begin));
	printTag(Logger.SOURCE_CONTEXT, this.parameters, true, true);
}
 
Example 8
Source File: CompilationResult.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public CategorizedProblem[] getAllProblems() {
	CategorizedProblem[] onlyProblems = getProblems();
	int onlyProblemCount = onlyProblems != null ? onlyProblems.length : 0;
	CategorizedProblem[] onlyTasks = getTasks();
	int onlyTaskCount = onlyTasks != null ? onlyTasks.length : 0;
	if (onlyTaskCount == 0) {
		return onlyProblems;
	}
	if (onlyProblemCount == 0) {
		return onlyTasks;
	}
	int totalNumberOfProblem = onlyProblemCount + onlyTaskCount;
	CategorizedProblem[] allProblems = new CategorizedProblem[totalNumberOfProblem];
	int allProblemIndex = 0;
	int taskIndex = 0;
	int problemIndex = 0;
	while (taskIndex + problemIndex < totalNumberOfProblem) {
		CategorizedProblem nextTask = null;
		CategorizedProblem nextProblem = null;
		if (taskIndex < onlyTaskCount) {
			nextTask = onlyTasks[taskIndex];
		}
		if (problemIndex < onlyProblemCount) {
			nextProblem = onlyProblems[problemIndex];
		}
		// select the next problem
		CategorizedProblem currentProblem = null;
		if (nextProblem != null) {
			if (nextTask != null) {
				if (nextProblem.getSourceStart() < nextTask.getSourceStart()) {
					currentProblem = nextProblem;
					problemIndex++;
				} else {
					currentProblem = nextTask;
					taskIndex++;
				}
			} else {
				currentProblem = nextProblem;
				problemIndex++;
			}
		} else {
			if (nextTask != null) {
				currentProblem = nextTask;
				taskIndex++;
			}
		}
		allProblems[allProblemIndex++] = currentProblem;
	}
	return allProblems;
}