Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jdt-core-dev] Openable.makeConsistent(IProgressMonitor monitor)

Hello developers of the JDT core,

I'm trying to learn how JDT is working and at the moment I examine the
package core.model. Now I'm a little bit confused about the function
"makeConsistent" in the class "Openable". It calls the function
"openWhenClosed(Object info, IProgressMonitor monitor)" and passes a
HashMap through the parameter "info" to it, but that function and no
other subsequent call handles the HashMap. This hash map is also
passed to a call of "Openable.generateInfos(Object info, HashMap
newElements, IProgressMonitor monitor)" and there is a type cast to
"OpenableElementInfo" what should throw a TypCastException IMHO.

I don't understand why Openable.makeConsistent passes that hash map!
It makes no sense to me. Please could someone try to explain me the
black magic behind it?

Here are the relevant code snippets:
-----
public void makeConsistent(IProgressMonitor monitor) throws JavaModelException {
	if (isConsistent()) return;
	
	// create a new info and make it the current info
	// (this will remove the info and its children just before storing
the new infos)
	JavaModelManager manager = JavaModelManager.getJavaModelManager();
	boolean hadTemporaryCache = manager.hasTemporaryCache();
	try {
		HashMap newElements = manager.getTemporaryCache();
		openWhenClosed(newElements, monitor);
		if (newElements.get(this) == null) {
			// close any buffer that was opened for the new elements
			Iterator iterator = newElements.keySet().iterator();
			while (iterator.hasNext()) {
				IJavaElement element = (IJavaElement)iterator.next();
				if (element instanceof Openable) {
					((Openable)element).closeBuffer();
				}
			}
			throw newNotPresentException();
		}
		if (!hadTemporaryCache) {
			manager.putInfos(this, newElements);
		}
	} finally {
		if (!hadTemporaryCache) {
			manager.resetTemporaryCache();
		}
	}
}
-------
protected void generateInfos(Object info, HashMap newElements,
   IProgressMonitor monitor) throws JavaModelException {

	...
	
	// open the parent if necessary
	openParent(info, newElements, monitor);
	if (monitor != null && monitor.isCanceled())
		throw new OperationCanceledException();

	 // puts the info before building the structure so that questions to
the handle behave as if the element existed
	 // (case of compilation units becoming working copies)
	newElements.put(this, info);

	// build the structure of the openable (this will open the buffer if needed)
	try {
		OpenableElementInfo openableElementInfo = (OpenableElementInfo)info;
		boolean isStructureKnown = buildStructure(openableElementInfo,
monitor, newElements, getResource());
		openableElementInfo.setIsStructureKnown(isStructureKnown);
	} catch (JavaModelException e) {
		newElements.remove(this);
		throw e;
	}
	
	// remove out of sync buffer for this element
JavaModelManager.getJavaModelManager().getElementsOutOfSynchWithBuffers().remove(this);
       ...
}


Back to the top