1 11 package org.eclipse.jdt.internal.core.search; 12 13 import java.util.HashSet ; 14 15 import org.eclipse.core.runtime.IPath; 16 import org.eclipse.jdt.core.IJavaElement; 17 import org.eclipse.jdt.core.IJavaElementDelta; 18 import org.eclipse.jdt.core.JavaModelException; 19 import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; 20 import org.eclipse.jdt.internal.core.JavaModelManager; 21 import org.eclipse.jdt.internal.core.JavaProject; 22 import org.eclipse.jdt.core.IJavaProject; 23 24 29 public class JavaWorkspaceScope extends JavaSearchScope { 30 31 protected boolean needsInitialize; 32 33 public boolean encloses(IJavaElement element) { 34 40 45 return true; 46 } 47 public boolean encloses(String resourcePathString) { 48 54 59 return true; 60 } 61 public IPath[] enclosingProjectsAndJars() { 62 if (this.needsInitialize) { 63 this.initialize(5); 64 } 65 return super.enclosingProjectsAndJars(); 66 } 67 public boolean equals(Object o) { 68 return o instanceof JavaWorkspaceScope; 69 } 70 public AccessRuleSet getAccessRuleSet(String relativePath, String containerPath) { 71 if (this.pathRestrictions == null) 72 return null; 73 return super.getAccessRuleSet(relativePath, containerPath); 74 } 75 public int hashCode() { 76 return JavaWorkspaceScope.class.hashCode(); 77 } 78 public void initialize(int size) { 79 super.initialize(size); 80 try { 81 IJavaProject[] projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects(); 82 for (int i = 0, length = projects.length; i < length; i++) { 83 int includeMask = SOURCES | APPLICATION_LIBRARIES | SYSTEM_LIBRARIES; 84 add((JavaProject) projects[i], null, includeMask, new HashSet (length*2, 1), null); 85 } 86 } catch (JavaModelException ignored) { 87 } 89 this.needsInitialize = false; 90 } 91 public void processDelta(IJavaElementDelta delta) { 92 if (this.needsInitialize) return; 93 IJavaElement element = delta.getElement(); 94 switch (element.getElementType()) { 95 case IJavaElement.JAVA_MODEL: 96 IJavaElementDelta[] children = delta.getAffectedChildren(); 97 for (int i = 0, length = children.length; i < length; i++) { 98 IJavaElementDelta child = children[i]; 99 this.processDelta(child); 100 } 101 break; 102 case IJavaElement.JAVA_PROJECT: 103 int kind = delta.getKind(); 104 switch (kind) { 105 case IJavaElementDelta.ADDED: 106 case IJavaElementDelta.REMOVED: 107 this.needsInitialize = true; 108 break; 109 case IJavaElementDelta.CHANGED: 110 int flags = delta.getFlags(); 111 if ((flags & IJavaElementDelta.F_CLOSED) != 0 112 || (flags & IJavaElementDelta.F_OPENED) != 0) { 113 this.needsInitialize = true; 114 } else { 115 children = delta.getAffectedChildren(); 116 for (int i = 0, length = children.length; i < length; i++) { 117 IJavaElementDelta child = children[i]; 118 this.processDelta(child); 119 } 120 } 121 break; 122 } 123 break; 124 case IJavaElement.PACKAGE_FRAGMENT_ROOT: 125 kind = delta.getKind(); 126 switch (kind) { 127 case IJavaElementDelta.ADDED: 128 case IJavaElementDelta.REMOVED: 129 this.needsInitialize = true; 130 break; 131 case IJavaElementDelta.CHANGED: 132 int flags = delta.getFlags(); 133 if ((flags & IJavaElementDelta.F_ADDED_TO_CLASSPATH) > 0 134 || (flags & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) > 0) { 135 this.needsInitialize = true; 136 } 137 break; 138 } 139 break; 140 } 141 } 142 public String toString() { 143 return "JavaWorkspaceScope"; } 145 } 146 | Popular Tags |