1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Patch for Andrew Niefer

fix bug 43129 - report definitions for variables, fields, enumerators and 
namespaces.

core:
- check definitions for variables, fields, enumerators and namespaces
- handle enter/exitLinkageSpecification
  * search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java
  * 
search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java

core.tests:
-added testbug43129() in OtherPatternTests
modified:
* resources/search/include.h
* resources/search/classDecl.cpp
* search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java

ui:
 modify UI to allow selecting Definitions for more items
* src/org/eclipse/cdt/internal/ui/search/CSearchPage.java
This commit is contained in:
John Camelon 2003-09-26 14:58:17 +00:00
parent db4d819623
commit 05f6b423c8
9 changed files with 145 additions and 13 deletions

View file

@ -1,3 +1,10 @@
2003-09-25 Andrew Niefer
-bug43129 - Cannot search for definitions of global variables
-added testbug43129() in OtherPatternTests
* resources/search/include.h
* resources/search/classDecl.cpp
* search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java
2003-09-25 Hoda Amer 2003-09-25 Hoda Amer
Enabled CompleteParseASTExpressionTest.testPostfixTypenameIdentifier() Enabled CompleteParseASTExpressionTest.testPostfixTypenameIdentifier()

View file

@ -61,4 +61,18 @@ Head * Head::operator *= ( int index ){
Head * Head::operator += ( int index ){ Head * Head::operator += ( int index ){
return array[ index ]; return array[ index ];
} }
extern int externalInt;
extern int externalIntWithInitializer = 2;
extern "C" int externCInt;
extern "C" int externCIntWithInitializer = 3;
void forwardFunction() { }
void normalFunction() { }
void DeclsAndDefns::forwardMethod(){ }
int DeclsAndDefns::staticField = 5;

View file

@ -9,4 +9,15 @@ class Head {
Head ** array; Head ** array;
}; };
class DeclsAndDefns{
static int staticField;
int nonStaticField;
void forwardMethod();
void inlineMethod() {}
};
void forwardFunction();
#endif #endif

View file

@ -240,6 +240,73 @@ public class OtherPatternTests extends BaseSearchTest {
assertEquals( matches.size(), 3 ); assertEquals( matches.size(), 3 );
} }
public void testBug43129(){
ICSearchPattern pattern = SearchEngine.createSearchPattern( "externalInt", VAR, DECLARATIONS, true );
search( workspace, pattern, scope, resultCollector );
Set matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 1 );
pattern = SearchEngine.createSearchPattern( "externalInt", VAR, DEFINITIONS, true );
search( workspace, pattern, scope, resultCollector );
matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 0 );
pattern = SearchEngine.createSearchPattern( "externalIntWithInitializer", VAR, DECLARATIONS, true );
search( workspace, pattern, scope, resultCollector );
matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 1 );
pattern = SearchEngine.createSearchPattern( "externalIntWithInitializer", VAR, DEFINITIONS, true );
search( workspace, pattern, scope, resultCollector );
matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 1 );
pattern = SearchEngine.createSearchPattern( "externCInt", VAR, DECLARATIONS, true );
search( workspace, pattern, scope, resultCollector );
matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 1 );
pattern = SearchEngine.createSearchPattern( "externCInt", VAR, DEFINITIONS, true );
search( workspace, pattern, scope, resultCollector );
matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 0 );
pattern = SearchEngine.createSearchPattern( "externCIntWithInitializer", VAR, DECLARATIONS, true );
search( workspace, pattern, scope, resultCollector );
matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 1 );
pattern = SearchEngine.createSearchPattern( "externCIntWithInitializer", VAR, DEFINITIONS, true );
search( workspace, pattern, scope, resultCollector );
matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 1 );
pattern = SearchEngine.createSearchPattern( "forwardFunction", FUNCTION, ALL_OCCURRENCES, true );
search( workspace, pattern, scope, resultCollector );
matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 2 );
pattern = SearchEngine.createSearchPattern( "normalFunction", FUNCTION, DECLARATIONS, true );
search( workspace, pattern, scope, resultCollector );
matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 1 );
pattern = SearchEngine.createSearchPattern( "normalFunction", FUNCTION, DEFINITIONS, true );
search( workspace, pattern, scope, resultCollector );
matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 1 );
pattern = SearchEngine.createSearchPattern( "forwardMethod", METHOD, ALL_OCCURRENCES, true );
search( workspace, pattern, scope, resultCollector );
matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 2 );
pattern = SearchEngine.createSearchPattern( "staticField", FIELD, ALL_OCCURRENCES, true );
search( workspace, pattern, scope, resultCollector );
matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 2 );
}
public void testNoResourceSearching(){ public void testNoResourceSearching(){
String pluginRoot = org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.core.tests").find(new Path("/")).getFile(); String pluginRoot = org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.core.tests").find(new Path("/")).getFile();
String path = pluginRoot + "resources/search/include.h"; String path = pluginRoot + "resources/search/include.h";
@ -256,5 +323,4 @@ public class OtherPatternTests extends BaseSearchTest {
Set matches = resultCollector.getSearchResults(); Set matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 4 ); assertEquals( matches.size(), 4 );
} }
} }

