1
0
Fork 0
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:
Doug Schaefer 2003-07-11 22:12:35 +00:00
parent 241ff5cf7f
commit bcf023a6c8
21 changed files with 1159 additions and 222 deletions

View file

@ -1,62 +1,69 @@
2003-07-03 Bogdan Gheorghe
Updated copyright notices.
2003-06-25 Bogdan Gheorghe
Added new Indexer framework:
* index/org/eclipse/cdt/internal/core/index/IDocument.java
* index/org/eclipse/cdt/internal/core/index/IEntryResult.java
* index/org/eclipse/cdt/internal/core/index/IIndex.java
* index/org/eclipse/cdt/internal/core/index/IIndexer.java
* index/org/eclipse/cdt/internal/core/index/IIndexerOutput.java
* index/org/eclipse/cdt/internal/core/index/IQueryResult.java
* index/org/eclipse/cdt/internal/core/index/impl/Block.java
* index/org/eclipse/cdt/internal/core/index/impl/BlocksIndexInput.java
* index/org/eclipse/cdt/internal/core/index/impl/BlocksIndexOutput.java
* index/org/eclipse/cdt/internal/core/index/impl/CodeByteStream.java
* index/org/eclipse/cdt/internal/core/index/impl/EntryResult.java
* index/org/eclipse/cdt/internal/core/index/impl/Field.java
* index/org/eclipse/cdt/internal/core/index/impl/GammaCompressedIndexBlock.java
* index/org/eclipse/cdt/internal/core/index/impl/IFileDocument.java
* index/org/eclipse/cdt/internal/core/index/impl/IIndexConstants.java
* index/org/eclipse/cdt/internal/core/index/impl/Index.java
* index/org/eclipse/cdt/internal/core/index/impl/IndexBlock.java
* index/org/eclipse/cdt/internal/core/index/impl/IndexedFile.java
* index/org/eclipse/cdt/internal/core/index/impl/IndexedFileHashedArray.java
* index/org/eclipse/cdt/internal/core/index/impl/IndexerOutput.java
* index/org/eclipse/cdt/internal/core/index/impl/IndexInput.java
* index/org/eclipse/cdt/internal/core/index/impl/IndexOutput.java
* index/org/eclipse/cdt/internal/core/index/impl/IndexSummary.java
* index/org/eclipse/cdt/internal/core/index/impl/InMemoryIndex.java
* index/org/eclipse/cdt/internal/core/index/impl/Int.java
* index/org/eclipse/cdt/internal/core/index/impl/MergeFactory.java
* index/org/eclipse/cdt/internal/core/index/impl/PropertyDocument.java
* index/org/eclipse/cdt/internal/core/index/impl/SafeRandomAccessFile.java
* index/org/eclipse/cdt/internal/core/index/impl/SimpleIndexInput.java
* index/org/eclipse/cdt/internal/core/index/impl/Util.java
* index/org/eclipse/cdt/internal/core/index/impl/WordEntry.java
* index/org/eclipse/cdt/internal/core/index/impl/WordEntryHashedArray.java
* index/org/eclipse/cdt/internal/core/search/CharOperation.java
* index/org/eclipse/cdt/internal/core/search/HashtableOfInt.java
* index/org/eclipse/cdt/internal/core/search/SimpleLookupTable.java
* index/org/eclipse/cdt/internal/core/search/Util.java
* index/org/eclipse/cdt/internal/core/search/message.properties
* index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java
* index/org/eclipse/cdt/internal/core/search/indexing/AddCompilationUnitToIndex.java
* index/org/eclipse/cdt/internal/core/search/indexing/AddFileToIndex.java
* index/org/eclipse/cdt/internal/core/search/indexing/AddFolderToIndex.java
* index/org/eclipse/cdt/internal/core/search/indexing/IIndexConstants.java
* index/org/eclipse/cdt/internal/core/search/indexing/IndexAllProject.java
* index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java
* index/org/eclipse/cdt/internal/core/search/indexing/IndexRequest.java
* index/org/eclipse/cdt/internal/core/search/indexing/ReadWriteMonitor.java
* index/org/eclipse/cdt/internal/core/search/indexing/RemoveFolderFromIndex.java
* index/org/eclipse/cdt/internal/core/search/indexing/RemoveFromIndex.java
* index/org/eclipse/cdt/internal/core/search/indexing/SaveIndex.java
* index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexer.java
* index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexerRequestor.java
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
Updated copyright notices.
2003-06-25 Bogdan Gheorghe
Added new Indexer framework:
* index/org/eclipse/cdt/internal/core/index/IDocument.java
* index/org/eclipse/cdt/internal/core/index/IEntryResult.java
* index/org/eclipse/cdt/internal/core/index/IIndex.java
* index/org/eclipse/cdt/internal/core/index/IIndexer.java
* index/org/eclipse/cdt/internal/core/index/IIndexerOutput.java
* index/org/eclipse/cdt/internal/core/index/IQueryResult.java
* index/org/eclipse/cdt/internal/core/index/impl/Block.java
* index/org/eclipse/cdt/internal/core/index/impl/BlocksIndexInput.java
* index/org/eclipse/cdt/internal/core/index/impl/BlocksIndexOutput.java
* index/org/eclipse/cdt/internal/core/index/impl/CodeByteStream.java
* index/org/eclipse/cdt/internal/core/index/impl/EntryResult.java
* index/org/eclipse/cdt/internal/core/index/impl/Field.java
* index/org/eclipse/cdt/internal/core/index/impl/GammaCompressedIndexBlock.java
* index/org/eclipse/cdt/internal/core/index/impl/IFileDocument.java
* index/org/eclipse/cdt/internal/core/index/impl/IIndexConstants.java
* index/org/eclipse/cdt/internal/core/index/impl/Index.java
* index/org/eclipse/cdt/internal/core/index/impl/IndexBlock.java
* index/org/eclipse/cdt/internal/core/index/impl/IndexedFile.java
* index/org/eclipse/cdt/internal/core/index/impl/IndexedFileHashedArray.java
* index/org/eclipse/cdt/internal/core/index/impl/IndexerOutput.java
* index/org/eclipse/cdt/internal/core/index/impl/IndexInput.java
* index/org/eclipse/cdt/internal/core/index/impl/IndexOutput.java
* index/org/eclipse/cdt/internal/core/index/impl/IndexSummary.java
* index/org/eclipse/cdt/internal/core/index/impl/InMemoryIndex.java
* index/org/eclipse/cdt/internal/core/index/impl/Int.java
* index/org/eclipse/cdt/internal/core/index/impl/MergeFactory.java
* index/org/eclipse/cdt/internal/core/index/impl/PropertyDocument.java
* index/org/eclipse/cdt/internal/core/index/impl/SafeRandomAccessFile.java
* index/org/eclipse/cdt/internal/core/index/impl/SimpleIndexInput.java
* index/org/eclipse/cdt/internal/core/index/impl/Util.java
* index/org/eclipse/cdt/internal/core/index/impl/WordEntry.java
* index/org/eclipse/cdt/internal/core/index/impl/WordEntryHashedArray.java
* index/org/eclipse/cdt/internal/core/search/CharOperation.java
* index/org/eclipse/cdt/internal/core/search/HashtableOfInt.java
* index/org/eclipse/cdt/internal/core/search/SimpleLookupTable.java
* index/org/eclipse/cdt/internal/core/search/Util.java
* index/org/eclipse/cdt/internal/core/search/message.properties
* index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java
* index/org/eclipse/cdt/internal/core/search/indexing/AddCompilationUnitToIndex.java
* index/org/eclipse/cdt/internal/core/search/indexing/AddFileToIndex.java
* index/org/eclipse/cdt/internal/core/search/indexing/AddFolderToIndex.java
* index/org/eclipse/cdt/internal/core/search/indexing/IIndexConstants.java
* index/org/eclipse/cdt/internal/core/search/indexing/IndexAllProject.java
* index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java
* index/org/eclipse/cdt/internal/core/search/indexing/IndexRequest.java
* index/org/eclipse/cdt/internal/core/search/indexing/ReadWriteMonitor.java
* index/org/eclipse/cdt/internal/core/search/indexing/RemoveFolderFromIndex.java
* index/org/eclipse/cdt/internal/core/search/indexing/RemoveFromIndex.java
* index/org/eclipse/cdt/internal/core/search/indexing/SaveIndex.java
* index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexer.java
* index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexerRequestor.java

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.internal.core.index.impl;
import java.io.IOException;
import org.eclipse.cdt.internal.core.index.IDocument;
import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.IQueryResult;

