mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Patch for Bogdan Gheorghe.
This patch adds working copy search, macro search and combines the function and method search patterns into one.
This commit is contained in:
parent
256866b864
commit
dbc6ab4f98
17 changed files with 269 additions and 143 deletions
|
@ -1,3 +1,7 @@
|
|||
2003-08-11 Andrew Niefer
|
||||
- Added testMacroPattern to OtherPatternTests
|
||||
- Changed the function tests to use new function/method pattern
|
||||
|
||||
2003-08-11 Bogdan Gheorghe
|
||||
- Added testMacros to IndexManagerTests
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "include.h"
|
||||
|
||||
#define FOO bar
|
||||
|
||||
class Heal{};
|
||||
|
||||
class A {
|
||||
|
|
|
@ -18,7 +18,6 @@ import java.util.Set;
|
|||
import org.eclipse.cdt.core.search.ICSearchPattern;
|
||||
import org.eclipse.cdt.core.search.SearchEngine;
|
||||
import org.eclipse.cdt.internal.core.search.CharOperation;
|
||||
import org.eclipse.cdt.internal.core.search.matching.FunctionDeclarationPattern;
|
||||
import org.eclipse.cdt.internal.core.search.matching.MethodDeclarationPattern;
|
||||
|
||||
/**
|
||||
|
@ -36,18 +35,17 @@ public class FunctionMethodPatternTests extends BaseSearchTest {
|
|||
super(name);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
|
||||
public void testFunctionIndexPrefix(){
|
||||
ICSearchPattern pattern = SearchEngine.createSearchPattern( "c()", FUNCTION, DECLARATIONS, true );
|
||||
assertTrue( pattern instanceof FunctionDeclarationPattern );
|
||||
|
||||
FunctionDeclarationPattern functionPattern = (FunctionDeclarationPattern)pattern;
|
||||
MethodDeclarationPattern functionPattern = (MethodDeclarationPattern)pattern;
|
||||
assertEquals( CharOperation.compareWith( "functionDecl/c".toCharArray(), functionPattern.indexEntryPrefix() ), 0);
|
||||
|
||||
functionPattern = (FunctionDeclarationPattern) SearchEngine.createSearchPattern( "rt*()", FUNCTION, DECLARATIONS, true );
|
||||
functionPattern = (MethodDeclarationPattern) SearchEngine.createSearchPattern( "rt*()", FUNCTION, DECLARATIONS, true );
|
||||
assertEquals( CharOperation.compareWith( "functionDecl/rt".toCharArray(), functionPattern.indexEntryPrefix() ), 0);
|
||||
|
||||
functionPattern = (FunctionDeclarationPattern) SearchEngine.createSearchPattern( "Ac", FUNCTION, REFERENCES, false );
|
||||
functionPattern = (MethodDeclarationPattern) SearchEngine.createSearchPattern( "Ac", FUNCTION, REFERENCES, false );
|
||||
assertEquals( CharOperation.compareWith( "functionRef/".toCharArray(), functionPattern.indexEntryPrefix() ), 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public class OtherPatternTests extends BaseSearchTest {
|
|||
super(name);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
|
||||
public void testNamespaceIndexPrefix(){
|
||||
ICSearchPattern pattern = SearchEngine.createSearchPattern( "A::B::c", NAMESPACE, DECLARATIONS, true );
|
||||
assertTrue( pattern instanceof NamespaceDeclarationPattern );
|
||||
|
@ -169,4 +169,12 @@ public class OtherPatternTests extends BaseSearchTest {
|
|||
assertEquals( matches.size(), 6 );
|
||||
}
|
||||
|
||||
public void testMacroPattern(){
|
||||
ICSearchPattern pattern = SearchEngine.createSearchPattern( "FOO", MACRO, DECLARATIONS, true );
|
||||
|
||||
search( workspace, pattern, scope, resultCollector );
|
||||
|
||||
Set matches = resultCollector.getSearchResults();
|
||||
assertEquals( matches.size(), 1 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
2003-08-11 Andrew Niefer
|
||||
Added getSharedWorkingCopies to CCorePlugin.
|
||||
|
||||
2003-08-10 Sean Evoy
|
||||
Fix for Bug 41274. Was not saving the library option properly because the value type
|
||||
of the option was not recognized.
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
2003-08-11 Bogdan Gheorghe
|
||||
- Added macro declarations to the index
|
||||
- Added macro prefix to AbstractIndexer
|
||||
|
||||
2003-08-07 Bogdan Gheorghe
|
||||
- Added shutdown cleanup routine in IndexManager
|
||||
|
|
|
@ -508,7 +508,26 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
|
|||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param _limitTo
|
||||
* @param simpleName
|
||||
* @param _matchMode
|
||||
* @param _caseSensitive
|
||||
* @return
|
||||
*/
|
||||
public static final char[] bestMacroPrefix( LimitTo limitTo, char[] macroName, int matchMode, boolean isCaseSenstive ){
|
||||
//since we only index macro declarations we already know the prefix
|
||||
char [] prefix = null;
|
||||
if( limitTo == DECLARATIONS ){
|
||||
prefix = MACRO_DECL;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
return bestPrefix( prefix, (char)0, macroName, null, matchMode, isCaseSenstive );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -107,6 +107,8 @@ public class CModelManager implements IResourceChangeListener {
|
|||
public static final String [] sourceExtensions = {"c", "cxx", "cc", "C", "cpp"};
|
||||
|
||||
public static final String [] headerExtensions = {"h", "hh", "hpp", "H"};
|
||||
|
||||
public static final IWorkingCopy[] NoWorkingCopy = new IWorkingCopy[0];
|
||||
|
||||
static CModelManager factory = null;
|
||||
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
2003-08-11 Andrew Niefer
|
||||
- Added Macro ICSearchConstant
|
||||
- Added acceptMacro to IIndexSearchRequestor and PathCollector
|
||||
- Added MacroDeclaration Pattern
|
||||
- Rolled method and function patterns into one method pattern
|
||||
- Added WorkingCopy support to search
|
||||
|
||||
2003-08-08 Bogdan Gheorghe
|
||||
- Added CreateSearchScope to create a search scope out of
|
||||
CElements
|
||||
|
|
|
@ -93,6 +93,7 @@ public interface ICSearchConstants {
|
|||
*/
|
||||
public static final SearchFor UNION = new SearchFor( 9 );
|
||||
|
||||
public static final SearchFor MACRO = new SearchFor( 10 );
|
||||
|
||||
/* Nature of match */
|
||||
|
||||
|
|
|
@ -80,4 +80,6 @@ void acceptVariableDeclaration(String resourcePath, char[] simpleTypeName);
|
|||
|
||||
void acceptFieldDeclaration(String resourcePath, char[] simpleTypeName, char[][] enclosingTypeNames);
|
||||
|
||||
void acceptMacroDeclaration(String resourcePath, char[] decodedSimpleName);
|
||||
|
||||
}
|
|
@ -152,6 +152,10 @@ import org.eclipse.core.runtime.Path;
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void acceptMacroDeclaration(String resourcePath, char[] decodedSimpleName) {
|
||||
this.paths.add(resourcePath);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -78,21 +78,34 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
|
|||
CSearchPattern pattern = null;
|
||||
if( searchFor == TYPE || searchFor == CLASS || searchFor == STRUCT || searchFor == ENUM || searchFor == UNION ){
|
||||
pattern = createClassPattern( patternString, searchFor, limitTo, matchMode, caseSensitive );
|
||||
} else if ( searchFor == METHOD ){
|
||||
pattern = createMethodPattern( patternString, limitTo, matchMode, caseSensitive );
|
||||
} else if ( searchFor == METHOD || searchFor == FUNCTION ){
|
||||
pattern = createMethodPattern( patternString, searchFor, limitTo, matchMode, caseSensitive );
|
||||
} else if ( searchFor == FIELD){
|
||||
pattern = createFieldPattern( patternString, limitTo, matchMode, caseSensitive );
|
||||
} else if ( searchFor == VAR ){
|
||||
pattern = createVariablePattern( patternString, limitTo, matchMode, caseSensitive );
|
||||
} else if ( searchFor == FUNCTION ){
|
||||
pattern = createFunctionPattern( patternString, limitTo, matchMode, caseSensitive );
|
||||
} else if ( searchFor == NAMESPACE ){
|
||||
pattern = createNamespacePattern( patternString, limitTo, matchMode, caseSensitive );
|
||||
} else if ( searchFor == MACRO ){
|
||||
pattern = createMacroPattern( patternString, limitTo, matchMode, caseSensitive );
|
||||
}
|
||||
|
||||
return pattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param patternString
|
||||
* @param limitTo
|
||||
* @param matchMode
|
||||
* @param caseSensitive
|
||||
* @return
|
||||
*/
|
||||
private static CSearchPattern createMacroPattern(String patternString, LimitTo limitTo, int matchMode, boolean caseSensitive) {
|
||||
if( limitTo != DECLARATIONS )
|
||||
return null;
|
||||
|
||||
return new MacroDeclarationPattern( patternString.toCharArray(), matchMode, limitTo, caseSensitive ); }
|
||||
|
||||
/**
|
||||
* @param patternString
|
||||
* @param limitTo
|
||||
|
@ -117,38 +130,38 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
|
|||
return new NamespaceDeclarationPattern( name, (char[][]) list.toArray( qualifications ), matchMode, limitTo, caseSensitive );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param patternString
|
||||
* @param limitTo
|
||||
* @param matchMode
|
||||
* @param caseSensitive
|
||||
* @return
|
||||
*/
|
||||
private static CSearchPattern createFunctionPattern(String patternString, LimitTo limitTo, int matchMode, boolean caseSensitive) {
|
||||
if( limitTo == ALL_OCCURRENCES ){
|
||||
OrPattern orPattern = new OrPattern();
|
||||
orPattern.addPattern( createFunctionPattern( patternString, DECLARATIONS, matchMode, caseSensitive ) );
|
||||
orPattern.addPattern( createFunctionPattern( patternString, REFERENCES, matchMode, caseSensitive ) );
|
||||
orPattern.addPattern( createFunctionPattern( patternString, DEFINITIONS, matchMode, caseSensitive ) );
|
||||
return orPattern;
|
||||
}
|
||||
|
||||
int index = patternString.indexOf( '(' );
|
||||
|
||||
String paramString = ( index == -1 ) ? "" : patternString.substring( index );
|
||||
|
||||
String nameString = ( index == -1 ) ? patternString : patternString.substring( 0, index );
|
||||
|
||||
IScanner scanner = ParserFactory.createScanner( new StringReader( paramString ), "TEXT", new ScannerInfo(), ParserMode.QUICK_PARSE, null );
|
||||
|
||||
LinkedList params = scanForParameters( scanner );
|
||||
|
||||
char [] name = nameString.toCharArray();
|
||||
char [][] parameters = new char [0][];
|
||||
parameters = (char[][])params.toArray( parameters );
|
||||
|
||||
return new FunctionDeclarationPattern( name, parameters, matchMode, limitTo, caseSensitive );
|
||||
}
|
||||
// /**
|
||||
// * @param patternString
|
||||
// * @param limitTo
|
||||
// * @param matchMode
|
||||
// * @param caseSensitive
|
||||
// * @return
|
||||
// */
|
||||
// private static CSearchPattern createFunctionPattern(String patternString, LimitTo limitTo, int matchMode, boolean caseSensitive) {
|
||||
// if( limitTo == ALL_OCCURRENCES ){
|
||||
// OrPattern orPattern = new OrPattern();
|
||||
// orPattern.addPattern( createFunctionPattern( patternString, DECLARATIONS, matchMode, caseSensitive ) );
|
||||
// orPattern.addPattern( createFunctionPattern( patternString, REFERENCES, matchMode, caseSensitive ) );
|
||||
// orPattern.addPattern( createFunctionPattern( patternString, DEFINITIONS, matchMode, caseSensitive ) );
|
||||
// return orPattern;
|
||||
// }
|
||||
//
|
||||
// int index = patternString.indexOf( '(' );
|
||||
//
|
||||
// String paramString = ( index == -1 ) ? "" : patternString.substring( index );
|
||||
//
|
||||
// String nameString = ( index == -1 ) ? patternString : patternString.substring( 0, index );
|
||||
//
|
||||
// IScanner scanner = ParserFactory.createScanner( new StringReader( paramString ), "TEXT", new ScannerInfo(), ParserMode.QUICK_PARSE, null );
|
||||
//
|
||||
// LinkedList params = scanForParameters( scanner );
|
||||
//
|
||||
// char [] name = nameString.toCharArray();
|
||||
// char [][] parameters = new char [0][];
|
||||
// parameters = (char[][])params.toArray( parameters );
|
||||
//
|
||||
// return new MethodDeclarationPattern( name, parameters, matchMode, FUNCTION, limitTo, caseSensitive );
|
||||
// }
|
||||
|
||||
/**
|
||||
* @param patternString
|
||||
|
@ -198,13 +211,13 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
|
|||
* @param caseSensitive
|
||||
* @return
|
||||
*/
|
||||
private static CSearchPattern createMethodPattern(String patternString, LimitTo limitTo, int matchMode, boolean caseSensitive) {
|
||||
private static CSearchPattern createMethodPattern(String patternString, SearchFor searchFor, LimitTo limitTo, int matchMode, boolean caseSensitive) {
|
||||
|
||||
if( limitTo == ALL_OCCURRENCES ){
|
||||
OrPattern orPattern = new OrPattern();
|
||||
orPattern.addPattern( createMethodPattern( patternString, DECLARATIONS, matchMode, caseSensitive ) );
|
||||
orPattern.addPattern( createMethodPattern( patternString, REFERENCES, matchMode, caseSensitive ) );
|
||||
orPattern.addPattern( createMethodPattern( patternString, DEFINITIONS, matchMode, caseSensitive ) );
|
||||
orPattern.addPattern( createMethodPattern( patternString, searchFor, DECLARATIONS, matchMode, caseSensitive ) );
|
||||
orPattern.addPattern( createMethodPattern( patternString, searchFor, REFERENCES, matchMode, caseSensitive ) );
|
||||
orPattern.addPattern( createMethodPattern( patternString, searchFor, DEFINITIONS, matchMode, caseSensitive ) );
|
||||
return orPattern;
|
||||
}
|
||||
|
||||
|
@ -226,7 +239,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
|
|||
char [][] parameters = new char [0][];
|
||||
parameters = (char[][])params.toArray( parameters );
|
||||
|
||||
return new MethodDeclarationPattern( name, qualifications, parameters, matchMode, limitTo, caseSensitive );
|
||||
return new MethodDeclarationPattern( name, qualifications, parameters, matchMode, searchFor, limitTo, caseSensitive );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,19 +9,15 @@
|
|||
* IBM Corp. - Rational Software - initial implementation
|
||||
******************************************************************************/
|
||||
/*
|
||||
* Created on Jul 11, 2003
|
||||
* Created on Aug 8, 2003
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.search.matching;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTMacro;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
|
||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||
import org.eclipse.cdt.internal.core.index.IEntryResult;
|
||||
import org.eclipse.cdt.internal.core.index.impl.IndexInput;
|
||||
|
@ -36,74 +32,38 @@ import org.eclipse.cdt.internal.core.search.indexing.AbstractIndexer;
|
|||
* To change the template for this generated type comment go to
|
||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||
*/
|
||||
public class FunctionDeclarationPattern extends CSearchPattern {
|
||||
public class MacroDeclarationPattern extends CSearchPattern {
|
||||
|
||||
protected char[] decodedSimpleName;
|
||||
protected char[] simpleName;
|
||||
|
||||
protected char[][] parameterNames;
|
||||
|
||||
|
||||
|
||||
public FunctionDeclarationPattern(char[] name, char [][] params, int matchMode, LimitTo limitTo, boolean caseSensitive) {
|
||||
/**
|
||||
* @param name
|
||||
* @param matchMode
|
||||
* @param limitTo
|
||||
* @param caseSensitive
|
||||
*/
|
||||
public MacroDeclarationPattern(char[] name, int matchMode, LimitTo limitTo, boolean caseSensitive) {
|
||||
super( matchMode, caseSensitive, limitTo );
|
||||
|
||||
simpleName = name;
|
||||
parameterNames = params;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.search.ICSearchPattern#matchLevel(org.eclipse.cdt.core.parser.ast.IASTOffsetableElement)
|
||||
*/
|
||||
public int matchLevel(ISourceElementCallbackDelegate node, LimitTo limit ) {
|
||||
if( !( node instanceof IASTFunction ) || !canAccept( limit ) )
|
||||
if( !(node instanceof IASTMacro) || !canAccept( limit ) ){
|
||||
return IMPOSSIBLE_MATCH;
|
||||
|
||||
IASTFunction function = (IASTFunction) node;
|
||||
String nodeName = function.getName();
|
||||
}
|
||||
|
||||
String nodeName = ((IASTOffsetableNamedElement)node).getName();
|
||||
|
||||
//check name, if simpleName == null, its treated the same as "*"
|
||||
if( simpleName != null && !matchesName( simpleName, nodeName.toCharArray() ) ){
|
||||
return IMPOSSIBLE_MATCH;
|
||||
}
|
||||
|
||||
if( parameterNames != null &&
|
||||
parameterNames.length > 0 &&
|
||||
parameterNames[0].length > 0
|
||||
){
|
||||
Iterator params = function.getParameters();
|
||||
|
||||
for( int i = 0; i < parameterNames.length; i++ ){
|
||||
|
||||
//if this function doesn't have this many parameters, it is not a match.
|
||||
//or if this function has a parameter, but parameterNames only has null.
|
||||
if( !params.hasNext() || parameterNames[ i ] == null )
|
||||
return IMPOSSIBLE_MATCH;
|
||||
|
||||
IASTParameterDeclaration param = (IASTParameterDeclaration) params.next();
|
||||
IASTTypeSpecifier typeSpec = param.getTypeSpecifier();
|
||||
String paramName = null;
|
||||
if( typeSpec instanceof IASTSimpleTypeSpecifier ){
|
||||
paramName = ((IASTSimpleTypeSpecifier)typeSpec).getTypename();
|
||||
} else if( typeSpec instanceof IASTOffsetableNamedElement ){
|
||||
paramName = ((IASTOffsetableNamedElement)typeSpec).getName();
|
||||
} else {
|
||||
//???
|
||||
return IMPOSSIBLE_MATCH;
|
||||
}
|
||||
|
||||
if( !matchesName( parameterNames[i], paramName.toCharArray() ) )
|
||||
return IMPOSSIBLE_MATCH;
|
||||
}
|
||||
//if this function still has more parameters, it is not a match
|
||||
if( params.hasNext() )
|
||||
return IMPOSSIBLE_MATCH;
|
||||
}
|
||||
|
||||
return ACCURATE_MATCH;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.search.matching.CSearchPattern#feedIndexRequestor(org.eclipse.cdt.internal.core.search.IIndexSearchRequestor, int, int[], org.eclipse.cdt.internal.core.index.impl.IndexInput, org.eclipse.cdt.core.search.ICSearchScope)
|
||||
*/
|
||||
|
@ -112,12 +72,11 @@ public class FunctionDeclarationPattern extends CSearchPattern {
|
|||
IndexedFile file = input.getIndexedFile(references[i]);
|
||||
String path;
|
||||
if (file != null && scope.encloses(path =file.getPath())) {
|
||||
requestor.acceptFunctionDeclaration(path, decodedSimpleName, parameterNames.length);
|
||||
requestor.acceptMacroDeclaration(path, decodedSimpleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void resetIndexInfo(){
|
||||
decodedSimpleName = null;
|
||||
}
|
||||
|
@ -130,17 +89,19 @@ public class FunctionDeclarationPattern extends CSearchPattern {
|
|||
int size = word.length;
|
||||
|
||||
int firstSlash = CharOperation.indexOf( SEPARATOR, word, 0 );
|
||||
|
||||
int slash = CharOperation.indexOf( SEPARATOR, word, firstSlash + 1 );
|
||||
|
||||
this.decodedSimpleName = CharOperation.subarray(word, firstSlash + 1, slash);
|
||||
|
||||
this.decodedSimpleName = CharOperation.subarray(word, firstSlash + 1, -1);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.search.matching.CSearchPattern#indexEntryPrefix()
|
||||
*/
|
||||
public char[] indexEntryPrefix() {
|
||||
return AbstractIndexer.bestFunctionPrefix( _limitTo, simpleName, _matchMode, _caseSensitive );
|
||||
return AbstractIndexer.bestMacroPrefix(
|
||||
_limitTo,
|
||||
simpleName,
|
||||
_matchMode, _caseSensitive
|
||||
);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -156,4 +117,7 @@ public class FunctionDeclarationPattern extends CSearchPattern {
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected char [] simpleName;
|
||||
protected char [] decodedSimpleName;
|
||||
}
|
|
@ -13,6 +13,7 @@
|
|||
*/
|
||||
package org.eclipse.cdt.internal.core.search.matching;
|
||||
|
||||
import java.io.CharArrayReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.InputStreamReader;
|
||||
|
@ -302,24 +303,26 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
|
|||
IWorkingCopy workingCopy = (IWorkingCopy)wcPaths.get( pathString );
|
||||
|
||||
if( workingCopy != null ){
|
||||
currentResource = workingCopy.getOriginalElement().getResource();
|
||||
reader = new CharArrayReader( workingCopy.getContents() );
|
||||
currentResource = workingCopy.getResource();
|
||||
realPath = currentResource.getLocation();
|
||||
} else {
|
||||
currentResource = workspaceRoot.findMember( pathString, true );
|
||||
}
|
||||
|
||||
try{
|
||||
if( currentResource == null ){
|
||||
IPath path = new Path( pathString );
|
||||
IFile file = workspaceRoot.getFile( path );
|
||||
file.createLink( path, 0, null );
|
||||
|
||||
try{
|
||||
if( currentResource == null ){
|
||||
IPath path = new Path( pathString );
|
||||
IFile file = workspaceRoot.getFile( path );
|
||||
file.createLink( path, 0, null );
|
||||
}
|
||||
if( currentResource != null && currentResource instanceof IFile ){
|
||||
IFile file = (IFile) currentResource;
|
||||
reader = new InputStreamReader( file.getContents() );
|
||||
realPath = currentResource.getLocation();
|
||||
} else continue;
|
||||
} catch ( CoreException e ){
|
||||
continue;
|
||||
}
|
||||
if( currentResource != null && currentResource instanceof IFile ){
|
||||
IFile file = (IFile) currentResource;
|
||||
reader = new InputStreamReader( file.getContents() );
|
||||
realPath = currentResource.getLocation();
|
||||
} else continue;
|
||||
} catch ( CoreException e ){
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
IPath path = new Path( pathString );
|
||||
|
|
|
@ -14,9 +14,16 @@
|
|||
package org.eclipse.cdt.internal.core.search.matching;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
|
||||
import org.eclipse.cdt.core.parser.ast.*;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
|
||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||
import org.eclipse.cdt.internal.core.index.IEntryResult;
|
||||
import org.eclipse.cdt.internal.core.index.impl.IndexInput;
|
||||
|
@ -31,45 +38,102 @@ import org.eclipse.cdt.internal.core.search.indexing.AbstractIndexer;
|
|||
* To change the template for this generated type comment go to
|
||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||
*/
|
||||
public class MethodDeclarationPattern extends FunctionDeclarationPattern {
|
||||
|
||||
private char[][] decodedQualifications;
|
||||
|
||||
public class MethodDeclarationPattern extends CSearchPattern {
|
||||
|
||||
private SearchFor searchFor;
|
||||
|
||||
private char[][] parameterNames;
|
||||
private char[] simpleName;
|
||||
private char[][] qualifications;
|
||||
|
||||
private char[] decodedSimpleName;
|
||||
private char[][] decodedQualifications;
|
||||
|
||||
public MethodDeclarationPattern(char[] name, char[][] qual, char [][] params, int matchMode, SearchFor search, LimitTo limitTo, boolean caseSensitive) {
|
||||
//super( name, params, matchMode, limitTo, caseSensitive );
|
||||
super( matchMode, caseSensitive, limitTo );
|
||||
|
||||
public MethodDeclarationPattern(char[] name, char[][] qual, char [][] params, int matchMode, LimitTo limitTo, boolean caseSensitive) {
|
||||
super( name, params, matchMode, limitTo, caseSensitive );
|
||||
qualifications = qual;
|
||||
simpleName = name;
|
||||
parameterNames = params;
|
||||
|
||||
searchFor = search;
|
||||
}
|
||||
|
||||
|
||||
public int matchLevel(ISourceElementCallbackDelegate node, LimitTo limit ) {
|
||||
if( !(node instanceof IASTMethod) || !canAccept( limit ) ){
|
||||
if( node instanceof IASTMethod ){
|
||||
if( searchFor != METHOD || !canAccept( limit ) ){
|
||||
return IMPOSSIBLE_MATCH;
|
||||
}
|
||||
} else if ( node instanceof IASTFunction ){
|
||||
if( searchFor != FUNCTION || !canAccept( limit ) ){
|
||||
return IMPOSSIBLE_MATCH;
|
||||
}
|
||||
} else {
|
||||
return IMPOSSIBLE_MATCH;
|
||||
}
|
||||
|
||||
if( super.matchLevel( node, limit ) == IMPOSSIBLE_MATCH ){
|
||||
|
||||
IASTFunction function = (IASTFunction) node;
|
||||
String nodeName = function.getName();
|
||||
|
||||
//check name, if simpleName == null, its treated the same as "*"
|
||||
if( simpleName != null && !matchesName( simpleName, nodeName.toCharArray() ) ){
|
||||
return IMPOSSIBLE_MATCH;
|
||||
}
|
||||
|
||||
|
||||
//create char[][] out of full name,
|
||||
String [] fullName = ((IASTQualifiedNameElement) node).getFullyQualifiedName();
|
||||
char [][] qualName = new char [ fullName.length - 1 ][];
|
||||
for( int i = 0; i < fullName.length - 1; i++ ){
|
||||
qualName[i] = fullName[i].toCharArray();
|
||||
}
|
||||
|
||||
//check containing scopes
|
||||
if( !matchQualifications( qualifications, qualName ) ){
|
||||
return IMPOSSIBLE_MATCH;
|
||||
}
|
||||
|
||||
//parameters
|
||||
if( parameterNames != null && parameterNames.length > 0 && parameterNames[0].length > 0 ){
|
||||
Iterator params = function.getParameters();
|
||||
|
||||
for( int i = 0; i < parameterNames.length; i++ ){
|
||||
|
||||
//if this function doesn't have this many parameters, it is not a match.
|
||||
//or if this function has a parameter, but parameterNames only has null.
|
||||
if( !params.hasNext() || parameterNames[ i ] == null )
|
||||
return IMPOSSIBLE_MATCH;
|
||||
|
||||
IASTParameterDeclaration param = (IASTParameterDeclaration) params.next();
|
||||
IASTTypeSpecifier typeSpec = param.getTypeSpecifier();
|
||||
String paramName = null;
|
||||
if( typeSpec instanceof IASTSimpleTypeSpecifier ){
|
||||
paramName = ((IASTSimpleTypeSpecifier)typeSpec).getTypename();
|
||||
} else if( typeSpec instanceof IASTOffsetableNamedElement ){
|
||||
paramName = ((IASTOffsetableNamedElement)typeSpec).getName();
|
||||
} else {
|
||||
//???
|
||||
return IMPOSSIBLE_MATCH;
|
||||
}
|
||||
|
||||
if( !matchesName( parameterNames[i], paramName.toCharArray() ) )
|
||||
return IMPOSSIBLE_MATCH;
|
||||
}
|
||||
//if this function still has more parameters, it is not a match
|
||||
if( params.hasNext() )
|
||||
return IMPOSSIBLE_MATCH;
|
||||
}
|
||||
|
||||
return ACCURATE_MATCH;
|
||||
}
|
||||
|
||||
public char[] indexEntryPrefix() {
|
||||
return AbstractIndexer.bestMethodPrefix( _limitTo, simpleName, qualifications, _matchMode, _caseSensitive );
|
||||
if( searchFor == FUNCTION )
|
||||
return AbstractIndexer.bestFunctionPrefix( _limitTo, simpleName, _matchMode, _caseSensitive );
|
||||
else if( searchFor == METHOD )
|
||||
return AbstractIndexer.bestMethodPrefix( _limitTo, simpleName, qualifications, _matchMode, _caseSensitive );
|
||||
else return null;
|
||||
}
|
||||
|
||||
protected void resetIndexInfo(){
|
||||
|
@ -116,7 +180,10 @@ public class MethodDeclarationPattern extends FunctionDeclarationPattern {
|
|||
IndexedFile file = input.getIndexedFile(references[i]);
|
||||
String path;
|
||||
if (file != null && scope.encloses(path =file.getPath())) {
|
||||
requestor.acceptMethodDeclaration(path, decodedSimpleName, parameterNames.length, decodedQualifications);
|
||||
if( searchFor == METHOD )
|
||||
requestor.acceptMethodDeclaration(path, decodedSimpleName, parameterNames.length, decodedQualifications);
|
||||
else if ( searchFor == FUNCTION )
|
||||
requestor.acceptFunctionDeclaration(path, decodedSimpleName, parameterNames.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,18 +6,23 @@ package org.eclipse.cdt.core;
|
|||
*/
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.HashSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.core.index.IndexModel;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.resources.IConsole;
|
||||
import org.eclipse.cdt.internal.core.CDescriptorManager;
|
||||
import org.eclipse.cdt.internal.core.CPathEntry;
|
||||
import org.eclipse.cdt.internal.core.model.BufferManager;
|
||||
import org.eclipse.cdt.internal.core.model.CModelManager;
|
||||
import org.eclipse.cdt.internal.core.model.IBufferFactory;
|
||||
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IProjectDescription;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
|
@ -111,6 +116,29 @@ public class CCorePlugin extends Plugin {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Answers the shared working copies currently registered for this buffer factory.
|
||||
* Working copies can be shared by several clients using the same buffer factory,see
|
||||
* <code>IWorkingCopy.getSharedWorkingCopy</code>.
|
||||
*
|
||||
* @param factory the given buffer factory
|
||||
* @return the list of shared working copies for a given buffer factory
|
||||
* @see IWorkingCopy
|
||||
*/
|
||||
public static IWorkingCopy[] getSharedWorkingCopies(IBufferFactory factory){
|
||||
|
||||
// if factory is null, default factory must be used
|
||||
if (factory == null) factory = BufferManager.getDefaultBufferManager().getDefaultBufferFactory();
|
||||
Map sharedWorkingCopies = CModelManager.getDefault().sharedWorkingCopies;
|
||||
|
||||
Map perFactoryWorkingCopies = (Map) sharedWorkingCopies.get(factory);
|
||||
if (perFactoryWorkingCopies == null) return CModelManager.NoWorkingCopy;
|
||||
Collection copies = perFactoryWorkingCopies.values();
|
||||
IWorkingCopy[] result = new IWorkingCopy[copies.size()];
|
||||
copies.toArray(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getResourceString(String key) {
|
||||
try {
|
||||
return fgResourceBundle.getString(key);
|
||||
|
|
Loading…
Add table
Reference in a new issue