1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
14 import java.util.ArrayList;
15 import java.util.HashMap;
16 import java.util.HashSet;
19 import net.sourceforge.phpdt.core.ElementChangedEvent;
20 import net.sourceforge.phpdt.core.IJavaElement;
21 import net.sourceforge.phpdt.core.IJavaProject;
22 import net.sourceforge.phpdt.core.JavaCore;
23 import net.sourceforge.phpdt.core.JavaModelException;
24 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
26 import org.eclipse.core.resources.IFile;
27 import org.eclipse.core.resources.IProject;
28 import org.eclipse.core.resources.IResource;
29 import org.eclipse.core.resources.IResourceChangeEvent;
30 import org.eclipse.core.resources.IResourceChangeListener;
31 import org.eclipse.core.resources.IResourceDelta;
32 import org.eclipse.core.resources.IResourceDeltaVisitor;
33 import org.eclipse.core.resources.IWorkspace;
34 import org.eclipse.core.runtime.CoreException;
35 import org.eclipse.core.runtime.IPath;
39 * This class is used by <code>JavaModelManager</code> to convert
40 * <code>IResourceDelta</code>s into <code>IJavaElementDelta</code>s.
41 * It also does some processing on the <code>JavaElement</code>s involved
42 * (e.g. closing them or updating classpaths).
44 public class DeltaProcessor implements IResourceChangeListener {
46 final static int IGNORE = 0;
47 final static int SOURCE = 1;
48 final static int BINARY = 2;
50 final static String EXTERNAL_JAR_ADDED = "external jar added"; //$NON-NLS-1$
51 final static String EXTERNAL_JAR_REMOVED = "external jar removed"; //$NON-NLS-1$
52 final static String EXTERNAL_JAR_CHANGED = "external jar changed"; //$NON-NLS-1$
53 final static String EXTERNAL_JAR_UNCHANGED = "external jar unchanged"; //$NON-NLS-1$
54 final static String INTERNAL_JAR_IGNORE = "internal jar ignore"; //$NON-NLS-1$
56 final static int NON_JAVA_RESOURCE = -1;
59 * The <code>JavaElementDelta</code> corresponding to the <code>IResourceDelta</code> being translated.
61 protected JavaElementDelta currentDelta;
63 // protected IndexManager indexManager = new IndexManager();
65 /* A table from IPath (from a classpath entry) to RootInfo */
68 /* A table from IPath (from a classpath entry) to ArrayList of RootInfo
69 * Used when an IPath corresponds to more than one root */
72 /* Whether the roots tables should be recomputed */
73 public boolean rootsAreStale = true;
75 /* A table from IPath (from a classpath entry) to RootInfo
76 * from the last time the delta processor was invoked. */
79 /* A table from IPath (from a classpath entry) to ArrayList of RootInfo
80 * from the last time the delta processor was invoked.
81 * Used when an IPath corresponds to more than one root */
84 /* A table from IPath (a source attachment path from a classpath entry) to IPath (a root path) */
85 Map sourceAttachments;
87 /* The java element that was last created (see createElement(IResource)).
88 * This is used as a stack of java elements (using getParent() to pop it, and
89 * using the various get*(...) to push it. */
90 Openable currentElement;
92 public HashMap externalTimeStamps = new HashMap();
93 public HashSet projectsToUpdate = new HashSet();
94 // list of root projects which namelookup caches need to be updated for dependents
95 // TODO: (jerome) is it needed? projectsToUpdate might be sufficient
96 public HashSet projectsForDependentNamelookupRefresh = new HashSet();
98 JavaModelManager manager;
100 /* A table from IJavaProject to an array of IPackageFragmentRoot.
101 * This table contains the pkg fragment roots of the project that are being deleted.
106 * A list of IJavaElement used as a scope for external archives refresh during POST_CHANGE.
107 * This is null if no refresh is needed.
109 HashSet refreshedElements;
110 public static boolean VERBOSE = false;
116 OutputsInfo(IPath[] paths, int[] traverseModes, int outputCount) {
118 this.traverseModes = traverseModes;
119 this.outputCount = outputCount;
121 public String toString() {
122 if (this.paths == null) return "<none>"; //$NON-NLS-1$
123 StringBuffer buffer = new StringBuffer();
124 for (int i = 0; i < this.outputCount; i++) {
125 buffer.append("path="); //$NON-NLS-1$
126 buffer.append(this.paths[i].toString());
127 buffer.append("\n->traverse="); //$NON-NLS-1$
128 switch (this.traverseModes[i]) {
130 buffer.append("BINARY"); //$NON-NLS-1$
133 buffer.append("IGNORE"); //$NON-NLS-1$
136 buffer.append("SOURCE"); //$NON-NLS-1$
139 buffer.append("<unknown>"); //$NON-NLS-1$
141 if (i+1 < this.outputCount) {
145 return buffer.toString();
149 IJavaProject project;
151 char[][] exclusionPatterns;
152 RootInfo(IJavaProject project, IPath rootPath, char[][] exclusionPatterns) {
153 this.project = project;
154 this.rootPath = rootPath;
155 this.exclusionPatterns = exclusionPatterns;
157 boolean isRootOfProject(IPath path) {
158 return this.rootPath.equals(path) && this.project.getProject().getFullPath().isPrefixOf(path);
160 public String toString() {
161 StringBuffer buffer = new StringBuffer("project="); //$NON-NLS-1$
162 if (this.project == null) {
163 buffer.append("null"); //$NON-NLS-1$
165 buffer.append(this.project.getElementName());
167 buffer.append("\npath="); //$NON-NLS-1$
168 if (this.rootPath == null) {
169 buffer.append("null"); //$NON-NLS-1$
171 buffer.append(this.rootPath.toString());
173 buffer.append("\nexcluding="); //$NON-NLS-1$
174 if (this.exclusionPatterns == null) {
175 buffer.append("null"); //$NON-NLS-1$
177 for (int i = 0, length = this.exclusionPatterns.length; i < length; i++) {
178 buffer.append(new String(this.exclusionPatterns[i]));
180 buffer.append("|"); //$NON-NLS-1$
184 return buffer.toString();
188 DeltaProcessor(JavaModelManager manager) {
189 this.manager = manager;
193 * Adds the dependents of the given project to the list of the projects
196 // void addDependentProjects(IPath projectPath, HashSet result) {
198 // IJavaProject[] projects = this.manager.getJavaModel().getJavaProjects();
199 // for (int i = 0, length = projects.length; i < length; i++) {
200 // IJavaProject project = projects[i];
201 // IClasspathEntry[] classpath = ((JavaProject)project).getExpandedClasspath(true);
202 // for (int j = 0, length2 = classpath.length; j < length2; j++) {
203 // IClasspathEntry entry = classpath[j];
204 // if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT
205 // && entry.getPath().equals(projectPath)) {
206 // result.add(project);
210 // } catch (JavaModelException e) {
214 * Adds the given element to the list of elements used as a scope for external jars refresh.
216 public void addForRefresh(IJavaElement element) {
217 if (this.refreshedElements == null) {
218 this.refreshedElements = new HashSet();
220 this.refreshedElements.add(element);
223 * Adds the given project and its dependents to the list of the projects
226 void addToProjectsToUpdateWithDependents(IProject project) {
227 this.projectsToUpdate.add(JavaCore.create(project));
228 // this.addDependentProjects(project.getFullPath(), this.projectsToUpdate);
232 * Adds the given child handle to its parent's cache of children.
234 protected void addToParentInfo(Openable child) {
236 Openable parent = (Openable) child.getParent();
237 if (parent != null && parent.isOpen()) {
239 JavaElementInfo info = (JavaElementInfo)parent.getElementInfo();
240 info.addChild(child);
241 } catch (JavaModelException e) {
242 // do nothing - we already checked if open
248 * Check all external archive (referenced by given roots, projects or model) status and issue a corresponding root delta.
249 * Also triggers index updates
251 // public void checkExternalArchiveChanges(IJavaElement[] refreshedElements, IProgressMonitor monitor) throws JavaModelException {
253 // for (int i = 0, length = refreshedElements.length; i < length; i++) {
254 // this.addForRefresh(refreshedElements[i]);
256 // boolean hasDelta = this.createExternalArchiveDelta(monitor);
257 // if (monitor != null && monitor.isCanceled()) return;
259 // // force classpath marker refresh of affected projects
260 // JavaModel.flushExternalFileCache();
261 // IJavaElementDelta[] projectDeltas = this.currentDelta.getAffectedChildren();
262 // for (int i = 0, length = projectDeltas.length; i < length; i++) {
263 // IJavaElementDelta delta = projectDeltas[i];
264 // ((JavaProject)delta.getElement()).getResolvedClasspath(
265 // true, // ignoreUnresolvedEntry
266 // true); // generateMarkerOnError
268 // if (this.currentDelta != null) { // if delta has not been fired while creating markers
269 // this.manager.fire(this.currentDelta, JavaModelManager.DEFAULT_CHANGE_EVENT);
273 // this.currentDelta = null;
274 // if (monitor != null) monitor.done();
278 * Check if external archives have changed and create the corresponding deltas.
279 * Returns whether at least on delta was created.
281 // public boolean createExternalArchiveDelta(IProgressMonitor monitor) throws JavaModelException {
283 // if (this.refreshedElements == null) return false;
285 // HashMap externalArchivesStatus = new HashMap();
286 // boolean hasDelta = false;
288 // // find JARs to refresh
289 // HashSet archivePathsToRefresh = new HashSet();
291 // Iterator iterator = this.refreshedElements.iterator();
292 // while (iterator.hasNext()) {
293 // IJavaElement element = (IJavaElement)iterator.next();
294 // switch(element.getElementType()){
295 // case IJavaElement.PACKAGE_FRAGMENT_ROOT :
296 // archivePathsToRefresh.add(element.getPath());
298 // case IJavaElement.JAVA_PROJECT :
299 // IJavaProject project = (IJavaProject) element;
300 // if (!JavaProject.hasJavaNature(project.getProject())) {
301 // // project is not accessible or has lost its Java nature
304 // IClasspathEntry[] classpath = project.getResolvedClasspath(true);
305 // for (int j = 0, cpLength = classpath.length; j < cpLength; j++){
306 // if (classpath[j].getEntryKind() == IClasspathEntry.CPE_LIBRARY){
307 // archivePathsToRefresh.add(classpath[j].getPath());
311 // case IJavaElement.JAVA_MODEL :
312 // IJavaProject[] projects = manager.getJavaModel().getOldJavaProjectsList();
313 // for (int j = 0, projectsLength = projects.length; j < projectsLength; j++){
314 // project = projects[j];
315 // if (!JavaProject.hasJavaNature(project.getProject())) {
316 // // project is not accessible or has lost its Java nature
319 // classpath = project.getResolvedClasspath(true);
320 // for (int k = 0, cpLength = classpath.length; k < cpLength; k++){
321 // if (classpath[k].getEntryKind() == IClasspathEntry.CPE_LIBRARY){
322 // archivePathsToRefresh.add(classpath[k].getPath());
330 // this.refreshedElements = null;
333 // // perform refresh
334 // IJavaProject[] projects = manager.getJavaModel().getOldJavaProjectsList();
335 // IWorkspaceRoot wksRoot = ResourcesPlugin.getWorkspace().getRoot();
336 // for (int i = 0, length = projects.length; i < length; i++) {
338 // if (monitor != null && monitor.isCanceled()) break;
340 // IJavaProject project = projects[i];
341 // if (!JavaProject.hasJavaNature(project.getProject())) {
342 // // project is not accessible or has lost its Java nature
345 // IClasspathEntry[] entries = project.getResolvedClasspath(true);
346 // for (int j = 0; j < entries.length; j++){
347 // if (entries[j].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
349 // IPath entryPath = entries[j].getPath();
351 // if (!archivePathsToRefresh.contains(entryPath)) continue; // not supposed to be refreshed
353 // String status = (String)externalArchivesStatus.get(entryPath);
354 // if (status == null){
356 // // compute shared status
357 // Object targetLibrary = JavaModel.getTarget(wksRoot, entryPath, true);
359 // if (targetLibrary == null){ // missing JAR
360 // if (this.externalTimeStamps.containsKey(entryPath)){
361 // this.externalTimeStamps.remove(entryPath);
362 // externalArchivesStatus.put(entryPath, EXTERNAL_JAR_REMOVED);
363 // // the jar was physically removed: remove the index
364 // indexManager.removeIndex(entryPath);
367 // } else if (targetLibrary instanceof File){ // external JAR
369 // File externalFile = (File)targetLibrary;
371 // // check timestamp to figure if JAR has changed in some way
372 // Long oldTimestamp =(Long) this.externalTimeStamps.get(entryPath);
373 // long newTimeStamp = getTimeStamp(externalFile);
374 // if (oldTimestamp != null){
376 // if (newTimeStamp == 0){ // file doesn't exist
377 // externalArchivesStatus.put(entryPath, EXTERNAL_JAR_REMOVED);
378 // this.externalTimeStamps.remove(entryPath);
379 // // remove the index
380 // indexManager.removeIndex(entryPath);
382 // } else if (oldTimestamp.longValue() != newTimeStamp){
383 // externalArchivesStatus.put(entryPath, EXTERNAL_JAR_CHANGED);
384 // this.externalTimeStamps.put(entryPath, new Long(newTimeStamp));
385 // // first remove the index so that it is forced to be re-indexed
386 // indexManager.removeIndex(entryPath);
387 // // then index the jar
388 // indexManager.indexLibrary(entryPath, project.getProject());
390 // externalArchivesStatus.put(entryPath, EXTERNAL_JAR_UNCHANGED);
393 // if (newTimeStamp == 0){ // jar still doesn't exist
394 // externalArchivesStatus.put(entryPath, EXTERNAL_JAR_UNCHANGED);
396 // externalArchivesStatus.put(entryPath, EXTERNAL_JAR_ADDED);
397 // this.externalTimeStamps.put(entryPath, new Long(newTimeStamp));
398 // // index the new jar
399 // indexManager.indexLibrary(entryPath, project.getProject());
402 // } else { // internal JAR
403 // externalArchivesStatus.put(entryPath, INTERNAL_JAR_IGNORE);
406 // // according to computed status, generate a delta
407 // status = (String)externalArchivesStatus.get(entryPath);
408 // if (status != null){
409 // if (status == EXTERNAL_JAR_ADDED){
410 // PackageFragmentRoot root = (PackageFragmentRoot)project.getPackageFragmentRoot(entryPath.toString());
412 // System.out.println("- External JAR ADDED, affecting root: "+root.getElementName()); //$NON-NLS-1$
414 // elementAdded(root, null, null);
416 // } else if (status == EXTERNAL_JAR_CHANGED) {
417 // PackageFragmentRoot root = (PackageFragmentRoot)project.getPackageFragmentRoot(entryPath.toString());
419 // System.out.println("- External JAR CHANGED, affecting root: "+root.getElementName()); //$NON-NLS-1$
421 // // reset the corresponding project built state, since the builder would miss this change
422 // this.manager.setLastBuiltState(project.getProject(), null /*no state*/);
423 // contentChanged(root, null);
425 // } else if (status == EXTERNAL_JAR_REMOVED) {
426 // PackageFragmentRoot root = (PackageFragmentRoot)project.getPackageFragmentRoot(entryPath.toString());
428 // System.out.println("- External JAR REMOVED, affecting root: "+root.getElementName()); //$NON-NLS-1$
430 // elementRemoved(root, null, null);
439 JavaElementDelta currentDelta() {
440 if (this.currentDelta == null) {
441 this.currentDelta = new JavaElementDelta(this.manager.getJavaModel());
443 return this.currentDelta;
447 * Process the given delta and look for projects being added, opened, closed or
448 * with a java nature being added or removed.
449 * Note that projects being deleted are checked in deleting(IProject).
450 * In all cases, add the project's dependents to the list of projects to update
451 * so that the classpath related markers can be updated.
453 // public void checkProjectsBeingAddedOrRemoved(IResourceDelta delta) {
454 // IResource resource = delta.getResource();
455 // switch (resource.getType()) {
456 // case IResource.ROOT :
457 // // workaround for bug 15168 circular errors not reported
458 // if (this.manager.javaProjectsCache == null) {
460 // this.manager.javaProjectsCache = this.manager.getJavaModel().getJavaProjects();
461 // } catch (JavaModelException e) {
465 // IResourceDelta[] children = delta.getAffectedChildren();
466 // for (int i = 0, length = children.length; i < length; i++) {
467 // this.checkProjectsBeingAddedOrRemoved(children[i]);
470 // case IResource.PROJECT :
471 // // NB: No need to check project's nature as if the project is not a java project:
472 // // - if the project is added or changed this is a noop for projectsBeingDeleted
473 // // - if the project is closed, it has already lost its java nature
474 // int deltaKind = delta.getKind();
475 // if (deltaKind == IResourceDelta.ADDED) {
476 // // remember project and its dependents
477 // IProject project = (IProject)resource;
478 // this.addToProjectsToUpdateWithDependents(project);
480 // // workaround for bug 15168 circular errors not reported
481 // if (JavaProject.hasJavaNature(project)) {
482 // this.addToParentInfo((JavaProject)JavaCore.create(project));
485 // } else if (deltaKind == IResourceDelta.CHANGED) {
486 // IProject project = (IProject)resource;
487 // if ((delta.getFlags() & IResourceDelta.OPEN) != 0) {
488 // // project opened or closed: remember project and its dependents
489 // this.addToProjectsToUpdateWithDependents(project);
491 // // workaround for bug 15168 circular errors not reported
492 // if (project.isOpen()) {
493 // if (JavaProject.hasJavaNature(project)) {
494 // this.addToParentInfo((JavaProject)JavaCore.create(project));
497 // JavaProject javaProject = (JavaProject)this.manager.getJavaModel().findJavaProject(project);
498 // if (javaProject != null) {
500 // javaProject.close();
501 // } catch (JavaModelException e) {
503 // this.removeFromParentInfo(javaProject);
506 // } else if ((delta.getFlags() & IResourceDelta.DESCRIPTION) != 0) {
507 // boolean wasJavaProject = this.manager.getJavaModel().findJavaProject(project) != null;
508 // boolean isJavaProject = JavaProject.hasJavaNature(project);
509 // if (wasJavaProject != isJavaProject) {
510 // // java nature added or removed: remember project and its dependents
511 // this.addToProjectsToUpdateWithDependents(project);
513 // // workaround for bug 15168 circular errors not reported
514 // if (isJavaProject) {
515 // this.addToParentInfo((JavaProject)JavaCore.create(project));
517 // JavaProject javaProject = (JavaProject)JavaCore.create(project);
519 // // flush classpath markers
521 // flushClasspathProblemMarkers(
522 // true, // flush cycle markers
523 // true //flush classpath format markers
526 // // remove problems and tasks created by the builder
527 // JavaBuilder.removeProblemsAndTasksFor(project);
531 // javaProject.close();
532 // } catch (JavaModelException e) {
534 // this.removeFromParentInfo(javaProject);
537 // // in case the project was removed then added then changed (see bug 19799)
538 // if (JavaProject.hasJavaNature(project)) { // need nature check - 18698
539 // this.addToParentInfo((JavaProject)JavaCore.create(project));
543 // // workaround for bug 15168 circular errors not reported
544 // // in case the project was removed then added then changed
545 // if (JavaProject.hasJavaNature(project)) { // need nature check - 18698
546 // this.addToParentInfo((JavaProject)JavaCore.create(project));
554 // private void checkSourceAttachmentChange(IResourceDelta delta, IResource res) {
555 // IPath rootPath = (IPath)this.sourceAttachments.get(res.getFullPath());
556 // if (rootPath != null) {
557 // RootInfo rootInfo = this.rootInfo(rootPath, delta.getKind());
558 // if (rootInfo != null) {
559 // IJavaProject projectOfRoot = rootInfo.project;
560 // IPackageFragmentRoot root = null;
562 // // close the root so that source attachement cache is flushed
563 // root = projectOfRoot.findPackageFragmentRoot(rootPath);
564 // if (root != null) {
567 // } catch (JavaModelException e) {
569 // if (root == null) return;
570 // switch (delta.getKind()) {
571 // case IResourceDelta.ADDED:
572 // currentDelta().sourceAttached(root);
574 // case IResourceDelta.CHANGED:
575 // currentDelta().sourceDetached(root);
576 // currentDelta().sourceAttached(root);
578 // case IResourceDelta.REMOVED:
579 // currentDelta().sourceDetached(root);
587 * Closes the given element, which removes it from the cache of open elements.
589 // protected static void close(Openable element) {
593 // } catch (JavaModelException e) {
598 * Generic processing for elements with changed contents:<ul>
599 * <li>The element is closed such that any subsequent accesses will re-open
600 * the element reflecting its new structure.
601 * <li>An entry is made in the delta reporting a content change (K_CHANGE with F_CONTENT flag set).
603 * Delta argument could be null if processing an external JAR change
605 // protected void contentChanged(Openable element, IResourceDelta delta) {
608 // int flags = IJavaElementDelta.F_CONTENT;
609 // if (element instanceof JarPackageFragmentRoot){
610 // flags |= IJavaElementDelta.F_ARCHIVE_CONTENT_CHANGED;
612 // currentDelta().changed(element, flags);
616 * Creates the openables corresponding to this resource.
617 * Returns null if none was found.
619 // protected Openable createElement(IResource resource, int elementType, RootInfo rootInfo) {
620 // if (resource == null) return null;
622 // IPath path = resource.getFullPath();
623 // IJavaElement element = null;
624 // switch (elementType) {
626 // case IJavaElement.JAVA_PROJECT:
628 // // note that non-java resources rooted at the project level will also enter this code with
629 // // an elementType JAVA_PROJECT (see #elementType(...)).
630 // if (resource instanceof IProject){
632 // this.popUntilPrefixOf(path);
634 // if (this.currentElement != null
635 // && this.currentElement.getElementType() == IJavaElement.JAVA_PROJECT
636 // && ((IJavaProject)this.currentElement).getProject().equals(resource)) {
637 // return this.currentElement;
639 // if (rootInfo != null && rootInfo.project.getProject().equals(resource)){
640 // element = (Openable)rootInfo.project;
643 // IProject proj = (IProject)resource;
644 // if (JavaProject.hasJavaNature(proj)) {
645 // element = JavaCore.create(proj);
647 // // java project may have been been closed or removed (look for
648 // // element amongst old java project s list).
649 // element = (Openable) manager.getJavaModel().findJavaProject(proj);
653 // case IJavaElement.PACKAGE_FRAGMENT_ROOT:
654 // element = rootInfo == null ? JavaCore.create(resource) : rootInfo.project.getPackageFragmentRoot(resource);
656 // case IJavaElement.PACKAGE_FRAGMENT:
657 // // find the element that encloses the resource
658 // this.popUntilPrefixOf(path);
660 // if (this.currentElement == null) {
661 // element = rootInfo == null ? JavaCore.create(resource) : JavaModelManager.create(resource, rootInfo.project);
664 // IPackageFragmentRoot root = this.currentElement.getPackageFragmentRoot();
665 // if (root == null) {
666 // element = rootInfo == null ? JavaCore.create(resource) : JavaModelManager.create(resource, rootInfo.project);
667 // } else if (((JavaProject)root.getJavaProject()).contains(resource)) {
668 // // create package handle
669 // IPath pkgPath = path.removeFirstSegments(root.getPath().segmentCount());
670 // String pkg = Util.packageName(pkgPath);
671 // if (pkg == null) return null;
672 // element = root.getPackageFragment(pkg);
676 // case IJavaElement.COMPILATION_UNIT:
677 // case IJavaElement.CLASS_FILE:
678 // // find the element that encloses the resource
679 // this.popUntilPrefixOf(path);
681 // if (this.currentElement == null) {
682 // element = rootInfo == null ? JavaCore.create(resource) : JavaModelManager.create(resource, rootInfo.project);
684 // // find the package
685 // IPackageFragment pkgFragment = null;
686 // switch (this.currentElement.getElementType()) {
687 // case IJavaElement.PACKAGE_FRAGMENT_ROOT:
688 // IPackageFragmentRoot root = (IPackageFragmentRoot)this.currentElement;
689 // IPath rootPath = root.getPath();
690 // IPath pkgPath = path.removeLastSegments(1);
691 // String pkgName = Util.packageName(pkgPath.removeFirstSegments(rootPath.segmentCount()));
692 // if (pkgName != null) {
693 // pkgFragment = root.getPackageFragment(pkgName);
696 // case IJavaElement.PACKAGE_FRAGMENT:
697 // Openable pkg = (Openable)this.currentElement;
698 // if (pkg.getPath().equals(path.removeLastSegments(1))) {
699 // pkgFragment = (IPackageFragment)pkg;
700 // } // else case of package x which is a prefix of x.y
702 // case IJavaElement.COMPILATION_UNIT:
703 // case IJavaElement.CLASS_FILE:
704 // pkgFragment = (IPackageFragment)this.currentElement.getParent();
707 // if (pkgFragment == null) {
708 // element = rootInfo == null ? JavaCore.create(resource) : JavaModelManager.create(resource, rootInfo.project);
710 // if (elementType == IJavaElement.COMPILATION_UNIT) {
711 // // create compilation unit handle
712 // // fileName validation has been done in elementType(IResourceDelta, int, boolean)
713 // String fileName = path.lastSegment();
714 // element = pkgFragment.getCompilationUnit(fileName);
716 // // create class file handle
717 // // fileName validation has been done in elementType(IResourceDelta, int, boolean)
718 // String fileName = path.lastSegment();
719 // element = pkgFragment.getClassFile(fileName);
725 // if (element == null) {
728 // this.currentElement = (Openable)element;
729 // return this.currentElement;
733 * Note that the project is about to be deleted.
735 // public void deleting(IProject project) {
738 // // discard indexing jobs that belong to this project so that the project can be
739 // // deleted without interferences from the index manager
740 // this.indexManager.discardJobs(project.getName());
742 // JavaProject javaProject = (JavaProject)JavaCore.create(project);
744 // // remember roots of this project
745 // if (this.removedRoots == null) {
746 // this.removedRoots = new HashMap();
748 // if (javaProject.isOpen()) {
749 // this.removedRoots.put(javaProject, javaProject.getPackageFragmentRoots());
751 // // compute roots without opening project
752 // this.removedRoots.put(
754 // javaProject.computePackageFragmentRoots(
755 // javaProject.getResolvedClasspath(true),
759 // javaProject.close();
761 // // workaround for bug 15168 circular errors not reported
762 // if (this.manager.javaProjectsCache == null) {
763 // this.manager.javaProjectsCache = this.manager.getJavaModel().getJavaProjects();
765 // this.removeFromParentInfo(javaProject);
767 // } catch (JavaModelException e) {
770 // this.addDependentProjects(project.getFullPath(), this.projectsToUpdate);
775 * Processing for an element that has been added:<ul>
776 * <li>If the element is a project, do nothing, and do not process
777 * children, as when a project is created it does not yet have any
778 * natures - specifically a java nature.
779 * <li>If the elemet is not a project, process it as added (see
780 * <code>basicElementAdded</code>.
782 * Delta argument could be null if processing an external JAR change
784 // protected void elementAdded(Openable element, IResourceDelta delta, RootInfo rootInfo) {
785 // int elementType = element.getElementType();
787 // if (elementType == IJavaElement.JAVA_PROJECT) {
788 // // project add is handled by JavaProject.configure() because
789 // // when a project is created, it does not yet have a java nature
790 // if (delta != null && JavaProject.hasJavaNature((IProject)delta.getResource())) {
791 // addToParentInfo(element);
792 // if ((delta.getFlags() & IResourceDelta.MOVED_FROM) != 0) {
793 // Openable movedFromElement = (Openable)element.getJavaModel().getJavaProject(delta.getMovedFromPath().lastSegment());
794 // currentDelta().movedTo(element, movedFromElement);
796 // currentDelta().added(element);
798 // this.projectsToUpdate.add(element);
799 // this.updateRoots(element.getPath(), delta);
800 // this.projectsForDependentNamelookupRefresh.add((JavaProject) element);
803 // addToParentInfo(element);
805 // // Force the element to be closed as it might have been opened
806 // // before the resource modification came in and it might have a new child
807 // // For example, in an IWorkspaceRunnable:
808 // // 1. create a package fragment p using a java model operation
809 // // 2. open package p
810 // // 3. add file X.java in folder p
811 // // When the resource delta comes in, only the addition of p is notified,
812 // // but the package p is already opened, thus its children are not recomputed
813 // // and it appears empty.
816 // if (delta != null && (delta.getFlags() & IResourceDelta.MOVED_FROM) != 0) {
817 // IPath movedFromPath = delta.getMovedFromPath();
818 // IResource res = delta.getResource();
819 // IResource movedFromRes;
820 // if (res instanceof IFile) {
821 // movedFromRes = res.getWorkspace().getRoot().getFile(movedFromPath);
823 // movedFromRes = res.getWorkspace().getRoot().getFolder(movedFromPath);
826 // // find the element type of the moved from element
827 // RootInfo movedFromInfo = this.enclosingRootInfo(movedFromPath, IResourceDelta.REMOVED);
828 // int movedFromType =
831 // IResourceDelta.REMOVED,
832 // element.getParent().getElementType(),
835 // // reset current element as it might be inside a nested root (popUntilPrefixOf() may use the outer root)
836 // this.currentElement = null;
838 // // create the moved from element
839 // Openable movedFromElement =
840 // elementType != IJavaElement.JAVA_PROJECT && movedFromType == IJavaElement.JAVA_PROJECT ?
841 // null : // outside classpath
842 // this.createElement(movedFromRes, movedFromType, movedFromInfo);
843 // if (movedFromElement == null) {
844 // // moved from outside classpath
845 // currentDelta().added(element);
847 // currentDelta().movedTo(element, movedFromElement);
850 // currentDelta().added(element);
853 // switch (elementType) {
854 // case IJavaElement.PACKAGE_FRAGMENT_ROOT :
855 // // when a root is added, and is on the classpath, the project must be updated
856 // JavaProject project = (JavaProject) element.getJavaProject();
857 // this.projectsToUpdate.add(project);
858 // this.projectsForDependentNamelookupRefresh.add(project);
861 // case IJavaElement.PACKAGE_FRAGMENT :
862 // // get rid of namelookup since it holds onto obsolete cached info
863 // project = (JavaProject) element.getJavaProject();
865 // project.getJavaProjectElementInfo().setNameLookup(null);
866 // this.projectsForDependentNamelookupRefresh.add(project);
867 // } catch (JavaModelException e) {
869 // // add subpackages
870 // if (delta != null){
871 // PackageFragmentRoot root = element.getPackageFragmentRoot();
872 // String name = element.getElementName();
873 // IResourceDelta[] children = delta.getAffectedChildren();
874 // for (int i = 0, length = children.length; i < length; i++) {
875 // IResourceDelta child = children[i];
876 // IResource resource = child.getResource();
877 // if (resource instanceof IFolder) {
878 // String folderName = resource.getName();
879 // if (Util.isValidFolderNameForPackage(folderName)) {
880 // String subpkgName =
881 // name.length() == 0 ?
883 // name + "." + folderName; //$NON-NLS-1$
884 // Openable subpkg = (Openable)root.getPackageFragment(subpkgName);
885 // this.updateIndex(subpkg, child);
886 // this.elementAdded(subpkg, child, rootInfo);
897 * Generic processing for a removed element:<ul>
898 * <li>Close the element, removing its structure from the cache
899 * <li>Remove the element from its parent's cache of children
900 * <li>Add a REMOVED entry in the delta
902 * Delta argument could be null if processing an external JAR change
904 // protected void elementRemoved(Openable element, IResourceDelta delta, RootInfo rootInfo) {
906 // if (element.isOpen()) {
909 // removeFromParentInfo(element);
910 // int elementType = element.getElementType();
911 // if (delta != null && (delta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
912 // IPath movedToPath = delta.getMovedToPath();
913 // IResource res = delta.getResource();
914 // IResource movedToRes;
915 // switch (res.getType()) {
916 // case IResource.PROJECT:
917 // movedToRes = res.getWorkspace().getRoot().getProject(movedToPath.lastSegment());
919 // case IResource.FOLDER:
920 // movedToRes = res.getWorkspace().getRoot().getFolder(movedToPath);
922 // case IResource.FILE:
923 // movedToRes = res.getWorkspace().getRoot().getFile(movedToPath);
929 // // find the element type of the moved from element
930 // RootInfo movedToInfo = this.enclosingRootInfo(movedToPath, IResourceDelta.ADDED);
934 // IResourceDelta.ADDED,
935 // element.getParent().getElementType(),
938 // // reset current element as it might be inside a nested root (popUntilPrefixOf() may use the outer root)
939 // this.currentElement = null;
941 // // create the moved To element
942 // Openable movedToElement =
943 // elementType != IJavaElement.JAVA_PROJECT && movedToType == IJavaElement.JAVA_PROJECT ?
944 // null : // outside classpath
945 // this.createElement(movedToRes, movedToType, movedToInfo);
946 // if (movedToElement == null) {
947 // // moved outside classpath
948 // currentDelta().removed(element);
950 // currentDelta().movedFrom(element, movedToElement);
953 // currentDelta().removed(element);
956 // switch (elementType) {
957 // case IJavaElement.JAVA_MODEL :
958 // this.indexManager.reset();
960 // case IJavaElement.JAVA_PROJECT :
961 // this.manager.removePerProjectInfo(
962 // (JavaProject) element);
963 // this.updateRoots(element.getPath(), delta);
964 // this.projectsForDependentNamelookupRefresh.add((JavaProject) element);
966 // case IJavaElement.PACKAGE_FRAGMENT_ROOT :
967 // JavaProject project = (JavaProject) element.getJavaProject();
968 // this.projectsToUpdate.add(project);
969 // this.projectsForDependentNamelookupRefresh.add(project);
971 // case IJavaElement.PACKAGE_FRAGMENT :
972 // //1G1TW2T - get rid of namelookup since it holds onto obsolete cached info
973 // project = (JavaProject) element.getJavaProject();
975 // project.getJavaProjectElementInfo().setNameLookup(null);
976 // this.projectsForDependentNamelookupRefresh.add(project);
977 // } catch (JavaModelException e) {
979 // // remove subpackages
980 // if (delta != null){
981 // PackageFragmentRoot root = element.getPackageFragmentRoot();
982 // String name = element.getElementName();
983 // IResourceDelta[] children = delta.getAffectedChildren();
984 // for (int i = 0, length = children.length; i < length; i++) {
985 // IResourceDelta child = children[i];
986 // IResource resource = child.getResource();
987 // if (resource instanceof IFolder) {
988 // String folderName = resource.getName();
989 // if (Util.isValidFolderNameForPackage(folderName)) {
990 // String subpkgName =
991 // name.length() == 0 ?
993 // name + "." + folderName; //$NON-NLS-1$
994 // Openable subpkg = (Openable)root.getPackageFragment(subpkgName);
995 // this.updateIndex(subpkg, child);
996 // this.elementRemoved(subpkg, child, rootInfo);
1006 * Returns the type of the java element the given delta matches to.
1007 * Returns NON_JAVA_RESOURCE if unknown (e.g. a non-java resource or excluded .java file)
1009 // private int elementType(IResource res, int kind, int parentType, RootInfo rootInfo) {
1010 // switch (parentType) {
1011 // case IJavaElement.JAVA_MODEL:
1012 // // case of a movedTo or movedFrom project (other cases are handled in processResourceDelta(...)
1013 // return IJavaElement.JAVA_PROJECT;
1014 // case NON_JAVA_RESOURCE:
1015 // case IJavaElement.JAVA_PROJECT:
1016 // if (rootInfo == null) {
1017 // rootInfo = this.enclosingRootInfo(res.getFullPath(), kind);
1019 // if (rootInfo != null && rootInfo.isRootOfProject(res.getFullPath())) {
1020 // return IJavaElement.PACKAGE_FRAGMENT_ROOT;
1022 // return NON_JAVA_RESOURCE; // not yet in a package fragment root or root of another project
1024 // case IJavaElement.PACKAGE_FRAGMENT_ROOT:
1025 // case IJavaElement.PACKAGE_FRAGMENT:
1026 // if (rootInfo == null) {
1027 // rootInfo = this.enclosingRootInfo(res.getFullPath(), kind);
1029 // if (rootInfo == null || Util.isExcluded(res, rootInfo.exclusionPatterns)) {
1030 // return NON_JAVA_RESOURCE;
1032 // if (res instanceof IFolder) {
1033 // if (Util.isValidFolderNameForPackage(res.getName())) {
1034 // return IJavaElement.PACKAGE_FRAGMENT;
1036 // return NON_JAVA_RESOURCE;
1039 // String fileName = res.getName();
1040 // if (Util.isValidCompilationUnitName(fileName)) {
1041 // return IJavaElement.COMPILATION_UNIT;
1042 // } else if (Util.isValidClassFileName(fileName)) {
1043 // return IJavaElement.CLASS_FILE;
1044 // } else if (this.rootInfo(res.getFullPath(), kind) != null) {
1045 // // case of proj=src=bin and resource is a jar file on the classpath
1046 // return IJavaElement.PACKAGE_FRAGMENT_ROOT;
1048 // return NON_JAVA_RESOURCE;
1052 // return NON_JAVA_RESOURCE;
1057 * Answer a combination of the lastModified stamp and the size.
1058 * Used for detecting external JAR changes
1060 public static long getTimeStamp(File file) {
1061 return file.lastModified() + file.length();
1064 // public void initializeRoots() {
1065 // // remember roots infos as old roots infos
1066 // this.oldRoots = this.roots == null ? new HashMap() : this.roots;
1067 // this.oldOtherRoots = this.otherRoots == null ? new HashMap() : this.otherRoots;
1069 // // recompute root infos only if necessary
1070 // if (!rootsAreStale) return;
1072 // this.roots = new HashMap();
1073 // this.otherRoots = new HashMap();
1074 // this.sourceAttachments = new HashMap();
1076 // IJavaModel model = this.manager.getJavaModel();
1077 // IJavaProject[] projects;
1079 // projects = model.getJavaProjects();
1080 // } catch (JavaModelException e) {
1081 // // nothing can be done
1084 // for (int i = 0, length = projects.length; i < length; i++) {
1085 // IJavaProject project = projects[i];
1086 // IClasspathEntry[] classpath;
1088 // classpath = project.getResolvedClasspath(true);
1089 // } catch (JavaModelException e) {
1090 // // continue with next project
1093 // for (int j= 0, classpathLength = classpath.length; j < classpathLength; j++) {
1094 // IClasspathEntry entry = classpath[j];
1095 // if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) continue;
1098 // IPath path = entry.getPath();
1099 // if (this.roots.get(path) == null) {
1100 // this.roots.put(path, new RootInfo(project, path, ((ClasspathEntry)entry).fullExclusionPatternChars()));
1102 // ArrayList rootList = (ArrayList)this.otherRoots.get(path);
1103 // if (rootList == null) {
1104 // rootList = new ArrayList();
1105 // this.otherRoots.put(path, rootList);
1107 // rootList.add(new RootInfo(project, path, ((ClasspathEntry)entry).fullExclusionPatternChars()));
1110 // // source attachment path
1111 // if (entry.getEntryKind() != IClasspathEntry.CPE_LIBRARY) continue;
1112 // QualifiedName qName = new QualifiedName(JavaCore.PLUGIN_ID, "sourceattachment: " + path.toOSString()); //$NON-NLS-1$;
1113 // String propertyString = null;
1115 // propertyString = ResourcesPlugin.getWorkspace().getRoot().getPersistentProperty(qName);
1116 // } catch (CoreException e) {
1119 // IPath sourceAttachmentPath;
1120 // if (propertyString != null) {
1121 // int index= propertyString.lastIndexOf(JarPackageFragmentRoot.ATTACHMENT_PROPERTY_DELIMITER);
1122 // sourceAttachmentPath = (index < 0) ? new Path(propertyString) : new Path(propertyString.substring(0, index));
1124 // sourceAttachmentPath = entry.getSourceAttachmentPath();
1126 // if (sourceAttachmentPath != null) {
1127 // this.sourceAttachments.put(sourceAttachmentPath, path);
1131 // this.rootsAreStale = false;
1135 * Returns whether a given delta contains some information relevant to the JavaModel,
1136 * in particular it will not consider SYNC or MARKER only deltas.
1138 public boolean isAffectedBy(IResourceDelta rootDelta){
1139 //if (rootDelta == null) System.out.println("NULL DELTA");
1140 //long start = System.currentTimeMillis();
1141 if (rootDelta != null) {
1142 // use local exception to quickly escape from delta traversal
1143 class FoundRelevantDeltaException extends RuntimeException {}
1145 rootDelta.accept(new IResourceDeltaVisitor() {
1146 public boolean visit(IResourceDelta delta) throws CoreException {
1147 switch (delta.getKind()){
1148 case IResourceDelta.ADDED :
1149 case IResourceDelta.REMOVED :
1150 throw new FoundRelevantDeltaException();
1151 case IResourceDelta.CHANGED :
1152 // if any flag is set but SYNC or MARKER, this delta should be considered
1153 if (delta.getAffectedChildren().length == 0 // only check leaf delta nodes
1154 && (delta.getFlags() & ~(IResourceDelta.SYNC | IResourceDelta.MARKERS)) != 0) {
1155 throw new FoundRelevantDeltaException();
1161 } catch(FoundRelevantDeltaException e) {
1162 //System.out.println("RELEVANT DELTA detected in: "+ (System.currentTimeMillis() - start));
1164 } catch(CoreException e) { // ignore delta if not able to traverse
1167 //System.out.println("IGNORE SYNC DELTA took: "+ (System.currentTimeMillis() - start));
1172 * Returns whether the given resource is in one of the given output folders and if
1173 * it is filtered out from this output folder.
1175 private boolean isResFilteredFromOutput(OutputsInfo info, IResource res, int elementType) {
1177 IPath resPath = res.getFullPath();
1178 for (int i = 0; i < info.outputCount; i++) {
1179 if (info.paths[i].isPrefixOf(resPath)) {
1180 if (info.traverseModes[i] != IGNORE) {
1182 if (info.traverseModes[i] == SOURCE && elementType == IJavaElement.CLASS_FILE) {
1185 // case of .class file under project and no source folder
1187 if (elementType == IJavaElement.JAVA_PROJECT
1188 && res instanceof IFile
1189 && PHPFileUtil.isPHPFile((IFile)res)) {
1203 * Generic processing for elements with changed contents:<ul>
1204 * <li>The element is closed such that any subsequent accesses will re-open
1205 * the element reflecting its new structure.
1206 * <li>An entry is made in the delta reporting a content change (K_CHANGE with F_CONTENT flag set).
1209 // protected void nonJavaResourcesChanged(Openable element, IResourceDelta delta)
1210 // throws JavaModelException {
1212 // // reset non-java resources if element was open
1213 // if (element.isOpen()) {
1214 // JavaElementInfo info = (JavaElementInfo)element.getElementInfo();
1215 // switch (element.getElementType()) {
1216 // case IJavaElement.JAVA_MODEL :
1217 // ((JavaModelInfo) info).nonJavaResources = null;
1218 // currentDelta().addResourceDelta(delta);
1220 // case IJavaElement.JAVA_PROJECT :
1221 // ((JavaProjectElementInfo) info).setNonJavaResources(null);
1223 // // if a package fragment root is the project, clear it too
1224 // JavaProject project = (JavaProject) element;
1225 // PackageFragmentRoot projectRoot =
1226 // (PackageFragmentRoot) project.getPackageFragmentRoot(project.getProject());
1227 // if (projectRoot.isOpen()) {
1228 // ((PackageFragmentRootInfo) projectRoot.getElementInfo()).setNonJavaResources(
1232 // case IJavaElement.PACKAGE_FRAGMENT :
1233 // ((PackageFragmentInfo) info).setNonJavaResources(null);
1235 // case IJavaElement.PACKAGE_FRAGMENT_ROOT :
1236 // ((PackageFragmentRootInfo) info).setNonJavaResources(null);
1240 // JavaElementDelta elementDelta = currentDelta().find(element);
1241 // if (elementDelta == null) {
1242 // currentDelta().changed(element, IJavaElementDelta.F_CONTENT);
1243 // elementDelta = currentDelta().find(element);
1245 // elementDelta.addResourceDelta(delta);
1247 // private OutputsInfo outputsInfo(RootInfo rootInfo, IResource res) {
1249 // IJavaProject proj =
1250 // rootInfo == null ?
1251 // (IJavaProject)this.createElement(res.getProject(), IJavaElement.JAVA_PROJECT, null) :
1252 // rootInfo.project;
1253 // if (proj != null) {
1254 // IPath projectOutput = proj.getOutputLocation();
1255 // int traverseMode = IGNORE;
1256 // if (proj.getProject().getFullPath().equals(projectOutput)){ // case of proj==bin==src
1257 // return new OutputsInfo(new IPath[] {projectOutput}, new int[] {SOURCE}, 1);
1259 // IClasspathEntry[] classpath = proj.getResolvedClasspath(true);
1260 // IPath[] outputs = new IPath[classpath.length+1];
1261 // int[] traverseModes = new int[classpath.length+1];
1262 // int outputCount = 1;
1263 // outputs[0] = projectOutput;
1264 // traverseModes[0] = traverseMode;
1265 // for (int i = 0, length = classpath.length; i < length; i++) {
1266 // IClasspathEntry entry = classpath[i];
1267 // IPath entryPath = entry.getPath();
1268 // IPath output = entry.getOutputLocation();
1269 // if (output != null) {
1270 // outputs[outputCount] = output;
1271 // // check case of src==bin
1272 // if (entryPath.equals(output)) {
1273 // traverseModes[outputCount++] = (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) ? SOURCE : BINARY;
1275 // traverseModes[outputCount++] = IGNORE;
1279 // // check case of src==bin
1280 // if (entryPath.equals(projectOutput)) {
1281 // traverseModes[0] = (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) ? SOURCE : BINARY;
1284 // return new OutputsInfo(outputs, traverseModes, outputCount);
1287 // } catch (JavaModelException e) {
1293 * Check whether the updated file is affecting some of the properties of a given project (like
1294 * its classpath persisted as a file).
1295 * Also force classpath problems to be refresh if not running in autobuild mode.
1296 * NOTE: It can induce resource changes, and cannot be called during POST_CHANGE notification.
1299 // public void performPreBuildCheck(
1300 // IResourceDelta delta,
1301 // IJavaElement parent) {
1303 // IResource resource = delta.getResource();
1304 // IJavaElement element = null;
1305 // boolean processChildren = false;
1307 // switch (resource.getType()) {
1309 // case IResource.ROOT :
1310 // if (delta.getKind() == IResourceDelta.CHANGED) {
1311 // element = JavaCore.create(resource);
1312 // processChildren = true;
1315 // case IResource.PROJECT :
1316 // int kind = delta.getKind();
1318 // case IResourceDelta.CHANGED:
1319 // // do not visit non-java projects (see bug 16140 Non-java project gets .classpath)
1320 // IProject project = (IProject)resource;
1321 // if (JavaProject.hasJavaNature(project)) {
1322 // element = JavaCore.create(resource);
1323 // processChildren = true;
1324 // } else if (JavaModelManager.getJavaModelManager().getJavaModel().findJavaProject(project) != null) {
1325 // // project had the java nature
1326 // this.rootsAreStale = true;
1328 // // remove classpath cache so that initializeRoots() will not consider the project has a classpath
1329 // this.manager.removePerProjectInfo((JavaProject)JavaCore.create(project));
1332 // case IResourceDelta.ADDED:
1333 // this.rootsAreStale = true;
1335 // case IResourceDelta.REMOVED:
1336 // // remove classpath cache so that initializeRoots() will not consider the project has a classpath
1337 // this.manager.removePerProjectInfo((JavaProject)JavaCore.create(resource));
1339 // this.rootsAreStale = true;
1343 // case IResource.FILE :
1344 // if (parent.getElementType() == IJavaElement.JAVA_PROJECT) {
1345 // IFile file = (IFile) resource;
1346 // JavaProject project = (JavaProject) parent;
1348 // /* check classpath file change */
1349 // if (file.getName().equals(JavaProject.CLASSPATH_FILENAME)) {
1350 // reconcileClasspathFileUpdate(delta, file, project);
1351 // this.rootsAreStale = true;
1354 //// /* check custom preference file change */
1355 //// if (file.getName().equals(JavaProject.PREF_FILENAME)) {
1356 //// reconcilePreferenceFileUpdate(delta, file, project);
1362 // if (processChildren) {
1363 // IResourceDelta[] children = delta.getAffectedChildren();
1364 // for (int i = 0; i < children.length; i++) {
1365 // performPreBuildCheck(children[i], element);
1370 // private void popUntilPrefixOf(IPath path) {
1371 // while (this.currentElement != null) {
1372 // IPath currentElementPath = null;
1373 // if (this.currentElement instanceof IPackageFragmentRoot) {
1374 // currentElementPath = ((IPackageFragmentRoot)this.currentElement).getPath();
1376 // IResource currentElementResource = this.currentElement.getResource();
1377 // if (currentElementResource != null) {
1378 // currentElementPath = currentElementResource.getFullPath();
1381 // if (currentElementPath != null) {
1382 // if (this.currentElement instanceof IPackageFragment
1383 // && this.currentElement.getElementName().length() == 0
1384 // && currentElementPath.segmentCount() != path.segmentCount()-1) {
1385 // // default package and path is not a direct child
1386 // this.currentElement = (Openable)this.currentElement.getParent();
1388 // if (currentElementPath.isPrefixOf(path)) {
1392 // this.currentElement = (Openable)this.currentElement.getParent();
1397 * Converts a <code>IResourceDelta</code> rooted in a <code>Workspace</code> into
1398 * the corresponding set of <code>IJavaElementDelta</code>, rooted in the
1399 * relevant <code>JavaModel</code>s.
1401 // public IJavaElementDelta processResourceDelta(IResourceDelta changes) {
1404 // IJavaModel model = this.manager.getJavaModel();
1405 // if (!model.isOpen()) {
1406 // // force opening of java model so that java element delta are reported
1408 // model.open(null);
1409 // } catch (JavaModelException e) {
1411 // e.printStackTrace();
1416 // this.initializeRoots();
1417 // this.currentElement = null;
1419 // // get the workspace delta, and start processing there.
1420 // IResourceDelta[] deltas = changes.getAffectedChildren();
1421 // for (int i = 0; i < deltas.length; i++) {
1422 // IResourceDelta delta = deltas[i];
1423 // IResource res = delta.getResource();
1425 // // find out the element type
1426 // RootInfo rootInfo = null;
1428 // IProject proj = (IProject)res;
1429 // boolean wasJavaProject = this.manager.getJavaModel().findJavaProject(proj) != null;
1430 // boolean isJavaProject = JavaProject.hasJavaNature(proj);
1431 // if (!wasJavaProject && !isJavaProject) {
1432 // elementType = NON_JAVA_RESOURCE;
1434 // rootInfo = this.enclosingRootInfo(res.getFullPath(), delta.getKind());
1435 // if (rootInfo != null && rootInfo.isRootOfProject(res.getFullPath())) {
1436 // elementType = IJavaElement.PACKAGE_FRAGMENT_ROOT;
1438 // elementType = IJavaElement.JAVA_PROJECT;
1442 // // traverse delta
1443 // if (!this.traverseDelta(delta, elementType, rootInfo, null)
1444 // || (wasJavaProject != isJavaProject && (delta.getKind()) == IResourceDelta.CHANGED)) { // project has changed nature (description or open/closed)
1446 // // add child as non java resource
1447 // nonJavaResourcesChanged((JavaModel)model, delta);
1448 // } catch (JavaModelException e) {
1454 // // update package fragment roots of projects that were affected
1455 // Iterator iterator = this.projectsToUpdate.iterator();
1456 // while (iterator.hasNext()) {
1457 // JavaProject project = (JavaProject)iterator.next();
1458 // project.updatePackageFragmentRoots();
1461 // updateDependentNamelookups();
1463 // return this.currentDelta;
1465 // this.currentDelta = null;
1466 // this.projectsToUpdate.clear();
1467 // this.projectsForDependentNamelookupRefresh.clear();
1472 * Update the JavaModel according to a .classpath file change. The file can have changed as a result of a previous
1473 * call to JavaProject#setRawClasspath or as a result of some user update (through repository)
1475 // void reconcileClasspathFileUpdate(IResourceDelta delta, IFile file, JavaProject project) {
1477 // switch (delta.getKind()) {
1478 // case IResourceDelta.REMOVED : // recreate one based on in-memory classpath
1480 // JavaModelManager.PerProjectInfo info = JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(project.getProject());
1481 // if (info.classpath != null) { // if there is an in-memory classpath
1482 // project.saveClasspath(info.classpath, info.outputLocation);
1484 // } catch (JavaModelException e) {
1485 // if (project.getProject().isAccessible()) {
1486 // Util.log(e, "Could not save classpath for "+ project.getPath()); //$NON-NLS-1$
1490 // case IResourceDelta.CHANGED :
1491 // if ((delta.getFlags() & IResourceDelta.CONTENT) == 0 // only consider content change
1492 // && (delta.getFlags() & IResourceDelta.MOVED_FROM) == 0) // and also move and overide scenario (see http://dev.eclipse.org/bugs/show_bug.cgi?id=21420)
1494 // case IResourceDelta.ADDED :
1495 // // check if any actual difference
1496 // project.flushClasspathProblemMarkers(false, true);
1497 // boolean wasSuccessful = false; // flag recording if .classpath file change got reflected
1499 // // force to (re)read the property file
1500 // IClasspathEntry[] fileEntries = project.readClasspathFile(true/*create markers*/, false/*don't log problems*/);
1501 // if (fileEntries == null)
1502 // break; // could not read, ignore
1503 // JavaModelManager.PerProjectInfo info = JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(project.getProject());
1504 // if (info.classpath != null) { // if there is an in-memory classpath
1505 // if (project.isClasspathEqualsTo(info.classpath, info.outputLocation, fileEntries)) {
1506 // wasSuccessful = true;
1511 // // will force an update of the classpath/output location based on the file information
1512 // // extract out the output location
1513 // IPath outputLocation = null;
1514 // if (fileEntries != null && fileEntries.length > 0) {
1515 // IClasspathEntry entry = fileEntries[fileEntries.length - 1];
1516 // if (entry.getContentKind() == ClasspathEntry.K_OUTPUT) {
1517 // outputLocation = entry.getPath();
1518 // IClasspathEntry[] copy = new IClasspathEntry[fileEntries.length - 1];
1519 // System.arraycopy(fileEntries, 0, copy, 0, copy.length);
1520 // fileEntries = copy;
1523 // // restore output location
1524 // if (outputLocation == null) {
1525 // outputLocation = SetClasspathOperation.ReuseOutputLocation;
1526 // // clean mode will also default to reusing current one
1528 // project.setRawClasspath(
1532 // true, // canChangeResource
1533 // project.getResolvedClasspath(true), // ignoreUnresolvedVariable
1534 // true, // needValidation
1535 // false); // no need to save
1537 // // if reach that far, the classpath file change got absorbed
1538 // wasSuccessful = true;
1539 // } catch (RuntimeException e) {
1540 // // setRawClasspath might fire a delta, and a listener may throw an exception
1541 // if (project.getProject().isAccessible()) {
1542 // Util.log(e, "Could not set classpath for "+ project.getPath()); //$NON-NLS-1$
1545 // } catch (JavaModelException e) { // CP failed validation
1546 // if (project.getProject().isAccessible()) {
1547 // if (e.getJavaModelStatus().getException() instanceof CoreException) {
1548 // // happens if the .classpath could not be written to disk
1549 // project.createClasspathProblemMarker(new JavaModelStatus(
1550 // IJavaModelStatusConstants.INVALID_CLASSPATH_FILE_FORMAT,
1551 // Util.bind("classpath.couldNotWriteClasspathFile", project.getElementName(), e.getMessage()))); //$NON-NLS-1$
1553 // project.createClasspathProblemMarker(new JavaModelStatus(
1554 // IJavaModelStatusConstants.INVALID_CLASSPATH_FILE_FORMAT,
1555 // Util.bind("classpath.invalidClasspathInClasspathFile", project.getElementName(), e.getMessage()))); //$NON-NLS-1$
1560 // if (!wasSuccessful) {
1562 // project.setRawClasspath0(JavaProject.INVALID_CLASSPATH);
1563 // project.updatePackageFragmentRoots();
1564 // } catch (JavaModelException e) {
1572 * Update the JavaModel according to a .jprefs file change. The file can have changed as a result of a previous
1573 * call to JavaProject#setOptions or as a result of some user update (through repository)
1574 * Unused until preference file get shared (.jpref)
1576 // void reconcilePreferenceFileUpdate(IResourceDelta delta, IFile file, JavaProject project) {
1578 // switch (delta.getKind()) {
1579 // case IResourceDelta.REMOVED : // flush project custom settings
1580 // project.setOptions(null);
1582 // case IResourceDelta.CHANGED :
1583 // if ((delta.getFlags() & IResourceDelta.CONTENT) == 0 // only consider content change
1584 // && (delta.getFlags() & IResourceDelta.MOVED_FROM) == 0) // and also move and overide scenario
1586 // identityCheck : { // check if any actual difference
1587 // // force to (re)read the property file
1588 // Preferences filePreferences = project.loadPreferences();
1589 // if (filePreferences == null){
1590 // project.setOptions(null); // should have got removed delta.
1593 // Preferences projectPreferences = project.getPreferences();
1594 // if (projectPreferences == null) return; // not a Java project
1596 // // compare preferences set to their default
1597 // String[] defaultProjectPropertyNames = projectPreferences.defaultPropertyNames();
1598 // String[] defaultFilePropertyNames = filePreferences.defaultPropertyNames();
1599 // if (defaultProjectPropertyNames.length == defaultFilePropertyNames.length) {
1600 // for (int i = 0; i < defaultProjectPropertyNames.length; i++){
1601 // String propertyName = defaultProjectPropertyNames[i];
1602 // if (!projectPreferences.getString(propertyName).trim().equals(filePreferences.getString(propertyName).trim())){
1603 // break identityCheck;
1606 // } else break identityCheck;
1608 // // compare custom preferences not set to their default
1609 // String[] projectPropertyNames = projectPreferences.propertyNames();
1610 // String[] filePropertyNames = filePreferences.propertyNames();
1611 // if (projectPropertyNames.length == filePropertyNames.length) {
1612 // for (int i = 0; i < projectPropertyNames.length; i++){
1613 // String propertyName = projectPropertyNames[i];
1614 // if (!projectPreferences.getString(propertyName).trim().equals(filePreferences.getString(propertyName).trim())){
1615 // break identityCheck;
1618 // } else break identityCheck;
1620 // // identical - do nothing
1623 // case IResourceDelta.ADDED :
1624 // // not identical, create delta and reset cached preferences
1625 // project.setPreferences(null);
1627 // //fCurrentDelta.changed(project, IJavaElementDelta.F_OPTIONS_CHANGED);
1632 * Removes the given element from its parents cache of children. If the
1633 * element does not have a parent, or the parent is not currently open,
1634 * this has no effect.
1636 protected void removeFromParentInfo(Openable child) {
1638 Openable parent = (Openable) child.getParent();
1639 if (parent != null && parent.isOpen()) {
1641 JavaElementInfo info = (JavaElementInfo)parent.getElementInfo();
1642 info.removeChild(child);
1643 } catch (JavaModelException e) {
1644 // do nothing - we already checked if open
1649 * Notification that some resource changes have happened
1650 * on the platform, and that the Java Model should update any required
1651 * internal structures such that its elements remain consistent.
1652 * Translates <code>IResourceDeltas</code> into <code>IJavaElementDeltas</code>.
1654 * @see IResourceDelta
1657 public void resourceChanged(IResourceChangeEvent event) {
1659 if (event.getSource() instanceof IWorkspace) {
1660 IResource resource = event.getResource();
1661 IResourceDelta delta = event.getDelta();
1663 switch(event.getType()){
1664 case IResourceChangeEvent.PRE_DELETE :
1666 if(resource.getType() == IResource.PROJECT
1667 && ((IProject) resource).hasNature(JavaCore.NATURE_ID)) {
1668 // TODO khartlage temp-del
1669 // this.deleting((IProject)resource);
1671 } catch(CoreException e){
1675 case IResourceChangeEvent.PRE_AUTO_BUILD :
1676 // TODO khartlage temp-del
1677 // if(isAffectedBy(delta)) { // avoid populating for SYNC or MARKER deltas
1678 // this.checkProjectsBeingAddedOrRemoved(delta);
1680 // // update the classpath related markers
1681 // this.updateClasspathMarkers();
1683 // // the following will close project if affected by the property file change
1685 // // don't fire classpath change deltas right away, but batch them
1686 // this.manager.stopDeltas();
1687 // this.performPreBuildCheck(delta, null);
1689 // this.manager.startDeltas();
1692 // only fire already computed deltas (resource ones will be processed in post change only)
1693 this.manager.fire(null, ElementChangedEvent.PRE_AUTO_BUILD);
1696 case IResourceChangeEvent.POST_AUTO_BUILD :
1697 // TODO khartlage temp-del
1698 // JavaBuilder.finishedBuilding(event);
1701 case IResourceChangeEvent.POST_CHANGE :
1702 // TODO khartlage temp-del
1703 // if (isAffectedBy(delta)) {
1705 // if (this.refreshedElements != null) {
1707 // createExternalArchiveDelta(null);
1708 // } catch (JavaModelException e) {
1709 // e.printStackTrace();
1712 // IJavaElementDelta translatedDelta = this.processResourceDelta(delta);
1713 // if (translatedDelta != null) {
1714 // this.manager.registerJavaModelDelta(translatedDelta);
1716 // this.manager.fire(null, ElementChangedEvent.POST_CHANGE);
1718 // // workaround for bug 15168 circular errors not reported
1719 // this.manager.javaProjectsCache = null;
1720 // this.removedRoots = null;
1727 * Finds the root info this path is included in.
1728 * Returns null if not found.
1730 RootInfo enclosingRootInfo(IPath path, int kind) {
1731 while (path != null && path.segmentCount() > 0) {
1732 RootInfo rootInfo = this.rootInfo(path, kind);
1733 if (rootInfo != null) return rootInfo;
1734 path = path.removeLastSegments(1);
1739 * Returns the root info for the given path. Look in the old roots table if kind is REMOVED.
1741 RootInfo rootInfo(IPath path, int kind) {
1742 if (kind == IResourceDelta.REMOVED) {
1743 return (RootInfo)this.oldRoots.get(path);
1745 return (RootInfo)this.roots.get(path);
1749 * Returns the other root infos for the given path. Look in the old other roots table if kind is REMOVED.
1751 ArrayList otherRootsInfo(IPath path, int kind) {
1752 if (kind == IResourceDelta.REMOVED) {
1753 return (ArrayList)this.oldOtherRoots.get(path);
1755 return (ArrayList)this.otherRoots.get(path);
1760 * Converts an <code>IResourceDelta</code> and its children into
1761 * the corresponding <code>IJavaElementDelta</code>s.
1762 * Return whether the delta corresponds to a java element.
1763 * If it is not a java element, it will be added as a non-java
1764 * resource by the sender of this method.
1766 // protected boolean traverseDelta(
1767 // IResourceDelta delta,
1769 // RootInfo rootInfo,
1770 // OutputsInfo outputsInfo) {
1772 // IResource res = delta.getResource();
1774 // // set stack of elements
1775 // if (this.currentElement == null && rootInfo != null) {
1776 // this.currentElement = (Openable)rootInfo.project;
1779 // // process current delta
1780 // boolean processChildren = true;
1781 // if (res instanceof IProject) {
1782 // processChildren =
1783 // this.updateCurrentDeltaAndIndex(
1785 // elementType == IJavaElement.PACKAGE_FRAGMENT_ROOT ?
1786 // IJavaElement.JAVA_PROJECT : // case of prj=src
1789 // } else if (rootInfo != null) {
1790 // processChildren = this.updateCurrentDeltaAndIndex(delta, elementType, rootInfo);
1792 // // not yet inside a package fragment root
1793 // processChildren = true;
1796 // // get the project's output locations and traverse mode
1797 // if (outputsInfo == null) outputsInfo = this.outputsInfo(rootInfo, res);
1799 // // process children if needed
1800 // if (processChildren) {
1801 // IResourceDelta[] children = delta.getAffectedChildren();
1802 // boolean oneChildOnClasspath = false;
1803 // int length = children.length;
1804 // IResourceDelta[] orphanChildren = null;
1805 // Openable parent = null;
1806 // boolean isValidParent = true;
1807 // for (int i = 0; i < length; i++) {
1808 // IResourceDelta child = children[i];
1809 // IResource childRes = child.getResource();
1811 // // check source attachment change
1812 // this.checkSourceAttachmentChange(child, childRes);
1814 // // find out whether the child is a package fragment root of the current project
1815 // IPath childPath = childRes.getFullPath();
1816 // int childKind = child.getKind();
1817 // RootInfo childRootInfo = this.rootInfo(childPath, childKind);
1818 // if (childRootInfo != null && !childRootInfo.isRootOfProject(childPath)) {
1819 // // package fragment root of another project (dealt with later)
1820 // childRootInfo = null;
1823 // // compute child type
1825 // this.elementType(
1829 // rootInfo == null ? childRootInfo : rootInfo
1832 // // is childRes in the output folder and is it filtered out ?
1833 // boolean isResFilteredFromOutput = this.isResFilteredFromOutput(outputsInfo, childRes, childType);
1835 // boolean isNestedRoot = rootInfo != null && childRootInfo != null;
1836 // if (!isResFilteredFromOutput
1837 // && !isNestedRoot) { // do not treat as non-java rsc if nested root
1838 // if (!this.traverseDelta(child, childType, rootInfo == null ? childRootInfo : rootInfo, outputsInfo)) { // traverse delta for child in the same project
1839 // // it is a non-java resource
1841 // if (rootInfo != null) { // if inside a package fragment root
1842 // if (!isValidParent) continue;
1843 // if (parent == null) {
1844 // // find the parent of the non-java resource to attach to
1845 // if (this.currentElement == null
1846 // || !this.currentElement.getJavaProject().equals(rootInfo.project)) {
1847 // // force the currentProject to be used
1848 // this.currentElement = (Openable)rootInfo.project;
1850 // if (elementType == IJavaElement.JAVA_PROJECT
1851 // || (elementType == IJavaElement.PACKAGE_FRAGMENT_ROOT
1852 // && res instanceof IProject)) {
1853 // // NB: attach non-java resource to project (not to its package fragment root)
1854 // parent = (Openable)rootInfo.project;
1856 // parent = this.createElement(res, elementType, rootInfo);
1858 // if (parent == null) {
1859 // isValidParent = false;
1863 // // add child as non java resource
1864 // nonJavaResourcesChanged(parent, child);
1866 // // the non-java resource (or its parent folder) will be attached to the java project
1867 // if (orphanChildren == null) orphanChildren = new IResourceDelta[length];
1868 // orphanChildren[i] = child;
1870 // } catch (JavaModelException e) {
1873 // oneChildOnClasspath = true;
1876 // oneChildOnClasspath = true; // to avoid reporting child delta as non-java resource delta
1879 // // if child is a nested root
1880 // // or if it is not a package fragment root of the current project
1881 // // but it is a package fragment root of another project, traverse delta too
1883 // || (childRootInfo == null && (childRootInfo = this.rootInfo(childPath, childKind)) != null)) {
1884 // this.traverseDelta(child, IJavaElement.PACKAGE_FRAGMENT_ROOT, childRootInfo, null); // binary output of childRootInfo.project cannot be this root
1885 // // NB: No need to check the return value as the child can only be on the classpath
1888 // // if the child is a package fragment root of one or several other projects
1889 // ArrayList rootList;
1890 // if ((rootList = this.otherRootsInfo(childPath, childKind)) != null) {
1891 // Iterator iterator = rootList.iterator();
1892 // while (iterator.hasNext()) {
1893 // childRootInfo = (RootInfo) iterator.next();
1894 // this.traverseDelta(child, IJavaElement.PACKAGE_FRAGMENT_ROOT, childRootInfo, null); // binary output of childRootInfo.project cannot be this root
1898 // if (orphanChildren != null
1899 // && (oneChildOnClasspath // orphan children are siblings of a package fragment root
1900 // || res instanceof IProject)) { // non-java resource directly under a project
1902 // // attach orphan children
1903 // IProject rscProject = res.getProject();
1904 // JavaProject adoptiveProject = (JavaProject)JavaCore.create(rscProject);
1905 // if (adoptiveProject != null
1906 // && JavaProject.hasJavaNature(rscProject)) { // delta iff Java project (18698)
1907 // for (int i = 0; i < length; i++) {
1908 // if (orphanChildren[i] != null) {
1910 // nonJavaResourcesChanged(adoptiveProject, orphanChildren[i]);
1911 // } catch (JavaModelException e) {
1916 // } // else resource delta will be added by parent
1917 // return elementType != NON_JAVA_RESOURCE; // TODO: (jerome) do we still need to return? (check could be done by caller)
1919 // return elementType != NON_JAVA_RESOURCE;
1924 * Update the classpath markers and cycle markers for the projects to update.
1926 // void updateClasspathMarkers() {
1928 // if (!ResourcesPlugin.getWorkspace().isAutoBuilding()) {
1929 // Iterator iterator = this.projectsToUpdate.iterator();
1930 // while (iterator.hasNext()) {
1932 // JavaProject project = (JavaProject)iterator.next();
1934 // // force classpath marker refresh
1935 // project.getResolvedClasspath(
1936 // true, // ignoreUnresolvedEntry
1937 // true); // generateMarkerOnError
1939 // } catch (JavaModelException e) {
1943 // if (!this.projectsToUpdate.isEmpty()){
1945 // // update all cycle markers
1946 // JavaProject.updateAllCycleMarkers();
1947 // } catch (JavaModelException e) {
1951 // this.projectsToUpdate = new HashSet();
1956 * Update the current delta (ie. add/remove/change the given element) and update the correponding index.
1957 * Returns whether the children of the given delta must be processed.
1958 * @throws a JavaModelException if the delta doesn't correspond to a java element of the given type.
1960 // private boolean updateCurrentDeltaAndIndex(IResourceDelta delta, int elementType, RootInfo rootInfo) {
1961 // Openable element;
1962 // switch (delta.getKind()) {
1963 // case IResourceDelta.ADDED :
1964 // IResource deltaRes = delta.getResource();
1965 // element = this.createElement(deltaRes, elementType, rootInfo);
1966 // if (element == null) {
1967 // // resource might be containing shared roots (see bug 19058)
1968 // this.updateRoots(deltaRes.getFullPath(), delta);
1971 // this.updateIndex(element, delta);
1972 // this.elementAdded(element, delta, rootInfo);
1974 // case IResourceDelta.REMOVED :
1975 // deltaRes = delta.getResource();
1976 // element = this.createElement(deltaRes, elementType, rootInfo);
1977 // if (element == null) {
1978 // // resource might be containing shared roots (see bug 19058)
1979 // this.updateRoots(deltaRes.getFullPath(), delta);
1982 // this.updateIndex(element, delta);
1983 // this.elementRemoved(element, delta, rootInfo);
1985 // if (deltaRes.getType() == IResource.PROJECT){
1986 // // reset the corresponding project built state, since cannot reuse if added back
1987 // this.manager.setLastBuiltState((IProject)deltaRes, null /*no state*/);
1990 // case IResourceDelta.CHANGED :
1991 // int flags = delta.getFlags();
1992 // if ((flags & IResourceDelta.CONTENT) != 0) {
1993 // // content has changed
1994 // element = this.createElement(delta.getResource(), elementType, rootInfo);
1995 // if (element == null) return false;
1996 // this.updateIndex(element, delta);
1997 // this.contentChanged(element, delta);
1998 // } else if (elementType == IJavaElement.JAVA_PROJECT) {
1999 // if ((flags & IResourceDelta.OPEN) != 0) {
2000 // // project has been opened or closed
2001 // IProject res = (IProject)delta.getResource();
2002 // element = this.createElement(res, elementType, rootInfo);
2003 // if (element == null) {
2004 // // resource might be containing shared roots (see bug 19058)
2005 // this.updateRoots(res.getFullPath(), delta);
2008 // if (res.isOpen()) {
2009 // if (JavaProject.hasJavaNature(res)) {
2010 // this.elementAdded(element, delta, rootInfo);
2011 // this.indexManager.indexAll(res);
2014 // JavaModel javaModel = this.manager.getJavaModel();
2015 // boolean wasJavaProject = javaModel.findJavaProject(res) != null;
2016 // if (wasJavaProject) {
2017 // this.elementRemoved(element, delta, rootInfo);
2018 // this.indexManager.discardJobs(element.getElementName());
2019 // this.indexManager.removeIndexFamily(res.getFullPath());
2023 // return false; // when a project is open/closed don't process children
2025 // if ((flags & IResourceDelta.DESCRIPTION) != 0) {
2026 // IProject res = (IProject)delta.getResource();
2027 // JavaModel javaModel = this.manager.getJavaModel();
2028 // boolean wasJavaProject = javaModel.findJavaProject(res) != null;
2029 // boolean isJavaProject = JavaProject.hasJavaNature(res);
2030 // if (wasJavaProject != isJavaProject) {
2031 // // project's nature has been added or removed
2032 // element = this.createElement(res, elementType, rootInfo);
2033 // if (element == null) return false; // note its resources are still visible as roots to other projects
2034 // if (isJavaProject) {
2035 // this.elementAdded(element, delta, rootInfo);
2036 // this.indexManager.indexAll(res);
2038 // this.elementRemoved(element, delta, rootInfo);
2039 // this.indexManager.discardJobs(element.getElementName());
2040 // this.indexManager.removeIndexFamily(res.getFullPath());
2041 // // reset the corresponding project built state, since cannot reuse if added back
2042 // this.manager.setLastBuiltState(res, null /*no state*/);
2044 // return false; // when a project's nature is added/removed don't process children
2054 * Traverse the set of projects which have changed namespace, and refresh their dependents
2056 // public void updateDependentNamelookups() {
2057 // Iterator iterator;
2058 // // update namelookup of dependent projects
2059 // iterator = this.projectsForDependentNamelookupRefresh.iterator();
2060 // HashSet affectedDependents = new HashSet();
2061 // while (iterator.hasNext()) {
2062 // JavaProject project = (JavaProject)iterator.next();
2063 // addDependentProjects(project.getPath(), affectedDependents);
2065 // iterator = affectedDependents.iterator();
2066 // while (iterator.hasNext()) {
2067 // JavaProject project = (JavaProject) iterator.next();
2068 // if (project.isOpen()){
2070 // ((JavaProjectElementInfo)project.getElementInfo()).setNameLookup(null);
2071 // } catch (JavaModelException e) {
2077 //protected void updateIndex(Openable element, IResourceDelta delta) {
2079 // if (indexManager == null)
2082 // switch (element.getElementType()) {
2083 // case IJavaElement.JAVA_PROJECT :
2084 // switch (delta.getKind()) {
2085 // case IResourceDelta.ADDED :
2086 // this.indexManager.indexAll(element.getJavaProject().getProject());
2088 // case IResourceDelta.REMOVED :
2089 // this.indexManager.removeIndexFamily(element.getJavaProject().getProject().getFullPath());
2090 // // NB: Discarding index jobs belonging to this project was done during PRE_DELETE
2092 // // NB: Update of index if project is opened, closed, or its java nature is added or removed
2093 // // is done in updateCurrentDeltaAndIndex
2096 // case IJavaElement.PACKAGE_FRAGMENT_ROOT :
2097 // if (element instanceof JarPackageFragmentRoot) {
2098 // JarPackageFragmentRoot root = (JarPackageFragmentRoot)element;
2099 // // index jar file only once (if the root is in its declaring project)
2100 // IPath jarPath = root.getPath();
2101 // switch (delta.getKind()) {
2102 // case IResourceDelta.ADDED:
2103 // // index the new jar
2104 // indexManager.indexLibrary(jarPath, root.getJavaProject().getProject());
2106 // case IResourceDelta.CHANGED:
2107 // // first remove the index so that it is forced to be re-indexed
2108 // indexManager.removeIndex(jarPath);
2109 // // then index the jar
2110 // indexManager.indexLibrary(jarPath, root.getJavaProject().getProject());
2112 // case IResourceDelta.REMOVED:
2113 // // the jar was physically removed: remove the index
2114 // this.indexManager.discardJobs(jarPath.toString());
2115 // this.indexManager.removeIndex(jarPath);
2120 // int kind = delta.getKind();
2121 // if (kind == IResourceDelta.ADDED || kind == IResourceDelta.REMOVED) {
2122 // IPackageFragmentRoot root = (IPackageFragmentRoot)element;
2123 // this.updateRootIndex(root, root.getPackageFragment(""), delta); //$NON-NLS-1$
2127 // // don't break as packages of the package fragment root can be indexed below
2128 // case IJavaElement.PACKAGE_FRAGMENT :
2129 // switch (delta.getKind()) {
2130 // case IResourceDelta.ADDED:
2131 // case IResourceDelta.REMOVED:
2132 // IPackageFragment pkg = null;
2133 // if (element instanceof IPackageFragmentRoot) {
2134 // IPackageFragmentRoot root = (IPackageFragmentRoot)element;
2135 // pkg = root.getPackageFragment(""); //$NON-NLS-1$
2137 // pkg = (IPackageFragment)element;
2139 // IResourceDelta[] children = delta.getAffectedChildren();
2140 // for (int i = 0, length = children.length; i < length; i++) {
2141 // IResourceDelta child = children[i];
2142 // IResource resource = child.getResource();
2143 // if (resource instanceof IFile) {
2144 // String name = resource.getName();
2145 // if (Util.isJavaFileName(name)) {
2146 // Openable cu = (Openable)pkg.getCompilationUnit(name);
2147 // this.updateIndex(cu, child);
2148 // } else if (Util.isClassFileName(name)) {
2149 // Openable classFile = (Openable)pkg.getClassFile(name);
2150 // this.updateIndex(classFile, child);
2157 // case IJavaElement.CLASS_FILE :
2158 // IFile file = (IFile) delta.getResource();
2159 // IJavaProject project = element.getJavaProject();
2160 // IPath binaryFolderPath = element.getPackageFragmentRoot().getPath();
2161 // // if the class file is part of the binary output, it has been created by
2162 // // the java builder -> ignore
2164 // if (binaryFolderPath.equals(project.getOutputLocation())) {
2167 // } catch (JavaModelException e) {
2169 // switch (delta.getKind()) {
2170 // case IResourceDelta.CHANGED :
2171 // // no need to index if the content has not changed
2172 // if ((delta.getFlags() & IResourceDelta.CONTENT) == 0)
2174 // case IResourceDelta.ADDED :
2175 // indexManager.addBinary(file, binaryFolderPath);
2177 // case IResourceDelta.REMOVED :
2178 // indexManager.remove(file.getFullPath().toString(), binaryFolderPath);
2182 // case IJavaElement.COMPILATION_UNIT :
2183 // file = (IFile) delta.getResource();
2184 // switch (delta.getKind()) {
2185 // case IResourceDelta.CHANGED :
2186 // // no need to index if the content has not changed
2187 // if ((delta.getFlags() & IResourceDelta.CONTENT) == 0)
2189 // case IResourceDelta.ADDED :
2190 // indexManager.addSource(file, file.getProject().getProject().getFullPath());
2192 // case IResourceDelta.REMOVED :
2193 // indexManager.remove(file.getFullPath().toString(), file.getProject().getProject().getFullPath());
2199 * Upadtes the index of the given root (assuming it's an addition or a removal).
2200 * This is done recusively, pkg being the current package.
2202 //private void updateRootIndex(IPackageFragmentRoot root, IPackageFragment pkg, IResourceDelta delta) {
2203 // this.updateIndex((Openable)pkg, delta);
2204 // IResourceDelta[] children = delta.getAffectedChildren();
2205 // String name = pkg.getElementName();
2206 // for (int i = 0, length = children.length; i < length; i++) {
2207 // IResourceDelta child = children[i];
2208 // IResource resource = child.getResource();
2209 // if (resource instanceof IFolder) {
2210 // String subpkgName =
2211 // name.length() == 0 ?
2212 // resource.getName() :
2213 // name + "." + resource.getName(); //$NON-NLS-1$
2214 // IPackageFragment subpkg = root.getPackageFragment(subpkgName);
2215 // this.updateRootIndex(root, subpkg, child);
2220 * Update the roots that are affected by the addition or the removal of the given container resource.
2222 //private void updateRoots(IPath containerPath, IResourceDelta containerDelta) {
2225 // if (containerDelta.getKind() == IResourceDelta.REMOVED) {
2226 // roots = this.oldRoots;
2227 // otherRoots = this.oldOtherRoots;
2229 // roots = this.roots;
2230 // otherRoots = this.otherRoots;
2232 // Iterator iterator = roots.keySet().iterator();
2233 // while (iterator.hasNext()) {
2234 // IPath path = (IPath)iterator.next();
2235 // if (containerPath.isPrefixOf(path) && !containerPath.equals(path)) {
2236 // IResourceDelta rootDelta = containerDelta.findMember(path.removeFirstSegments(1));
2237 // if (rootDelta == null) continue;
2238 // RootInfo rootInfo = (RootInfo)roots.get(path);
2240 // if (!rootInfo.project.getPath().isPrefixOf(path)) { // only consider roots that are not included in the container
2241 // this.updateCurrentDeltaAndIndex(rootDelta, IJavaElement.PACKAGE_FRAGMENT_ROOT, rootInfo);
2244 // ArrayList rootList = (ArrayList)otherRoots.get(path);
2245 // if (rootList != null) {
2246 // Iterator otherProjects = rootList.iterator();
2247 // while (otherProjects.hasNext()) {
2248 // rootInfo = (RootInfo)otherProjects.next();
2249 // if (!rootInfo.project.getPath().isPrefixOf(path)) { // only consider roots that are not included in the container
2250 // this.updateCurrentDeltaAndIndex(rootDelta, IJavaElement.PACKAGE_FRAGMENT_ROOT, rootInfo);