View file

@ -10,8 +10,8 @@
*******************************************************************************/
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.IIndexerOutput;
/**
* An indexerOutput is used by an indexer to add documents and word references to

View file

@ -10,9 +10,6 @@
*******************************************************************************/
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.File;
import java.io.FileInputStream;
@ -20,6 +17,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
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.IResource;

View file

@ -33,17 +33,18 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
}
public void addClassSpecifier(IASTClassSpecifier classSpecification){
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))
{
this.output.addRef(encodeTypeEntry(classSpecification.getName().toCharArray(),STRUCT));
this.output.addRef(encodeTypeEntry(classSpecification.getFullyQualifiedName(),STRUCT));
}
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 '/'
*/
protected static final char[] encodeTypeEntry( char[] typeName, int classType) {
int pos;
//3 - 1 for SUFFIX letter, 2 Separators
char[] result = new char[TYPE_DECL_LENGTH + typeName.length + 3];
protected static final char[] encodeTypeEntry( String [] fullTypeName, int classType) {
int pos, nameLength = 0;
for (int i=0; i<fullTypeName.length; i++){
String namePart = fullTypeName[i];
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);
switch (classType)
{
@ -103,12 +107,22 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
result[pos++] = UNION_SUFFIX;
break;
}
result[pos++] = SEPARATOR;
System.arraycopy(typeName, 0, result, pos, typeName.length);
pos += typeName.length;
result[pos++] = SEPARATOR;
//Encode in the following manner
// [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;
char [] tempName = fullTypeName[i].toCharArray();
System.arraycopy(tempName, 0, result, pos, tempName.length);
pos+=tempName.length;
}
return result;
}
/**
@ -136,5 +150,74 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
}
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;
}
}

View file

@ -13,10 +13,10 @@ package org.eclipse.cdt.internal.core.search.indexing;
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.impl.IFileDocument;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IPath;
public class AddCompilationUnitToIndex extends AddFileToIndex {
char[] contents;

View file

@ -12,11 +12,11 @@ package org.eclipse.cdt.internal.core.search.indexing;
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.runtime.IPath;
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 {
IFile resource;

View file

@ -11,6 +11,9 @@
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.IProject;
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.IPath;
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 {
IPath folderPath;

View file

@ -13,14 +13,14 @@ package org.eclipse.cdt.internal.core.search.indexing;
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.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
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 {
IPath folderPath;

View file

@ -1,29 +1,58 @@
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
* Modified ICSearchConstants to use new nested classes SearchFor and LimitTo instead of int
for stronger type safety
* Updated MatchLocator to invoke parser to do actual search.
Modified ICSearchConstants to use new nested classes SearchFor and LimitTo instead of int
for stronger type safety
Updated MatchLocator to invoke parser to do actual search.
2003-06-27 Andrew Niefer
Modified:
search/org.eclipse.cdt.core.search.matching/MatchLocator.java
- enter/exitInclusion
- enterClassSpecifier
search/org.eclipse.cdt.core.search.matching/CSearchPattern.java
- createClassPattern
- matchesName
search/org.eclipse.cdt.core.search.matching/ClassDeclarationPattern.java
- matchLevel
search/org.eclipse.cdt.core.search/ICSearchPattern.java
search/org.eclipse.cdt.core.search/ICSearchResultCollector.java
search/org.eclipse.cdt.core.search/SearchEngine.java
Modified:
search/org.eclipse.cdt.core.search.matching/MatchLocator.java
- enter/exitInclusion
- enterClassSpecifier
search/org.eclipse.cdt.core.search.matching/CSearchPattern.java
- createClassPattern
- matchesName
search/org.eclipse.cdt.core.search.matching/ClassDeclarationPattern.java
- matchLevel
search/org.eclipse.cdt.core.search/ICSearchPattern.java
search/org.eclipse.cdt.core.search/ICSearchResultCollector.java
search/org.eclipse.cdt.core.search/SearchEngine.java
2003-06-25 Bogdan Gheorghe
Modified:
* search/org/eclipse/cdt/core/search/ICSearchConstants.java
* search/org/eclipse/cdt/internal/core/search/Utils.java
- moved to index/org/eclipse/cdt/internal/core/search/Utils.java
* search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java
* search/org/eclipse/cdt/internal/core/search/processing/IJob.java
* search/org/eclipse/cdt/internal/core/search/processing/JobManager.java
Modified:
* search/org/eclipse/cdt/core/search/ICSearchConstants.java
* search/org/eclipse/cdt/internal/core/search/Utils.java
- moved to index/org/eclipse/cdt/internal/core/search/Utils.java
* search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java
* search/org/eclipse/cdt/internal/core/search/processing/IJob.java
* search/org/eclipse/cdt/internal/core/search/processing/JobManager.java

View file

@ -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
* 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
* http://www.eclipse.org/legal/cpl-v05.html
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corp. - Rational Software - initial implementation
******************************************************************************/
* IBM Corporation - initial API and implementation
*******************************************************************************/
/*
* Created on Jun 12, 2003
*/
package org.eclipse.cdt.core.search;
/**
* @author aniefer
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.core.runtime.IPath;
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();
}

View file

@ -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
* 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
* http://www.eclipse.org/legal/cpl-v05.html
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corp. - Rational Software - initial implementation
******************************************************************************/
* IBM Corporation - initial API and implementation
*******************************************************************************/
/*
* Created on Jun 11, 2003
*/
package org.eclipse.cdt.core.search;
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.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.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.MatchLocator;
import org.eclipse.core.resources.IWorkspace;
@ -35,6 +38,12 @@ public class SearchEngine implements ICSearchConstants{
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
}
public SearchEngine(IWorkingCopy[] workingCopies) {
this.workingCopies = workingCopies;
}
/**
* @return
*/
public static ICSearchScope createWorkspaceScope() {
// 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$
}
/* index search */
PathCollector pathCollector = new PathCollector();
CModelManager modelManager = CModelManager.getDefault();
IndexManager indexManager = modelManager.getIndexManager();
SubProgressMonitor subMonitor = (progressMonitor == null ) ? null : new SubProgressMonitor( progressMonitor, 5 );
indexManager.performConcurrentJob(
new PatternSearchJob(),
new PatternSearchJob(
(CSearchPattern) pattern,
scope,
pathCollector,
indexManager
),
ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
subMonitor );
@ -114,7 +135,8 @@ public class SearchEngine implements ICSearchConstants{
if( progressMonitor != null && progressMonitor.isCanceled() )
throw new OperationCanceledException();
//matchLocator.locateMatches( pathCollector.getPaths(), workspace, workingCopies );
//TODO: BOG Filter Working Copies...
matchLocator.locateMatches( pathCollector.getPaths(), workspace, this.workingCopies);
} finally {
collector.done();
}

View file

@ -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
* 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
* http://www.eclipse.org/legal/cpl-v05.html
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corp. - Rational Software - initial implementation
******************************************************************************/
/*
* Created on Jun 12, 2003
*/
* IBM Corporation - initial API and implementation
*******************************************************************************/
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 {
/**
*
*/
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() {
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;
}
}

View file

@ -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$
}
}

View file

@ -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);
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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
* 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
* http://www.eclipse.org/legal/cpl-v05.html
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corp. - Rational Software - initial implementation
******************************************************************************/
* IBM Corporation - initial API and implementation
*******************************************************************************/
/*
* Created on Jun 13, 2003
*/
package org.eclipse.cdt.internal.core.search;
import org.eclipse.cdt.internal.core.search.processing.IJob;
import org.eclipse.core.runtime.IProgressMonitor;
import java.io.IOException;
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 PatternSearchJob() {
super();
// TODO Auto-generated constructor stub
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.search.processing.IJob#belongsTo(java.lang.String)
*/
protected CSearchPattern pattern;
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) {
// TODO Auto-generated method stub
return false;
return true;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.search.processing.IJob#cancel()
*/
public void cancel() {
// TODO Auto-generated method stub
}
public boolean execute(IProgressMonitor progressMonitor) {
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.search.processing.IJob#execute(org.eclipse.core.runtime.IProgressMonitor)
*/
public boolean execute(IProgressMonitor progress) {
// TODO Auto-generated method stub
return false;
if (progressMonitor != null && progressMonitor.isCanceled())
throw new OperationCanceledException();
boolean isComplete = COMPLETE;
executionTime = 0;
if (this.indexSelector == null) {
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() {
// TODO Auto-generated method stub
return false;
if (this.indexSelector == null) { // only check once. As long as this job is used, it will keep the same index picture
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$
}
}

View file

@ -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
* 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
* http://www.eclipse.org/legal/cpl-v05.html
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corp. - Rational Software - initial implementation
******************************************************************************/
* IBM Corporation - initial API and implementation
*******************************************************************************/
/*
* Created on Jun 13, 2003
*/
package org.eclipse.cdt.internal.core.search.matching;
import java.io.IOException;
import java.io.StringReader;
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.search.ICSearchConstants;
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.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
*
* 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 POSSIBLE_MATCH = 1;
@ -50,12 +57,8 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
_caseSensitive = caseSensitive;
}
/**
*
*/
public CSearchPattern() {
super();
// TODO Auto-generated constructor stub
}
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:
// pattern = createFieldPattern( patternString, limitTo, matchMode, caseSensitive );
// break;
return pattern;
}
@ -157,7 +158,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
} else if ( searchFor == UNION ) {
kind = ASTClassKind.UNION;
}
char [][] qualifications = new char[0][];
return new ClassDeclarationPattern( name.toCharArray(), (char[][])list.toArray( qualifications ), kind, matchMode, caseSensitive );
}
@ -184,7 +185,66 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
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 boolean _caseSensitive;
}

View file

@ -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
* 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
* http://www.eclipse.org/legal/cpl-v05.html
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corp. - Rational Software - initial implementation
******************************************************************************/
* IBM Corporation - initial API and implementation
*******************************************************************************/
/*
* Created on Jun 13, 2003
*/
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.IASTClassSpecifier;
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.IIndexSearchRequestor;
import org.eclipse.cdt.internal.core.search.indexing.AbstractIndexer;
/**
* @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 ClassDeclarationPattern( int matchMode, boolean caseSensitive ){
@ -50,7 +56,8 @@ public class ClassDeclarationPattern extends CSearchPattern {
return IMPOSSIBLE_MATCH;
IASTClassSpecifier clsSpec = (IASTClassSpecifier) node;
String nodeName = clsSpec.getName();
//check name, if simpleName == null, its treated the same as "*"
if( simpleName != null && !matchesName( simpleName, clsSpec.getName().toCharArray() ) ){
return IMPOSSIBLE_MATCH;
@ -92,4 +99,87 @@ public class ClassDeclarationPattern extends CSearchPattern {
private char[][] containingTypes;
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;
}
}

View file

@ -13,10 +13,10 @@
*/
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.OperationCanceledException;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.cdt.internal.core.search.Util;
public abstract class JobManager implements Runnable {