mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Case insensitive searches, bug 293669.
This commit is contained in:
parent
cee26c6a8f
commit
ed2b0017e9
3 changed files with 141 additions and 27 deletions
|
@ -54,6 +54,7 @@ public class IndexSearchTest extends IndexTestBase {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
if (fProject == null) {
|
if (fProject == null) {
|
||||||
|
@ -63,6 +64,7 @@ public class IndexSearchTest extends IndexTestBase {
|
||||||
fIndex.acquireReadLock();
|
fIndex.acquireReadLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
fIndex.releaseReadLock();
|
fIndex.releaseReadLock();
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
|
@ -235,6 +237,39 @@ public class IndexSearchTest extends IndexTestBase {
|
||||||
assertEquals(1, bindings.length);
|
assertEquals(1, bindings.length);
|
||||||
checkIsEnumeration(bindings[0]);
|
checkIsEnumeration(bindings[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testCaseInsensitivePatternSearch_239669() throws CoreException {
|
||||||
|
IIndexBinding[] bindings;
|
||||||
|
|
||||||
|
Pattern pEnumAndEnumeration= Pattern.compile("E20061017", Pattern.CASE_INSENSITIVE);
|
||||||
|
Pattern pEnumeration= Pattern.compile("E20061017");
|
||||||
|
bindings= fIndex.findBindings(pEnumAndEnumeration, true, INDEX_FILTER, NPM);
|
||||||
|
assertEquals(2, bindings.length);
|
||||||
|
bindings= fIndex.findBindings(pEnumeration, true, INDEX_FILTER, NPM);
|
||||||
|
assertEquals(1, bindings.length);
|
||||||
|
|
||||||
|
pEnumAndEnumeration= Pattern.compile("E2006101.*", Pattern.CASE_INSENSITIVE);
|
||||||
|
pEnumeration= Pattern.compile("E2006101.*");
|
||||||
|
bindings= fIndex.findBindings(pEnumAndEnumeration, true, INDEX_FILTER, NPM);
|
||||||
|
assertEquals(2, bindings.length);
|
||||||
|
bindings= fIndex.findBindings(pEnumeration, true, INDEX_FILTER, NPM);
|
||||||
|
assertEquals(1, bindings.length);
|
||||||
|
|
||||||
|
Pattern macro1= Pattern.compile("Foo", Pattern.CASE_INSENSITIVE);
|
||||||
|
Pattern macro2= Pattern.compile("Foo");
|
||||||
|
bindings= fIndex.findMacroContainers(macro1, INDEX_FILTER, NPM);
|
||||||
|
assertEquals(2, bindings.length);
|
||||||
|
bindings= fIndex.findMacroContainers(macro2, INDEX_FILTER, NPM);
|
||||||
|
assertEquals(1, bindings.length);
|
||||||
|
|
||||||
|
macro1= Pattern.compile("Foo.*", Pattern.CASE_INSENSITIVE);
|
||||||
|
macro2= Pattern.compile("Foo.*");
|
||||||
|
bindings= fIndex.findMacroContainers(macro1, INDEX_FILTER, NPM);
|
||||||
|
assertEquals(2, bindings.length);
|
||||||
|
bindings= fIndex.findMacroContainers(macro2, INDEX_FILTER, NPM);
|
||||||
|
assertEquals(1, bindings.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testFindStatic_161216() throws CoreException {
|
public void testFindStatic_161216() throws CoreException {
|
||||||
Pattern pFunc= Pattern.compile("staticFunc20061017");
|
Pattern pFunc= Pattern.compile("staticFunc20061017");
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
#define FOO 1
|
||||||
|
#define Foo(x) 2
|
|
@ -567,26 +567,29 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
return findBindings(new Pattern[] { pattern }, isFullyQualified, filter, monitor);
|
return findBindings(new Pattern[] { pattern }, isFullyQualified, filter, monitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IIndexFragmentBinding[] findBindings(Pattern[] pattern, boolean isFullyQualified, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
|
public IIndexFragmentBinding[] findBindings(Pattern[] patterns, boolean isFullyQualified, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
|
||||||
if (monitor == null) {
|
if (monitor == null) {
|
||||||
monitor= new NullProgressMonitor();
|
monitor= new NullProgressMonitor();
|
||||||
}
|
}
|
||||||
// check for some easy cases
|
// check for some easy cases
|
||||||
char[][] simpleNames= extractSimpleNames(pattern);
|
Boolean caseSensitive= getCaseSensitive(patterns);
|
||||||
if (simpleNames != null) {
|
if (caseSensitive != null) {
|
||||||
if (simpleNames.length == 1) {
|
char[][] simpleNames= extractSimpleNames(patterns);
|
||||||
return findBindings(simpleNames[0], isFullyQualified, filter, monitor);
|
if (simpleNames != null) {
|
||||||
} else if (isFullyQualified) {
|
if (simpleNames.length == 1) {
|
||||||
return findBindings(simpleNames, filter, monitor);
|
return findBindings(simpleNames[0], isFullyQualified, caseSensitive, filter, monitor);
|
||||||
|
} else if (isFullyQualified) {
|
||||||
|
return findBindings(simpleNames, caseSensitive, filter, monitor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char[] prefix= extractPrefix(patterns);
|
||||||
|
if (prefix != null) {
|
||||||
|
return findBindingsForPrefix(prefix, isFullyQualified, caseSensitive, filter, monitor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char[] prefix= extractPrefix(pattern);
|
BindingFinder finder = new BindingFinder(patterns, isFullyQualified, filter, monitor);
|
||||||
if (prefix != null) {
|
|
||||||
return findBindingsForPrefix(prefix, isFullyQualified, filter, monitor);
|
|
||||||
}
|
|
||||||
|
|
||||||
BindingFinder finder = new BindingFinder(pattern, isFullyQualified, filter, monitor);
|
|
||||||
for (PDOMLinkage linkage : getLinkageList()) {
|
for (PDOMLinkage linkage : getLinkageList()) {
|
||||||
if (filter.acceptLinkage(linkage)) {
|
if (filter.acceptLinkage(linkage)) {
|
||||||
try {
|
try {
|
||||||
|
@ -602,6 +605,29 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
return finder.getBindings();
|
return finder.getBindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Boolean getCaseSensitive(Pattern[] patterns) {
|
||||||
|
Boolean caseSensitive= null;
|
||||||
|
for (Pattern p : patterns) {
|
||||||
|
switch(p.flags()) {
|
||||||
|
case 0:
|
||||||
|
if (caseSensitive == Boolean.FALSE) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
caseSensitive= Boolean.TRUE;
|
||||||
|
break;
|
||||||
|
case Pattern.CASE_INSENSITIVE:
|
||||||
|
if (caseSensitive == Boolean.TRUE) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
caseSensitive= Boolean.FALSE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return caseSensitive;
|
||||||
|
}
|
||||||
|
|
||||||
private char[][] extractSimpleNames(Pattern[] pattern) {
|
private char[][] extractSimpleNames(Pattern[] pattern) {
|
||||||
char[][] result= new char[pattern.length][];
|
char[][] result= new char[pattern.length][];
|
||||||
int i= 0;
|
int i= 0;
|
||||||
|
@ -638,6 +664,20 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
if (monitor == null) {
|
if (monitor == null) {
|
||||||
monitor= new NullProgressMonitor();
|
monitor= new NullProgressMonitor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Pattern[] patterns= new Pattern[]{pattern};
|
||||||
|
Boolean caseSensitive= getCaseSensitive(patterns);
|
||||||
|
if (caseSensitive != null) {
|
||||||
|
char[][] simpleNames= extractSimpleNames(patterns);
|
||||||
|
if (simpleNames != null && simpleNames.length == 1) {
|
||||||
|
return findMacroContainers(simpleNames[0], false, caseSensitive, filter, monitor);
|
||||||
|
}
|
||||||
|
char[] prefix= extractPrefix(patterns);
|
||||||
|
if (prefix != null) {
|
||||||
|
return findMacroContainers(prefix, true, caseSensitive, filter, monitor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
List<IIndexFragmentBinding> result= new ArrayList<IIndexFragmentBinding>();
|
List<IIndexFragmentBinding> result= new ArrayList<IIndexFragmentBinding>();
|
||||||
for (PDOMLinkage linkage : getLinkageList()) {
|
for (PDOMLinkage linkage : getLinkageList()) {
|
||||||
if (filter.acceptLinkage(linkage)) {
|
if (filter.acceptLinkage(linkage)) {
|
||||||
|
@ -657,6 +697,10 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IIndexFragmentBinding[] findBindings(char[][] names, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
|
public IIndexFragmentBinding[] findBindings(char[][] names, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
|
||||||
|
return findBindings(names, true, filter, monitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IIndexFragmentBinding[] findBindings(char[][] names, boolean caseSensitive, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
|
||||||
if (names.length == 0) {
|
if (names.length == 0) {
|
||||||
return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
|
return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
|
||||||
}
|
}
|
||||||
|
@ -667,7 +711,7 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
nodes.add(linkage);
|
nodes.add(linkage);
|
||||||
for (int i=0; i < names.length-1; i++) {
|
for (int i=0; i < names.length-1; i++) {
|
||||||
char[] name= names[i];
|
char[] name= names[i];
|
||||||
NamedNodeCollector collector= new NamedNodeCollector(linkage, name, false, true);
|
NamedNodeCollector collector= new NamedNodeCollector(linkage, name, false, caseSensitive);
|
||||||
for (Iterator<PDOMNamedNode> in = nodes.iterator(); in.hasNext();) {
|
for (Iterator<PDOMNamedNode> in = nodes.iterator(); in.hasNext();) {
|
||||||
PDOMNode node= in.next();
|
PDOMNode node= in.next();
|
||||||
node.accept(collector);
|
node.accept(collector);
|
||||||
|
@ -676,7 +720,7 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
nodes.addAll(Arrays.asList(collector.getNodes()));
|
nodes.addAll(Arrays.asList(collector.getNodes()));
|
||||||
}
|
}
|
||||||
char[] name= names[names.length-1];
|
char[] name= names[names.length-1];
|
||||||
BindingCollector collector= new BindingCollector(linkage, name, filter, false, true);
|
BindingCollector collector= new BindingCollector(linkage, name, filter, false, caseSensitive);
|
||||||
for (Iterator<PDOMNamedNode> in = nodes.iterator(); in.hasNext();) {
|
for (Iterator<PDOMNamedNode> in = nodes.iterator(); in.hasNext();) {
|
||||||
PDOMNode node= in.next();
|
PDOMNode node= in.next();
|
||||||
node.accept(collector);
|
node.accept(collector);
|
||||||
|
@ -969,13 +1013,17 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
public File getPath() {
|
public File getPath() {
|
||||||
return fPath;
|
return fPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IIndexFragmentBinding[] findBindingsForPrefix(char[] prefix, boolean filescope, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
|
public IIndexFragmentBinding[] findBindingsForPrefix(char[] prefix, boolean filescope, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
|
||||||
|
return findBindingsForPrefix(prefix, filescope, false, filter, monitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IIndexFragmentBinding[] findBindingsForPrefix(char[] prefix, boolean filescope, boolean caseSensitive, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
|
||||||
ArrayList<IIndexFragmentBinding> result= new ArrayList<IIndexFragmentBinding>();
|
ArrayList<IIndexFragmentBinding> result= new ArrayList<IIndexFragmentBinding>();
|
||||||
for (PDOMLinkage linkage : getLinkageList()) {
|
for (PDOMLinkage linkage : getLinkageList()) {
|
||||||
if (filter.acceptLinkage(linkage)) {
|
if (filter.acceptLinkage(linkage)) {
|
||||||
PDOMBinding[] bindings;
|
PDOMBinding[] bindings;
|
||||||
BindingCollector visitor = new BindingCollector(linkage, prefix, filter, true, false);
|
BindingCollector visitor = new BindingCollector(linkage, prefix, filter, true, caseSensitive);
|
||||||
visitor.setMonitor(monitor);
|
visitor.setMonitor(monitor);
|
||||||
try {
|
try {
|
||||||
linkage.accept(visitor);
|
linkage.accept(visitor);
|
||||||
|
@ -996,22 +1044,34 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IIndexFragmentBinding[] findBindings(char[] name, boolean filescope, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
|
public IIndexFragmentBinding[] findBindings(char[] name, boolean filescope, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
|
||||||
|
return findBindings(name, filescope, true, filter, monitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IIndexFragmentBinding[] findBindings(char[] name, boolean filescope, boolean isCaseSensitive, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
|
||||||
ArrayList<IIndexFragmentBinding> result= new ArrayList<IIndexFragmentBinding>();
|
ArrayList<IIndexFragmentBinding> result= new ArrayList<IIndexFragmentBinding>();
|
||||||
try {
|
try {
|
||||||
for (PDOMLinkage linkage : getLinkageList()) {
|
for (PDOMLinkage linkage : getLinkageList()) {
|
||||||
if (filter.acceptLinkage(linkage)) {
|
if (filter.acceptLinkage(linkage)) {
|
||||||
PDOMBinding[] bindings= linkage.getBindingsViaCache(name, monitor);
|
if (isCaseSensitive) {
|
||||||
for (PDOMBinding binding : bindings) {
|
PDOMBinding[] bindings= linkage.getBindingsViaCache(name, monitor);
|
||||||
if (filter.acceptBinding(binding)) {
|
for (PDOMBinding binding : bindings) {
|
||||||
result.add(binding);
|
if (filter.acceptBinding(binding)) {
|
||||||
|
result.add(binding);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!filescope) {
|
|
||||||
BindingCollector visitor = new BindingCollector(linkage, name, filter, false, true);
|
if (!isCaseSensitive || !filescope) {
|
||||||
|
BindingCollector visitor= new BindingCollector(linkage, name, filter, false, isCaseSensitive);
|
||||||
visitor.setMonitor(monitor);
|
visitor.setMonitor(monitor);
|
||||||
linkage.getNestedBindingsIndex().accept(visitor);
|
|
||||||
|
if (!isCaseSensitive)
|
||||||
bindings= visitor.getBindings();
|
linkage.accept(visitor);
|
||||||
|
|
||||||
|
if (!filescope)
|
||||||
|
linkage.getNestedBindingsIndex().accept(visitor);
|
||||||
|
|
||||||
|
PDOMBinding[] bindings = visitor.getBindings();
|
||||||
for (PDOMBinding binding : bindings) {
|
for (PDOMBinding binding : bindings) {
|
||||||
result.add(binding);
|
result.add(binding);
|
||||||
}
|
}
|
||||||
|
@ -1023,6 +1083,23 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
return result.toArray(new IIndexFragmentBinding[result.size()]);
|
return result.toArray(new IIndexFragmentBinding[result.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IIndexFragmentBinding[] findMacroContainers(char[] prefix, boolean isPrefix, boolean isCaseSensitive, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
|
||||||
|
ArrayList<IIndexFragmentBinding> result= new ArrayList<IIndexFragmentBinding>();
|
||||||
|
try {
|
||||||
|
for (PDOMLinkage linkage : getLinkageList()) {
|
||||||
|
if (filter.acceptLinkage(linkage)) {
|
||||||
|
MacroContainerCollector visitor = new MacroContainerCollector(linkage, prefix, isPrefix, isCaseSensitive);
|
||||||
|
visitor.setMonitor(monitor);
|
||||||
|
linkage.getMacroIndex().accept(visitor);
|
||||||
|
result.addAll(visitor.getMacroList());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException e) {
|
||||||
|
}
|
||||||
|
return result.toArray(new IIndexFragmentBinding[result.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
public IIndexMacro[] findMacros(char[] prefix, boolean isPrefix, boolean isCaseSensitive, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
|
public IIndexMacro[] findMacros(char[] prefix, boolean isPrefix, boolean isCaseSensitive, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
|
||||||
ArrayList<IIndexMacro> result= new ArrayList<IIndexMacro>();
|
ArrayList<IIndexMacro> result= new ArrayList<IIndexMacro>();
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Add table
Reference in a new issue