use of org.eclipse.jdt.core.IJavaElementDelta in project che by eclipse.
the class DeltaProcessor method updateJavaModel.
// /*
// * Validate the classpaths of the projects affected by the given delta.
// * Create markers if necessary.
// * Returns whether cycle markers should be recomputed.
// */
// private boolean validateClasspaths(IResourceDelta delta) {
// HashSet affectedProjects = new HashSet(5);
// validateClasspaths(delta, affectedProjects);
// boolean needCycleValidation = false;
//
// // validate classpaths of affected projects (dependent projects
// // or projects that reference a library in one of the projects that have changed)
// if (!affectedProjects.isEmpty()) {
// IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
// IProject[] projects = workspaceRoot.getProjects();
// int length = projects.length;
// for (int i = 0; i < length; i++){
// IProject project = projects[i];
// JavaProject javaProject = (JavaProject)JavaCore.create(project);
// try {
// IPath projectPath = project.getFullPath();
// IClasspathEntry[] classpath = javaProject.getResolvedClasspath(); // allowed to reuse model cache
// for (int j = 0, cpLength = classpath.length; j < cpLength; j++) {
// IClasspathEntry entry = classpath[j];
// switch (entry.getEntryKind()) {
// case IClasspathEntry.CPE_PROJECT:
// if (affectedProjects.contains(entry.getPath())) {
// this.state.addClasspathValidation(javaProject);
// needCycleValidation = true;
// }
// break;
// case IClasspathEntry.CPE_LIBRARY:
// IPath entryPath = entry.getPath();
// IPath libProjectPath = entryPath.removeLastSegments(entryPath.segmentCount()-1);
// if (!libProjectPath.equals(projectPath) // if library contained in another project
// && affectedProjects.contains(libProjectPath)) {
// this.state.addClasspathValidation(javaProject);
// }
// break;
// }
// }
// } catch(JavaModelException e) {
// // project no longer exists
// }
// }
// }
// return needCycleValidation;
// }
/*
* Update Java Model given some delta
*/
public void updateJavaModel(IJavaElementDelta customDelta) {
if (customDelta == null) {
for (int i = 0, length = this.javaModelDeltas.size(); i < length; i++) {
IJavaElementDelta delta = (IJavaElementDelta) this.javaModelDeltas.get(i);
this.modelUpdater.processJavaDelta(delta);
}
} else {
this.modelUpdater.processJavaDelta(customDelta);
}
}
use of org.eclipse.jdt.core.IJavaElementDelta in project che by eclipse.
the class DeltaProcessor method mergeDeltas.
/*
* Merges all awaiting deltas.
*/
private IJavaElementDelta mergeDeltas(Collection deltas) {
if (deltas.size() == 0)
return null;
if (deltas.size() == 1)
return (IJavaElementDelta) deltas.iterator().next();
if (VERBOSE) {
System.out.println(//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"MERGING " + deltas.size() + " DELTAS [" + Thread.currentThread() + "]");
}
Iterator iterator = deltas.iterator();
JavaElementDelta rootDelta = new JavaElementDelta(this.manager.javaModel);
boolean insertedTree = false;
while (iterator.hasNext()) {
JavaElementDelta delta = (JavaElementDelta) iterator.next();
if (VERBOSE) {
System.out.println(delta.toString());
}
IJavaElement element = delta.getElement();
if (this.manager.javaModel.equals(element)) {
IJavaElementDelta[] children = delta.getAffectedChildren();
for (int j = 0; j < children.length; j++) {
JavaElementDelta projectDelta = (JavaElementDelta) children[j];
rootDelta.insertDeltaTree(projectDelta.getElement(), projectDelta);
insertedTree = true;
}
IResourceDelta[] resourceDeltas = delta.getResourceDeltas();
if (resourceDeltas != null) {
for (int i = 0, length = resourceDeltas.length; i < length; i++) {
rootDelta.addResourceDelta(resourceDeltas[i]);
insertedTree = true;
}
}
} else {
rootDelta.insertDeltaTree(element, delta);
insertedTree = true;
}
}
if (insertedTree)
return rootDelta;
return null;
}
use of org.eclipse.jdt.core.IJavaElementDelta in project che by eclipse.
the class DeltaProcessor method fire.
/*
* Fire Java Model delta, flushing them after the fact after post_change notification.
* If the firing mode has been turned off, this has no effect.
*/
public void fire(IJavaElementDelta customDelta, int eventType) {
if (!this.isFiring)
return;
if (DEBUG) {
System.out.println(//$NON-NLS-1$
"-----------------------------------------------------------------------------------------------------------------------");
}
IJavaElementDelta deltaToNotify;
if (customDelta == null) {
deltaToNotify = mergeDeltas(this.javaModelDeltas);
} else {
deltaToNotify = customDelta;
}
// Refresh internal scopes
if (deltaToNotify != null) {
Iterator scopes = this.manager.searchScopes.keySet().iterator();
while (scopes.hasNext()) {
AbstractSearchScope scope = (AbstractSearchScope) scopes.next();
scope.processDelta(deltaToNotify, eventType);
}
JavaWorkspaceScope workspaceScope = this.manager.workspaceScope;
if (workspaceScope != null)
workspaceScope.processDelta(deltaToNotify, eventType);
}
// Notification
// Important: if any listener reacts to notification by updating the listeners list or mask, these lists will
// be duplicated, so it is necessary to remember original lists in a variable (since field values may change under us)
IElementChangedListener[] listeners;
int[] listenerMask;
int listenerCount;
synchronized (this.state) {
listeners = this.state.elementChangedListeners;
listenerMask = this.state.elementChangedListenerMasks;
listenerCount = this.state.elementChangedListenerCount;
}
switch(eventType) {
case DEFAULT_CHANGE_EVENT:
case ElementChangedEvent.POST_CHANGE:
firePostChangeDelta(deltaToNotify, listeners, listenerMask, listenerCount);
fireReconcileDelta(listeners, listenerMask, listenerCount);
break;
}
}
use of org.eclipse.jdt.core.IJavaElementDelta in project che by eclipse.
the class DeltaProcessor method resourceChanged.
/*
* Notification that some resource changes have happened
* on the platform, and that the Java Model should update any required
* internal structures such that its elements remain consistent.
* Translates <code>IResourceDeltas</code> into <code>IJavaElementDeltas</code>.
*
* @see IResourceDelta
* @see IResource
*/
public void resourceChanged(IResourceChangeEvent event) {
int eventType = this.overridenEventType == -1 ? event.getType() : this.overridenEventType;
IResource resource = event.getResource();
IResourceDelta delta = (IResourceDelta) event.getDelta();
switch(eventType) {
case IResourceChangeEvent.PRE_DELETE:
// }
return;
case IResourceChangeEvent.PRE_REFRESH:
// }
return;
case IResourceChangeEvent.POST_CHANGE:
HashSet elementsToRefresh = this.state.removeExternalElementsToRefresh();
if (// avoid populating for SYNC or MARKER deltas
isAffectedBy(delta) || elementsToRefresh != null) {
try {
try {
stopDeltas();
checkProjectsAndClasspathChanges(delta);
// generate external archive change deltas
if (elementsToRefresh != null) {
createExternalArchiveDelta(elementsToRefresh, null);
}
// generate classpath change deltas
HashMap classpathChanges = this.state.removeAllClasspathChanges();
// if (classpathChanges.size() > 0) {
// boolean hasDelta = this.currentDelta != null;
// JavaElementDelta javaDelta = currentDelta();
// Iterator changes = classpathChanges.values().iterator();
// while (changes.hasNext()) {
// ClasspathChange change = (ClasspathChange) changes.next();
// int result = change.generateDelta(javaDelta, false/*don't add classpath change*/);
// if ((result & ClasspathChange.HAS_DELTA) != 0) {
// hasDelta = true;
//
// // need to recompute root infos
// this.state.rootsAreStale = true;
//
// change.requestIndexing();
// this.state.addClasspathValidation(change.project);
// }
// if ((result & ClasspathChange.HAS_PROJECT_CHANGE) != 0) {
// this.state.addProjectReferenceChange(change.project, change.oldResolvedClasspath);
// }
// if ((result & ClasspathChange.HAS_LIBRARY_CHANGE) != 0) {
// this.state.addExternalFolderChange(change.project, change.oldResolvedClasspath);
// }
// }
// // process late coming external elements to refresh (see https://bugs.eclipse.org/bugs/show_bug
// .cgi?id=212769 )
// elementsToRefresh = this.state.removeExternalElementsToRefresh();
// if (elementsToRefresh != null) {
// hasDelta |= createExternalArchiveDelta(elementsToRefresh, null);
// }
// if (!hasDelta)
// this.currentDelta = null;
// }
// generate Java deltas from resource changes
IJavaElementDelta translatedDelta = processResourceDelta(delta);
if (translatedDelta != null) {
registerJavaModelDelta(translatedDelta);
}
} finally {
// don't hold onto parser longer than necessary
this.sourceElementParserCache = null;
startDeltas();
}
IElementChangedListener[] listeners;
int listenerCount;
synchronized (this.state) {
listeners = this.state.elementChangedListeners;
listenerCount = this.state.elementChangedListenerCount;
}
notifyTypeHierarchies(listeners, listenerCount);
fire(null, ElementChangedEvent.POST_CHANGE);
} finally {
// workaround for bug 15168 circular errors not reported
this.state.resetOldJavaProjectNames();
this.oldRoots = null;
}
}
return;
case IResourceChangeEvent.PRE_BUILD:
// does not fire any deltas
return;
case IResourceChangeEvent.POST_BUILD:
// JavaBuilder.buildFinished();
return;
}
}
use of org.eclipse.jdt.core.IJavaElementDelta in project che by eclipse.
the class DeltaProcessor method fireReconcileDelta.
private void fireReconcileDelta(IElementChangedListener[] listeners, int[] listenerMask, int listenerCount) {
IJavaElementDelta deltaToNotify = mergeDeltas(this.reconcileDeltas.values());
if (DEBUG) {
//$NON-NLS-1$//$NON-NLS-2$
System.out.println("FIRING POST_RECONCILE Delta [" + Thread.currentThread() + "]:");
//$NON-NLS-1$
System.out.println(deltaToNotify == null ? "<NONE>" : deltaToNotify.toString());
}
if (deltaToNotify != null) {
// flush now so as to keep listener reactions to post their own deltas for subsequent iteration
this.reconcileDeltas = new HashMap();
notifyListeners(deltaToNotify, ElementChangedEvent.POST_RECONCILE, listeners, listenerMask, listenerCount);
}
}
Aggregations