From 04453687f088c5f51595b22b872f592fea0fa99c Mon Sep 17 00:00:00 2001 From: John Camelon Date: Tue, 12 Aug 2003 15:20:21 +0000 Subject: [PATCH] Patch for Bogdan Gheorghe This patch combines the field and variable search patterns into one in order to allow qualified searches on variables. --- core/org.eclipse.cdt.core.tests/ChangeLog | 4 + .../core/search/tests/OtherPatternTests.java | 11 +- core/org.eclipse.cdt.core/index/ChangeLog | 4 + .../core/search/indexing/AbstractIndexer.java | 4 +- core/org.eclipse.cdt.core/search/ChangeLog | 4 + .../core/search/matching/CSearchPattern.java | 31 +--- .../matching/FieldDeclarationPattern.java | 56 ++++++-- .../matching/VariableDeclarationPattern.java | 135 ------------------ 8 files changed, 69 insertions(+), 180 deletions(-) delete mode 100644 core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/VariableDeclarationPattern.java diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index b1cfd6cf11c..b68a0ebdeb8 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -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 diff --git a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java index acbe13f2474..6471030a043 100644 --- a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java +++ b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java @@ -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); } diff --git a/core/org.eclipse.cdt.core/index/ChangeLog b/core/org.eclipse.cdt.core/index/ChangeLog index dbd77c5d364..2ae7a4a5377 100644 --- a/core/org.eclipse.cdt.core/index/ChangeLog +++ b/core/org.eclipse.cdt.core/index/ChangeLog @@ -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 diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java index 00993fa1075..d2b278fa613 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java @@ -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) { diff --git a/core/org.eclipse.cdt.core/search/ChangeLog b/core/org.eclipse.cdt.core/search/ChangeLog index c6faa6c46d2..b4bdf179d89 100644 --- a/core/org.eclipse.cdt.core/search/ChangeLog +++ b/core/org.eclipse.cdt.core/search/ChangeLog @@ -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 diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java index 29fb4ff8de5..fee6932ad03 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java @@ -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 ); } /** diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java index 3b215a37257..265342043ab 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java @@ -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; } diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/VariableDeclarationPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/VariableDeclarationPattern.java deleted file mode 100644 index 131a321d163..00000000000 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/VariableDeclarationPattern.java +++ /dev/null @@ -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; - -} \ No newline at end of file