mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 08:55:25 +02:00
Patch for Bogdan Gheorghe:
Indexer - Added additional file extensions to supported indexed files - Changed the parser instantiation to pass in retrieved build info - Added function decl index entry based on enterFunctionBody - Added method decl index entry based on enterMethodBody - Added forward decl refs - Added debug tracing to AbstractIndexer Search - Changed matching and reporting functions to handle nodes of type IElaboratedTypeSpecifier UI - Added a search dialog pop up item to the context menu for the CEditor and CContentOutlinePage
This commit is contained in:
parent
301de9ca43
commit
a80d2f71de
16 changed files with 396 additions and 40 deletions
|
@ -94,11 +94,12 @@ public class IndexManagerTests extends TestCase {
|
|||
suite.addTest(new IndexManagerTests("testRemoveProjectFromIndex"));
|
||||
suite.addTest(new IndexManagerTests("testRefs"));
|
||||
suite.addTest(new IndexManagerTests("testMacros"));
|
||||
suite.addTest(new IndexManagerTests("testForwardDeclarations"));
|
||||
suite.addTest(new IndexManagerTests("testDependencyTree"));
|
||||
suite.addTest(new IndexManagerTests("testIndexShutdown"));
|
||||
|
||||
return suite;
|
||||
//return new TestSuite(IndexManagerTests.class);
|
||||
// return new TestSuite(IndexManagerTests.class);
|
||||
}
|
||||
/*
|
||||
* Utils
|
||||
|
@ -374,7 +375,7 @@ public class IndexManagerTests extends TestCase {
|
|||
IIndex ind = indexManager.getIndex(testProjectPath,true,true);
|
||||
assertTrue("Index exists for project",ind != null);
|
||||
|
||||
String [] typeRefEntryResultModel ={"EntryResult: word=typeRef/C/C/B/A, refs={ 1 }", "EntryResult: word=typeRef/E/e1/B/A, refs={ 1 }", "EntryResult: word=typeRef/V/x/B/A, refs={ 1 }"};
|
||||
String [] typeRefEntryResultModel ={"EntryResult: word=typeRef/C/C/B/A, refs={ 1 }", "EntryResult: word=typeRef/C/ForwardA/A, refs={ 1 }", "EntryResult: word=typeRef/E/e1/B/A, refs={ 1 }", "EntryResult: word=typeRef/V/x/B/A, refs={ 1 }"};
|
||||
IEntryResult[] typerefresults = ind.queryEntries(IIndexConstants.TYPE_REF);
|
||||
|
||||
if (typerefresults.length != typeRefEntryResultModel.length)
|
||||
|
@ -496,6 +497,49 @@ public class IndexManagerTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void testForwardDeclarations() throws Exception{
|
||||
//Add a new file to the project, give it some time to index
|
||||
importFile("refTest.cpp","resources/indexer/refTest.cpp");
|
||||
//Enable indexing on the created project
|
||||
//By doing this, we force the Index Manager to indexAll()
|
||||
indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager();
|
||||
indexManager.setEnabled(testProject,true);
|
||||
Thread.sleep(TIMEOUT);
|
||||
//Make sure project got added to index
|
||||
IPath testProjectPath = testProject.getFullPath();
|
||||
IIndex ind = indexManager.getIndex(testProjectPath,true,true);
|
||||
assertTrue("Index exists for project",ind != null);
|
||||
|
||||
IEntryResult[] fwdDclResults = ind.queryEntries("typeDecl/C/ForwardA/A".toCharArray());
|
||||
|
||||
String [] fwdDclModel = {"EntryResult: word=typeDecl/C/ForwardA/A, refs={ 1 }"};
|
||||
|
||||
if (fwdDclResults.length != fwdDclModel.length)
|
||||
fail("Entry Result length different from model for forward declarations");
|
||||
|
||||
for (int i=0;i<fwdDclResults.length; i++)
|
||||
{
|
||||
assertEquals(fwdDclModel[i],fwdDclResults[i].toString());
|
||||
}
|
||||
|
||||
IEntryResult[] fwdDclRefResults = ind.queryEntries("typeRef/C/ForwardA/A".toCharArray());
|
||||
|
||||
String [] fwdDclRefModel = {"EntryResult: word=typeRef/C/ForwardA/A, refs={ 1 }"};
|
||||
|
||||
if (fwdDclRefResults.length != fwdDclRefModel.length)
|
||||
fail("Entry Result length different from model for forward declarations refs");
|
||||
|
||||
for (int i=0;i<fwdDclRefResults.length; i++)
|
||||
{
|
||||
assertEquals(fwdDclRefModel[i],fwdDclRefResults[i].toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void testFunctionDeclarations2() throws Exception{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void testDependencyTree() throws Exception{
|
||||
//Add a file to the project
|
||||
IFile depTest = importFile("DepTest.cpp","resources/dependency/DepTest.cpp");
|
||||
|
@ -511,8 +555,8 @@ public class IndexManagerTests extends TestCase {
|
|||
DependencyManager dependencyManager = CCorePlugin.getDefault().getCoreModel().getDependencyManager();
|
||||
dependencyManager.setEnabled(testProject,true);
|
||||
Thread.sleep(10000);
|
||||
String[] depTestModel = {"\\IndexerTestProject\\d.h", "\\IndexerTestProject\\Inc1.h", "\\IndexerTestProject\\c.h", "\\IndexerTestProject\\a.h", "\\IndexerTestProject\\DepTest.h"};
|
||||
String[] depTest2Model = {"\\IndexerTestProject\\d.h", "\\IndexerTestProject\\DepTest2.h"};
|
||||
String[] depTestModel = {File.separator + "IndexerTestProject" + File.separator + "d.h", File.separator + "IndexerTestProject" + File.separator + "Inc1.h", File.separator + "IndexerTestProject" + File.separator + "c.h", File.separator + "IndexerTestProject" + File.separator + "a.h", File.separator + "IndexerTestProject" + File.separator + "DepTest.h"};
|
||||
String[] depTest2Model = {File.separator + "IndexerTestProject" + File.separator + "d.h", File.separator + "IndexerTestProject" + File.separator + "DepTest2.h"};
|
||||
|
||||
ArrayList includes = new ArrayList();
|
||||
dependencyManager.performConcurrentJob(new DependencyQueryJob(testProject,depTest,dependencyManager,includes),ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,null);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
namespace A
|
||||
{
|
||||
class ForwardA;
|
||||
ForwardA * tmp;
|
||||
int something(void);
|
||||
namespace B
|
||||
{
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
2003-08-20 Bogdan Gheorghe
|
||||
- Added debug tracing in AbstractIndexer
|
||||
- Added additional file extensions to supported indexed files
|
||||
- Changed the parser instantiation to pass in retrieved build
|
||||
info
|
||||
- Added function decl index entry based on enterFunctionBody
|
||||
- Added method decl index entry based on enterMethodBody
|
||||
- Added forward decl refs
|
||||
|
||||
2003-08-14 Bogdan Gheorghe
|
||||
- Added forward declarations to index
|
||||
|
||||
2003-08-12 Bogdan Gheorghe
|
||||
- Changed var prefix in AbstractIndexer to pass in fully
|
||||
qualified names
|
||||
|
|
|
@ -21,7 +21,6 @@ import java.util.Locale;
|
|||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import org.eclipse.cdt.internal.core.*;
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
|
|
@ -16,6 +16,7 @@ import java.util.Iterator;
|
|||
|
||||
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTField;
|
||||
|
@ -23,6 +24,7 @@ import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
|||
import org.eclipse.cdt.core.parser.ast.IASTMacro;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
||||
import org.eclipse.cdt.core.search.ICSearchConstants;
|
||||
|
@ -40,10 +42,16 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
|
|||
final static int ENUM = 4;
|
||||
final static int VAR = 5;
|
||||
|
||||
public static boolean VERBOSE = false;
|
||||
|
||||
public AbstractIndexer() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static void verbose(String log) {
|
||||
System.out.println("(" + Thread.currentThread() + ") " + log); //$NON-NLS-1$//$NON-NLS-2$
|
||||
}
|
||||
|
||||
public void addClassSpecifier(IASTClassSpecifier classSpecification){
|
||||
|
||||
if (classSpecification.getClassKind().equals(ASTClassKind.CLASS))
|
||||
|
@ -89,12 +97,10 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
|
|||
this.output.addRef(encodeTypeEntry(enumeration.getFullyQualifiedName(), ENUM, ICSearchConstants.REFERENCES));
|
||||
}
|
||||
public void addVariable(IASTVariable variable) {
|
||||
|
||||
this.output.addRef(encodeTypeEntry(variable.getFullyQualifiedName(), VAR, ICSearchConstants.DECLARATIONS));
|
||||
}
|
||||
|
||||
public void addVariableReference(IASTVariable variable) {
|
||||
|
||||
this.output.addRef(encodeTypeEntry(variable.getFullyQualifiedName(), VAR, ICSearchConstants.REFERENCES));
|
||||
}
|
||||
|
||||
|
@ -117,6 +123,21 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
|
|||
public void addMethodReference(IASTMethod method) {
|
||||
this.output.addRef(encodeEntry(method.getFullyQualifiedName(),METHOD_REF,METHOD_REF_LENGTH));
|
||||
}
|
||||
|
||||
public void addElaboratedForwardDeclaration(IASTElaboratedTypeSpecifier elaboratedType) {
|
||||
if (elaboratedType.getClassKind().equals(ASTClassKind.CLASS))
|
||||
{
|
||||
this.output.addRef(encodeTypeEntry(elaboratedType.getFullyQualifiedName(),CLASS, ICSearchConstants.DECLARATIONS));
|
||||
}
|
||||
else if (elaboratedType.getClassKind().equals(ASTClassKind.STRUCT))
|
||||
{
|
||||
this.output.addRef(encodeTypeEntry(elaboratedType.getFullyQualifiedName(),STRUCT, ICSearchConstants.DECLARATIONS));
|
||||
}
|
||||
else if (elaboratedType.getClassKind().equals(ASTClassKind.UNION))
|
||||
{
|
||||
this.output.addRef(encodeTypeEntry(elaboratedType.getFullyQualifiedName(),UNION, ICSearchConstants.DECLARATIONS));
|
||||
}
|
||||
}
|
||||
|
||||
public void addConstructorDeclaration(){
|
||||
|
||||
|
@ -160,18 +181,32 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
|
|||
//this.output.addRef(CharOperation.concat(TYPE_REF, CharOperation.lastSegment(typeName, '.')));
|
||||
}
|
||||
|
||||
public void addClassReference(IASTClassSpecifier reference){
|
||||
if (reference.getClassKind().equals(ASTClassKind.CLASS))
|
||||
{
|
||||
this.output.addRef(encodeTypeEntry(reference.getFullyQualifiedName(),CLASS, ICSearchConstants.REFERENCES));
|
||||
}
|
||||
else if (reference.getClassKind().equals(ASTClassKind.STRUCT))
|
||||
{
|
||||
this.output.addRef(encodeTypeEntry(reference.getFullyQualifiedName(),STRUCT,ICSearchConstants.REFERENCES));
|
||||
public void addClassReference(IASTTypeSpecifier reference){
|
||||
String[] fullyQualifiedName = null;
|
||||
ASTClassKind classKind = null;
|
||||
|
||||
if (reference instanceof IASTClassSpecifier){
|
||||
IASTClassSpecifier classRef = (IASTClassSpecifier) reference;
|
||||
fullyQualifiedName = classRef.getFullyQualifiedName();
|
||||
classKind = classRef.getClassKind();
|
||||
}
|
||||
else if (reference.getClassKind().equals(ASTClassKind.UNION))
|
||||
else if (reference instanceof IASTElaboratedTypeSpecifier){
|
||||
IASTElaboratedTypeSpecifier typeRef = (IASTElaboratedTypeSpecifier) reference;
|
||||
fullyQualifiedName = typeRef.getFullyQualifiedName();
|
||||
classKind = typeRef.getClassKind();
|
||||
}
|
||||
|
||||
if (classKind.equals(ASTClassKind.CLASS))
|
||||
{
|
||||
this.output.addRef(encodeTypeEntry(fullyQualifiedName,CLASS, ICSearchConstants.REFERENCES));
|
||||
}
|
||||
else if (classKind.equals(ASTClassKind.STRUCT))
|
||||
{
|
||||
this.output.addRef(encodeTypeEntry(reference.getFullyQualifiedName(),UNION,ICSearchConstants.REFERENCES));
|
||||
this.output.addRef(encodeTypeEntry(fullyQualifiedName,STRUCT,ICSearchConstants.REFERENCES));
|
||||
}
|
||||
else if (classKind.equals(ASTClassKind.UNION))
|
||||
{
|
||||
this.output.addRef(encodeTypeEntry(fullyQualifiedName,UNION,ICSearchConstants.REFERENCES));
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
@ -234,6 +269,10 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
|
|||
System.arraycopy(tempName, 0, result, pos, tempName.length);
|
||||
pos+=tempName.length;
|
||||
}
|
||||
|
||||
if (VERBOSE)
|
||||
AbstractIndexer.verbose(new String(result));
|
||||
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
|
@ -262,6 +301,10 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
|
|||
System.arraycopy(tempName, 0, result, pos, tempName.length);
|
||||
pos+=tempName.length;
|
||||
}
|
||||
|
||||
if (VERBOSE)
|
||||
AbstractIndexer.verbose(new String(result));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,12 +18,16 @@ package org.eclipse.cdt.internal.core.search.indexing;
|
|||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.parser.IParser;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
|
||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.internal.core.index.IDocument;
|
||||
import org.eclipse.cdt.internal.core.parser.ScannerInfo;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
|
||||
/**
|
||||
* A SourceIndexer indexes source files using the parser. The following items are indexed:
|
||||
|
@ -39,7 +43,7 @@ import org.eclipse.cdt.internal.core.parser.ScannerInfo;
|
|||
public class SourceIndexer extends AbstractIndexer {
|
||||
|
||||
//TODO: Indexer, add additional file types
|
||||
public static final String[] FILE_TYPES= new String[] {"cpp","h"}; //$NON-NLS-1$
|
||||
public static final String[] FILE_TYPES= new String[] {"cpp","h","c", "cc", "hh", "cxx", "hpp"}; //$NON-NLS-1$
|
||||
//protected DefaultProblemFactory problemFactory= new DefaultProblemFactory(Locale.getDefault());
|
||||
IFile resourceFile;
|
||||
|
||||
|
@ -58,11 +62,31 @@ public class SourceIndexer extends AbstractIndexer {
|
|||
output.addDocument(document);
|
||||
// Create a new Parser
|
||||
SourceIndexerRequestor requestor = new SourceIndexerRequestor(this, document);
|
||||
|
||||
//Get the scanner info
|
||||
IProject currentProject = resourceFile.getProject();
|
||||
IScannerInfo scanInfo = new ScannerInfo();
|
||||
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(currentProject);
|
||||
if (provider != null){
|
||||
IScannerInfo buildScanInfo = provider.getScannerInformation(currentProject);
|
||||
if (buildScanInfo != null){
|
||||
scanInfo = new ScannerInfo(buildScanInfo.getDefinedSymbols(), buildScanInfo.getIncludePaths());
|
||||
}
|
||||
}
|
||||
|
||||
IParser parser = ParserFactory.createParser(
|
||||
ParserFactory.createScanner( new StringReader( document.getStringContent() ), resourceFile.getLocation().toOSString(), new ScannerInfo(), ParserMode.COMPLETE_PARSE, requestor ),
|
||||
ParserFactory.createScanner( new StringReader( document.getStringContent() ), resourceFile.getLocation().toOSString(), scanInfo, ParserMode.COMPLETE_PARSE, requestor ),
|
||||
requestor, ParserMode.COMPLETE_PARSE);
|
||||
|
||||
try{
|
||||
parser.parse();
|
||||
boolean retVal = parser.parse();
|
||||
|
||||
if (VERBOSE){
|
||||
if (!retVal)
|
||||
AbstractIndexer.verbose("PARSE FAILED " + resourceFile.getName().toString());
|
||||
else
|
||||
AbstractIndexer.verbose("PARSE SUCCEEDED " + resourceFile.getName().toString());
|
||||
}
|
||||
}
|
||||
catch( Exception e ){
|
||||
System.out.println( "Parse Exception in SourceIndexer" );
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.eclipse.cdt.core.parser.ast.IASTNamespaceReference;
|
|||
import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTTypedefReference;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
|
||||
|
@ -148,7 +149,8 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo
|
|||
*/
|
||||
public void enterFunctionBody(IASTFunction function) {
|
||||
// TODO Auto-generated method stub
|
||||
//System.out.println("enterFunctionBody");
|
||||
indexer.addFunctionDeclaration(function);
|
||||
//indexer.addFunctionDefinition();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -245,7 +247,8 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo
|
|||
*/
|
||||
public void enterMethodBody(IASTMethod method) {
|
||||
// TODO Auto-generated method stub
|
||||
//System.out.println("enterMethodBody");
|
||||
//System.out.println("enterMethodBody " + method.getName());
|
||||
indexer.addMethodDeclaration(method);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -272,8 +275,11 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo
|
|||
// TODO Auto-generated method stub
|
||||
//System.out.println("acceptClassReference");
|
||||
if (reference.getReferencedElement() instanceof IASTClassSpecifier)
|
||||
indexer.addClassReference((IASTClassSpecifier)reference.getReferencedElement());
|
||||
|
||||
indexer.addClassReference((IASTClassSpecifier)reference.getReferencedElement());
|
||||
else if (reference.getReferencedElement() instanceof IASTElaboratedTypeSpecifier)
|
||||
{
|
||||
indexer.addClassReference((IASTTypeSpecifier) reference.getReferencedElement());
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -407,8 +413,7 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptElaboratedForewardDeclaration(org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier)
|
||||
*/
|
||||
public void acceptElaboratedForewardDeclaration(IASTElaboratedTypeSpecifier elaboratedType)
|
||||
{
|
||||
// TODO BOGDAN IMPLEMENT THIS
|
||||
public void acceptElaboratedForewardDeclaration(IASTElaboratedTypeSpecifier elaboratedType){
|
||||
indexer.addElaboratedForwardDeclaration(elaboratedType);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
2003-08-20 Bogdan Gheorghe
|
||||
- Changed matching and reporting functions to handle nodes
|
||||
of type IElaboratedTypeSpecifier
|
||||
|
||||
2003-08-12 Bogdan Gheorghe
|
||||
- Rolled field and variable search patterns into one pattern, in
|
||||
order to allow for qualified var searches
|
||||
|
|
|
@ -188,8 +188,17 @@ public class BasicSearchResultCollector implements ICSearchResultCollector {
|
|||
|
||||
private void setElementInfo( BasicSearchMatch match, IASTOffsetableElement node ){
|
||||
//ImageDescriptor imageDescriptor = null;
|
||||
if( node instanceof IASTClassSpecifier ){
|
||||
ASTClassKind kind = ((IASTClassSpecifier)node).getClassKind();
|
||||
if( node instanceof IASTClassSpecifier ||
|
||||
node instanceof IASTElaboratedTypeSpecifier ){
|
||||
|
||||
ASTClassKind kind = null;
|
||||
if (node instanceof IASTClassSpecifier){
|
||||
kind = ((IASTClassSpecifier)node).getClassKind();
|
||||
}
|
||||
else{
|
||||
kind = ((IASTElaboratedTypeSpecifier)node).getClassKind();
|
||||
}
|
||||
|
||||
if( kind == ASTClassKind.CLASS ){
|
||||
match.type = ICElement.C_CLASS;
|
||||
} else if ( kind == ASTClassKind.STRUCT ){
|
||||
|
|
|
@ -18,6 +18,7 @@ import java.io.IOException;
|
|||
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
|
||||
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement;
|
||||
|
@ -59,13 +60,21 @@ public class ClassDeclarationPattern extends CSearchPattern {
|
|||
|
||||
public int matchLevel( ISourceElementCallbackDelegate node, LimitTo limit ){
|
||||
|
||||
if( !( node instanceof IASTClassSpecifier ) && !( node instanceof IASTEnumerationSpecifier ) )
|
||||
if( !( node instanceof IASTClassSpecifier ) && !( node instanceof IASTEnumerationSpecifier ) && !(node instanceof IASTElaboratedTypeSpecifier) )
|
||||
return IMPOSSIBLE_MATCH;
|
||||
|
||||
if( ! canAccept( limit ) )
|
||||
return IMPOSSIBLE_MATCH;
|
||||
|
||||
String nodeName = ((IASTOffsetableNamedElement)node).getName();
|
||||
String nodeName = null;
|
||||
if (node instanceof IASTElaboratedTypeSpecifier)
|
||||
{
|
||||
nodeName = ((IASTElaboratedTypeSpecifier)node).getName();
|
||||
}
|
||||
else
|
||||
{
|
||||
nodeName = ((IASTOffsetableNamedElement)node).getName();
|
||||
}
|
||||
|
||||
//check name, if simpleName == null, its treated the same as "*"
|
||||
if( simpleName != null && !matchesName( simpleName, nodeName.toCharArray() ) ){
|
||||
|
@ -88,9 +97,13 @@ public class ClassDeclarationPattern extends CSearchPattern {
|
|||
if( node instanceof IASTClassSpecifier ){
|
||||
IASTClassSpecifier clsSpec = (IASTClassSpecifier) node;
|
||||
return ( classKind == clsSpec.getClassKind() ) ? ACCURATE_MATCH : IMPOSSIBLE_MATCH;
|
||||
} else {
|
||||
} else if (node instanceof IASTEnumerationSpecifier){
|
||||
return ( classKind == ASTClassKind.ENUM ) ? ACCURATE_MATCH : IMPOSSIBLE_MATCH;
|
||||
}
|
||||
} else if (node instanceof IASTElaboratedTypeSpecifier ){
|
||||
IASTElaboratedTypeSpecifier elabTypeSpec = (IASTElaboratedTypeSpecifier) node;
|
||||
return ( classKind == elabTypeSpec.getClassKind() ) ? ACCURATE_MATCH : IMPOSSIBLE_MATCH;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return ACCURATE_MATCH;
|
||||
|
|
|
@ -23,9 +23,12 @@ import java.util.HashMap;
|
|||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.parser.IParser;
|
||||
import org.eclipse.cdt.core.parser.IProblem;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
|
||||
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
|
||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||
|
@ -69,6 +72,7 @@ import org.eclipse.cdt.core.search.IMatch;
|
|||
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.internal.core.parser.ScannerInfo;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
|
@ -300,6 +304,8 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
|
|||
Reader reader = null;
|
||||
|
||||
IPath realPath = null;
|
||||
IProject project = null;
|
||||
|
||||
if( workspaceRoot != null ){
|
||||
IWorkingCopy workingCopy = (IWorkingCopy)wcPaths.get( pathString );
|
||||
|
||||
|
@ -307,6 +313,7 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
|
|||
reader = new CharArrayReader( workingCopy.getContents() );
|
||||
currentResource = workingCopy.getResource();
|
||||
realPath = currentResource.getLocation();
|
||||
project = currentResource.getProject();
|
||||
} else {
|
||||
currentResource = workspaceRoot.findMember( pathString, true );
|
||||
|
||||
|
@ -315,11 +322,13 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
|
|||
IPath path = new Path( pathString );
|
||||
IFile file = workspaceRoot.getFile( path );
|
||||
file.createLink( path, 0, null );
|
||||
project = file.getProject();
|
||||
}
|
||||
if( currentResource != null && currentResource instanceof IFile ){
|
||||
IFile file = (IFile) currentResource;
|
||||
reader = new InputStreamReader( file.getContents() );
|
||||
realPath = currentResource.getLocation();
|
||||
project = file.getProject();
|
||||
} else continue;
|
||||
} catch ( CoreException e ){
|
||||
continue;
|
||||
|
@ -336,7 +345,14 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
|
|||
}
|
||||
}
|
||||
|
||||
IScanner scanner = ParserFactory.createScanner( reader, realPath.toOSString(), new ScannerInfo(), ParserMode.COMPLETE_PARSE, this );
|
||||
//Get the scanner info
|
||||
IScannerInfo scanInfo = new ScannerInfo();
|
||||
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project);
|
||||
if (provider != null){
|
||||
IScannerInfo buildScanInfo = provider.getScannerInformation(project);
|
||||
scanInfo = new ScannerInfo(buildScanInfo.getDefinedSymbols(), buildScanInfo.getIncludePaths());
|
||||
}
|
||||
IScanner scanner = ParserFactory.createScanner( reader, realPath.toOSString(), scanInfo, ParserMode.COMPLETE_PARSE, this );
|
||||
IParser parser = ParserFactory.createParser( scanner, this, ParserMode.COMPLETE_PARSE );
|
||||
|
||||
parser.parse();
|
||||
|
@ -358,6 +374,7 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
|
|||
: offsetableElement.getStartingOffset();
|
||||
length = offsetableElement.getName().length();
|
||||
}
|
||||
|
||||
|
||||
IMatch match = null;
|
||||
if( currentResource != null ){
|
||||
|
@ -417,9 +434,8 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptElaboratedForewardDeclaration(org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier)
|
||||
*/
|
||||
public void acceptElaboratedForewardDeclaration(IASTElaboratedTypeSpecifier elaboratedType)
|
||||
{
|
||||
//TODO BOGDAN IMPLEMENT THIS
|
||||
public void acceptElaboratedForewardDeclaration(IASTElaboratedTypeSpecifier elaboratedType){
|
||||
check( DECLARATIONS, elaboratedType );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
2003-08-20 Bogdan Gheorghe
|
||||
Added a search dialog pop up to the context menu for the
|
||||
CEditor and CContentOutlinePage
|
||||
|
||||
2003-08-19 Keith Campbell
|
||||
Extended CView and CViewDragAdapter to use LocalSelectionTransfer.
|
||||
Eventually this will permit dragging elements from the "C/C++ Projects" view
|
||||
|
|
|
@ -285,6 +285,12 @@ SearchForReferencesAction.label=Reference&s
|
|||
SearchForReferencesAction.tooltip=Search for References to Name in Workspace
|
||||
SearchForReferencesAction.description=Searches for references to name in workspace
|
||||
|
||||
# ------- SearchDialogAction ---------------
|
||||
SearchDialogAction.label=Dialog
|
||||
SearchDialogAction.tooltip=Opens Search Dialog
|
||||
SearchDialogAction.description=Opens Search Dialog
|
||||
|
||||
|
||||
# ------- LexicalSortingAction------------
|
||||
|
||||
LexicalSortingAction.label=Sort
|
||||
|
|
|
@ -59,7 +59,8 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS
|
|||
|
||||
private OpenIncludeAction fOpenIncludeAction;
|
||||
private SearchForReferencesAction fSearchForReferencesAction;
|
||||
|
||||
private SearchDialogAction fSearchDialogAction;
|
||||
|
||||
private MemberFilterActionGroup fMemberFilterActionGroup;
|
||||
|
||||
public CContentOutlinePage(CEditor editor) {
|
||||
|
@ -77,6 +78,7 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS
|
|||
|
||||
fOpenIncludeAction= new OpenIncludeAction(this);
|
||||
fSearchForReferencesAction= new SearchForReferencesAction(this);
|
||||
fSearchDialogAction = new SearchDialogAction(this, editor);
|
||||
}
|
||||
|
||||
public ICElement getRoot() {
|
||||
|
@ -136,6 +138,11 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS
|
|||
if (OpenIncludeAction.canActionBeAdded(getSelection())) {
|
||||
menu.add(fOpenIncludeAction);
|
||||
}
|
||||
|
||||
if (SearchDialogAction.canActionBeAdded(getSelection())) {
|
||||
menu.add(fSearchDialogAction);
|
||||
}
|
||||
|
||||
if (SearchForReferencesAction.canActionBeAdded(getSelection())) {
|
||||
menu.add(fSearchForReferencesAction);
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@ import org.eclipse.cdt.core.model.ISourceRange;
|
|||
import org.eclipse.cdt.core.model.ISourceReference;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.internal.ui.editor.asm.AsmTextTools;
|
||||
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
|
||||
import org.eclipse.cdt.internal.ui.editor.asm.AsmTextTools;
|
||||
import org.eclipse.cdt.internal.ui.text.CPairMatcher;
|
||||
import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration;
|
||||
import org.eclipse.cdt.internal.ui.text.CTextTools;
|
||||
|
@ -98,6 +98,8 @@ public class CEditor extends TextEditor implements ISelectionChangedListener {
|
|||
|
||||
private SearchForReferencesAction fSearchForReferencesAction;
|
||||
|
||||
private SearchDialogAction fSearchDialogAction;
|
||||
|
||||
protected ISelectionChangedListener fStatusLineClearer;
|
||||
|
||||
/** The property change listener */
|
||||
|
@ -426,6 +428,8 @@ public class CEditor extends TextEditor implements ISelectionChangedListener {
|
|||
setAction("OpenOnSelection", new OpenOnSelectionAction(this));
|
||||
|
||||
fSearchForReferencesAction = new SearchForReferencesAction(getSelectionProvider());
|
||||
|
||||
fSearchDialogAction = new SearchDialogAction(getSelectionProvider(), this);
|
||||
}
|
||||
|
||||
public void editorContextMenuAboutToShow(IMenuManager menu) {
|
||||
|
@ -443,6 +447,11 @@ public class CEditor extends TextEditor implements ISelectionChangedListener {
|
|||
|
||||
MenuManager search = new MenuManager("Search", IContextMenuConstants.GROUP_SEARCH); //$NON-NLS-1$
|
||||
menu.appendToGroup(ITextEditorActionConstants.GROUP_FIND, search);
|
||||
|
||||
if (SearchDialogAction.canActionBeAdded(getSelectionProvider().getSelection())){
|
||||
search.add(fSearchDialogAction);
|
||||
}
|
||||
|
||||
if (SearchForReferencesAction.canActionBeAdded(getSelectionProvider().getSelection())) {
|
||||
search.add(fSearchForReferencesAction);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* Created on Aug 12, 2003
|
||||
*
|
||||
* To change the template for this generated file go to
|
||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||
*/
|
||||
package org.eclipse.cdt.internal.ui.editor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.ISelectionProvider;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.search.ui.SearchUI;
|
||||
import org.eclipse.ui.IEditorDescriptor;
|
||||
import org.eclipse.ui.IEditorRegistry;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.texteditor.ITextEditor;
|
||||
|
||||
/**
|
||||
* @author bgheorgh
|
||||
*
|
||||
* To change the template for this generated type comment go to
|
||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||
*/
|
||||
public class SearchDialogAction extends Action {
|
||||
|
||||
private static final String PREFIX= "SearchDialogAction.";
|
||||
private static final String C_SEARCH_PAGE_ID= "org.eclipse.cdt.ui.CSearchPage";
|
||||
|
||||
private ISelectionProvider fSelectionProvider;
|
||||
private ITextEditor fEditor;
|
||||
|
||||
public SearchDialogAction(ISelectionProvider provider, CEditor editor) {
|
||||
super(CUIPlugin.getResourceString(PREFIX + "label"));
|
||||
setDescription(CUIPlugin.getResourceString(PREFIX + "description"));
|
||||
setToolTipText(CUIPlugin.getResourceString(PREFIX + "tooltip"));
|
||||
|
||||
if(provider instanceof CContentOutlinePage) {
|
||||
CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, CPluginImages.IMG_MENU_OPEN_INCLUDE);
|
||||
setText("Dialog"); // $NON-NLS
|
||||
}
|
||||
|
||||
fSelectionProvider= provider;
|
||||
fEditor = editor;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
String search_name;
|
||||
|
||||
ISelection selection= fSelectionProvider.getSelection();
|
||||
if(selection instanceof ITextSelection) {
|
||||
search_name = ((ITextSelection)selection).getText();
|
||||
if(search_name.length() == 0) return;
|
||||
} else {
|
||||
ICElement element= getElement(selection);
|
||||
if (element == null) {
|
||||
return;
|
||||
}
|
||||
search_name = element.getElementName();
|
||||
}
|
||||
|
||||
SearchUI.openSearchDialog(fEditor.getEditorSite().getWorkbenchWindow(),C_SEARCH_PAGE_ID);
|
||||
|
||||
// // @@@ we rely on the internal functions of the Search plugin, since
|
||||
// // none of these are actually exported. This is probably going to change
|
||||
// // with 2.0.
|
||||
// TextSearchResultCollector col = new TextSearchResultCollector();
|
||||
// try {
|
||||
// //TextSearchPage
|
||||
// //ProgressMonitor monitor = new ProgressMonitor();
|
||||
// //col.setProgressMonitor(monitor)
|
||||
// SearchUI.activateSearchResultView();
|
||||
// //col.aboutToStart();
|
||||
//
|
||||
// // We now have the element, start a search on the string
|
||||
// //TextSearchEngine engine = new TextSearchEngine();
|
||||
// TextSearchScope scope= TextSearchScope.newWorkspaceScope();
|
||||
// // Add the extensions from the C editor definition for now
|
||||
// // FIXME: For C/C++ not all files rely on extension to be C++ for <cstring>
|
||||
// String[] cexts = CoreModel.getDefault().getTranslationUnitExtensions();
|
||||
// for (int i = 0; i < cexts.length; i++) {
|
||||
// scope.addExtension("*." + cexts[i]);
|
||||
// }
|
||||
//// scope.addExtension("*.c");
|
||||
//// scope.addExtension("*.h");
|
||||
//// scope.addExtension("*.cc");
|
||||
//// scope.addExtension("*.hh");
|
||||
//
|
||||
// TextSearchOperation op= new TextSearchOperation(
|
||||
// CUIPlugin.getWorkspace(),
|
||||
// search_name,
|
||||
// "",
|
||||
// scope,
|
||||
// col);
|
||||
//
|
||||
//
|
||||
// //engine.search(CUIPlugin.getWorkspace(), element.getName(),
|
||||
// // null, scope, col);
|
||||
// IRunnableContext context= null;
|
||||
// //context= getContainer().getRunnableContext();
|
||||
//
|
||||
// Shell shell= new Shell(); // getShell();
|
||||
// if (context == null)
|
||||
// context= new ProgressMonitorDialog(shell);
|
||||
//
|
||||
//
|
||||
// try {
|
||||
// context.run(true, true, op);
|
||||
// } catch (InvocationTargetException ex) {
|
||||
// ExceptionHandler.handle(ex, "Error","Error"); //$NON-NLS-2$ //$NON-NLS-1$
|
||||
// } catch (InterruptedException e) {
|
||||
// }
|
||||
// } catch (Exception e) {}
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
private static ICElement getElement(ISelection sel) {
|
||||
if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
|
||||
List list= ((IStructuredSelection)sel).toList();
|
||||
if (list.size() == 1) {
|
||||
Object element= list.get(0);
|
||||
if (element instanceof ICElement) {
|
||||
return (ICElement)element;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean canActionBeAdded(ISelection selection) {
|
||||
if(selection instanceof ITextSelection) {
|
||||
return (((ITextSelection)selection).getLength() > 0);
|
||||
} else {
|
||||
return getElement(selection) != null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String getEditorID(String name) {
|
||||
IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
|
||||
if (registry != null) {
|
||||
IEditorDescriptor descriptor = registry.getDefaultEditor(name);
|
||||
if (descriptor != null) {
|
||||
return descriptor.getId();
|
||||
} else {
|
||||
return registry.getDefaultEditor().getId();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue