1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 18:26:01 +02:00

Proper implementation of ICPPClassType.getMethods() for all subclasses, bug 240599.

This commit is contained in:
Markus Schorn 2008-07-14 14:00:43 +00:00
parent d95322ff16
commit c032266686
11 changed files with 89 additions and 44 deletions

View file

@ -77,7 +77,7 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType {
}
public ICPPMethod[] getMethods() throws DOMException {
return null;
return CPPClassType.getMethods(this);
}
public ICPPMethod[] getAllDeclaredMethods() throws DOMException {

View file

@ -143,8 +143,7 @@ public class CPPClassSpecialization extends CPPSpecialization implements
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getMethods()
*/
public ICPPMethod[] getMethods() throws DOMException {
// TODO Auto-generated method stub
return null;
return CPPClassType.getMethods(this);
}
/* (non-Javadoc)

View file

@ -222,7 +222,7 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements
}
public ICPPMethod[] getMethods() throws DOMException {
return mixin.getMethods();
return CPPClassType.getMethods(this);
}
public ICPPMethod[] getAllDeclaredMethods() throws DOMException {

View file

@ -49,6 +49,7 @@ import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.ObjectSet;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
@ -61,6 +62,21 @@ import org.eclipse.core.runtime.PlatformObject;
* @author aniefer
*/
public class CPPClassType extends PlatformObject implements ICPPInternalClassTypeMixinHost {
public static ICPPMethod[] getMethods(ICPPClassType ct) throws DOMException {
ObjectSet<ICPPMethod> set = new ObjectSet<ICPPMethod>(4);
set.addAll(ct.getDeclaredMethods());
ICPPClassScope scope = (ICPPClassScope) ct.getCompositeScope();
set.addAll( scope.getImplicitMethods() );
ICPPBase [] bases = ct.getBases();
for (ICPPBase base : bases) {
IBinding b = base.getBaseClass();
if( b instanceof ICPPClassType )
set.addAll( ((ICPPClassType)b).getMethods() );
}
return set.keyArray(ICPPMethod.class);
}
public static class CPPClassTypeProblem extends ProblemBinding implements ICPPClassType{
public CPPClassTypeProblem( IASTNode node, int id, char[] arg ) {
super( node, id, arg );
@ -399,7 +415,7 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp
}
public ICPPMethod[] getMethods() throws DOMException {
return mixin.getMethods();
return getMethods(this);
}
public ICPPMethod[] getAllDeclaredMethods() throws DOMException {

View file

@ -124,21 +124,6 @@ class ClassTypeMixin {
return bindings;
}
public ICPPMethod[] getMethods() throws DOMException {
ObjectSet<ICPPMethod> set = new ObjectSet<ICPPMethod>(4);
set.addAll(getDeclaredMethods());
ICPPClassScope scope = (ICPPClassScope) host.getCompositeScope();
set.addAll( scope.getImplicitMethods() );
ICPPBase [] bases = getBases();
for (ICPPBase base : bases) {
IBinding b = base.getBaseClass();
if( b instanceof ICPPClassType )
set.addAll( ((ICPPClassType)b).getMethods() );
}
return set.keyArray(ICPPMethod.class);
}
public ICPPField[] getDeclaredFields() throws DOMException {
if( host.getDefinition() == null ){
host.checkForDefinition();

View file

@ -6,8 +6,9 @@
* 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.core.pdom.dom.cpp;
@ -41,6 +42,7 @@ import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPClassSpecializationScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
@ -184,11 +186,14 @@ class PDOMCPPClassInstance extends PDOMCPPInstance implements
public ICPPField[] getDeclaredFields() throws DOMException { fail(); return null; }
public IField[] getFields() throws DOMException { fail(); return null; }
public IBinding[] getFriends() throws DOMException { fail(); return null; }
public ICPPMethod[] getMethods() throws DOMException { fail(); return null; }
public ICPPClassType[] getNestedClasses() throws DOMException { fail(); return null; }
@Override
public Object clone() {fail();return null;}
public ICPPMethod[] getMethods() throws DOMException {
return CPPClassType.getMethods(this);
}
public ICPPClassType getClassType() {
return this;
}

View file

@ -6,8 +6,9 @@
* 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.core.pdom.dom.cpp;
@ -37,6 +38,7 @@ import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPClassSpecializationScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBase;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
@ -216,9 +218,12 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements
//ICPPClassType unimplemented
public IField[] getFields() throws DOMException { fail(); return null; }
public IBinding[] getFriends() throws DOMException { fail(); return null; }
public ICPPMethod[] getMethods() throws DOMException { fail(); return null; }
public ICPPClassType[] getNestedClasses() throws DOMException { fail(); return null; }
public ICPPMethod[] getMethods() throws DOMException {
return CPPClassType.getMethods(this);
}
public IScope getCompositeScope() throws DOMException {
return this;
}

View file

@ -47,6 +47,7 @@ import org.eclipse.cdt.core.parser.util.CharArrayMap;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.index.IIndexScope;
@ -224,15 +225,8 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
}
}
public ICPPMethod[] getMethods() throws DOMException {
try {
PDOMClassUtil.MethodCollector methods = new PDOMClassUtil.MethodCollector(true);
acceptInHierarchy(this, new HashSet<IPDOMMemberOwner>(), methods);
return methods.getMethods();
} catch (CoreException e) {
CCorePlugin.log(e);
return new ICPPMethod[0];
}
public ICPPMethod[] getMethods() throws DOMException {
return CPPClassType.getMethods(this);
}
public ICPPMethod[] getImplicitMethods() {

View file

@ -162,11 +162,14 @@ class PDOMCPPDeferredClassInstance extends PDOMCPPInstance implements ICPPDeferr
public ICPPField[] getDeclaredFields() throws DOMException { fail(); return null; }
public IField[] getFields() throws DOMException { fail(); return null; }
public IBinding[] getFriends() throws DOMException { fail(); return null; }
public ICPPMethod[] getMethods() throws DOMException { fail(); return null; }
public ICPPClassType[] getNestedClasses() throws DOMException { fail(); return null; }
@Override
public Object clone() {fail();return null;}
public ICPPMethod[] getMethods() throws DOMException {
return ICPPMethod.EMPTY_CPPMETHOD_ARRAY;
}
public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) {
IType[] arguments = getArguments();
IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap, instantiationScope);

View file

@ -67,6 +67,7 @@ public class BaseUITestCase extends BaseTestCase {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.testplugin.util.BaseTestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
super.setUp();
}
@ -74,6 +75,7 @@ public class BaseUITestCase extends BaseTestCase {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.testplugin.util.BaseTestCase#tearDown()
*/
@Override
protected void tearDown() throws Exception {
runEventQueue(0);
super.tearDown();
@ -249,13 +251,13 @@ public class BaseUITestCase extends BaseTestCase {
hs.executeCommand(commandID, null);
}
private Control[] findControls(Control w, Class clazz) {
ArrayList result= new ArrayList();
private Control[] findControls(Control w, Class<?> clazz) {
ArrayList<Control> result= new ArrayList<Control>();
findControls(w, clazz, result);
return (Control[]) result.toArray(new Control[result.size()]);
return result.toArray(new Control[result.size()]);
}
private void findControls(Control w, Class clazz, List result) {
private void findControls(Control w, Class<?> clazz, List<Control> result) {
if (clazz.isInstance(w)) {
result.add(w);
}
@ -271,7 +273,9 @@ public class BaseUITestCase extends BaseTestCase {
final protected TreeItem checkTreeNode(IViewPart part, int i0, String label) {
Tree tree= null;
TreeItem root= null;
StringBuilder cands= new StringBuilder();
for (int i=0; i<400; i++) {
cands.setLength(0);
Control[] trees= findControls(part.getSite().getShell(), Tree.class);
for (int j = 0; j < trees.length; j++) {
try {
@ -280,6 +284,10 @@ public class BaseUITestCase extends BaseTestCase {
if (label.equals(root.getText())) {
return root;
}
if (j > 0) {
cands.append('|');
}
cands.append(root.getText());
}
catch (SWTException e) {
// in case widget was disposed, item may be replaced
@ -292,7 +300,7 @@ public class BaseUITestCase extends BaseTestCase {
}
assertNotNull("No tree in viewpart", tree);
assertNotNull("Tree node " + label + "{" + i0 + "} does not exist!", root);
assertEquals(label, root.getText());
assertEquals(label, cands.toString());
return root;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* Copyright (c) 2007, 2008 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
@ -8,7 +8,6 @@
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.callhierarchy;
import junit.framework.Test;
@ -43,6 +42,7 @@ public class CallHierarchyBugs extends CallHierarchyBaseTest {
return suite(CallHierarchyBugs.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
restoreAllParts();
@ -249,4 +249,34 @@ public class CallHierarchyBugs extends CallHierarchyBaseTest {
checkTreeNode(item, 1, "Derived::vmethod()");
checkTreeNode(item, 2, null);
}
// template <class T> class CSome {
// public:
// T Foo (const T& x) { return 2*x; }
// };
// template <> class CSome <int> {
// public:
// int Foo (const int& x) { return 3*x; }
// };
// void test() {
// CSome <int> X;
// X.Foo(3);
// }
public void testMethodInstance_Bug240599() throws Exception {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "CSome.cpp", content);
waitForIndexer(fIndex, file, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
final CHViewPart ch= (CHViewPart) activateView(CUIPlugin.ID_CALL_HIERARCHY);
final IWorkbenchWindow workbenchWindow = ch.getSite().getWorkbenchWindow();
// open editor, check outline
CEditor editor= openEditor(file);
int idx = content.indexOf("Foo(3)");
editor.selectAndReveal(idx, 0);
openCallHierarchy(editor, true);
Tree chTree= checkTreeNode(ch, 0, "CSome::Foo(const int &)").getParent();
TreeItem item= checkTreeNode(chTree, 0, 0, "test()");
checkTreeNode(chTree, 0, 1, null);
}
}