View file

@ -1,3 +1,10 @@
2003-09-25 Andrew Niefer
- bug43129 - Cannot search for definitions of global variables
- check definitions for variables, fields, enumerators and namespaces
- handle enter/exitLinkageSpecification
* search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java
* search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java
2003-09-25 Andrew Niefer 2003-09-25 Andrew Niefer
- partial fix for 43664 Modify Matchlocator to not try and create a link if we have no - partial fix for 43664 Modify Matchlocator to not try and create a link if we have no
resource, instead just use the path resource, instead just use the path

View file

@ -132,6 +132,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
if( limitTo == ALL_OCCURRENCES ){ if( limitTo == ALL_OCCURRENCES ){
OrPattern orPattern = new OrPattern(); OrPattern orPattern = new OrPattern();
orPattern.addPattern( createNamespacePattern( patternString, DECLARATIONS, matchMode, caseSensitive ) ); orPattern.addPattern( createNamespacePattern( patternString, DECLARATIONS, matchMode, caseSensitive ) );
orPattern.addPattern( createNamespacePattern( patternString, DEFINITIONS, matchMode, caseSensitive ) );
orPattern.addPattern( createNamespacePattern( patternString, REFERENCES, matchMode, caseSensitive ) ); orPattern.addPattern( createNamespacePattern( patternString, REFERENCES, matchMode, caseSensitive ) );
return orPattern; return orPattern;
} }
@ -190,6 +191,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
OrPattern orPattern = new OrPattern(); OrPattern orPattern = new OrPattern();
orPattern.addPattern( createFieldPattern( patternString, searchFor, DECLARATIONS, matchMode, caseSensitive ) ); orPattern.addPattern( createFieldPattern( patternString, searchFor, DECLARATIONS, matchMode, caseSensitive ) );
orPattern.addPattern( createFieldPattern( patternString, searchFor, REFERENCES, matchMode, caseSensitive ) ); orPattern.addPattern( createFieldPattern( patternString, searchFor, REFERENCES, matchMode, caseSensitive ) );
orPattern.addPattern( createFieldPattern( patternString, searchFor, DEFINITIONS, matchMode, caseSensitive ) );
return orPattern; return orPattern;
} }

View file

