Search in sources :

Example 16 with IResourceDelta

use of org.eclipse.core.resources.IResourceDelta in project che by eclipse.

the class DeltaProcessor method updateIndex.

private void updateIndex(Openable element, IResourceDelta delta) {
    IndexManager indexManager = this.manager.indexManager;
    if (indexManager == null)
        return;
    switch(element.getElementType()) {
        case IJavaElement.JAVA_PROJECT:
            switch(delta.getKind()) {
                case IResourceDelta.ADDED:
                    indexManager.indexAll(element.getJavaProject().getProject());
                    break;
                case IResourceDelta.REMOVED:
                    indexManager.removeIndexFamily(element.getJavaProject().getProject().getFullPath());
                    // NB: Discarding index jobs belonging to this project was done during PRE_DELETE
                    break;
            }
            break;
        case IJavaElement.PACKAGE_FRAGMENT_ROOT:
            if (element instanceof JarPackageFragmentRoot) {
                JarPackageFragmentRoot root = (JarPackageFragmentRoot) element;
                // index jar file only once (if the root is in its declaring project)
                IPath jarPath = root.getPath();
                switch(delta.getKind()) {
                    case IResourceDelta.ADDED:
                        // index the new jar
                        indexManager.indexLibrary(jarPath, root.getJavaProject().getProject(), root.getIndexPath());
                        break;
                    case IResourceDelta.CHANGED:
                        // first remove the index so that it is forced to be re-indexed
                        indexManager.removeIndex(jarPath);
                        // then index the jar
                        indexManager.indexLibrary(jarPath, root.getJavaProject().getProject(), root.getIndexPath());
                        break;
                    case IResourceDelta.REMOVED:
                        // the jar was physically removed: remove the index
                        indexManager.discardJobs(jarPath.toString());
                        indexManager.removeIndex(jarPath);
                        break;
                }
                break;
            }
            int kind = delta.getKind();
            if (kind == IResourceDelta.ADDED || kind == IResourceDelta.REMOVED || (kind == IResourceDelta.CHANGED && (delta.getFlags() & IResourceDelta.LOCAL_CHANGED) != 0)) {
                PackageFragmentRoot root = (PackageFragmentRoot) element;
                updateRootIndex(root, CharOperation.NO_STRINGS, delta);
                break;
            }
        // $FALL-THROUGH$
        case IJavaElement.PACKAGE_FRAGMENT:
            switch(delta.getKind()) {
                case IResourceDelta.CHANGED:
                    if ((delta.getFlags() & IResourceDelta.LOCAL_CHANGED) == 0)
                        break;
                // $FALL-THROUGH$
                case IResourceDelta.ADDED:
                case IResourceDelta.REMOVED:
                    IPackageFragment pkg = null;
                    if (element instanceof IPackageFragmentRoot) {
                        PackageFragmentRoot root = (PackageFragmentRoot) element;
                        pkg = root.getPackageFragment(CharOperation.NO_STRINGS);
                    } else {
                        pkg = (IPackageFragment) element;
                    }
                    RootInfo rootInfo = rootInfo(pkg.getParent().getPath(), delta.getKind());
                    boolean isSource = // if null, defaults to source
                    rootInfo == null || rootInfo.entryKind == IClasspathEntry.CPE_SOURCE;
                    IResourceDelta[] children = (IResourceDelta[]) delta.getAffectedChildren();
                    for (int i = 0, length = children.length; i < length; i++) {
                        IResourceDelta child = children[i];
                        IResource resource = child.getResource();
                        // TODO (philippe) Why do this? Every child is added anyway as the delta is walked
                        if (resource instanceof IFile) {
                            String name = resource.getName();
                            if (isSource) {
                                if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(name)) {
                                    Openable cu = (Openable) pkg.getCompilationUnit(name);
                                    updateIndex(cu, child);
                                }
                            } else if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(name)) {
                                Openable classFile = (Openable) pkg.getClassFile(name);
                                updateIndex(classFile, child);
                            }
                        }
                    }
                    break;
            }
            break;
        case IJavaElement.CLASS_FILE:
            //				}
            break;
        case IJavaElement.COMPILATION_UNIT:
            IFile file = (IFile) delta.getResource();
            switch(delta.getKind()) {
                case IResourceDelta.CHANGED:
                    // no need to index if the content has not changed
                    int flags = delta.getFlags();
                    if ((flags & IResourceDelta.CONTENT) == 0 && (flags & IResourceDelta.ENCODING) == 0)
                        break;
                // $FALL-THROUGH$
                case IResourceDelta.ADDED:
                    indexManager.addSource(file, element.getJavaProject().getPath(), getSourceElementParser(element));
                    // Clean file from secondary types cache but do not update indexing secondary type cache as it will be updated through indexing itself
                    this.manager.secondaryTypesRemoving(file, false);
                    break;
                case IResourceDelta.REMOVED:
                    indexManager.remove(Util.relativePath(file.getFullPath(), 1), element.getJavaProject().getPath());
                    // Clean file from secondary types cache and update indexing secondary type cache as indexing cannot remove secondary types from cache
                    this.manager.secondaryTypesRemoving(file, true);
                    break;
            }
    }
}
Also used : IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IndexManager(org.eclipse.jdt.internal.core.search.indexing.IndexManager) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 17 with IResourceDelta

use of org.eclipse.core.resources.IResourceDelta 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 18 with IResourceDelta

use of org.eclipse.core.resources.IResourceDelta in project che by eclipse.

the class DeltaProcessingState method updateRoots.

/*
	 * Update the roots that are affected by the addition or the removal of the given container resource.
	 */
