mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Patch for Bogdan Gheorghe:
- support for class specifier search - a new C/C++ search menu item.
This commit is contained in:
parent
241ff5cf7f
commit
bcf023a6c8
21 changed files with 1159 additions and 222 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
2003-07-10 Bogdan Gheorghe
|
||||||
|
Added bestTypeDeclarationPrefix to AbstractIndexer to allow the
|
||||||
|
search engine to create a query string for the index.
|
||||||
|
Changed encoding in AbstractIndexer to encode fully qualified names.
|
||||||
|
|
||||||
|
* index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java
|
||||||
|
|
||||||
2003-07-03 Bogdan Gheorghe
|
2003-07-03 Bogdan Gheorghe
|
||||||
Updated copyright notices.
|
Updated copyright notices.
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
package org.eclipse.cdt.internal.core.index.impl;
|
package org.eclipse.cdt.internal.core.index.impl;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.index.IDocument;
|
import org.eclipse.cdt.internal.core.index.IDocument;
|
||||||
import org.eclipse.cdt.internal.core.index.IEntryResult;
|
import org.eclipse.cdt.internal.core.index.IEntryResult;
|
||||||
import org.eclipse.cdt.internal.core.index.IQueryResult;
|
import org.eclipse.cdt.internal.core.index.IQueryResult;
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.index.impl;
|
package org.eclipse.cdt.internal.core.index.impl;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexerOutput;
|
|
||||||
import org.eclipse.cdt.internal.core.index.IDocument;
|
import org.eclipse.cdt.internal.core.index.IDocument;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndexerOutput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An indexerOutput is used by an indexer to add documents and word references to
|
* An indexerOutput is used by an indexer to add documents and word references to
|
||||||
|
|
|
@ -10,9 +10,6 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.search;
|
package org.eclipse.cdt.internal.core.search;
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.MissingResourceException;
|
|
||||||
import java.util.ResourceBundle;
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
@ -20,6 +17,9 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.MissingResourceException;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IContainer;
|
import org.eclipse.core.resources.IContainer;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
|
|
@ -33,17 +33,18 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addClassSpecifier(IASTClassSpecifier classSpecification){
|
public void addClassSpecifier(IASTClassSpecifier classSpecification){
|
||||||
|
|
||||||
if (classSpecification.getClassKind().equals(ASTClassKind.CLASS))
|
if (classSpecification.getClassKind().equals(ASTClassKind.CLASS))
|
||||||
{
|
{
|
||||||
this.output.addRef(encodeTypeEntry(classSpecification.getName().toCharArray(),CLASS));
|
this.output.addRef(encodeTypeEntry(classSpecification.getFullyQualifiedName(),CLASS));
|
||||||
}
|
}
|
||||||
else if (classSpecification.getClassKind().equals(ASTClassKind.STRUCT))
|
else if (classSpecification.getClassKind().equals(ASTClassKind.STRUCT))
|
||||||
{
|
{
|
||||||
this.output.addRef(encodeTypeEntry(classSpecification.getName().toCharArray(),STRUCT));
|
this.output.addRef(encodeTypeEntry(classSpecification.getFullyQualifiedName(),STRUCT));
|
||||||
}
|
}
|
||||||
else if (classSpecification.getClassKind().equals(ASTClassKind.UNION))
|
else if (classSpecification.getClassKind().equals(ASTClassKind.UNION))
|
||||||
{
|
{
|
||||||
this.output.addRef(encodeTypeEntry(classSpecification.getName().toCharArray(),UNION));
|
this.output.addRef(encodeTypeEntry(classSpecification.getFullyQualifiedName(),UNION));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,11 +84,14 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
|
||||||
/**
|
/**
|
||||||
* Type entries are encoded as follow: 'typeDecl/' ('C' | 'S' | 'U' ) '/' TypeName '/'
|
* Type entries are encoded as follow: 'typeDecl/' ('C' | 'S' | 'U' ) '/' TypeName '/'
|
||||||
*/
|
*/
|
||||||
protected static final char[] encodeTypeEntry( char[] typeName, int classType) {
|
protected static final char[] encodeTypeEntry( String [] fullTypeName, int classType) {
|
||||||
|
int pos, nameLength = 0;
|
||||||
int pos;
|
for (int i=0; i<fullTypeName.length; i++){
|
||||||
//3 - 1 for SUFFIX letter, 2 Separators
|
String namePart = fullTypeName[i];
|
||||||
char[] result = new char[TYPE_DECL_LENGTH + typeName.length + 3];
|
nameLength+= namePart.length();
|
||||||
|
}
|
||||||
|
//char[] has to be of size - [type decl length + length of the name + separators + letter]
|
||||||
|
char[] result = new char[TYPE_DECL_LENGTH + nameLength + fullTypeName.length + 1 ];
|
||||||
System.arraycopy(TYPE_DECL, 0, result, 0, pos = TYPE_DECL_LENGTH);
|
System.arraycopy(TYPE_DECL, 0, result, 0, pos = TYPE_DECL_LENGTH);
|
||||||
switch (classType)
|
switch (classType)
|
||||||
{
|
{
|
||||||
|
@ -103,12 +107,22 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
|
||||||
result[pos++] = UNION_SUFFIX;
|
result[pos++] = UNION_SUFFIX;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
result[pos++] = SEPARATOR;
|
result[pos++] = SEPARATOR;
|
||||||
System.arraycopy(typeName, 0, result, pos, typeName.length);
|
//Encode in the following manner
|
||||||
pos += typeName.length;
|
// [typeDecl info]/[typeName]/[qualifiers]
|
||||||
|
if (fullTypeName.length > 0){
|
||||||
|
//Extract the name first
|
||||||
|
char [] tempName = fullTypeName[fullTypeName.length-1].toCharArray();
|
||||||
|
System.arraycopy(tempName, 0, result, pos, tempName.length);
|
||||||
|
pos += tempName.length;
|
||||||
|
}
|
||||||
|
//Extract the qualifiers
|
||||||
|
for (int i=0; i<(fullTypeName.length - 1); i++){
|
||||||
result[pos++] = SEPARATOR;
|
result[pos++] = SEPARATOR;
|
||||||
|
char [] tempName = fullTypeName[i].toCharArray();
|
||||||
|
System.arraycopy(tempName, 0, result, pos, tempName.length);
|
||||||
|
pos+=tempName.length;
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -136,5 +150,74 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Type entries are encoded as follow: 'typeDecl/' ('C' | 'S' | 'U' ) '/' TypeName '/'
|
||||||
|
* Current encoding is optimized for queries: all classes
|
||||||
|
*/
|
||||||
|
public static final char[] bestTypeDeclarationPrefix(char[] typeName, char[][] containingTypes, ASTClassKind classKind, int matchMode, boolean isCaseSensitive) {
|
||||||
|
// index is case sensitive, thus in case attempting case insensitive search, cannot consider
|
||||||
|
// type name.
|
||||||
|
if (!isCaseSensitive){
|
||||||
|
typeName = null;
|
||||||
|
}
|
||||||
|
//Class kind not provided, best we can do
|
||||||
|
if (classKind == null){
|
||||||
|
return TYPE_DECL;
|
||||||
|
}
|
||||||
|
|
||||||
|
char classType=CLASS_SUFFIX;
|
||||||
|
if (classKind == ASTClassKind.STRUCT){
|
||||||
|
classType = STRUCT_SUFFIX;
|
||||||
|
}
|
||||||
|
else if (classKind == ASTClassKind.UNION){
|
||||||
|
classType = UNION_SUFFIX;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(matchMode){
|
||||||
|
case EXACT_MATCH :
|
||||||
|
case PREFIX_MATCH :
|
||||||
|
break;
|
||||||
|
case PATTERN_MATCH :
|
||||||
|
if (typeName != null){
|
||||||
|
int starPos = CharOperation.indexOf('*', typeName);
|
||||||
|
switch(starPos) {
|
||||||
|
case -1 :
|
||||||
|
break;
|
||||||
|
case 0 :
|
||||||
|
typeName = null;
|
||||||
|
break;
|
||||||
|
default :
|
||||||
|
typeName = CharOperation.subarray(typeName, 0, starPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int containingTypesLength=0;
|
||||||
|
int typeLength = typeName == null ? 0 : typeName.length;
|
||||||
|
int pos;
|
||||||
|
//figure out the total length of the qualifiers
|
||||||
|
for (int i=0; i<containingTypes.length; i++){
|
||||||
|
containingTypesLength+= containingTypes[i].length;
|
||||||
|
}
|
||||||
|
//typed decl length + length of qualifiers + qualifier separators + name length + 2 (1 for name separator, 1 for letter)
|
||||||
|
char[] result = new char[TYPE_DECL_LENGTH + containingTypesLength + containingTypes.length + typeLength + 2 ];
|
||||||
|
System.arraycopy(TYPE_DECL, 0, result, 0, pos = TYPE_DECL_LENGTH);
|
||||||
|
result[pos++] = classType;
|
||||||
|
result[pos++] = SEPARATOR;
|
||||||
|
|
||||||
|
if (typeLength > 0){
|
||||||
|
System.arraycopy(typeName, 0, result, pos, typeName.length);
|
||||||
|
pos += typeName.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i=0; i<containingTypes.length; i++){
|
||||||
|
result[pos++] = SEPARATOR;
|
||||||
|
char[] tempName = containingTypes[i];
|
||||||
|
System.arraycopy(tempName, 0, result, pos, tempName.length);
|
||||||
|
pos += tempName.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,10 +13,10 @@ package org.eclipse.cdt.internal.core.search.indexing;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
|
||||||
import org.eclipse.core.runtime.IPath;
|
|
||||||
import org.eclipse.cdt.internal.core.index.IIndex;
|
import org.eclipse.cdt.internal.core.index.IIndex;
|
||||||
import org.eclipse.cdt.internal.core.index.impl.IFileDocument;
|
import org.eclipse.cdt.internal.core.index.impl.IFileDocument;
|
||||||
|
import org.eclipse.core.resources.IFile;
|
||||||
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
|
||||||
public class AddCompilationUnitToIndex extends AddFileToIndex {
|
public class AddCompilationUnitToIndex extends AddFileToIndex {
|
||||||
char[] contents;
|
char[] contents;
|
||||||
|
|
|
@ -12,11 +12,11 @@ package org.eclipse.cdt.internal.core.search.indexing;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndex;
|
||||||
|
import org.eclipse.cdt.internal.core.search.processing.JobManager;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
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.cdt.internal.core.index.IIndex;
|
|
||||||
import org.eclipse.cdt.internal.core.search.processing.JobManager;
|
|
||||||
|
|
||||||
public abstract class AddFileToIndex extends IndexRequest {
|
public abstract class AddFileToIndex extends IndexRequest {
|
||||||
IFile resource;
|
IFile resource;
|
||||||
|
|
|
@ -11,6 +11,9 @@
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.core.search.indexing;
|
package org.eclipse.cdt.internal.core.search.indexing;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndex;
|
||||||
|
import org.eclipse.cdt.internal.core.search.Util;
|
||||||
|
import org.eclipse.cdt.internal.core.search.processing.JobManager;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
@ -19,9 +22,6 @@ import org.eclipse.core.resources.IResourceProxyVisitor;
|
||||||
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.cdt.internal.core.search.Util;
|
|
||||||
import org.eclipse.cdt.internal.core.index.IIndex;
|
|
||||||
import org.eclipse.cdt.internal.core.search.processing.JobManager;
|
|
||||||
|
|
||||||
class AddFolderToIndex extends IndexRequest {
|
class AddFolderToIndex extends IndexRequest {
|
||||||
IPath folderPath;
|
IPath folderPath;
|
||||||
|
|
|
@ -13,14 +13,14 @@ package org.eclipse.cdt.internal.core.search.indexing;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndex;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IQueryResult;
|
||||||
|
import org.eclipse.cdt.internal.core.search.Util;
|
||||||
|
import org.eclipse.cdt.internal.core.search.processing.JobManager;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
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.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.cdt.internal.core.search.Util;
|
|
||||||
import org.eclipse.cdt.internal.core.index.IIndex;
|
|
||||||
import org.eclipse.cdt.internal.core.index.IQueryResult;
|
|
||||||
import org.eclipse.cdt.internal.core.search.processing.JobManager;
|
|
||||||
|
|
||||||
class RemoveFolderFromIndex extends IndexRequest {
|
class RemoveFolderFromIndex extends IndexRequest {
|
||||||
IPath folderPath;
|
IPath folderPath;
|
||||||
|
|
|
@ -1,7 +1,38 @@
|
||||||
|
2003-07-10 Bogdan Gheorghe
|
||||||
|
Provided implementation for ICSearchScope.java, CSearchScope.java
|
||||||
|
|
||||||
|
Hooked up new CWorkspaceScope, PathCollector, PatternSearchJob in SearchEngine.java
|
||||||
|
|
||||||
|
Provided implementation for PatternSearchJob.java - PatternSearchJob is where the first part
|
||||||
|
of the search occurs - using an IndexSelector to filter the indexes, it gets the indexes from
|
||||||
|
the IndexManager and then uses the passed in pattern to find the index matched. Once it finds
|
||||||
|
an index match it adds the file path to the PathCollector.
|
||||||
|
|
||||||
|
Modified CSearchPattern - added support to find index entries.
|
||||||
|
|
||||||
|
Modified ClassDeclarationPattern - added support to decode, match and report
|
||||||
|
index entries.
|
||||||
|
|
||||||
|
|
||||||
|
Added:
|
||||||
|
* search/org/eclipse/cdt/internal/core/search/CWorkspaceScope.java
|
||||||
|
* search/org/eclipse/cdt/internal/core/search/IIndexSearchRequestor.java
|
||||||
|
* search/org/eclipse/cdt/internal/core/search/IndexSelector.java
|
||||||
|
* search/org/eclipse/cdt/internal/core/search/PathCollector.java
|
||||||
|
|
||||||
|
Modified:
|
||||||
|
* search/org/eclipse/cdt/core/search/ICSearchScope.java
|
||||||
|
* search/org/eclipse/cdt/core/search/SearchEngine.java
|
||||||
|
* search/org/eclipse/cdt/internal/core/search/CSearchScope.java
|
||||||
|
* search/org/eclipse/cdt/internal/core/search/PatternSearchJob.java
|
||||||
|
* search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java
|
||||||
|
* search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java
|
||||||
|
|
||||||
2003-07-04 Andrew Niefer
|
2003-07-04 Andrew Niefer
|
||||||
* Modified ICSearchConstants to use new nested classes SearchFor and LimitTo instead of int
|
Modified ICSearchConstants to use new nested classes SearchFor and LimitTo instead of int
|
||||||
for stronger type safety
|
for stronger type safety
|
||||||
* Updated MatchLocator to invoke parser to do actual search.
|
|
||||||
|
Updated MatchLocator to invoke parser to do actual search.
|
||||||
|
|
||||||
2003-06-27 Andrew Niefer
|
2003-06-27 Andrew Niefer
|
||||||
Modified:
|
Modified:
|
||||||
|
@ -18,9 +49,7 @@ Modified:
|
||||||
search/org.eclipse.cdt.core.search/SearchEngine.java
|
search/org.eclipse.cdt.core.search/SearchEngine.java
|
||||||
|
|
||||||
2003-06-25 Bogdan Gheorghe
|
2003-06-25 Bogdan Gheorghe
|
||||||
|
|
||||||
Modified:
|
Modified:
|
||||||
|
|
||||||
* search/org/eclipse/cdt/core/search/ICSearchConstants.java
|
* search/org/eclipse/cdt/core/search/ICSearchConstants.java
|
||||||
* search/org/eclipse/cdt/internal/core/search/Utils.java
|
* search/org/eclipse/cdt/internal/core/search/Utils.java
|
||||||
- moved to index/org/eclipse/cdt/internal/core/search/Utils.java
|
- moved to index/org/eclipse/cdt/internal/core/search/Utils.java
|
||||||
|
|
|
@ -1,24 +1,46 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2003 IBM Corporation and others.
|
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Common Public License v0.5
|
* are made available under the terms of the Common Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/cpl-v05.html
|
* http://www.eclipse.org/legal/cpl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corp. - Rational Software - initial implementation
|
* IBM Corporation - initial API and implementation
|
||||||
******************************************************************************/
|
*******************************************************************************/
|
||||||
/*
|
/*
|
||||||
* Created on Jun 12, 2003
|
* Created on Jun 12, 2003
|
||||||
*/
|
*/
|
||||||
package org.eclipse.cdt.core.search;
|
package org.eclipse.cdt.core.search;
|
||||||
|
|
||||||
/**
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
* @author aniefer
|
import org.eclipse.core.runtime.IPath;
|
||||||
*
|
|
||||||
* To change the template for this generated type comment go to
|
|
||||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
|
||||||
*/
|
|
||||||
public interface ICSearchScope {
|
public interface ICSearchScope {
|
||||||
|
/**
|
||||||
|
* Checks whether the resource at the given path is enclosed by this scope.
|
||||||
|
*
|
||||||
|
* @param resourcePath if the resource is contained in
|
||||||
|
* @return whether the resource is enclosed by this scope
|
||||||
|
*/
|
||||||
|
public boolean encloses(String resourcePath);
|
||||||
|
/**
|
||||||
|
* Checks whether this scope encloses the given element.
|
||||||
|
*
|
||||||
|
* @param element the given element
|
||||||
|
* @return <code>true</code> if the element is in this scope
|
||||||
|
*/
|
||||||
|
public boolean encloses(ICElement element);
|
||||||
|
/**
|
||||||
|
* Returns the paths to the enclosing projects for this search scope.
|
||||||
|
* <ul>
|
||||||
|
* <li> If the path is a project path, this is the full path of the project
|
||||||
|
* (see <code>IResource.getFullPath()</code>).
|
||||||
|
* For example, /MyProject
|
||||||
|
* </li>
|
||||||
|
*
|
||||||
|
* @return an array of paths to the enclosing projects.
|
||||||
|
*/
|
||||||
|
IPath[] enclosingProjects();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +1,26 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2003 IBM Corporation and others.
|
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Common Public License v0.5
|
* are made available under the terms of the Common Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/cpl-v05.html
|
* http://www.eclipse.org/legal/cpl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corp. - Rational Software - initial implementation
|
* IBM Corporation - initial API and implementation
|
||||||
******************************************************************************/
|
*******************************************************************************/
|
||||||
/*
|
/*
|
||||||
* Created on Jun 11, 2003
|
* Created on Jun 11, 2003
|
||||||
*/
|
*/
|
||||||
package org.eclipse.cdt.core.search;
|
package org.eclipse.cdt.core.search;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
|
|
||||||
import org.eclipse.cdt.internal.core.model.CModelManager;
|
import org.eclipse.cdt.internal.core.model.CModelManager;
|
||||||
|
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
|
||||||
|
import org.eclipse.cdt.internal.core.search.CWorkspaceScope;
|
||||||
|
import org.eclipse.cdt.internal.core.search.PathCollector;
|
||||||
import org.eclipse.cdt.internal.core.search.PatternSearchJob;
|
import org.eclipse.cdt.internal.core.search.PatternSearchJob;
|
||||||
import org.eclipse.cdt.internal.core.search.Util;
|
import org.eclipse.cdt.internal.core.search.Util;
|
||||||
|
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
|
||||||
import org.eclipse.cdt.internal.core.search.matching.CSearchPattern;
|
import org.eclipse.cdt.internal.core.search.matching.CSearchPattern;
|
||||||
import org.eclipse.cdt.internal.core.search.matching.MatchLocator;
|
import org.eclipse.cdt.internal.core.search.matching.MatchLocator;
|
||||||
import org.eclipse.core.resources.IWorkspace;
|
import org.eclipse.core.resources.IWorkspace;
|
||||||
|
@ -35,6 +38,12 @@ public class SearchEngine implements ICSearchConstants{
|
||||||
|
|
||||||
private boolean VERBOSE = false;
|
private boolean VERBOSE = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A list of working copies that take precedence over their original
|
||||||
|
* compilation units.
|
||||||
|
*/
|
||||||
|
private IWorkingCopy[] workingCopies = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -43,12 +52,16 @@ public class SearchEngine implements ICSearchConstants{
|
||||||
// TODO Auto-generated constructor stub
|
// TODO Auto-generated constructor stub
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SearchEngine(IWorkingCopy[] workingCopies) {
|
||||||
|
this.workingCopies = workingCopies;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static ICSearchScope createWorkspaceScope() {
|
public static ICSearchScope createWorkspaceScope() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return new CWorkspaceScope();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,13 +110,21 @@ public class SearchEngine implements ICSearchConstants{
|
||||||
progressMonitor.beginTask( Util.bind("engine.searching"), 100 ); //$NON_NLS-1$
|
progressMonitor.beginTask( Util.bind("engine.searching"), 100 ); //$NON_NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* index search */
|
||||||
|
PathCollector pathCollector = new PathCollector();
|
||||||
|
|
||||||
CModelManager modelManager = CModelManager.getDefault();
|
CModelManager modelManager = CModelManager.getDefault();
|
||||||
IndexManager indexManager = modelManager.getIndexManager();
|
IndexManager indexManager = modelManager.getIndexManager();
|
||||||
|
|
||||||
SubProgressMonitor subMonitor = (progressMonitor == null ) ? null : new SubProgressMonitor( progressMonitor, 5 );
|
SubProgressMonitor subMonitor = (progressMonitor == null ) ? null : new SubProgressMonitor( progressMonitor, 5 );
|
||||||
|
|
||||||
indexManager.performConcurrentJob(
|
indexManager.performConcurrentJob(
|
||||||
new PatternSearchJob(),
|
new PatternSearchJob(
|
||||||
|
(CSearchPattern) pattern,
|
||||||
|
scope,
|
||||||
|
pathCollector,
|
||||||
|
indexManager
|
||||||
|
),
|
||||||
ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
|
ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
|
||||||
subMonitor );
|
subMonitor );
|
||||||
|
|
||||||
|
@ -114,7 +135,8 @@ public class SearchEngine implements ICSearchConstants{
|
||||||
if( progressMonitor != null && progressMonitor.isCanceled() )
|
if( progressMonitor != null && progressMonitor.isCanceled() )
|
||||||
throw new OperationCanceledException();
|
throw new OperationCanceledException();
|
||||||
|
|
||||||
//matchLocator.locateMatches( pathCollector.getPaths(), workspace, workingCopies );
|
//TODO: BOG Filter Working Copies...
|
||||||
|
matchLocator.locateMatches( pathCollector.getPaths(), workspace, this.workingCopies);
|
||||||
} finally {
|
} finally {
|
||||||
collector.done();
|
collector.done();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,34 +1,152 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2003 IBM Corporation and others.
|
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Common Public License v0.5
|
* are made available under the terms of the Common Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/cpl-v05.html
|
* http://www.eclipse.org/legal/cpl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corp. - Rational Software - initial implementation
|
* IBM Corporation - initial API and implementation
|
||||||
******************************************************************************/
|
*******************************************************************************/
|
||||||
/*
|
|
||||||
* Created on Jun 12, 2003
|
|
||||||
*/
|
|
||||||
package org.eclipse.cdt.internal.core.search;
|
package org.eclipse.cdt.internal.core.search;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||||
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
import org.eclipse.core.runtime.Path;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author aniefer
|
|
||||||
*
|
|
||||||
* To change the template for this generated type comment go to
|
|
||||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
|
||||||
*/
|
|
||||||
public class CSearchScope implements ICSearchScope {
|
public class CSearchScope implements ICSearchScope {
|
||||||
|
|
||||||
/**
|
private ArrayList elements;
|
||||||
*
|
|
||||||
*/
|
/* The paths of the resources in this search scope*/
|
||||||
|
private IPath[] paths;
|
||||||
|
private boolean[] pathWithSubFolders;
|
||||||
|
private int pathsCount;
|
||||||
|
|
||||||
|
private IPath[] enclosingProjects;
|
||||||
|
|
||||||
public CSearchScope() {
|
public CSearchScope() {
|
||||||
super();
|
super();
|
||||||
// TODO Auto-generated constructor stub
|
this.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void initialize() {
|
||||||
|
this.paths = new IPath[1];
|
||||||
|
this.pathWithSubFolders = new boolean[1];
|
||||||
|
this.pathsCount = 0;
|
||||||
|
this.enclosingProjects = new IPath[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addEnclosingProject(IPath path) {
|
||||||
|
int length = this.enclosingProjects.length;
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
if (this.enclosingProjects[i].equals(path)) return;
|
||||||
|
}
|
||||||
|
System.arraycopy(
|
||||||
|
this.enclosingProjects,
|
||||||
|
0,
|
||||||
|
this.enclosingProjects = new IPath[length+1],
|
||||||
|
0,
|
||||||
|
length);
|
||||||
|
this.enclosingProjects[length] = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(ICProject cProject, boolean includesPrereqProjects, HashSet visitedProjects) {
|
||||||
|
IProject project = cProject.getProject();
|
||||||
|
if (!project.isAccessible() || !visitedProjects.add(project)) return;
|
||||||
|
|
||||||
|
this.addEnclosingProject(project.getFullPath());
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Adds the given path to this search scope. Remember if subfolders need to be included as well.
|
||||||
|
*/
|
||||||
|
private void add(IPath path, boolean withSubFolders) {
|
||||||
|
if (this.paths.length == this.pathsCount) {
|
||||||
|
System.arraycopy(
|
||||||
|
this.paths,
|
||||||
|
0,
|
||||||
|
this.paths = new IPath[this.pathsCount * 2],
|
||||||
|
0,
|
||||||
|
this.pathsCount);
|
||||||
|
System.arraycopy(
|
||||||
|
this.pathWithSubFolders,
|
||||||
|
0,
|
||||||
|
this.pathWithSubFolders = new boolean[this.pathsCount * 2],
|
||||||
|
0,
|
||||||
|
this.pathsCount);
|
||||||
|
}
|
||||||
|
this.paths[this.pathsCount] = path;
|
||||||
|
this.pathWithSubFolders[this.pathsCount++] = withSubFolders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean encloses(String resourcePathString) {
|
||||||
|
IPath resourcePath;
|
||||||
|
int separatorIndex = -1; //resourcePathString.indexOf(JAR_FILE_ENTRY_SEPARATOR);
|
||||||
|
if (separatorIndex != -1) {
|
||||||
|
resourcePath =
|
||||||
|
new Path(resourcePathString.substring(0, separatorIndex)).
|
||||||
|
append(new Path(resourcePathString.substring(separatorIndex+1)));
|
||||||
|
} else {
|
||||||
|
resourcePath = new Path(resourcePathString);
|
||||||
|
}
|
||||||
|
return this.encloses(resourcePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether this search scope encloses the given path.
|
||||||
|
*/
|
||||||
|
private boolean encloses(IPath path) {
|
||||||
|
for (int i = 0; i < this.pathsCount; i++) {
|
||||||
|
if (this.pathWithSubFolders[i]) {
|
||||||
|
if (this.paths[i].isPrefixOf(path)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// if not looking at subfolders, this scope encloses the given path
|
||||||
|
// if this path is a direct child of the scope's ressource
|
||||||
|
// or if this path is the scope's resource (see bug 13919 Declaration for package not found if scope is not project)
|
||||||
|
IPath scopePath = this.paths[i];
|
||||||
|
if (scopePath.isPrefixOf(path)
|
||||||
|
&& ((scopePath.segmentCount() == path.segmentCount() - 1)
|
||||||
|
|| (scopePath.segmentCount() == path.segmentCount()))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean encloses(ICElement element) {
|
||||||
|
if (this.elements != null) {
|
||||||
|
for (int i = 0, length = this.elements.size(); i < length; i++) {
|
||||||
|
ICElement scopeElement = (ICElement)this.elements.get(i);
|
||||||
|
ICElement searchedElement = element;
|
||||||
|
while (searchedElement != null) {
|
||||||
|
if (searchedElement.equals(scopeElement)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
searchedElement = searchedElement.getParent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return this.encloses(this.fullPath(element));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IPath[] enclosingProjects() {
|
||||||
|
return this.enclosingProjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IPath fullPath(ICElement element) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM Corporation - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
package org.eclipse.cdt.internal.core.search;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
|
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.runtime.IPath;
|
||||||
|
|
||||||
|
public class CWorkspaceScope extends CSearchScope {
|
||||||
|
|
||||||
|
protected boolean needsInitialize;
|
||||||
|
|
||||||
|
public boolean encloses(String resourcePath) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean encloses(ICElement element) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IPath[] enclosingProjects() {
|
||||||
|
if (this.needsInitialize) {
|
||||||
|
this.initialize();
|
||||||
|
}
|
||||||
|
return super.enclosingProjects();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initialize() {
|
||||||
|
super.initialize();
|
||||||
|
ICProject[] projects = CoreModel.getDefault().getCModel().getCProjects(); // ModelManager ;//.getJavaModelManager().getJavaModel().getJavaProjects();
|
||||||
|
for (int i = 0, length = projects.length; i < length; i++)
|
||||||
|
this.add(projects[i], false, new HashSet(2));
|
||||||
|
this.needsInitialize = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void processDelta(ICElementDelta delta) {
|
||||||
|
//TODO: BOG Hook this up to the model manager to give us updates when the workspace changes
|
||||||
|
// if (this.needsInitialize) return;
|
||||||
|
// ICElement element = delta.getElement();
|
||||||
|
// switch (element.getElementType()) {
|
||||||
|
// case ICElement.C_MODEL:
|
||||||
|
// ICElementDelta[] children = delta.getAffectedChildren();
|
||||||
|
// for (int i = 0, length = children.length; i < length; i++) {
|
||||||
|
// ICElementDelta child = children[i];
|
||||||
|
// this.processDelta(child);
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
// case ICElement.C_PROJECT:
|
||||||
|
// int kind = delta.getKind();
|
||||||
|
// switch (kind) {
|
||||||
|
// case ICElementDelta.ADDED:
|
||||||
|
// case ICElementDelta.REMOVED:
|
||||||
|
// this.needsInitialize = true;
|
||||||
|
// break;
|
||||||
|
// case ICElementDelta.CHANGED:
|
||||||
|
// children = delta.getAffectedChildren();
|
||||||
|
// for (int i = 0, length = children.length; i < length; i++) {
|
||||||
|
// ICElementDelta child = children[i];
|
||||||
|
// this.processDelta(child);
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "CWorkspaceScope"; //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM Corporation - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.core.search;
|
||||||
|
|
||||||
|
public interface IIndexSearchRequestor {
|
||||||
|
/**
|
||||||
|
* Accepts the declaration of a class in the compilation unit with the given resource path.
|
||||||
|
* The class is declared in the given package and with the given type name.
|
||||||
|
* <p>
|
||||||
|
* Note that the resource path can be null if the search query doesn't require it (eg. get all class names).
|
||||||
|
*/
|
||||||
|
void acceptClassDeclaration(String resourcePath, char[] simpleTypeName, char[][] enclosingTypeNames);
|
||||||
|
/**
|
||||||
|
* Accepts the declaration of a constructor in the compilation unit with the given resource path.
|
||||||
|
* The constructor is declared with a given name and number of arguments.
|
||||||
|
*/
|
||||||
|
void acceptConstructorDeclaration(String resourcePath, char[] typeName, int parameterCount);
|
||||||
|
/**
|
||||||
|
* Accepts the reference to a constructor in the compilation unit with the given resource path.
|
||||||
|
* The constructor is referenced using the given name and a number of arguments.
|
||||||
|
*
|
||||||
|
* Note that the resource path can be null if the search query doesn't require it.
|
||||||
|
*/
|
||||||
|
void acceptConstructorReference(String resourcePath, char[] typeName, int parameterCount);
|
||||||
|
/**
|
||||||
|
* Accepts the declaration of a field in the compilation unit with the given resource path.
|
||||||
|
* <p>
|
||||||
|
* Note that the resource path can be null if the search query doesn't require it (eg. get all class names).
|
||||||
|
* Likewise, the declaring package name and the declaring type names if the query doesn't require them.
|
||||||
|
*/
|
||||||
|
void acceptFieldDeclaration(String resourcePath, char[] fieldName);
|
||||||
|
/**
|
||||||
|
* Accepts the reference to a field in the compilation unit with the given resource path.
|
||||||
|
* The field is referenced using the given name
|
||||||
|
*/
|
||||||
|
void acceptFieldReference(String resourcePath, char[] fieldName);
|
||||||
|
/**
|
||||||
|
* Accepts the declaration of a method in the compilation unit with the given resource path.
|
||||||
|
* The method is declared with a given method name and number of arguments.
|
||||||
|
*/
|
||||||
|
void acceptMethodDeclaration(String resourcePath, char[] methodName, int parameterCount);
|
||||||
|
/**
|
||||||
|
* Accepts the reference to a method in the compilation unit with the given resource path.
|
||||||
|
* The method is referenced using the given selector and a number of arguments.
|
||||||
|
*
|
||||||
|
* Note that the resource path can be null if the search query doesn't require it.
|
||||||
|
*/
|
||||||
|
void acceptMethodReference(String resourcePath, char[] methodName, int parameterCount);
|
||||||
|
/**
|
||||||
|
* Accepts the reference to a supertype in the compilation unit with the given resource path.
|
||||||
|
* Note that the resource path and/or the package name can be null.
|
||||||
|
*/
|
||||||
|
void acceptSuperTypeReference(String resourcePath, char[] qualification, char[] typeName, char[] enclosingTypeName, char classOrInterface, char[] superQualification, char[] superTypeName, char superClassOrInterface, int modifiers);
|
||||||
|
/**
|
||||||
|
* Accepts the reference to a class in the compilation unit with the given resource path.
|
||||||
|
* The class is referenced using the given type name.
|
||||||
|
* <p>
|
||||||
|
* Note that the resource path can be null if the search query doesn't require it.
|
||||||
|
*/
|
||||||
|
void acceptTypeReference(String resourcePath, char[] typeName);
|
||||||
|
}
|
|
@ -0,0 +1,118 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM Corporation - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.core.search;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
import org.eclipse.cdt.core.model.ICModel;
|
||||||
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndex;
|
||||||
|
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
|
||||||
|
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||||
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Selects the indexes that correspond to projects in a given search scope
|
||||||
|
* and that are dependent on a given focus element.
|
||||||
|
*/
|
||||||
|
public class IndexSelector {
|
||||||
|
ICSearchScope searchScope;
|
||||||
|
ICElement focus;
|
||||||
|
IndexManager indexManager;
|
||||||
|
IPath[] indexKeys; // cache of the keys for looking index up
|
||||||
|
boolean isPolymorphicSearch;
|
||||||
|
public IndexSelector(
|
||||||
|
ICSearchScope searchScope,
|
||||||
|
ICElement focus,
|
||||||
|
boolean isPolymorphicSearch,
|
||||||
|
IndexManager indexManager) {
|
||||||
|
this.searchScope = searchScope;
|
||||||
|
this.focus = focus;
|
||||||
|
this.indexManager = indexManager;
|
||||||
|
this.isPolymorphicSearch = isPolymorphicSearch;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Returns whether elements of the given project can see the given focus (an ICProject)
|
||||||
|
*/
|
||||||
|
public static boolean canSeeFocus(ICElement focus, boolean isPolymorphicSearch, IPath projectPath) {
|
||||||
|
//TODO: BOG Temp - Provide Proper Impl
|
||||||
|
ICModel model = focus.getCModel();
|
||||||
|
ICProject project = getCProject(projectPath, model);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Compute the list of paths which are keying index files.
|
||||||
|
*/
|
||||||
|
private void initializeIndexKeys() {
|
||||||
|
|
||||||
|
ArrayList requiredIndexKeys = new ArrayList();
|
||||||
|
IPath[] projects = this.searchScope.enclosingProjects();
|
||||||
|
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
|
||||||
|
ICElement projectFocus = this.focus == null ? null : getProject(this.focus);
|
||||||
|
for (int i = 0; i < projects.length; i++) {
|
||||||
|
IPath location;
|
||||||
|
IPath path = projects[i];
|
||||||
|
if ((!root.getProject(path.lastSegment()).exists()) // if project does not exist
|
||||||
|
&& path.segmentCount() > 1
|
||||||
|
&& ((location = root.getFile(path).getLocation()) == null
|
||||||
|
|| !new java.io.File(location.toOSString()).exists()) // and internal jar file does not exist
|
||||||
|
&& !new java.io.File(path.toOSString()).exists()) { // and external jar file does not exist
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (projectFocus == null || canSeeFocus(projectFocus, this.isPolymorphicSearch, path)) {
|
||||||
|
if (requiredIndexKeys.indexOf(path) == -1) {
|
||||||
|
requiredIndexKeys.add(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.indexKeys = new IPath[requiredIndexKeys.size()];
|
||||||
|
requiredIndexKeys.toArray(this.indexKeys);
|
||||||
|
}
|
||||||
|
public IIndex[] getIndexes() {
|
||||||
|
if (this.indexKeys == null) {
|
||||||
|
this.initializeIndexKeys();
|
||||||
|
}
|
||||||
|
// acquire the in-memory indexes on the fly
|
||||||
|
int length = this.indexKeys.length;
|
||||||
|
IIndex[] indexes = new IIndex[length];
|
||||||
|
int count = 0;
|
||||||
|
for (int i = 0; i < length; i++){
|
||||||
|
// may trigger some index recreation work
|
||||||
|
IIndex index = indexManager.getIndex(indexKeys[i], true /*reuse index file*/, false /*do not create if none*/);
|
||||||
|
if (index != null) indexes[count++] = index; // only consider indexes which are ready yet
|
||||||
|
}
|
||||||
|
if (count != length) {
|
||||||
|
System.arraycopy(indexes, 0, indexes=new IIndex[count], 0, count);
|
||||||
|
}
|
||||||
|
return indexes;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Returns the project that corresponds to the given path.
|
||||||
|
* Returns null if the path doesn't correspond to a project.
|
||||||
|
*/
|
||||||
|
private static ICProject getCProject(IPath path, ICModel model) {
|
||||||
|
ICProject project = model.getCProject(path.lastSegment());
|
||||||
|
if (project.exists()) {
|
||||||
|
return project;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static ICElement getProject(ICElement element) {
|
||||||
|
while (!(element instanceof ICProject)) {
|
||||||
|
element = element.getParent();
|
||||||
|
}
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,131 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM Corporation - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.core.search;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import org.eclipse.core.resources.IFile;
|
||||||
|
import org.eclipse.core.resources.IWorkspace;
|
||||||
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
import org.eclipse.core.runtime.Path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collects the resource paths reported by a client to this search requestor.
|
||||||
|
*/
|
||||||
|
public class PathCollector implements IIndexSearchRequestor {
|
||||||
|
|
||||||
|
/* a set of resource paths */
|
||||||
|
public HashSet paths = new HashSet(5);
|
||||||
|
/**
|
||||||
|
* @see IIndexSearchRequestor
|
||||||
|
*/
|
||||||
|
public void acceptClassDeclaration(String resourcePath, char[] simpleTypeName, char[][] enclosingTypeNames) {
|
||||||
|
this.paths.add( resourcePath);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @see IIndexSearchRequestor
|
||||||
|
*/
|
||||||
|
public void acceptConstructorDeclaration(String resourcePath, char[] typeName, int parameterCount) {
|
||||||
|
|
||||||
|
this.paths.add(resourcePath);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @see IIndexSearchRequestor
|
||||||
|
*/
|
||||||
|
public void acceptConstructorReference(String resourcePath, char[] typeName, int parameterCount) {
|
||||||
|
|
||||||
|
this.paths.add(resourcePath);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @see IIndexSearchRequestor
|
||||||
|
*/
|
||||||
|
public void acceptFieldDeclaration(String resourcePath, char[] fieldName) {
|
||||||
|
this.paths.add(resourcePath);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @see IIndexSearchRequestor
|
||||||
|
*/
|
||||||
|
public void acceptFieldReference(String resourcePath, char[] fieldName) {
|
||||||
|
|
||||||
|
this.paths.add(resourcePath);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @see IIndexSearchRequestor
|
||||||
|
*/
|
||||||
|
public void acceptInterfaceDeclaration(String resourcePath, char[] simpleTypeName, char[][] enclosingTypeNames, char[] packageName) {
|
||||||
|
|
||||||
|
this.paths.add(resourcePath);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @see IIndexSearchRequestor
|
||||||
|
*/
|
||||||
|
public void acceptMethodDeclaration(String resourcePath, char[] methodName, int parameterCount) {
|
||||||
|
|
||||||
|
this.paths.add(resourcePath);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @see IIndexSearchRequestor
|
||||||
|
*/
|
||||||
|
public void acceptMethodReference(String resourcePath, char[] methodName, int parameterCount) {
|
||||||
|
|
||||||
|
this.paths.add(resourcePath);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @see IIndexSearchRequestor
|
||||||
|
*/
|
||||||
|
public void acceptPackageReference(String resourcePath, char[] packageName) {
|
||||||
|
|
||||||
|
this.paths.add(resourcePath);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @see IIndexSearchRequestor
|
||||||
|
*/
|
||||||
|
public void acceptSuperTypeReference(String resourcePath, char[] qualification, char[] typeName, char[] enclosingTypeName, char classOrInterface, char[] superQualification, char[] superTypeName, char superClassOrInterface, int modifiers) {
|
||||||
|
this.paths.add(resourcePath);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @see IIndexSearchRequestor
|
||||||
|
*/
|
||||||
|
public void acceptSuperTypeReference(String resourcePath, char[] qualification, char[] typeName, char classOrInterface, char[] superQualification, char[] superTypeName, char superClassOrInterface, int modifiers) {
|
||||||
|
this.paths.add(resourcePath);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @see IIndexSearchRequestor
|
||||||
|
*/
|
||||||
|
public void acceptTypeReference(String resourcePath, char[] typeName) {
|
||||||
|
this.paths.add(resourcePath);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Returns the files that correspond to the paths that have been collected.
|
||||||
|
*/
|
||||||
|
public IFile[] getFiles(IWorkspace workspace) {
|
||||||
|
IFile[] result = new IFile[this.paths.size()];
|
||||||
|
int i = 0;
|
||||||
|
for (Iterator iter = this.paths.iterator(); iter.hasNext();) {
|
||||||
|
String resourcePath = (String)iter.next();
|
||||||
|
IPath path = new Path(resourcePath);
|
||||||
|
result[i++] = workspace.getRoot().getFile(path);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Returns the paths that have been collected.
|
||||||
|
*/
|
||||||
|
public String[] getPaths() {
|
||||||
|
String[] result = new String[this.paths.size()];
|
||||||
|
int i = 0;
|
||||||
|
for (Iterator iter = this.paths.iterator(); iter.hasNext();) {
|
||||||
|
result[i++] = (String)iter.next();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,67 +1,168 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2003 IBM Corporation and others.
|
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Common Public License v0.5
|
* are made available under the terms of the Common Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/cpl-v05.html
|
* http://www.eclipse.org/legal/cpl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corp. - Rational Software - initial implementation
|
* IBM Corporation - initial API and implementation
|
||||||
******************************************************************************/
|
*******************************************************************************/
|
||||||
/*
|
/*
|
||||||
* Created on Jun 13, 2003
|
* Created on Jun 13, 2003
|
||||||
*/
|
*/
|
||||||
package org.eclipse.cdt.internal.core.search;
|
package org.eclipse.cdt.internal.core.search;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.search.processing.IJob;
|
import java.io.IOException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
|
||||||
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndex;
|
||||||
|
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
|
||||||
|
import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor;
|
||||||
|
import org.eclipse.cdt.internal.core.search.matching.CSearchPattern;
|
||||||
|
import org.eclipse.cdt.internal.core.search.processing.IJob;
|
||||||
|
import org.eclipse.cdt.internal.core.search.processing.JobManager;
|
||||||
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.OperationCanceledException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author aniefer
|
|
||||||
*
|
|
||||||
* To change the template for this generated type comment go to
|
|
||||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
|
||||||
*/
|
|
||||||
public class PatternSearchJob implements IJob {
|
public class PatternSearchJob implements IJob {
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public PatternSearchJob() {
|
|
||||||
super();
|
|
||||||
// TODO Auto-generated constructor stub
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
protected CSearchPattern pattern;
|
||||||
* @see org.eclipse.cdt.internal.core.search.processing.IJob#belongsTo(java.lang.String)
|
protected ICSearchScope scope;
|
||||||
*/
|
protected ICElement focus;
|
||||||
|
protected IIndexSearchRequestor requestor;
|
||||||
|
protected IndexManager indexManager;
|
||||||
|
protected int detailLevel;
|
||||||
|
protected IndexSelector indexSelector;
|
||||||
|
protected boolean isPolymorphicSearch;
|
||||||
|
protected long executionTime = 0;
|
||||||
|
|
||||||
|
public PatternSearchJob(
|
||||||
|
CSearchPattern pattern,
|
||||||
|
ICSearchScope scope,
|
||||||
|
IIndexSearchRequestor requestor,
|
||||||
|
IndexManager indexManager) {
|
||||||
|
|
||||||
|
this(
|
||||||
|
pattern,
|
||||||
|
scope,
|
||||||
|
null,
|
||||||
|
false,
|
||||||
|
requestor,
|
||||||
|
indexManager);
|
||||||
|
}
|
||||||
|
public PatternSearchJob(
|
||||||
|
CSearchPattern pattern,
|
||||||
|
ICSearchScope scope,
|
||||||
|
ICElement focus,
|
||||||
|
boolean isPolymorphicSearch,
|
||||||
|
IIndexSearchRequestor requestor,
|
||||||
|
IndexManager indexManager) {
|
||||||
|
|
||||||
|
this.pattern = pattern;
|
||||||
|
this.scope = scope;
|
||||||
|
this.focus = focus;
|
||||||
|
this.isPolymorphicSearch = isPolymorphicSearch;
|
||||||
|
this.requestor = requestor;
|
||||||
|
this.indexManager = indexManager;
|
||||||
|
}
|
||||||
public boolean belongsTo(String jobFamily) {
|
public boolean belongsTo(String jobFamily) {
|
||||||
// TODO Auto-generated method stub
|
return true;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.internal.core.search.processing.IJob#cancel()
|
|
||||||
*/
|
|
||||||
public void cancel() {
|
public void cancel() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public boolean execute(IProgressMonitor progressMonitor) {
|
||||||
|
|
||||||
/* (non-Javadoc)
|
if (progressMonitor != null && progressMonitor.isCanceled())
|
||||||
* @see org.eclipse.cdt.internal.core.search.processing.IJob#execute(org.eclipse.core.runtime.IProgressMonitor)
|
throw new OperationCanceledException();
|
||||||
*/
|
boolean isComplete = COMPLETE;
|
||||||
public boolean execute(IProgressMonitor progress) {
|
executionTime = 0;
|
||||||
// TODO Auto-generated method stub
|
if (this.indexSelector == null) {
|
||||||
return false;
|
this.indexSelector =
|
||||||
|
new IndexSelector(this.scope, this.focus, this.isPolymorphicSearch, this.indexManager);
|
||||||
|
}
|
||||||
|
IIndex[] searchIndexes = this.indexSelector.getIndexes();
|
||||||
|
try {
|
||||||
|
int max = searchIndexes.length;
|
||||||
|
if (progressMonitor != null) {
|
||||||
|
progressMonitor.beginTask("", max); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
for (int i = 0; i < max; i++) {
|
||||||
|
isComplete &= search(searchIndexes[i], progressMonitor);
|
||||||
|
if (progressMonitor != null) {
|
||||||
|
if (progressMonitor.isCanceled()) {
|
||||||
|
throw new OperationCanceledException();
|
||||||
|
} else {
|
||||||
|
progressMonitor.worked(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (JobManager.VERBOSE) {
|
||||||
|
JobManager.verbose("-> execution time: " + executionTime + "ms - " + this);//$NON-NLS-1$//$NON-NLS-2$
|
||||||
|
}
|
||||||
|
return isComplete;
|
||||||
|
} finally {
|
||||||
|
if (progressMonitor != null) {
|
||||||
|
progressMonitor.done();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.internal.core.search.processing.IJob#isReadyToRun()
|
|
||||||
*/
|
|
||||||
public boolean isReadyToRun() {
|
public boolean isReadyToRun() {
|
||||||
// TODO Auto-generated method stub
|
if (this.indexSelector == null) { // only check once. As long as this job is used, it will keep the same index picture
|
||||||
return false;
|
this.indexSelector = new IndexSelector(this.scope, this.focus, this.isPolymorphicSearch, this.indexManager);
|
||||||
|
this.indexSelector.getIndexes(); // will only cache answer if all indexes were available originally
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public boolean search(IIndex index, IProgressMonitor progressMonitor) {
|
||||||
|
|
||||||
|
if (progressMonitor != null && progressMonitor.isCanceled())
|
||||||
|
throw new OperationCanceledException();
|
||||||
|
|
||||||
|
// IIndex inMemIndex = indexManager.peekAtIndex(new Path(((Index)index).toString.substring("Index for ".length()).replace('\\','/')));
|
||||||
|
// if (inMemIndex != index) {
|
||||||
|
// System.out.println("SANITY CHECK: search job using obsolete index: ["+index+ "] instead of: ["+inMemIndex+"]");
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (index == null)
|
||||||
|
return COMPLETE;
|
||||||
|
ReadWriteMonitor monitor = indexManager.getMonitorFor(index);
|
||||||
|
if (monitor == null)
|
||||||
|
return COMPLETE; // index got deleted since acquired
|
||||||
|
try {
|
||||||
|
monitor.enterRead(); // ask permission to read
|
||||||
|
|
||||||
|
/* if index has changed, commit these before querying */
|
||||||
|
if (index.hasChanged()) {
|
||||||
|
try {
|
||||||
|
monitor.exitRead(); // free read lock
|
||||||
|
monitor.enterWrite(); // ask permission to write
|
||||||
|
this.indexManager.saveIndex(index);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return FAILED;
|
||||||
|
} finally {
|
||||||
|
monitor.exitWriteEnterRead(); // finished writing and reacquire read permission
|
||||||
|
}
|
||||||
|
}
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
pattern.findIndexMatches(
|
||||||
|
index,
|
||||||
|
requestor,
|
||||||
|
detailLevel,
|
||||||
|
progressMonitor,
|
||||||
|
this.scope);
|
||||||
|
executionTime += System.currentTimeMillis() - start;
|
||||||
|
return COMPLETE;
|
||||||
|
} catch (IOException e) {
|
||||||
|
return FAILED;
|
||||||
|
} finally {
|
||||||
|
monitor.exitRead(); // finished reading
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public String toString() {
|
||||||
|
return "searching " + pattern.toString(); //$NON-NLS-1$
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2003 IBM Corporation and others.
|
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Common Public License v0.5
|
* are made available under the terms of the Common Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/cpl-v05.html
|
* http://www.eclipse.org/legal/cpl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corp. - Rational Software - initial implementation
|
* IBM Corporation - initial API and implementation
|
||||||
******************************************************************************/
|
*******************************************************************************/
|
||||||
/*
|
/*
|
||||||
* Created on Jun 13, 2003
|
* Created on Jun 13, 2003
|
||||||
*/
|
*/
|
||||||
package org.eclipse.cdt.internal.core.search.matching;
|
package org.eclipse.cdt.internal.core.search.matching;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
@ -25,16 +26,22 @@ import org.eclipse.cdt.core.parser.ScannerException;
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
|
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
|
||||||
import org.eclipse.cdt.core.search.ICSearchConstants;
|
import org.eclipse.cdt.core.search.ICSearchConstants;
|
||||||
import org.eclipse.cdt.core.search.ICSearchPattern;
|
import org.eclipse.cdt.core.search.ICSearchPattern;
|
||||||
|
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IEntryResult;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndex;
|
||||||
|
import org.eclipse.cdt.internal.core.index.impl.BlocksIndexInput;
|
||||||
|
import org.eclipse.cdt.internal.core.index.impl.IndexInput;
|
||||||
import org.eclipse.cdt.internal.core.parser.ScannerInfo;
|
import org.eclipse.cdt.internal.core.parser.ScannerInfo;
|
||||||
import org.eclipse.cdt.internal.core.search.CharOperation;
|
import org.eclipse.cdt.internal.core.search.CharOperation;
|
||||||
|
import org.eclipse.cdt.internal.core.search.IIndexSearchRequestor;
|
||||||
|
import org.eclipse.cdt.internal.core.search.indexing.IIndexConstants;
|
||||||
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.OperationCanceledException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author aniefer
|
* @author aniefer
|
||||||
*
|
|
||||||
* To change the template for this generated type comment go to
|
|
||||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
|
||||||
*/
|
*/
|
||||||
public abstract class CSearchPattern implements ICSearchConstants, ICSearchPattern {
|
public abstract class CSearchPattern implements ICSearchConstants, ICSearchPattern, IIndexConstants {
|
||||||
|
|
||||||
public static final int IMPOSSIBLE_MATCH = 0;
|
public static final int IMPOSSIBLE_MATCH = 0;
|
||||||
public static final int POSSIBLE_MATCH = 1;
|
public static final int POSSIBLE_MATCH = 1;
|
||||||
|
@ -50,12 +57,8 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
|
||||||
_caseSensitive = caseSensitive;
|
_caseSensitive = caseSensitive;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public CSearchPattern() {
|
public CSearchPattern() {
|
||||||
super();
|
super();
|
||||||
// TODO Auto-generated constructor stub
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CSearchPattern createPattern( String patternString, SearchFor searchFor, LimitTo limitTo, int matchMode, boolean caseSensitive ){
|
public static CSearchPattern createPattern( String patternString, SearchFor searchFor, LimitTo limitTo, int matchMode, boolean caseSensitive ){
|
||||||
|
@ -74,8 +77,6 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
|
||||||
//case ICSearchConstants.FIELD:
|
//case ICSearchConstants.FIELD:
|
||||||
// pattern = createFieldPattern( patternString, limitTo, matchMode, caseSensitive );
|
// pattern = createFieldPattern( patternString, limitTo, matchMode, caseSensitive );
|
||||||
// break;
|
// break;
|
||||||
|
|
||||||
|
|
||||||
return pattern;
|
return pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,6 +185,65 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query a given index for matching entries.
|
||||||
|
*/
|
||||||
|
public void findIndexMatches(IIndex index, IIndexSearchRequestor requestor, int detailLevel, IProgressMonitor progressMonitor, ICSearchScope scope) throws IOException {
|
||||||
|
|
||||||
|
if (progressMonitor != null && progressMonitor.isCanceled()) throw new OperationCanceledException();
|
||||||
|
|
||||||
|
IndexInput input = new BlocksIndexInput(index.getIndexFile());
|
||||||
|
try {
|
||||||
|
input.open();
|
||||||
|
findIndexMatches(input, requestor, detailLevel, progressMonitor,scope);
|
||||||
|
} finally {
|
||||||
|
input.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Query a given index for matching entries.
|
||||||
|
*/
|
||||||
|
public void findIndexMatches(IndexInput input, IIndexSearchRequestor requestor, int detailLevel, IProgressMonitor progressMonitor, ICSearchScope scope) throws IOException {
|
||||||
|
|
||||||
|
if (progressMonitor != null && progressMonitor.isCanceled()) throw new OperationCanceledException();
|
||||||
|
|
||||||
|
/* narrow down a set of entries using prefix criteria */
|
||||||
|
IEntryResult[] entries = input.queryEntriesPrefixedBy(indexEntryPrefix());
|
||||||
|
if (entries == null) return;
|
||||||
|
|
||||||
|
/* only select entries which actually match the entire search pattern */
|
||||||
|
for (int i = 0, max = entries.length; i < max; i++){
|
||||||
|
|
||||||
|
if (progressMonitor != null && progressMonitor.isCanceled()) throw new OperationCanceledException();
|
||||||
|
|
||||||
|
/* retrieve and decode entry */
|
||||||
|
IEntryResult entry = entries[i];
|
||||||
|
decodeIndexEntry(entry);
|
||||||
|
if (matchIndexEntry()){
|
||||||
|
feedIndexRequestor(requestor, detailLevel, entry.getFileReferences(), input, scope);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Feed the requestor according to the current search pattern
|
||||||
|
*/
|
||||||
|
public abstract void feedIndexRequestor(IIndexSearchRequestor requestor, int detailLevel, int[] references, IndexInput input, ICSearchScope scope) throws IOException ;
|
||||||
|
/**
|
||||||
|
* Decodes the index entry
|
||||||
|
*/
|
||||||
|
protected abstract void decodeIndexEntry(IEntryResult entryResult);
|
||||||
|
/**
|
||||||
|
* Answers the suitable prefix that should be used in order
|
||||||
|
* to query indexes for the corresponding item.
|
||||||
|
* The more accurate the prefix and the less false hits will have
|
||||||
|
* to be eliminated later on.
|
||||||
|
*/
|
||||||
|
public abstract char[] indexEntryPrefix();
|
||||||
|
/**
|
||||||
|
* Checks whether an entry matches the current search pattern
|
||||||
|
*/
|
||||||
|
protected abstract boolean matchIndexEntry();
|
||||||
|
|
||||||
protected int _matchMode;
|
protected int _matchMode;
|
||||||
protected boolean _caseSensitive;
|
protected boolean _caseSensitive;
|
||||||
|
|
|
@ -1,29 +1,35 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2003 IBM Corporation and others.
|
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Common Public License v0.5
|
* are made available under the terms of the Common Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/cpl-v05.html
|
* http://www.eclipse.org/legal/cpl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corp. - Rational Software - initial implementation
|
* IBM Corporation - initial API and implementation
|
||||||
******************************************************************************/
|
*******************************************************************************/
|
||||||
/*
|
/*
|
||||||
* Created on Jun 13, 2003
|
* Created on Jun 13, 2003
|
||||||
*/
|
*/
|
||||||
package org.eclipse.cdt.internal.core.search.matching;
|
package org.eclipse.cdt.internal.core.search.matching;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
|
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTOffsetableElement;
|
import org.eclipse.cdt.core.parser.ast.IASTOffsetableElement;
|
||||||
|
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IEntryResult;
|
||||||
|
import org.eclipse.cdt.internal.core.index.impl.IndexInput;
|
||||||
|
import org.eclipse.cdt.internal.core.index.impl.IndexedFile;
|
||||||
import org.eclipse.cdt.internal.core.search.CharOperation;
|
import org.eclipse.cdt.internal.core.search.CharOperation;
|
||||||
|
import org.eclipse.cdt.internal.core.search.IIndexSearchRequestor;
|
||||||
|
import org.eclipse.cdt.internal.core.search.indexing.AbstractIndexer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author aniefer
|
* @author aniefer
|
||||||
*
|
|
||||||
* To change the template for this generated type comment go to
|
|
||||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class ClassDeclarationPattern extends CSearchPattern {
|
public class ClassDeclarationPattern extends CSearchPattern {
|
||||||
|
|
||||||
public ClassDeclarationPattern( int matchMode, boolean caseSensitive ){
|
public ClassDeclarationPattern( int matchMode, boolean caseSensitive ){
|
||||||
|
@ -50,6 +56,7 @@ public class ClassDeclarationPattern extends CSearchPattern {
|
||||||
return IMPOSSIBLE_MATCH;
|
return IMPOSSIBLE_MATCH;
|
||||||
|
|
||||||
IASTClassSpecifier clsSpec = (IASTClassSpecifier) node;
|
IASTClassSpecifier clsSpec = (IASTClassSpecifier) node;
|
||||||
|
String nodeName = clsSpec.getName();
|
||||||
|
|
||||||
//check name, if simpleName == null, its treated the same as "*"
|
//check name, if simpleName == null, its treated the same as "*"
|
||||||
if( simpleName != null && !matchesName( simpleName, clsSpec.getName().toCharArray() ) ){
|
if( simpleName != null && !matchesName( simpleName, clsSpec.getName().toCharArray() ) ){
|
||||||
|
@ -92,4 +99,87 @@ public class ClassDeclarationPattern extends CSearchPattern {
|
||||||
private char[][] containingTypes;
|
private char[][] containingTypes;
|
||||||
private ASTClassKind classKind;
|
private ASTClassKind classKind;
|
||||||
|
|
||||||
|
protected char[] decodedSimpleName;
|
||||||
|
private char[][] decodedContainingTypes;
|
||||||
|
protected char decodedType;
|
||||||
|
|
||||||
|
|
||||||
|
public void feedIndexRequestor(IIndexSearchRequestor requestor, int detailLevel, int[] references, IndexInput input, ICSearchScope scope) throws IOException {
|
||||||
|
boolean isClass = decodedType == CLASS_SUFFIX;
|
||||||
|
for (int i = 0, max = references.length; i < max; i++) {
|
||||||
|
IndexedFile file = input.getIndexedFile(references[i]);
|
||||||
|
String path;
|
||||||
|
if (file != null && scope.encloses(path =file.getPath())) {
|
||||||
|
//TODO: BOG Fix this up - even if it's not a class we still care
|
||||||
|
if (isClass) {
|
||||||
|
requestor.acceptClassDeclaration(path, decodedSimpleName, decodedContainingTypes);
|
||||||
|
} else {
|
||||||
|
requestor.acceptClassDeclaration(path, decodedSimpleName, decodedContainingTypes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void decodeIndexEntry(IEntryResult entryResult) {
|
||||||
|
char[] word = entryResult.getWord();
|
||||||
|
int size = word.length;
|
||||||
|
|
||||||
|
this.decodedType = word[TYPE_DECL_LENGTH];
|
||||||
|
int oldSlash = TYPE_DECL_LENGTH+1;
|
||||||
|
int slash = CharOperation.indexOf(SEPARATOR, word, oldSlash+1);
|
||||||
|
|
||||||
|
this.decodedSimpleName = CharOperation.subarray(word, oldSlash+1, slash);
|
||||||
|
|
||||||
|
if (slash != -1){
|
||||||
|
if (slash+1 < size){
|
||||||
|
this.decodedContainingTypes = CharOperation.splitOn('/', CharOperation.subarray(word, slash+1, size));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public char[] indexEntryPrefix() {
|
||||||
|
return AbstractIndexer.bestTypeDeclarationPrefix(
|
||||||
|
simpleName,
|
||||||
|
containingTypes,
|
||||||
|
classKind,
|
||||||
|
_matchMode,
|
||||||
|
_caseSensitive
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean matchIndexEntry() {
|
||||||
|
|
||||||
|
//TODO: BOG PUT QUALIFIER CHECKING BACK IN
|
||||||
|
// if (containingTypes != null){
|
||||||
|
// // empty char[][] means no enclosing type (in which case, the decoded one is the empty char array)
|
||||||
|
// if (containingTypes.length == 0){
|
||||||
|
// if (decodedContainingTypes != CharOperation.NO_CHAR_CHAR) return false;
|
||||||
|
// } else {
|
||||||
|
// if (!CharOperation.equals(containingTypes, decodedContainingTypes, _caseSensitive)) return false;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
/* check simple name matches */
|
||||||
|
if (simpleName != null){
|
||||||
|
switch(_matchMode){
|
||||||
|
case EXACT_MATCH :
|
||||||
|
if (!CharOperation.equals(simpleName, decodedSimpleName, _caseSensitive)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PREFIX_MATCH :
|
||||||
|
if (!CharOperation.prefixEquals(simpleName, decodedSimpleName, _caseSensitive)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PATTERN_MATCH :
|
||||||
|
if (!CharOperation.match(simpleName, decodedSimpleName, _caseSensitive)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,10 @@
|
||||||
*/
|
*/
|
||||||
package org.eclipse.cdt.internal.core.search.processing;
|
package org.eclipse.cdt.internal.core.search.processing;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.core.search.Util;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.OperationCanceledException;
|
import org.eclipse.core.runtime.OperationCanceledException;
|
||||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||||
import org.eclipse.cdt.internal.core.search.Util;
|
|
||||||
|
|
||||||
public abstract class JobManager implements Runnable {
|
public abstract class JobManager implements Runnable {
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue