Example usage for org.eclipse.jdt.core ElementChangedEvent POST_CHANGE

List of usage examples for org.eclipse.jdt.core ElementChangedEvent POST_CHANGE

Introduction

In this page you can find the example usage for org.eclipse.jdt.core ElementChangedEvent POST_CHANGE.

Prototype

int POST_CHANGE

To view the source code for org.eclipse.jdt.core ElementChangedEvent POST_CHANGE.

Click Source Link

Document

Event type constant (bit mask) indicating an after-the-fact report of creations, deletions, and modifications to one or more Java element(s) expressed as a hierarchical java element delta as returned by getDelta().

Usage

From source file:com.amazonaws.eclipse.lambda.project.listener.LambdaProjectChangeTracker.java

License:Open Source License

public void start() {
    JavaCore.addElementChangedListener(projectChangeListener, ElementChangedEvent.POST_CHANGE);
}

From source file:com.codenvy.ide.ext.java.server.internal.core.DeltaProcessor.java

License:Open Source License

public void fire(IJavaElementDelta customDelta, int eventType) {
    if (!this.isFiring)
        return;/*from  w  w  w.  j a v  a2 s  .  co m*/

    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;
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.DeltaProcessor.java

License:Open Source License

private void firePostChangeDelta(IJavaElementDelta deltaToNotify, IElementChangedListener[] listeners,
        int[] listenerMask, int listenerCount) {

    // post change deltas
    if (DEBUG) {// w w w .j a va 2 s  .co m
        System.out.println("FIRING POST_CHANGE Delta [" + Thread.currentThread() + "]:"); //$NON-NLS-1$//$NON-NLS-2$
        System.out.println(deltaToNotify == null ? "<NONE>" : deltaToNotify.toString()); //$NON-NLS-1$
    }
    if (deltaToNotify != null) {
        // flush now so as to keep listener reactions to post their own deltas for subsequent iteration
        flush();

        //         // mark the operation stack has not modifying resources since resource deltas are being fired
        //         JavaModelOperation.setAttribute(JavaModelOperation.HAS_MODIFIED_RESOURCE_ATTR, null);

        notifyListeners(deltaToNotify, ElementChangedEvent.POST_CHANGE, listeners, listenerMask, listenerCount);
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.DeltaProcessor.java

License:Open Source License

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:
        //            try {
        //               if(resource.getType() == IResource.PROJECT
        //                  && ((IProject) resource).hasNature(JavaCore.NATURE_ID)) {
        ///*from ww w.j  a v a  2s.  c o m*/
        //                  deleting((IProject)resource);
        //               }
        //            } catch(CoreException e){
        //               // project doesn't exist or is not open: ignore
        //            }
        return;

    case IResourceChangeEvent.PRE_REFRESH:
        //            IProject[] projects = null;
        //            Object o = event.getSource();
        //            if (o instanceof IProject) {
        //               projects = new IProject[] { (IProject) o };
        //            } else if (o instanceof IWorkspace) {
        //               // https://bugs.eclipse.org/bugs/show_bug.cgi?id=261594. The single workspace refresh
        //               // notification we see, implies that all projects are about to be refreshed.
        //                projects = ((IWorkspace) o).getRoot().getProjects(IContainer.INCLUDE_HIDDEN);
        //            }
        //            //https://bugs.eclipse.org/bugs/show_bug.cgi?id=302295
        //            // Refresh all project references together in a single job
        //            JavaModelManager.getExternalManager().refreshReferences(projects, null);
        //
        //            IJavaProject[] javaElements = new IJavaProject[projects.length];
        //            for (int index = 0; index < projects.length; index++) {
        //               javaElements[index] = JavaCore.create(projects[index]);
        //            }
        //            try {
        //               checkExternalArchiveChanges(javaElements, true, null);
        //            } catch (JavaModelException e) {
        //                 if (!e.isDoesNotExist())
        //                    Util.log(e, "Exception while updating external archives"); //$NON-NLS-1$
        //            }
        return;

    case IResourceChangeEvent.POST_CHANGE:
        HashSet elementsToRefresh = this.state.removeExternalElementsToRefresh();
        if (isAffectedBy(delta) // avoid populating for SYNC or MARKER deltas
                || 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 {
                    this.sourceElementParserCache = null; // don't hold onto parser longer than necessary
                    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:
        //            // force initialization of roots before builders run to avoid deadlock in another thread
        //            // (note this is no-op if already initialized)
        //            // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=241751
        //            this.state.initializeRoots(false/*not initiAfterLoad*/);
        //
        //            boolean isAffected = isAffectedBy(delta);
        //            boolean needCycleValidation = isAffected && validateClasspaths(delta);
        //
        //            // update external folders if necessary
        //             ExternalFolderChange[] folderChanges = this.state.removeExternalFolderChanges();
        //            if (folderChanges != null) {
        //                for (int i = 0, length = folderChanges.length; i < length; i++) {
        //                    try {
        //                       folderChanges[i].updateExternalFoldersIfNecessary(false/*do not refresh since we are not in the thread that added the external folder to the classpath*/, null);
        //                    } catch (JavaModelException e) {
        //                       if (!e.isDoesNotExist())
        //                          Util.log(e, "Exception while updating external folders"); //$NON-NLS-1$
        //                    }
        //                }
        //            }
        //
        //            // create classpath markers if necessary
        //            ClasspathValidation[] validations = this.state.removeClasspathValidations();
        //            if (validations != null) {
        //               for (int i = 0, length = validations.length; i < length; i++) {
        //                  ClasspathValidation validation = validations[i];
        //                  validation.validate();
        //               }
        //            }
        //
        //            // update project references if necessary
        //             ProjectReferenceChange[] projectRefChanges = this.state.removeProjectReferenceChanges();
        //            if (projectRefChanges != null) {
        //                for (int i = 0, length = projectRefChanges.length; i < length; i++) {
        //                    try {
        //                       projectRefChanges[i].updateProjectReferencesIfNecessary();
        //                    } catch(JavaModelException e) {
        //                        // project doesn't exist any longer, continue with next one
        //                       if (!e.isDoesNotExist())
        //                          Util.log(e, "Exception while updating project references"); //$NON-NLS-1$
        //                    }
        //                }
        //            }
        //
        //            if (needCycleValidation || projectRefChanges != null) {
        //               // update all cycle markers since the project references changes may have affected cycles
        //               try {
        //                  JavaProject.validateCycles(null);
        //               } catch (JavaModelException e) {
        //                  // a project no longer exists
        //               }
        //            }
        //
        //            if (isAffected) {
        //               Object source = event.getSource();
        //               projects = null;
        //               if (source instanceof IWorkspace) {
        //                   projects = ((IWorkspace) source).getRoot().getProjects();
        //               } else if (source instanceof IProject) {
        //                  projects = new IProject[] {(IProject) source};
        //               } else {
        //                  Util.log(new Exception(),
        //                         "Expected to see a workspace or project on the PRE_BUILD resource change but was: " + source.toString()); //$NON-NLS-1$
        //               }
        //               if (projects != null) {
        //                  // If we are about to do a build and a Java project's first builder is not the Java builder,
        //                  // then it is possible that one of the earlier builders will build a jar file that is on that
        //                  // project's classpath. If we see that, then to be safe we must flush the caching of the
        //                  // JavaModelManager's external file state.
        //                  // A possible further optimization for this situation where earlier builders can affect the
        //                  // Java builder would be to add a new classpath element attribute that identifies whether
        //                  // or not a library jar is "stable" and needs to be flushed.
        //                  for (int i = 0; i < projects.length; i++) {
        //                     try {
        //                        IProject project = projects[i];
        //                        if (project.isOpen() && project.hasNature(JavaCore.NATURE_ID)) {
        //                           IBuildConfiguration[] configs = project.getBuildConfigs();
        //                           if (configs.length > 1 && !JavaCore.BUILDER_ID.equals(configs[0].getName())) {
        //                              this.manager.resetExternalFilesCache();
        //                              break;
        //                           }
        //                        }
        //                     } catch (CoreException exception) {
        //                          Util.log(exception, "Exception while checking builder configuration ordering"); //$NON-NLS-1$
        //                     }
        //                   }
        //               }
        //               JavaBuilder.buildStarting();
        //            }

        // does not fire any deltas
        return;

    case IResourceChangeEvent.POST_BUILD:
        JavaBuilder.buildFinished();
        return;
    }
}

From source file:com.google.gdt.eclipse.core.reference.ElementChangeListener.java

License:Open Source License

/**
 * Starts tracking element changes.
 */
void start() {
    JavaCore.addElementChangedListener(this, ElementChangedEvent.POST_CHANGE);
}

From source file:com.google.gdt.eclipse.suite.launch.processors.LaunchConfigAffectingChangesListener.java

License:Open Source License

public void start() {
    ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
    JavaCore.addElementChangedListener(this, ElementChangedEvent.POST_CHANGE);

    ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
    manager.addLaunchConfigurationListener(this);

    IEclipsePreferences projectScopeNode = ((IEclipsePreferences) Platform.getPreferencesService().getRootNode()
            .node(ProjectScope.SCOPE));/*from w  w w.j av a  2s . co  m*/
    IPreferenceNodeVisitor visitor = new IPreferenceNodeVisitor() {
        public boolean visit(IEclipsePreferences node) {
            node.addNodeChangeListener(LaunchConfigAffectingChangesListener.this);
            node.addPreferenceChangeListener(LaunchConfigAffectingChangesListener.this);
            return true;
        }
    };
    try {
        projectScopeNode.accept(visitor);
    } catch (BackingStoreException e) {
        CorePluginLog.logError(e);
    }

    WebAppProjectProperties.addWarOutLocationChangedListener(this);
}

From source file:com.google.gwt.eclipse.core.uibinder.model.reference.UiBinderReferenceManager.java

License:Open Source License

/**
 * Starts the reference manager.//from w  ww  . ja  va 2 s  .c om
 */
public void start() {
    if (UiBinderConstants.UI_BINDER_ENABLED) {
        load();

        referenceManager.addReferencedResourceChangeListener(referenceChangeListener);
        referenceManager.start();

        JavaCore.addElementChangedListener(uiBinderSubtypePurger, ElementChangedEvent.POST_CHANGE);
        ResourcesPlugin.getWorkspace().addResourceChangeListener(resourcePurger,
                IResourceChangeEvent.POST_CHANGE);
    }
}

From source file:com.google.inject.tools.ideplugin.eclipse.EclipseProjectSource.java

License:Apache License

private void startListeningForChanges() {
    changeListener = new ElementChangedListener();
    JavaCore.addElementChangedListener(changeListener, ElementChangedEvent.POST_CHANGE);
}

From source file:com.google.inject.tools.ideplugin.eclipse.EclipseSourceImpl.java

License:Apache License

private void startListeningForChanges() {
    changeListener = new ElementChangedListener();
    for (JavaProject project : projects) {
        createTypeHierarchy(project);//from ww w .  j a va 2s . c o m
    }
    JavaCore.addElementChangedListener(changeListener, ElementChangedEvent.POST_CHANGE);
}

From source file:com.iw.plugins.spindle.editors.actions.JumpToJavaAction.java

License:Mozilla Public License

public void elementChanged(ElementChangedEvent event) {
    if (fType == null || event.getType() != ElementChangedEvent.POST_CHANGE)
        return;/*from w  ww  .  j  a  v  a  2  s . co  m*/

    if (!fType.exists())
        fType = null;

}