mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Use node-selector for Open Call Hierarchy and Open Type Hierarchy.
This commit is contained in:
parent
6be8db253c
commit
9d9607ee05
6 changed files with 18 additions and 128 deletions
|
@ -298,7 +298,8 @@ public class BaseUITestCase extends BaseTestCase {
|
|||
|
||||
final protected TreeItem checkTreeNode(Tree tree, int i0, String label) {
|
||||
TreeItem root= null;
|
||||
for (int i=0; i<400; i++) {
|
||||
for (int millis=0; millis < 5000; millis= millis==0 ? 1 : millis*2) {
|
||||
runEventQueue(millis);
|
||||
try {
|
||||
root= tree.getItem(i0);
|
||||
if (label.equals(root.getText())) {
|
||||
|
@ -311,7 +312,6 @@ public class BaseUITestCase extends BaseTestCase {
|
|||
catch (IllegalArgumentException e) {
|
||||
// item does not yet exist.
|
||||
}
|
||||
runEventQueue(10);
|
||||
}
|
||||
assertNotNull("Tree node " + label + "{" + i0 + "} does not exist!", root);
|
||||
assertEquals(label, root.getText());
|
||||
|
@ -321,7 +321,8 @@ public class BaseUITestCase extends BaseTestCase {
|
|||
final protected TreeItem checkTreeNode(Tree tree, int i0, int i1, String label) {
|
||||
TreeItem item= null;
|
||||
String itemText= null;
|
||||
for (int i=0; i<400; i++) {
|
||||
for (int millis=0; millis < 5000; millis= millis==0 ? 1 : millis*2) {
|
||||
runEventQueue(millis);
|
||||
TreeItem root= tree.getItem(i0);
|
||||
try {
|
||||
TreeItem firstItem= root.getItem(0);
|
||||
|
@ -333,7 +334,7 @@ public class BaseUITestCase extends BaseTestCase {
|
|||
if (label.equals(itemText)) {
|
||||
return item;
|
||||
}
|
||||
if (i > 100) {
|
||||
if (millis > 2000) {
|
||||
assertEquals(label, itemText);
|
||||
return item;
|
||||
}
|
||||
|
@ -348,7 +349,6 @@ public class BaseUITestCase extends BaseTestCase {
|
|||
catch (SWTException e) {
|
||||
// widget was disposed, try again.
|
||||
}
|
||||
runEventQueue(10);
|
||||
}
|
||||
assertEquals("Timeout expired waiting for tree node {" + i0 + "," + i1 + "}", label, itemText);
|
||||
return null;
|
||||
|
|
|
@ -82,7 +82,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
|
|||
checkTreeNode(tree, 0, "proto()");
|
||||
checkTreeNode(tree, 0, 0, "main()");
|
||||
|
||||
editor.selectAndReveal(content.indexOf("func(); //ref"), 7);
|
||||
editor.selectAndReveal(content.indexOf("func(); //ref"), 4);
|
||||
openCallHierarchy(editor);
|
||||
checkTreeNode(tree, 0, "func()");
|
||||
checkTreeNode(tree, 0, 0, "main()");
|
||||
|
@ -737,7 +737,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
|
|||
checkTreeNode(tree, 0, "proto(int)");
|
||||
checkTreeNode(tree, 0, 0, "main(int)");
|
||||
|
||||
editor.selectAndReveal(content.indexOf("func(1); //ref"), 7);
|
||||
editor.selectAndReveal(content.indexOf("func(1); //ref"), 4);
|
||||
openCallHierarchy(editor);
|
||||
checkTreeNode(tree, 0, "func(int)");
|
||||
checkTreeNode(tree, 0, 0, "main(int)");
|
||||
|
|
|
@ -37,7 +37,7 @@ public class InitializersInCallHierarchyTest extends CallHierarchyBaseTest {
|
|||
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
|
||||
CEditor editor = openFile(file);
|
||||
|
||||
editor.selectAndReveal(content.indexOf("a"), 5);
|
||||
editor.selectAndReveal(content.indexOf("a"), 1);
|
||||
openCallHierarchy(editor);
|
||||
Tree tree = getCHTreeViewer().getTree();
|
||||
checkTreeNode(tree, 0, "a");
|
||||
|
|
|
@ -28,7 +28,6 @@ import org.eclipse.ui.texteditor.ITextEditor;
|
|||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
|
@ -44,13 +43,10 @@ import org.eclipse.cdt.core.model.CModelException;
|
|||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.IFunctionDeclaration;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
|
||||
import org.eclipse.cdt.internal.ui.util.StatusLineHandler;
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.FindNameForSelectionVisitor;
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.IndexUI;
|
||||
|
||||
public class TypeHierarchyUI {
|
||||
|
@ -114,6 +110,7 @@ public class TypeHierarchyUI {
|
|||
final Display display= Display.getCurrent();
|
||||
|
||||
Job job= new Job(Messages.TypeHierarchyUI_OpenTypeHierarchy) {
|
||||
@Override
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
try {
|
||||
StatusLineHandler.clearStatusLine(editor.getSite());
|
||||
|
@ -147,7 +144,7 @@ public class TypeHierarchyUI {
|
|||
|
||||
index.acquireReadLock();
|
||||
try {
|
||||
IASTName name= getSelectedName(index, editorInput, sel);
|
||||
IASTName name= IndexUI.getSelectedName(editorInput, sel);
|
||||
if (name != null) {
|
||||
IBinding binding= name.resolveBinding();
|
||||
if (!isValidInput(binding)) {
|
||||
|
@ -260,21 +257,6 @@ public class TypeHierarchyUI {
|
|||
return IndexUI.findAnyDeclaration(index, project, binding);
|
||||
}
|
||||
|
||||
private static IASTName getSelectedName(IIndex index, IEditorInput editorInput, IRegion sel) throws CoreException {
|
||||
int selectionStart = sel.getOffset();
|
||||
int selectionLength = sel.getLength();
|
||||
|
||||
IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editorInput);
|
||||
if (workingCopy == null)
|
||||
return null;
|
||||
|
||||
int options= ITranslationUnit.AST_SKIP_INDEXED_HEADERS;
|
||||
IASTTranslationUnit ast = workingCopy.getAST(index, options);
|
||||
FindNameForSelectionVisitor finder= new FindNameForSelectionVisitor(ast.getFilePath(), selectionStart, selectionLength);
|
||||
ast.accept(finder);
|
||||
return finder.getSelectedName();
|
||||
}
|
||||
|
||||
public static boolean isValidInput(IBinding binding) {
|
||||
if (isValidTypeInput(binding)
|
||||
|| binding instanceof ICPPMember
|
||||
|
|
|
@ -1,95 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 Wind River Systems, Inc. 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:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.viewsupport;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
|
||||
/**
|
||||
* Searches for a name related to the given selection. The first choice will be the
|
||||
* largest name inside the selection. If it does not exist the smallest name
|
||||
* surounding the selection is taken.
|
||||
* @see IASTNode#accept(ASTVisitor)
|
||||
* @since 4.0
|
||||
*/
|
||||
public class FindNameForSelectionVisitor extends ASTVisitor {
|
||||
|
||||
private String fFilePath;
|
||||
private int fOffset;
|
||||
private int fEndOffset;
|
||||
private IASTName fSelectedName;
|
||||
|
||||
public FindNameForSelectionVisitor(String filePath, int selectionStart, int selectionLength) {
|
||||
fFilePath= filePath;
|
||||
fOffset= selectionStart;
|
||||
fEndOffset= selectionStart+selectionLength;
|
||||
|
||||
shouldVisitDeclarations= true;
|
||||
shouldVisitNames= true;
|
||||
}
|
||||
|
||||
/**
|
||||
* After the visitor was accepted by an ast-node you can query the
|
||||
* selected name.
|
||||
* @return the name found for the selection, or <code>null</code>.
|
||||
* @since 4.0
|
||||
*/
|
||||
public IASTName getSelectedName() {
|
||||
return fSelectedName;
|
||||
}
|
||||
|
||||
public int visit(IASTDeclaration declaration) {
|
||||
IASTFileLocation loc= declaration.getFileLocation();
|
||||
if (loc == null || !loc.getFileName().equals(fFilePath)) {
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
int offset= loc.getNodeOffset();
|
||||
int endoffset= offset + loc.getNodeLength();
|
||||
if (endoffset < fOffset || fEndOffset < offset) {
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
public int visit(IASTName name) {
|
||||
IASTFileLocation loc= name.getFileLocation();
|
||||
if (loc == null) {
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
if (!loc.getFileName().equals(fFilePath)) {
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
int offset= loc.getNodeOffset();
|
||||
int endoffset= offset + loc.getNodeLength();
|
||||
|
||||
// check if name is inside of selection
|
||||
if (fOffset <= offset && endoffset <= fEndOffset) {
|
||||
fSelectedName= name;
|
||||
return PROCESS_ABORT;
|
||||
}
|
||||
|
||||
// check if name surrounds selection
|
||||
if (offset <= fOffset && fEndOffset <= endoffset) {
|
||||
fSelectedName= name;
|
||||
// continue as we might find a name inside of the selection,
|
||||
// which is preferred.
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
}
|
|
@ -368,9 +368,14 @@ public class IndexUI {
|
|||
}
|
||||
|
||||
public static IASTName getSelectedName(IEditorInput editorInput, ITextSelection selection) throws CoreException {
|
||||
final int selectionStart = selection.getOffset();
|
||||
final int selectionLength = selection.getLength();
|
||||
return getSelectedName(editorInput, selection.getOffset(), selection.getLength());
|
||||
}
|
||||
|
||||
public static IASTName getSelectedName(IEditorInput editorInput, IRegion selection) throws CoreException {
|
||||
return getSelectedName(editorInput, selection.getOffset(), selection.getLength());
|
||||
}
|
||||
|
||||
private static IASTName getSelectedName(IEditorInput editorInput, final int offset, final int length) {
|
||||
IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editorInput);
|
||||
if (workingCopy == null)
|
||||
return null;
|
||||
|
@ -379,9 +384,7 @@ public class IndexUI {
|
|||
ASTProvider.getASTProvider().runOnAST(workingCopy, ASTProvider.WAIT_YES, null, new ASTRunnable() {
|
||||
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
|
||||
if (ast != null) {
|
||||
FindNameForSelectionVisitor finder= new FindNameForSelectionVisitor(ast.getFilePath(), selectionStart, selectionLength);
|
||||
ast.accept(finder);
|
||||
result[0]= finder.getSelectedName();
|
||||
result[0]= ast.getNodeSelector(null).findEnclosingName(offset, length);
|
||||
}
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue