mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 18:56:02 +02:00
Bug 311164: Correct getDefinitions() for specializations.
This commit is contained in:
parent
5e9a025222
commit
37f471698a
6 changed files with 57 additions and 30 deletions
|
@ -19,6 +19,7 @@ import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUti
|
||||||
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getUltimateType;
|
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getUltimateType;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.IName;
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||||
|
@ -4963,4 +4964,34 @@ public class AST2TemplateTests extends AST2BaseTest {
|
||||||
final String code= getAboveComment();
|
final String code= getAboveComment();
|
||||||
parseAndCheckBindings(code);
|
parseAndCheckBindings(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// template<typename T1, typename T2> class CT {};
|
||||||
|
// template<> class CT<int,char> {};
|
||||||
|
// template<> class CT<char,char> {};
|
||||||
|
public void testBug311164() throws Exception {
|
||||||
|
CPPASTNameBase.sAllowNameComputation= true;
|
||||||
|
final String code= getAboveComment();
|
||||||
|
parseAndCheckBindings(code);
|
||||||
|
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
|
||||||
|
final IASTTranslationUnit tu = bh.getTranslationUnit();
|
||||||
|
|
||||||
|
IBinding b= bh.assertNonProblem("CT {", 2);
|
||||||
|
IName[] names = tu.getDeclarationsInAST(b);
|
||||||
|
assertEquals(1, names.length);
|
||||||
|
assertEquals("CT", names[0].toString());
|
||||||
|
names= tu.getReferences(b);
|
||||||
|
assertEquals(2, names.length);
|
||||||
|
assertEquals("CT", names[0].toString());
|
||||||
|
assertEquals("CT", names[1].toString());
|
||||||
|
|
||||||
|
b= bh.assertNonProblem("CT<int,char>", 0);
|
||||||
|
names = tu.getDeclarationsInAST(b);
|
||||||
|
assertEquals(1, names.length);
|
||||||
|
assertEquals("CT<int, char>", names[0].toString());
|
||||||
|
|
||||||
|
b= bh.assertNonProblem("CT<char,char>", 0);
|
||||||
|
names = tu.getDeclarationsInAST(b);
|
||||||
|
assertEquals(1, names.length);
|
||||||
|
assertEquals("CT<char, char>", names[0].toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
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.ICPPNamespace;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||||
|
@ -1728,28 +1727,5 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest {
|
||||||
assertEquals(offset, loc.getNodeOffset());
|
assertEquals(offset, loc.getNodeOffset());
|
||||||
assertEquals(length, loc.getNodeLength());
|
assertEquals(length, loc.getNodeLength());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBug92632() throws Exception
|
|
||||||
{
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
|
||||||
buffer.append("namespace N{ \n"); //$NON-NLS-1$
|
|
||||||
buffer.append(" template < class T > class AAA { T _t; };\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("} \n"); //$NON-NLS-1$
|
|
||||||
buffer.append("N::AAA<int> a; \n"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
String code = buffer.toString();
|
|
||||||
int index = code.indexOf("AAA<int>"); //$NON-NLS-1$
|
|
||||||
IASTNode node = parse( code, index, index + 8, true );
|
|
||||||
assertNotNull( node );
|
|
||||||
assertTrue( node instanceof IASTName );
|
|
||||||
assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPTemplateInstance );
|
|
||||||
assertEquals( ((IASTName)node).toString(), "AAA<int>" ); //$NON-NLS-1$
|
|
||||||
IName[] decls = getDeclarationOffTU((IASTName)node);
|
|
||||||
assertEquals(decls.length, 1);
|
|
||||||
assertEquals( decls[0].toString(), "AAA" ); //$NON-NLS-1$
|
|
||||||
assertEquals( ((ASTNode)decls[0]).getOffset(), 53);
|
|
||||||
assertEquals( ((ASTNode)decls[0]).getLength(), 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -197,8 +197,8 @@ public class IndexLocationTest extends BaseTestCase {
|
||||||
assertTrue(content2.getFile("external2.h").exists());
|
assertTrue(content2.getFile("external2.h").exists());
|
||||||
|
|
||||||
IIndex index = CCorePlugin.getIndexManager().getIndex(cproject);
|
IIndex index = CCorePlugin.getIndexManager().getIndex(cproject);
|
||||||
TestSourceReader.waitUntilFileIsIndexed(index, file, 10000);
|
|
||||||
CCorePlugin.getIndexManager().reindex(cproject);
|
CCorePlugin.getIndexManager().reindex(cproject);
|
||||||
|
TestSourceReader.waitUntilFileIsIndexed(index, file, 10000);
|
||||||
waitForIndexer(cproject);
|
waitForIndexer(cproject);
|
||||||
index.acquireReadLock();
|
index.acquireReadLock();
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1437,10 +1437,9 @@ public class CPPVisitor extends ASTQueries {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isDeclarationsBinding(IBinding nameBinding) {
|
private boolean isDeclarationsBinding(IBinding nameBinding) {
|
||||||
nameBinding= unwindBinding(nameBinding);
|
|
||||||
if (nameBinding != null) {
|
if (nameBinding != null) {
|
||||||
for (IBinding binding : bindings) {
|
for (IBinding binding : bindings) {
|
||||||
if (nameBinding.equals(unwindBinding(binding))) {
|
if (nameBinding.equals(binding)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// a using declaration is a declaration for the references of its delegates
|
// a using declaration is a declaration for the references of its delegates
|
||||||
|
|
|
@ -337,13 +337,16 @@ public class BaseUITestCase extends BaseTestCase {
|
||||||
final protected TreeItem checkTreeNode(Tree tree, int i0, int i1, String label) {
|
final protected TreeItem checkTreeNode(Tree tree, int i0, int i1, String label) {
|
||||||
TreeItem item= null;
|
TreeItem item= null;
|
||||||
String itemText= null;
|
String itemText= null;
|
||||||
|
SWTException ex= null;
|
||||||
|
String firstItemText= null;
|
||||||
for (int millis=0; millis < 5000; millis= millis==0 ? 1 : millis*2) {
|
for (int millis=0; millis < 5000; millis= millis==0 ? 1 : millis*2) {
|
||||||
runEventQueue(millis);
|
runEventQueue(millis);
|
||||||
TreeItem root= tree.getItem(i0);
|
TreeItem root= tree.getItem(i0);
|
||||||
|
ex= null;
|
||||||
try {
|
try {
|
||||||
TreeItem firstItem= root.getItem(0);
|
TreeItem firstItem= root.getItem(0);
|
||||||
final String text= firstItem.getText();
|
firstItemText= firstItem.getText();
|
||||||
if (text.length() > 0 && !text.equals("...")) {
|
if (firstItemText.length() > 0 && !firstItemText.equals("...")) {
|
||||||
item= root.getItem(i1);
|
item= root.getItem(i1);
|
||||||
itemText= item.getText();
|
itemText= item.getText();
|
||||||
assertNotNull("Unexpected tree node " + itemText, label);
|
assertNotNull("Unexpected tree node " + itemText, label);
|
||||||
|
@ -362,9 +365,13 @@ public class BaseUITestCase extends BaseTestCase {
|
||||||
return null;
|
return null;
|
||||||
} catch (SWTException e) {
|
} catch (SWTException e) {
|
||||||
// widget was disposed, try again.
|
// widget was disposed, try again.
|
||||||
|
ex= e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertEquals("Timeout expired waiting for tree node {" + i0 + "," + i1 + "}", label, itemText);
|
if (ex != null)
|
||||||
|
throw ex;
|
||||||
|
|
||||||
|
assertEquals("Timeout expired waiting for tree node {" + i0 + "," + i1 + "}; firstItem=" + firstItemText, label, itemText);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1139,4 +1139,18 @@ public class CPPSelectionTestsNoIndexer extends BaseUITestCase {
|
||||||
IASTNode node= testF3(file, offset);
|
IASTNode node= testF3(file, offset);
|
||||||
assertContents(code, node.getFileLocation().getNodeOffset(), "func(T a, T b)");
|
assertContents(code, node.getFileLocation().getNodeOffset(), "func(T a, T b)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// namespace N {
|
||||||
|
// template <typename T> class AAA { T _t; };
|
||||||
|
// }
|
||||||
|
// N::AAA<int> a;
|
||||||
|
public void testBug92632() throws Exception {
|
||||||
|
String code= getContentsForTest(1)[0].toString();
|
||||||
|
IFile file = importFile("testBug92632.cpp", code);
|
||||||
|
int index = code.indexOf("AAA<int>"); //$NON-NLS-1$
|
||||||
|
IASTNode node= testF3(file, index);
|
||||||
|
assertContents(code, node.getFileLocation().getNodeOffset(), "AAA");
|
||||||
|
node= testF3(file, index+4);
|
||||||
|
assertContents(code, node.getFileLocation().getNodeOffset(), "AAA");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue