1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 14:55:41 +02:00

Open Element to show macro parameters, bug 209762.

This commit is contained in:
Markus Schorn 2008-03-05 13:44:35 +00:00
parent bb5cead81a
commit a5f83b394c
4 changed files with 77 additions and 20 deletions

View file

@ -125,7 +125,16 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
*/ */
public static IndexTypeInfo create(IIndex index, IIndexMacro macro) { public static IndexTypeInfo create(IIndex index, IIndexMacro macro) {
final char[] name= macro.getNameCharArray(); final char[] name= macro.getNameCharArray();
return new IndexTypeInfo(new String[] {new String(name)}, ICElement.C_MACRO, index); final char[][] ps= macro.getParameterList();
String[] params= null;
if (ps != null) {
params= new String[ps.length];
int i=-1;
for (char[] p : ps) {
params[++i]= new String(p);
}
}
return new IndexTypeInfo(new String[] {new String(name)}, ICElement.C_MACRO, params, null, index);
} }
private IndexTypeInfo(String[] fqn, IIndexFileLocation fileLocal, int elementType, IIndex index, String[] params, String returnType, ITypeReference reference) { private IndexTypeInfo(String[] fqn, IIndexFileLocation fileLocal, int elementType, IIndex index, String[] params, String returnType, ITypeReference reference) {
@ -412,6 +421,7 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
HashMap<IIndexFileLocation, IIndexFile> iflMap= new HashMap<IIndexFileLocation, IIndexFile>(); HashMap<IIndexFileLocation, IIndexFile> iflMap= new HashMap<IIndexFileLocation, IIndexFile>();
for (int i = 0; i < ibs.length; i++) { for (int i = 0; i < ibs.length; i++) {
IIndexMacro macro= ibs[i]; IIndexMacro macro= ibs[i];
if (checkParameters(macro.getParameterList())) {
if (checkFile(iflMap, macro.getFile())) { if (checkFile(iflMap, macro.getFile())) {
IndexTypeReference ref= createReference(macro); IndexTypeReference ref= createReference(macro);
if (ref != null) { if (ref != null) {
@ -419,6 +429,7 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
} }
} }
} }
}
} catch(CoreException ce) { } catch(CoreException ce) {
CCorePlugin.log(ce); CCorePlugin.log(ce);
} catch (InterruptedException ie) { } catch (InterruptedException ie) {
@ -429,6 +440,21 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
return references.toArray(new IndexTypeReference[references.size()]); return references.toArray(new IndexTypeReference[references.size()]);
} }
private boolean checkParameters(char[][] parameterList) {
if (parameterList == null) {
return params == null;
}
if (params == null || parameterList.length != params.length) {
return false;
}
for (int i = 0; i < parameterList.length; i++) {
if (!params[i].equals(new String(parameterList[i]))) {
return false;
}
}
return true;
}
/** /**
* Makes sure that per file only refs from one IIndexFile object are taken. * Makes sure that per file only refs from one IIndexFile object are taken.
*/ */
@ -520,6 +546,7 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
return returnType; return returnType;
} }
@Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
@ -532,6 +559,7 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
/** /**
* Type info objects are equal if they compute the same references. * Type info objects are equal if they compute the same references.
*/ */
@Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj)
return true; return true;

View file

