Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2008 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.internal.core.builder;
 
 import  org.eclipse.core.resources.*;
 import  org.eclipse.core.runtime.*;
 
 
 public class BuildNotifier {
 
 protected IProgressMonitor monitor;
 protected boolean cancelling;
 protected float percentComplete;
 protected float progressPerCompilationUnit;
 protected int newErrorCount;
 protected int fixedErrorCount;
 protected int newWarningCount;
 protected int fixedWarningCount;
 protected int workDone;
 protected int totalWork;
 protected String previousSubtask;
 
 public static int NewErrorCount = 0;
 public static int FixedErrorCount = 0;
 public static int NewWarningCount = 0;
 public static int FixedWarningCount = 0;
 
 public static void resetProblemCounters() {
 	 = 0;
 }
 
 public BuildNotifier(IProgressMonitor monitor, IProject project) {
 	this. = monitor;
 	this. = false;
 	this. = 0;
 	this. = 1000000;
 }

Notification before a compile that a unit is about to be compiled.
 
 public void aboutToCompile(SourceFile unit) {
 	String message = Messages.bind(.unit.resource.getFullPath().removeLastSegments(1).makeRelative().toString());
 	subTask(message);
 }
 
 public void begin() {
 	if (this. != null)
 		this..beginTask(""this.); //$NON-NLS-1$
 	this. = null;
 }

Check whether the build has been canceled.
 
 public void checkCancel() {
 	if (this. != null && this..isCanceled())
 		throw new OperationCanceledException();
 }

Check whether the build has been canceled. Must use this call instead of checkCancel() when within the compiler.
 
 public void checkCancelWithinCompiler() {
 	if (this. != null && this..isCanceled() && !this.) {
 		// Once the compiler has been canceled, don't check again.
 		setCancelling(true);
 		// Only AbortCompilation can stop the compiler cleanly.
 		// We check cancelation again following the call to compile.
 		throw new AbortCompilation(truenull);
 	}
 }

Notification while within a compile that a unit has finished being compiled.
 
 public void compiled(SourceFile unit) {
 	String message = Messages.bind(.unit.resource.getFullPath().removeLastSegments(1).makeRelative().toString());
 	subTask(message);
public void done() {
	if (this. != null)
		this..done();
	this. = null;
Returns a string describing the problems.
protected String problemsMessage() {
	int numNew = this. + this.;
	int numFixed = this. + this.;
	if (numNew == 0 && numFixed == 0) return ""//$NON-NLS-1$
	boolean displayBoth = numNew > 0 && numFixed > 0;
	StringBuffer buffer = new StringBuffer();
	buffer.append('(');
	if (numNew > 0) {
		// (Found x errors + y warnings)
		buffer.append(' ');
		if (displayBoth || this. > 0) {
			if (this. == 1)
			else
			if (displayBoth || this. > 0)
				buffer.append(" + "); //$NON-NLS-1$
		}
		if (displayBoth || this. > 0) {
			if (this. == 1)
			else
		}
		if (numFixed > 0)
			buffer.append(", "); //$NON-NLS-1$
	}
	if (numFixed > 0) {
		// (Fixed x errors + y warnings) or (Found x errors + y warnings, Fixed x + y)
		buffer.append(' ');
		if (displayBoth) {
			buffer.append(String.valueOf(this.));
			buffer.append(" + "); //$NON-NLS-1$
			buffer.append(String.valueOf(this.));
else {
			if (this. > 0) {
				if (this. == 1)
				else
				if (this. > 0)
					buffer.append(" + "); //$NON-NLS-1$
			}
			if (this. > 0) {
				if (this. == 1)
				else
			}
		}
	}
	buffer.append(')');
	return buffer.toString();
Sets the cancelling flag, which indicates we are in the middle of being cancelled. Certain places (those callable indirectly from the compiler) should not check cancel again while this is true, to avoid OperationCanceledException being thrown at an inopportune time.
public void setCancelling(boolean cancelling) {
	this. = cancelling;
Sets the amount of progress to report for compiling each compilation unit.
public void setProgressPerCompilationUnit(float progress) {
	this. = progress;
public void subTask(String message) {
	String msg = pm.length() == 0 ? message : pm + " " + message//$NON-NLS-1$
	if (msg.equals(this.)) return// avoid refreshing with same one
	//if (JavaBuilder.DEBUG) System.out.println(msg);
	if (this. != null)
		this..subTask(msg);
	this. = msg;
protected void updateProblemCounts(CategorizedProblem[] newProblems) {
	for (int i = 0, l = newProblems.lengthi < li++)
		if (newProblems[i].isError()) this.++; else this.++;
Update the problem counts from one compilation result given the old and new problems, either of which may be null.
protected void updateProblemCounts(IMarker[] oldProblemsCategorizedProblem[] newProblems) {
	if (newProblems != null) {
		next : for (int i = 0, l = newProblems.lengthi < li++) {
			CategorizedProblem newProblem = newProblems[i];
			if (newProblem.getID() == .continue// skip task
			boolean isError = newProblem.isError();
			String message = newProblem.getMessage();
			if (oldProblems != null) {
				for (int j = 0, m = oldProblems.length; j < mj++) {
					IMarker pb = oldProblems[j];
					if (pb == nullcontinue// already matched up with a new problem
					boolean wasError = IMarker.SEVERITY_ERROR
						== pb.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
					if (isError == wasError && message.equals(pb.getAttribute(IMarker.MESSAGE, ""))) { //$NON-NLS-1$
						oldProblems[j] = null;
						continue next;
					}
				}
			}
			if (isErrorthis.++; else this.++;
		}
	}
	if (oldProblems != null) {
		next : for (int i = 0, l = oldProblems.length; i < li++) {
			IMarker oldProblem = oldProblems[i];
			if (oldProblem == nullcontinue next; // already matched up with a new problem
			boolean wasError = IMarker.SEVERITY_ERROR
				== oldProblem.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
			String message = oldProblem.getAttribute(IMarker.MESSAGE, ""); //$NON-NLS-1$
			if (newProblems != null) {
				for (int j = 0, m = newProblems.lengthj < mj++) {
					CategorizedProblem pb = newProblems[j];
					if (pb.getID() == .continue// skip task
					if (wasError == pb.isError() && message.equals(pb.getMessage()))
						continue next;
				}
			}
			if (wasErrorthis.++; else this.++;
		}
	}
public void updateProgress(float newPercentComplete) {
	if (newPercentComplete > this.) {
		this. = Math.min(newPercentComplete, 1.0f);
		int work = Math.round(this. * this.);
		if (work > this.) {
			if (this. != null)
				this..worked(work - this.);
			//if (JavaBuilder.DEBUG)
				//System.out.println(java.text.NumberFormat.getPercentInstance().format(this.percentComplete));
			this. = work;
		}
	}
public void updateProgressDelta(float percentWorked) {
	updateProgress(this. + percentWorked);
New to GrepCode? Check out our FAQ X