mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Patch for Bogdan Gheorghe:
Here's a patch that simplifies how workspace scopes are built - instead of getting info from the CModelManager, we go straight to the workspace. This will improve shutdown/search performance.
This commit is contained in:
parent
746563ed2b
commit
f72312491a
2 changed files with 58 additions and 3 deletions
|
@ -14,11 +14,13 @@ package org.eclipse.cdt.internal.core.search;
|
|||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.eclipse.cdt.core.CProjectNature;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.IMember;
|
||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IProjectDescription;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
@ -83,6 +85,53 @@ public class CSearchScope implements ICSearchScope {
|
|||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param project
|
||||
* @param b
|
||||
* @param set
|
||||
*/
|
||||
public void add(IProject project, boolean includesPrereqProjects, HashSet visitedProjects) {
|
||||
|
||||
if (!project.isAccessible() || !visitedProjects.add(project)) return;
|
||||
|
||||
IProjectDescription projDesc = null;
|
||||
try {
|
||||
projDesc = project.getDescription();
|
||||
} catch (CoreException e) {}
|
||||
|
||||
if (projDesc == null)
|
||||
return;
|
||||
|
||||
String[] natures = projDesc.getNatureIds();
|
||||
|
||||
boolean flag = false;
|
||||
for (int i=0; i< natures.length; i++){
|
||||
if (natures[i].equals(CProjectNature.C_NATURE_ID)){
|
||||
flag=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!flag)
|
||||
//CNature not found; not a CDT project
|
||||
return;
|
||||
|
||||
this.addEnclosingProject(project.getFullPath());
|
||||
|
||||
if (includesPrereqProjects){
|
||||
IProject[] refProjects=null;
|
||||
try {
|
||||
refProjects = project.getReferencedProjects();
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
for (int i=0; i<refProjects.length; i++){
|
||||
ICProject cProj= (ICProject)refProjects[i].getAdapter(ICElement.class);
|
||||
if (cProj != null){
|
||||
this.add(cProj, true, visitedProjects);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Adds the given path to this search scope. Remember if subfolders need to be included as well.
|
||||
*/
|
||||
|
|
|
@ -13,10 +13,10 @@ package org.eclipse.cdt.internal.core.search;
|
|||
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICElementDelta;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
public class CWorkspaceScope extends CSearchScope {
|
||||
|
@ -24,10 +24,16 @@ public class CWorkspaceScope extends CSearchScope {
|
|||
protected boolean needsInitialize;
|
||||
|
||||
public boolean encloses(String resourcePath) {
|
||||
//Workspace scope encloses all elements in the workspace -
|
||||
//as long as we add the proper projects to enclosingProjects,
|
||||
//we can return true for all paths
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean encloses(ICElement element) {
|
||||
//Workspace scope encloses all elements in the workspace -
|
||||
//as long as we add the proper projects to enclosingProjects,
|
||||
//we can return true for all paths
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -40,7 +46,7 @@ public class CWorkspaceScope extends CSearchScope {
|
|||
|
||||
public void initialize() {
|
||||
super.initialize();
|
||||
ICProject[] projects = CoreModel.getDefault().getCModel().getCProjects(); // ModelManager ;//.getJavaModelManager().getJavaModel().getJavaProjects();
|
||||
IProject[] projects = CCorePlugin.getWorkspace().getRoot().getProjects();
|
||||
for (int i = 0, length = projects.length; i < length; i++)
|
||||
this.add(projects[i], false, new HashSet(2));
|
||||
this.needsInitialize = false;
|
||||
|
|
Loading…
Add table
Reference in a new issue