public synchronized void updateRoots(IPath containerPath, IResourceDelta containerDelta, DeltaProcessor deltaProcessor) {
    Map updatedRoots;
    Map otherUpdatedRoots;
    if (containerDelta.getKind() == IResourceDelta.REMOVED) {
        updatedRoots = this.oldRoots;
        otherUpdatedRoots = this.oldOtherRoots;
    } else {
        updatedRoots = this.roots;
        otherUpdatedRoots = this.otherRoots;
    }
    int containerSegmentCount = containerPath.segmentCount();
    boolean containerIsProject = containerSegmentCount == 1;
    Iterator iterator = updatedRoots.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry entry = (Map.Entry) iterator.next();
        IPath path = (IPath) entry.getKey();
        if (containerPath.isPrefixOf(path) && !containerPath.equals(path)) {
            IResourceDelta rootDelta = (IResourceDelta) containerDelta.findMember(path.removeFirstSegments(containerSegmentCount));
            if (rootDelta == null)
                continue;
            DeltaProcessor.RootInfo rootInfo = (DeltaProcessor.RootInfo) entry.getValue();
            if (!containerIsProject || !rootInfo.project.getPath().isPrefixOf(path)) {
                // only consider folder roots that are not included in the container
                deltaProcessor.updateCurrentDeltaAndIndex(rootDelta, IJavaElement.PACKAGE_FRAGMENT_ROOT, rootInfo);
            }
            ArrayList rootList = (ArrayList) otherUpdatedRoots.get(path);
            if (rootList != null) {
                Iterator otherProjects = rootList.iterator();
                while (otherProjects.hasNext()) {
                    rootInfo = (DeltaProcessor.RootInfo) otherProjects.next();
                    if (!containerIsProject || !rootInfo.project.getPath().isPrefixOf(path)) {
                        // only consider folder roots that are not included in the container
                        deltaProcessor.updateCurrentDeltaAndIndex(rootDelta, IJavaElement.PACKAGE_FRAGMENT_ROOT, rootInfo);
                    }
                }
            }
        }
    }
}
Also used : IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IPath(org.eclipse.core.runtime.IPath) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 19 with IResourceDelta

use of org.eclipse.core.resources.IResourceDelta in project che by eclipse.

the class RefactoringHistoryService method peformResourceChanged.

private void peformResourceChanged(final IResourceChangeEvent event) {
    final int type = event.getType();
    if ((type & IResourceChangeEvent.POST_CHANGE) != 0) {
        final IResourceDelta delta = event.getDelta();
        if (delta != null) {
            final IResourceDelta[] deltas = delta.getAffectedChildren();
            if (deltas.length == 2) {
                final IPath toPath = deltas[0].getMovedToPath();
                final IPath fromPath = deltas[1].getMovedFromPath();
                if (fromPath != null && toPath != null) {
                    final IResource oldResource = deltas[0].getResource();
                    final IResource newResource = deltas[1].getResource();
                    if (oldResource.getType() == IResource.PROJECT && newResource.getType() == IResource.PROJECT)
                        moveHistory((IProject) oldResource, (IProject) newResource, new NullProgressMonitor());
                } else {
                    if (deltas[0].getKind() == IResourceDelta.ADDED && deltas[1].getKind() == IResourceDelta.REMOVED) {
                        final IResource newResource = deltas[0].getResource();
                        final IResource oldResource = deltas[1].getResource();
                        if (oldResource.getType() == IResource.PROJECT && newResource.getType() == IResource.PROJECT)
                            moveHistory((IProject) oldResource, (IProject) newResource, new NullProgressMonitor());
                    }
                }
            }
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 20 with IResourceDelta

use of org.eclipse.core.resources.IResourceDelta in project che by eclipse.

the class ResourceChangeChecker method getChangedFiles.

/* package */
IFile[] getChangedFiles() throws CoreException {
    IResourceDelta root = fDeltaFactory.getDelta();
    final List result = new ArrayList();
    root.accept(new IResourceDeltaVisitor() {

        public boolean visit(IResourceDelta delta) throws CoreException {
            final IResource resource = delta.getResource();
            if (resource.getType() == IResource.FILE) {
                final int kind = delta.getKind();
                if (isSet(kind, IResourceDelta.CHANGED)) {
                    result.add(resource);
                } else if (isSet(kind, IResourceDelta.ADDED) && isSet(delta.getFlags(), IResourceDelta.CONTENT | IResourceDelta.MOVED_FROM)) {
                    final IFile movedFrom = resource.getWorkspace().getRoot().getFile(delta.getMovedFromPath());
                    result.add(movedFrom);
                }
            }
            return true;
        }
    });
    return (IFile[]) result.toArray(new IFile[result.size()]);
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IResourceDeltaVisitor(org.eclipse.core.resources.IResourceDeltaVisitor) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Aggregations

IResourceDelta (org.eclipse.core.resources.IResourceDelta)33 IResource (org.eclipse.core.resources.IResource)21 IPath (org.eclipse.core.runtime.IPath)12 IProject (org.eclipse.core.resources.IProject)10 CoreException (org.eclipse.core.runtime.CoreException)9 IResourceDeltaVisitor (org.eclipse.core.resources.IResourceDeltaVisitor)8 ArrayList (java.util.ArrayList)7 IFile (org.eclipse.core.resources.IFile)5 HashSet (java.util.HashSet)4 List (java.util.List)4 Iterator (java.util.Iterator)3 IResourceChangeListener (org.eclipse.core.resources.IResourceChangeListener)3 Project (aQute.bnd.build.Project)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 IFolder (org.eclipse.core.resources.IFolder)2 IResourceChangeEvent (org.eclipse.core.resources.IResourceChangeEvent)2 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2