Search in sources :

Example 1 with IElementChangedListener

use of org.eclipse.jdt.core.IElementChangedListener in project che by eclipse.

the class DeltaProcessor method notifyTypeHierarchies.

private void notifyTypeHierarchies(IElementChangedListener[] listeners, int listenerCount) {
    for (int i = 0; i < listenerCount; i++) {
        final IElementChangedListener listener = listeners[i];
        if (!(listener instanceof TypeHierarchy))
            continue;
        // wrap callbacks with Safe runnable for subsequent listeners to be called when some are causing grief
        SafeRunner.run(new ISafeRunnable() {

            public void handleException(Throwable exception) {
                //$NON-NLS-1$
                Util.log(exception, "Exception occurred in listener of Java element change notification");
            }

            public void run() throws Exception {
                TypeHierarchy typeHierarchy = (TypeHierarchy) listener;
                if (typeHierarchy.hasFineGrainChanges()) {
                    // case of changes in primary working copies
                    typeHierarchy.needsRefresh = true;
                    typeHierarchy.fireChange();
                }
            }
        });
    }
}
Also used : IElementChangedListener(org.eclipse.jdt.core.IElementChangedListener) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) TypeHierarchy(org.eclipse.jdt.internal.core.hierarchy.TypeHierarchy) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException)

Example 2 with IElementChangedListener

use of org.eclipse.jdt.core.IElementChangedListener 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 3 with IElementChangedListener

use of org.eclipse.jdt.core.IElementChangedListener in project che by eclipse.

the class DeltaProcessor method notifyListeners.

private void notifyListeners(IJavaElementDelta deltaToNotify, int eventType, IElementChangedListener[] listeners, int[] listenerMask, int listenerCount) {
    final ElementChangedEvent extraEvent = new ElementChangedEvent(deltaToNotify, eventType);
    for (int i = 0; i < listenerCount; i++) {
        if ((listenerMask[i] & eventType) != 0) {
            final IElementChangedListener listener = listeners[i];
            long start = -1;
            if (VERBOSE) {
                //$NON-NLS-1$//$NON-NLS-2$
                System.out.print("Listener #" + (i + 1) + "=" + listener.toString());
                start = System.currentTimeMillis();
            }
            // wrap callbacks with Safe runnable for subsequent listeners to be called when some are causing grief
            SafeRunner.run(new ISafeRunnable() {

                public void handleException(Throwable exception) {
                    //$NON-NLS-1$
                    Util.log(exception, "Exception occurred in listener of Java element change notification");
                }

                public void run() throws Exception {
                    PerformanceStats stats = null;
                    if (PERF) {
                    //							stats = PerformanceStats.getStats(JavaModelManager.DELTA_LISTENER_PERF, listener);
                    //							stats.startRun();
                    }
                    listener.elementChanged(extraEvent);
                    if (PERF) {
                        stats.endRun();
                    }
                }
            });
            if (VERBOSE) {
                //$NON-NLS-1$ //$NON-NLS-2$
                System.out.println(" -> " + (System.currentTimeMillis() - start) + "ms");
            }
        }
    }
}
Also used : PerformanceStats(org.eclipse.core.runtime.PerformanceStats) IElementChangedListener(org.eclipse.jdt.core.IElementChangedListener) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) ElementChangedEvent(org.eclipse.jdt.core.ElementChangedEvent)

Example 4 with IElementChangedListener

use of org.eclipse.jdt.core.IElementChangedListener 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)

Aggregations

IElementChangedListener (org.eclipse.jdt.core.IElementChangedListener)4 CoreException (org.eclipse.core.runtime.CoreException)2 ISafeRunnable (org.eclipse.core.runtime.ISafeRunnable)2 IJavaElementDelta (org.eclipse.jdt.core.IJavaElementDelta)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 IResource (org.eclipse.core.resources.IResource)1 IResourceDelta (org.eclipse.core.resources.IResourceDelta)1 PerformanceStats (org.eclipse.core.runtime.PerformanceStats)1 ElementChangedEvent (org.eclipse.jdt.core.ElementChangedEvent)1 TypeHierarchy (org.eclipse.jdt.internal.core.hierarchy.TypeHierarchy)1 AbstractSearchScope (org.eclipse.jdt.internal.core.search.AbstractSearchScope)1 JavaWorkspaceScope (org.eclipse.jdt.internal.core.search.JavaWorkspaceScope)1