1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-19 15:05:36 +02:00

Bug 305487: ArrayStoreException using F3

This commit is contained in:
Markus Schorn 2010-03-15 15:41:43 +00:00
parent 05957c8002
commit 0dc6ec197c
3 changed files with 34 additions and 38 deletions

View file

@ -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);
}

View file

@ -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);
}
}

View file

@ -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<IName> nameList= new ArrayList<IName>();
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 <code>null</code> 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;