mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 361999: Call Hierarchy for instance of template-specialization.
This commit is contained in:
parent
2ef264d1ab
commit
ecfdcab4ab
8 changed files with 86 additions and 40 deletions
|
@ -12,6 +12,7 @@ package org.eclipse.cdt.ui.tests.callhierarchy;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.core.runtime.jobs.Job;
|
||||||
import org.eclipse.jface.text.ITextSelection;
|
import org.eclipse.jface.text.ITextSelection;
|
||||||
import org.eclipse.jface.viewers.TreeViewer;
|
import org.eclipse.jface.viewers.TreeViewer;
|
||||||
import org.eclipse.swt.SWTException;
|
import org.eclipse.swt.SWTException;
|
||||||
|
@ -81,24 +82,21 @@ public class CallHierarchyBaseTest extends BaseUITestCase {
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void openCallHierarchy(CEditor editor) {
|
protected void openCallHierarchy(CEditor editor) throws InterruptedException {
|
||||||
CallHierarchyUI.open(editor, (ITextSelection) editor.getSelectionProvider().getSelection());
|
CallHierarchyUI.open(editor, (ITextSelection) editor.getSelectionProvider().getSelection());
|
||||||
|
for (Job job : Job.getJobManager().find(CallHierarchyUI.class)) {
|
||||||
|
job.join();
|
||||||
|
}
|
||||||
|
runEventQueue(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void openCallHierarchy(CEditor editor, boolean showReferencedBy) {
|
protected void openCallHierarchy(CEditor editor, boolean showReferencedBy) throws InterruptedException {
|
||||||
CallHierarchyUI.setIsJUnitTest(true);
|
openCallHierarchy(editor);
|
||||||
CallHierarchyUI.open(editor, (ITextSelection) editor.getSelectionProvider().getSelection());
|
|
||||||
runEventQueue(0);
|
|
||||||
CHViewPart ch= null;
|
|
||||||
IWorkbenchPage page = editor.getSite().getPage();
|
IWorkbenchPage page = editor.getSite().getPage();
|
||||||
for (int i = 0; i < 400; i++) {
|
CHViewPart ch= (CHViewPart)page.findView(CUIPlugin.ID_CALL_HIERARCHY);
|
||||||
ch= (CHViewPart)page.findView(CUIPlugin.ID_CALL_HIERARCHY);
|
|
||||||
if (ch != null)
|
|
||||||
break;
|
|
||||||
runEventQueue(10);
|
|
||||||
}
|
|
||||||
assertNotNull(ch);
|
assertNotNull(ch);
|
||||||
ch.onSetShowReferencedBy(showReferencedBy);
|
ch.onSetShowReferencedBy(showReferencedBy);
|
||||||
|
runEventQueue(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TreeViewer getCHTreeViewer() {
|
protected TreeViewer getCHTreeViewer() {
|
||||||
|
@ -111,7 +109,6 @@ public class CallHierarchyBaseTest extends BaseUITestCase {
|
||||||
break;
|
break;
|
||||||
runEventQueue(10);
|
runEventQueue(10);
|
||||||
}
|
}
|
||||||
assertNotNull(ch);
|
|
||||||
return ch.getTreeViewer();
|
return ch.getTreeViewer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -479,4 +479,30 @@ public class CallHierarchyBugs extends CallHierarchyBaseTest {
|
||||||
checkTreeNode(chTree, 0, 1, "Derived::dosomething() : void");
|
checkTreeNode(chTree, 0, 1, "Derived::dosomething() : void");
|
||||||
checkTreeNode(chTree, 0, 2, null);
|
checkTreeNode(chTree, 0, 2, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// template<typename T> struct Array {
|
||||||
|
// template<typename TIterator> void erase(TIterator it) {}
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// int main() {
|
||||||
|
// Array<int> test;
|
||||||
|
// test.erase(1);
|
||||||
|
// }
|
||||||
|
public void testCallsToInstanceofSpecializedTemplate_361999() throws Exception {
|
||||||
|
final String content = getAboveComment();
|
||||||
|
IFile f2= createFile(getProject(), "testCallsToInstanceofSpecializedTemplate_361999.cpp", content);
|
||||||
|
waitForIndexer(fIndex, f2, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
|
||||||
|
|
||||||
|
final CHViewPart ch= (CHViewPart) activateView(CUIPlugin.ID_CALL_HIERARCHY);
|
||||||
|
|
||||||
|
// open editor, check outline
|
||||||
|
CEditor editor= openEditor(f2);
|
||||||
|
int idx = content.indexOf("erase(TIterator it)");
|
||||||
|
editor.selectAndReveal(idx, 0);
|
||||||
|
openCallHierarchy(editor, true);
|
||||||
|
|
||||||
|
Tree chTree= checkTreeNode(ch, 0, "Array<T>::erase(TIterator) : void").getParent();
|
||||||
|
TreeItem ti= checkTreeNode(chTree, 0, 0, "main() : int");
|
||||||
|
checkTreeNode(chTree, 0, 1, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,6 @@ import org.eclipse.jface.text.IDocument;
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.testplugin.TestScannerProvider;
|
import org.eclipse.cdt.core.testplugin.TestScannerProvider;
|
||||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||||
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A collection of code completion tests.
|
* A collection of code completion tests.
|
||||||
|
@ -959,8 +958,7 @@ public class CompletionTests extends AbstractContentAssistTest {
|
||||||
createFile(fProject, "header191315.h", content[0].toString());
|
createFile(fProject, "header191315.h", content[0].toString());
|
||||||
createFile(fProject, "source191315.c", content[1].toString());
|
createFile(fProject, "source191315.c", content[1].toString());
|
||||||
createFile(fProject, "source191315.cpp", content[1].toString());
|
createFile(fProject, "source191315.cpp", content[1].toString());
|
||||||
IFile dfile= createFile(fProject, "header191315.h", content[0].toString());
|
waitForIndexer(fCProject);
|
||||||
TestSourceReader.waitUntilFileIsIndexed(CCorePlugin.getIndexManager().getIndex(fCProject), dfile, 8000);
|
|
||||||
final String[] expected= {
|
final String[] expected= {
|
||||||
"c_linkage()"
|
"c_linkage()"
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,7 +22,6 @@ import org.eclipse.jface.text.IDocument;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||||
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Completion tests for plain C.
|
* Completion tests for plain C.
|
||||||
|
@ -313,8 +312,7 @@ public class CompletionTests_PlainC extends AbstractContentAssistTest {
|
||||||
createFile(fProject, "header191315.h", content[0].toString());
|
createFile(fProject, "header191315.h", content[0].toString());
|
||||||
createFile(fProject, "source191315.c", content[1].toString());
|
createFile(fProject, "source191315.c", content[1].toString());
|
||||||
createFile(fProject, "source191315.cpp", content[1].toString());
|
createFile(fProject, "source191315.cpp", content[1].toString());
|
||||||
IFile dfile= createFile(fProject, "header191315.h", content[0].toString());
|
waitForIndexer(fCProject);
|
||||||
TestSourceReader.waitUntilFileIsIndexed(CCorePlugin.getIndexManager().getIndex(fCProject), dfile, 8000);
|
|
||||||
final String[] expected= {
|
final String[] expected= {
|
||||||
"c_linkage(void)"
|
"c_linkage(void)"
|
||||||
};
|
};
|
||||||
|
|
|
@ -93,7 +93,7 @@ public class CHQueries {
|
||||||
private static void findCalledBy1(IIndex index, IBinding callee, boolean includeOrdinaryCalls,
|
private static void findCalledBy1(IIndex index, IBinding callee, boolean includeOrdinaryCalls,
|
||||||
ICProject project, CalledByResult result) throws CoreException {
|
ICProject project, CalledByResult result) throws CoreException {
|
||||||
findCalledBy2(index, callee, includeOrdinaryCalls, project, result);
|
findCalledBy2(index, callee, includeOrdinaryCalls, project, result);
|
||||||
List<? extends IBinding> specializations = IndexUI.findSpecializations(callee);
|
List<? extends IBinding> specializations = IndexUI.findSpecializations(index, callee);
|
||||||
for (IBinding spec : specializations) {
|
for (IBinding spec : specializations) {
|
||||||
findCalledBy2(index, spec, includeOrdinaryCalls, project, result);
|
findCalledBy2(index, spec, includeOrdinaryCalls, project, result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,7 @@ public class CallHierarchyUI {
|
||||||
final ICElement[] elems= findDefinitions(input);
|
final ICElement[] elems= findDefinitions(input);
|
||||||
if (elems != null && elems.length > 0) {
|
if (elems != null && elems.length > 0) {
|
||||||
display.asyncExec(new Runnable() {
|
display.asyncExec(new Runnable() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
internalOpen(window, elems);
|
internalOpen(window, elems);
|
||||||
}});
|
}});
|
||||||
|
@ -134,6 +135,7 @@ public class CallHierarchyUI {
|
||||||
final ICElement[] elems= findDefinitions(project, editorInput, sel);
|
final ICElement[] elems= findDefinitions(project, editorInput, sel);
|
||||||
if (elems.length > 0) {
|
if (elems.length > 0) {
|
||||||
display.asyncExec(new Runnable() {
|
display.asyncExec(new Runnable() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
internalOpen(editor.getSite().getWorkbenchWindow(), elems);
|
internalOpen(editor.getSite().getWorkbenchWindow(), elems);
|
||||||
}});
|
}});
|
||||||
|
@ -146,6 +148,10 @@ public class CallHierarchyUI {
|
||||||
return e.getStatus();
|
return e.getStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public boolean belongsTo(Object family) {
|
||||||
|
return family == CallHierarchyUI.class;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
job.setUser(true);
|
job.setUser(true);
|
||||||
job.schedule();
|
job.schedule();
|
||||||
|
|
|
@ -147,6 +147,7 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
||||||
return defaultLabel;
|
return defaultLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
String type;
|
String type;
|
||||||
if ((flags & FIND_REFERENCES) != 0) {
|
if ((flags & FIND_REFERENCES) != 0) {
|
||||||
|
@ -197,14 +198,17 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
||||||
return label + " " + countLabel; //$NON-NLS-1$
|
return label + " " + countLabel; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean canRerun() {
|
public boolean canRerun() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean canRunInBackground() {
|
public boolean canRunInBackground() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ISearchResult getSearchResult() {
|
public ISearchResult getSearchResult() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -344,7 +348,7 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
||||||
if ((flags & FIND_REFERENCES) != 0) {
|
if ((flags & FIND_REFERENCES) != 0) {
|
||||||
for (IBinding binding : bindings) {
|
for (IBinding binding : bindings) {
|
||||||
if (binding != null) {
|
if (binding != null) {
|
||||||
List<? extends IBinding> specializations = IndexUI.findSpecializations(binding);
|
List<? extends IBinding> specializations = IndexUI.findSpecializations(index, binding);
|
||||||
for (IBinding spec : specializations) {
|
for (IBinding spec : specializations) {
|
||||||
if (spec != null && handled.add(spec)) {
|
if (spec != null && handled.add(spec)) {
|
||||||
createMatches1(index, spec, names);
|
createMatches1(index, spec, names);
|
||||||
|
@ -481,6 +485,7 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
||||||
return preferred;
|
return preferred;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public final IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
|
public final IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
|
||||||
PDOMSearchResult result= (PDOMSearchResult) getSearchResult();
|
PDOMSearchResult result= (PDOMSearchResult) getSearchResult();
|
||||||
result.removeAll();
|
result.removeAll();
|
||||||
|
|
|
@ -409,6 +409,7 @@ public class IndexUI {
|
||||||
|
|
||||||
final IASTName[] result= {null};
|
final IASTName[] result= {null};
|
||||||
ASTProvider.getASTProvider().runOnAST(workingCopy, ASTProvider.WAIT_ACTIVE_ONLY, null, new ASTRunnable() {
|
ASTProvider.getASTProvider().runOnAST(workingCopy, ASTProvider.WAIT_ACTIVE_ONLY, null, new ASTRunnable() {
|
||||||
|
@Override
|
||||||
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
|
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
|
||||||
if (ast != null) {
|
if (ast != null) {
|
||||||
final IASTNodeSelector nodeSelector = ast.getNodeSelector(null);
|
final IASTNodeSelector nodeSelector = ast.getNodeSelector(null);
|
||||||
|
@ -490,29 +491,39 @@ public class IndexUI {
|
||||||
/**
|
/**
|
||||||
* Searches for all specializations that depend on the definition of the given binding.
|
* Searches for all specializations that depend on the definition of the given binding.
|
||||||
*/
|
*/
|
||||||
public static List<? extends IBinding> findSpecializations(IBinding binding) throws CoreException {
|
public static List<? extends IBinding> findSpecializations(IIndex index, IBinding binding) throws CoreException {
|
||||||
List<IBinding> result= null;
|
List<IBinding> result= null;
|
||||||
|
|
||||||
IBinding owner = binding.getOwner();
|
// Check for instances of the given binding
|
||||||
if (owner != null) {
|
|
||||||
List<? extends IBinding> specializedOwners= findSpecializations(owner);
|
|
||||||
if (!specializedOwners.isEmpty()) {
|
|
||||||
result= new ArrayList<IBinding>(specializedOwners.size());
|
|
||||||
|
|
||||||
for (IBinding specOwner : specializedOwners) {
|
|
||||||
if (specOwner instanceof ICPPClassSpecialization) {
|
|
||||||
result.add(((ICPPClassSpecialization) specOwner).specializeMember(binding));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (binding instanceof ICPPInstanceCache) {
|
if (binding instanceof ICPPInstanceCache) {
|
||||||
final List<ICPPTemplateInstance> instances= Arrays.asList(((ICPPInstanceCache) binding).getAllInstances());
|
final List<ICPPTemplateInstance> instances= Arrays.asList(((ICPPInstanceCache) binding).getAllInstances());
|
||||||
if (!instances.isEmpty()) {
|
if (!instances.isEmpty()) {
|
||||||
|
for (ICPPTemplateInstance inst : instances) {
|
||||||
|
if (!ASTInternal.hasDeclaration(inst)) {
|
||||||
if (result == null)
|
if (result == null)
|
||||||
result= new ArrayList<IBinding>(instances.size());
|
result= new ArrayList<IBinding>(instances.size());
|
||||||
|
result.add(inst);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for specializations of the owner
|
||||||
|
IBinding owner = binding.getOwner();
|
||||||
|
if (owner != null) {
|
||||||
|
for (IBinding specOwner : findSpecializations(index, owner)) {
|
||||||
|
if (specOwner instanceof ICPPClassSpecialization) {
|
||||||
|
// Add the specialized member
|
||||||
|
IBinding specializedMember = ((ICPPClassSpecialization) specOwner).specializeMember(binding);
|
||||||
|
specializedMember= index.adaptBinding(specializedMember);
|
||||||
|
if (specializedMember != null) {
|
||||||
|
if (result == null)
|
||||||
|
result= new ArrayList<IBinding>(findSpecializations(index, owner).size());
|
||||||
|
result.add(specializedMember);
|
||||||
|
// Also add instances of the specialized member
|
||||||
|
if (specializedMember instanceof ICPPInstanceCache) {
|
||||||
|
final List<ICPPTemplateInstance> instances= Arrays.asList(((ICPPInstanceCache) specializedMember).getAllInstances());
|
||||||
|
if (!instances.isEmpty()) {
|
||||||
for (ICPPTemplateInstance inst : instances) {
|
for (ICPPTemplateInstance inst : instances) {
|
||||||
if (!ASTInternal.hasDeclaration(inst)) {
|
if (!ASTInternal.hasDeclaration(inst)) {
|
||||||
result.add(inst);
|
result.add(inst);
|
||||||
|
@ -520,6 +531,11 @@ public class IndexUI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Add table
Reference in a new issue