mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 06:32:10 +02:00
Bug 432703 - 'Open Declaration' in parameter referencing previous
parameter Change-Id: I3ea07345093c7d3663de70fb534532bbdf0bd191 Signed-off-by: Nathan Ridge <zeratul976@hotmail.com> Reviewed-on: https://git.eclipse.org/r/24933 Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com> Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
parent
90f0e17976
commit
f699ed76a0
2 changed files with 29 additions and 4 deletions
|
@ -1272,4 +1272,15 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
|
||||||
assertEquals(hfile.getLocation().toOSString(), location.getFileName());
|
assertEquals(hfile.getLocation().toOSString(), location.getFileName());
|
||||||
assertEquals(hoffset, location.getNodeOffset());
|
assertEquals(hoffset, location.getNodeOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// int waldo(int a, decltype(a) b);
|
||||||
|
public void testFunctionParameterReferencingPreviousParameter_432703() throws Exception {
|
||||||
|
String code = getAboveComment();
|
||||||
|
IFile file = importFile("test.cpp", code);
|
||||||
|
waitUntilFileIsIndexed(index, file);
|
||||||
|
|
||||||
|
int offset= code.indexOf("a)");
|
||||||
|
IASTNode def = testF3(file, offset + 1);
|
||||||
|
assertTrue(def instanceof IASTName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,9 @@ import org.eclipse.cdt.core.dom.IName;
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTNameCollector;
|
import org.eclipse.cdt.core.dom.ast.ASTNameCollector;
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
|
import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
|
||||||
|
@ -50,6 +52,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNodeSelector;
|
import org.eclipse.cdt.core.dom.ast.IASTNodeSelector;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorFunctionStyleMacroDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorFunctionStyleMacroDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||||
|
@ -407,14 +410,25 @@ class OpenDeclarationsJob extends Job implements ASTRunnable {
|
||||||
|
|
||||||
private static boolean isInSameFunction(IASTName refName, IName funcDeclName) {
|
private static boolean isInSameFunction(IASTName refName, IName funcDeclName) {
|
||||||
if (funcDeclName instanceof IASTName) {
|
if (funcDeclName instanceof IASTName) {
|
||||||
IASTDeclaration fdef = getEnclosingFunctionDefinition((IASTNode) funcDeclName);
|
IASTDeclaration fdecl = getEnclosingFunctionDeclaration((IASTNode) funcDeclName);
|
||||||
return fdef != null && fdef.contains(refName);
|
return fdecl != null && fdecl.contains(refName);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IASTDeclaration getEnclosingFunctionDefinition(IASTNode node) {
|
private static boolean isFunctionDeclaration(IASTNode node) {
|
||||||
while (node != null && !(node instanceof IASTFunctionDefinition)) {
|
if (node instanceof IASTFunctionDefinition) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (node instanceof IASTSimpleDeclaration) {
|
||||||
|
IASTDeclarator[] declarators = ((IASTSimpleDeclaration) node).getDeclarators();
|
||||||
|
return declarators.length == 1 && declarators[0] instanceof IASTFunctionDeclarator;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IASTDeclaration getEnclosingFunctionDeclaration(IASTNode node) {
|
||||||
|
while (node != null && !isFunctionDeclaration(node)) {
|
||||||
node= node.getParent();
|
node= node.getParent();
|
||||||
}
|
}
|
||||||
return (IASTDeclaration) node;
|
return (IASTDeclaration) node;
|
||||||
|
|
Loading…
Add table
Reference in a new issue