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

View file

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

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
* 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;
}
}

View file

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

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

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

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

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
* 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)

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

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

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

View file

@ -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) {

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

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

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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) {

View file

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

View file

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

View file

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

View file

@ -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];

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
* 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() );

View file

@ -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) {

View file

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

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

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

View file

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

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

View file

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

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

View file

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

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
* 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

View file

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

View file

@ -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() {

View file

@ -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++ ){

View file

@ -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() {

View file

@ -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];

View file

@ -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() {

View file

@ -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() {

View file

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

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

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

View file

@ -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) {

View file

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