1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Fix for 172842, IndexView holds on to index-bindings.

This commit is contained in:
Markus Schorn 2007-06-29 11:16:09 +00:00
parent 8bc05fc9c1
commit a7927f6fa4
13 changed files with 497 additions and 379 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2006 QNX Software Systems
* Copyright (c) 2005, 2007 QNX Software Systems
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
*
* Contributors:
* QNX Software Systems - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.indexview;
@ -35,8 +36,8 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
*/
public class CountNodeAction extends IndexAction {
public CountNodeAction(TreeViewer viewer) {
super(viewer, CUIPlugin.getResourceString("IndexView.CountSymbols.name")); //$NON-NLS-1$
public CountNodeAction(IndexView view, TreeViewer viewer) {
super(view, viewer, CUIPlugin.getResourceString("IndexView.CountSymbols.name")); //$NON-NLS-1$
}
public boolean valid() {
@ -74,43 +75,60 @@ public class CountNodeAction extends IndexAction {
final PDOM pdom = (PDOM)CCoreInternals.getPDOMManager().getPDOM(project);
//pdom.getDB().reportFreeBlocks();
pdom.getFileIndex().accept(new IBTreeVisitor() {
public int compare(int record) throws CoreException {
return 0;
}
public boolean visit(int record) throws CoreException {
if (record != 0) {
PDOMFile file = new PDOMFile(pdom, record);
++count[FILES];
PDOMMacro macro = file.getFirstMacro();
while (macro != null) {
++count[MACROS];
macro = macro.getNextMacro();
pdom.acquireReadLock();
try {
pdom.getFileIndex().accept(new IBTreeVisitor() {
public int compare(int record) throws CoreException {
return 0;
}
public boolean visit(int record) throws CoreException {
if (record != 0) {
PDOMFile file = new PDOMFile(pdom, record);
++count[FILES];
PDOMMacro macro = file.getFirstMacro();
while (macro != null) {
++count[MACROS];
macro = macro.getNextMacro();
}
}
return true;
}
return true;
}
});
pdom.accept(new IPDOMVisitor() {
public boolean visit(IPDOMNode node) throws CoreException {
++count[SYMBOLS];
if (node instanceof PDOMBinding) {
PDOMBinding binding = (PDOMBinding)node;
for (PDOMName name = binding.getFirstReference(); name != null; name = name.getNextInBinding())
++count[REFS];
for (PDOMName name = binding.getFirstDeclaration(); name != null; name = name.getNextInBinding())
++count[DECLS];
for (PDOMName name = binding.getFirstDefinition(); name != null; name = name.getNextInBinding())
++count[DEFS];
});
pdom.accept(new IPDOMVisitor() {
public boolean visit(IPDOMNode node)
throws CoreException {
++count[SYMBOLS];
if (node instanceof PDOMBinding) {
PDOMBinding binding = (PDOMBinding) node;
for (PDOMName name = binding
.getFirstReference(); name != null; name = name
.getNextInBinding())
++count[REFS];
for (PDOMName name = binding
.getFirstDeclaration(); name != null; name = name
.getNextInBinding())
++count[DECLS];
for (PDOMName name = binding
.getFirstDefinition(); name != null; name = name
.getNextInBinding())
++count[DEFS];
}
return true;
}
return true;
}
public void leave(IPDOMNode node) throws CoreException {
}
});
public void leave(IPDOMNode node) throws CoreException {
}
});
} finally {
pdom.releaseReadLock();
}
}
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
MessageDialog.openInformation(null,

View file

@ -1,12 +1,13 @@
/*******************************************************************************
* Copyright (c) 2006 IBM and others.
* Copyright (c) 2006, 2007 IBM and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
* IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.indexview;
@ -24,19 +25,17 @@ import org.eclipse.jface.viewers.TreeViewer;
*
*/
public class DiscardExternalDefsAction extends IndexAction {
final IndexView view;
public DiscardExternalDefsAction(TreeViewer viewer, IndexView view) {
super(viewer, CUIPlugin.getResourceString("IndexView.ToggleExternals.name"), IAction.AS_CHECK_BOX); //$NON-NLS-1$
super(view, viewer, CUIPlugin.getResourceString("IndexView.ToggleExternals.name"), IAction.AS_CHECK_BOX); //$NON-NLS-1$
setToolTipText(CUIPlugin.getResourceString("IndexView.ToggleExternals.tooltip")); //$NON-NLS-1$
CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, "public_co.gif"); //$NON-NLS-1$
this.view = view;
}
public void run() {
ISelection selection = viewer.getSelection();
if (!(selection instanceof IStructuredSelection))
return;
view.toggleExternalDefs();
indexView.toggleExternalDefs();
}
public boolean valid() {

View file

@ -1,12 +1,13 @@
/*******************************************************************************
* Copyright (c) 2006 QNX Software Systems and others.
* Copyright (c) 2006, 2007 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.indexview;
@ -17,9 +18,9 @@ import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.search.PDOMSearchBindingQuery;
import org.eclipse.cdt.internal.ui.search.PDOMSearchQuery;
/**
@ -28,33 +29,42 @@ import org.eclipse.cdt.internal.ui.search.PDOMSearchQuery;
*/
public class FindDeclarationsAction extends IndexAction {
public FindDeclarationsAction(TreeViewer viewer) {
super(viewer, CUIPlugin.getResourceString("IndexView.findDeclarations.name")); //$NON-NLS-1$
public FindDeclarationsAction(IndexView view, TreeViewer viewer) {
super(view, viewer, CUIPlugin.getResourceString("IndexView.findDeclarations.name")); //$NON-NLS-1$
}
private IIndexBinding getBinding() {
private IndexNode getBindingNode() {
ISelection selection = viewer.getSelection();
if (!(selection instanceof IStructuredSelection))
return null;
Object[] objs = ((IStructuredSelection)selection).toArray();
return (objs.length == 1 && objs[0] instanceof IIndexBinding)
? (IIndexBinding)objs[0] : null;
if (objs.length == 1 && objs[0] instanceof IndexNode) {
IndexNode node= (IndexNode) objs[0];
if (node.fObject instanceof IIndexBinding) {
return node;
}
}
return null;
}
public void run() {
IIndexBinding binding = getBinding();
PDOMSearchBindingQuery query = new PDOMSearchBindingQuery(
null,
binding,
PDOMSearchQuery.FIND_DECLARATIONS | PDOMSearchQuery.FIND_DEFINITIONS);
NewSearchUI.activateSearchResultView();
NewSearchUI.runQueryInBackground(query);
IndexNode binding = getBindingNode();
if (binding != null) {
ICProject cproject= binding.getProject();
if (cproject != null) {
IndexViewSearchQuery query = new IndexViewSearchQuery(
null,
cproject, indexView.getLastWriteAccess(cproject),
(IIndexBinding) binding.fObject, binding.fText,
PDOMSearchQuery.FIND_DECLARATIONS | PDOMSearchQuery.FIND_DEFINITIONS);
NewSearchUI.activateSearchResultView();
NewSearchUI.runQueryInBackground(query);
}
}
}
public boolean valid() {
return getBinding() != null;
return getBindingNode() != null;
}
}

View file

@ -1,20 +1,21 @@
/*******************************************************************************
* Copyright (c) 2006 QNX Software Systems and others.
* Copyright (c) 2006, 2007 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.indexview;
import org.eclipse.cdt.internal.ui.search.PDOMSearchBindingQuery;
import org.eclipse.cdt.internal.ui.search.PDOMSearchQuery;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
@ -27,32 +28,42 @@ import org.eclipse.search.ui.NewSearchUI;
*/
public class FindReferencesAction extends IndexAction {
public FindReferencesAction(TreeViewer viewer) {
super(viewer, CUIPlugin.getResourceString("IndexView.findReferences.name")); //$NON-NLS-1$
public FindReferencesAction(IndexView view, TreeViewer viewer) {
super(view, viewer, CUIPlugin.getResourceString("IndexView.findReferences.name")); //$NON-NLS-1$
}
private IIndexBinding getBinding() {
private IndexNode getBindingNode() {
ISelection selection = viewer.getSelection();
if (!(selection instanceof IStructuredSelection))
return null;
Object[] objs = ((IStructuredSelection)selection).toArray();
return (objs.length == 1 && objs[0] instanceof IIndexBinding)
? (IIndexBinding)objs[0] : null;
if (objs.length == 1 && objs[0] instanceof IndexNode) {
IndexNode node= (IndexNode) objs[0];
if (node.fObject instanceof IIndexBinding) {
return node;
}
}
return null;
}
public void run() {
PDOMSearchBindingQuery query = new PDOMSearchBindingQuery(
null,
getBinding(),
PDOMSearchQuery.FIND_REFERENCES);
NewSearchUI.activateSearchResultView();
NewSearchUI.runQueryInBackground(query);
IndexNode binding = getBindingNode();
if (binding != null) {
ICProject cproject= binding.getProject();
if (cproject != null) {
IndexViewSearchQuery query = new IndexViewSearchQuery(
null,
cproject, indexView.getLastWriteAccess(cproject),
(IIndexBinding) binding.fObject, binding.fText,
PDOMSearchQuery.FIND_REFERENCES);
NewSearchUI.activateSearchResultView();
NewSearchUI.runQueryInBackground(query);
}
}
}
public boolean valid() {
return getBinding() != null;
return getBindingNode() != null;
}
}

View file

@ -1,12 +1,13 @@
/*******************************************************************************
* Copyright (c) 2006 QNX Software Systems and others.
* Copyright (c) 2006, 2007 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.indexview;
@ -23,25 +24,30 @@ import org.eclipse.jface.viewers.TreeViewer;
*/
public abstract class IndexAction extends Action {
protected TreeViewer viewer;
final protected IndexView indexView;
final protected TreeViewer viewer;
protected IndexAction(TreeViewer viewer) {
protected IndexAction(IndexView view, TreeViewer viewer) {
super();
this.indexView= view;
this.viewer = viewer;
}
protected IndexAction(TreeViewer viewer, String text) {
protected IndexAction(IndexView view, TreeViewer viewer, String text) {
super(text);
this.indexView= view;
this.viewer = viewer;
}
protected IndexAction(TreeViewer viewer, String text, ImageDescriptor image) {
protected IndexAction(IndexView view, TreeViewer viewer, String text, ImageDescriptor image) {
super(text, image);
this.indexView= view;
this.viewer = viewer;
}
protected IndexAction(TreeViewer viewer, String text, int style) {
protected IndexAction(IndexView view, TreeViewer viewer, String text, int style) {
super(text, style);
this.indexView= view;
this.viewer = viewer;
}

View file

@ -6,14 +6,14 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
* IBM Corporation
* Andrew Ferguson (Symbian)
* Bryan Wilkinson (QNX)
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
* IBM Corporation
* Andrew Ferguson (Symbian)
* Bryan Wilkinson (QNX)
*******************************************************************************/
package org.eclipse.cdt.internal.ui;
package org.eclipse.cdt.internal.ui.indexview;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.resource.ImageDescriptor;
@ -22,6 +22,7 @@ import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
@ -47,8 +48,8 @@ import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
/**
@ -58,9 +59,36 @@ import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
*/
public class IndexLabelProvider extends LabelProvider {
public String getText(Object element) {
if (element == null) {
return "null :("; //$NON-NLS-1$
} else if (element instanceof PDOMNode) {
if (element instanceof IndexNode) {
return ((IndexNode) element).fText;
}
return super.getText(element);
}
public Image getImage(Object element) {
if (element instanceof IndexNode) {
return ((IndexNode) element).fImage;
}
ImageDescriptor desc= null;
if (element instanceof ICProject)
desc = CPluginImages.DESC_OBJS_SEARCHHIERPROJECT;
else if (element instanceof ICContainer)
desc = CPluginImages.DESC_OBJS_SEARCHHIERFODLER;
else if (element instanceof ITranslationUnit) {
ITranslationUnit tu = (ITranslationUnit)element;
desc = tu.isHeaderUnit()
? CPluginImages.DESC_OBJS_TUNIT_HEADER
: CPluginImages.DESC_OBJS_TUNIT;
}
if (desc != null)
return CUIPlugin.getImageDescriptorRegistry().get(desc);
return super.getImage(element);
}
public static String getText(IPDOMNode element) {
if (element instanceof PDOMNamedNode) {
try {
String result = ((PDOMNamedNode)element).getDBName().getString();
@ -139,11 +167,11 @@ public class IndexLabelProvider extends LabelProvider {
} catch (CoreException e) {
return e.getMessage();
}
} else
return super.getText(element);
}
return ""; //$NON-NLS-1$
}
public Image getImage(Object element) {
public static Image getImage(IPDOMNode element) {
ImageDescriptor desc = null;
if (element instanceof IVariable)
@ -177,23 +205,13 @@ public class IndexLabelProvider extends LabelProvider {
desc = CElementImageProvider.getEnumeratorImageDescriptor();
else if (element instanceof ITypedef)
desc = CElementImageProvider.getTypedefImageDescriptor();
else if (element instanceof ICProject)
desc = CPluginImages.DESC_OBJS_SEARCHHIERPROJECT;
else if (element instanceof ICContainer)
desc = CPluginImages.DESC_OBJS_SEARCHHIERFODLER;
else if (element instanceof ITranslationUnit) {
ITranslationUnit tu = (ITranslationUnit)element;
desc = tu.isHeaderUnit()
? CPluginImages.DESC_OBJS_TUNIT_HEADER
: CPluginImages.DESC_OBJS_TUNIT;
}
if (desc != null)
return CUIPlugin.getImageDescriptorRegistry().get(desc);
else if (element instanceof PDOMLinkage)
return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
else
return super.getImage(element);
return null;
}
}

View file

@ -0,0 +1,65 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.indexview;
import org.eclipse.swt.graphics.Image;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.model.ICProject;
class IndexNode {
Object fParent;
IPDOMNode fObject;
String fText;
Image fImage;
boolean fHasDeclarationInProject;
public ICProject getProject() {
if (fParent instanceof IndexNode) {
return ((IndexNode) fParent).getProject();
}
if (fParent instanceof ICProject) {
return (ICProject) fParent;
}
return null;
}
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((fParent == null) ? 0 : fParent.hashCode());
result = prime * result + ((fText == null) ? 0 : fText.hashCode());
return result;
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final IndexNode other = (IndexNode) obj;
if (fParent == null) {
if (other.fParent != null)
return false;
} else if (!fParent.equals(other.fParent))
return false;
if (fText == null) {
if (other.fText != null)
return false;
} else if (!fText.equals(other.fText))
return false;
return true;
}
}

View file

@ -6,20 +6,19 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
* Andrew Ferguson (Symbian)
* QNX - Initial API and implementation
* Andrew Ferguson (Symbian)
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.indexview;
import java.util.Arrays;
import java.util.Comparator;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
@ -28,21 +27,23 @@ import org.eclipse.jface.action.Separator;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ElementChangedEvent;
@ -57,9 +58,9 @@ import org.eclipse.cdt.internal.core.CCoreInternals;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.cdt.internal.ui.IndexLabelProvider;
import org.eclipse.cdt.internal.ui.viewsupport.AsyncTreeContentProvider;
import org.eclipse.cdt.internal.ui.viewsupport.ExtendedTreeViewer;
/**
* @author Doug Schaefer
@ -68,7 +69,6 @@ import org.eclipse.cdt.internal.ui.IndexLabelProvider;
public class IndexView extends ViewPart implements PDOM.IListener, IElementChangedListener {
private TreeViewer viewer;
// private DrillDownAdapter drillDownAdapter;
private ToggleLinkingAction toggleLinkingAction;
private IndexAction countSymbolsAction;
private IndexAction discardExternalDefsAction;
@ -78,14 +78,17 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
Filter filter = new Filter();
public boolean isLinking = false;
private volatile boolean fUpdateRequested= false;
private Map fTimestampPerProject= new HashMap();
private IndexContentProvider contentProvider;
public void toggleExternalDefs() {
filter.showExternalDefs = ! filter.showExternalDefs;
if (!filter.showExternalDefs) {
viewer.addFilter(filter);
} else {
viewer.removeFilter(filter);
}
filter.showExternalDefs = ! filter.showExternalDefs;
}
public void toggleLinking() {
@ -100,9 +103,6 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
* editor (if option enabled)
*/
void handleSelectionChanged(SelectionChangedEvent event) {
// final IStructuredSelection selection = (IStructuredSelection) event.getSelection();
// updateStatusLine(selection);
// updateActionBars(selection);
if (isLinking) {
openDefinitionAction.run();
}
@ -111,190 +111,189 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
private static class Filter extends ViewerFilter {
public boolean showExternalDefs = false;
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof PDOMBinding) {
PDOMBinding binding = (PDOMBinding)element;
try {
PDOMName name = binding.getFirstReference();
if (name == null)
name = binding.getFirstDeclaration();
if (name == null)
name = binding.getFirstDefinition();
if (name == null)
return false;
IASTFileLocation location = name.getFileLocation();
IPath path = new Path(location.getFileName());
Object input = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
if (input == null)
return false;
return true;
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
return true;
}
if (element instanceof IndexNode) {
IndexNode node= (IndexNode)element;
return node.fHasDeclarationInProject;
}
else
return true;
}
}
private class Counter implements IPDOMVisitor {
public int count;
public boolean visit(IPDOMNode node) throws CoreException {
++count;
return false;
}
public void leave(IPDOMNode node) throws CoreException {
}
}
private static class Children implements IPDOMVisitor {
private int index;
private IPDOMNode[] nodes;
public Children(IPDOMNode[] nodes) {
this.nodes = nodes;
}
public boolean visit(IPDOMNode node) throws CoreException {
nodes[index++] = node;
return false;
}
public void leave(IPDOMNode node) throws CoreException {
}
}
private static class HasChildren implements IPDOMVisitor {
public boolean hasChildren;
public boolean visit(IPDOMNode node) throws CoreException {
hasChildren = true;
throw new CoreException(Status.OK_STATUS);
}
public void leave(IPDOMNode node) throws CoreException {
}
}
static PDOMBinding[] trim(PDOMBinding []binding) {
int len;
for (len = 0; len < binding.length; len++)
if(binding[len] == null) {
PDOMBinding [] newBinding = new PDOMBinding [len];
System.arraycopy(binding, 0, newBinding, 0, len);
return newBinding;
public static boolean hasDeclarationInProject(IPDOMNode element) {
if (element instanceof PDOMBinding) {
try {
PDOMBinding binding = (PDOMBinding)element;
final PDOM pdom= binding.getPDOM();
IIndexName[] names= pdom.findNames(binding, IIndex.FIND_DECLARATIONS);
for (int i = 0; i < names.length; i++) {
IIndexName name = names[i];
if (name.getFile().getLocation().getFullPath() != null) {
return true;
}
}
names= pdom.findNames(binding, IIndex.FIND_DEFINITIONS);
for (int i = 0; i < names.length; i++) {
IIndexName name = names[i];
if (name.getFile().getLocation().getFullPath() != null) {
return true;
}
}
} catch (CoreException e) {
CCorePlugin.log(e);
}
}
return binding;
else if (element instanceof PDOMLinkage) {
return true;
}
return false;
}
}
private class IndexContentProvider implements ITreeContentProvider {
public Object[] getChildren(Object parentElement) {
private static class Children implements IPDOMVisitor {
private ArrayList fNodes;
public Children() {
fNodes= new ArrayList();
}
public boolean visit(IPDOMNode node) throws CoreException {
fNodes.add(node);
return false;
}
public void leave(IPDOMNode node) throws CoreException {
}
public IPDOMNode[] getNodes() {
return (IPDOMNode[]) fNodes.toArray(new IPDOMNode[fNodes.size()]);
}
}
private class IndexContentProvider extends AsyncTreeContentProvider {
public IndexContentProvider(Display disp) {
super(disp);
}
public Object getParent(Object element) {
if (element instanceof IndexNode) {
return ((IndexNode) element).fParent;
}
if (element instanceof ICElement) {
return ((ICElement) element).getParent();
}
return null;
}
protected Object[] syncronouslyComputeChildren(Object parentElement) {
if (parentElement instanceof ICModel) {
ICModel element = (ICModel) parentElement;
try {
return element.getCProjects();
} catch (CModelException e) {
CUIPlugin.getDefault().log(e);
return new Object[0];
}
}
else if (parentElement instanceof IndexNode) {
final IndexNode node= (IndexNode) parentElement;
if (node.fObject instanceof PDOMBinding) {
final PDOMBinding binding= (PDOMBinding) node.fObject;
if (!binding.mayHaveChildren()) {
return new Object[0];
}
}
}
// allow for async computation
return null;
}
protected Object[] asyncronouslyComputeChildren(Object parentElement, IProgressMonitor monitor) {
try {
if (parentElement instanceof ICProject) {
ICProject cproject= (ICProject)parentElement;
if (!cproject.getProject().isOpen()) {
return new Object[0];
}
PDOM pdom = (PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject);
PDOMLinkage[] linkages= pdom.getLinkageImpls();
if (linkages.length == 1) {
// Skip linkages in hierarchy if there is only one
return getChildren(linkages[0]);
}
return linkages;
} else if (parentElement instanceof IPDOMNode) {
IPDOMNode node = (IPDOMNode)parentElement;
Counter counter = new Counter();
node.accept(counter);
IPDOMNode[] children = new IPDOMNode[counter.count];
Children childrener = new Children(children);
node.accept(childrener);
return children;
return computeChildren(cproject);
}
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
return new Object[0];
}
public Object getParent(Object element) {
// TODO should really figure this out
return null;
}
public boolean hasChildren(Object element) {
try {
if (element instanceof ICProject) {
ICProject cproject= (ICProject)element;
if (!cproject.getProject().isOpen()) {
return false;
}
PDOM pdom = (PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject);
PDOMLinkage[] linkages = pdom.getLinkageImpls();
if (linkages.length == 0)
return false;
else if (linkages.length == 1)
// Skipping linkages if only one
return hasChildren(linkages[0]);
else
return true;
} else if (element instanceof IPDOMNode) {
HasChildren hasChildren = new HasChildren();
try {
((IPDOMNode)element).accept(hasChildren);
} catch (CoreException e) {
if (e.getStatus() != Status.OK_STATUS)
throw e;
}
return hasChildren.hasChildren;
}
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
return false;
}
public Object[] getElements(Object inputElement) {
try {
if (inputElement instanceof ICModel) {
ICModel model = (ICModel)inputElement;
ICProject[] projects = model.getCProjects();
Arrays.sort(projects, new Comparator() {
public int compare(Object arg0, Object arg1) {
String name0 = ((ICProject)arg0).getElementName();
String name1 = ((ICProject)arg1).getElementName();
return name0.compareToIgnoreCase(name1);
else if (parentElement instanceof IndexNode) {
IndexNode node= (IndexNode) parentElement;
ICProject cproject= node.getProject();
if (cproject != null && cproject.getProject().isOpen()) {
Long ts= (Long) fTimestampPerProject.get(cproject.getElementName());
PDOM pdom= (PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject);
pdom.acquireReadLock();
try {
if (ts == null || ts.longValue() == pdom.getLastWriteAccess()) {
return computeChildren(parentElement, node.fObject);
}
}
});
return projects;
finally {
pdom.releaseReadLock();
}
}
}
} catch (CModelException e) {
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return new Object[0];
}
public void dispose() {
private Object[] computeChildren(ICProject cproject) throws CoreException, InterruptedException {
PDOM pdom = (PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject);
pdom.acquireReadLock();
try {
fTimestampPerProject.put(cproject.getElementName(), new Long(pdom.getLastWriteAccess()));
IPDOMNode[] linkages= pdom.getLinkageImpls();
if (linkages.length == 1) {
// Skip linkages in hierarchy if there is only one
return computeChildren(cproject, linkages[0]);
}
return wrap(cproject, linkages);
}
finally {
pdom.releaseReadLock();
}
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
private Object[] computeChildren(Object parent, IPDOMNode node) throws CoreException {
Children collector = new Children();
node.accept(collector);
return wrap(parent, collector.getNodes());
}
private Object[] wrap(Object parent, IPDOMNode[] nodes) {
if (nodes.length == 0) {
return nodes;
}
IndexNode[] result= new IndexNode[nodes.length];
for (int i = 0; i < result.length; i++) {
final IndexNode indexNode = result[i]= new IndexNode();
final IPDOMNode node= nodes[i];
indexNode.fParent= parent;
indexNode.fObject= node;
indexNode.fText= IndexLabelProvider.getText(node);
indexNode.fImage= IndexLabelProvider.getImage(node);
indexNode.fHasDeclarationInProject= Filter.hasDeclarationInProject(node);
}
return result;
}
}
public void createPartControl(Composite parent) {
viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
// viewer = new TreeViewer(parent, SWT.VIRTUAL | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
// drillDownAdapter = new DrillDownAdapter(viewer);
viewer.setContentProvider(new IndexContentProvider());
viewer = new ExtendedTreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
contentProvider= new IndexContentProvider(getSite().getShell().getDisplay());
viewer.setContentProvider(contentProvider);
viewer.setLabelProvider(new IndexLabelProvider());
viewer.setUseHashlookup(true);
ICModel model = CoreModel.getDefault().getCModel();
viewer.setInput(model);
viewer.addFilter(filter);
try {
ICProject[] projects = model.getCProjects();
for (int i = 0; i < projects.length; ++i) {
PDOM pdom = (PDOM)CCoreInternals.getPDOMManager().getPDOM(projects[i]);
pdom.addListener(this);
}
viewer.setChildCount(model, projects.length);
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
@ -345,12 +344,12 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
}
private void makeActions() {
countSymbolsAction = new CountNodeAction(viewer);
countSymbolsAction = new CountNodeAction(this, viewer);
discardExternalDefsAction = new DiscardExternalDefsAction(viewer, this);
toggleLinkingAction = new ToggleLinkingAction(this);
openDefinitionAction = new OpenDefinitionAction(viewer);
findDeclarationsAction = new FindDeclarationsAction(viewer);
findReferencesAction = new FindReferencesAction(viewer);
openDefinitionAction = new OpenDefinitionAction(this, viewer);
findDeclarationsAction = new FindDeclarationsAction(this, viewer);
findReferencesAction = new FindReferencesAction(this, viewer);
}
private void hookContextMenu() {
@ -377,8 +376,6 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
manager.add(findDeclarationsAction);
if (findReferencesAction.valid())
manager.add(findReferencesAction);
//manager.add(new Separator());
//drillDownAdapter.addNavigationActions(manager);
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}
@ -417,7 +414,7 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
public void run() {
fUpdateRequested= false;
if (!viewer.getControl().isDisposed()) {
viewer.refresh();
contentProvider.recompute();
}
}
});
@ -458,5 +455,9 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
}
}
}
public long getLastWriteAccess(ICProject cproject) {
Long result= (Long) fTimestampPerProject.get(cproject.getElementName());
return result == null ? -1 : result.longValue();
}
}

View file

@ -1,16 +1,16 @@
/*******************************************************************************
* Copyright (c) 2006 QNX Software Systems and others.
* Copyright (c) 2006, 2007 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
package org.eclipse.cdt.internal.ui.indexview;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@ -21,25 +21,39 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.core.CCoreInternals;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.ui.search.PDOMSearchQuery;
/**
* @author Doug Schaefer
*
* This is the search query to be used for searching the PDOM.
*/
public class PDOMSearchBindingQuery extends PDOMSearchQuery {
public class IndexViewSearchQuery extends PDOMSearchQuery {
private IIndexBinding binding;
private IIndexBinding fBinding;
private long fLastWrite;
private String fName;
private ICProject fProject;
public PDOMSearchBindingQuery(ICElement[] scope, IIndexBinding binding, int flags) {
public IndexViewSearchQuery(ICElement[] scope, ICProject project, long pdomLastWrite, IIndexBinding binding, String name, int flags) {
super(scope, flags);
this.binding = binding;
fProject= project;
fBinding = binding;
fLastWrite= pdomLastWrite;
fName= name;
}
public IStatus runWithIndex(IIndex index, IProgressMonitor monitor) throws OperationCanceledException {
try {
createMatches(index, binding);
if (((PDOM) CCoreInternals.getPDOMManager().getPDOM(fProject)).getLastWriteAccess() == fLastWrite) {
createMatches(index, fBinding);
}
return Status.OK_STATUS;
} catch (CoreException e) {
return new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, 0, e.getLocalizedMessage(), e);
@ -47,7 +61,6 @@ public class PDOMSearchBindingQuery extends PDOMSearchQuery {
}
public String getLabel() {
return super.getLabel() + " " + binding.getName(); //$NON-NLS-1$
return super.getLabel() + " " + fName; //$NON-NLS-1$
}
}

View file

@ -1,12 +1,13 @@
/*******************************************************************************
* Copyright (c) 2006 QNX Software Systems and others.
* Copyright (c) 2006, 2007 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.indexview;
@ -29,8 +30,12 @@ import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.core.CCoreInternals;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.ui.util.EditorUtility;
/**
@ -39,32 +44,36 @@ import org.eclipse.cdt.internal.ui.util.EditorUtility;
*/
public class OpenDefinitionAction extends IndexAction {
public OpenDefinitionAction(TreeViewer viewer) {
super(viewer, CUIPlugin.getResourceString("IndexView.openDefinition.name"));//$NON-NLS-1$
public OpenDefinitionAction(IndexView view, TreeViewer viewer) {
super(view, viewer, CUIPlugin.getResourceString("IndexView.openDefinition.name"));//$NON-NLS-1$
}
public void run() {
private IndexNode getBindingNode() {
ISelection selection = viewer.getSelection();
if (!(selection instanceof IStructuredSelection))
return null;
Object[] objs = ((IStructuredSelection)selection).toArray();
if (objs.length == 1 && objs[0] instanceof IndexNode) {
IndexNode node= (IndexNode) objs[0];
if (node.fObject instanceof IIndexBinding) {
return node;
}
}
return null;
}
public void run() {
IndexNode bindingNode= getBindingNode();
if (bindingNode == null) {
return;
}
try {
IIndex index= CCorePlugin.getIndexManager().getIndex(CoreModel.getDefault().getCModel().getCProjects());
Object[] objs = ((IStructuredSelection)selection).toArray();
for (int i = 0; i < objs.length; ++i) {
if (!(objs[i] instanceof IIndexBinding))
continue;
index.acquireReadLock();
try {
IIndexBinding binding = (IIndexBinding)objs[i];
IIndexName[] defs= index.findDefinitions(binding);
for (int j = 0; j < defs.length; j++) {
IIndexName name = defs[j];
showInEditor(name);
}
} finally {
index.releaseReadLock();
ICProject cproject= bindingNode.getProject();
if (cproject != null) {
IIndex index= CCorePlugin.getIndexManager().getIndex(cproject);
if (!openDefinition(cproject, bindingNode, index)) {
index= CCorePlugin.getIndexManager().getIndex(CoreModel.getDefault().getCModel().getCProjects());
openDefinition(cproject, bindingNode, index);
}
}
}
@ -75,6 +84,29 @@ public class OpenDefinitionAction extends IndexAction {
}
}
private boolean openDefinition(ICProject cproject, IndexNode bindingNode, IIndex index)
throws InterruptedException, CoreException, CModelException, PartInitException {
index.acquireReadLock();
try {
if (indexView.getLastWriteAccess(cproject) != ((PDOM) CCoreInternals.getPDOMManager().getPDOM(cproject)).getLastWriteAccess()) {
return true;
}
IIndexName[] defs= index.findDefinitions((IIndexBinding) bindingNode.fObject);
if (defs.length > 0) {
showInEditor(defs[0]);
return true;
}
defs= index.findDeclarations((IIndexBinding) bindingNode.fObject);
if (defs.length > 0) {
showInEditor(defs[0]);
return true;
}
} finally {
index.releaseReadLock();
}
return false;
}
private void showInEditor(IIndexName name) throws CModelException, PartInitException, CoreException {
IPath path = IndexLocationFactory.getPath(name.getFile().getLocation());
if(path!=null) {
@ -99,14 +131,6 @@ public class OpenDefinitionAction extends IndexAction {
}
public boolean valid() {
ISelection selection = viewer.getSelection();
if (!(selection instanceof IStructuredSelection))
return false;
Object[] objs = ((IStructuredSelection)selection).toArray();
for (int i = 0; i < objs.length; ++i)
if (objs[i] instanceof IIndexBinding)
return true;
return false;
return getBindingNode() != null;
}
}

View file

@ -1,51 +0,0 @@
/*******************************************************************************
* Copyright (c) 2005, 2007 QNX Software Systems
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX software Systems - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.indexview;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.ui.CUIPlugin;
/**
* Sets all selected actions to use the Fast indexer.
*
* @author dschaefer
*/
public class SetFastIndexerAction extends IndexAction {
public SetFastIndexerAction(TreeViewer viewer) {
super(viewer, CUIPlugin.getResourceString("IndexView.setFastIndexer.name")); //$NON-NLS-1$
}
public void run() {
try {
IIndexManager manager = CCorePlugin.getIndexManager();
ICProject[] projects = CoreModel.getDefault().getCModel().getCProjects();
for (int i = 0; i < projects.length; ++i) {
manager.setIndexerId(projects[i], IPDOMManager.ID_FAST_INDEXER);
}
} catch (CoreException e) {
CCorePlugin.log(e);
}
}
public boolean valid() {
return true;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006 QNX Software Systems and others.
* Copyright (c) 2006, 2007 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -474,7 +474,7 @@ public class PDOMSearchPage extends DialogPage implements ISearchPage {
try {
searchFlags = settings.getInt(STORE_SEARCH_FLAGS);
} catch (NumberFormatException e) {
// Int was unitialized, assume the defaults
// was uninitialized, assume the defaults
}
previousPatterns = settings.getArray(STORE_PREVIOUS_PATTERNS);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -21,7 +21,11 @@ public class ExtendedTreeViewer extends TreeViewer {
public ExtendedTreeViewer(Composite parent) {
super(parent);
}
public ExtendedTreeViewer(Composite parent, int style) {
super(parent, style);
}
public void refresh(final Object[] elements) {
preservingSelection(new Runnable() {
public void run() {