From 885d10dd7a33c33b45b2a0e0b44f101185866c19 Mon Sep 17 00:00:00 2001 From: Andrew Niefer Date: Thu, 24 Feb 2005 20:45:41 +0000 Subject: [PATCH] fix bug 86358 --- .../core/parser/tests/ast2/AST2CPPTests.java | 47 +++++++++++++++++++ .../core/dom/parser/cpp/CPPFunction.java | 15 +++++- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index e79fa949c01..0e1223d1cb3 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -2289,5 +2289,52 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances( col, point, 4 ); } + + public void testBug86358_1() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("namespace Outer{ \n"); //$NON-NLS-1$ + buffer.append(" int i; \n"); //$NON-NLS-1$ + buffer.append(" namespace Inner { \n"); //$NON-NLS-1$ + buffer.append(" void f() { i++; } \n"); //$NON-NLS-1$ + buffer.append(" int i; \n"); //$NON-NLS-1$ + buffer.append(" void g() { i++; } \n"); //$NON-NLS-1$ + buffer.append(" } \n"); //$NON-NLS-1$ + buffer.append("} \n"); //$NON-NLS-1$ + + IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); + CPPNameCollector col = new CPPNameCollector(); + tu.getVisitor().visitTranslationUnit(col); + + IVariable i = (IVariable) col.getName(4).resolveBinding(); + IVariable i2 = (IVariable) col.getName(7).resolveBinding(); + + assertInstances( col, i, 2 ); + assertInstances( col, i2, 2 ); + } + + public void testBug86358_2() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("namespace Q { \n"); //$NON-NLS-1$ + buffer.append(" namespace V { \n"); //$NON-NLS-1$ + buffer.append(" void f(); \n"); //$NON-NLS-1$ + buffer.append(" } \n"); //$NON-NLS-1$ + buffer.append(" void V::f() {} \n"); //$NON-NLS-1$ + buffer.append(" namespace V { \n"); //$NON-NLS-1$ + buffer.append(" } \n"); //$NON-NLS-1$ + buffer.append("} \n"); //$NON-NLS-1$ + + IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); + CPPNameCollector col = new CPPNameCollector(); + tu.getVisitor().visitTranslationUnit(col); + + IFunction f1 = (IFunction) col.getName(2).resolveBinding(); + IFunction f2 = (IFunction) col.getName(5).resolveBinding(); + assertSame( f1, f2 ); + + IASTName [] decls = tu.getDeclarations( f2 ); + assertEquals( decls.length, 2 ); + assertSame( decls[0], col.getName(2) ); + assertSame( decls[1], col.getName(5) ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java index 61638de3f71..3f7904aa5b6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java @@ -31,6 +31,7 @@ import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; @@ -181,14 +182,24 @@ public class CPPFunction implements IFunction, ICPPBinding { * @see org.eclipse.cdt.core.dom.ast.IBinding#getName() */ public String getName() { - return (definition != null ) ? definition.getName().toString() : declarations[0].getName().toString(); + IASTName name = (definition != null ) ? definition.getName() : declarations[0].getName(); + if( name instanceof ICPPASTQualifiedName ){ + IASTName [] ns = ((ICPPASTQualifiedName)name).getNames(); + name = ns[ ns.length - 1 ]; + } + return name.toString(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray() */ public char[] getNameCharArray() { - return (definition != null ) ? definition.getName().toCharArray() : declarations[0].getName().toCharArray(); + IASTName name = (definition != null ) ? definition.getName() : declarations[0].getName(); + if( name instanceof ICPPASTQualifiedName ){ + IASTName [] ns = ((ICPPASTQualifiedName)name).getNames(); + name = ns[ ns.length - 1 ]; + } + return name.toCharArray(); } /* (non-Javadoc)