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

The following examples show how to use org.eclipse.jdt.core.compiler.CategorizedProblem#isError() . 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: CompilationResult.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void record(CategorizedProblem newProblem, ReferenceContext referenceContext, boolean mandatoryError) {
	//new Exception("VERBOSE PROBLEM REPORTING").printStackTrace();
	if(newProblem.getID() == IProblem.Task) {
		recordTask(newProblem);
		return;
	}
	if (this.problemCount == 0) {
		this.problems = new CategorizedProblem[5];
	} else if (this.problemCount == this.problems.length) {
		System.arraycopy(this.problems, 0, (this.problems = new CategorizedProblem[this.problemCount * 2]), 0, this.problemCount);
	}
	this.problems[this.problemCount++] = newProblem;
	if (referenceContext != null){
		if (this.problemsMap == null) this.problemsMap = new HashMap(5);
		if (this.firstErrors == null) this.firstErrors = new HashSet(5);
		if (newProblem.isError() && !referenceContext.hasErrors()) this.firstErrors.add(newProblem);
		this.problemsMap.put(newProblem, referenceContext);
	}
	if (newProblem.isError()) {
		this.numberOfErrors++;
		if (mandatoryError) this.hasMandatoryErrors = true;
		if ((newProblem.getID() & IProblem.Syntax) != 0) {
			this.hasSyntaxError = true;
		}
	}
}
 
Example 2
Source File: Compiler.java    From APDE with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void loggingExtraProblems(Main currentMain) {
	// Unknown whether or not this is actually necessary
	ArrayList<CategorizedProblem> problems = compiler.getExtraProblems();
	if (problems != null) {
		for (CategorizedProblem problem : problems) {
			handleProblem(problem);
			
			// These counters are necessary for ECJ to function properly
			if (problem.isError()) {
				currentMain.globalErrorsCount++;
			}  else {
				currentMain.globalWarningsCount++;
			}
		}
	}
}
 
Example 3
Source File: Compiler.java    From APDE with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int logProblems(CategorizedProblem[] problems, char[] unitSource, Main currentMain) {
	int localErrorCount = 0;
	
	for (CategorizedProblem problem : problems) {
		if (problem != null) {
			handleProblem(problem);
			
			// These counters are necessary for ECJ to function properly
			if (problem.isError()) {
				localErrorCount++;
				currentMain.globalErrorsCount++;
			} else if (problem.getID() == IProblem.Task) {
				currentMain.globalTasksCount++;
			} else {
				currentMain.globalWarningsCount++;
			}
		}
	}
	
	return localErrorCount;
}
 
Example 4
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 5
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 6
Source File: CompilationResult.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private int computePriority(CategorizedProblem problem){
	final int P_STATIC = 10000;
	final int P_OUTSIDE_METHOD = 40000;
	final int P_FIRST_ERROR = 20000;
	final int P_ERROR = 100000;

	int priority = 10000 - problem.getSourceLineNumber(); // early problems first
	if (priority < 0) priority = 0;
	if (problem.isError()){
		priority += P_ERROR;
	}
	ReferenceContext context = this.problemsMap == null ? null : (ReferenceContext) this.problemsMap.get(problem);
	if (context != null){
		if (context instanceof AbstractMethodDeclaration){
			AbstractMethodDeclaration method = (AbstractMethodDeclaration) context;
			if (method.isStatic()) {
				priority += P_STATIC;
			}
		} else {
			priority += P_OUTSIDE_METHOD;
		}
		if (this.firstErrors.contains(problem)){ // if context is null, firstErrors is null too
		  priority += P_FIRST_ERROR;
	    }
	} else {
		priority += P_OUTSIDE_METHOD;
	}
	return priority;
}
 
Example 7
Source File: CompilationResult.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void removeProblem(CategorizedProblem problem) {
	if (this.problemsMap != null) this.problemsMap.remove(problem);
	if (this.firstErrors != null) this.firstErrors.remove(problem);
	if (problem.isError()) {
		this.numberOfErrors--;
	}
	this.problemCount--;
}
 
Example 8
Source File: CompilerJdt.java    From takari-lifecycle with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void acceptResult(CompilationResult result) {
  if (result == null) {
    return; // ah?
  }

  final String sourceName = new String(result.getFileName());
  final File sourceFile = new File(sourceName);

  Resource<File> input = context.getProcessedSource(sourceFile);

  // track type references
  if (result.rootReferences != null && result.qualifiedReferences != null && result.simpleNameReferences != null) {
    context.setAttribute(input.getResource(), ATTR_REFERENCES, new ReferenceCollection(result.rootReferences, result.qualifiedReferences, result.simpleNameReferences));
  }

  if (result.hasProblems()) {
    for (CategorizedProblem problem : result.getProblems()) {
      if (problem.isError() || isShowWarnings()) {
        MessageSeverity severity = problem.isError() ? MessageSeverity.ERROR : MessageSeverity.WARNING;
        input.addMessage(problem.getSourceLineNumber(), ((DefaultProblem) problem).column, problem.getMessage(), severity, null /* cause */);
      }
    }
  }

  try {
    if (!result.hasErrors() && !isProcOnly()) {
      for (ClassFile classFile : result.getClassFiles()) {
        char[] filename = classFile.fileName();
        int length = filename.length;
        char[] relativeName = new char[length + 6];
        System.arraycopy(filename, 0, relativeName, 0, length);
        System.arraycopy(SuffixConstants.SUFFIX_class, 0, relativeName, length, 6);
        CharOperation.replace(relativeName, '/', File.separatorChar);
        String relativeStringName = new String(relativeName);
        writeClassFile(input, relativeStringName, classFile);
      }
    }
  } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
  // XXX double check affected sources are recompiled when this source has errors
}