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;
 
 import java.util.Map;
 
 import  org.eclipse.core.runtime.ISafeRunnable;
 import  org.eclipse.core.runtime.OperationCanceledException;
 import  org.eclipse.core.runtime.SafeRunner;
Reconcile a working copy and signal the changes through a delta.

High level summmary of what a reconcile does:

  • populates the model with the new working copy contents
  • fires a fine grained delta (flag F_FINE_GRAINED) describing the difference between the previous content and the new content (which method was added/removed, which field was changed, etc.)
  • computes problems and reports them to the IProblemRequestor (begingReporting(), n x acceptProblem(...), endReporting()) iff (working copy is not consistent with its buffer || forceProblemDetection is set) && problem requestor is active
  • produces a DOM AST (either JLS_2, JLS_3 or NO_AST) that is resolved if flag is set
  • notifies compilation participants of the reconcile allowing them to participate in this operation and report problems
 
 	public static boolean PERF = false;
 
 	public int astLevel;
 	public boolean resolveBindings;
 	public HashMap problems;
 	public int reconcileFlags;
 	public boolean requestorIsActive;
 
 	public ReconcileWorkingCopyOperation(IJavaElement workingCopyint astLevelint reconcileFlagsWorkingCopyOwner workingCopyOwner) {
 		super(new IJavaElement[] {workingCopy});
 		this. = astLevel;
 		this. = reconcileFlags;
 		this. = workingCopyOwner;
 	}

Throws:
JavaModelException if setting the source of the original compilation unit fails
 
 	protected void executeOperation() throws JavaModelException {
 		try {
 
 			CompilationUnit workingCopy = getWorkingCopy();
 			boolean wasConsistent = workingCopy.isConsistent();
 
 			// check is problem requestor is active
 			IProblemRequestor problemRequestor = workingCopy.getPerWorkingCopyInfo();
 			if (problemRequestor != null)
 				problemRequestor =  ((JavaModelManager.PerWorkingCopyInfo)problemRequestor).getProblemRequestor();
 			boolean defaultRequestorIsActive = problemRequestor != null && problemRequestor.isActive();
 			IProblemRequestor ownerProblemRequestor = this..getProblemRequestor(workingCopy);
 			boolean ownerRequestorIsActive = ownerProblemRequestor != null && ownerProblemRequestor != problemRequestor && ownerProblemRequestor.isActive();
 			this. = defaultRequestorIsActive || ownerRequestorIsActive;
 
 			// create the delta builder (this remembers the current content of the cu)
 			this. = new JavaElementDeltaBuilder(workingCopy);
 
 			// make working copy consistent if needed and compute AST if needed
 			makeConsistent(workingCopy);
 
 			// notify reconcile participants only if working copy was not consistent or if forcing problem detection
 			// (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=177319)
 			if (!wasConsistent || ((this. & .) != 0)) {
 				notifyParticipants(workingCopy);
 
 				// recreate ast if one participant reset it
 				if (this. == null)
 					makeConsistent(workingCopy);
 			}
			// report problems
			if (this. != null && (((this. & .) != 0) || !wasConsistent)) {
				if (defaultRequestorIsActive) {
					reportProblems(workingCopyproblemRequestor);
				}
				if (ownerRequestorIsActive) {
					reportProblems(workingCopyownerProblemRequestor);
				}
			}
			// report delta
			if (delta != null) {
				addReconcileDelta(workingCopydelta);
			}
finally {
		}
	}

Report working copy problems to a given requestor.

Parameters:
workingCopy
problemRequestor
	private void reportProblems(CompilationUnit workingCopyIProblemRequestor problemRequestor) {
		try {
			problemRequestor.beginReporting();
			for (Iterator iteraror = this..values().iterator(); iteraror.hasNext();) {
				CategorizedProblem[] categorizedProblems = (CategorizedProblem[]) iteraror.next();
				if (categorizedProblems == nullcontinue;
				for (int i = 0, length = categorizedProblems.lengthi < lengthi++) {
					CategorizedProblem problem = categorizedProblems[i];
						..println("PROBLEM FOUND while reconciling : " + problem.getMessage());//$NON-NLS-1$
					}
					if (this. != null && this..isCanceled()) break;
					problemRequestor.acceptProblem(problem);
				}
			}
finally {
			problemRequestor.endReporting();
		}
	}

Returns the working copy this operation is working on.
	}
	/* (non-Javadoc)
	 * @see org.eclipse.jdt.internal.core.JavaModelOperation#isReadOnly()
	 */
	public boolean isReadOnly() {
		return true;
	}
	/*
	 * Makes the given working copy consistent, computes the delta and computes an AST if needed.
	 * Returns the AST.
	 */
		if (!workingCopy.isConsistent()) {
			// make working copy consistent
			if (this. == nullthis. = new HashMap();
			this. = workingCopy.makeConsistent(this.this.this.this.this.);
			if (this. != null && this.. != null)
			return this.;
		}
		if (this. != null)
			return this.// no need to recompute AST if known already
		try {
			CompilationUnit source = workingCopy.cloneCachingContents();
			// find problems if needed
			if (JavaProject.hasJavaNature(workingCopy.getJavaProject().getProject())
				if (this. == null)
					this. = new HashMap();
				unit =
					CompilationUnitProblemFinder.process(
						source,
						this. != ./*creating AST if level is not NO_AST */,
				if (this. != nullthis..worked(1);
			}
			// create AST if needed
					&& unit !=null/*unit is null if working copy is consistent && (problem detection not forced || non-Java project) -> don't create AST as per API*/) {
				Map options = workingCopy.getJavaProject().getOptions(true);
				// convert AST
				this. =
						unit,
						options,
						source,
				if (this. != null) {
					if (this.. == null) {
						this.. = new JavaElementDelta(workingCopy);
					}
				}
				if (this. != nullthis..worked(1);
			}
	    } catch (JavaModelException e) {
	    	if (JavaProject.hasJavaNature(workingCopy.getJavaProject().getProject()))
	    		throw e;
	    	// else JavaProject has lost its nature (or most likely was closed/deleted) while reconciling -> ignore
	    	// (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=100919)
	    } finally {
	        if (unit != null) {
	            unit.cleanUp();
	        }
	    }
		return this.;
	}
	private void notifyParticipants(final CompilationUnit workingCopy) {
		if (participants == nullreturn;
		final ReconcileContext context = new ReconcileContext(thisworkingCopy);
		for (int i = 0, length = participants.lengthi < lengthi++) {
			final CompilationParticipant participant = participants[i];
			SafeRunner.run(new ISafeRunnable() {
				public void handleException(Throwable exception) {
					if (exception instanceof Error) {
						throw (Errorexception// errors are not supposed to be caught
else if (exception instanceof OperationCanceledException)
						throw (OperationCanceledException) exception;
					else if (exception instanceof UnsupportedOperationException) {
						// might want to disable participant as it tried to modify the buffer of the working copy being reconciled
						Util.log(exception"Reconcile participant attempted to modify the buffer of the working copy being reconciled"); //$NON-NLS-1$
else
						Util.log(exception"Exception occurred in reconcile participant"); //$NON-NLS-1$
				}
				public void run() throws Exception {
					participant.reconcile(context);
				}
			});
		}
	}
	protected IJavaModelStatus verify() {
		IJavaModelStatus status = super.verify();
		if (!status.isOK()) {
			return status;
		}
		CompilationUnit workingCopy = getWorkingCopy();
		if (!workingCopy.isWorkingCopy()) {
			return new JavaModelStatus(.workingCopy); //was destroyed
		}
		return status;
	}
New to GrepCode? Check out our FAQ X