[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] Indexer/Search/UI patch
|
This patch contains the following changes:
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
- Bogdan
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/ChangeLog,v
retrieving revision 1.143
diff -u -r1.143 ChangeLog
--- ChangeLog 20 Aug 2003 17:52:23 -0000 1.143
+++ ChangeLog 20 Aug 2003 19:02:11 -0000
@@ -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
Index: src/org/eclipse/cdt/internal/ui/CPluginResources.properties
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties,v
retrieving revision 1.14
diff -u -r1.14 CPluginResources.properties
--- src/org/eclipse/cdt/internal/ui/CPluginResources.properties 26 Jun 2003 17:43:36 -0000 1.14
+++ src/org/eclipse/cdt/internal/ui/CPluginResources.properties 20 Aug 2003 19:02:11 -0000
@@ -285,6 +285,12 @@
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
Index: src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java,v
retrieving revision 1.12
diff -u -r1.12 CContentOutlinePage.java
--- src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java 5 May 2003 14:15:16 -0000 1.12
+++ src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java 20 Aug 2003 19:02:12 -0000
@@ -59,7 +59,8 @@
private OpenIncludeAction fOpenIncludeAction;
private SearchForReferencesAction fSearchForReferencesAction;
-
+ private SearchDialogAction fSearchDialogAction;
+
private MemberFilterActionGroup fMemberFilterActionGroup;
public CContentOutlinePage(CEditor editor) {
@@ -77,6 +78,7 @@
fOpenIncludeAction= new OpenIncludeAction(this);
fSearchForReferencesAction= new SearchForReferencesAction(this);
+ fSearchDialogAction = new SearchDialogAction(this, editor);
}
public ICElement getRoot() {
@@ -136,6 +138,11 @@
if (OpenIncludeAction.canActionBeAdded(getSelection())) {
menu.add(fOpenIncludeAction);
}
+
+ if (SearchDialogAction.canActionBeAdded(getSelection())) {
+ menu.add(fSearchDialogAction);
+ }
+
if (SearchForReferencesAction.canActionBeAdded(getSelection())) {
menu.add(fSearchForReferencesAction);
}
Index: src/org/eclipse/cdt/internal/ui/editor/CEditor.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java,v
retrieving revision 1.27
diff -u -r1.27 CEditor.java
--- src/org/eclipse/cdt/internal/ui/editor/CEditor.java 7 Jul 2003 15:35:44 -0000 1.27
+++ src/org/eclipse/cdt/internal/ui/editor/CEditor.java 20 Aug 2003 19:02:12 -0000
@@ -18,8 +18,8 @@
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 @@
private SearchForReferencesAction fSearchForReferencesAction;
+ private SearchDialogAction fSearchDialogAction;
+
protected ISelectionChangedListener fStatusLineClearer;
/** The property change listener */
@@ -426,6 +428,8 @@
setAction("OpenOnSelection", new OpenOnSelectionAction(this));
fSearchForReferencesAction = new SearchForReferencesAction(getSelectionProvider());
+
+ fSearchDialogAction = new SearchDialogAction(getSelectionProvider(), this);
}
public void editorContextMenuAboutToShow(IMenuManager menu) {
@@ -443,6 +447,11 @@
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);
}
Index: src/org/eclipse/cdt/internal/ui/editor/SearchDialogAction.java
===================================================================
RCS file: src/org/eclipse/cdt/internal/ui/editor/SearchDialogAction.java
diff -N src/org/eclipse/cdt/internal/ui/editor/SearchDialogAction.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/internal/ui/editor/SearchDialogAction.java 20 Aug 2003 19:02:12 -0000
@@ -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;
+ }
+
+}
Index: index/ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/index/ChangeLog,v
retrieving revision 1.12
diff -u -r1.12 ChangeLog
--- index/ChangeLog 12 Aug 2003 15:20:21 -0000 1.12
+++ index/ChangeLog 20 Aug 2003 19:00:53 -0000
@@ -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
Index: index/org/eclipse/cdt/internal/core/Util.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/Util.java,v
retrieving revision 1.1
diff -u -r1.1 Util.java
--- index/org/eclipse/cdt/internal/core/Util.java 12 Aug 2003 20:20:04 -0000 1.1
+++ index/org/eclipse/cdt/internal/core/Util.java 20 Aug 2003 19:00:53 -0000
@@ -21,7 +21,6 @@
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;
Index: index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java,v
retrieving revision 1.13
diff -u -r1.13 AbstractIndexer.java
--- index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java 12 Aug 2003 20:20:04 -0000 1.13
+++ index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java 20 Aug 2003 19:00:54 -0000
@@ -16,6 +16,7 @@
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.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 @@
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 @@
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 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 @@
//this.output.addRef(CharOperation.concat(TYPE_REF, CharOperation.lastSegment(typeName, '.')));
}
- public void addClassReference(IASTClassSpecifier reference){
- if (reference.getClassKind().equals(ASTClassKind.CLASS))
+ 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 instanceof IASTElaboratedTypeSpecifier){
+ IASTElaboratedTypeSpecifier typeRef = (IASTElaboratedTypeSpecifier) reference;
+ fullyQualifiedName = typeRef.getFullyQualifiedName();
+ classKind = typeRef.getClassKind();
+ }
+
+ if (classKind.equals(ASTClassKind.CLASS))
{
- this.output.addRef(encodeTypeEntry(reference.getFullyQualifiedName(),CLASS, ICSearchConstants.REFERENCES));
+ this.output.addRef(encodeTypeEntry(fullyQualifiedName,CLASS, ICSearchConstants.REFERENCES));
}
- else if (reference.getClassKind().equals(ASTClassKind.STRUCT))
+ else if (classKind.equals(ASTClassKind.STRUCT))
{
- this.output.addRef(encodeTypeEntry(reference.getFullyQualifiedName(),STRUCT,ICSearchConstants.REFERENCES));
+ this.output.addRef(encodeTypeEntry(fullyQualifiedName,STRUCT,ICSearchConstants.REFERENCES));
}
- else if (reference.getClassKind().equals(ASTClassKind.UNION))
+ else if (classKind.equals(ASTClassKind.UNION))
{
- this.output.addRef(encodeTypeEntry(reference.getFullyQualifiedName(),UNION,ICSearchConstants.REFERENCES));
+ this.output.addRef(encodeTypeEntry(fullyQualifiedName,UNION,ICSearchConstants.REFERENCES));
}
}
/**
@@ -234,6 +269,10 @@
System.arraycopy(tempName, 0, result, pos, tempName.length);
pos+=tempName.length;
}
+
+ if (VERBOSE)
+ AbstractIndexer.verbose(new String(result));
+
return result;
}
/**
@@ -262,6 +301,10 @@
System.arraycopy(tempName, 0, result, pos, tempName.length);
pos+=tempName.length;
}
+
+ if (VERBOSE)
+ AbstractIndexer.verbose(new String(result));
+
return result;
}
Index: index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexer.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexer.java,v
retrieving revision 1.6
diff -u -r1.6 SourceIndexer.java
--- index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexer.java 25 Jul 2003 16:45:49 -0000 1.6
+++ index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexer.java 20 Aug 2003 19:00:54 -0000
@@ -18,12 +18,16 @@
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 @@
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 @@
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" );
Index: index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexerRequestor.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexerRequestor.java,v
retrieving revision 1.11
diff -u -r1.11 SourceIndexerRequestor.java
--- index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexerRequestor.java 12 Aug 2003 20:40:04 -0000 1.11
+++ index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexerRequestor.java 20 Aug 2003 19:00:54 -0000
@@ -39,6 +39,7 @@
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 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 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 @@
// 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 @@
/* (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);
}
}
Index: search/ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/ChangeLog,v
retrieving revision 1.17
diff -u -r1.17 ChangeLog
--- search/ChangeLog 12 Aug 2003 15:20:21 -0000 1.17
+++ search/ChangeLog 20 Aug 2003 19:00:54 -0000
@@ -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
Index: search/org/eclipse/cdt/core/search/BasicSearchResultCollector.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchResultCollector.java,v
retrieving revision 1.4
diff -u -r1.4 BasicSearchResultCollector.java
--- search/org/eclipse/cdt/core/search/BasicSearchResultCollector.java 12 Aug 2003 20:20:04 -0000 1.4
+++ search/org/eclipse/cdt/core/search/BasicSearchResultCollector.java 20 Aug 2003 19:00:54 -0000
@@ -188,8 +188,17 @@
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 ){
Index: search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java,v
retrieving revision 1.11
diff -u -r1.11 ClassDeclarationPattern.java
--- search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java 12 Aug 2003 20:20:04 -0000 1.11
+++ search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java 20 Aug 2003 19:00:54 -0000
@@ -18,6 +18,7 @@
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 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 @@
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;
Index: search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java,v
retrieving revision 1.19
diff -u -r1.19 MatchLocator.java
--- search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java 12 Aug 2003 20:40:04 -0000 1.19
+++ search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java 20 Aug 2003 19:00:54 -0000
@@ -23,9 +23,12 @@
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.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 @@
Reader reader = null;
IPath realPath = null;
+ IProject project = null;
+
if( workspaceRoot != null ){
IWorkingCopy workingCopy = (IWorkingCopy)wcPaths.get( pathString );
@@ -307,6 +313,7 @@
reader = new CharArrayReader( workingCopy.getContents() );
currentResource = workingCopy.getResource();
realPath = currentResource.getLocation();
+ project = currentResource.getProject();
} else {
currentResource = workspaceRoot.findMember( pathString, true );
@@ -315,11 +322,13 @@
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 @@
}
}
- 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 @@
: offsetableElement.getStartingOffset();
length = offsetableElement.getName().length();
}
+
IMatch match = null;
if( currentResource != null ){
@@ -417,9 +434,8 @@
/* (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 );
}
Index: indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java,v
retrieving revision 1.10
diff -u -r1.10 IndexManagerTests.java
--- indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java 12 Aug 2003 22:22:58 -0000 1.10
+++ indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java 20 Aug 2003 19:01:35 -0000
@@ -94,11 +94,12 @@
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 @@
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 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 @@
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);
Index: resources/indexer/reftest.cpp
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/resources/indexer/reftest.cpp,v
retrieving revision 1.1
diff -u -r1.1 reftest.cpp
--- resources/indexer/reftest.cpp 25 Jul 2003 15:21:49 -0000 1.1
+++ resources/indexer/reftest.cpp 20 Aug 2003 19:01:35 -0000
@@ -1,5 +1,7 @@
namespace A
{
+ class ForwardA;
+ ForwardA * tmp;
int something(void);
namespace B
{