@ -73,6 +73,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
setPriority(Job.LONG); setPriority(Job.LONG);
} }
@Override
public IStatus run(final IProgressMonitor monitor) { public IStatus run(final IProgressMonitor monitor) {
monitor.beginTask(OpenTypeMessages.ElementSelectionDialog_UpdateElementsJob_inProgress, IProgressMonitor.UNKNOWN); monitor.beginTask(OpenTypeMessages.ElementSelectionDialog_UpdateElementsJob_inProgress, IProgressMonitor.UNKNOWN);
final ITypeInfo[] elements= getElementsByPrefix(fCurrentPrefix, monitor); final ITypeInfo[] elements= getElementsByPrefix(fCurrentPrefix, monitor);
@ -108,6 +109,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
fMonitor= monitor; fMonitor= monitor;
} }
@Override
public void done(IJobChangeEvent event) { public void done(IJobChangeEvent event) {
fDone= true; fDone= true;
final Shell shell= getShell(); final Shell shell= getShell();
@ -122,6 +124,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
} }
} }
@Override
public void running(final IJobChangeEvent event) { public void running(final IJobChangeEvent event) {
fDone= false; fDone= false;
final Shell shell= getShell(); final Shell shell= getShell();
@ -172,6 +175,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
/* /*
* @see org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog#create() * @see org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog#create()
*/ */
@Override
public void create() { public void create() {
super.create(); super.create();
// trigger initial query // trigger initial query
@ -181,6 +185,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
/* /*
* @see org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog#close() * @see org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog#close()
*/ */
@Override
public boolean close() { public boolean close() {
fUpdateJob.cancel(); fUpdateJob.cancel();
return super.close(); return super.close();
@ -199,6 +204,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
/* /*
* @see org.eclipse.ui.dialogs.AbstractElementListSelectionDialog#setMatchEmptyString(boolean) * @see org.eclipse.ui.dialogs.AbstractElementListSelectionDialog#setMatchEmptyString(boolean)
*/ */
@Override
public void setMatchEmptyString(boolean matchEmptyString) { public void setMatchEmptyString(boolean matchEmptyString) {
super.setMatchEmptyString(matchEmptyString); super.setMatchEmptyString(matchEmptyString);
fAllowEmptyString= matchEmptyString; fAllowEmptyString= matchEmptyString;
@ -219,6 +225,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
/* /*
* @see org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog#showLowLevelFilter() * @see org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog#showLowLevelFilter()
*/ */
@Override
protected boolean showLowLevelFilter() { protected boolean showLowLevelFilter() {
// the low-level filter is useless for us // the low-level filter is useless for us
return false; return false;
@ -227,6 +234,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
/* /*
* @see org.eclipse.ui.dialogs.TwoPaneElementSelector#createDialogArea(org.eclipse.swt.widgets.Composite) * @see org.eclipse.ui.dialogs.TwoPaneElementSelector#createDialogArea(org.eclipse.swt.widgets.Composite)
*/ */
@Override
public Control createDialogArea(Composite parent) { public Control createDialogArea(Composite parent) {
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, fHelpContextId); PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, fHelpContextId);
return super.createDialogArea(parent); return super.createDialogArea(parent);
@ -235,6 +243,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
/* /*
* @see org.eclipse.ui.dialogs.TwoPaneElementSelector#createLowerList(org.eclipse.swt.widgets.Composite) * @see org.eclipse.ui.dialogs.TwoPaneElementSelector#createLowerList(org.eclipse.swt.widgets.Composite)
*/ */
@Override
protected Table createLowerList(Composite parent) { protected Table createLowerList(Composite parent) {
Table table= super.createLowerList(parent); Table table= super.createLowerList(parent);
createProgressMonitorPart(parent); createProgressMonitorPart(parent);
@ -268,9 +277,10 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
if (monitor.isCanceled()) { if (monitor.isCanceled()) {
return null; return null;
} }
HashSet types = new HashSet(); HashSet<IndexTypeInfo> types = new HashSet<IndexTypeInfo>();
if(prefix != null) { if(prefix != null) {
final IndexFilter filter= new IndexFilter() { final IndexFilter filter= new IndexFilter() {
@Override
public boolean acceptBinding(IBinding binding) throws CoreException { public boolean acceptBinding(IBinding binding) throws CoreException {
if (isVisibleType(IndexModelUtil.getElementType(binding))) { if (isVisibleType(IndexModelUtil.getElementType(binding))) {
return IndexFilter.ALL_DECLARED.acceptBinding(binding); return IndexFilter.ALL_DECLARED.acceptBinding(binding);
@ -310,9 +320,10 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
CCorePlugin.log(ie); CCorePlugin.log(ie);
} }
} }
return (ITypeInfo[])types.toArray(new ITypeInfo[types.size()]); return types.toArray(new ITypeInfo[types.size()]);
} }
@Override
protected final void setListElements(Object[] elements) { protected final void setListElements(Object[] elements) {
super.setListElements(elements); super.setListElements(elements);
} }
@ -320,14 +331,18 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
/** /**
* @deprecated Unsupported * @deprecated Unsupported
*/ */
@Deprecated
@Override
public void setElements(Object[] elements) { public void setElements(Object[] elements) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
protected void handleEmptyList() { protected void handleEmptyList() {
updateOkState(); updateOkState();
} }
@Override
protected Text createFilterText(Composite parent) { protected Text createFilterText(Composite parent) {
final Text result = super.createFilterText(parent); final Text result = super.createFilterText(parent);
Listener listener = new Listener() { Listener listener = new Listener() {

View file

@ -69,6 +69,7 @@ public class TypeInfoLabelProvider extends LabelProvider {
/* non java-doc /* non java-doc
* @see ILabelProvider#getText * @see ILabelProvider#getText
*/ */
@Override
public String getText(Object element) { public String getText(Object element) {
if (! (element instanceof ITypeInfo)) if (! (element instanceof ITypeInfo))
return super.getText(element); return super.getText(element);
@ -95,7 +96,7 @@ public class TypeInfoLabelProvider extends LabelProvider {
} }
buf.append(qualifiedName.getFullyQualifiedName()); buf.append(qualifiedName.getFullyQualifiedName());
} }
if (isSet(SHOW_PARAMETERS) && typeInfo.getCElementType() == ICElement.C_FUNCTION) { if (isSet(SHOW_PARAMETERS) && typeInfo.getCElementType() == ICElement.C_FUNCTION || typeInfo.getCElementType() == ICElement.C_MACRO) {
if (typeInfo instanceof IFunctionInfo) { if (typeInfo instanceof IFunctionInfo) {
IFunctionInfo functionInfo= (IFunctionInfo)typeInfo; IFunctionInfo functionInfo= (IFunctionInfo)typeInfo;
String[] params= functionInfo.getParameters(); String[] params= functionInfo.getParameters();
@ -157,6 +158,7 @@ public class TypeInfoLabelProvider extends LabelProvider {
/* non java-doc /* non java-doc
* @see ILabelProvider#getImage * @see ILabelProvider#getImage
*/ */
@Override
public Image getImage(Object element) { public Image getImage(Object element) {
if (!(element instanceof ITypeInfo)) if (!(element instanceof ITypeInfo))
return super.getImage(element); return super.getImage(element);

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others. * Copyright (c) 2004, 2008 IBM Corporation 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
@ -62,7 +62,7 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
private StringMatcher fNameMatcher = null; private StringMatcher fNameMatcher = null;
private StringMatcher[] fSegmentMatchers = null; private StringMatcher[] fSegmentMatchers = null;
private boolean fMatchGlobalNamespace = false; private boolean fMatchGlobalNamespace = false;
private Collection fVisibleTypes = new HashSet(); private Collection<Integer> fVisibleTypes = new HashSet<Integer>();
private boolean fShowLowLevelTypes = false; private boolean fShowLowLevelTypes = false;
/* /*
@ -107,12 +107,12 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
fNameMatcher = fSegmentMatchers[fSegmentMatchers.length-1]; fNameMatcher = fSegmentMatchers[fSegmentMatchers.length-1];
} }
public void setVisibleTypes(Collection visibleTypes) { public void setVisibleTypes(Collection<Integer> visibleTypes) {
fVisibleTypes.clear(); fVisibleTypes.clear();
fVisibleTypes.addAll(visibleTypes); fVisibleTypes.addAll(visibleTypes);
} }
public Collection getVisibleTypes() { public Collection<Integer> getVisibleTypes() {
return fVisibleTypes; return fVisibleTypes;
} }
@ -228,7 +228,7 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
// the filter matcher contains state information, must not be static // the filter matcher contains state information, must not be static
private final TypeFilterMatcher fFilterMatcher = new TypeFilterMatcher(); private final TypeFilterMatcher fFilterMatcher = new TypeFilterMatcher();
private Set fKnownTypes = new HashSet(ALL_TYPES.length); private Set<Integer> fKnownTypes = new HashSet<Integer>(ALL_TYPES.length);
private Text fTextWidget; private Text fTextWidget;
private boolean fSelectFilterText = false; private boolean fSelectFilterText = false;
private FilteredList fNewFilteredList; private FilteredList fNewFilteredList;
@ -296,6 +296,7 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.ui.dialogs.AbstractElementListSelectionDialog#createFilterText(org.eclipse.swt.widgets.Composite) * @see org.eclipse.ui.dialogs.AbstractElementListSelectionDialog#createFilterText(org.eclipse.swt.widgets.Composite)
*/ */
@Override
protected Text createFilterText(Composite parent) { protected Text createFilterText(Composite parent) {
fTextWidget = super.createFilterText(parent); fTextWidget = super.createFilterText(parent);
@ -308,6 +309,7 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.ui.dialogs.AbstractElementListSelectionDialog#createFilteredList(org.eclipse.swt.widgets.Composite) * @see org.eclipse.ui.dialogs.AbstractElementListSelectionDialog#createFilteredList(org.eclipse.swt.widgets.Composite)
*/ */
@Override
protected FilteredList createFilteredList(Composite parent) { protected FilteredList createFilteredList(Composite parent) {
fNewFilteredList = super.createFilteredList(parent); fNewFilteredList = super.createFilteredList(parent);
fNewFilteredList.setFilterMatcher(fFilterMatcher); fNewFilteredList.setFilterMatcher(fFilterMatcher);
@ -316,6 +318,7 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
if (fNewFilteredList != null) { if (fNewFilteredList != null) {
fNewFilteredList.getAccessible().addAccessibleListener( fNewFilteredList.getAccessible().addAccessibleListener(
new AccessibleAdapter() { new AccessibleAdapter() {
@Override
public void getName(AccessibleEvent e) { public void getName(AccessibleEvent e) {
e.result = TypeInfoMessages.TypeSelectionDialog_upperLabel; e.result = TypeInfoMessages.TypeSelectionDialog_upperLabel;
} }
@ -328,6 +331,7 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.jface.window.Window#create() * @see org.eclipse.jface.window.Window#create()
*/ */
@Override
public void create() { public void create() {
super.create(); super.create();
if (fSelectFilterText) if (fSelectFilterText)
@ -337,6 +341,7 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
/* /*
* @see Window#close() * @see Window#close()
*/ */
@Override
public boolean close() { public boolean close() {
writeSettings(getDialogSettings()); writeSettings(getDialogSettings());
return super.close(); return super.close();
@ -345,6 +350,7 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
/* /*
* @see org.eclipse.jface.window.Window#createContents(org.eclipse.swt.widgets.Composite) * @see org.eclipse.jface.window.Window#createContents(org.eclipse.swt.widgets.Composite)
*/ */
@Override
protected Control createContents(Composite parent) { protected Control createContents(Composite parent) {
readSettings(getDialogSettings()); readSettings(getDialogSettings());
return super.createContents(parent); return super.createContents(parent);
@ -400,6 +406,7 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
checkbox.setImage(icon); checkbox.setImage(icon);
checkbox.setSelection(fFilterMatcher.getVisibleTypes().contains(fTypeObject)); checkbox.setSelection(fFilterMatcher.getVisibleTypes().contains(fTypeObject));
checkbox.addSelectionListener(new SelectionAdapter() { checkbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
if (e.widget instanceof Button) { if (e.widget instanceof Button) {
Button checkbox = (Button) e.widget; Button checkbox = (Button) e.widget;
@ -458,6 +465,7 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
checkbox.setText(name); checkbox.setText(name);
checkbox.setSelection(fFilterMatcher.getShowLowLevelTypes()); checkbox.setSelection(fFilterMatcher.getShowLowLevelTypes());
checkbox.addSelectionListener(new SelectionAdapter() { checkbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
if (e.widget instanceof Button) { if (e.widget instanceof Button) {
Button button = (Button) e.widget; Button button = (Button) e.widget;
@ -614,6 +622,7 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
/* (non-Cdoc) /* (non-Cdoc)
* @see org.eclipse.jface.window.Window#getInitialSize() * @see org.eclipse.jface.window.Window#getInitialSize()
*/ */
@Override
protected Point getInitialSize() { protected Point getInitialSize() {
Point result = super.getInitialSize(); Point result = super.getInitialSize();
if (fSize != null) { if (fSize != null) {
@ -629,6 +638,7 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
/* (non-Cdoc) /* (non-Cdoc)
* @see org.eclipse.jface.window.Window#getInitialLocation(org.eclipse.swt.graphics.Point) * @see org.eclipse.jface.window.Window#getInitialLocation(org.eclipse.swt.graphics.Point)
*/ */
@Override
protected Point getInitialLocation(Point initialSize) { protected Point getInitialLocation(Point initialSize) {
Point result = super.getInitialLocation(initialSize); Point result = super.getInitialLocation(initialSize);
if (fLocation != null) { if (fLocation != null) {
@ -650,18 +660,20 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
/* /*
* @see org.eclipse.ui.dialogs.SelectionStatusDialog#computeResult() * @see org.eclipse.ui.dialogs.SelectionStatusDialog#computeResult()
*/ */
@Override
protected void computeResult() { protected void computeResult() {
ITypeInfo selection = (ITypeInfo) getLowerSelectedElement(); ITypeInfo selection = (ITypeInfo) getLowerSelectedElement();
if (selection == null) if (selection == null)
return; return;
List result = new ArrayList(1); List<ITypeInfo> result = new ArrayList<ITypeInfo>(1);
result.add(selection); result.add(selection);
setResult(result); setResult(result);
} }
@Override
public Object[] getFoldedElements(int index) { public Object[] getFoldedElements(int index) {
ArrayList result= new ArrayList(); ArrayList<IndexTypeInfo> result= new ArrayList<IndexTypeInfo>();
Object[] typeInfos= super.getFoldedElements(index); Object[] typeInfos= super.getFoldedElements(index);
if (typeInfos != null) { if (typeInfos != null) {
for (int i = 0; i < typeInfos.length; i++) { for (int i = 0; i < typeInfos.length; i++) {
@ -674,7 +686,7 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
return result.toArray(); return result.toArray();
} }
private void addFoldedElements(IndexTypeInfo typeInfo, ArrayList result) { private void addFoldedElements(IndexTypeInfo typeInfo, ArrayList<IndexTypeInfo> result) {
ITypeReference[] refs= typeInfo.getReferences(); ITypeReference[] refs= typeInfo.getReferences();
for (int i = 0; i < refs.length; i++) { for (int i = 0; i < refs.length; i++) {
result.add(new IndexTypeInfo(typeInfo, refs[i])); result.add(new IndexTypeInfo(typeInfo, refs[i]));