mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
add composite for (ITypedef & ICPPSpecialization) binding
This commit is contained in:
parent
f2655d2516
commit
eb628d737d
4 changed files with 75 additions and 2 deletions
|
@ -15,6 +15,7 @@ import junit.framework.TestSuite;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.IType;
|
import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||||
|
@ -43,6 +44,44 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
||||||
suite.addTest(suite(ProjectWithDepProj.class));
|
suite.addTest(suite(ProjectWithDepProj.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IndexCPPTemplateResolutionTest() {
|
||||||
|
setStrategy(new ReferencedProject(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
// template<typename T> class A {
|
||||||
|
// public:
|
||||||
|
// typedef T TD;
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// class B {};
|
||||||
|
// A<B>::TD foo;
|
||||||
|
|
||||||
|
// class C {};
|
||||||
|
// A<C>::TD bar;
|
||||||
|
//
|
||||||
|
// void qux() {
|
||||||
|
// A<B>::TD foo2= foo;
|
||||||
|
// A<C>::TD bar2= bar;
|
||||||
|
// }
|
||||||
|
public void testTypedefSpecialization() {
|
||||||
|
IBinding b0= getBindingFromASTName("TD foo2", 2);
|
||||||
|
IBinding b1= getBindingFromASTName("TD bar2", 2);
|
||||||
|
assertInstance(b0, ITypedef.class);
|
||||||
|
assertInstance(b1, ITypedef.class);
|
||||||
|
assertInstance(b0, ICPPSpecialization.class);
|
||||||
|
assertInstance(b1, ICPPSpecialization.class);
|
||||||
|
ObjectMap om0= ((ICPPSpecialization)b0).getArgumentMap();
|
||||||
|
ObjectMap om1= ((ICPPSpecialization)b1).getArgumentMap();
|
||||||
|
assertEquals(1, om0.size());
|
||||||
|
assertEquals(1, om1.size());
|
||||||
|
assertInstance(om0.keyAt(0), ICPPTemplateTypeParameter.class);
|
||||||
|
assertInstance(om0.getAt(0), ICPPClassType.class);
|
||||||
|
assertInstance(om1.keyAt(0), ICPPTemplateTypeParameter.class);
|
||||||
|
assertInstance(om1.getAt(0), ICPPClassType.class);
|
||||||
|
assertEquals("B", ((ICPPClassType)om0.getAt(0)).getName());
|
||||||
|
assertEquals("C", ((ICPPClassType)om1.getAt(0)).getName());
|
||||||
|
}
|
||||||
|
|
||||||
// template<typename X>
|
// template<typename X>
|
||||||
// void foo(X x) {}
|
// void foo(X x) {}
|
||||||
//
|
//
|
||||||
|
|
|
@ -53,6 +53,7 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
import org.eclipse.cdt.core.parser.util.ObjectSet;
|
import org.eclipse.cdt.core.parser.util.ObjectSet;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassType.CPPClassTypeProblem;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassType.CPPClassTypeProblem;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndexType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author aniefer
|
* @author aniefer
|
||||||
|
@ -484,8 +485,8 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements
|
||||||
public boolean isSameType( IType type ) {
|
public boolean isSameType( IType type ) {
|
||||||
if( type == this )
|
if( type == this )
|
||||||
return true;
|
return true;
|
||||||
if( type instanceof ITypedef )
|
if( type instanceof ITypedef || type instanceof IIndexType)
|
||||||
return ((ITypedef)type).isSameType( this );
|
return type.isSameType( this );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -207,6 +207,8 @@ public class CPPCompositesFactory extends AbstractCompositeFactory implements IC
|
||||||
return new CompositeCPPField(this, (ICPPField) binding);
|
return new CompositeCPPField(this, (ICPPField) binding);
|
||||||
} if(binding instanceof ICPPParameter) {
|
} if(binding instanceof ICPPParameter) {
|
||||||
return new CompositeCPPParameterSpecialization(this, (ICPPParameter) binding);
|
return new CompositeCPPParameterSpecialization(this, (ICPPParameter) binding);
|
||||||
|
} if(binding instanceof ITypedef) {
|
||||||
|
return new CompositeCPPTypedefSpecialization(this, (ICPPBinding) binding);
|
||||||
} else {
|
} else {
|
||||||
throw new CompositingNotImplementedError("composite binding unavailable for "+binding+" "+binding.getClass()); //$NON-NLS-1$ //$NON-NLS-2$
|
throw new CompositingNotImplementedError("composite binding unavailable for "+binding+" "+binding.getClass()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2007 Symbian Software Systems and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Andrew Ferguson (Symbian) - Initial implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.core.index.composite.cpp;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||||
|
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||||
|
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
|
||||||
|
|
||||||
|
class CompositeCPPTypedefSpecialization extends CompositeCPPTypedef implements ICPPSpecialization {
|
||||||
|
public CompositeCPPTypedefSpecialization(ICompositesFactory cf, ICPPBinding delegate) {
|
||||||
|
super(cf, delegate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectMap getArgumentMap() {
|
||||||
|
return TemplateInstanceUtil.getArgumentMap(cf, rbinding);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IBinding getSpecializedBinding() {
|
||||||
|
return TemplateInstanceUtil.getSpecializedBinding(cf, rbinding);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue