diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java index a8f7d01e007..e6c00415706 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2009 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2010 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 @@ -105,6 +105,10 @@ public class BaseUITestCase extends BaseTestCase { return TestSourceReader.getContentsForTest(CTestPlugin.getDefault().getBundle(), "ui", getClass(), getName(), sections); } + public String getAboveComment() throws IOException { + return getContentsForTest(1)[0].toString(); + } + protected IFile createFile(IContainer container, String fileName, String contents) throws Exception { return TestSourceReader.createFile(container, new Path(fileName), contents); } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java index 9f91deb2c41..91f4cd02047 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2010 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 @@ -1172,4 +1172,19 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde assertEquals(hoffset, ((ASTNode) def).getOffset()); assertEquals(9, ((ASTNode) def).getLength()); } + + // void test( ABC* p); + // void test( ABC* q) {} + // void call_test(){ + // test( 0 ); + // } + public void testBug305487() throws Exception { + String code = getAboveComment(); + IFile file = importFile("testBug305487.cpp", code); //$NON-NLS-1$ + waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + + int offset= code.indexOf("test( 0 )"); //$NON-NLS-1$ + IASTNode def = testF3(file, offset + 1); + assertTrue(def instanceof IASTName); + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsJob.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsJob.java index 67208aaea92..2ab2f54d587 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsJob.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsJob.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Wind River Systems, Inc. and others. + * Copyright (c) 2009, 2010 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 @@ -192,39 +192,32 @@ class OpenDeclarationsJob extends Job implements ASTRunnable { navigateToName(sourceName); return Status.OK_STATUS; } - IName[] declNames = null; + List nameList= new ArrayList(); String filename = ast.getFilePath(); for (IBinding binding : bindings) { if (binding != null && !(binding instanceof IProblemBinding)) { IName[] names = findDeclNames(ast, kind, binding); - for (int i = 0; i < names.length; i++) { - if (names[i] instanceof IIndexName && - filename.equals(((IIndexName) names[i]).getFileLocation().getFileName())) { + for (final IName name : names) { + if (name instanceof IIndexName && + filename.equals(((IIndexName) name).getFileLocation().getFileName())) { // Exclude index names from the current file. - names[i] = null; - } else if (isSameName(names[i], sourceName)) { + } else if (isSameName(name, sourceName)) { // Exclude the current location. - names[i] = null; } else if (binding instanceof IParameter) { - if (!isInSameFunction(sourceName, names[i])) { - names[i] = null; + if (isInSameFunction(sourceName, name)) { + nameList.add(name); } } else if (binding instanceof ICPPTemplateParameter) { - if (!isInSameTemplate(sourceName, names[i])) { - names[i] = null; + if (isInSameTemplate(sourceName, name)) { + nameList.add(name); } + } else if (name != null) { + nameList.add(name); } } - compact(names); - if (declNames == null) { - declNames = names; - } else { - declNames = (IName[]) ArrayUtil.addAll(IName.class, declNames, names); - } } } - declNames = (IName[]) ArrayUtil.removeNulls(IName.class, declNames); - + IName[] declNames = nameList.toArray(new IName[nameList.size()]); if (navigateViaCElements(fTranslationUnit.getCProject(), fIndex, declNames)) { found= true; } else { @@ -377,22 +370,6 @@ class OpenDeclarationsJob extends Job implements ASTRunnable { return null; } - /** - * Compacts an array by moving all null elements to the end. - * @param array - */ - private void compact(Object[] array) { - for (int i = 0, j = 0; i < array.length; i++) { - if (array[i] != null) { - if (i != j) { - array[j] = array[i]; - array[i] = null; - } - j++; - } - } - } - private boolean isSameName(IName n1, IName n2) { if (n1 == n2) return true;