1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-29 11:55:40 +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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* QNX Software Systems - initial API and implementation * QNX Software Systems - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.indexview; 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 class CountNodeAction extends IndexAction {
public CountNodeAction(TreeViewer viewer) { public CountNodeAction(IndexView view, TreeViewer viewer) {
super(viewer, CUIPlugin.getResourceString("IndexView.CountSymbols.name")); //$NON-NLS-1$ super(view, viewer, CUIPlugin.getResourceString("IndexView.CountSymbols.name")); //$NON-NLS-1$
} }
public boolean valid() { public boolean valid() {
@ -74,43 +75,60 @@ public class CountNodeAction extends IndexAction {
final PDOM pdom = (PDOM)CCoreInternals.getPDOMManager().getPDOM(project); final PDOM pdom = (PDOM)CCoreInternals.getPDOMManager().getPDOM(project);
//pdom.getDB().reportFreeBlocks(); //pdom.getDB().reportFreeBlocks();
pdom.getFileIndex().accept(new IBTreeVisitor() { pdom.acquireReadLock();
public int compare(int record) throws CoreException { try {
return 0; pdom.getFileIndex().accept(new IBTreeVisitor() {
} public int compare(int record) throws CoreException {
public boolean visit(int record) throws CoreException { return 0;
if (record != 0) { }
PDOMFile file = new PDOMFile(pdom, record);
++count[FILES]; public boolean visit(int record) throws CoreException {
PDOMMacro macro = file.getFirstMacro(); if (record != 0) {
while (macro != null) { PDOMFile file = new PDOMFile(pdom, record);
++count[MACROS]; ++count[FILES];
macro = macro.getNextMacro(); 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)
pdom.accept(new IPDOMVisitor() { throws CoreException {
public boolean visit(IPDOMNode node) throws CoreException { ++count[SYMBOLS];
++count[SYMBOLS]; if (node instanceof PDOMBinding) {
if (node instanceof PDOMBinding) { PDOMBinding binding = (PDOMBinding) node;
PDOMBinding binding = (PDOMBinding)node; for (PDOMName name = binding
for (PDOMName name = binding.getFirstReference(); name != null; name = name.getNextInBinding()) .getFirstReference(); name != null; name = name
++count[REFS]; .getNextInBinding())
for (PDOMName name = binding.getFirstDeclaration(); name != null; name = name.getNextInBinding()) ++count[REFS];
++count[DECLS]; for (PDOMName name = binding
for (PDOMName name = binding.getFirstDefinition(); name != null; name = name.getNextInBinding()) .getFirstDeclaration(); name != null; name = name
++count[DEFS]; .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) { } catch (CoreException e) {
CUIPlugin.getDefault().log(e); CUIPlugin.getDefault().log(e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
} }
MessageDialog.openInformation(null, 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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.indexview; package org.eclipse.cdt.internal.ui.indexview;
@ -24,19 +25,17 @@ import org.eclipse.jface.viewers.TreeViewer;
* *
*/ */
public class DiscardExternalDefsAction extends IndexAction { public class DiscardExternalDefsAction extends IndexAction {
final IndexView view;
public DiscardExternalDefsAction(TreeViewer viewer, 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$ setToolTipText(CUIPlugin.getResourceString("IndexView.ToggleExternals.tooltip")); //$NON-NLS-1$
CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, "public_co.gif"); //$NON-NLS-1$ CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, "public_co.gif"); //$NON-NLS-1$
this.view = view;
} }
public void run() { public void run() {
ISelection selection = viewer.getSelection(); ISelection selection = viewer.getSelection();
if (!(selection instanceof IStructuredSelection)) if (!(selection instanceof IStructuredSelection))
return; return;
view.toggleExternalDefs(); indexView.toggleExternalDefs();
} }
public boolean valid() { 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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.indexview; 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.search.ui.NewSearchUI;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.search.PDOMSearchBindingQuery;
import org.eclipse.cdt.internal.ui.search.PDOMSearchQuery; 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 class FindDeclarationsAction extends IndexAction {
public FindDeclarationsAction(TreeViewer viewer) { public FindDeclarationsAction(IndexView view, TreeViewer viewer) {
super(viewer, CUIPlugin.getResourceString("IndexView.findDeclarations.name")); //$NON-NLS-1$ super(view, viewer, CUIPlugin.getResourceString("IndexView.findDeclarations.name")); //$NON-NLS-1$
} }
private IIndexBinding getBinding() { private IndexNode getBindingNode() {
ISelection selection = viewer.getSelection(); ISelection selection = viewer.getSelection();
if (!(selection instanceof IStructuredSelection)) if (!(selection instanceof IStructuredSelection))
return null; return null;
Object[] objs = ((IStructuredSelection)selection).toArray(); Object[] objs = ((IStructuredSelection)selection).toArray();
return (objs.length == 1 && objs[0] instanceof IIndexBinding) if (objs.length == 1 && objs[0] instanceof IndexNode) {
? (IIndexBinding)objs[0] : null; IndexNode node= (IndexNode) objs[0];
if (node.fObject instanceof IIndexBinding) {
return node;
}
}
return null;
} }
public void run() { public void run() {
IIndexBinding binding = getBinding(); IndexNode binding = getBindingNode();
PDOMSearchBindingQuery query = new PDOMSearchBindingQuery( if (binding != null) {
null, ICProject cproject= binding.getProject();
binding, if (cproject != null) {
PDOMSearchQuery.FIND_DECLARATIONS | PDOMSearchQuery.FIND_DEFINITIONS); IndexViewSearchQuery query = new IndexViewSearchQuery(
null,
NewSearchUI.activateSearchResultView(); cproject, indexView.getLastWriteAccess(cproject),
(IIndexBinding) binding.fObject, binding.fText,
NewSearchUI.runQueryInBackground(query); PDOMSearchQuery.FIND_DECLARATIONS | PDOMSearchQuery.FIND_DEFINITIONS);
NewSearchUI.activateSearchResultView();
NewSearchUI.runQueryInBackground(query);
}
}
} }
public boolean valid() { 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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.indexview; 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.internal.ui.search.PDOMSearchQuery;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
@ -27,32 +28,42 @@ import org.eclipse.search.ui.NewSearchUI;
*/ */
public class FindReferencesAction extends IndexAction { public class FindReferencesAction extends IndexAction {
public FindReferencesAction(TreeViewer viewer) { public FindReferencesAction(IndexView view, TreeViewer viewer) {
super(viewer, CUIPlugin.getResourceString("IndexView.findReferences.name")); //$NON-NLS-1$ super(view, viewer, CUIPlugin.getResourceString("IndexView.findReferences.name")); //$NON-NLS-1$
} }
private IIndexBinding getBinding() { private IndexNode getBindingNode() {
ISelection selection = viewer.getSelection(); ISelection selection = viewer.getSelection();
if (!(selection instanceof IStructuredSelection)) if (!(selection instanceof IStructuredSelection))
return null; return null;
Object[] objs = ((IStructuredSelection)selection).toArray(); Object[] objs = ((IStructuredSelection)selection).toArray();
return (objs.length == 1 && objs[0] instanceof IIndexBinding) if (objs.length == 1 && objs[0] instanceof IndexNode) {
? (IIndexBinding)objs[0] : null; IndexNode node= (IndexNode) objs[0];
if (node.fObject instanceof IIndexBinding) {
return node;
}
}
return null;
} }
public void run() { public void run() {
PDOMSearchBindingQuery query = new PDOMSearchBindingQuery( IndexNode binding = getBindingNode();
null, if (binding != null) {
getBinding(), ICProject cproject= binding.getProject();
PDOMSearchQuery.FIND_REFERENCES); if (cproject != null) {
IndexViewSearchQuery query = new IndexViewSearchQuery(
NewSearchUI.activateSearchResultView(); null,
cproject, indexView.getLastWriteAccess(cproject),
NewSearchUI.runQueryInBackground(query); (IIndexBinding) binding.fObject, binding.fText,
PDOMSearchQuery.FIND_REFERENCES);
NewSearchUI.activateSearchResultView();
NewSearchUI.runQueryInBackground(query);
}
}
} }
public boolean valid() { 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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.indexview; package org.eclipse.cdt.internal.ui.indexview;
@ -23,25 +24,30 @@ import org.eclipse.jface.viewers.TreeViewer;
*/ */
public abstract class IndexAction extends Action { 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(); super();
this.indexView= view;
this.viewer = viewer; this.viewer = viewer;
} }
protected IndexAction(TreeViewer viewer, String text) { protected IndexAction(IndexView view, TreeViewer viewer, String text) {
super(text); super(text);
this.indexView= view;
this.viewer = viewer; this.viewer = viewer;
} }
protected IndexAction(TreeViewer viewer, String text, ImageDescriptor image) { protected IndexAction(IndexView view, TreeViewer viewer, String text, ImageDescriptor image) {
super(text, image); super(text, image);
this.indexView= view;
this.viewer = viewer; this.viewer = viewer;
} }
protected IndexAction(TreeViewer viewer, String text, int style) { protected IndexAction(IndexView view, TreeViewer viewer, String text, int style) {
super(text, style); super(text, style);
this.indexView= view;
this.viewer = viewer; this.viewer = viewer;
} }

View file

@ -6,14 +6,14 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* IBM Corporation * IBM Corporation
* Andrew Ferguson (Symbian) * Andrew Ferguson (Symbian)
* Bryan Wilkinson (QNX) * 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.core.runtime.CoreException;
import org.eclipse.jface.resource.ImageDescriptor; 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.ISharedImages;
import org.eclipse.ui.PlatformUI; 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.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.ICompositeType; 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.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode; 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; 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 class IndexLabelProvider extends LabelProvider {
public String getText(Object element) { public String getText(Object element) {
if (element == null) { if (element instanceof IndexNode) {
return "null :("; //$NON-NLS-1$ return ((IndexNode) element).fText;
} else if (element instanceof PDOMNode) { }
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 { try {
String result = ((PDOMNamedNode)element).getDBName().getString(); String result = ((PDOMNamedNode)element).getDBName().getString();
@ -139,11 +167,11 @@ public class IndexLabelProvider extends LabelProvider {
} catch (CoreException e) { } catch (CoreException e) {
return e.getMessage(); 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; ImageDescriptor desc = null;
if (element instanceof IVariable) if (element instanceof IVariable)
@ -177,23 +205,13 @@ public class IndexLabelProvider extends LabelProvider {
desc = CElementImageProvider.getEnumeratorImageDescriptor(); desc = CElementImageProvider.getEnumeratorImageDescriptor();
else if (element instanceof ITypedef) else if (element instanceof ITypedef)
desc = CElementImageProvider.getTypedefImageDescriptor(); 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) if (desc != null)
return CUIPlugin.getImageDescriptorRegistry().get(desc); return CUIPlugin.getImageDescriptorRegistry().get(desc);
else if (element instanceof PDOMLinkage) else if (element instanceof PDOMLinkage)
return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT); 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 * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Andrew Ferguson (Symbian) * Andrew Ferguson (Symbian)
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.indexview; package org.eclipse.cdt.internal.ui.indexview;
import java.util.Arrays; import java.util.ArrayList;
import java.util.Comparator; 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.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager; 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.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IActionBars; import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.part.ViewPart; 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.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor; 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.CModelException;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ElementChangedEvent; 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.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; 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.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 * @author Doug Schaefer
@ -68,7 +69,6 @@ import org.eclipse.cdt.internal.ui.IndexLabelProvider;
public class IndexView extends ViewPart implements PDOM.IListener, IElementChangedListener { public class IndexView extends ViewPart implements PDOM.IListener, IElementChangedListener {
private TreeViewer viewer; private TreeViewer viewer;
// private DrillDownAdapter drillDownAdapter;
private ToggleLinkingAction toggleLinkingAction; private ToggleLinkingAction toggleLinkingAction;
private IndexAction countSymbolsAction; private IndexAction countSymbolsAction;
private IndexAction discardExternalDefsAction; private IndexAction discardExternalDefsAction;
@ -78,14 +78,17 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
Filter filter = new Filter(); Filter filter = new Filter();
public boolean isLinking = false; public boolean isLinking = false;
private volatile boolean fUpdateRequested= false; private volatile boolean fUpdateRequested= false;
private Map fTimestampPerProject= new HashMap();
private IndexContentProvider contentProvider;
public void toggleExternalDefs() { public void toggleExternalDefs() {
filter.showExternalDefs = ! filter.showExternalDefs;
if (!filter.showExternalDefs) { if (!filter.showExternalDefs) {
viewer.addFilter(filter); viewer.addFilter(filter);
} else { } else {
viewer.removeFilter(filter); viewer.removeFilter(filter);
} }
filter.showExternalDefs = ! filter.showExternalDefs;
} }
public void toggleLinking() { public void toggleLinking() {
@ -100,9 +103,6 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
* editor (if option enabled) * editor (if option enabled)
*/ */
void handleSelectionChanged(SelectionChangedEvent event) { void handleSelectionChanged(SelectionChangedEvent event) {
// final IStructuredSelection selection = (IStructuredSelection) event.getSelection();
// updateStatusLine(selection);
// updateActionBars(selection);
if (isLinking) { if (isLinking) {
openDefinitionAction.run(); openDefinitionAction.run();
} }
@ -111,190 +111,189 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
private static class Filter extends ViewerFilter { private static class Filter extends ViewerFilter {
public boolean showExternalDefs = false; public boolean showExternalDefs = false;
public boolean select(Viewer viewer, Object parentElement, Object element) { public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof PDOMBinding) { if (element instanceof IndexNode) {
PDOMBinding binding = (PDOMBinding)element; IndexNode node= (IndexNode)element;
try { return node.fHasDeclarationInProject;
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;
}
} }
else else
return true; return true;
} }
} public static boolean hasDeclarationInProject(IPDOMNode element) {
if (element instanceof PDOMBinding) {
private class Counter implements IPDOMVisitor { try {
public int count; PDOMBinding binding = (PDOMBinding)element;
public boolean visit(IPDOMNode node) throws CoreException { final PDOM pdom= binding.getPDOM();
++count; IIndexName[] names= pdom.findNames(binding, IIndex.FIND_DECLARATIONS);
return false; for (int i = 0; i < names.length; i++) {
} IIndexName name = names[i];
public void leave(IPDOMNode node) throws CoreException { if (name.getFile().getLocation().getFullPath() != null) {
} return true;
} }
}
private static class Children implements IPDOMVisitor { names= pdom.findNames(binding, IIndex.FIND_DEFINITIONS);
private int index; for (int i = 0; i < names.length; i++) {
private IPDOMNode[] nodes; IIndexName name = names[i];
public Children(IPDOMNode[] nodes) { if (name.getFile().getLocation().getFullPath() != null) {
this.nodes = nodes; return true;
} }
public boolean visit(IPDOMNode node) throws CoreException { }
nodes[index++] = node; } catch (CoreException e) {
return false; CCorePlugin.log(e);
} }
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;
} }
return binding; else if (element instanceof PDOMLinkage) {
return true;
}
return false;
}
} }
private class IndexContentProvider implements ITreeContentProvider { private static class Children implements IPDOMVisitor {
public Object[] getChildren(Object parentElement) { 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 { try {
if (parentElement instanceof ICProject) { if (parentElement instanceof ICProject) {
ICProject cproject= (ICProject)parentElement; ICProject cproject= (ICProject)parentElement;
if (!cproject.getProject().isOpen()) { if (!cproject.getProject().isOpen()) {
return new Object[0]; return new Object[0];
} }
PDOM pdom = (PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject); return computeChildren(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;
} }
} catch (CoreException e) { else if (parentElement instanceof IndexNode) {
CUIPlugin.getDefault().log(e); IndexNode node= (IndexNode) parentElement;
} ICProject cproject= node.getProject();
return new Object[0]; if (cproject != null && cproject.getProject().isOpen()) {
} Long ts= (Long) fTimestampPerProject.get(cproject.getElementName());
PDOM pdom= (PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject);
public Object getParent(Object element) { pdom.acquireReadLock();
// TODO should really figure this out try {
return null; if (ts == null || ts.longValue() == pdom.getLastWriteAccess()) {
} return computeChildren(parentElement, node.fObject);
}
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);
} }
}); finally {
return projects; pdom.releaseReadLock();
}
}
} }
} catch (CModelException e) { } catch (CoreException e) {
CUIPlugin.getDefault().log(e); CUIPlugin.getDefault().log(e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} }
return new Object[0]; 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) { public void createPartControl(Composite parent) {
viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); viewer = new ExtendedTreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
// viewer = new TreeViewer(parent, SWT.VIRTUAL | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); contentProvider= new IndexContentProvider(getSite().getShell().getDisplay());
// drillDownAdapter = new DrillDownAdapter(viewer); viewer.setContentProvider(contentProvider);
viewer.setContentProvider(new IndexContentProvider());
viewer.setLabelProvider(new IndexLabelProvider()); viewer.setLabelProvider(new IndexLabelProvider());
viewer.setUseHashlookup(true);
ICModel model = CoreModel.getDefault().getCModel(); ICModel model = CoreModel.getDefault().getCModel();
viewer.setInput(model); viewer.setInput(model);
viewer.addFilter(filter);
try { try {
ICProject[] projects = model.getCProjects(); ICProject[] projects = model.getCProjects();
for (int i = 0; i < projects.length; ++i) { for (int i = 0; i < projects.length; ++i) {
PDOM pdom = (PDOM)CCoreInternals.getPDOMManager().getPDOM(projects[i]); PDOM pdom = (PDOM)CCoreInternals.getPDOMManager().getPDOM(projects[i]);
pdom.addListener(this); pdom.addListener(this);
} }
viewer.setChildCount(model, projects.length);
} catch (CoreException e) { } catch (CoreException e) {
CUIPlugin.getDefault().log(e); CUIPlugin.getDefault().log(e);
} }
@ -345,12 +344,12 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
} }
private void makeActions() { private void makeActions() {
countSymbolsAction = new CountNodeAction(viewer); countSymbolsAction = new CountNodeAction(this, viewer);
discardExternalDefsAction = new DiscardExternalDefsAction(viewer, this); discardExternalDefsAction = new DiscardExternalDefsAction(viewer, this);
toggleLinkingAction = new ToggleLinkingAction(this); toggleLinkingAction = new ToggleLinkingAction(this);
openDefinitionAction = new OpenDefinitionAction(viewer); openDefinitionAction = new OpenDefinitionAction(this, viewer);
findDeclarationsAction = new FindDeclarationsAction(viewer); findDeclarationsAction = new FindDeclarationsAction(this, viewer);
findReferencesAction = new FindReferencesAction(viewer); findReferencesAction = new FindReferencesAction(this, viewer);
} }
private void hookContextMenu() { private void hookContextMenu() {
@ -377,8 +376,6 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
manager.add(findDeclarationsAction); manager.add(findDeclarationsAction);
if (findReferencesAction.valid()) if (findReferencesAction.valid())
manager.add(findReferencesAction); manager.add(findReferencesAction);
//manager.add(new Separator());
//drillDownAdapter.addNavigationActions(manager);
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
} }
@ -417,7 +414,7 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
public void run() { public void run() {
fUpdateRequested= false; fUpdateRequested= false;
if (!viewer.getControl().isDisposed()) { 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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems) * 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.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; 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.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.ui.CUIPlugin; 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 * @author Doug Schaefer
* *
* This is the search query to be used for searching the PDOM. * 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); super(scope, flags);
this.binding = binding; fProject= project;
fBinding = binding;
fLastWrite= pdomLastWrite;
fName= name;
} }
public IStatus runWithIndex(IIndex index, IProgressMonitor monitor) throws OperationCanceledException { public IStatus runWithIndex(IIndex index, IProgressMonitor monitor) throws OperationCanceledException {
try { try {
createMatches(index, binding); if (((PDOM) CCoreInternals.getPDOMManager().getPDOM(fProject)).getLastWriteAccess() == fLastWrite) {
createMatches(index, fBinding);
}
return Status.OK_STATUS; return Status.OK_STATUS;
} catch (CoreException e) { } catch (CoreException e) {
return new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, 0, e.getLocalizedMessage(), 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() { 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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.indexview; 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.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.ui.CUIPlugin; 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; 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 class OpenDefinitionAction extends IndexAction {
public OpenDefinitionAction(TreeViewer viewer) { public OpenDefinitionAction(IndexView view, TreeViewer viewer) {
super(viewer, CUIPlugin.getResourceString("IndexView.openDefinition.name"));//$NON-NLS-1$ super(view, viewer, CUIPlugin.getResourceString("IndexView.openDefinition.name"));//$NON-NLS-1$
} }
public void run() { private IndexNode getBindingNode() {
ISelection selection = viewer.getSelection(); ISelection selection = viewer.getSelection();
if (!(selection instanceof IStructuredSelection)) 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; return;
}
try { try {
IIndex index= CCorePlugin.getIndexManager().getIndex(CoreModel.getDefault().getCModel().getCProjects()); ICProject cproject= bindingNode.getProject();
Object[] objs = ((IStructuredSelection)selection).toArray(); if (cproject != null) {
for (int i = 0; i < objs.length; ++i) { IIndex index= CCorePlugin.getIndexManager().getIndex(cproject);
if (!(objs[i] instanceof IIndexBinding)) if (!openDefinition(cproject, bindingNode, index)) {
continue; index= CCorePlugin.getIndexManager().getIndex(CoreModel.getDefault().getCModel().getCProjects());
openDefinition(cproject, bindingNode, index);
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();
} }
} }
} }
@ -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 { private void showInEditor(IIndexName name) throws CModelException, PartInitException, CoreException {
IPath path = IndexLocationFactory.getPath(name.getFile().getLocation()); IPath path = IndexLocationFactory.getPath(name.getFile().getLocation());
if(path!=null) { if(path!=null) {
@ -99,14 +131,6 @@ public class OpenDefinitionAction extends IndexAction {
} }
public boolean valid() { public boolean valid() {
ISelection selection = viewer.getSelection(); return getBindingNode() != null;
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;
} }
} }

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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -474,7 +474,7 @@ public class PDOMSearchPage extends DialogPage implements ISearchPage {
try { try {
searchFlags = settings.getInt(STORE_SEARCH_FLAGS); searchFlags = settings.getInt(STORE_SEARCH_FLAGS);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
// Int was unitialized, assume the defaults // was uninitialized, assume the defaults
} }
previousPatterns = settings.getArray(STORE_PREVIOUS_PATTERNS); 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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -21,7 +21,11 @@ public class ExtendedTreeViewer extends TreeViewer {
public ExtendedTreeViewer(Composite parent) { public ExtendedTreeViewer(Composite parent) {
super(parent); super(parent);
} }
public ExtendedTreeViewer(Composite parent, int style) {
super(parent, style);
}
public void refresh(final Object[] elements) { public void refresh(final Object[] elements) {
preservingSelection(new Runnable() { preservingSelection(new Runnable() {
public void run() { public void run() {