Search in sources :

Example 1 with IJavaElementDelta

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);
    }
}
Also used : IJavaElementDelta(org.eclipse.jdt.core.IJavaElementDelta)

Example 2 with IJavaElementDelta

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;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IJavaElementDelta(org.eclipse.jdt.core.IJavaElementDelta) Iterator(java.util.Iterator) IJavaElementDelta(org.eclipse.jdt.core.IJavaElementDelta) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 3 with IJavaElementDelta

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;
    }
}
Also used : IElementChangedListener(org.eclipse.jdt.core.IElementChangedListener) Iterator(java.util.Iterator) AbstractSearchScope(org.eclipse.jdt.internal.core.search.AbstractSearchScope) IJavaElementDelta(org.eclipse.jdt.core.IJavaElementDelta) JavaWorkspaceScope(org.eclipse.jdt.internal.core.search.JavaWorkspaceScope)

Example 4 with IJavaElementDelta

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;
    }
}
Also used : HashMap(java.util.HashMap) IElementChangedListener(org.eclipse.jdt.core.IElementChangedListener) IJavaElementDelta(org.eclipse.jdt.core.IJavaElementDelta) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta) HashSet(java.util.HashSet)

Example 5 with IJavaElementDelta

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);
    }
}
Also used : HashMap(java.util.HashMap) IJavaElementDelta(org.eclipse.jdt.core.IJavaElementDelta)

Aggregations

IJavaElementDelta (org.eclipse.jdt.core.IJavaElementDelta)8 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 IResourceDelta (org.eclipse.core.resources.IResourceDelta)2 IElementChangedListener (org.eclipse.jdt.core.IElementChangedListener)2 IJavaElement (org.eclipse.jdt.core.IJavaElement)2 IResource (org.eclipse.core.resources.IResource)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)1 AbstractSearchScope (org.eclipse.jdt.internal.core.search.AbstractSearchScope)1 JavaWorkspaceScope (org.eclipse.jdt.internal.core.search.JavaWorkspaceScope)1