mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-09 01:05:38 +02:00
Fix and Testcase for 195822, failures navigating in modified buffers.
This commit is contained in:
parent
1737387d1f
commit
8c8fddbf72
4 changed files with 87 additions and 24 deletions
|
@ -10,11 +10,8 @@
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
* Andrew Ferguson (Symbian)
|
* Andrew Ferguson (Symbian)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
/*
|
|
||||||
* Created on Nov 29, 2004
|
|
||||||
*/
|
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|
||||||
|
|
||||||
|
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.IName;
|
import org.eclipse.cdt.core.dom.IName;
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||||
|
@ -1177,7 +1174,10 @@ public class CPPVisitor {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if( prop == IASTDeclarator.DECLARATOR_NAME ){
|
} else if( prop == IASTDeclarator.DECLARATOR_NAME ){
|
||||||
IASTNode p = name.getParent().getParent();
|
IASTNode p = name.getParent();
|
||||||
|
while (p instanceof IASTDeclarator) {
|
||||||
|
p= p.getParent();
|
||||||
|
}
|
||||||
if( p instanceof IASTSimpleDeclaration ){
|
if( p instanceof IASTSimpleDeclaration ){
|
||||||
IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration)p).getDeclSpecifier();
|
IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration)p).getDeclSpecifier();
|
||||||
if( declSpec.getStorageClass() == IASTDeclSpecifier.sc_typedef )
|
if( declSpec.getStorageClass() == IASTDeclSpecifier.sc_typedef )
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
|
import org.eclipse.jface.text.IDocument;
|
||||||
import org.eclipse.jface.text.ITextSelection;
|
import org.eclipse.jface.text.ITextSelection;
|
||||||
import org.eclipse.jface.text.TextSelection;
|
import org.eclipse.jface.text.TextSelection;
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
|
@ -41,18 +42,19 @@ import org.eclipse.ui.PartInitException;
|
||||||
import org.eclipse.ui.PlatformUI;
|
import org.eclipse.ui.PlatformUI;
|
||||||
import org.eclipse.ui.part.FileEditorInput;
|
import org.eclipse.ui.part.FileEditorInput;
|
||||||
import org.eclipse.ui.texteditor.AbstractTextEditor;
|
import org.eclipse.ui.texteditor.AbstractTextEditor;
|
||||||
|
import org.eclipse.ui.texteditor.ITextEditor;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.core.model.ILanguage;
|
import org.eclipse.cdt.core.model.ILanguage;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||||
import org.eclipse.cdt.core.testplugin.FileManager;
|
import org.eclipse.cdt.core.testplugin.FileManager;
|
||||||
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
import org.eclipse.cdt.ui.tests.BaseUITestCase;
|
import org.eclipse.cdt.ui.tests.BaseUITestCase;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||||
|
@ -175,7 +177,7 @@ public class CPPSelectionTestsNoIndexer extends BaseUITestCase {
|
||||||
//Obtain file handle
|
//Obtain file handle
|
||||||
IFile file = project.getProject().getFile(fileName);
|
IFile file = project.getProject().getFile(fileName);
|
||||||
|
|
||||||
IPath location = new Path(project.getLocation().removeLastSegments(1).toOSString() + File.separator + fileName); //$NON-NLS-1$
|
IPath location = new Path(project.getLocation().removeLastSegments(1).toOSString() + File.separator + fileName);
|
||||||
|
|
||||||
File linkFile = new File(location.toOSString());
|
File linkFile = new File(location.toOSString());
|
||||||
if (!linkFile.exists()) {
|
if (!linkFile.exists()) {
|
||||||
|
@ -237,8 +239,9 @@ public class CPPSelectionTestsNoIndexer extends BaseUITestCase {
|
||||||
assertFalse(true);
|
assertFalse(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (part instanceof AbstractTextEditor) {
|
if (part instanceof ITextEditor) {
|
||||||
((AbstractTextEditor)part).getSelectionProvider().setSelection(new TextSelection(offset,length));
|
ITextEditor editor= (ITextEditor) part;
|
||||||
|
editor.getSelectionProvider().setSelection(new TextSelection(offset,length));
|
||||||
|
|
||||||
final OpenDeclarationsAction action = (OpenDeclarationsAction) ((AbstractTextEditor)part).getAction("OpenDeclarations"); //$NON-NLS-1$
|
final OpenDeclarationsAction action = (OpenDeclarationsAction) ((AbstractTextEditor)part).getAction("OpenDeclarations"); //$NON-NLS-1$
|
||||||
action.runSync();
|
action.runSync();
|
||||||
|
@ -249,7 +252,7 @@ public class CPPSelectionTestsNoIndexer extends BaseUITestCase {
|
||||||
final IASTName[] result= {null};
|
final IASTName[] result= {null};
|
||||||
if (sel instanceof ITextSelection) {
|
if (sel instanceof ITextSelection) {
|
||||||
final ITextSelection textSel = (ITextSelection)sel;
|
final ITextSelection textSel = (ITextSelection)sel;
|
||||||
ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(file);
|
ITranslationUnit tu= CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editor.getEditorInput());
|
||||||
IStatus ok= ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_YES, monitor, new ASTRunnable() {
|
IStatus ok= ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_YES, monitor, new ASTRunnable() {
|
||||||
public IStatus runOnAST(ILanguage language, IASTTranslationUnit ast) throws CoreException {
|
public IStatus runOnAST(ILanguage language, IASTTranslationUnit ast) throws CoreException {
|
||||||
IASTName[] names = language.getSelectedNames(ast, textSel.getOffset(), textSel.getLength());
|
IASTName[] names = language.getSelectedNames(ast, textSel.getOffset(), textSel.getLength());
|
||||||
|
@ -921,7 +924,7 @@ public class CPPSelectionTestsNoIndexer extends BaseUITestCase {
|
||||||
String code = buffer.toString();
|
String code = buffer.toString();
|
||||||
IFile file = importFileWithLink("testBug78354.cpp", code); //$NON-NLS-1$
|
IFile file = importFileWithLink("testBug78354.cpp", code); //$NON-NLS-1$
|
||||||
|
|
||||||
int offset = code.indexOf("TestTypeOne myFirstLink = 5;"); //$NON-NLS-1$ //$NON-NLS-2$
|
int offset = code.indexOf("TestTypeOne myFirstLink = 5;"); //$NON-NLS-1$
|
||||||
IASTNode decl = testF3(file, offset);
|
IASTNode decl = testF3(file, offset);
|
||||||
assertTrue(decl instanceof IASTName);
|
assertTrue(decl instanceof IASTName);
|
||||||
assertEquals(((IASTName)decl).toString(), "TestTypeOne"); //$NON-NLS-1$
|
assertEquals(((IASTName)decl).toString(), "TestTypeOne"); //$NON-NLS-1$
|
||||||
|
@ -966,4 +969,40 @@ public class CPPSelectionTestsNoIndexer extends BaseUITestCase {
|
||||||
assertEquals(((ASTNode)decl).getOffset(), 4);
|
assertEquals(((ASTNode)decl).getOffset(), 4);
|
||||||
assertEquals(((ASTNode)decl).getLength(), 1);
|
assertEquals(((ASTNode)decl).getLength(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// typedef int (*functionPointer)(int);
|
||||||
|
// functionPointer fctVariable;
|
||||||
|
|
||||||
|
// typedef int (functionPointerArray[2])(int);
|
||||||
|
// functionPointerArray fctVariablArray;
|
||||||
|
public void testBug195822() throws Exception {
|
||||||
|
StringBuffer[] contents= getContentsForTest(2);
|
||||||
|
String code= contents[0].toString();
|
||||||
|
String appendCode= contents[1].toString();
|
||||||
|
|
||||||
|
String[] filenames= {"testBug195822.c", "testBug195822.cpp"};
|
||||||
|
for (int i=0; i<2; i++) {
|
||||||
|
IFile file = importFile(filenames[i], code);
|
||||||
|
int od1 = code.indexOf("functionPointer");
|
||||||
|
int or1 = code.indexOf("functionPointer", od1+1);
|
||||||
|
|
||||||
|
IASTNode decl = testF3(file, or1);
|
||||||
|
assertTrue(decl instanceof IASTName);
|
||||||
|
assertEquals(((IASTName)decl).toString(), "functionPointer"); //$NON-NLS-1$
|
||||||
|
assertEquals(((ASTNode)decl).getOffset(), od1);
|
||||||
|
|
||||||
|
IEditorPart editor= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
|
||||||
|
assertNotNull(editor);
|
||||||
|
assertTrue(editor instanceof ITextEditor);
|
||||||
|
IDocument doc= ((ITextEditor) editor).getDocumentProvider().getDocument(editor.getEditorInput());
|
||||||
|
doc.replace(doc.getLength(), 0, appendCode);
|
||||||
|
int od2 = appendCode.indexOf("functionPointerArray");
|
||||||
|
int or2 = appendCode.indexOf("functionPointerArray", od2+1);
|
||||||
|
|
||||||
|
decl = testF3(file, code.length() + or2);
|
||||||
|
assertTrue(decl instanceof IASTName);
|
||||||
|
assertEquals(((IASTName)decl).toString(), "functionPointerArray");
|
||||||
|
assertEquals(((ASTNode)decl).getOffset(), code.length() + od2);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,9 @@ import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.core.runtime.jobs.Job;
|
import org.eclipse.core.runtime.jobs.Job;
|
||||||
|
import org.eclipse.jface.text.IRegion;
|
||||||
import org.eclipse.jface.text.ITextSelection;
|
import org.eclipse.jface.text.ITextSelection;
|
||||||
|
import org.eclipse.jface.text.Region;
|
||||||
import org.eclipse.swt.widgets.Display;
|
import org.eclipse.swt.widgets.Display;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
@ -39,6 +41,7 @@ import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
import org.eclipse.cdt.core.index.IIndexManager;
|
import org.eclipse.cdt.core.index.IIndexManager;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexName;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.core.model.ILanguage;
|
import org.eclipse.cdt.core.model.ILanguage;
|
||||||
|
@ -51,6 +54,8 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable;
|
import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable;
|
||||||
|
import org.eclipse.cdt.internal.core.model.ext.CElementHandleFactory;
|
||||||
|
import org.eclipse.cdt.internal.core.model.ext.ICElementHandle;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.actions.OpenActionUtil;
|
import org.eclipse.cdt.internal.ui.actions.OpenActionUtil;
|
||||||
import org.eclipse.cdt.internal.ui.editor.ASTProvider;
|
import org.eclipse.cdt.internal.ui.editor.ASTProvider;
|
||||||
|
@ -222,7 +227,7 @@ public class OpenDeclarationsAction extends SelectionParseAction {
|
||||||
final ArrayList elements= new ArrayList();
|
final ArrayList elements= new ArrayList();
|
||||||
for (int i = 0; i < declNames.length; i++) {
|
for (int i = 0; i < declNames.length; i++) {
|
||||||
try {
|
try {
|
||||||
ICElement elem = IndexUI.getCElementForName(project, index, declNames[i]);
|
ICElement elem = getCElementForName(project, index, declNames[i]);
|
||||||
if (elem instanceof ISourceReference) {
|
if (elem instanceof ISourceReference) {
|
||||||
elements.add(elem);
|
elements.add(elem);
|
||||||
}
|
}
|
||||||
|
@ -266,6 +271,27 @@ public class OpenDeclarationsAction extends SelectionParseAction {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ICElementHandle getCElementForName(ICProject project, IIndex index, IName declName)
|
||||||
|
throws CoreException {
|
||||||
|
if (declName instanceof IIndexName) {
|
||||||
|
return IndexUI.getCElementForName(project, index, (IIndexName) declName);
|
||||||
|
}
|
||||||
|
if (declName instanceof IASTName) {
|
||||||
|
IASTName astName = (IASTName) declName;
|
||||||
|
IBinding binding= astName.resolveBinding();
|
||||||
|
if (binding != null) {
|
||||||
|
ITranslationUnit tu= IndexUI.getTranslationUnit(project, astName);
|
||||||
|
if (tu != null) {
|
||||||
|
IASTFileLocation loc= astName.getFileLocation();
|
||||||
|
IRegion region= new Region(loc.getNodeOffset(), loc.getNodeLength());
|
||||||
|
return CElementHandleFactory.create(tu, binding, astName.isDefinition(), region, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private IName[] findNames(IIndex index, IASTTranslationUnit ast,
|
private IName[] findNames(IIndex index, IASTTranslationUnit ast,
|
||||||
boolean isDefinition, IBinding binding) throws CoreException {
|
boolean isDefinition, IBinding binding) throws CoreException {
|
||||||
IName[] declNames= isDefinition ?
|
IName[] declNames= isDefinition ?
|
||||||
|
|
|
@ -258,19 +258,17 @@ public class IndexUI {
|
||||||
return EMPTY_ELEMENTS;
|
return EMPTY_ELEMENTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ICElementHandle getCElementForName(ICProject preferProject, IIndex index, IName declName)
|
/**
|
||||||
throws CoreException {
|
* Creates CElementHandles for definitions or declarations when you expect to find those
|
||||||
if (declName instanceof IASTName) {
|
* in the index.
|
||||||
return getCElementForName(preferProject, index, (IASTName) declName);
|
* @param preferProject
|
||||||
}
|
* @param index
|
||||||
else if (declName instanceof IIndexName) {
|
* @param declName
|
||||||
return getCElementForName(preferProject, index, (IIndexName) declName);
|
* @return the ICElementHandle or <code>null</code>.
|
||||||
}
|
*/
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ICElementHandle getCElementForName(ICProject preferProject, IIndex index, IASTName declName)
|
public static ICElementHandle getCElementForName(ICProject preferProject, IIndex index, IASTName declName)
|
||||||
throws CoreException {
|
throws CoreException {
|
||||||
|
assert !declName.isReference();
|
||||||
IBinding binding= declName.resolveBinding();
|
IBinding binding= declName.resolveBinding();
|
||||||
if (binding != null) {
|
if (binding != null) {
|
||||||
ITranslationUnit tu= getTranslationUnit(preferProject, declName);
|
ITranslationUnit tu= getTranslationUnit(preferProject, declName);
|
||||||
|
@ -289,7 +287,7 @@ public class IndexUI {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ITranslationUnit getTranslationUnit(ICProject cproject, IName name) {
|
public static ITranslationUnit getTranslationUnit(ICProject cproject, IName name) {
|
||||||
IPath path= Path.fromOSString(name.getFileLocation().getFileName());
|
IPath path= Path.fromOSString(name.getFileLocation().getFileName());
|
||||||
try {
|
try {
|
||||||
return CoreModelUtil.findTranslationUnitForLocation(path, cproject);
|
return CoreModelUtil.findTranslationUnitForLocation(path, cproject);
|
||||||
|
|
Loading…
Add table
Reference in a new issue