mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
All methods of ArrayUtil are now type-safe.
This commit is contained in:
parent
28699d05bb
commit
1e014bba19
32 changed files with 206 additions and 153 deletions
|
@ -30,9 +30,9 @@ public class ArrayUtilsTest extends TestCase {
|
||||||
assertEquals(o2, array[1]);
|
assertEquals(o2, array[1]);
|
||||||
assertEquals(o3, array[2]);
|
assertEquals(o3, array[2]);
|
||||||
|
|
||||||
array= ArrayUtil.append(Object.class, null, 0, o1);
|
array= ArrayUtil.appendAt(Object.class, null, 0, o1);
|
||||||
array= ArrayUtil.append(Object.class, array, 1, o2);
|
array= ArrayUtil.appendAt(Object.class, array, 1, o2);
|
||||||
array= ArrayUtil.append(Object.class, array, 2, o3);
|
array= ArrayUtil.appendAt(Object.class, array, 2, o3);
|
||||||
assertEquals(o1, array[0]);
|
assertEquals(o1, array[0]);
|
||||||
assertEquals(o2, array[1]);
|
assertEquals(o2, array[1]);
|
||||||
assertEquals(o3, array[2]);
|
assertEquals(o3, array[2]);
|
||||||
|
|
|
@ -14,4 +14,42 @@
|
||||||
</message_arguments>
|
</message_arguments>
|
||||||
</filter>
|
</filter>
|
||||||
</resource>
|
</resource>
|
||||||
|
<resource path="parser/org/eclipse/cdt/core/parser/util/ArrayUtil.java" type="org.eclipse.cdt.core.parser.util.ArrayUtil">
|
||||||
|
<filter id="420679712">
|
||||||
|
<message_arguments>
|
||||||
|
<message_argument value="org.eclipse.cdt.core.parser.util.ArrayUtil.addAll(Class<?>, Object[], Object[])"/>
|
||||||
|
<message_argument value="T"/>
|
||||||
|
</message_arguments>
|
||||||
|
</filter>
|
||||||
|
<filter id="420679712">
|
||||||
|
<message_arguments>
|
||||||
|
<message_argument value="org.eclipse.cdt.core.parser.util.ArrayUtil.append(Class<?>, Object[], Object)"/>
|
||||||
|
<message_argument value="T"/>
|
||||||
|
</message_arguments>
|
||||||
|
</filter>
|
||||||
|
<filter id="420679712">
|
||||||
|
<message_arguments>
|
||||||
|
<message_argument value="org.eclipse.cdt.core.parser.util.ArrayUtil.prepend(Class<?>, Object[], Object)"/>
|
||||||
|
<message_argument value="T"/>
|
||||||
|
</message_arguments>
|
||||||
|
</filter>
|
||||||
|
<filter id="420679712">
|
||||||
|
<message_arguments>
|
||||||
|
<message_argument value="org.eclipse.cdt.core.parser.util.ArrayUtil.removeNulls(Class<?>, Object[])"/>
|
||||||
|
<message_argument value="T"/>
|
||||||
|
</message_arguments>
|
||||||
|
</filter>
|
||||||
|
<filter id="420679712">
|
||||||
|
<message_arguments>
|
||||||
|
<message_argument value="org.eclipse.cdt.core.parser.util.ArrayUtil.trim(Class<?>, Object[])"/>
|
||||||
|
<message_argument value="T"/>
|
||||||
|
</message_arguments>
|
||||||
|
</filter>
|
||||||
|
<filter id="420679712">
|
||||||
|
<message_arguments>
|
||||||
|
<message_argument value="org.eclipse.cdt.core.parser.util.ArrayUtil.trim(Class<?>, Object[], boolean)"/>
|
||||||
|
<message_argument value="T"/>
|
||||||
|
</message_arguments>
|
||||||
|
</filter>
|
||||||
|
</resource>
|
||||||
</component>
|
</component>
|
||||||
|
|
|
@ -16,6 +16,8 @@ package org.eclipse.cdt.core.parser.util;
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @noextend This class is not intended to be subclassed by clients.
|
* @noextend This class is not intended to be subclassed by clients.
|
||||||
*/
|
*/
|
||||||
|
@ -28,11 +30,12 @@ public abstract class ArrayUtil {
|
||||||
* If the array is null or not large enough, a larger one is allocated, using
|
* If the array is null or not large enough, a larger one is allocated, using
|
||||||
* the given class object.
|
* the given class object.
|
||||||
*/
|
*/
|
||||||
static public Object[] append(Class<?> c, Object[] array, Object obj) {
|
@SuppressWarnings("unchecked")
|
||||||
|
static public <T> T[] append(Class<? extends T> c, T[] array, T obj) {
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
return array;
|
return array;
|
||||||
if (array == null || array.length == 0) {
|
if (array == null || array.length == 0) {
|
||||||
array = (Object[]) Array.newInstance(c, DEFAULT_LENGTH);
|
array = (T[]) Array.newInstance(c, DEFAULT_LENGTH);
|
||||||
array[0] = obj;
|
array[0] = obj;
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
@ -43,7 +46,7 @@ public abstract class ArrayUtil {
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object[] temp = (Object[]) Array.newInstance(c, Math.max(array.length * 2, DEFAULT_LENGTH));
|
T[] temp = (T[]) Array.newInstance(c, Math.max(array.length * 2, DEFAULT_LENGTH));
|
||||||
System.arraycopy(array, 0, temp, 0, array.length);
|
System.arraycopy(array, 0, temp, 0, array.length);
|
||||||
temp[array.length] = obj;
|
temp[array.length] = obj;
|
||||||
return temp;
|
return temp;
|
||||||
|
@ -69,38 +72,12 @@ public abstract class ArrayUtil {
|
||||||
return haveNull ? right + 1 : -1;
|
return haveNull ? right + 1 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Assumes that array contains nulls at the end, only.
|
|
||||||
* Appends object using the current length of the array.
|
|
||||||
* @since 4.0
|
|
||||||
*/
|
|
||||||
static public Object[] append(Class<?> c, Object[] array, int currentLength, Object obj) {
|
|
||||||
if (obj == null)
|
|
||||||
return array;
|
|
||||||
if (array == null || array.length == 0) {
|
|
||||||
array = (Object[]) Array.newInstance(c, DEFAULT_LENGTH);
|
|
||||||
array[0] = obj;
|
|
||||||
return array;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assumes that array contains nulls at the end, only.
|
* Assumes that array contains nulls at the end, only.
|
||||||
* Appends element after the last non-null element.
|
* Appends element after the last non-null element.
|
||||||
* If the array is not large enough, a larger one is allocated.
|
* If the array is not large enough, a larger one is allocated.
|
||||||
* Null <code>array</code> is supported for backward compatibility only and only when T is Object.
|
* Null <code>array</code> is supported for backward compatibility only and only when T is
|
||||||
|
* Object.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
static public <T> T[] append(T[] array, T obj) {
|
static public <T> T[] append(T[] array, T obj) {
|
||||||
|
@ -127,12 +104,41 @@ public abstract class ArrayUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type safe version of {@link #append(Class, Object[], int, Object)}
|
* @deprecated Use {@link #appendAt(Class, Object[], int, Object)} instead.
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
static public Object[] append(Class<?> c, Object[] array, int currentLength, Object obj) {
|
||||||
|
return appendAt((Class<Object>) c, array, currentLength, obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assumes that array contains nulls at the end, only.
|
||||||
|
* Appends object using the current length of the array.
|
||||||
* @since 5.1
|
* @since 5.1
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
static public <T> T[] appendAt(Class<T> c, T[] array, int currentLength, T obj) {
|
static public <T> T[] appendAt(Class<T> c, T[] array, int currentLength, T obj) {
|
||||||
return (T[]) append(c, array, currentLength, obj);
|
if (obj == null)
|
||||||
|
return array;
|
||||||
|
if (array == null || array.length == 0) {
|
||||||
|
array = (T[]) Array.newInstance(c, DEFAULT_LENGTH);
|
||||||
|
array[0] = obj;
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentLength < array.length) {
|
||||||
|
Assert.isTrue(array[currentLength] == null);
|
||||||
|
Assert.isTrue(currentLength == 0 || array[currentLength - 1] != null);
|
||||||
|
array[currentLength]= obj;
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
T[] temp = (T[]) Array.newInstance(c, array.length * 2);
|
||||||
|
System.arraycopy(array, 0, temp, 0, array.length);
|
||||||
|
temp[array.length] = obj;
|
||||||
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,9 +153,10 @@ public abstract class ArrayUtil {
|
||||||
* @param array the array to be trimmed
|
* @param array the array to be trimmed
|
||||||
* @param forceNew
|
* @param forceNew
|
||||||
*/
|
*/
|
||||||
static public Object[] trim(Class<?> c, Object[] array, boolean forceNew) {
|
@SuppressWarnings("unchecked")
|
||||||
|
static public <T> T[] trim(Class<? extends T> c, T[] array, boolean forceNew) {
|
||||||
if (array == null)
|
if (array == null)
|
||||||
return (Object[]) Array.newInstance(c, 0);
|
return (T[]) Array.newInstance(c, 0);
|
||||||
|
|
||||||
int i = array.length;
|
int i = array.length;
|
||||||
if (i == 0 || array[i - 1] != null) {
|
if (i == 0 || array[i - 1] != null) {
|
||||||
|
@ -158,15 +165,15 @@ public abstract class ArrayUtil {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
i= findFirstNull(array);
|
i= findFirstNull(array);
|
||||||
assert i >= 0;
|
Assert.isTrue(i >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object[] temp = (Object[]) Array.newInstance(c, i);
|
T[] temp = (T[]) Array.newInstance(c, i);
|
||||||
System.arraycopy(array, 0, temp, 0, i);
|
System.arraycopy(array, 0, temp, 0, i);
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object[] trim(Class<?> c, Object[] array) {
|
public static <T> T[] trim(Class<? extends T> c, T[] array) {
|
||||||
return trim(c, array, false);
|
return trim(c, array, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +197,7 @@ public abstract class ArrayUtil {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
i= findFirstNull(array);
|
i= findFirstNull(array);
|
||||||
assert i >= 0;
|
Assert.isTrue(i >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
T[] temp = (T[]) Array.newInstance(array.getClass().getComponentType(), i);
|
T[] temp = (T[]) Array.newInstance(array.getClass().getComponentType(), i);
|
||||||
|
@ -219,7 +226,8 @@ public abstract class ArrayUtil {
|
||||||
* @param source The source array. May not be <code>null</code>.
|
* @param source The source array. May not be <code>null</code>.
|
||||||
* @return The concatenated array, which may be the same as the first parameter.
|
* @return The concatenated array, which may be the same as the first parameter.
|
||||||
*/
|
*/
|
||||||
public static Object[] addAll(Class<?> c, Object[] dest, Object[] source) {
|
@SuppressWarnings("unchecked")
|
||||||
|
public static <T> T[] addAll(Class<? extends T> c, T[] dest, T[] source) {
|
||||||
if (source == null || source.length == 0)
|
if (source == null || source.length == 0)
|
||||||
return dest;
|
return dest;
|
||||||
|
|
||||||
|
@ -232,7 +240,7 @@ public abstract class ArrayUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dest == null || dest.length == 0) {
|
if (dest == null || dest.length == 0) {
|
||||||
dest = (Object[]) Array.newInstance(c, numToAdd);
|
dest = (T[]) Array.newInstance(c, numToAdd);
|
||||||
System.arraycopy(source, 0, dest, 0, numToAdd);
|
System.arraycopy(source, 0, dest, 0, numToAdd);
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
@ -246,7 +254,7 @@ public abstract class ArrayUtil {
|
||||||
System.arraycopy(source, 0, dest, firstFree, numToAdd);
|
System.arraycopy(source, 0, dest, firstFree, numToAdd);
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
Object[] temp = (Object[]) Array.newInstance(c, firstFree + numToAdd);
|
T[] temp = (T[]) Array.newInstance(c, firstFree + numToAdd);
|
||||||
System.arraycopy(dest, 0, temp, 0, firstFree);
|
System.arraycopy(dest, 0, temp, 0, firstFree);
|
||||||
System.arraycopy(source, 0, temp, firstFree, numToAdd);
|
System.arraycopy(source, 0, temp, firstFree, numToAdd);
|
||||||
return temp;
|
return temp;
|
||||||
|
@ -302,21 +310,22 @@ public abstract class ArrayUtil {
|
||||||
* object identity.
|
* object identity.
|
||||||
* @param array the array to search
|
* @param array the array to search
|
||||||
* @param obj the object to search for
|
* @param obj the object to search for
|
||||||
* @return true if the specified array contains the specified object, or the specified array is null
|
* @return <code>true</code> if the specified array contains the specified object, or
|
||||||
|
* the specified array is <code>null</code>
|
||||||
*/
|
*/
|
||||||
public static boolean contains(Object[] array, Object obj) {
|
public static <T> boolean contains(T[] array, T obj) {
|
||||||
return indexOf(array, obj) >= 0;
|
return indexOf(array, obj) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the index into the specified array of the specified object, or -1 if the array does not
|
* Returns the index into the specified array of the specified object, or -1 if the array does
|
||||||
* contain the object, or if the array is null. Comparison is by object identity.
|
* not contain the object, or if the array is null. Comparison is by object identity.
|
||||||
* @param array the array to search
|
* @param array the array to search
|
||||||
* @param obj the object to search for
|
* @param obj the object to search for
|
||||||
* @return the index into the specified array of the specified object, or -1 if the array does not
|
* @return the index into the specified array of the specified object, or -1 if the array does
|
||||||
* contain the object, or if the array is null
|
* not contain the object, or if the array is <code>null</code>
|
||||||
*/
|
*/
|
||||||
public static int indexOf(Object[] array, Object obj) {
|
public static <T> int indexOf(T[] array, T obj) {
|
||||||
int result = -1;
|
int result = -1;
|
||||||
if (array != null) {
|
if (array != null) {
|
||||||
for (int i = 0; i < array.length; i++) {
|
for (int i = 0; i < array.length; i++) {
|
||||||
|
@ -333,22 +342,23 @@ public abstract class ArrayUtil {
|
||||||
* object identity.
|
* object identity.
|
||||||
* @param array the array to search
|
* @param array the array to search
|
||||||
* @param obj the object to search for
|
* @param obj the object to search for
|
||||||
* @return true if the specified array contains the specified object, or the specified array is null
|
* @return true if the specified array contains the specified object, or the specified array is
|
||||||
|
* <code>null</code>
|
||||||
*/
|
*/
|
||||||
public static boolean containsEqual(Object[] array, Object obj) {
|
public static <T> boolean containsEqual(T[] array, T obj) {
|
||||||
return indexOfEqual(array, obj) != -1;
|
return indexOfEqual(array, obj) != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assumes that array contains nulls at the end, only.
|
* Assumes that array contains nulls at the end, only.
|
||||||
* Returns the index into the specified array of the specified object, or -1 if the array does not
|
* Returns the index into the specified array of the specified object, or -1 if the array does
|
||||||
* contain the object, or if the array is null. Comparison is by equals().
|
* not contain the object, or if the array is null. Comparison is by equals().
|
||||||
* @param comments the array to search
|
* @param comments the array to search
|
||||||
* @param comment the object to search for
|
* @param comment the object to search for
|
||||||
* @return the index into the specified array of the specified object, or -1 if the array does not
|
* @return the index into the specified array of the specified object, or -1 if the array does
|
||||||
* contain an equal object, or if the array is null
|
* not contain an equal object, or if the array is <code>null</code>
|
||||||
*/
|
*/
|
||||||
public static int indexOfEqual(Object[] comments, Object comment) {
|
public static <T> int indexOfEqual(T[] comments, T comment) {
|
||||||
int result = -1;
|
int result = -1;
|
||||||
if (comments != null) {
|
if (comments != null) {
|
||||||
for (int i= 0; (i < comments.length) && (comments[i] != null); i++) {
|
for (int i= 0; (i < comments.length) && (comments[i] != null); i++) {
|
||||||
|
@ -368,9 +378,10 @@ public abstract class ArrayUtil {
|
||||||
*
|
*
|
||||||
* If there are no nulls in the original array then the original array is returned.
|
* If there are no nulls in the original array then the original array is returned.
|
||||||
*/
|
*/
|
||||||
public static Object[] removeNulls(Class<?> c, Object[] array) {
|
@SuppressWarnings("unchecked")
|
||||||
|
public static <T> T[] removeNulls(Class<? extends T> c, T[] array) {
|
||||||
if (array == null)
|
if (array == null)
|
||||||
return (Object[]) Array.newInstance(c, 0);
|
return (T[]) Array.newInstance(c, 0);
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
int validEntries = 0;
|
int validEntries = 0;
|
||||||
|
@ -382,7 +393,7 @@ public abstract class ArrayUtil {
|
||||||
if (array.length == validEntries)
|
if (array.length == validEntries)
|
||||||
return array;
|
return array;
|
||||||
|
|
||||||
Object[] newArray = (Object[]) Array.newInstance(c, validEntries);
|
T[] newArray = (T[]) Array.newInstance(c, validEntries);
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for (i = 0; i < array.length; i++) {
|
for (i = 0; i < array.length; i++) {
|
||||||
if (array[i] != null)
|
if (array[i] != null)
|
||||||
|
@ -404,9 +415,8 @@ public abstract class ArrayUtil {
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T> T[] removeNulls(T[] array) {
|
public static <T> T[] removeNulls(T[] array) {
|
||||||
int i;
|
|
||||||
int validEntries = 0;
|
int validEntries = 0;
|
||||||
for (i = 0; i < array.length; i++) {
|
for (int i = 0; i < array.length; i++) {
|
||||||
if (array[i] != null)
|
if (array[i] != null)
|
||||||
validEntries++;
|
validEntries++;
|
||||||
}
|
}
|
||||||
|
@ -416,7 +426,7 @@ public abstract class ArrayUtil {
|
||||||
|
|
||||||
T[] newArray = (T[]) Array.newInstance(array.getClass().getComponentType(), validEntries);
|
T[] newArray = (T[]) Array.newInstance(array.getClass().getComponentType(), validEntries);
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for (i = 0; i < array.length; i++) {
|
for (int i = 0; i < array.length; i++) {
|
||||||
if (array[i] != null)
|
if (array[i] != null)
|
||||||
newArray[j++] = array[i];
|
newArray[j++] = array[i];
|
||||||
}
|
}
|
||||||
|
@ -425,40 +435,45 @@ public abstract class ArrayUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To improve performance, this method should be used instead of ArrayUtil#removeNulls(Class, Object[]) when
|
* @deprecated Use {@link #trimAt(Class, Object[], int)} instead
|
||||||
* all of the non-null elements in the array are grouped together at the beginning of the array
|
|
||||||
* and all of the nulls are at the end of the array.
|
|
||||||
* The position of the last non-null element in the array must also be known.
|
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Deprecated
|
||||||
public static Object[] removeNullsAfter(Class<?> c, Object[] array, int index) {
|
public static Object[] removeNullsAfter(Class<?> c, Object[] array, int index) {
|
||||||
|
return trimAt((Class<Object>) c, array, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To improve performance, this method should be used instead of
|
||||||
|
* {@link #removeNulls(Class, Object[])} when all of the non-<code>null</code> elements in
|
||||||
|
* the array are grouped together at the beginning of the array and all of the nulls are at
|
||||||
|
* the end of the array. The position of the last non-null element in the array must also
|
||||||
|
* be known.
|
||||||
|
*
|
||||||
|
* @since 5.1
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static <T> T[] trimAt(Class<T> c, T[] array, int index) {
|
||||||
final int newLen= index + 1;
|
final int newLen= index + 1;
|
||||||
if (array != null && array.length == newLen)
|
if (array != null && array.length == newLen)
|
||||||
return array;
|
return array;
|
||||||
|
|
||||||
Object[] newArray = (Object[]) Array.newInstance(c, newLen);
|
T[] newArray = (T[]) Array.newInstance(c, newLen);
|
||||||
if (array != null && newLen > 0)
|
if (array != null && newLen > 0)
|
||||||
System.arraycopy(array, 0, newArray, 0, newLen);
|
System.arraycopy(array, 0, newArray, 0, newLen);
|
||||||
return newArray;
|
return newArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Type safe version of {@link #removeNullsAfter(Class, Object[], int)}
|
|
||||||
* @since 5.1
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static <T> T[] trimAt(Class<T> c, T[] array, int index) {
|
|
||||||
return (T[]) removeNullsAfter(c, array, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts the obj at the beginning of the array, shifting the whole thing one index
|
* Inserts the obj at the beginning of the array, shifting the whole thing one index
|
||||||
* Assumes that array contains nulls at the end, only.
|
* Assumes that array contains nulls at the end, only.
|
||||||
*/
|
*/
|
||||||
public static Object[] prepend(Class<?> c, Object[] array, Object obj) {
|
@SuppressWarnings("unchecked")
|
||||||
|
public static <T> T[] prepend(Class<? extends T> c, T[] array, T obj) {
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
return array;
|
return array;
|
||||||
if (array == null || array.length == 0) {
|
if (array == null || array.length == 0) {
|
||||||
array = (Object[]) Array.newInstance(c, DEFAULT_LENGTH);
|
array = (T[]) Array.newInstance(c, DEFAULT_LENGTH);
|
||||||
array[0] = obj;
|
array[0] = obj;
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
@ -468,7 +483,7 @@ public abstract class ArrayUtil {
|
||||||
System.arraycopy(array, 0, array, 1, i);
|
System.arraycopy(array, 0, array, 1, i);
|
||||||
array[0] = obj;
|
array[0] = obj;
|
||||||
} else {
|
} else {
|
||||||
Object[] temp = (Object[]) Array.newInstance(c, array.length * 2);
|
T[] temp = (T[]) Array.newInstance(c, array.length * 2);
|
||||||
System.arraycopy(array, 0, temp, 1, array.length);
|
System.arraycopy(array, 0, temp, 1, array.length);
|
||||||
temp[0] = obj;
|
temp[0] = obj;
|
||||||
array = temp;
|
array = temp;
|
||||||
|
@ -484,7 +499,7 @@ public abstract class ArrayUtil {
|
||||||
* @since 5.2
|
* @since 5.2
|
||||||
*/
|
*/
|
||||||
public static <T> T[] prepend(T[] array, T obj) {
|
public static <T> T[] prepend(T[] array, T obj) {
|
||||||
assert array != null;
|
Assert.isNotNull(array);
|
||||||
|
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
return array;
|
return array;
|
||||||
|
@ -517,7 +532,7 @@ public abstract class ArrayUtil {
|
||||||
* Removes first occurrence of element in array and moves objects behind up front.
|
* Removes first occurrence of element in array and moves objects behind up front.
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
public static void remove(Object[] array, Object element) {
|
public static <T> void remove(T[] array, T element) {
|
||||||
if (array != null) {
|
if (array != null) {
|
||||||
for (int i = 0; i < array.length; i++) {
|
for (int i = 0; i < array.length; i++) {
|
||||||
if (element == array[i]) {
|
if (element == array[i]) {
|
||||||
|
|
|
@ -45,7 +45,7 @@ public abstract class ASTAmbiguousNode extends ASTNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTName[] getNames() {
|
public IASTName[] getNames() {
|
||||||
names = (IASTName[]) ArrayUtil.removeNullsAfter(IASTName.class, names, namesPos);
|
names = (IASTName[]) ArrayUtil.trimAt(IASTName.class, names, namesPos);
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,7 +137,7 @@ public class ASTQueries {
|
||||||
active[j++]= d;
|
active[j++]= d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
active= (IASTDeclaration[]) ArrayUtil.removeNullsAfter(IASTDeclaration.class, active, j-1);
|
active= (IASTDeclaration[]) ArrayUtil.trimAt(IASTDeclaration.class, active, j-1);
|
||||||
}
|
}
|
||||||
return active;
|
return active;
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
|
||||||
if (d != null) {
|
if (d != null) {
|
||||||
d.setParent(this);
|
d.setParent(this);
|
||||||
d.setPropertyInParent(OWNED_DECLARATION);
|
d.setPropertyInParent(OWNED_DECLARATION);
|
||||||
fAllDeclarations = (IASTDeclaration[]) ArrayUtil.append(IASTDeclaration.class,
|
fAllDeclarations = (IASTDeclaration[]) ArrayUtil.appendAt(IASTDeclaration.class,
|
||||||
fAllDeclarations, ++fLastDeclaration, d);
|
fAllDeclarations, ++fLastDeclaration, d);
|
||||||
fActiveDeclarations= null;
|
fActiveDeclarations= null;
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
|
||||||
@Override
|
@Override
|
||||||
public final IASTDeclaration[] getDeclarations(boolean includeInactive) {
|
public final IASTDeclaration[] getDeclarations(boolean includeInactive) {
|
||||||
if (includeInactive) {
|
if (includeInactive) {
|
||||||
fAllDeclarations= (IASTDeclaration[]) ArrayUtil.removeNullsAfter(IASTDeclaration.class,
|
fAllDeclarations= (IASTDeclaration[]) ArrayUtil.trimAt(IASTDeclaration.class,
|
||||||
fAllDeclarations, fLastDeclaration);
|
fAllDeclarations, fLastDeclaration);
|
||||||
return fAllDeclarations;
|
return fAllDeclarations;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,14 +54,14 @@ public class CASTAmbiguousDeclarator extends ASTAmbiguousNode implements IASTAmb
|
||||||
public void addDeclarator(IASTDeclarator d) {
|
public void addDeclarator(IASTDeclarator d) {
|
||||||
assertNotFrozen();
|
assertNotFrozen();
|
||||||
if (d != null) {
|
if (d != null) {
|
||||||
dtors = (IASTDeclarator[]) ArrayUtil.append(IASTDeclarator.class, dtors, ++dtorPos, d);
|
dtors = (IASTDeclarator[]) ArrayUtil.appendAt(IASTDeclarator.class, dtors, ++dtorPos, d);
|
||||||
d.setParent(this);
|
d.setParent(this);
|
||||||
d.setPropertyInParent(SUBDECLARATOR);
|
d.setPropertyInParent(SUBDECLARATOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTDeclarator[] getDeclarators() {
|
public IASTDeclarator[] getDeclarators() {
|
||||||
dtors = (IASTDeclarator[]) ArrayUtil.removeNullsAfter(IASTDeclarator.class, dtors, dtorPos );
|
dtors = (IASTDeclarator[]) ArrayUtil.trimAt(IASTDeclarator.class, dtors, dtorPos );
|
||||||
return dtors;
|
return dtors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,14 +31,14 @@ public class CASTAmbiguousExpression extends ASTAmbiguousNode implements IASTAmb
|
||||||
public void addExpression(IASTExpression e) {
|
public void addExpression(IASTExpression e) {
|
||||||
assertNotFrozen();
|
assertNotFrozen();
|
||||||
if (e != null) {
|
if (e != null) {
|
||||||
expressions = (IASTExpression[]) ArrayUtil.append( IASTExpression.class, expressions, ++expressionsPos, e );
|
expressions = (IASTExpression[]) ArrayUtil.appendAt( IASTExpression.class, expressions, ++expressionsPos, e );
|
||||||
e.setParent(this);
|
e.setParent(this);
|
||||||
e.setPropertyInParent(SUBEXPRESSION);
|
e.setPropertyInParent(SUBEXPRESSION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTExpression[] getExpressions() {
|
public IASTExpression[] getExpressions() {
|
||||||
expressions = (IASTExpression[]) ArrayUtil.removeNullsAfter( IASTExpression.class, expressions, expressionsPos );
|
expressions = (IASTExpression[]) ArrayUtil.trimAt( IASTExpression.class, expressions, expressionsPos );
|
||||||
return expressions;
|
return expressions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class CASTAmbiguousParameterDeclaration extends ASTAmbiguousNode implemen
|
||||||
public void addParameterDeclaration(IASTParameterDeclaration d) {
|
public void addParameterDeclaration(IASTParameterDeclaration d) {
|
||||||
assertNotFrozen();
|
assertNotFrozen();
|
||||||
if (d != null) {
|
if (d != null) {
|
||||||
paramDecls = (IASTParameterDeclaration[]) ArrayUtil.append(IASTParameterDeclaration.class, paramDecls, ++declPos, d);
|
paramDecls = (IASTParameterDeclaration[]) ArrayUtil.appendAt(IASTParameterDeclaration.class, paramDecls, ++declPos, d);
|
||||||
d.setParent(this);
|
d.setParent(this);
|
||||||
d.setPropertyInParent(SUBDECLARATION);
|
d.setPropertyInParent(SUBDECLARATION);
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ public class CASTAmbiguousParameterDeclaration extends ASTAmbiguousNode implemen
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTParameterDeclaration[] getParameterDeclarations() {
|
public IASTParameterDeclaration[] getParameterDeclarations() {
|
||||||
paramDecls = (IASTParameterDeclaration[]) ArrayUtil.removeNullsAfter(IASTParameterDeclaration.class, paramDecls, declPos );
|
paramDecls = (IASTParameterDeclaration[]) ArrayUtil.trimAt(IASTParameterDeclaration.class, paramDecls, declPos );
|
||||||
return paramDecls;
|
return paramDecls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ public class CASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAmbi
|
||||||
public void addStatement(IASTStatement s) {
|
public void addStatement(IASTStatement s) {
|
||||||
assertNotFrozen();
|
assertNotFrozen();
|
||||||
if (s != null) {
|
if (s != null) {
|
||||||
stmts = (IASTStatement[]) ArrayUtil.append( IASTStatement.class, stmts, ++stmtsPos, s );
|
stmts = (IASTStatement[]) ArrayUtil.appendAt( IASTStatement.class, stmts, ++stmtsPos, s );
|
||||||
s.setParent(this);
|
s.setParent(this);
|
||||||
s.setPropertyInParent(STATEMENT);
|
s.setPropertyInParent(STATEMENT);
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ public class CASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAmbi
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IASTStatement[] getStatements() {
|
public IASTStatement[] getStatements() {
|
||||||
stmts = (IASTStatement[]) ArrayUtil.removeNullsAfter( IASTStatement.class, stmts, stmtsPos );
|
stmts = (IASTStatement[]) ArrayUtil.trimAt( IASTStatement.class, stmts, stmtsPos );
|
||||||
return stmts;
|
return stmts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class CASTArrayDeclarator extends CASTDeclarator implements IASTArrayDecl
|
||||||
public IASTArrayModifier[] getArrayModifiers() {
|
public IASTArrayModifier[] getArrayModifiers() {
|
||||||
if (arrayMods == null)
|
if (arrayMods == null)
|
||||||
return IASTArrayModifier.EMPTY_ARRAY;
|
return IASTArrayModifier.EMPTY_ARRAY;
|
||||||
arrayMods = (IASTArrayModifier[]) ArrayUtil.removeNullsAfter(IASTArrayModifier.class,
|
arrayMods = (IASTArrayModifier[]) ArrayUtil.trimAt(IASTArrayModifier.class,
|
||||||
arrayMods, arrayModsPos);
|
arrayMods, arrayModsPos);
|
||||||
return arrayMods;
|
return arrayMods;
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ public class CASTArrayDeclarator extends CASTDeclarator implements IASTArrayDecl
|
||||||
if (arrayModifier != null) {
|
if (arrayModifier != null) {
|
||||||
arrayModifier.setParent(this);
|
arrayModifier.setParent(this);
|
||||||
arrayModifier.setPropertyInParent(ARRAY_MODIFIER);
|
arrayModifier.setPropertyInParent(ARRAY_MODIFIER);
|
||||||
arrayMods = (IASTArrayModifier[]) ArrayUtil.append(IASTArrayModifier.class, arrayMods,
|
arrayMods = (IASTArrayModifier[]) ArrayUtil.appendAt(IASTArrayModifier.class, arrayMods,
|
||||||
++arrayModsPos, arrayModifier);
|
++arrayModsPos, arrayModifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class CASTDeclarator extends ASTNode implements IASTDeclarator, IASTAmbig
|
||||||
|
|
||||||
public IASTPointerOperator[] getPointerOperators() {
|
public IASTPointerOperator[] getPointerOperators() {
|
||||||
if (pointerOps == null) return IASTPointerOperator.EMPTY_ARRAY;
|
if (pointerOps == null) return IASTPointerOperator.EMPTY_ARRAY;
|
||||||
pointerOps = (IASTPointerOperator[]) ArrayUtil.removeNullsAfter(IASTPointerOperator.class, pointerOps, pointerOpsPos);
|
pointerOps = (IASTPointerOperator[]) ArrayUtil.trimAt(IASTPointerOperator.class, pointerOps, pointerOpsPos);
|
||||||
return pointerOps;
|
return pointerOps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ public class CASTDeclarator extends ASTNode implements IASTDeclarator, IASTAmbig
|
||||||
if (operator != null) {
|
if (operator != null) {
|
||||||
operator.setParent(this);
|
operator.setParent(this);
|
||||||
operator.setPropertyInParent(POINTER_OPERATOR);
|
operator.setPropertyInParent(POINTER_OPERATOR);
|
||||||
pointerOps = (IASTPointerOperator[]) ArrayUtil.append(IASTPointerOperator.class, pointerOps, ++pointerOpsPos, operator);
|
pointerOps = (IASTPointerOperator[]) ArrayUtil.appendAt(IASTPointerOperator.class, pointerOps, ++pointerOpsPos, operator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,14 +61,14 @@ public class CASTDesignatedInitializer extends ASTNode implements ICASTDesignate
|
||||||
if (designator != null) {
|
if (designator != null) {
|
||||||
designator.setParent(this);
|
designator.setParent(this);
|
||||||
designator.setPropertyInParent(DESIGNATOR);
|
designator.setPropertyInParent(DESIGNATOR);
|
||||||
designators = (ICASTDesignator[]) ArrayUtil.append( ICASTDesignator.class, designators, ++designatorsPos, designator );
|
designators = (ICASTDesignator[]) ArrayUtil.appendAt( ICASTDesignator.class, designators, ++designatorsPos, designator );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ICASTDesignator[] getDesignators() {
|
public ICASTDesignator[] getDesignators() {
|
||||||
if( designators == null ) return ICASTDesignatedInitializer.EMPTY_DESIGNATOR_ARRAY;
|
if( designators == null ) return ICASTDesignatedInitializer.EMPTY_DESIGNATOR_ARRAY;
|
||||||
designators = (ICASTDesignator[]) ArrayUtil.removeNullsAfter( ICASTDesignator.class, designators, designatorsPos );
|
designators = (ICASTDesignator[]) ArrayUtil.trimAt( ICASTDesignator.class, designators, designatorsPos );
|
||||||
return designators;
|
return designators;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,14 +69,14 @@ public class CASTEnumerationSpecifier extends CASTBaseDeclSpecifier
|
||||||
if (enumerator != null) {
|
if (enumerator != null) {
|
||||||
enumerator.setParent(this);
|
enumerator.setParent(this);
|
||||||
enumerator.setPropertyInParent(ENUMERATOR);
|
enumerator.setPropertyInParent(ENUMERATOR);
|
||||||
enumerators = (IASTEnumerator[]) ArrayUtil.append( IASTEnumerator.class, enumerators, ++enumeratorsPos, enumerator );
|
enumerators = (IASTEnumerator[]) ArrayUtil.appendAt( IASTEnumerator.class, enumerators, ++enumeratorsPos, enumerator );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IASTEnumerator[] getEnumerators() {
|
public IASTEnumerator[] getEnumerators() {
|
||||||
if( enumerators == null ) return IASTEnumerator.EMPTY_ENUMERATOR_ARRAY;
|
if( enumerators == null ) return IASTEnumerator.EMPTY_ENUMERATOR_ARRAY;
|
||||||
enumerators = (IASTEnumerator[]) ArrayUtil.removeNullsAfter( IASTEnumerator.class, enumerators, enumeratorsPos );
|
enumerators = (IASTEnumerator[]) ArrayUtil.trimAt( IASTEnumerator.class, enumerators, enumeratorsPos );
|
||||||
return enumerators;
|
return enumerators;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class CASTFunctionDeclarator extends CASTDeclarator implements IASTStanda
|
||||||
|
|
||||||
public IASTParameterDeclaration[] getParameters() {
|
public IASTParameterDeclaration[] getParameters() {
|
||||||
if( parameters == null ) return IASTParameterDeclaration.EMPTY_PARAMETERDECLARATION_ARRAY;
|
if( parameters == null ) return IASTParameterDeclaration.EMPTY_PARAMETERDECLARATION_ARRAY;
|
||||||
parameters = (IASTParameterDeclaration[]) ArrayUtil.removeNullsAfter( IASTParameterDeclaration.class, parameters, parametersPos );
|
parameters = (IASTParameterDeclaration[]) ArrayUtil.trimAt( IASTParameterDeclaration.class, parameters, parametersPos );
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ public class CASTFunctionDeclarator extends CASTDeclarator implements IASTStanda
|
||||||
if (parameter != null) {
|
if (parameter != null) {
|
||||||
parameter.setParent(this);
|
parameter.setParent(this);
|
||||||
parameter.setPropertyInParent(FUNCTION_PARAMETER);
|
parameter.setPropertyInParent(FUNCTION_PARAMETER);
|
||||||
parameters = (IASTParameterDeclaration[]) ArrayUtil.append( IASTParameterDeclaration.class, parameters, ++parametersPos, parameter );
|
parameters = (IASTParameterDeclaration[]) ArrayUtil.appendAt( IASTParameterDeclaration.class, parameters, ++parametersPos, parameter );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ public class CASTInitializerList extends ASTNode implements IASTInitializerList,
|
||||||
public void addClause(IASTInitializerClause d) {
|
public void addClause(IASTInitializerClause d) {
|
||||||
assertNotFrozen();
|
assertNotFrozen();
|
||||||
if (d != null) {
|
if (d != null) {
|
||||||
initializers = (IASTInitializerClause[]) ArrayUtil.append( IASTInitializerClause.class, initializers, ++initializersPos, d );
|
initializers = (IASTInitializerClause[]) ArrayUtil.appendAt( IASTInitializerClause.class, initializers, ++initializersPos, d );
|
||||||
d.setParent(this);
|
d.setParent(this);
|
||||||
d.setPropertyInParent(NESTED_INITIALIZER);
|
d.setPropertyInParent(NESTED_INITIALIZER);
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class CASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclarat
|
||||||
public IASTDeclarator[] getDeclarators() {
|
public IASTDeclarator[] getDeclarators() {
|
||||||
if (declarators == null)
|
if (declarators == null)
|
||||||
return IASTDeclarator.EMPTY_DECLARATOR_ARRAY;
|
return IASTDeclarator.EMPTY_DECLARATOR_ARRAY;
|
||||||
declarators = (IASTDeclarator[]) ArrayUtil.removeNullsAfter(IASTDeclarator.class, declarators, declaratorsPos);
|
declarators = (IASTDeclarator[]) ArrayUtil.trimAt(IASTDeclarator.class, declarators, declaratorsPos);
|
||||||
return declarators;
|
return declarators;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ public class CASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclarat
|
||||||
if (d != null) {
|
if (d != null) {
|
||||||
d.setParent(this);
|
d.setParent(this);
|
||||||
d.setPropertyInParent(DECLARATOR);
|
d.setPropertyInParent(DECLARATOR);
|
||||||
declarators = (IASTDeclarator[]) ArrayUtil.append(IASTDeclarator.class, declarators, ++declaratorsPos, d);
|
declarators = (IASTDeclarator[]) ArrayUtil.appendAt(IASTDeclarator.class, declarators, ++declaratorsPos, d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,14 +74,14 @@ public class CPPASTAmbiguousDeclarator extends ASTAmbiguousNode implements IASTA
|
||||||
public void addDeclarator(IASTDeclarator d) {
|
public void addDeclarator(IASTDeclarator d) {
|
||||||
assertNotFrozen();
|
assertNotFrozen();
|
||||||
if (d != null) {
|
if (d != null) {
|
||||||
dtors = (IASTDeclarator[]) ArrayUtil.append(IASTDeclarator.class, dtors, ++dtorPos, d);
|
dtors = (IASTDeclarator[]) ArrayUtil.appendAt(IASTDeclarator.class, dtors, ++dtorPos, d);
|
||||||
d.setParent(this);
|
d.setParent(this);
|
||||||
d.setPropertyInParent(SUBDECLARATOR);
|
d.setPropertyInParent(SUBDECLARATOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTDeclarator[] getDeclarators() {
|
public IASTDeclarator[] getDeclarators() {
|
||||||
dtors = (IASTDeclarator[]) ArrayUtil.removeNullsAfter(IASTDeclarator.class, dtors, dtorPos );
|
dtors = (IASTDeclarator[]) ArrayUtil.trimAt(IASTDeclarator.class, dtors, dtorPos );
|
||||||
return dtors;
|
return dtors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,14 +40,14 @@ public class CPPASTAmbiguousExpression extends ASTAmbiguousNode implements
|
||||||
public void addExpression(IASTExpression e) {
|
public void addExpression(IASTExpression e) {
|
||||||
assertNotFrozen();
|
assertNotFrozen();
|
||||||
if (e != null) {
|
if (e != null) {
|
||||||
exp = (IASTExpression[]) ArrayUtil.append( IASTExpression.class, exp, ++expPos, e );
|
exp = (IASTExpression[]) ArrayUtil.appendAt( IASTExpression.class, exp, ++expPos, e );
|
||||||
e.setParent(this);
|
e.setParent(this);
|
||||||
e.setPropertyInParent(SUBEXPRESSION);
|
e.setPropertyInParent(SUBEXPRESSION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTExpression[] getExpressions() {
|
public IASTExpression[] getExpressions() {
|
||||||
exp = (IASTExpression[]) ArrayUtil.removeNullsAfter( IASTExpression.class, exp, expPos );
|
exp = (IASTExpression[]) ArrayUtil.trimAt( IASTExpression.class, exp, expPos );
|
||||||
return exp;
|
return exp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class CPPASTAmbiguousStatement extends ASTAmbiguousNode implements
|
||||||
public void addStatement(IASTStatement s) {
|
public void addStatement(IASTStatement s) {
|
||||||
assertNotFrozen();
|
assertNotFrozen();
|
||||||
if (s != null) {
|
if (s != null) {
|
||||||
stmts = (IASTStatement[]) ArrayUtil.append( IASTStatement.class, stmts, ++stmtsPos, s );
|
stmts = (IASTStatement[]) ArrayUtil.appendAt( IASTStatement.class, stmts, ++stmtsPos, s );
|
||||||
s.setParent(this);
|
s.setParent(this);
|
||||||
s.setPropertyInParent(STATEMENT);
|
s.setPropertyInParent(STATEMENT);
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ public class CPPASTAmbiguousStatement extends ASTAmbiguousNode implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IASTStatement[] getStatements() {
|
public IASTStatement[] getStatements() {
|
||||||
stmts = (IASTStatement[]) ArrayUtil.removeNullsAfter( IASTStatement.class, stmts, stmtsPos );
|
stmts = (IASTStatement[]) ArrayUtil.trimAt( IASTStatement.class, stmts, stmtsPos );
|
||||||
return stmts;
|
return stmts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class CPPASTArrayDeclarator extends CPPASTDeclarator implements ICPPASTAr
|
||||||
public IASTArrayModifier[] getArrayModifiers() {
|
public IASTArrayModifier[] getArrayModifiers() {
|
||||||
if (arrayMods == null)
|
if (arrayMods == null)
|
||||||
return IASTArrayModifier.EMPTY_ARRAY;
|
return IASTArrayModifier.EMPTY_ARRAY;
|
||||||
arrayMods = (IASTArrayModifier[]) ArrayUtil.removeNullsAfter(IASTArrayModifier.class,
|
arrayMods = (IASTArrayModifier[]) ArrayUtil.trimAt(IASTArrayModifier.class,
|
||||||
arrayMods, arrayModsPos);
|
arrayMods, arrayModsPos);
|
||||||
return arrayMods;
|
return arrayMods;
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ public class CPPASTArrayDeclarator extends CPPASTDeclarator implements ICPPASTAr
|
||||||
public void addArrayModifier(IASTArrayModifier arrayModifier) {
|
public void addArrayModifier(IASTArrayModifier arrayModifier) {
|
||||||
assertNotFrozen();
|
assertNotFrozen();
|
||||||
if (arrayModifier != null) {
|
if (arrayModifier != null) {
|
||||||
arrayMods = (IASTArrayModifier[]) ArrayUtil.append(IASTArrayModifier.class, arrayMods,
|
arrayMods = (IASTArrayModifier[]) ArrayUtil.appendAt(IASTArrayModifier.class, arrayMods,
|
||||||
++arrayModsPos, arrayModifier);
|
++arrayModsPos, arrayModifier);
|
||||||
arrayModifier.setParent(this);
|
arrayModifier.setParent(this);
|
||||||
arrayModifier.setPropertyInParent(ARRAY_MODIFIER);
|
arrayModifier.setPropertyInParent(ARRAY_MODIFIER);
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class CPPASTEnumerationSpecifier extends CPPASTBaseDeclSpecifier
|
||||||
if (enumerator != null) {
|
if (enumerator != null) {
|
||||||
enumerator.setParent(this);
|
enumerator.setParent(this);
|
||||||
enumerator.setPropertyInParent(ENUMERATOR);
|
enumerator.setPropertyInParent(ENUMERATOR);
|
||||||
fItems = (IASTEnumerator[]) ArrayUtil.append( IASTEnumerator.class, fItems, ++fItemPos, enumerator );
|
fItems = (IASTEnumerator[]) ArrayUtil.appendAt( IASTEnumerator.class, fItems, ++fItemPos, enumerator );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ public class CPPASTEnumerationSpecifier extends CPPASTBaseDeclSpecifier
|
||||||
if (fItems == null)
|
if (fItems == null)
|
||||||
return IASTEnumerator.EMPTY_ENUMERATOR_ARRAY;
|
return IASTEnumerator.EMPTY_ENUMERATOR_ARRAY;
|
||||||
|
|
||||||
fItems = (IASTEnumerator[]) ArrayUtil.removeNullsAfter(IASTEnumerator.class, fItems, fItemPos);
|
fItems = (IASTEnumerator[]) ArrayUtil.trimAt(IASTEnumerator.class, fItems, fItemPos);
|
||||||
return fItems;
|
return fItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class CPPASTFunctionWithTryBlock extends CPPASTFunctionDefinition impleme
|
||||||
public void addCatchHandler(ICPPASTCatchHandler statement) {
|
public void addCatchHandler(ICPPASTCatchHandler statement) {
|
||||||
assertNotFrozen();
|
assertNotFrozen();
|
||||||
if (statement != null) {
|
if (statement != null) {
|
||||||
catchHandlers = (ICPPASTCatchHandler[]) ArrayUtil.append(ICPPASTCatchHandler.class, catchHandlers, ++catchHandlersPos, statement);
|
catchHandlers = (ICPPASTCatchHandler[]) ArrayUtil.appendAt(ICPPASTCatchHandler.class, catchHandlers, ++catchHandlersPos, statement);
|
||||||
statement.setParent(this);
|
statement.setParent(this);
|
||||||
statement.setPropertyInParent(CATCH_HANDLER);
|
statement.setPropertyInParent(CATCH_HANDLER);
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ public class CPPASTFunctionWithTryBlock extends CPPASTFunctionDefinition impleme
|
||||||
@Override
|
@Override
|
||||||
public ICPPASTCatchHandler[] getCatchHandlers() {
|
public ICPPASTCatchHandler[] getCatchHandlers() {
|
||||||
if (catchHandlers == null) return ICPPASTCatchHandler.EMPTY_CATCHHANDLER_ARRAY;
|
if (catchHandlers == null) return ICPPASTCatchHandler.EMPTY_CATCHHANDLER_ARRAY;
|
||||||
catchHandlers = (ICPPASTCatchHandler[]) ArrayUtil.removeNullsAfter(ICPPASTCatchHandler.class, catchHandlers, catchHandlersPos);
|
catchHandlers = (ICPPASTCatchHandler[]) ArrayUtil.trimAt(ICPPASTCatchHandler.class, catchHandlers, catchHandlersPos);
|
||||||
return catchHandlers;
|
return catchHandlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class CPPASTInitializerList extends ASTNode implements ICPPASTInitializer
|
||||||
public void addClause(IASTInitializerClause d) {
|
public void addClause(IASTInitializerClause d) {
|
||||||
assertNotFrozen();
|
assertNotFrozen();
|
||||||
if (d != null) {
|
if (d != null) {
|
||||||
initializers = (IASTInitializerClause[]) ArrayUtil.append( IASTInitializerClause.class, initializers, ++initializersPos, d );
|
initializers = (IASTInitializerClause[]) ArrayUtil.appendAt( IASTInitializerClause.class, initializers, ++initializersPos, d );
|
||||||
d.setParent(this);
|
d.setParent(this);
|
||||||
d.setPropertyInParent(NESTED_INITIALIZER);
|
d.setPropertyInParent(NESTED_INITIALIZER);
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class CPPASTLinkageSpecification extends ASTNode implements
|
||||||
if (decl != null) {
|
if (decl != null) {
|
||||||
decl.setParent(this);
|
decl.setParent(this);
|
||||||
decl.setPropertyInParent(OWNED_DECLARATION);
|
decl.setPropertyInParent(OWNED_DECLARATION);
|
||||||
fAllDeclarations = (IASTDeclaration[]) ArrayUtil.append( IASTDeclaration.class, fAllDeclarations, ++fLastDeclaration, decl);
|
fAllDeclarations = (IASTDeclaration[]) ArrayUtil.appendAt( IASTDeclaration.class, fAllDeclarations, ++fLastDeclaration, decl);
|
||||||
fActiveDeclarations= null;
|
fActiveDeclarations= null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ public class CPPASTLinkageSpecification extends ASTNode implements
|
||||||
|
|
||||||
public final IASTDeclaration[] getDeclarations(boolean includeInactive) {
|
public final IASTDeclaration[] getDeclarations(boolean includeInactive) {
|
||||||
if (includeInactive) {
|
if (includeInactive) {
|
||||||
fAllDeclarations= (IASTDeclaration[]) ArrayUtil.removeNullsAfter(IASTDeclaration.class, fAllDeclarations, fLastDeclaration);
|
fAllDeclarations= (IASTDeclaration[]) ArrayUtil.trimAt(IASTDeclaration.class, fAllDeclarations, fLastDeclaration);
|
||||||
return fAllDeclarations;
|
return fAllDeclarations;
|
||||||
}
|
}
|
||||||
return getDeclarations();
|
return getDeclarations();
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class CPPASTNamespaceDefinition extends ASTNode
|
||||||
if (decl != null) {
|
if (decl != null) {
|
||||||
decl.setParent(this);
|
decl.setParent(this);
|
||||||
decl.setPropertyInParent(OWNED_DECLARATION);
|
decl.setPropertyInParent(OWNED_DECLARATION);
|
||||||
fAllDeclarations = (IASTDeclaration[]) ArrayUtil.append(IASTDeclaration.class, fAllDeclarations, ++fLastDeclaration, decl);
|
fAllDeclarations = (IASTDeclaration[]) ArrayUtil.appendAt(IASTDeclaration.class, fAllDeclarations, ++fLastDeclaration, decl);
|
||||||
fActiveDeclarations= null;
|
fActiveDeclarations= null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ public class CPPASTNamespaceDefinition extends ASTNode
|
||||||
|
|
||||||
public final IASTDeclaration[] getDeclarations(boolean includeInactive) {
|
public final IASTDeclaration[] getDeclarations(boolean includeInactive) {
|
||||||
if (includeInactive) {
|
if (includeInactive) {
|
||||||
fAllDeclarations= (IASTDeclaration[]) ArrayUtil.removeNullsAfter(IASTDeclaration.class, fAllDeclarations, fLastDeclaration);
|
fAllDeclarations= (IASTDeclaration[]) ArrayUtil.trimAt(IASTDeclaration.class, fAllDeclarations, fLastDeclaration);
|
||||||
return fAllDeclarations;
|
return fAllDeclarations;
|
||||||
}
|
}
|
||||||
return getDeclarations();
|
return getDeclarations();
|
||||||
|
|
|
@ -113,7 +113,7 @@ public class CPPASTQualifiedName extends CPPASTNameBase
|
||||||
assertNotFrozen();
|
assertNotFrozen();
|
||||||
assert !(name instanceof ICPPASTQualifiedName);
|
assert !(name instanceof ICPPASTQualifiedName);
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
names = (IASTName[]) ArrayUtil.append(IASTName.class, names, ++namesPos, name);
|
names = (IASTName[]) ArrayUtil.appendAt(IASTName.class, names, ++namesPos, name);
|
||||||
name.setParent(this);
|
name.setParent(this);
|
||||||
name.setPropertyInParent(SEGMENT_NAME);
|
name.setPropertyInParent(SEGMENT_NAME);
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ public class CPPASTQualifiedName extends CPPASTNameBase
|
||||||
if (namesPos < 0)
|
if (namesPos < 0)
|
||||||
return IASTName.EMPTY_NAME_ARRAY;
|
return IASTName.EMPTY_NAME_ARRAY;
|
||||||
|
|
||||||
names = (IASTName[]) ArrayUtil.removeNullsAfter(IASTName.class, names, namesPos);
|
names = (IASTName[]) ArrayUtil.trimAt(IASTName.class, names, namesPos);
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class CPPASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclar
|
||||||
public IASTDeclarator[] getDeclarators() {
|
public IASTDeclarator[] getDeclarators() {
|
||||||
if (declarators == null)
|
if (declarators == null)
|
||||||
return IASTDeclarator.EMPTY_DECLARATOR_ARRAY;
|
return IASTDeclarator.EMPTY_DECLARATOR_ARRAY;
|
||||||
declarators = (IASTDeclarator[]) ArrayUtil.removeNullsAfter(IASTDeclarator.class, declarators, declaratorsPos);
|
declarators = (IASTDeclarator[]) ArrayUtil.trimAt(IASTDeclarator.class, declarators, declaratorsPos);
|
||||||
return declarators;
|
return declarators;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ public class CPPASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclar
|
||||||
public void addDeclarator(IASTDeclarator d) {
|
public void addDeclarator(IASTDeclarator d) {
|
||||||
assertNotFrozen();
|
assertNotFrozen();
|
||||||
if (d != null) {
|
if (d != null) {
|
||||||
declarators = (IASTDeclarator[]) ArrayUtil.append(IASTDeclarator.class, declarators, ++declaratorsPos, d);
|
declarators = (IASTDeclarator[]) ArrayUtil.appendAt(IASTDeclarator.class, declarators, ++declaratorsPos, d);
|
||||||
d.setParent(this);
|
d.setParent(this);
|
||||||
d.setPropertyInParent(DECLARATOR);
|
d.setPropertyInParent(DECLARATOR);
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ public class CPPASTTemplateDeclaration extends ASTNode
|
||||||
@Override
|
@Override
|
||||||
public ICPPASTTemplateParameter[] getTemplateParameters() {
|
public ICPPASTTemplateParameter[] getTemplateParameters() {
|
||||||
if (parameters == null) return ICPPASTTemplateParameter.EMPTY_TEMPLATEPARAMETER_ARRAY;
|
if (parameters == null) return ICPPASTTemplateParameter.EMPTY_TEMPLATEPARAMETER_ARRAY;
|
||||||
parameters = (ICPPASTTemplateParameter[]) ArrayUtil.removeNullsAfter(ICPPASTTemplateParameter.class, parameters, parametersPos);
|
parameters = (ICPPASTTemplateParameter[]) ArrayUtil.trimAt(ICPPASTTemplateParameter.class, parameters, parametersPos);
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ public class CPPASTTemplateDeclaration extends ASTNode
|
||||||
public void addTemplateParameter(ICPPASTTemplateParameter parm) {
|
public void addTemplateParameter(ICPPASTTemplateParameter parm) {
|
||||||
assertNotFrozen();
|
assertNotFrozen();
|
||||||
if (parm != null) {
|
if (parm != null) {
|
||||||
parameters = (ICPPASTTemplateParameter[]) ArrayUtil.append(ICPPASTTemplateParameter.class, parameters, ++parametersPos, parm);
|
parameters = (ICPPASTTemplateParameter[]) ArrayUtil.appendAt(ICPPASTTemplateParameter.class, parameters, ++parametersPos, parm);
|
||||||
parm.setParent(this);
|
parm.setParent(this);
|
||||||
parm.setPropertyInParent(PARAMETER);
|
parm.setPropertyInParent(PARAMETER);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class CPPASTTryBlockStatement extends ASTNode implements ICPPASTTryBlockS
|
||||||
public void addCatchHandler(ICPPASTCatchHandler statement) {
|
public void addCatchHandler(ICPPASTCatchHandler statement) {
|
||||||
assertNotFrozen();
|
assertNotFrozen();
|
||||||
if (statement != null) {
|
if (statement != null) {
|
||||||
catchHandlers = (ICPPASTCatchHandler[]) ArrayUtil.append( ICPPASTCatchHandler.class, catchHandlers, ++catchHandlersPos, statement );
|
catchHandlers = (ICPPASTCatchHandler[]) ArrayUtil.appendAt( ICPPASTCatchHandler.class, catchHandlers, ++catchHandlersPos, statement );
|
||||||
statement.setParent(this);
|
statement.setParent(this);
|
||||||
statement.setPropertyInParent(CATCH_HANDLER);
|
statement.setPropertyInParent(CATCH_HANDLER);
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ public class CPPASTTryBlockStatement extends ASTNode implements ICPPASTTryBlockS
|
||||||
|
|
||||||
public ICPPASTCatchHandler[] getCatchHandlers() {
|
public ICPPASTCatchHandler[] getCatchHandlers() {
|
||||||
if( catchHandlers == null ) return ICPPASTCatchHandler.EMPTY_CATCHHANDLER_ARRAY;
|
if( catchHandlers == null ) return ICPPASTCatchHandler.EMPTY_CATCHHANDLER_ARRAY;
|
||||||
catchHandlers = (ICPPASTCatchHandler[]) ArrayUtil.removeNullsAfter( ICPPASTCatchHandler.class, catchHandlers, catchHandlersPos );
|
catchHandlers = (ICPPASTCatchHandler[]) ArrayUtil.trimAt( ICPPASTCatchHandler.class, catchHandlers, catchHandlersPos );
|
||||||
return catchHandlers;
|
return catchHandlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class CPPCompositeBinding extends PlatformObject implements IBinding {
|
||||||
IBinding[] bindings;
|
IBinding[] bindings;
|
||||||
|
|
||||||
public CPPCompositeBinding(IBinding[] bindingList) {
|
public CPPCompositeBinding(IBinding[] bindingList) {
|
||||||
bindings = (IBinding[]) ArrayUtil.trim(IBinding.class, bindingList, true);
|
bindings = ArrayUtil.trim(bindingList, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -100,7 +100,7 @@ class PDOMCPPUsingDeclaration extends PDOMCPPBinding implements ICPPUsingDeclara
|
||||||
do {
|
do {
|
||||||
IBinding delegate = alias.getBinding();
|
IBinding delegate = alias.getBinding();
|
||||||
if (delegate != null) {
|
if (delegate != null) {
|
||||||
delegates= (IBinding[]) ArrayUtil.append(IBinding.class, delegates, i++, delegate);
|
delegates= (IBinding[]) ArrayUtil.appendAt(IBinding.class, delegates, i++, delegate);
|
||||||
}
|
}
|
||||||
} while ((alias = alias.getNext()) != null);
|
} while ((alias = alias.getNext()) != null);
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue