1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix for 162755, cleanup in ArrayUtil

This commit is contained in:
Markus Schorn 2006-10-31 10:08:56 +00:00
parent 6b96ffedab
commit 6ac289f820
53 changed files with 484 additions and 327 deletions

View file

@ -0,0 +1,233 @@
/*******************************************************************************
* 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.core.parser.tests;
import junit.framework.TestCase;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
public class ArrayUtilsTest extends TestCase {
private Object o1= new Object();
private Object o2= new Object();
private Object o3= new Object();
private Object o4= new Object();
public void testAppend() {
Object[] array= null;
array= ArrayUtil.append(array, o1);
array= ArrayUtil.append(array, o2);
array= ArrayUtil.append(array, o3);
assertEquals(o1, array[0]);
assertEquals(o2, array[1]);
assertEquals(o3, array[2]);
array= ArrayUtil.append(Object.class, null, 0, o1);
array= ArrayUtil.append(Object.class, array, 1, o2);
array= ArrayUtil.append(Object.class, array, 2, o3);
assertEquals(o1, array[0]);
assertEquals(o2, array[1]);
assertEquals(o3, array[2]);
}
public void testPrepend() {
Object[] array= null;
array= ArrayUtil.prepend(Object.class, array, o1);
array= ArrayUtil.prepend(Object.class, array, o2);
array= ArrayUtil.prepend(Object.class, array, o3);
assertEquals(o3, array[0]);
assertEquals(o2, array[1]);
assertEquals(o1, array[2]);
}
public void testTrim() {
Object[] array= new Object[] {null, null};
array= ArrayUtil.trim(Object.class, array);
assertEquals(0, array.length);
array= new Object[] {o1, null};
array= ArrayUtil.trim(Object.class, array);
assertEquals(1, array.length);
assertEquals(o1, array[0]);
array= new Object[] {o1, o2};
Object[] array2= ArrayUtil.trim(Object.class, array);
assertEquals(2, array2.length);
assertSame(o1, array2[0]);
assertSame(o2, array2[1]);
assertSame(array, array2);
array= new Object[] {null, null};
array= ArrayUtil.trim(Object.class, array, true);
assertEquals(0, array.length);
array= new Object[] {o1, null};
array= ArrayUtil.trim(Object.class, array, true);
assertEquals(1, array.length);
assertEquals(o1, array[0]);
array= new Object[] {o1, o2};
array2= ArrayUtil.trim(Object.class, array, true);
assertEquals(2, array2.length);
assertSame(o1, array2[0]);
assertSame(o2, array2[1]);
assertNotSame(array, array2);
}
public void testAddAll() {
Object[] array1= {o1, o2, null};
Object[] array2= {o3, null};
Object[] result;
result= ArrayUtil.addAll(Object.class, array2, array1);
assertEquals(o3, result[0]);
assertEquals(o1, result[1]);
assertEquals(o2, result[2]);
result= ArrayUtil.addAll(Object.class, array1, array2);
assertEquals(o1, result[0]);
assertEquals(o2, result[1]);
assertEquals(o3, result[2]);
assertSame(array1, result);
array1= new Object[] {o1, o2};
array2= new Object[] {o3, null};
result= ArrayUtil.addAll(Object.class, array2, array1);
assertEquals(o3, result[0]);
assertEquals(o1, result[1]);
assertEquals(o2, result[2]);
result= ArrayUtil.addAll(Object.class, array1, array2);
assertEquals(o1, result[0]);
assertEquals(o2, result[1]);
assertEquals(o3, result[2]);
array1= new Object[] {o1, o2};
array2= new Object[] {o3};
result= ArrayUtil.addAll(Object.class, array2, array1);
assertEquals(o3, result[0]);
assertEquals(o1, result[1]);
assertEquals(o2, result[2]);
result= ArrayUtil.addAll(Object.class, array1, array2);
assertEquals(o1, result[0]);
assertEquals(o2, result[1]);
assertEquals(o3, result[2]);
array1= new Object[] {o1, o2};
array2= new Object[] {};
result= ArrayUtil.addAll(Object.class, array2, array1);
assertEquals(o1, result[0]);
assertEquals(o2, result[1]);
assertNotSame(array1, result);
result= ArrayUtil.addAll(Object.class, array1, array2);
assertEquals(o1, result[0]);
assertEquals(o2, result[1]);
assertSame(array1, result);
}
public void testRemove() {
Object[] array= new Object[] {o1, o2, o3, o4, null};
ArrayUtil.remove(array, o3);
assertSame(o1, array[0]);
assertSame(o2, array[1]);
assertSame(o4, array[2]);
assertNull(array[3]);
ArrayUtil.remove(array, o1);
assertSame(o2, array[0]);
assertSame(o4, array[1]);
assertNull(array[2]);
ArrayUtil.remove(array, o4);
assertSame(o2, array[0]);
assertNull(array[1]);
ArrayUtil.remove(array, o2);
assertNull(array[0]);
array= new Object[] {o1, o2, o3, o4};
ArrayUtil.remove(array, o3);
assertSame(o1, array[0]);
assertSame(o2, array[1]);
assertSame(o4, array[2]);
assertNull(array[3]);
ArrayUtil.remove(array, o1);
assertSame(o2, array[0]);
assertSame(o4, array[1]);
assertNull(array[2]);
ArrayUtil.remove(array, o4);
assertSame(o2, array[0]);
assertNull(array[1]);
ArrayUtil.remove(array, o2);
assertNull(array[0]);
}
public void testRemoveNulls() {
Object[] array= new Object[0];
Object[] result;
result= ArrayUtil.removeNulls(Object.class, array);
assertEquals(0, result.length);
assertSame(result, array);
array= new Object[]{null};
result= ArrayUtil.removeNulls(Object.class, array);
assertEquals(0, result.length);
array= new Object[]{o1};
result= ArrayUtil.removeNulls(Object.class, array);
assertEquals(1, result.length);
assertSame(result[0], o1);
assertSame(result, array);
array= new Object[]{o1, null};
result= ArrayUtil.removeNulls(Object.class, array);
assertEquals(1, result.length);
assertSame(result[0], o1);
array= new Object[]{null, o1};
result= ArrayUtil.removeNulls(Object.class, array);
assertEquals(1, result.length);
assertSame(result[0], o1);
array= new Object[]{o1, o2};
result= ArrayUtil.removeNulls(Object.class, array);
assertEquals(2, result.length);
assertSame(result[0], o1);
assertSame(result[1], o2);
assertSame(result, array);
array= new Object[]{null, o1, o2};
result= ArrayUtil.removeNulls(Object.class, array);
assertEquals(2, result.length);
assertSame(result[0], o1);
assertSame(result[1], o2);
array= new Object[]{o1, null, o2};
result= ArrayUtil.removeNulls(Object.class, array);
assertEquals(2, result.length);
assertSame(result[0], o1);
assertSame(result[1], o2);
array= new Object[]{o1, o2, null};
result= ArrayUtil.removeNulls(Object.class, array);
assertEquals(2, result.length);
assertSame(result[0], o1);
assertSame(result[1], o2);
}
}

View file

@ -31,6 +31,7 @@ import org.eclipse.cdt.core.parser.tests.scanner2.Scanner2Test;
public class ParserTestSuite extends TestCase { public class ParserTestSuite extends TestCase {
public static Test suite() { public static Test suite() {
TestSuite suite= new TestSuite(ParserTestSuite.class.getName()); TestSuite suite= new TestSuite(ParserTestSuite.class.getName());
suite.addTestSuite(ArrayUtilsTest.class);
suite.addTestSuite(Scanner2Test.class ); suite.addTestSuite(Scanner2Test.class );
suite.addTestSuite(QuickParseASTTests.class); suite.addTestSuite(QuickParseASTTests.class);
suite.addTestSuite(ParserSymbolTableTest.class); suite.addTestSuite(ParserSymbolTableTest.class);

View file

@ -112,7 +112,7 @@ public class IndexListenerTest extends BaseTestCase {
IFile file= TestSourceReader.createFile(fProject1.getProject(), "test.cpp", "int a;"); IFile file= TestSourceReader.createFile(fProject1.getProject(), "test.cpp", "int a;");
synchronized (mutex) { synchronized (mutex) {
mutex.wait(1000); mutex.wait(2000);
} }
assertEquals(1, projects.size()); assertEquals(1, projects.size());
assertTrue(projects.contains(fProject1)); assertTrue(projects.contains(fProject1));

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
@ -25,18 +26,12 @@ public class ArrayUtil {
} }
public static final int DEFAULT_LENGTH = 2; public static final int DEFAULT_LENGTH = 2;
/** /**
* Adds obj to array in the first null slot. * Assumes that array contains nulls at the end, only.
* If array is null, a new array is created and obj is added to the new array. * Appends element after the last non-null element.
* If the array is full, a new array of larger size is created, the contents * If the array is null or not large enough, a larger one is allocated, using
* of array are copied over and obj is added to the new array. * the given class object.
*
* The type of any new arrays will be array of c, where c is given.
* es: c = IBinding.class results in an IBinding[]
* @param Class c
* @param Object [] array
* @param Object obj
* @return
*/ */
static public Object [] append( Class c, Object[] array, Object obj ){ static public Object [] append( Class c, Object[] array, Object obj ){
if( obj == null ) if( obj == null )
@ -47,37 +42,65 @@ public class ArrayUtil {
return array; return array;
} }
int i = 0; int i= findFirstNull(array);
for( ; i < array.length; i++ ){ if (i >= 0) {
if( array[i] == null ){
array[i]= obj; array[i]= obj;
return array; return array;
} }
}
Object [] temp = (Object[]) Array.newInstance( c, array.length * 2 ); Object [] temp = (Object[]) Array.newInstance( c, array.length * 2 );
System.arraycopy( array, 0, temp, 0, array.length ); System.arraycopy( array, 0, temp, 0, array.length );
temp[array.length] = obj; temp[array.length] = obj;
array = temp; return temp;
}
/**
* Assumes that array contains nulls at the end, only.
* @returns index of first null, or -1
*/
private static int findFirstNull(Object[] array) {
boolean haveNull= false;
int left= 0;
int right= array.length-1;
while (left <= right) {
int mid= (left+right)/2;
if (array[mid] == null) {
haveNull= true;
right= mid-1;
}
else {
left= mid+1;
}
}
return haveNull ? right+1 : -1;
}
/**
* Assumes that array contains nulls at the end, only.
* Appends object using the current length of the array.
* @since 4.0
*/
static public Object [] append(Class c, Object[] array, int currentLength, Object obj ){
if( obj == null )
return array;
if( array == null || array.length == 0){
array = (Object[]) Array.newInstance( c, DEFAULT_LENGTH );
array[0] = obj;
return array; return array;
} }
static public int [] setInt( int[] array, int idx, int val ){ if (currentLength < array.length) {
if( array == null ){ assert array[currentLength] == null;
array = new int [ DEFAULT_LENGTH > idx + 1 ? DEFAULT_LENGTH : idx + 1]; assert currentLength == 0 || array[currentLength-1] != null;
array[idx] = val; array[currentLength]= obj;
return array; return array;
} }
if( array.length <= idx ){ Object [] temp = (Object[]) Array.newInstance( c, array.length * 2 );
int newLen = array.length * 2;
while( newLen <= idx ) newLen *=2;
int [] temp = new int [newLen];
System.arraycopy( array, 0, temp, 0, array.length ); System.arraycopy( array, 0, temp, 0, array.length );
temp[array.length] = obj;
array = temp; return temp;
}
array[idx] = val;
return array;
} }
static public Object [] append( Object[] array, Object obj ){ static public Object [] append( Object[] array, Object obj ){
@ -86,6 +109,7 @@ public class ArrayUtil {
/** /**
* Trims the given array and returns a new array with no null entries. * Trims the given array and returns a new array with no null entries.
* Assumes that nulls can be found at the end, only.
* if array == null, a new array of length 0 is returned * if array == null, a new array of length 0 is returned
* if forceNew == true, a new array will always be created. * if forceNew == true, a new array will always be created.
* if forceNew == false, a new array will only be created if the original array * if forceNew == false, a new array will only be created if the original array
@ -100,16 +124,20 @@ public class ArrayUtil {
if( array == null ) if( array == null )
return (Object[]) Array.newInstance( c, 0 ); return (Object[]) Array.newInstance( c, 0 );
int i = 0; int i = array.length;
for( ; i < array.length; i++ ){ if (i==0 || array[i-1] != null) {
if( array[i] == null ) break; if (!forceNew) {
return array;
} }
if( forceNew || i < array.length ){ }
else {
i=findFirstNull(array);
assert i>=0;
}
Object [] temp = (Object[]) Array.newInstance( c, i ); Object [] temp = (Object[]) Array.newInstance( c, i );
System.arraycopy( array, 0, temp, 0, i ); System.arraycopy( array, 0, temp, 0, i );
array = temp; return temp;
}
return array;
} }
/** /**
@ -122,19 +150,19 @@ public class ArrayUtil {
} }
/** /**
* @param transitives * Assumes that both arrays contain nulls at the end, only.
* @param usings
*/ */
public static Object[] addAll( Class c, Object[] dest, Object[] source ) { public static Object[] addAll( Class c, Object[] dest, Object[] source ) {
if( source == null || source.length == 0 ) if( source == null || source.length == 0 )
return dest; return dest;
int numToAdd = 0; int numToAdd = findFirstNull(source);
while( numToAdd < source.length && source[numToAdd] != null ) if (numToAdd <= 0) {
numToAdd++; if (numToAdd == 0) {
if( numToAdd == 0 )
return dest; return dest;
}
numToAdd= source.length;
}
if( dest == null || dest.length == 0 ){ if( dest == null || dest.length == 0 ){
dest = (Object[]) Array.newInstance( c, numToAdd ); dest = (Object[]) Array.newInstance( c, numToAdd );
@ -142,9 +170,10 @@ public class ArrayUtil {
return dest; return dest;
} }
int firstFree = 0; int firstFree = findFirstNull(dest);
while( firstFree < dest.length && dest[firstFree] != null ) if (firstFree < 0) {
firstFree++; firstFree= dest.length;
}
if( firstFree + numToAdd <= dest.length ){ if( firstFree + numToAdd <= dest.length ){
System.arraycopy( source, 0, dest, firstFree, numToAdd ); System.arraycopy( source, 0, dest, firstFree, numToAdd );
@ -156,32 +185,6 @@ public class ArrayUtil {
return temp; return temp;
} }
/**
* Replaces the item at index idx with the given object. If the obj is an Object[],
* then the contents of that array are inserted with the first element overwriting
* whatever was at idx.
* @param class1
* @param nodes
* @param declarations
* @return
*/
public static Object[] replace( Class c, Object[] array, int idx, Object obj ) {
if( array == null || idx >= array.length )
return array;
if( obj instanceof Object [] ){
Object [] objs = (Object[]) obj;
Object [] temp = (Object[]) Array.newInstance( c, array.length + objs.length - 1 );
System.arraycopy( array, 0, temp, 0, idx );
System.arraycopy( objs, 0, temp, idx, objs.length );
System.arraycopy( array, idx + 1, temp, idx + objs.length, array.length - idx - 1);
array = temp;
} else {
array[idx] = obj;
}
return array;
}
public static boolean contains( Object [] array, Object obj ){ public static boolean contains( Object [] array, Object obj ){
if( array == null ) return false; if( array == null ) return false;
for( int i = 0; i < array.length; i++ ) for( int i = 0; i < array.length; i++ )
@ -198,8 +201,6 @@ public class ArrayUtil {
* *
* If there are no nulls in the original array then the original * If there are no nulls in the original array then the original
* array is returned. * array is returned.
*
* @return
*/ */
public static Object[] removeNulls(Class c, Object[] array) { public static Object[] removeNulls(Class c, Object[] array) {
if( array == null ) if( array == null )
@ -235,24 +236,19 @@ public class ArrayUtil {
if( array == null || index < 0) if( array == null || index < 0)
return (Object[]) Array.newInstance( c, 0 ); return (Object[]) Array.newInstance( c, 0 );
if( array.length == index + 1 ) final int newLen= index+1;
if( array.length == newLen)
return array; return array;
Object[] newArray = (Object[]) Array.newInstance(c, index + 1); Object[] newArray = (Object[]) Array.newInstance(c, newLen);
for( int i = 0; i <= index; i++ ){ System.arraycopy(array, 0, newArray, 0, newLen);
newArray[i] = array[i];
}
return newArray; return newArray;
} }
/** /**
* Insert the obj at the beginning of the array, shifting the whole thing one index * Insert the obj at the beginning of the array, shifting the whole thing one index
* @param c * Assumes that array contains nulls at the end, only.
* @param array
* @param idx
* @param obj
* @return
*/ */
public static Object[] prepend(Class c, Object[] array, Object obj) { public static Object[] prepend(Class c, Object[] array, Object obj) {
if( obj == null ) if( obj == null )
@ -263,17 +259,12 @@ public class ArrayUtil {
return array; return array;
} }
int i = 0; int i = findFirstNull(array);
for( ; i < array.length; i++ ){ if (i >= 0) {
if( array[i] == null ){ System.arraycopy( array, 0, array, 1, i);
array[i] = obj;
return array;
}
}
if( i < array.length ){
System.arraycopy( array, 0, array, 1, array.length - i );
array[0] = obj; array[0] = obj;
} else { }
else {
Object [] temp = (Object[]) Array.newInstance( c, array.length * 2 ); Object [] temp = (Object[]) Array.newInstance( c, array.length * 2 );
System.arraycopy( array, 0, temp, 1, array.length ); System.arraycopy( array, 0, temp, 1, array.length );
temp[0] = obj; temp[0] = obj;
@ -283,13 +274,41 @@ public class ArrayUtil {
return array; return array;
} }
public static void reverse(Object [] array) { /**
for (int left = 0, right = array.length - 1; * Removes first occurrence of element in array and moves objects behind up front.
left < right; ++left, --right) { * @since 4.0
Object tmp = array[left]; */
array[left] = array[right]; public static void remove(Object[] array, Object element) {
array[right] = tmp; if( array != null ) {
for (int i = 0; i < array.length; i++) {
if( element == array[i] ) {
System.arraycopy(array, i+1, array, i, array.length-i-1);
array[array.length-1]= null;
return;
}
}
} }
} }
static public int [] setInt( int[] array, int idx, int val ){
if( array == null ){
array = new int [ DEFAULT_LENGTH > idx + 1 ? DEFAULT_LENGTH : idx + 1];
array[idx] = val;
return array;
}
if( array.length <= idx ){
int newLen = array.length * 2;
while( newLen <= idx ) newLen *=2;
int [] temp = new int [newLen];
System.arraycopy( array, 0, temp, 0, array.length );
array = temp;
}
array[idx] = val;
return array;
}
} }

View file

@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
@ -24,8 +25,7 @@ public class CASTAmbiguousExpression extends CASTAmbiguity implements
public void addExpression(IASTExpression e) { public void addExpression(IASTExpression e) {
if (e != null) { if (e != null) {
expressionsPos++; expressions = (IASTExpression[]) ArrayUtil.append( IASTExpression.class, expressions, ++expressionsPos, e );
expressions = (IASTExpression[]) ArrayUtil.append( IASTExpression.class, expressions, e );
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
@ -23,8 +24,7 @@ public class CASTAmbiguousStatement extends CASTAmbiguity implements
public void addStatement(IASTStatement s) { public void addStatement(IASTStatement s) {
if (s != null) { if (s != null) {
stmtsPos++; stmts = (IASTStatement[]) ArrayUtil.append( IASTStatement.class, stmts, ++stmtsPos, s );
stmts = (IASTStatement[]) ArrayUtil.append( IASTStatement.class, stmts, s );
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others. * Copyright (c) 2005, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
@ -34,8 +35,7 @@ public class CASTArrayDeclarator extends CASTDeclarator implements
public void addArrayModifier(IASTArrayModifier arrayModifier) { public void addArrayModifier(IASTArrayModifier arrayModifier) {
if (arrayModifier != null) { if (arrayModifier != null) {
arrayModsPos++; arrayMods = (IASTArrayModifier[]) ArrayUtil.append( IASTArrayModifier.class, arrayMods, ++arrayModsPos, arrayModifier );
arrayMods = (IASTArrayModifier[]) ArrayUtil.append( IASTArrayModifier.class, arrayMods, arrayModifier );
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others. * Copyright (c) 2005, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
@ -75,8 +76,7 @@ public class CASTCompositeTypeSpecifier extends CASTBaseDeclSpecifier implements
*/ */
public void addMemberDeclaration(IASTDeclaration declaration) { public void addMemberDeclaration(IASTDeclaration declaration) {
if (declaration != null) { if (declaration != null) {
declarationsPos++; declarations = (IASTDeclaration[]) ArrayUtil.append( IASTDeclaration.class, declarations, ++declarationsPos, declaration );
declarations = (IASTDeclaration[]) ArrayUtil.append( IASTDeclaration.class, declarations, declaration );
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others. * Copyright (c) 2005, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
@ -35,7 +36,7 @@ public class CASTCompoundStatement extends CASTNode implements
*/ */
public IASTStatement[] getStatements() { public IASTStatement[] getStatements() {
if( statements == null ) return IASTStatement.EMPTY_STATEMENT_ARRAY; if( statements == null ) return IASTStatement.EMPTY_STATEMENT_ARRAY;
return (IASTStatement[]) ArrayUtil.removeNulls( IASTStatement.class, statements ); return (IASTStatement[]) ArrayUtil.trim( IASTStatement.class, statements );
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others. * Copyright (c) 2005, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
@ -80,8 +81,7 @@ public class CASTDeclarator extends CASTNode implements IASTDeclarator {
*/ */
public void addPointerOperator(IASTPointerOperator operator) { public void addPointerOperator(IASTPointerOperator operator) {
if (operator != null) { if (operator != null) {
pointerOpsPos++; pointerOps = (IASTPointerOperator[]) ArrayUtil.append( IASTPointerOperator.class, pointerOps, ++pointerOpsPos, operator );
pointerOps = (IASTPointerOperator[]) ArrayUtil.append( IASTPointerOperator.class, pointerOps, operator );
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
@ -29,8 +30,7 @@ public class CASTDesignatedInitializer extends CASTNode implements
*/ */
public void addDesignator(ICASTDesignator designator) { public void addDesignator(ICASTDesignator designator) {
if (designator != null) { if (designator != null) {
designatorsPos++; designators = (ICASTDesignator[]) ArrayUtil.append( ICASTDesignator.class, designators, ++designatorsPos, designator );
designators = (ICASTDesignator[]) ArrayUtil.append( ICASTDesignator.class, designators, designator );
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others. * Copyright (c) 2005, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
@ -28,8 +29,7 @@ public class CASTEnumerationSpecifier extends CASTBaseDeclSpecifier implements
*/ */
public void addEnumerator(IASTEnumerator enumerator) { public void addEnumerator(IASTEnumerator enumerator) {
if (enumerator != null) { if (enumerator != null) {
enumeratorsPos++; enumerators = (IASTEnumerator[]) ArrayUtil.append( IASTEnumerator.class, enumerators, ++enumeratorsPos, enumerator );
enumerators = (IASTEnumerator[]) ArrayUtil.append( IASTEnumerator.class, enumerators, enumerator );
} }
} }

View file

@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
@ -27,7 +28,7 @@ public class CASTExpressionList extends CASTNode implements IASTExpressionList,
public IASTExpression[] getExpressions() { public IASTExpression[] getExpressions() {
if (expressions == null) if (expressions == null)
return IASTExpression.EMPTY_EXPRESSION_ARRAY; return IASTExpression.EMPTY_EXPRESSION_ARRAY;
return (IASTExpression[]) ArrayUtil.removeNulls( IASTExpression.class, expressions ); return (IASTExpression[]) ArrayUtil.trim( IASTExpression.class, expressions );
} }
public void addExpression(IASTExpression expression) { public void addExpression(IASTExpression expression) {

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others. * Copyright (c) 2005, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
@ -41,8 +42,7 @@ public class CASTFunctionDeclarator extends CASTDeclarator implements
*/ */
public void addParameterDeclaration(IASTParameterDeclaration parameter) { public void addParameterDeclaration(IASTParameterDeclaration parameter) {
if (parameter != null) { if (parameter != null) {
parametersPos++; parameters = (IASTParameterDeclaration[]) ArrayUtil.append( IASTParameterDeclaration.class, parameters, ++parametersPos, parameter );
parameters = (IASTParameterDeclaration[]) ArrayUtil.append( IASTParameterDeclaration.class, parameters, parameter );
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others. * Copyright (c) 2005, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
@ -34,8 +35,7 @@ public class CASTInitializerList extends CASTNode implements
public void addInitializer( IASTInitializer d ) public void addInitializer( IASTInitializer d )
{ {
if (d != null) { if (d != null) {
initializersPos++; initializers = (IASTInitializer[]) ArrayUtil.append( IASTInitializer.class, initializers, ++initializersPos, d );
initializers = (IASTInitializer[]) ArrayUtil.append( IASTInitializer.class, initializers, d );
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others. * Copyright (c) 2005, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
@ -42,8 +43,7 @@ public class CASTSimpleDeclaration extends CASTNode implements
public void addDeclarator( IASTDeclarator d ) public void addDeclarator( IASTDeclarator d )
{ {
if (d != null) { if (d != null) {
declaratorsPos++; declarators = (IASTDeclarator[]) ArrayUtil.append( IASTDeclarator.class, declarators, ++declaratorsPos, d );
declarators = (IASTDeclarator[]) ArrayUtil.append( IASTDeclarator.class, declarators, d );
} }
} }

View file

@ -88,8 +88,7 @@ public class CASTTranslationUnit extends CASTNode implements
public void addDeclaration(IASTDeclaration d) { public void addDeclaration(IASTDeclaration d) {
if (d != null) { if (d != null) {
declsPos++; decls = (IASTDeclaration[]) ArrayUtil.append( IASTDeclaration.class, decls, ++declsPos, d );
decls = (IASTDeclaration[]) ArrayUtil.append( IASTDeclaration.class, decls, d );
} }
} }
@ -175,6 +174,7 @@ public class CASTTranslationUnit extends CASTNode implements
if (!names[i].isDefinition()) if (!names[i].isDefinition())
names[i] = null; names[i] = null;
} }
// nulls can be anywhere, don't use trim()
return (IASTName[])ArrayUtil.removeNulls(IASTName.class, names); return (IASTName[])ArrayUtil.removeNulls(IASTName.class, names);
} }

View file

@ -27,8 +27,7 @@ public class CPPASTAmbiguousDeclaration extends CPPASTAmbiguity implements
public void addDeclaration(IASTDeclaration d) { public void addDeclaration(IASTDeclaration d) {
if (d != null) { if (d != null) {
declsPos++; decls = (IASTDeclaration[]) ArrayUtil.append(IASTDeclaration.class, decls, ++declsPos, d );
decls = (IASTDeclaration[]) ArrayUtil.append(IASTDeclaration.class, decls, d );
} }
} }

View file

@ -24,8 +24,7 @@ public class CPPASTAmbiguousExpression extends CPPASTAmbiguity implements
public void addExpression(IASTExpression e) { public void addExpression(IASTExpression e) {
if (e != null) { if (e != null) {
expPos++; exp = (IASTExpression[]) ArrayUtil.append( IASTExpression.class, exp, ++expPos, e );
exp = (IASTExpression[]) ArrayUtil.append( IASTExpression.class, exp, e );
} }
} }

View file

@ -23,8 +23,7 @@ public class CPPASTAmbiguousStatement extends CPPASTAmbiguity implements
public void addStatement(IASTStatement s) { public void addStatement(IASTStatement s) {
if (s != null) { if (s != null) {
stmtsPos++; stmts = (IASTStatement[]) ArrayUtil.append( IASTStatement.class, stmts, ++stmtsPos, s );
stmts = (IASTStatement[]) ArrayUtil.append( IASTStatement.class, stmts, s );
} }
} }

View file

@ -33,8 +33,7 @@ public class CPPASTArrayDeclarator extends CPPASTDeclarator implements
public void addArrayModifier(IASTArrayModifier arrayModifier) { public void addArrayModifier(IASTArrayModifier arrayModifier) {
if (arrayModifier != null) { if (arrayModifier != null) {
arrayModsPos++; arrayMods = (IASTArrayModifier[]) ArrayUtil.append( IASTArrayModifier.class, arrayMods, ++arrayModsPos, arrayModifier );
arrayMods = (IASTArrayModifier[]) ArrayUtil.append( IASTArrayModifier.class, arrayMods, arrayModifier );
} }
} }

View file

@ -50,8 +50,7 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier
*/ */
public void addBaseSpecifier(ICPPASTBaseSpecifier baseSpec) { public void addBaseSpecifier(ICPPASTBaseSpecifier baseSpec) {
if (baseSpec != null) { if (baseSpec != null) {
baseSpecsPos++; baseSpecs = (ICPPASTBaseSpecifier[]) ArrayUtil.append( ICPPASTBaseSpecifier.class, baseSpecs, ++baseSpecsPos, baseSpec );
baseSpecs = (ICPPASTBaseSpecifier[]) ArrayUtil.append( ICPPASTBaseSpecifier.class, baseSpecs, baseSpec );
} }
} }
@ -88,7 +87,7 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier
*/ */
public IASTDeclaration[] getMembers() { public IASTDeclaration[] getMembers() {
if( declarations == null ) return IASTDeclaration.EMPTY_DECLARATION_ARRAY; if( declarations == null ) return IASTDeclaration.EMPTY_DECLARATION_ARRAY;
return (IASTDeclaration[]) ArrayUtil.removeNulls( IASTDeclaration.class, declarations ); return (IASTDeclaration[]) ArrayUtil.trim( IASTDeclaration.class, declarations );
} }
@ -151,7 +150,9 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier
if( declarations == null ) return; if( declarations == null ) return;
for( int i = 0; i < declarations.length; ++i ) for( int i = 0; i < declarations.length; ++i )
{ {
if( declarations[i] == null ) continue; if( declarations[i] == null ) {
break;
}
if( declarations[i] == child ) if( declarations[i] == child )
{ {
other.setParent( child.getParent() ); other.setParent( child.getParent() );

View file

@ -34,7 +34,7 @@ public class CPPASTCompoundStatement extends CPPASTNode implements
*/ */
public IASTStatement[] getStatements() { public IASTStatement[] getStatements() {
if( statements == null ) return IASTStatement.EMPTY_STATEMENT_ARRAY; if( statements == null ) return IASTStatement.EMPTY_STATEMENT_ARRAY;
return (IASTStatement[]) ArrayUtil.removeNulls( IASTStatement.class, statements ); return (IASTStatement[]) ArrayUtil.trim( IASTStatement.class, statements );
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -78,8 +78,7 @@ public class CPPASTDeclarator extends CPPASTNode implements IASTDeclarator {
*/ */
public void addPointerOperator(IASTPointerOperator operator) { public void addPointerOperator(IASTPointerOperator operator) {
if (operator != null) { if (operator != null) {
pointerOpsPos++; pointerOps = (IASTPointerOperator[]) ArrayUtil.append( IASTPointerOperator.class, pointerOps, ++pointerOpsPos, operator );
pointerOps = (IASTPointerOperator[]) ArrayUtil.append( IASTPointerOperator.class, pointerOps, operator );
} }
} }

View file

@ -31,8 +31,7 @@ public class CPPASTEnumerationSpecifier extends CPPASTBaseDeclSpecifier
*/ */
public void addEnumerator(IASTEnumerator enumerator) { public void addEnumerator(IASTEnumerator enumerator) {
if (enumerator != null) { if (enumerator != null) {
enumeratorsPos++; enumerators = (IASTEnumerator[]) ArrayUtil.append( IASTEnumerator.class, enumerators, ++enumeratorsPos, enumerator );
enumerators = (IASTEnumerator[]) ArrayUtil.append( IASTEnumerator.class, enumerators, enumerator );
} }
} }

View file

@ -26,7 +26,7 @@ public class CPPASTExpressionList extends CPPASTNode implements
public IASTExpression [] getExpressions() { public IASTExpression [] getExpressions() {
if( expressions == null ) return IASTExpression.EMPTY_EXPRESSION_ARRAY; if( expressions == null ) return IASTExpression.EMPTY_EXPRESSION_ARRAY;
return (IASTExpression[]) ArrayUtil.removeNulls( IASTExpression.class, expressions ); return (IASTExpression[]) ArrayUtil.trim( IASTExpression.class, expressions );
} }
public void addExpression(IASTExpression expression) { public void addExpression(IASTExpression expression) {

View file

@ -52,8 +52,7 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements
*/ */
public void addParameterDeclaration(IASTParameterDeclaration parameter) { public void addParameterDeclaration(IASTParameterDeclaration parameter) {
if (parameter != null) { if (parameter != null) {
parametersPos++; parameters = (IASTParameterDeclaration []) ArrayUtil.append( IASTParameterDeclaration.class, parameters, ++parametersPos, parameter );
parameters = (IASTParameterDeclaration []) ArrayUtil.append( IASTParameterDeclaration.class, parameters, parameter );
} }
} }
@ -120,8 +119,7 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements
*/ */
public void addExceptionSpecificationTypeId(IASTTypeId typeId) { public void addExceptionSpecificationTypeId(IASTTypeId typeId) {
if (typeId != null) { if (typeId != null) {
typeIdsPos++; typeIds = (IASTTypeId[]) ArrayUtil.append( IASTTypeId.class, typeIds, ++typeIdsPos, typeId );
typeIds = (IASTTypeId[]) ArrayUtil.append( IASTTypeId.class, typeIds, typeId );
} }
} }
@ -160,8 +158,7 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements
*/ */
public void addConstructorToChain(ICPPASTConstructorChainInitializer initializer) { public void addConstructorToChain(ICPPASTConstructorChainInitializer initializer) {
if (initializer != null) { if (initializer != null) {
constructorChainPos++; constructorChain = (ICPPASTConstructorChainInitializer[]) ArrayUtil.append(ICPPASTConstructorChainInitializer.class, constructorChain, ++constructorChainPos, initializer );
constructorChain = (ICPPASTConstructorChainInitializer[]) ArrayUtil.append( ICPPASTConstructorChainInitializer.class, constructorChain, initializer );
} }
} }

View file

@ -26,8 +26,7 @@ public class CPPASTFunctionTryBlockDeclarator extends CPPASTFunctionDeclarator
*/ */
public void addCatchHandler(ICPPASTCatchHandler statement) { public void addCatchHandler(ICPPASTCatchHandler statement) {
if (statement != null) { if (statement != null) {
catchHandlersPos++; catchHandlers = (ICPPASTCatchHandler[]) ArrayUtil.append( ICPPASTCatchHandler.class, catchHandlers, ++catchHandlersPos, statement );
catchHandlers = (ICPPASTCatchHandler[]) ArrayUtil.append( ICPPASTCatchHandler.class, catchHandlers, statement );
} }
} }

View file

@ -34,8 +34,7 @@ public class CPPASTInitializerList extends CPPASTNode implements
public void addInitializer( IASTInitializer d ) public void addInitializer( IASTInitializer d )
{ {
if (d != null) { if (d != null) {
initializersPos++; initializers = (IASTInitializer[]) ArrayUtil.append( IASTInitializer.class, initializers, ++initializersPos, d );
initializers = (IASTInitializer[]) ArrayUtil.append( IASTInitializer.class, initializers, d );
} }
} }

View file

@ -43,7 +43,7 @@ public class CPPASTLinkageSpecification extends CPPASTNode implements
*/ */
public IASTDeclaration [] getDeclarations() { public IASTDeclaration [] getDeclarations() {
if( declarations == null ) return IASTDeclaration.EMPTY_DECLARATION_ARRAY; if( declarations == null ) return IASTDeclaration.EMPTY_DECLARATION_ARRAY;
return (IASTDeclaration[]) ArrayUtil.removeNulls( IASTDeclaration.class, declarations ); return (IASTDeclaration[]) ArrayUtil.trim( IASTDeclaration.class, declarations );
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -49,7 +50,7 @@ public class CPPASTNamespaceDefinition extends CPPASTNode implements
*/ */
public IASTDeclaration [] getDeclarations() { public IASTDeclaration [] getDeclarations() {
if( declarations == null ) return IASTDeclaration.EMPTY_DECLARATION_ARRAY; if( declarations == null ) return IASTDeclaration.EMPTY_DECLARATION_ARRAY;
return (IASTDeclaration[]) ArrayUtil.removeNulls( IASTDeclaration.class, declarations ); return (IASTDeclaration[]) ArrayUtil.trim( IASTDeclaration.class, declarations );
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -101,7 +102,7 @@ public class CPPASTNamespaceDefinition extends CPPASTNode implements
if( declarations == null ) return; if( declarations == null ) return;
for( int i = 0; i < declarations.length; ++i ) for( int i = 0; i < declarations.length; ++i )
{ {
if( declarations[i] == null ) continue; if( declarations[i] == null ) break;
if( declarations[i] == child ) if( declarations[i] == child )
{ {
other.setParent( child.getParent() ); other.setParent( child.getParent() );

View file

@ -73,7 +73,7 @@ public class CPPASTNewExpression extends CPPASTNode implements
public IASTExpression [] getNewTypeIdArrayExpressions() { public IASTExpression [] getNewTypeIdArrayExpressions() {
if( arrayExpressions == null ) return IASTExpression.EMPTY_EXPRESSION_ARRAY; if( arrayExpressions == null ) return IASTExpression.EMPTY_EXPRESSION_ARRAY;
return (IASTExpression[]) ArrayUtil.removeNulls( IASTExpression.class, arrayExpressions ); return (IASTExpression[]) ArrayUtil.trim( IASTExpression.class, arrayExpressions );
} }
public void addNewTypeIdArrayExpression(IASTExpression expression) { public void addNewTypeIdArrayExpression(IASTExpression expression) {

View file

@ -10,7 +10,6 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNameOwner; import org.eclipse.cdt.core.dom.ast.IASTNameOwner;
@ -21,7 +20,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTOperatorName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
/** /**
* @author jcamelon * @author jcamelon
@ -71,8 +69,7 @@ public class CPPASTQualifiedName extends CPPASTNode implements
*/ */
public void addName(IASTName name) { public void addName(IASTName name) {
if (name != null) { if (name != null) {
namesPos++; names = (IASTName[]) ArrayUtil.append( IASTName.class, names, ++namesPos, name );
names = (IASTName[]) ArrayUtil.append( IASTName.class, names, name );
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -43,8 +44,7 @@ public class CPPASTSimpleDeclaration extends CPPASTNode implements
public void addDeclarator( IASTDeclarator d ) public void addDeclarator( IASTDeclarator d )
{ {
if (d != null) { if (d != null) {
declaratorsPos++; declarators = (IASTDeclarator[]) ArrayUtil.append( IASTDeclarator.class, declarators, ++declaratorsPos, d );
declarators = (IASTDeclarator[]) ArrayUtil.append( IASTDeclarator.class, declarators, d );
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -71,8 +72,7 @@ public class CPPASTTemplateDeclaration extends CPPASTNode implements
*/ */
public void addTemplateParamter(ICPPASTTemplateParameter parm) { public void addTemplateParamter(ICPPASTTemplateParameter parm) {
if (parm != null) { if (parm != null) {
parametersPos++; parameters = (ICPPASTTemplateParameter[]) ArrayUtil.append( ICPPASTTemplateParameter.class, parameters, ++parametersPos, parm );
parameters = (ICPPASTTemplateParameter[]) ArrayUtil.append( ICPPASTTemplateParameter.class, parameters, parm );
} }
} }

View file

@ -60,7 +60,7 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, I
*/ */
public IASTNode[] getTemplateArguments() { public IASTNode[] getTemplateArguments() {
if( templateArguments == null ) return ICPPASTTemplateId.EMPTY_ARG_ARRAY; if( templateArguments == null ) return ICPPASTTemplateId.EMPTY_ARG_ARRAY;
return (IASTNode[]) ArrayUtil.removeNulls( IASTNode.class, templateArguments ); return (IASTNode[]) ArrayUtil.trim( IASTNode.class, templateArguments );
} }
private IASTNode [] templateArguments = null; private IASTNode [] templateArguments = null;

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -34,8 +35,7 @@ public class CPPASTTemplatedTypeTemplateParameter extends CPPASTNode implements
public void addTemplateParamter(ICPPASTTemplateParameter parm) { public void addTemplateParamter(ICPPASTTemplateParameter parm) {
if(parm != null) { if(parm != null) {
parametersPos++; parameters = (ICPPASTTemplateParameter[]) ArrayUtil.append( ICPPASTTemplateParameter.class, parameters, ++parametersPos, parm );
parameters = (ICPPASTTemplateParameter[]) ArrayUtil.append( ICPPASTTemplateParameter.class, parameters, parm );
} }
} }

View file

@ -112,7 +112,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
public IASTDeclaration[] getDeclarations() { public IASTDeclaration[] getDeclarations() {
if (decls == null) if (decls == null)
return IASTDeclaration.EMPTY_DECLARATION_ARRAY; return IASTDeclaration.EMPTY_DECLARATION_ARRAY;
return (IASTDeclaration[]) ArrayUtil.removeNulls( IASTDeclaration.class, decls ); return (IASTDeclaration[]) ArrayUtil.trim( IASTDeclaration.class, decls );
} }
/* /*
@ -212,6 +212,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
if (!names[i].isDefinition()) if (!names[i].isDefinition())
names[i] = null; names[i] = null;
} }
// nulls can be anywhere, don't use trim()
return (IASTName[])ArrayUtil.removeNulls(IASTName.class, names); return (IASTName[])ArrayUtil.removeNulls(IASTName.class, names);
} }
@ -585,7 +586,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
if( decls == null ) return; if( decls == null ) return;
for( int i = 0; i < decls.length; ++i ) for( int i = 0; i < decls.length; ++i )
{ {
if( decls[i] == null ) continue; if( decls[i] == null ) break;
if( decls[i] == child ) if( decls[i] == child )
{ {
other.setParent( child.getParent() ); other.setParent( child.getParent() );

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -29,8 +30,7 @@ public class CPPASTTryBlockStatement extends CPPASTNode implements
*/ */
public void addCatchHandler(ICPPASTCatchHandler statement) { public void addCatchHandler(ICPPASTCatchHandler statement) {
if (statement != null) { if (statement != null) {
catchHandlersPos++; catchHandlers = (ICPPASTCatchHandler[]) ArrayUtil.append( ICPPASTCatchHandler.class, catchHandlers, ++catchHandlersPos, statement );
catchHandlers = (ICPPASTCatchHandler[]) ArrayUtil.append( ICPPASTCatchHandler.class, catchHandlers, statement );
} }
} }

View file

@ -440,17 +440,7 @@ public class CPPClassType extends PlatformObject implements ICPPClassType, ICPPI
definition = null; definition = null;
return; return;
} }
if( declarations != null ) { ArrayUtil.remove(declarations, node);
for (int i = 0; i < declarations.length; i++) {
if( node == declarations[i] ) {
if( i == declarations.length - 1 )
declarations[i] = null;
else
System.arraycopy( declarations, i + 1, declarations, i, declarations.length - 1 - i );
return;
}
}
}
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Dec 16, 2004 * Created on Dec 16, 2004

View file

@ -244,15 +244,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
return; return;
} }
if( declarations != null ) { if( declarations != null ) {
for (int i = 0; i < declarations.length; i++) { ArrayUtil.remove(declarations, node);
if( node == declarations[i] ) {
if( i == declarations.length - 1 )
declarations[i] = null;
else
System.arraycopy( declarations, i + 1, declarations, i, declarations.length - 1 - i );
return;
}
}
} }
} }

View file

@ -336,17 +336,7 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI
addDefinition( node ); addDefinition( node );
} }
public void removeDeclaration(IASTNode node) { public void removeDeclaration(IASTNode node) {
if( namespaceDefinitions != null ) { ArrayUtil.remove(namespaceDefinitions, node);
for (int i = 0; i < namespaceDefinitions.length; i++) {
if( node == namespaceDefinitions[i] ) {
if( i == namespaceDefinitions.length - 1 )
namespaceDefinitions[i] = null;
else
System.arraycopy( namespaceDefinitions, i + 1, namespaceDefinitions, i, namespaceDefinitions.length - 1 - i );
return;
}
}
}
} }
public IBinding[] getMemberBindings() { public IBinding[] getMemberBindings() {

View file

@ -108,17 +108,9 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI
} }
public void removeDeclaration(IASTNode node) { public void removeDeclaration(IASTNode node) {
if( declarations != null ) { ArrayUtil.remove(declarations, node);
for (int i = 0; i < declarations.length; i++) {
if( node == declarations[i] ) {
if( i == declarations.length - 1 )
declarations[i] = null;
else
System.arraycopy( declarations, i + 1, declarations, i, declarations.length - 1 - i );
}
}
}
} }
private IASTName getPrimaryDeclaration(){ private IASTName getPrimaryDeclaration(){
if( declarations != null ){ if( declarations != null ){
for( int i = 0; i < declarations.length && declarations[i] != null; i++ ){ for( int i = 0; i < declarations.length && declarations[i] != null; i++ ){

View file

@ -87,16 +87,7 @@ public abstract class CPPSpecialization extends PlatformObject implements ICPPSp
definition = null; definition = null;
return; return;
} }
if( declarations != null ) { ArrayUtil.remove(declarations, node);
for (int i = 0; i < declarations.length; i++) {
if( node == declarations[i] ) {
if( i == declarations.length - 1 )
declarations[i] = null;
else
System.arraycopy( declarations, i + 1, declarations, i, declarations.length - 1 - i );
}
}
}
} }
public String getName() { public String getName() {

View file

@ -349,17 +349,7 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC
definition = null; definition = null;
return; return;
} }
if( declarations != null ) { ArrayUtil.remove(declarations, node);
for (int i = 0; i < declarations.length; i++) {
if( node == declarations[i] ) {
if( i == declarations.length - 1 )
declarations[i] = null;
else
System.arraycopy( declarations, i + 1, declarations, i, declarations.length - 1 - i );
return;
}
}
}
} }
protected void updateTemplateParameterBindings( IASTName name ){ protected void updateTemplateParameterBindings( IASTName name ){
IASTName orig = definition != null ? definition : declarations[0]; IASTName orig = definition != null ? definition : declarations[0];

View file

@ -144,17 +144,7 @@ public class CPPTemplateParameter extends PlatformObject implements ICPPTemplate
} }
} }
public void removeDeclaration(IASTNode node) { public void removeDeclaration(IASTNode node) {
if( declarations != null ) { ArrayUtil.remove(declarations, node);
for (int i = 0; i < declarations.length; i++) {
if( node == declarations[i] ) {
if( i == declarations.length - 1 )
declarations[i] = null;
else
System.arraycopy( declarations, i + 1, declarations, i, declarations.length - 1 - i );
return;
}
}
}
} }
public ILinkage getLinkage() { public ILinkage getLinkage() {

View file

@ -206,17 +206,7 @@ public class CPPTypedef extends PlatformObject implements ITypedef, ITypeContain
} }
public void removeDeclaration(IASTNode node) { public void removeDeclaration(IASTNode node) {
if( declarations != null ) { ArrayUtil.remove(declarations, node);
for (int i = 0; i < declarations.length; i++) {
if( node == declarations[i] ) {
if( i == declarations.length - 1 )
declarations[i] = null;
else
System.arraycopy( declarations, i + 1, declarations, i, declarations.length - 1 - i );
return;
}
}
}
} }
public ILinkage getLinkage() { public ILinkage getLinkage() {

View file

@ -166,16 +166,7 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt
definition = null; definition = null;
return; return;
} }
if( declarations != null ) { ArrayUtil.remove(declarations, node);
for (int i = 0; i < declarations.length; i++) {
if( node == declarations[i] ) {
if( i == declarations.length - 1 )
declarations[i] = null;
else
System.arraycopy( declarations, i + 1, declarations, i, declarations.length - 1 - i );
}
}
}
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner2; package org.eclipse.cdt.internal.core.parser.scanner2;
@ -36,8 +37,7 @@ public class DependencyTree implements IASTTranslationUnit.IDependencyTree, IDep
public void addInclusionNode(IASTInclusionNode node) { public void addInclusionNode(IASTInclusionNode node) {
if (node != null) { if (node != null) {
incsPos++; incs = (IASTInclusionNode[]) ArrayUtil.append( IASTInclusionNode.class, incs, ++incsPos, node );
incs = (IASTInclusionNode[]) ArrayUtil.append( IASTInclusionNode.class, incs, node );
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner2; package org.eclipse.cdt.internal.core.parser.scanner2;
@ -36,8 +37,7 @@ public class InclusionNode implements IASTInclusionNode, IDependencyNodeHost {
public void addInclusionNode(IASTInclusionNode node) { public void addInclusionNode(IASTInclusionNode node) {
if (node != null) { if (node != null) {
incsPos++; incs = (IASTInclusionNode[]) ArrayUtil.append( IASTInclusionNode.class, incs, ++incsPos, node );
incs = (IASTInclusionNode[]) ArrayUtil.append( IASTInclusionNode.class, incs, node );
} }
} }

View file

@ -981,8 +981,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
public void addSubContext(_Context c) { public void addSubContext(_Context c) {
if (subContexts == null) if (subContexts == null)
subContexts = new _Context[DEFAULT_SUBCONTEXT_ARRAY_SIZE]; subContexts = new _Context[DEFAULT_SUBCONTEXT_ARRAY_SIZE];
subContexts = (_Context[]) ArrayUtil.append(_Context.class, subContexts = (_Context[]) ArrayUtil.append(_Context.class, subContexts, c);
subContexts, c);
} }
public boolean hasSubContexts() { public boolean hasSubContexts() {
@ -1093,8 +1092,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
public void addBuiltinMacro(IMacroDefinition def) { public void addBuiltinMacro(IMacroDefinition def) {
if (def != null) { if (def != null) {
builtinsPos++; builtins = (IMacroDefinition[]) ArrayUtil.append( IMacroDefinition.class, builtins, ++builtinsPos, def );
builtins = (IMacroDefinition[]) ArrayUtil.append( IMacroDefinition.class, builtins, def );
} }
} }
@ -1667,17 +1665,15 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
else if (cc instanceof _MacroExpansion && r.hasAncestor(cc)) else if (cc instanceof _MacroExpansion && r.hasAncestor(cc))
++currentCount; ++currentCount;
else { else {
result = (_WeightedContext[]) ArrayUtil.append( result = (_WeightedContext[]) ArrayUtil.append(_WeightedContext.class, result,
_WeightedContext.class, result, new _WeightedContext( new _WeightedContext(cc, currentCount));
cc, currentCount));
cc = r; cc = r;
currentCount = 1; currentCount = 1;
} }
} }
result = (_WeightedContext[]) ArrayUtil.append(_WeightedContext.class, result = (_WeightedContext[]) ArrayUtil.append(_WeightedContext.class, result,
result, new _WeightedContext(cc, currentCount)); new _WeightedContext(cc, currentCount));
return (_WeightedContext[]) ArrayUtil.removeNulls( return (_WeightedContext[]) ArrayUtil.trim(_WeightedContext.class, result);
_WeightedContext.class, result);
} }
protected IASTNodeLocation createSoleLocation(_Context c, int offset, protected IASTNodeLocation createSoleLocation(_Context c, int offset,
@ -2492,7 +2488,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
results = (_Context[]) ArrayUtil.addAll( _Context.class, results, s ); results = (_Context[]) ArrayUtil.addAll( _Context.class, results, s );
} }
} }
return (_Context[]) ArrayUtil.removeNulls( _Context.class, results ); return (_Context[]) ArrayUtil.trim( _Context.class, results );
} }
public IASTName[] getDeclarations(IMacroBinding binding) { public IASTName[] getDeclarations(IMacroBinding binding) {

View file

@ -13,6 +13,7 @@
package org.eclipse.cdt.internal.core.pdom.dom.cpp; package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -33,7 +34,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList; import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList;
@ -118,8 +118,8 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
List list = new ArrayList(); List list = new ArrayList();
for (PDOMCPPBase base = getFirstBase(); base != null; base = base.getNextBase()) for (PDOMCPPBase base = getFirstBase(); base != null; base = base.getNextBase())
list.add(base); list.add(base);
Collections.reverse(list);
ICPPBase[] bases = (ICPPBase[])list.toArray(new ICPPBase[list.size()]); ICPPBase[] bases = (ICPPBase[])list.toArray(new ICPPBase[list.size()]);
ArrayUtil.reverse(bases);
return bases; return bases;
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);