1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-12 10:45:37 +02:00

Fix for 172656, search results hold on to bindings from index.

This commit is contained in:
Markus Schorn 2007-06-28 13:24:34 +00:00
parent 4969836e86
commit d846abee43
7 changed files with 141 additions and 87 deletions

View file

@ -8,6 +8,7 @@
* Contributors:
* QNX Software Systems - initial API and implementation
* Andrew Ferguson (Symbian)
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.browser;
@ -65,8 +66,7 @@ public class AllTypesCache {
ITypeInfo[] result = new ITypeInfo[all.length];
for(int i=0; i<all.length; i++) {
IIndexBinding ib = (IIndexBinding) all[i];
result[i] = new IndexTypeInfo(ib.getQualifiedName(), IndexModelUtil.getElementType(ib), index);
result[i] = IndexTypeInfo.create(index, all[i]);
}
if(DEBUG) {

View file

@ -10,6 +10,7 @@
* IBM Corporation
* Andrew Ferguson (Symbian)
* Anton Leherbauer (Wind River Systems)
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.browser;
@ -20,7 +21,10 @@ import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IField;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileLocation;
@ -52,6 +56,43 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
private final String returnType;
private ITypeReference reference; // lazily constructed
/**
* Creates a typeinfo suitable for the binding.
* @since 4.0.1
*/
public static IndexTypeInfo create(IIndex index, IIndexBinding binding) {
String[] fqn;
int elementType;
try {
elementType = IndexModelUtil.getElementType(binding);
if (binding instanceof ICPPBinding) {
fqn= ((ICPPBinding)binding).getQualifiedName();
}
else if (binding instanceof IField) {
IField field= (IField) binding;
ICompositeType owner= field.getCompositeTypeOwner();
fqn= new String[] {owner.getName(), field.getName()};
}
else {
fqn= new String[] {binding.getName()};
}
if (binding instanceof IFunction) {
final IFunction function= (IFunction)binding;
final String[] paramTypes= IndexModelUtil.extractParameterTypes(function);
final String returnType= IndexModelUtil.extractReturnType(function);
return new IndexTypeInfo(fqn, elementType, paramTypes, returnType, null);
}
} catch (DOMException e) {
// index bindings don't throw DOMExceptions.
throw new AssertionError();
}
return new IndexTypeInfo(fqn, elementType, index);
}
/**
* @deprecated, use {@link #create(IIndex, IBinding)}.
*/
public IndexTypeInfo(String[] fqn, int elementType, IIndex index) {
this.fqn = fqn;
this.elementType = elementType;
@ -60,6 +101,9 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
this.returnType= null;
}
/**
* @deprecated, use {@link #create(IIndex, IBinding)}.
*/
public IndexTypeInfo(String[] fqn, int elementType, String[] params, String returnType, IIndex index) {
this.fqn = fqn;
this.elementType = elementType;

View file

@ -7,6 +7,7 @@
*
* Contributors:
* Anton Leherbauer (Wind River Systems) - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.browser.opentype;
@ -39,13 +40,8 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.browser.ITypeInfo;
import org.eclipse.cdt.core.browser.IndexTypeInfo;
import org.eclipse.cdt.core.browser.QualifiedTypeName;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IField;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog;
@ -242,38 +238,15 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
IIndex index = CCorePlugin.getIndexManager().getIndex(CoreModel.getDefault().getCModel().getCProjects());
try {
index.acquireReadLock();
IBinding[] bindings= index.findBindingsForPrefix(prefix, false, IndexFilter.ALL_DECLARED, monitor);
IIndexBinding[] bindings= index.findBindingsForPrefix(prefix, false, IndexFilter.ALL_DECLARED, monitor);
for(int i=0; i<bindings.length; i++) {
if (i % 0x1000 == 0 && monitor.isCanceled()) {
return null;
}
IBinding binding = bindings[i];
try {
IIndexBinding binding = bindings[i];
final int elementType = IndexModelUtil.getElementType(binding);
if (isVisibleType(elementType)) {
String[] fqn;
if(binding instanceof ICPPBinding) {
fqn= ((ICPPBinding)binding).getQualifiedName();
} else if (binding instanceof IField) {
IField field= (IField) binding;
ICompositeType owner= field.getCompositeTypeOwner();
fqn= new String[] {owner.getName(), field.getName()};
}
else {
fqn= new String[] {binding.getName()};
}
if (binding instanceof IFunction) {
final IFunction function= (IFunction)binding;
final String[] paramTypes= IndexModelUtil.extractParameterTypes(function);
final String returnType= IndexModelUtil.extractReturnType(function);
types.add(new IndexTypeInfo(fqn, elementType, paramTypes, returnType, index));
} else {
types.add(new IndexTypeInfo(fqn, elementType, index));
}
}
} catch(DOMException de) {
CCorePlugin.log(de);
types.add(IndexTypeInfo.create(index, binding));
}
}
} finally {

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
@ -15,6 +15,8 @@ package org.eclipse.cdt.internal.ui.search;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.cdt.core.browser.ITypeInfo;
import org.eclipse.cdt.core.browser.IndexTypeInfo;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexName;
@ -25,18 +27,16 @@ import org.eclipse.cdt.core.index.IIndexName;
*/
public class PDOMSearchElement {
private final IIndexBinding binding;
private final String name;
private final ITypeInfo typeInfo;
private final String filename;
public PDOMSearchElement(IIndexName name, IIndexBinding binding) throws CoreException {
this.binding= binding;
this.name = binding.getName();
this.typeInfo= IndexTypeInfo.create(null, binding);
filename = new Path(name.getFileLocation().getFileName()).toOSString();
}
public int hashCode() {
return name.hashCode() + filename.hashCode();
return (typeInfo.getCElementType() *31 + typeInfo.getName().hashCode())*31 + filename.hashCode();
}
public boolean equals(Object obj) {
@ -45,16 +45,16 @@ public class PDOMSearchElement {
if (this == obj)
return true;
PDOMSearchElement other = (PDOMSearchElement)obj;
return name.equals(other.name)
return typeInfo.getCElementType() == other.typeInfo.getCElementType()
&& typeInfo.getName().equals(other.typeInfo.getName())
&& filename.equals(other.filename);
}
public ITypeInfo getTypeInfo() {
return typeInfo;
}
public String getFileName() {
return filename;
}
public IIndexBinding getBinding() {
return binding;
}
}

View file

@ -0,0 +1,56 @@
/*******************************************************************************
* 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.search;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
import org.eclipse.swt.graphics.Image;
import org.eclipse.cdt.ui.browser.typeinfo.TypeInfoLabelProvider;
import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
import org.eclipse.cdt.internal.ui.viewsupport.CUILabelProvider;
/**
* @author Doug Schaefer
*
*/
public class PDOMSearchLabelProvider extends LabelProvider {
private final AbstractTextSearchViewPage fPage;
private final TypeInfoLabelProvider fTypeInfoLabelProvider;
private final CUILabelProvider fCElementLabelProvider;
public PDOMSearchLabelProvider(AbstractTextSearchViewPage page) {
fTypeInfoLabelProvider= new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_FULLY_QUALIFIED | TypeInfoLabelProvider.SHOW_PARAMETERS);
fCElementLabelProvider= new CUILabelProvider(0, CElementImageProvider.SMALL_ICONS);
fPage= page;
}
public Image getImage(Object element) {
if (element instanceof PDOMSearchElement)
return fTypeInfoLabelProvider.getImage(((PDOMSearchElement)element).getTypeInfo());
return fCElementLabelProvider.getImage(element);
}
public String getText(Object element) {
if (element instanceof PDOMSearchElement) {
return fTypeInfoLabelProvider.getText(((PDOMSearchElement)element).getTypeInfo());
}
return fCElementLabelProvider.getText(element);
}
protected int getMatchCount(Object element) {
return fPage.getInput().getMatchCount(element);
}
}

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
@ -7,42 +7,32 @@
*
* Contributors:
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
import org.eclipse.cdt.internal.ui.IndexLabelProvider;
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
import org.eclipse.swt.graphics.Image;
/**
* @author Doug Schaefer
*
*/
public class PDOMSearchListLabelProvider extends IndexLabelProvider {
private final AbstractTextSearchViewPage page;
public class PDOMSearchListLabelProvider extends PDOMSearchLabelProvider {
public PDOMSearchListLabelProvider(AbstractTextSearchViewPage page) {
this.page = page;
}
public Image getImage(Object element) {
if (element instanceof PDOMSearchElement)
return getImage(((PDOMSearchElement)element).getBinding());
else
return super.getImage(element);
super(page);
}
public String getText(Object element) {
final String text= super.getText(element);
if (element instanceof PDOMSearchElement) {
PDOMSearchElement searchElement = (PDOMSearchElement)element;
String filename = " - " + searchElement.getFileName(); //$NON-NLS-1$
int count = page.getInput().getMatchCount(element);
return getText(searchElement.getBinding()) + filename + " " //$NON-NLS-1$
final int count= getMatchCount(element);
final String filename = " - " + searchElement.getFileName(); //$NON-NLS-1$
return text + filename + " " //$NON-NLS-1$
+ CSearchMessages.getFormattedString("CSearchResultCollector.matches", new Integer(count)); //$NON-NLS-1$
} else
return super.getText(element);
}
return text;
}
}

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
@ -7,40 +7,31 @@
*
* Contributors:
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
import org.eclipse.cdt.internal.ui.IndexLabelProvider;
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
import org.eclipse.swt.graphics.Image;
/**
* @author Doug Schaefer
*
*/
public class PDOMSearchTreeLabelProvider extends IndexLabelProvider {
private final AbstractTextSearchViewPage page;
public class PDOMSearchTreeLabelProvider extends PDOMSearchLabelProvider {
public PDOMSearchTreeLabelProvider(AbstractTextSearchViewPage page) {
this.page = page;
}
public Image getImage(Object element) {
if (element instanceof PDOMSearchElement)
return getImage(((PDOMSearchElement)element).getBinding());
else
return super.getImage(element);
super(page);
}
public String getText(Object element) {
if (element instanceof PDOMSearchElement) {
int count = page.getInput().getMatchCount(element);
return getText(((PDOMSearchElement)element).getBinding()) + " " //$NON-NLS-1$
final String text= super.getText(element);
final int count= getMatchCount(element);
if (count == 0) {
return text;
}
return text + " " //$NON-NLS-1$
+ CSearchMessages.getFormattedString("CSearchResultCollector.matches", new Integer(count)); //$NON-NLS-1$
} else
return super.getText(element);
}
}