1 11 package org.eclipse.jdt.internal.core.search.indexing; 12 13 import org.eclipse.core.resources.IFile; 14 import org.eclipse.core.resources.IProject; 15 import org.eclipse.core.resources.IResource; 16 import org.eclipse.core.resources.IResourceProxy; 17 import org.eclipse.core.resources.IResourceProxyVisitor; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IPath; 20 import org.eclipse.core.runtime.IProgressMonitor; 21 import org.eclipse.jdt.core.JavaCore; 22 import org.eclipse.jdt.internal.compiler.SourceElementParser; 23 import org.eclipse.jdt.internal.core.index.Index; 24 import org.eclipse.jdt.internal.core.search.processing.JobManager; 25 import org.eclipse.jdt.internal.core.util.Util; 26 27 class AddFolderToIndex extends IndexRequest { 28 IPath folderPath; 29 IProject project; 30 char[][] inclusionPatterns; 31 char[][] exclusionPatterns; 32 33 public AddFolderToIndex(IPath folderPath, IProject project, char[][] inclusionPatterns, char[][] exclusionPatterns, IndexManager manager) { 34 super(project.getFullPath(), manager); 35 this.folderPath = folderPath; 36 this.project = project; 37 this.inclusionPatterns = inclusionPatterns; 38 this.exclusionPatterns = exclusionPatterns; 39 } 40 public boolean execute(IProgressMonitor progressMonitor) { 41 42 if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true; 43 if (!project.isAccessible()) return true; IResource folder = this.project.getParent().findMember(this.folderPath); 45 if (folder == null || folder.getType() == IResource.FILE) return true; 47 48 Index index = this.manager.getIndex(this.containerPath, true, true ); 49 if (index == null) return true; 50 ReadWriteMonitor monitor = index.monitor; 51 if (monitor == null) return true; 53 try { 54 monitor.enterRead(); 56 final IPath container = this.containerPath; 57 final IndexManager indexManager = this.manager; 58 final SourceElementParser parser = indexManager.getSourceElementParser(JavaCore.create(this.project), null); 59 if (this.exclusionPatterns == null && this.inclusionPatterns == null) { 60 folder.accept( 61 new IResourceProxyVisitor() { 62 public boolean visit(IResourceProxy proxy) { 63 if (proxy.getType() == IResource.FILE) { 64 if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(proxy.getName())) 65 indexManager.addSource((IFile) proxy.requestResource(), container, parser); 66 return false; 67 } 68 return true; 69 } 70 }, 71 IResource.NONE 72 ); 73 } else { 74 folder.accept( 75 new IResourceProxyVisitor() { 76 public boolean visit(IResourceProxy proxy) { 77 switch(proxy.getType()) { 78 case IResource.FILE : 79 if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(proxy.getName())) { 80 IResource resource = proxy.requestResource(); 81 if (!Util.isExcluded(resource, inclusionPatterns, exclusionPatterns)) 82 indexManager.addSource((IFile)resource, container, parser); 83 } 84 return false; 85 case IResource.FOLDER : 86 if (exclusionPatterns != null && inclusionPatterns == null) { 87 if (Util.isExcluded(proxy.requestFullPath(), inclusionPatterns, exclusionPatterns, true)) 89 return false; 90 } 91 } 92 return true; 93 } 94 }, 95 IResource.NONE 96 ); 97 } 98 } catch (CoreException e) { 99 if (JobManager.VERBOSE) { 100 Util.verbose("-> failed to add " + this.folderPath + " to index because of the following exception:", System.err); e.printStackTrace(); 102 } 103 return false; 104 } finally { 105 monitor.exitRead(); } 107 return true; 108 } 109 public String toString() { 110 return "adding " + this.folderPath + " to index " + this.containerPath; } 112 } 113 | Popular Tags |