@ -116,7 +116,6 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
public void acceptASMDefinition(IASTASMDefinition asmDefinition) { } public void acceptASMDefinition(IASTASMDefinition asmDefinition) { }
public void acceptAbstractTypeSpecDeclaration(IASTAbstractTypeSpecifierDeclaration abstractDeclaration) {} public void acceptAbstractTypeSpecDeclaration(IASTAbstractTypeSpecifierDeclaration abstractDeclaration) {}
public void enterLinkageSpecification(IASTLinkageSpecification linkageSpec) { }
public void enterTemplateDeclaration(IASTTemplateDeclaration declaration) { } public void enterTemplateDeclaration(IASTTemplateDeclaration declaration) { }
public void enterTemplateSpecialization(IASTTemplateSpecialization specialization) { } public void enterTemplateSpecialization(IASTTemplateSpecialization specialization) { }
public void enterTemplateInstantiation(IASTTemplateInstantiation instantiation) { } public void enterTemplateInstantiation(IASTTemplateInstantiation instantiation) { }
@ -124,11 +123,17 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
public void exitTemplateDeclaration(IASTTemplateDeclaration declaration) {} public void exitTemplateDeclaration(IASTTemplateDeclaration declaration) {}
public void exitTemplateSpecialization(IASTTemplateSpecialization specialization) { } public void exitTemplateSpecialization(IASTTemplateSpecialization specialization) { }
public void exitTemplateExplicitInstantiation(IASTTemplateInstantiation instantiation) { } public void exitTemplateExplicitInstantiation(IASTTemplateInstantiation instantiation) { }
public void exitLinkageSpecification(IASTLinkageSpecification linkageSpec) { }
public void enterCodeBlock(IASTCodeScope scope) { } public void enterCodeBlock(IASTCodeScope scope) { }
public void exitCodeBlock(IASTCodeScope scope) { } public void exitCodeBlock(IASTCodeScope scope) { }
public void enterLinkageSpecification(IASTLinkageSpecification linkageSpec){
pushScope( linkageSpec );
}
public void exitLinkageSpecification(IASTLinkageSpecification linkageSpec){
popScope();
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptParameterReference(org.eclipse.cdt.internal.core.parser.ast.complete.ASTParameterReference) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptParameterReference(org.eclipse.cdt.internal.core.parser.ast.complete.ASTParameterReference)
@ -157,12 +162,27 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
public void acceptVariable(IASTVariable variable){ public void acceptVariable(IASTVariable variable){
lastDeclaration = variable; lastDeclaration = variable;
check( DECLARATIONS, variable );
check( DECLARATIONS, variable );
//A declaration is a definition unless...:
//it contains the extern specifier or a linkage-spec and no initializer
if( variable.getInitializerClause() != null ||
( !variable.isExtern() && !(currentScope instanceof IASTLinkageSpecification) ) ){
check( DEFINITIONS, variable );
}
} }
public void acceptField(IASTField field){ public void acceptField(IASTField field){
lastDeclaration = field; lastDeclaration = field;
check( DECLARATIONS, field ); if( currentScope instanceof IASTClassSpecifier ){
check( DECLARATIONS, field );
if( !field.isStatic() ){
check( DEFINITIONS, field );
}
} else {
check( DEFINITIONS, field );
}
} }
public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration){ public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration){
@ -173,6 +193,7 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
IASTEnumerator enumerator = (IASTEnumerator) iter.next(); IASTEnumerator enumerator = (IASTEnumerator) iter.next();
lastDeclaration = enumerator; lastDeclaration = enumerator;
check ( DECLARATIONS, enumerator ); check ( DECLARATIONS, enumerator );
check ( DEFINITIONS, enumerator );
} }
} }
@ -240,6 +261,7 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
public void enterNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) { public void enterNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) {
lastDeclaration = namespaceDefinition; lastDeclaration = namespaceDefinition;
check( DECLARATIONS, namespaceDefinition ); check( DECLARATIONS, namespaceDefinition );
check( DEFINITIONS, namespaceDefinition );
pushScope( namespaceDefinition ); pushScope( namespaceDefinition );
} }

View file

@ -1,3 +1,8 @@
2003-09-25 Andrew Niefer
-bug43129 - Search: Cannot search for definitions of global variables
- modify UI to allow selecting Definitions for more items
* src/org/eclipse/cdt/internal/ui/search/CSearchPage.java
2003-09-25 Hoda Amer 2003-09-25 Hoda Amer
Solution to bug#43646: Code Assist won't work if missing end bracket Solution to bug#43646: Code Assist won't work if missing end bracket

View file

@ -295,19 +295,17 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
private void setLimitTo( List searchFor ) { private void setLimitTo( List searchFor ) {
HashSet set = new HashSet(); HashSet set = new HashSet();
set.add( DEFINITIONS );
set.add( DECLARATIONS ); set.add( DECLARATIONS );
set.add( REFERENCES ); set.add( REFERENCES );
set.add( ALL_OCCURRENCES ); set.add( ALL_OCCURRENCES );
for (Iterator iter = searchFor.iterator(); iter.hasNext();) { for (Iterator iter = searchFor.iterator(); iter.hasNext();) {
SearchFor element = (SearchFor) iter.next(); SearchFor element = (SearchFor) iter.next();
if( element != FUNCTION && element != METHOD ){ if( element == FUNCTION || element == METHOD || element == VAR || element == FIELD || element == NAMESPACE ){
set.remove( DEFINITIONS ); set.add( DEFINITIONS );
break; break;
} }
} }
for( int i = 0; i < fLimitTo.length; i++ ) for( int i = 0; i < fLimitTo.length; i++ )