diff options
author | paltherr <paltherr@epfl.ch> | 2003-09-07 10:50:55 +0000 |
---|---|---|
committer | paltherr <paltherr@epfl.ch> | 2003-09-07 10:50:55 +0000 |
commit | 7e8533ec4275548c8fe13d78f8872b932a806956 (patch) | |
tree | 4f65e2cde88eebfeed3873fe4409e17d4cab6f05 /sources/scalac/ast | |
parent | d107eb40f1372ab1a1b9b26220e55c512d44ecd7 (diff) | |
download | scala-7e8533ec4275548c8fe13d78f8872b932a806956.tar.gz scala-7e8533ec4275548c8fe13d78f8872b932a806956.tar.bz2 scala-7e8533ec4275548c8fe13d78f8872b932a806956.zip |
- Added additional cloneArray methods
Diffstat (limited to 'sources/scalac/ast')
-rw-r--r-- | sources/scalac/ast/Tree.java.tmpl | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/sources/scalac/ast/Tree.java.tmpl b/sources/scalac/ast/Tree.java.tmpl index 868bdda09a..ca2f06242a 100644 --- a/sources/scalac/ast/Tree.java.tmpl +++ b/sources/scalac/ast/Tree.java.tmpl @@ -133,9 +133,35 @@ public class Tree { /** Returns a shallow copy of the given array. */ public static Tree[] cloneArray(Tree[] array) { - if (array.length == 0) return array; - Tree[] clone = new Tree[array.length]; - for (int i = 0; i < clone.length; i++) clone[i] = array[i]; + return cloneArray(0, array, 0); + } + + /** + * Returns a shallow copy of the given array prefixed by "prefix" + * null items. + */ + public static Tree[] cloneArray(int prefix, Tree[] array) { + return cloneArray(prefix, array, 0); + } + + /** + * Returns a shallow copy of the given array suffixed by "suffix" + * null items. + */ + public static Tree[] cloneArray(Tree[] array, int suffix) { + return cloneArray(0, array, suffix); + } + + /** + * Returns a shallow copy of the given array prefixed by "prefix" + * null items and suffixed by "suffix" null items. + */ + public static Tree[] cloneArray(int prefix, Tree[] array, int suffix) { + assert prefix >= 0 && suffix >= 0: prefix + " - " + suffix; + int size = prefix + array.length + suffix; + if (size == 0) return EMPTY_ARRAY; + Tree[] clone = new Tree[size]; + for (int i = 0; i < array.length; i++) clone[prefix + i] = array[i]; return clone; } |