1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Patch for Bogdan Gheorghe

This patch combines the field and variable search patterns into one in order to allow qualified searches on variables.
This commit is contained in:
John Camelon 2003-08-12 15:20:21 +00:00
parent 04fd4de249
commit 04453687f0
8 changed files with 69 additions and 180 deletions

View file

@ -1,3 +1,7 @@
2003-08-12 Bogdan Gheorghe
- Changed testVariableIndexPrefix, testVariableDeclaration to
reflect changes to the var search pattern
2003-08-11 Andrew Niefer
- Added testMacroPattern to OtherPatternTests
- Changed the function tests to use new function/method pattern

View file

@ -22,7 +22,6 @@ import org.eclipse.cdt.internal.core.search.CharOperation;
import org.eclipse.cdt.internal.core.search.matching.FieldDeclarationPattern;
import org.eclipse.cdt.internal.core.search.matching.NamespaceDeclarationPattern;
import org.eclipse.cdt.internal.core.search.matching.OrPattern;
import org.eclipse.cdt.internal.core.search.matching.VariableDeclarationPattern;
/**
* @author aniefer
@ -59,18 +58,18 @@ public class OtherPatternTests extends BaseSearchTest {
public void testVariableIndexPrefix(){
ICSearchPattern pattern = SearchEngine.createSearchPattern( "c", VAR, DECLARATIONS, true );
assertTrue( pattern instanceof VariableDeclarationPattern );
assertTrue( pattern instanceof FieldDeclarationPattern );
VariableDeclarationPattern variablePattern = (VariableDeclarationPattern)pattern;
FieldDeclarationPattern variablePattern = (FieldDeclarationPattern)pattern;
assertEquals( CharOperation.compareWith( "typeDecl/V/c".toCharArray(), variablePattern.indexEntryPrefix() ), 0);
variablePattern = (VariableDeclarationPattern) SearchEngine.createSearchPattern( "rt*", VAR, DECLARATIONS, true );
variablePattern = (FieldDeclarationPattern) SearchEngine.createSearchPattern( "rt*", VAR, DECLARATIONS, true );
assertEquals( CharOperation.compareWith( "typeDecl/V/rt".toCharArray(), variablePattern.indexEntryPrefix() ), 0);
variablePattern = (VariableDeclarationPattern) SearchEngine.createSearchPattern( "Ac", VAR, REFERENCES, false );
variablePattern = (FieldDeclarationPattern) SearchEngine.createSearchPattern( "Ac", VAR, REFERENCES, false );
assertEquals( CharOperation.compareWith( "typeRef/V/".toCharArray(), variablePattern.indexEntryPrefix() ), 0);
variablePattern = (VariableDeclarationPattern) SearchEngine.createSearchPattern( "A?c", VAR, REFERENCES, true );
variablePattern = (FieldDeclarationPattern) SearchEngine.createSearchPattern( "A?c", VAR, REFERENCES, true );
assertEquals( CharOperation.compareWith( "typeRef/V/A".toCharArray(), variablePattern.indexEntryPrefix() ), 0);
}

View file

@ -1,3 +1,7 @@
2003-08-12 Bogdan Gheorghe
- Changed var prefix in AbstractIndexer to pass in fully
qualified names
2003-08-11 Bogdan Gheorghe
- Added macro declarations to the index
- Added macro prefix to AbstractIndexer

View file

@ -336,7 +336,7 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
return bestPrefix( prefix, (char) 0, namespaceName, containingTypes, matchMode, isCaseSensitive );
}
public static final char[] bestVariablePrefix( LimitTo limitTo, char[] varName, int matchMode, boolean isCaseSenstive ){
public static final char[] bestVariablePrefix( LimitTo limitTo, char[] varName, char[][] containingTypes, int matchMode, boolean isCaseSenstive ){
char [] prefix = null;
if( limitTo == REFERENCES ){
prefix = TYPE_REF;
@ -346,7 +346,7 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
return TYPE_ALL;
}
return bestPrefix( prefix, VAR_SUFFIX, varName, null, matchMode, isCaseSenstive );
return bestPrefix( prefix, VAR_SUFFIX, varName, containingTypes, matchMode, isCaseSenstive );
}
public static final char[] bestFieldPrefix( LimitTo limitTo, char[] fieldName,char[][] containingTypes, int matchMode, boolean isCaseSensitive) {

View file

@ -1,3 +1,7 @@
2003-08-12 Bogdan Gheorghe
- Rolled field and variable search patterns into one pattern, in
order to allow for qualified var searches
2003-08-11 Andrew Niefer
- Added Macro ICSearchConstant
- Added acceptMacro to IIndexSearchRequestor and PathCollector

View file

@ -80,10 +80,8 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
pattern = createClassPattern( patternString, searchFor, 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 == FIELD || searchFor == VAR ){
pattern = createFieldPattern( patternString, searchFor, limitTo, matchMode, caseSensitive );
} else if ( searchFor == NAMESPACE ){
pattern = createNamespacePattern( patternString, limitTo, matchMode, caseSensitive );
} else if ( searchFor == MACRO ){
@ -170,28 +168,11 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
* @param caseSensitive
* @return
*/
private static CSearchPattern createVariablePattern(String patternString, LimitTo limitTo, int matchMode, boolean caseSensitive) {
private static CSearchPattern createFieldPattern(String patternString, SearchFor searchFor, LimitTo limitTo, int matchMode, boolean caseSensitive) {
if( limitTo == ALL_OCCURRENCES ){
OrPattern orPattern = new OrPattern();
orPattern.addPattern( createVariablePattern( patternString, DECLARATIONS, matchMode, caseSensitive ) );
orPattern.addPattern( createVariablePattern( patternString, REFERENCES, matchMode, caseSensitive ) );
return orPattern;
}
return new VariableDeclarationPattern( patternString.toCharArray(), matchMode, limitTo, caseSensitive );
}
/**
* @param patternString
* @param limitTo
* @param matchMode
* @param caseSensitive
* @return
*/
private static CSearchPattern createFieldPattern(String patternString, LimitTo limitTo, int matchMode, boolean caseSensitive) {
if( limitTo == ALL_OCCURRENCES ){
OrPattern orPattern = new OrPattern();
orPattern.addPattern( createFieldPattern( patternString, DECLARATIONS, matchMode, caseSensitive ) );
orPattern.addPattern( createFieldPattern( patternString, REFERENCES, matchMode, caseSensitive ) );
orPattern.addPattern( createFieldPattern( patternString, searchFor, DECLARATIONS, matchMode, caseSensitive ) );
orPattern.addPattern( createFieldPattern( patternString, searchFor, REFERENCES, matchMode, caseSensitive ) );
return orPattern;
}
@ -201,7 +182,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
char [] name = (char []) list.removeLast();
char [][] qualifications = new char[0][];
return new FieldDeclarationPattern( name, (char[][]) list.toArray( qualifications ), matchMode, limitTo, caseSensitive );
return new FieldDeclarationPattern( name, (char[][]) list.toArray( qualifications ), matchMode, searchFor, limitTo, caseSensitive );
}
/**

View file

@ -17,7 +17,9 @@ import java.io.IOException;
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
import org.eclipse.cdt.core.parser.ast.IASTField;
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement;
import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.impl.IndexInput;
@ -33,7 +35,7 @@ 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 FieldDeclarationPattern extends VariableDeclarationPattern {
public class FieldDeclarationPattern extends CSearchPattern {
/**
* @param name
@ -42,18 +44,27 @@ public class FieldDeclarationPattern extends VariableDeclarationPattern {
* @param limitTo
* @param caseSensitive
*/
public FieldDeclarationPattern(char[] name, char[][] qual, int matchMode, LimitTo limitTo, boolean caseSensitive) {
super( name, matchMode, limitTo, caseSensitive );
public FieldDeclarationPattern(char[] name, char[][] qual, int matchMode, SearchFor sfor, LimitTo limitTo, boolean caseSensitive) {
super( matchMode, caseSensitive, limitTo );
qualifications = qual;
searchFor = sfor;
simpleName = name;
}
public int matchLevel(ISourceElementCallbackDelegate node, LimitTo limit ) {
if( !(node instanceof IASTField) ){
return IMPOSSIBLE_MATCH;
}
if( node instanceof IASTField ){
if( searchFor != FIELD || !canAccept( limit ) )
return IMPOSSIBLE_MATCH;
} else if ( node instanceof IASTVariable ){
if( searchFor != VAR || !canAccept( limit ) )
return IMPOSSIBLE_MATCH;
} else return IMPOSSIBLE_MATCH;
if( super.matchLevel( node, limit ) == IMPOSSIBLE_MATCH ){
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;
}
@ -73,7 +84,16 @@ public class FieldDeclarationPattern extends VariableDeclarationPattern {
}
public char[] indexEntryPrefix() {
return AbstractIndexer.bestFieldPrefix( _limitTo, simpleName, qualifications, _matchMode, _caseSensitive );
if( searchFor == FIELD ){
return AbstractIndexer.bestFieldPrefix( _limitTo, simpleName, qualifications, _matchMode, _caseSensitive );
} else if( searchFor == VAR ) {
return AbstractIndexer.bestVariablePrefix(
_limitTo,
simpleName, qualifications,
_matchMode, _caseSensitive
);
}
return null;
}
protected void resetIndexInfo(){
@ -84,11 +104,18 @@ public class FieldDeclarationPattern extends VariableDeclarationPattern {
protected void decodeIndexEntry(IEntryResult entryResult) {
char[] word = entryResult.getWord();
int size = word.length;
int firstSlash = 0;
int slash = 0;
int firstSlash = CharOperation.indexOf( SEPARATOR, word, 0 );
int slash = CharOperation.indexOf(SEPARATOR, word, firstSlash + 1);
if( searchFor == FIELD ){
firstSlash = CharOperation.indexOf( SEPARATOR, word, 0 );
slash = CharOperation.indexOf(SEPARATOR, word, firstSlash + 1);
} else if( searchFor == VAR ) {
int realStart = CharOperation.indexOf( SEPARATOR, word, 0 );
firstSlash = CharOperation.indexOf( SEPARATOR, word, realStart + 1);
slash = CharOperation.indexOf(SEPARATOR, word, firstSlash + 1);
}
this.decodedSimpleName = CharOperation.subarray(word, firstSlash + 1, slash);
if( slash != -1 && slash+1 < size ){
@ -130,4 +157,9 @@ public class FieldDeclarationPattern extends VariableDeclarationPattern {
private char [][] qualifications;
private char [][] decodedQualifications;
private char [] simpleName;
private char [] decodedSimpleName;
private char decodedType;
private SearchFor searchFor;
}

View file

@ -1,135 +0,0 @@
/*******************************************************************************
* Copyright (c) 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
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Corp. - Rational Software - initial implementation
******************************************************************************/
/*
* Created on Jul 11, 2003
*/
package org.eclipse.cdt.internal.core.search.matching;
import java.io.IOException;
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
import org.eclipse.cdt.core.parser.ast.IASTVariable;
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 VariableDeclarationPattern extends CSearchPattern {
/**
* @param name
* @param matchMode
* @param limitTo
* @param caseSensitive
*/
public VariableDeclarationPattern(char[] name, int matchMode, LimitTo limitTo, boolean caseSensitive) {
super( matchMode, caseSensitive, limitTo );
simpleName = name;
}
/* (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 IASTVariable) || !canAccept( limit ) ){
return IMPOSSIBLE_MATCH;
}
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;
}
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)
*/
public void feedIndexRequestor(IIndexSearchRequestor requestor, int detailLevel, int[] references, IndexInput input, ICSearchScope scope) throws IOException {
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())) {
requestor.acceptVariableDeclaration(path, decodedSimpleName);
}
}
}
protected void resetIndexInfo(){
decodedType = 0;
decodedSimpleName = null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.search.matching.CSearchPattern#decodeIndexEntry(org.eclipse.cdt.internal.core.index.IEntryResult)
*/
protected void decodeIndexEntry(IEntryResult entryResult) {
char[] word = entryResult.getWord();
int size = word.length;
int firstSlash = CharOperation.indexOf( SEPARATOR, word, 0 );
this.decodedType = word[ firstSlash + 1 ];
firstSlash += 2;
int slash = CharOperation.indexOf(SEPARATOR, word, firstSlash + 1);
this.decodedSimpleName = CharOperation.subarray(word, firstSlash + 1, slash);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.search.matching.CSearchPattern#indexEntryPrefix()
*/
public char[] indexEntryPrefix() {
return AbstractIndexer.bestVariablePrefix(
_limitTo,
simpleName,
_matchMode, _caseSensitive
);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.search.matching.CSearchPattern#matchIndexEntry()
*/
protected boolean matchIndexEntry() {
if( decodedType != VAR_SUFFIX ){
return false;
}
/* check simple name matches */
if (simpleName != null){
if( ! matchesName( simpleName, decodedSimpleName ) ){
return false;
}
}
return true;
}
protected char [] simpleName;
protected char [] decodedSimpleName;
protected char decodedType;
}