1st step in eliminating Class.forName when working with array types. Class.getComponentType on directly allocated arrays does not need that.
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.vm4brwsr;
20 import org.apidesign.bck2brwsr.core.JavaScriptBody;
24 * @author Jaroslav Tulach <jtulach@netbeans.org>
28 short[] shorts = { 2, 3 };
29 int[] ints = { 4, 5, 6 };
30 float[] floats = { 7, 8, 9, 10 };
31 double[][] doubles = { {11}, {12}, {13}, {14}, {15} };
32 char[] chars = { 'a', 'b' };
56 static double[][] dbls = new double[1][2];
57 public static double twoDoubles() {
58 return dbls[0][0] + dbls[0][0];
61 static int[][] tints = new int[1][2];
62 public static int twoInts() {
63 return tints[0][0] + tints[0][0];
66 private static final Array[] ARR = { new Array(), new Array(), new Array() };
68 private static Array[][] arr() {
69 Array[][] matrix = new Array[3][3];
70 for (int i = 0; i < ARR.length; i++) {
71 matrix[i][i] = ARR[i];
75 private static <T> T[] filter(T[] in) {
79 public static double sum() {
81 for (Array[] row : arr()) {
92 sum += filter(row)[indx].doubles();
97 private static final int[] arr = { 0, 1, 2, 3, 4, 5 };
98 public static int simple(boolean clone) {
113 public static String objectArrayClass() {
114 return Object[].class.getName();
117 public static boolean instanceOfArray(Object obj) {
118 return obj instanceof Object[];
121 public static int sum(int size) {
122 int[] arr = new int[size];
123 return arr[0] + arr[1];
126 static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) {
127 while (count-- > 0) {
128 dst[dstBegin++] = value[srcBegin++];
132 public static char copyArray() {
133 char[] arr = { '0' };
134 arraycopy(arr()[0][0].chars, 0, arr, 0, 1);
138 @JavaScriptBody(args = { }, body =
139 "if (!vm.java_lang_Class(false).forName__Ljava_lang_Class_2Ljava_lang_String_2) throw 'forName not defined';\n"
140 + "vm.java_lang_Class(false).forName__Ljava_lang_Class_2Ljava_lang_String_2 = function(s) {\n"
141 + " throw 'Do not call me: ' + s;\n"
143 private static void disableClassForName() {
146 public static String nameOfClonedComponent() {
147 disableClassForName();
148 Object[] intArr = new Integer[10];
149 intArr = intArr.clone();
150 return intArr.getClass().getComponentType().getName();
153 public static int multiLen() {
154 return new int[1][0].length;