diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ArrayUtilsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ArrayUtilsTest.java new file mode 100644 index 00000000000..707785be1e5 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ArrayUtilsTest.java @@ -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); + } +} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java index 08da06ea722..dc9651579a3 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java @@ -31,6 +31,7 @@ import org.eclipse.cdt.core.parser.tests.scanner2.Scanner2Test; public class ParserTestSuite extends TestCase { public static Test suite() { TestSuite suite= new TestSuite(ParserTestSuite.class.getName()); + suite.addTestSuite(ArrayUtilsTest.class); suite.addTestSuite(Scanner2Test.class ); suite.addTestSuite(QuickParseASTTests.class); suite.addTestSuite(ParserSymbolTableTest.class); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexListenerTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexListenerTest.java index 14778ac6d62..82da478fc23 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexListenerTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexListenerTest.java @@ -112,7 +112,7 @@ public class IndexListenerTest extends BaseTestCase { IFile file= TestSourceReader.createFile(fProject1.getProject(), "test.cpp", "int a;"); synchronized (mutex) { - mutex.wait(1000); + mutex.wait(2000); } assertEquals(1, projects.size()); assertTrue(projects.contains(fProject1)); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ArrayUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ArrayUtil.java index d52ee277f19..44efa9ce25c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ArrayUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ArrayUtil.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ /* @@ -25,67 +26,90 @@ public class ArrayUtil { } public static final int DEFAULT_LENGTH = 2; + /** - * Adds obj to array in the first null slot. - * If array is null, a new array is created and obj is added to the new array. - * If the array is full, a new array of larger size is created, the contents - * of array are copied over and obj is added to the new array. - * - * 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 + * Assumes that array contains nulls at the end, only. + * Appends element after the last non-null element. + * If the array is null or not large enough, a larger one is allocated, using + * the given class object. */ static public Object [] append( Class c, Object[] array, 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; - } - - int i = 0; - for( ; i < array.length; i++ ){ - if( array[i] == null ){ - array[i] = obj; - return array; - } - } - Object [] temp = (Object[]) Array.newInstance( c, array.length * 2 ); - System.arraycopy( array, 0, temp, 0, array.length ); - temp[array.length] = obj; - array = temp; - return array; + if( array == null || array.length == 0){ + array = (Object[]) Array.newInstance( c, DEFAULT_LENGTH ); + array[0] = obj; + return array; + } + + int i= findFirstNull(array); + if (i >= 0) { + array[i]= obj; + return array; + } + + Object [] temp = (Object[]) Array.newInstance( c, array.length * 2 ); + System.arraycopy( array, 0, temp, 0, array.length ); + temp[array.length] = obj; + 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; + } - 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; + + /** + * 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; + } + + if (currentLength < array.length) { + assert array[currentLength] == null; + assert currentLength == 0 || array[currentLength-1] != null; + array[currentLength]= obj; + return array; + } + + Object [] temp = (Object[]) Array.newInstance( c, array.length * 2 ); + System.arraycopy( array, 0, temp, 0, array.length ); + temp[array.length] = obj; + return temp; } - + static public Object [] append( Object[] array, Object obj ){ return append( Object.class, array, obj ); } /** * 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 forceNew == true, a new array will always be created. * if forceNew == false, a new array will only be created if the original array @@ -100,16 +124,20 @@ public class ArrayUtil { if( array == null ) return (Object[]) Array.newInstance( c, 0 ); - int i = 0; - for( ; i < array.length; i++ ){ - if( array[i] == null ) break; + int i = array.length; + if (i==0 || array[i-1] != null) { + if (!forceNew) { + return array; + } } - if( forceNew || i < array.length ){ - Object [] temp = (Object[]) Array.newInstance( c, i ); - System.arraycopy( array, 0, temp, 0, i ); - array = temp; + else { + i=findFirstNull(array); + assert i>=0; } - return array; + + Object [] temp = (Object[]) Array.newInstance( c, i ); + System.arraycopy( array, 0, temp, 0, i ); + return temp; } /** @@ -122,19 +150,19 @@ public class ArrayUtil { } /** - * @param transitives - * @param usings + * Assumes that both arrays contain nulls at the end, only. */ public static Object[] addAll( Class c, Object[] dest, Object[] source ) { if( source == null || source.length == 0 ) return dest; - int numToAdd = 0; - while( numToAdd < source.length && source[numToAdd] != null ) - numToAdd++; - - if( numToAdd == 0 ) - return dest; + int numToAdd = findFirstNull(source); + if (numToAdd <= 0) { + if (numToAdd == 0) { + return dest; + } + numToAdd= source.length; + } if( dest == null || dest.length == 0 ){ dest = (Object[]) Array.newInstance( c, numToAdd ); @@ -142,9 +170,10 @@ public class ArrayUtil { return dest; } - int firstFree = 0; - while( firstFree < dest.length && dest[firstFree] != null ) - firstFree++; + int firstFree = findFirstNull(dest); + if (firstFree < 0) { + firstFree= dest.length; + } if( firstFree + numToAdd <= dest.length ){ System.arraycopy( source, 0, dest, firstFree, numToAdd ); @@ -155,32 +184,6 @@ public class ArrayUtil { System.arraycopy( source, 0, temp, firstFree, numToAdd ); 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 ){ if( array == null ) return false; @@ -198,8 +201,6 @@ public class ArrayUtil { * * If there are no nulls in the original array then the original * array is returned. - * - * @return */ public static Object[] removeNulls(Class c, Object[] array) { if( array == null ) @@ -222,7 +223,7 @@ public class ArrayUtil { return newArray; } - + /** * To improve performance, this method should be used instead of ArrayUtil#removeNulls(Class, Object[]) when * all of the non-null elements in the array are grouped together at the beginning of the array @@ -235,24 +236,19 @@ public class ArrayUtil { if( array == null || index < 0) return (Object[]) Array.newInstance( c, 0 ); - if( array.length == index + 1 ) + final int newLen= index+1; + if( array.length == newLen) return array; - Object[] newArray = (Object[]) Array.newInstance(c, index + 1); - for( int i = 0; i <= index; i++ ){ - newArray[i] = array[i]; - } - + Object[] newArray = (Object[]) Array.newInstance(c, newLen); + System.arraycopy(array, 0, newArray, 0, newLen); return newArray; } + /** * Insert the obj at the beginning of the array, shifting the whole thing one index - * @param c - * @param array - * @param idx - * @param obj - * @return + * Assumes that array contains nulls at the end, only. */ public static Object[] prepend(Class c, Object[] array, Object obj) { if( obj == null ) @@ -263,17 +259,12 @@ public class ArrayUtil { return array; } - int i = 0; - for( ; i < array.length; i++ ){ - if( array[i] == null ){ - array[i] = obj; - return array; - } - } - if( i < array.length ){ - System.arraycopy( array, 0, array, 1, array.length - i ); + int i = findFirstNull(array); + if (i >= 0) { + System.arraycopy( array, 0, array, 1, i); array[0] = obj; - } else { + } + else { Object [] temp = (Object[]) Array.newInstance( c, array.length * 2 ); System.arraycopy( array, 0, temp, 1, array.length ); temp[0] = obj; @@ -283,13 +274,41 @@ public class ArrayUtil { return array; } - public static void reverse(Object [] array) { - for (int left = 0, right = array.length - 1; - left < right; ++left, --right) { - Object tmp = array[left]; - array[left] = array[right]; - array[right] = tmp; + /** + * Removes first occurrence of element in array and moves objects behind up front. + * @since 4.0 + */ + public static void remove(Object[] array, Object element) { + 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; + } + + + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousExpression.java index 250195200a1..a1f02d57bc5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousExpression.java @@ -7,6 +7,7 @@ * * Contributors: * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; @@ -24,8 +25,7 @@ public class CASTAmbiguousExpression extends CASTAmbiguity implements public void addExpression(IASTExpression e) { if (e != null) { - expressionsPos++; - expressions = (IASTExpression[]) ArrayUtil.append( IASTExpression.class, expressions, e ); + expressions = (IASTExpression[]) ArrayUtil.append( IASTExpression.class, expressions, ++expressionsPos, e ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousStatement.java index 51ecd6ebbc1..50233f8770b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousStatement.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; @@ -23,8 +24,7 @@ public class CASTAmbiguousStatement extends CASTAmbiguity implements public void addStatement(IASTStatement s) { if (s != null) { - stmtsPos++; - stmts = (IASTStatement[]) ArrayUtil.append( IASTStatement.class, stmts, s ); + stmts = (IASTStatement[]) ArrayUtil.append( IASTStatement.class, stmts, ++stmtsPos, s ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDeclarator.java index ce37d621833..5e84c76d7e0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDeclarator.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; @@ -34,8 +35,7 @@ public class CASTArrayDeclarator extends CASTDeclarator implements public void addArrayModifier(IASTArrayModifier arrayModifier) { if (arrayModifier != null) { - arrayModsPos++; - arrayMods = (IASTArrayModifier[]) ArrayUtil.append( IASTArrayModifier.class, arrayMods, arrayModifier ); + arrayMods = (IASTArrayModifier[]) ArrayUtil.append( IASTArrayModifier.class, arrayMods, ++arrayModsPos, arrayModifier ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompositeTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompositeTypeSpecifier.java index 314dcab6260..2537ca692dc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompositeTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompositeTypeSpecifier.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; @@ -75,8 +76,7 @@ public class CASTCompositeTypeSpecifier extends CASTBaseDeclSpecifier implements */ public void addMemberDeclaration(IASTDeclaration declaration) { if (declaration != null) { - declarationsPos++; - declarations = (IASTDeclaration[]) ArrayUtil.append( IASTDeclaration.class, declarations, declaration ); + declarations = (IASTDeclaration[]) ArrayUtil.append( IASTDeclaration.class, declarations, ++declarationsPos, declaration ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatement.java index fd6fc293fa9..f44d8bea10e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatement.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; @@ -35,7 +36,7 @@ public class CASTCompoundStatement extends CASTNode implements */ public IASTStatement[] getStatements() { if( statements == null ) return IASTStatement.EMPTY_STATEMENT_ARRAY; - return (IASTStatement[]) ArrayUtil.removeNulls( IASTStatement.class, statements ); + return (IASTStatement[]) ArrayUtil.trim( IASTStatement.class, statements ); } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java index ef4ad8be33b..fa327723a71 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ 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) { if (operator != null) { - pointerOpsPos++; - pointerOps = (IASTPointerOperator[]) ArrayUtil.append( IASTPointerOperator.class, pointerOps, operator ); + pointerOps = (IASTPointerOperator[]) ArrayUtil.append( IASTPointerOperator.class, pointerOps, ++pointerOpsPos, operator ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDesignatedInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDesignatedInitializer.java index 0c0b0930a53..6593880c543 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDesignatedInitializer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDesignatedInitializer.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; @@ -29,8 +30,7 @@ public class CASTDesignatedInitializer extends CASTNode implements */ public void addDesignator(ICASTDesignator designator) { if (designator != null) { - designatorsPos++; - designators = (ICASTDesignator[]) ArrayUtil.append( ICASTDesignator.class, designators, designator ); + designators = (ICASTDesignator[]) ArrayUtil.append( ICASTDesignator.class, designators, ++designatorsPos, designator ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerationSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerationSpecifier.java index e1445af2df7..2f62d83b394 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerationSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerationSpecifier.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; @@ -28,8 +29,7 @@ public class CASTEnumerationSpecifier extends CASTBaseDeclSpecifier implements */ public void addEnumerator(IASTEnumerator enumerator) { if (enumerator != null) { - enumeratorsPos++; - enumerators = (IASTEnumerator[]) ArrayUtil.append( IASTEnumerator.class, enumerators, enumerator ); + enumerators = (IASTEnumerator[]) ArrayUtil.append( IASTEnumerator.class, enumerators, ++enumeratorsPos, enumerator ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionList.java index 842168692e8..6a4a2079ce5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionList.java @@ -7,6 +7,7 @@ * * Contributors: * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; @@ -27,7 +28,7 @@ public class CASTExpressionList extends CASTNode implements IASTExpressionList, public IASTExpression[] getExpressions() { 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) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java index 1c79ce2c952..b462b654665 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; @@ -41,8 +42,7 @@ public class CASTFunctionDeclarator extends CASTDeclarator implements */ public void addParameterDeclaration(IASTParameterDeclaration parameter) { if (parameter != null) { - parametersPos++; - parameters = (IASTParameterDeclaration[]) ArrayUtil.append( IASTParameterDeclaration.class, parameters, parameter ); + parameters = (IASTParameterDeclaration[]) ArrayUtil.append( IASTParameterDeclaration.class, parameters, ++parametersPos, parameter ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerList.java index b9cc0284d31..94d7bc2cda6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerList.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; @@ -34,8 +35,7 @@ public class CASTInitializerList extends CASTNode implements public void addInitializer( IASTInitializer d ) { if (d != null) { - initializersPos++; - initializers = (IASTInitializer[]) ArrayUtil.append( IASTInitializer.class, initializers, d ); + initializers = (IASTInitializer[]) ArrayUtil.append( IASTInitializer.class, initializers, ++initializersPos, d ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java index 8bb6da9560b..0b657bef023 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; @@ -42,8 +43,7 @@ public class CASTSimpleDeclaration extends CASTNode implements public void addDeclarator( IASTDeclarator d ) { if (d != null) { - declaratorsPos++; - declarators = (IASTDeclarator[]) ArrayUtil.append( IASTDeclarator.class, declarators, d ); + declarators = (IASTDeclarator[]) ArrayUtil.append( IASTDeclarator.class, declarators, ++declaratorsPos, d ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java index 706f8331db4..939f38296cb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java @@ -88,8 +88,7 @@ public class CASTTranslationUnit extends CASTNode implements public void addDeclaration(IASTDeclaration d) { if (d != null) { - declsPos++; - decls = (IASTDeclaration[]) ArrayUtil.append( IASTDeclaration.class, decls, d ); + decls = (IASTDeclaration[]) ArrayUtil.append( IASTDeclaration.class, decls, ++declsPos, d ); } } @@ -175,6 +174,7 @@ public class CASTTranslationUnit extends CASTNode implements if (!names[i].isDefinition()) names[i] = null; } + // nulls can be anywhere, don't use trim() return (IASTName[])ArrayUtil.removeNulls(IASTName.class, names); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclaration.java index 54b682818b4..88e24c26653 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclaration.java @@ -27,8 +27,7 @@ public class CPPASTAmbiguousDeclaration extends CPPASTAmbiguity implements public void addDeclaration(IASTDeclaration d) { if (d != null) { - declsPos++; - decls = (IASTDeclaration[]) ArrayUtil.append(IASTDeclaration.class, decls, d ); + decls = (IASTDeclaration[]) ArrayUtil.append(IASTDeclaration.class, decls, ++declsPos, d ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java index e026a497016..179f4c72215 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java @@ -24,8 +24,7 @@ public class CPPASTAmbiguousExpression extends CPPASTAmbiguity implements public void addExpression(IASTExpression e) { if (e != null) { - expPos++; - exp = (IASTExpression[]) ArrayUtil.append( IASTExpression.class, exp, e ); + exp = (IASTExpression[]) ArrayUtil.append( IASTExpression.class, exp, ++expPos, e ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java index 3fcf87d7c91..6ff569ad294 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java @@ -23,8 +23,7 @@ public class CPPASTAmbiguousStatement extends CPPASTAmbiguity implements public void addStatement(IASTStatement s) { if (s != null) { - stmtsPos++; - stmts = (IASTStatement[]) ArrayUtil.append( IASTStatement.class, stmts, s ); + stmts = (IASTStatement[]) ArrayUtil.append( IASTStatement.class, stmts, ++stmtsPos, s ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayDeclarator.java index 65a363d074a..f1c8c6da4cb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayDeclarator.java @@ -33,8 +33,7 @@ public class CPPASTArrayDeclarator extends CPPASTDeclarator implements public void addArrayModifier(IASTArrayModifier arrayModifier) { if (arrayModifier != null) { - arrayModsPos++; - arrayMods = (IASTArrayModifier[]) ArrayUtil.append( IASTArrayModifier.class, arrayMods, arrayModifier ); + arrayMods = (IASTArrayModifier[]) ArrayUtil.append( IASTArrayModifier.class, arrayMods, ++arrayModsPos, arrayModifier ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java index e08e9d155e8..1740055e9af 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java @@ -50,8 +50,7 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier */ public void addBaseSpecifier(ICPPASTBaseSpecifier baseSpec) { if (baseSpec != null) { - baseSpecsPos++; - baseSpecs = (ICPPASTBaseSpecifier[]) ArrayUtil.append( ICPPASTBaseSpecifier.class, baseSpecs, baseSpec ); + baseSpecs = (ICPPASTBaseSpecifier[]) ArrayUtil.append( ICPPASTBaseSpecifier.class, baseSpecs, ++baseSpecsPos, baseSpec ); } } @@ -88,7 +87,7 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier */ public IASTDeclaration[] getMembers() { 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; for( int i = 0; i < declarations.length; ++i ) { - if( declarations[i] == null ) continue; + if( declarations[i] == null ) { + break; + } if( declarations[i] == child ) { other.setParent( child.getParent() ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java index 5501f1436cb..082f074f165 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java @@ -34,7 +34,7 @@ public class CPPASTCompoundStatement extends CPPASTNode implements */ public IASTStatement[] getStatements() { if( statements == null ) return IASTStatement.EMPTY_STATEMENT_ARRAY; - return (IASTStatement[]) ArrayUtil.removeNulls( IASTStatement.class, statements ); + return (IASTStatement[]) ArrayUtil.trim( IASTStatement.class, statements ); } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java index c27f058e6ec..6e9569b1579 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java @@ -78,8 +78,7 @@ public class CPPASTDeclarator extends CPPASTNode implements IASTDeclarator { */ public void addPointerOperator(IASTPointerOperator operator) { if (operator != null) { - pointerOpsPos++; - pointerOps = (IASTPointerOperator[]) ArrayUtil.append( IASTPointerOperator.class, pointerOps, operator ); + pointerOps = (IASTPointerOperator[]) ArrayUtil.append( IASTPointerOperator.class, pointerOps, ++pointerOpsPos, operator ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java index d0185f0b993..f71cb98c072 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java @@ -31,8 +31,7 @@ public class CPPASTEnumerationSpecifier extends CPPASTBaseDeclSpecifier */ public void addEnumerator(IASTEnumerator enumerator) { if (enumerator != null) { - enumeratorsPos++; - enumerators = (IASTEnumerator[]) ArrayUtil.append( IASTEnumerator.class, enumerators, enumerator ); + enumerators = (IASTEnumerator[]) ArrayUtil.append( IASTEnumerator.class, enumerators, ++enumeratorsPos, enumerator ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionList.java index 43a6029cf1e..4c1b2203331 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionList.java @@ -26,7 +26,7 @@ public class CPPASTExpressionList extends CPPASTNode implements public IASTExpression [] getExpressions() { 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) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java index fae598ae019..3575f0c53d6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java @@ -52,8 +52,7 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements */ public void addParameterDeclaration(IASTParameterDeclaration parameter) { if (parameter != null) { - parametersPos++; - parameters = (IASTParameterDeclaration []) ArrayUtil.append( IASTParameterDeclaration.class, parameters, parameter ); + parameters = (IASTParameterDeclaration []) ArrayUtil.append( IASTParameterDeclaration.class, parameters, ++parametersPos, parameter ); } } @@ -120,8 +119,7 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements */ public void addExceptionSpecificationTypeId(IASTTypeId typeId) { if (typeId != null) { - typeIdsPos++; - typeIds = (IASTTypeId[]) ArrayUtil.append( IASTTypeId.class, typeIds, typeId ); + typeIds = (IASTTypeId[]) ArrayUtil.append( IASTTypeId.class, typeIds, ++typeIdsPos, typeId ); } } @@ -160,8 +158,7 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements */ public void addConstructorToChain(ICPPASTConstructorChainInitializer initializer) { if (initializer != null) { - constructorChainPos++; - constructorChain = (ICPPASTConstructorChainInitializer[]) ArrayUtil.append( ICPPASTConstructorChainInitializer.class, constructorChain, initializer ); + constructorChain = (ICPPASTConstructorChainInitializer[]) ArrayUtil.append(ICPPASTConstructorChainInitializer.class, constructorChain, ++constructorChainPos, initializer ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionTryBlockDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionTryBlockDeclarator.java index b736f311305..e542f778b38 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionTryBlockDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionTryBlockDeclarator.java @@ -26,8 +26,7 @@ public class CPPASTFunctionTryBlockDeclarator extends CPPASTFunctionDeclarator */ public void addCatchHandler(ICPPASTCatchHandler statement) { if (statement != null) { - catchHandlersPos++; - catchHandlers = (ICPPASTCatchHandler[]) ArrayUtil.append( ICPPASTCatchHandler.class, catchHandlers, statement ); + catchHandlers = (ICPPASTCatchHandler[]) ArrayUtil.append( ICPPASTCatchHandler.class, catchHandlers, ++catchHandlersPos, statement ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerList.java index c8e173fbc06..bd22353725b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerList.java @@ -34,8 +34,7 @@ public class CPPASTInitializerList extends CPPASTNode implements public void addInitializer( IASTInitializer d ) { if (d != null) { - initializersPos++; - initializers = (IASTInitializer[]) ArrayUtil.append( IASTInitializer.class, initializers, d ); + initializers = (IASTInitializer[]) ArrayUtil.append( IASTInitializer.class, initializers, ++initializersPos, d ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLinkageSpecification.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLinkageSpecification.java index 5f40386f4a8..b02783cd2f5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLinkageSpecification.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLinkageSpecification.java @@ -43,14 +43,14 @@ public class CPPASTLinkageSpecification extends CPPASTNode implements */ public IASTDeclaration [] getDeclarations() { if( declarations == null ) return IASTDeclaration.EMPTY_DECLARATION_ARRAY; - return (IASTDeclaration[]) ArrayUtil.removeNulls( IASTDeclaration.class, declarations ); + return (IASTDeclaration[]) ArrayUtil.trim( IASTDeclaration.class, declarations ); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification#addDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration) */ public void addDeclaration(IASTDeclaration declaration) { - declarations = (IASTDeclaration[]) ArrayUtil.append( IASTDeclaration.class, declarations, declaration ); + declarations = (IASTDeclaration[]) ArrayUtil.append( IASTDeclaration.class, declarations, declaration ); } private IASTDeclaration [] declarations = new IASTDeclaration[4]; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java index 759b1c972bf..2127722d29e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -49,7 +50,7 @@ public class CPPASTNamespaceDefinition extends CPPASTNode implements */ public IASTDeclaration [] getDeclarations() { if( declarations == null ) return IASTDeclaration.EMPTY_DECLARATION_ARRAY; - return (IASTDeclaration[]) ArrayUtil.removeNulls( IASTDeclaration.class, declarations ); + return (IASTDeclaration[]) ArrayUtil.trim( IASTDeclaration.class, declarations ); } /* (non-Javadoc) @@ -101,7 +102,7 @@ public class CPPASTNamespaceDefinition extends CPPASTNode implements if( declarations == null ) return; for( int i = 0; i < declarations.length; ++i ) { - if( declarations[i] == null ) continue; + if( declarations[i] == null ) break; if( declarations[i] == child ) { other.setParent( child.getParent() ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java index bc4c0748dce..f520a2a1ff5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java @@ -73,7 +73,7 @@ public class CPPASTNewExpression extends CPPASTNode implements public IASTExpression [] getNewTypeIdArrayExpressions() { 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) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java index d7059bfd525..474ad2fb18e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java @@ -10,7 +10,6 @@ *******************************************************************************/ 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.IASTName; 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.ICPPASTTemplateId; import org.eclipse.cdt.core.parser.util.ArrayUtil; -import org.eclipse.cdt.internal.core.dom.Linkage; /** * @author jcamelon @@ -71,8 +69,7 @@ public class CPPASTQualifiedName extends CPPASTNode implements */ public void addName(IASTName name) { if (name != null) { - namesPos++; - names = (IASTName[]) ArrayUtil.append( IASTName.class, names, name ); + names = (IASTName[]) ArrayUtil.append( IASTName.class, names, ++namesPos, name ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java index ec65ec0b8c1..85976739697 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -43,8 +44,7 @@ public class CPPASTSimpleDeclaration extends CPPASTNode implements public void addDeclarator( IASTDeclarator d ) { if (d != null) { - declaratorsPos++; - declarators = (IASTDeclarator[]) ArrayUtil.append( IASTDeclarator.class, declarators, d ); + declarators = (IASTDeclarator[]) ArrayUtil.append( IASTDeclarator.class, declarators, ++declaratorsPos, d ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateDeclaration.java index 156c9533383..13160aeb982 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateDeclaration.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -71,8 +72,7 @@ public class CPPASTTemplateDeclaration extends CPPASTNode implements */ public void addTemplateParamter(ICPPASTTemplateParameter parm) { if (parm != null) { - parametersPos++; - parameters = (ICPPASTTemplateParameter[]) ArrayUtil.append( ICPPASTTemplateParameter.class, parameters, parm ); + parameters = (ICPPASTTemplateParameter[]) ArrayUtil.append( ICPPASTTemplateParameter.class, parameters, ++parametersPos, parm ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java index 7b966d9d540..6766c1ff0c5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java @@ -60,7 +60,7 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, I */ public IASTNode[] getTemplateArguments() { 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; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplatedTypeTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplatedTypeTemplateParameter.java index 2dcbbfcf5ea..849fd0fcfd1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplatedTypeTemplateParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplatedTypeTemplateParameter.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -34,8 +35,7 @@ public class CPPASTTemplatedTypeTemplateParameter extends CPPASTNode implements public void addTemplateParamter(ICPPASTTemplateParameter parm) { if(parm != null) { - parametersPos++; - parameters = (ICPPASTTemplateParameter[]) ArrayUtil.append( ICPPASTTemplateParameter.class, parameters, parm ); + parameters = (ICPPASTTemplateParameter[]) ArrayUtil.append( ICPPASTTemplateParameter.class, parameters, ++parametersPos, parm ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java index f481d9ca4d9..f847133ef78 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java @@ -112,7 +112,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements public IASTDeclaration[] getDeclarations() { if (decls == null) 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()) names[i] = null; } + // nulls can be anywhere, don't use trim() return (IASTName[])ArrayUtil.removeNulls(IASTName.class, names); } @@ -585,7 +586,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements if( decls == null ) return; for( int i = 0; i < decls.length; ++i ) { - if( decls[i] == null ) continue; + if( decls[i] == null ) break; if( decls[i] == child ) { other.setParent( child.getParent() ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java index d5d62b89a9f..9e9ea5c1edd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -29,8 +30,7 @@ public class CPPASTTryBlockStatement extends CPPASTNode implements */ public void addCatchHandler(ICPPASTCatchHandler statement) { if (statement != null) { - catchHandlersPos++; - catchHandlers = (ICPPASTCatchHandler[]) ArrayUtil.append( ICPPASTCatchHandler.class, catchHandlers, statement ); + catchHandlers = (ICPPASTCatchHandler[]) ArrayUtil.append( ICPPASTCatchHandler.class, catchHandlers, ++catchHandlersPos, statement ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java index 5efddcac574..7835bc686ec 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java @@ -429,7 +429,7 @@ public class CPPClassType extends PlatformObject implements ICPPClassType, ICPPI //keep the lowest offset declaration in [0] if( declarations.length > 0 && ((ASTNode)node).getOffset() < ((ASTNode)declarations[0]).getOffset() ){ - declarations = (IASTName[]) ArrayUtil.prepend( IASTName.class, declarations, name ); + declarations = (IASTName[]) ArrayUtil.prepend( IASTName.class, declarations, name ); } else { declarations = (IASTName[]) ArrayUtil.append( IASTName.class, declarations, name ); } @@ -440,17 +440,7 @@ public class CPPClassType extends PlatformObject implements ICPPClassType, ICPPI definition = null; return; } - if( declarations != null ) { - 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; - } - } - } + ArrayUtil.remove(declarations, node); } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPCompositeBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPCompositeBinding.java index 6dc7d956ef9..88cdd1bcee5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPCompositeBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPCompositeBinding.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ /* * Created on Dec 16, 2004 diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java index 22b7efd35a0..e59f9ae3b58 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java @@ -244,15 +244,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt return; } if( declarations != null ) { - 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; - } - } + ArrayUtil.remove(declarations, node); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java index 52dd05764a0..e01e4e4716c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java @@ -336,17 +336,7 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI addDefinition( node ); } public void removeDeclaration(IASTNode node) { - if( namespaceDefinitions != null ) { - 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; - } - } - } + ArrayUtil.remove(namespaceDefinitions, node); } public IBinding[] getMemberBindings() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java index 62083daa2cc..278dffdbf6b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java @@ -108,17 +108,9 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI } public void removeDeclaration(IASTNode node) { - if( declarations != null ) { - 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 ); - } - } - } + ArrayUtil.remove(declarations, node); } + private IASTName getPrimaryDeclaration(){ if( declarations != null ){ for( int i = 0; i < declarations.length && declarations[i] != null; i++ ){ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSpecialization.java index cc8bd66e0ca..df071c887b5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSpecialization.java @@ -87,16 +87,7 @@ public abstract class CPPSpecialization extends PlatformObject implements ICPPSp definition = null; return; } - if( declarations != null ) { - 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 ); - } - } - } + ArrayUtil.remove(declarations, node); } public String getName() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java index 23c8e6b0846..883618d4890 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java @@ -349,17 +349,7 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC definition = null; return; } - if( declarations != null ) { - 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; - } - } - } + ArrayUtil.remove(declarations, node); } protected void updateTemplateParameterBindings( IASTName name ){ IASTName orig = definition != null ? definition : declarations[0]; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameter.java index e8f3574ea61..969dc04ab3f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameter.java @@ -144,17 +144,7 @@ public class CPPTemplateParameter extends PlatformObject implements ICPPTemplate } } public void removeDeclaration(IASTNode node) { - if( declarations != null ) { - 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; - } - } - } + ArrayUtil.remove(declarations, node); } public ILinkage getLinkage() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java index ddc7437e66f..9d23bd4b01f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java @@ -206,17 +206,7 @@ public class CPPTypedef extends PlatformObject implements ITypedef, ITypeContain } public void removeDeclaration(IASTNode node) { - if( declarations != null ) { - 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; - } - } - } + ArrayUtil.remove(declarations, node); } public ILinkage getLinkage() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java index df30af7fba5..312b9191188 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java @@ -166,16 +166,7 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt definition = null; return; } - if( declarations != null ) { - 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 ); - } - } - } + ArrayUtil.remove(declarations, node); } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DependencyTree.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DependencyTree.java index 2e62393bc3f..0cdaaca9312 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DependencyTree.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DependencyTree.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.parser.scanner2; @@ -36,8 +37,7 @@ public class DependencyTree implements IASTTranslationUnit.IDependencyTree, IDep public void addInclusionNode(IASTInclusionNode node) { if (node != null) { - incsPos++; - incs = (IASTInclusionNode[]) ArrayUtil.append( IASTInclusionNode.class, incs, node ); + incs = (IASTInclusionNode[]) ArrayUtil.append( IASTInclusionNode.class, incs, ++incsPos, node ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/InclusionNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/InclusionNode.java index 59f17737b03..0bb0dff200b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/InclusionNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/InclusionNode.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.parser.scanner2; @@ -36,8 +37,7 @@ public class InclusionNode implements IASTInclusionNode, IDependencyNodeHost { public void addInclusionNode(IASTInclusionNode node) { if (node != null) { - incsPos++; - incs = (IASTInclusionNode[]) ArrayUtil.append( IASTInclusionNode.class, incs, node ); + incs = (IASTInclusionNode[]) ArrayUtil.append( IASTInclusionNode.class, incs, ++incsPos, node ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java index 7bc334d4699..fd0a498f13f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java @@ -981,8 +981,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { public void addSubContext(_Context c) { if (subContexts == null) subContexts = new _Context[DEFAULT_SUBCONTEXT_ARRAY_SIZE]; - subContexts = (_Context[]) ArrayUtil.append(_Context.class, - subContexts, c); + subContexts = (_Context[]) ArrayUtil.append(_Context.class, subContexts, c); } public boolean hasSubContexts() { @@ -1093,8 +1092,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { public void addBuiltinMacro(IMacroDefinition def) { if (def != null) { - builtinsPos++; - builtins = (IMacroDefinition[]) ArrayUtil.append( IMacroDefinition.class, builtins, def ); + builtins = (IMacroDefinition[]) ArrayUtil.append( IMacroDefinition.class, builtins, ++builtinsPos, def ); } } @@ -1667,17 +1665,15 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { else if (cc instanceof _MacroExpansion && r.hasAncestor(cc)) ++currentCount; else { - result = (_WeightedContext[]) ArrayUtil.append( - _WeightedContext.class, result, new _WeightedContext( - cc, currentCount)); + result = (_WeightedContext[]) ArrayUtil.append(_WeightedContext.class, result, + new _WeightedContext(cc, currentCount)); cc = r; currentCount = 1; } } - result = (_WeightedContext[]) ArrayUtil.append(_WeightedContext.class, - result, new _WeightedContext(cc, currentCount)); - return (_WeightedContext[]) ArrayUtil.removeNulls( - _WeightedContext.class, result); + result = (_WeightedContext[]) ArrayUtil.append(_WeightedContext.class, result, + new _WeightedContext(cc, currentCount)); + return (_WeightedContext[]) ArrayUtil.trim(_WeightedContext.class, result); } 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 ); } } - return (_Context[]) ArrayUtil.removeNulls( _Context.class, results ); + return (_Context[]) ArrayUtil.trim( _Context.class, results ); } public IASTName[] getDeclarations(IMacroBinding binding) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java index 707210b8903..6615c1bd87b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.List; 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.ICPPField; 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.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList; @@ -118,8 +118,8 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType, List list = new ArrayList(); for (PDOMCPPBase base = getFirstBase(); base != null; base = base.getNextBase()) list.add(base); + Collections.reverse(list); ICPPBase[] bases = (ICPPBase[])list.toArray(new ICPPBase[list.size()]); - ArrayUtil.reverse(bases); return bases; } catch (CoreException e) { CCorePlugin.log(e);