mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-06 07:45:50 +02:00
Bug 72741 - add cancel handling for the pattern search and the findBindings routine in the PDOM.
This commit is contained in:
parent
3ddf1a258f
commit
eac22a6a7b
8 changed files with 55 additions and 19 deletions
|
@ -19,8 +19,11 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IField;
|
import org.eclipse.cdt.core.dom.ast.IField;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||||
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
|
@ -37,7 +40,7 @@ public class ClassTests extends PDOMTestBase {
|
||||||
public void test1() throws Exception {
|
public void test1() throws Exception {
|
||||||
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project);
|
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project);
|
||||||
|
|
||||||
IBinding[] Bs = pdom.findBindings(Pattern.compile("B"));
|
IBinding[] Bs = pdom.findBindings(Pattern.compile("B"), new NullProgressMonitor());
|
||||||
assertEquals(1, Bs.length);
|
assertEquals(1, Bs.length);
|
||||||
ICPPClassType B = (ICPPClassType)Bs[0];
|
ICPPClassType B = (ICPPClassType)Bs[0];
|
||||||
ICPPMethod[] Bmethods = B.getAllDeclaredMethods();
|
ICPPMethod[] Bmethods = B.getAllDeclaredMethods();
|
||||||
|
@ -53,7 +56,7 @@ public class ClassTests extends PDOMTestBase {
|
||||||
public void testNested() throws Exception {
|
public void testNested() throws Exception {
|
||||||
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project);
|
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project);
|
||||||
|
|
||||||
IBinding[] bindings = pdom.findBindings(Pattern.compile("NestedA"));
|
IBinding[] bindings = pdom.findBindings(Pattern.compile("NestedA"), new NullProgressMonitor());
|
||||||
assertEquals(1, bindings.length);
|
assertEquals(1, bindings.length);
|
||||||
ICPPClassType NestedA = (ICPPClassType)bindings[0];
|
ICPPClassType NestedA = (ICPPClassType)bindings[0];
|
||||||
ICPPClassType[] nested = NestedA.getNestedClasses();
|
ICPPClassType[] nested = NestedA.getNestedClasses();
|
||||||
|
@ -74,4 +77,18 @@ public class ClassTests extends PDOMTestBase {
|
||||||
loc = refs[0].getFileLocation();
|
loc = refs[0].getFileLocation();
|
||||||
assertEquals(offset(118, 108), loc.getNodeOffset());
|
assertEquals(offset(118, 108), loc.getNodeOffset());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public void failedTest147903() throws Exception {
|
||||||
|
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project);
|
||||||
|
|
||||||
|
IBinding[] bindings = pdom.findBindings(Pattern.compile("pr147903"), new NullProgressMonitor());
|
||||||
|
assertEquals(1, bindings.length);
|
||||||
|
ICPPNamespaceScope ns = ((ICPPNamespace)bindings[0]).getNamespaceScope();
|
||||||
|
bindings = ns.find("testRef");
|
||||||
|
assertEquals(1, bindings.length);
|
||||||
|
IASTName[] refs = pdom.getReferences(bindings[0]);
|
||||||
|
for (int i = 0; i < refs.length; ++i)
|
||||||
|
System.out.println(refs[i].getFileLocation().getNodeOffset());
|
||||||
|
assertEquals(5, refs.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||||
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
|
@ -37,7 +38,7 @@ public class EnumerationTests extends PDOMTestBase {
|
||||||
// Check bindings
|
// Check bindings
|
||||||
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project);
|
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project);
|
||||||
Pattern pattern = Pattern.compile("TestCEnum");
|
Pattern pattern = Pattern.compile("TestCEnum");
|
||||||
IBinding[] bindings = pdom.findBindings(pattern);
|
IBinding[] bindings = pdom.findBindings(pattern, new NullProgressMonitor());
|
||||||
assertEquals(1, bindings.length);
|
assertEquals(1, bindings.length);
|
||||||
IEnumeration enumeration = (IEnumeration)bindings[0];
|
IEnumeration enumeration = (IEnumeration)bindings[0];
|
||||||
assertEquals("TestCEnum", enumeration.getName());
|
assertEquals("TestCEnum", enumeration.getName());
|
||||||
|
@ -70,7 +71,7 @@ public class EnumerationTests extends PDOMTestBase {
|
||||||
// Check bindings
|
// Check bindings
|
||||||
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project);
|
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project);
|
||||||
Pattern pattern = Pattern.compile("TestCPPEnum");
|
Pattern pattern = Pattern.compile("TestCPPEnum");
|
||||||
IBinding[] bindings = pdom.findBindings(pattern);
|
IBinding[] bindings = pdom.findBindings(pattern, new NullProgressMonitor());
|
||||||
assertEquals(1, bindings.length);
|
assertEquals(1, bindings.length);
|
||||||
IEnumeration enumeration = (IEnumeration)bindings[0];
|
IEnumeration enumeration = (IEnumeration)bindings[0];
|
||||||
assertEquals("TestCPPEnum", enumeration.getName());
|
assertEquals("TestCPPEnum", enumeration.getName());
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||||
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
|
@ -40,7 +41,7 @@ public class TypesTests extends PDOMTestBase {
|
||||||
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project);
|
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project);
|
||||||
|
|
||||||
// Get the binding for A::f
|
// Get the binding for A::f
|
||||||
IBinding [] CAs = pdom.findBindings(Pattern.compile("CA"));
|
IBinding [] CAs = pdom.findBindings(Pattern.compile("CA"), new NullProgressMonitor());
|
||||||
assertEquals(1, CAs.length);
|
assertEquals(1, CAs.length);
|
||||||
ICompositeType CA = (ICompositeType)CAs[0];
|
ICompositeType CA = (ICompositeType)CAs[0];
|
||||||
IField [] CAfields = CA.getFields();
|
IField [] CAfields = CA.getFields();
|
||||||
|
@ -59,7 +60,7 @@ public class TypesTests extends PDOMTestBase {
|
||||||
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project);
|
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project);
|
||||||
|
|
||||||
// Get the binding for A::f
|
// Get the binding for A::f
|
||||||
IBinding [] As = pdom.findBindings(Pattern.compile("A"));
|
IBinding [] As = pdom.findBindings(Pattern.compile("A"), new NullProgressMonitor());
|
||||||
assertEquals(1, As.length);
|
assertEquals(1, As.length);
|
||||||
ICPPClassType A = (ICPPClassType)As[0];
|
ICPPClassType A = (ICPPClassType)As[0];
|
||||||
ICPPMethod[] Amethods = A.getMethods();
|
ICPPMethod[] Amethods = A.getMethods();
|
||||||
|
@ -76,7 +77,7 @@ public class TypesTests extends PDOMTestBase {
|
||||||
|
|
||||||
public void test145351() throws Exception {
|
public void test145351() throws Exception {
|
||||||
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project);
|
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project);
|
||||||
IBinding [] bindings = pdom.findBindings(Pattern.compile("spinlock_t"));
|
IBinding [] bindings = pdom.findBindings(Pattern.compile("spinlock_t"), new NullProgressMonitor());
|
||||||
assertEquals(1, bindings.length);
|
assertEquals(1, bindings.length);
|
||||||
ITypedef spinlock_t = (ITypedef)bindings[0];
|
ITypedef spinlock_t = (ITypedef)bindings[0];
|
||||||
IASTName [] refs = pdom.getReferences(spinlock_t);
|
IASTName [] refs = pdom.getReferences(spinlock_t);
|
||||||
|
|
|
@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IAdaptable;
|
import org.eclipse.core.runtime.IAdaptable;
|
||||||
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the reader interface to the PDOM. It is used by general
|
* This is the reader interface to the PDOM. It is used by general
|
||||||
|
@ -32,7 +33,7 @@ public interface IPDOM extends IAdaptable {
|
||||||
* @return
|
* @return
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
public IBinding[] findBindings(Pattern pattern) throws CoreException;
|
public IBinding[] findBindings(Pattern pattern, IProgressMonitor monitor) throws CoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find all bindings whose qualified names match the array of patterns.
|
* Find all bindings whose qualified names match the array of patterns.
|
||||||
|
@ -41,7 +42,7 @@ public interface IPDOM extends IAdaptable {
|
||||||
* @return
|
* @return
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
public IBinding[] findBindings(Pattern[] pattern) throws CoreException;
|
public IBinding[] findBindings(Pattern[] pattern, IProgressMonitor monitor) throws CoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively visit the nodes in this PDOM using the given visitor.
|
* Recursively visit the nodes in this PDOM using the given visitor.
|
||||||
|
|
|
@ -43,7 +43,9 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile.Comparator;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile.Finder;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile.Finder;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.PlatformObject;
|
import org.eclipse.core.runtime.PlatformObject;
|
||||||
|
import org.eclipse.core.runtime.Status;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The PDOM Database.
|
* The PDOM Database.
|
||||||
|
@ -252,17 +254,22 @@ public class PDOM extends PlatformObject
|
||||||
|
|
||||||
private static class BindingFinder implements IPDOMVisitor {
|
private static class BindingFinder implements IPDOMVisitor {
|
||||||
private final Pattern[] pattern;
|
private final Pattern[] pattern;
|
||||||
|
private final IProgressMonitor monitor;
|
||||||
|
|
||||||
private final IBinding[] match;
|
private final IBinding[] match;
|
||||||
private int level = 0;
|
private int level = 0;
|
||||||
private List bindings = new ArrayList();
|
private List bindings = new ArrayList();
|
||||||
|
|
||||||
public BindingFinder(Pattern[] pattern) {
|
public BindingFinder(Pattern[] pattern, IProgressMonitor monitor) {
|
||||||
this.pattern = pattern;
|
this.pattern = pattern;
|
||||||
|
this.monitor = monitor;
|
||||||
match = new IBinding[pattern.length];
|
match = new IBinding[pattern.length];
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean visit(IPDOMNode node) throws CoreException {
|
public boolean visit(IPDOMNode node) throws CoreException {
|
||||||
|
if (monitor.isCanceled())
|
||||||
|
throw new CoreException(Status.OK_STATUS);
|
||||||
|
|
||||||
if (node instanceof IBinding) {
|
if (node instanceof IBinding) {
|
||||||
IBinding binding = (IBinding)node;
|
IBinding binding = (IBinding)node;
|
||||||
if (pattern[level].matcher(binding.getName()).matches()) {
|
if (pattern[level].matcher(binding.getName()).matches()) {
|
||||||
|
@ -292,15 +299,22 @@ public class PDOM extends PlatformObject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBinding[] findBindings(Pattern pattern) throws CoreException {
|
public IBinding[] findBindings(Pattern pattern, IProgressMonitor monitor) throws CoreException {
|
||||||
return findBindings(new Pattern[] { pattern });
|
return findBindings(new Pattern[] { pattern }, monitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBinding[] findBindings(Pattern[] pattern) throws CoreException {
|
public IBinding[] findBindings(Pattern[] pattern, IProgressMonitor monitor) throws CoreException {
|
||||||
BindingFinder finder = new BindingFinder(pattern);
|
BindingFinder finder = new BindingFinder(pattern, monitor);
|
||||||
PDOMLinkage linkage = getFirstLinkage();
|
PDOMLinkage linkage = getFirstLinkage();
|
||||||
while (linkage != null) {
|
while (linkage != null) {
|
||||||
linkage.accept(finder);
|
try {
|
||||||
|
linkage.accept(finder);
|
||||||
|
} catch (CoreException e) {
|
||||||
|
if (e.getStatus() != Status.OK_STATUS)
|
||||||
|
throw e;
|
||||||
|
else
|
||||||
|
return new IBinding[0];
|
||||||
|
}
|
||||||
linkage = linkage.getNextLinkage();
|
linkage = linkage.getNextLinkage();
|
||||||
}
|
}
|
||||||
return finder.getBindings();
|
return finder.getBindings();
|
||||||
|
|
|
@ -54,6 +54,7 @@ import org.eclipse.core.resources.IProjectDescription;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.jface.action.Action;
|
import org.eclipse.jface.action.Action;
|
||||||
import org.eclipse.jface.dialogs.MessageDialog;
|
import org.eclipse.jface.dialogs.MessageDialog;
|
||||||
|
@ -269,7 +270,7 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
|
||||||
for (int n = 0; n < cProjectsToSearch.size(); n++)
|
for (int n = 0; n < cProjectsToSearch.size(); n++)
|
||||||
{
|
{
|
||||||
PDOM pdom = (PDOM)pdomManager.getPDOM((ICProject) cProjectsToSearch.get(n));
|
PDOM pdom = (PDOM)pdomManager.getPDOM((ICProject) cProjectsToSearch.get(n));
|
||||||
IBinding[] bindings = pdom.findBindings(pattern);
|
IBinding[] bindings = pdom.findBindings(pattern, new NullProgressMonitor());
|
||||||
|
|
||||||
for (int i = 0; i < bindings.length; ++i) {
|
for (int i = 0; i < bindings.length; ++i) {
|
||||||
PDOMBinding binding = (PDOMBinding)bindings[i];
|
PDOMBinding binding = (PDOMBinding)bindings[i];
|
||||||
|
|
|
@ -129,7 +129,7 @@ public class PDOMSearchPatternQuery extends PDOMSearchQuery {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
IBinding[] bindings = pdom.findBindings(pattern);
|
IBinding[] bindings = pdom.findBindings(pattern, monitor);
|
||||||
for (int i = 0; i < bindings.length; ++i) {
|
for (int i = 0; i < bindings.length; ++i) {
|
||||||
PDOMBinding pdomBinding = (PDOMBinding)bindings[i];
|
PDOMBinding pdomBinding = (PDOMBinding)bindings[i];
|
||||||
createMatches(pdomBinding.getLinkage().getLanguage(), pdomBinding);
|
createMatches(pdomBinding.getLinkage().getLanguage(), pdomBinding);
|
||||||
|
|
|
@ -48,6 +48,7 @@ import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IAdaptable;
|
import org.eclipse.core.runtime.IAdaptable;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.jface.operation.IRunnableContext;
|
import org.eclipse.jface.operation.IRunnableContext;
|
||||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
|
@ -383,7 +384,7 @@ public class NewClassWizardUtil {
|
||||||
IPDOMManager pdomManager = CCorePlugin.getPDOMManager();
|
IPDOMManager pdomManager = CCorePlugin.getPDOMManager();
|
||||||
try {
|
try {
|
||||||
PDOM pdom = (PDOM)pdomManager.getPDOM(project);
|
PDOM pdom = (PDOM)pdomManager.getPDOM(project);
|
||||||
IBinding[] bindings = pdom.findBindings(Pattern.compile(typeName.getName()));
|
IBinding[] bindings = pdom.findBindings(Pattern.compile(typeName.getName()), new NullProgressMonitor());
|
||||||
boolean sameTypeNameExists = false;
|
boolean sameTypeNameExists = false;
|
||||||
boolean sameNameDifferentTypeExists = false;
|
boolean sameNameDifferentTypeExists = false;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue