1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 356493: Namespace alias in qualified name.

This commit is contained in:
Markus Schorn 2011-09-07 12:08:35 +02:00
parent ac6a9d9852
commit aa6c2c50d0
2 changed files with 29 additions and 1 deletions

View file

@ -1584,6 +1584,19 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
getBindingFromASTName("g(1)", 1);
}
// namespace ns {
// void fun();
// }
// namespace alias = ns;
// void alias::fun() {
// }
public void testNamespaceAliasAsQualifier_356493() throws Exception {
IFunction ref= getBindingFromASTName("fun", 0);
assertEquals("ns", ref.getOwner().getName());
}
/* CPP assertion helpers */
/* ##################################################################### */

View file

@ -137,6 +137,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
@ -2316,7 +2317,7 @@ public class CPPVisitor extends ASTQueries {
}
if (--i < 0)
break;
return qn[i].resolveBinding();
return bindingToOwner(qn[i].resolveBinding());
}
name= (IASTName) node;
node= node.getParent();
@ -2324,6 +2325,20 @@ public class CPPVisitor extends ASTQueries {
return findDeclarationOwner(node, allowFunction);
}
private static IBinding bindingToOwner(IBinding b) {
if (b instanceof ITypedef) {
IType t= SemanticUtil.getNestedType((IType) b, TDEF);
if (t instanceof IBinding)
return (IBinding) t;
return b;
}
while (b instanceof ICPPNamespaceAlias) {
b= ((ICPPNamespaceAlias) b).getBinding();
}
return b;
}
/**
* Searches for the first class, namespace, or function, if <code>allowFunction</code>
* is <code>true</code>, enclosing the declaration the provided node belongs to and returns