Merging default branch into emul to continue experiments with the emulation project layout
1.1 --- a/.hgignore Thu Oct 11 06:15:22 2012 -0700
1.2 +++ b/.hgignore Wed Jan 23 20:16:48 2013 +0100
1.3 @@ -1,4 +1,4 @@
1.4 ^target/.*
1.5 .*/target/.*
1.6 .*orig$
1.7 -
1.8 +.*~
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/COPYING Wed Jan 23 20:16:48 2013 +0100
2.3 @@ -0,0 +1,15 @@
2.4 +Back 2 Browser Bytecode Translator
2.5 +Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
2.6 +
2.7 +This program is free software: you can redistribute it and/or modify
2.8 +it under the terms of the GNU General Public License as published by
2.9 +the Free Software Foundation, version 2 of the License.
2.10 +
2.11 +This program is distributed in the hope that it will be useful,
2.12 +but WITHOUT ANY WARRANTY; without even the implied warranty of
2.13 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.14 +GNU General Public License for more details.
2.15 +
2.16 +You should have received a copy of the GNU General Public License
2.17 +along with this program. Look for COPYING file in the top folder.
2.18 +If not, see http://opensource.org/licenses/GPL-2.0.
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/benchmarks/matrix-multiplication/pom.xml Wed Jan 23 20:16:48 2013 +0100
3.3 @@ -0,0 +1,56 @@
3.4 +<?xml version="1.0"?>
3.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3.6 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3.7 + <modelVersion>4.0.0</modelVersion>
3.8 +
3.9 + <groupId>org.apidesign.bck2brwsr</groupId>
3.10 + <artifactId>matrix.multiplication</artifactId>
3.11 + <version>0.3-SNAPSHOT</version>
3.12 + <packaging>jar</packaging>
3.13 +
3.14 + <name>Matrix multiplication</name>
3.15 +
3.16 + <properties>
3.17 + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3.18 + </properties>
3.19 +
3.20 + <build>
3.21 + <plugins>
3.22 + <plugin>
3.23 + <groupId>org.apache.maven.plugins</groupId>
3.24 + <artifactId>maven-compiler-plugin</artifactId>
3.25 + <version>2.3.2</version>
3.26 + <configuration>
3.27 + <source>1.7</source>
3.28 + <target>1.7</target>
3.29 + </configuration>
3.30 + </plugin>
3.31 + </plugins>
3.32 + </build>
3.33 +
3.34 + <dependencies>
3.35 + <dependency>
3.36 + <groupId>org.apidesign.bck2brwsr</groupId>
3.37 + <artifactId>emul</artifactId>
3.38 + <version>0.3-SNAPSHOT</version>
3.39 + </dependency>
3.40 + <dependency>
3.41 + <groupId>org.testng</groupId>
3.42 + <artifactId>testng</artifactId>
3.43 + <version>6.5.2</version>
3.44 + <scope>test</scope>
3.45 + <exclusions>
3.46 + <exclusion>
3.47 + <artifactId>junit</artifactId>
3.48 + <groupId>junit</groupId>
3.49 + </exclusion>
3.50 + </exclusions>
3.51 + </dependency>
3.52 + <dependency>
3.53 + <groupId>org.apidesign.bck2brwsr</groupId>
3.54 + <artifactId>vmtest</artifactId>
3.55 + <version>0.3-SNAPSHOT</version>
3.56 + <scope>test</scope>
3.57 + </dependency>
3.58 + </dependencies>
3.59 +</project>
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/benchmarks/matrix-multiplication/src/main/java/org/apidesign/benchmark/matrixmul/Matrix.java Wed Jan 23 20:16:48 2013 +0100
4.3 @@ -0,0 +1,108 @@
4.4 +/**
4.5 + * Back 2 Browser Bytecode Translator
4.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
4.7 + *
4.8 + * This program is free software: you can redistribute it and/or modify
4.9 + * it under the terms of the GNU General Public License as published by
4.10 + * the Free Software Foundation, version 2 of the License.
4.11 + *
4.12 + * This program is distributed in the hope that it will be useful,
4.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4.15 + * GNU General Public License for more details.
4.16 + *
4.17 + * You should have received a copy of the GNU General Public License
4.18 + * along with this program. Look for COPYING file in the top folder.
4.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
4.20 + */
4.21 +package org.apidesign.benchmark.matrixmul;
4.22 +
4.23 +import java.io.IOException;
4.24 +import java.util.Arrays;
4.25 +
4.26 +public class Matrix {
4.27 + private final int rank;
4.28 + private final float data[][];
4.29 +
4.30 + public Matrix(int r) {
4.31 + this(r, new float[r][r]);
4.32 + }
4.33 +
4.34 + private Matrix(int r, float[][] data) {
4.35 + this.rank = r;
4.36 + this.data = data;
4.37 + }
4.38 +
4.39 + public void setElement(int i, int j, float value) {
4.40 + data[i][j] = value;
4.41 + }
4.42 + public float getElement(int i, int j) {
4.43 + return data[i][j];
4.44 + }
4.45 +
4.46 + public void generateData() {
4.47 + //final Random rand = new Random();
4.48 + //final int x = 10;
4.49 + for (int i = 0; i < rank; i++) {
4.50 + for (int j = 0; j < rank; j++) {
4.51 + data[i][j] = 1 / (1 + i + j);
4.52 + }
4.53 + }
4.54 + }
4.55 +
4.56 + public Matrix multiply(Matrix m) {
4.57 + if (rank != m.rank) {
4.58 + throw new IllegalArgumentException("Rank doesn't match");
4.59 + }
4.60 +
4.61 + final float res[][] = new float[rank][rank];
4.62 + for (int i = 0; i < rank; i++) {
4.63 + for (int j = 0; j < rank; j++) {
4.64 + float ij = 0;
4.65 + for (int q = 0; q < rank; q++) {
4.66 + ij += data[i][q] * m.data[q][j];
4.67 + }
4.68 + res[i][j] = ij;
4.69 + }
4.70 + }
4.71 + return new Matrix(rank, res);
4.72 + }
4.73 +
4.74 + public void printOn(Appendable s) throws IOException {
4.75 + for (int i = 0; i < rank; i++) {
4.76 + String sep = "";
4.77 + for (int j = 0; j < rank; j++) {
4.78 + s.append(sep + data[i][j]);
4.79 + sep = " ";
4.80 + }
4.81 + s.append("\n");
4.82 + }
4.83 + }
4.84 +
4.85 + @Override
4.86 + public boolean equals(Object obj) {
4.87 + if (obj instanceof Matrix) {
4.88 + Matrix snd = (Matrix)obj;
4.89 + if (snd.rank != rank) {
4.90 + return false;
4.91 + }
4.92 + for (int i = 0; i < rank; i++) {
4.93 + for (int j = 0; j < rank; j++) {
4.94 + if (data[i][j] != snd.data[i][j]) {
4.95 + return false;
4.96 + }
4.97 + }
4.98 + }
4.99 + return true;
4.100 + }
4.101 + return false;
4.102 + }
4.103 +
4.104 + @Override
4.105 + public int hashCode() {
4.106 + int hash = 3;
4.107 + hash = 97 * hash + this.rank;
4.108 + hash = 97 * hash + Arrays.deepHashCode(this.data);
4.109 + return hash;
4.110 + }
4.111 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/benchmarks/matrix-multiplication/src/test/java/org/apidesign/benchmark/matrixmul/MatrixTest.java Wed Jan 23 20:16:48 2013 +0100
5.3 @@ -0,0 +1,57 @@
5.4 +/**
5.5 + * Back 2 Browser Bytecode Translator
5.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5.7 + *
5.8 + * This program is free software: you can redistribute it and/or modify
5.9 + * it under the terms of the GNU General Public License as published by
5.10 + * the Free Software Foundation, version 2 of the License.
5.11 + *
5.12 + * This program is distributed in the hope that it will be useful,
5.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5.15 + * GNU General Public License for more details.
5.16 + *
5.17 + * You should have received a copy of the GNU General Public License
5.18 + * along with this program. Look for COPYING file in the top folder.
5.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
5.20 + */
5.21 +package org.apidesign.benchmark.matrixmul;
5.22 +
5.23 +import java.io.IOException;
5.24 +import org.apidesign.bck2brwsr.vmtest.Compare;
5.25 +import org.apidesign.bck2brwsr.vmtest.VMTest;
5.26 +import org.testng.annotations.Factory;
5.27 +
5.28 +/**
5.29 + *
5.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
5.31 + */
5.32 +public class MatrixTest {
5.33 + public MatrixTest() {
5.34 + }
5.35 +
5.36 + @Compare(scripting = false)
5.37 + public String tenThousandIterations() throws IOException {
5.38 +
5.39 + Matrix m1 = new Matrix(5);
5.40 + Matrix m2 = new Matrix(5);
5.41 +
5.42 + m1.generateData();
5.43 + m2.generateData();
5.44 +
5.45 + Matrix res = null;
5.46 + for (int i = 0; i < 10000; i++) {
5.47 + res = m1.multiply(m2);
5.48 + m1 = res;
5.49 + }
5.50 +
5.51 + StringBuilder sb = new StringBuilder();
5.52 + res.printOn(sb);
5.53 + return sb.toString();
5.54 + }
5.55 +
5.56 + @Factory
5.57 + public static Object[] create() {
5.58 + return VMTest.create(MatrixTest.class);
5.59 + }
5.60 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/benchmarks/pom.xml Wed Jan 23 20:16:48 2013 +0100
6.3 @@ -0,0 +1,17 @@
6.4 +<?xml version="1.0" encoding="UTF-8"?>
6.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
6.6 + <modelVersion>4.0.0</modelVersion>
6.7 + <parent>
6.8 + <artifactId>bck2brwsr</artifactId>
6.9 + <groupId>org.apidesign</groupId>
6.10 + <version>0.3-SNAPSHOT</version>
6.11 + </parent>
6.12 + <groupId>org.apidesign.bck2brwsr</groupId>
6.13 + <artifactId>benchmarks</artifactId>
6.14 + <version>0.3-SNAPSHOT</version>
6.15 + <packaging>pom</packaging>
6.16 + <name>Performance benchmarks</name>
6.17 + <modules>
6.18 + <module>matrix-multiplication</module>
6.19 + </modules>
6.20 +</project>
7.1 --- a/core/pom.xml Thu Oct 11 06:15:22 2012 -0700
7.2 +++ b/core/pom.xml Wed Jan 23 20:16:48 2013 +0100
7.3 @@ -5,14 +5,27 @@
7.4 <parent>
7.5 <groupId>org.apidesign</groupId>
7.6 <artifactId>bck2brwsr</artifactId>
7.7 - <version>1.0-SNAPSHOT</version>
7.8 + <version>0.3-SNAPSHOT</version>
7.9 </parent>
7.10 <groupId>org.apidesign.bck2brwsr</groupId>
7.11 <artifactId>core</artifactId>
7.12 - <version>1.0-SNAPSHOT</version>
7.13 - <name>core</name>
7.14 + <version>0.3-SNAPSHOT</version>
7.15 + <name>Core JS Annotations</name>
7.16 <url>http://maven.apache.org</url>
7.17 - <properties>
7.18 + <build>
7.19 + <plugins>
7.20 + <plugin>
7.21 + <groupId>org.apache.maven.plugins</groupId>
7.22 + <artifactId>maven-compiler-plugin</artifactId>
7.23 + <version>2.3.2</version>
7.24 + <configuration>
7.25 + <source>1.7</source>
7.26 + <target>1.7</target>
7.27 + </configuration>
7.28 + </plugin>
7.29 + </plugins>
7.30 + </build>
7.31 + <properties>
7.32 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
7.33 </properties>
7.34 <dependencies>
7.35 @@ -22,5 +35,11 @@
7.36 <version>3.8.1</version>
7.37 <scope>test</scope>
7.38 </dependency>
7.39 + <dependency>
7.40 + <groupId>org.netbeans.api</groupId>
7.41 + <artifactId>org-openide-util-lookup</artifactId>
7.42 + </dependency>
7.43 </dependencies>
7.44 + <description>Contains esential annotations for associating JavaScript code with
7.45 +methods and classes.</description>
7.46 </project>
8.1 --- a/core/src/main/java/org/apidesign/bck2brwsr/core/ExtraJavaScript.java Thu Oct 11 06:15:22 2012 -0700
8.2 +++ b/core/src/main/java/org/apidesign/bck2brwsr/core/ExtraJavaScript.java Wed Jan 23 20:16:48 2013 +0100
8.3 @@ -1,3 +1,20 @@
8.4 +/**
8.5 + * Back 2 Browser Bytecode Translator
8.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
8.7 + *
8.8 + * This program is free software: you can redistribute it and/or modify
8.9 + * it under the terms of the GNU General Public License as published by
8.10 + * the Free Software Foundation, version 2 of the License.
8.11 + *
8.12 + * This program is distributed in the hope that it will be useful,
8.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8.15 + * GNU General Public License for more details.
8.16 + *
8.17 + * You should have received a copy of the GNU General Public License
8.18 + * along with this program. Look for COPYING file in the top folder.
8.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
8.20 + */
8.21 package org.apidesign.bck2brwsr.core;
8.22
8.23 import java.lang.annotation.ElementType;
9.1 --- a/core/src/main/java/org/apidesign/bck2brwsr/core/JavaScriptBody.java Thu Oct 11 06:15:22 2012 -0700
9.2 +++ b/core/src/main/java/org/apidesign/bck2brwsr/core/JavaScriptBody.java Wed Jan 23 20:16:48 2013 +0100
9.3 @@ -1,6 +1,19 @@
9.4 -/*
9.5 - * To change this template, choose Tools | Templates
9.6 - * and open the template in the editor.
9.7 +/**
9.8 + * Back 2 Browser Bytecode Translator
9.9 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
9.10 + *
9.11 + * This program is free software: you can redistribute it and/or modify
9.12 + * it under the terms of the GNU General Public License as published by
9.13 + * the Free Software Foundation, version 2 of the License.
9.14 + *
9.15 + * This program is distributed in the hope that it will be useful,
9.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9.18 + * GNU General Public License for more details.
9.19 + *
9.20 + * You should have received a copy of the GNU General Public License
9.21 + * along with this program. Look for COPYING file in the top folder.
9.22 + * If not, see http://opensource.org/licenses/GPL-2.0.
9.23 */
9.24 package org.apidesign.bck2brwsr.core;
9.25
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/core/src/main/java/org/apidesign/bck2brwsr/core/JavaScriptOnly.java Wed Jan 23 20:16:48 2013 +0100
10.3 @@ -0,0 +1,37 @@
10.4 +/**
10.5 + * Back 2 Browser Bytecode Translator
10.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
10.7 + *
10.8 + * This program is free software: you can redistribute it and/or modify
10.9 + * it under the terms of the GNU General Public License as published by
10.10 + * the Free Software Foundation, version 2 of the License.
10.11 + *
10.12 + * This program is distributed in the hope that it will be useful,
10.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10.15 + * GNU General Public License for more details.
10.16 + *
10.17 + * You should have received a copy of the GNU General Public License
10.18 + * along with this program. Look for COPYING file in the top folder.
10.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
10.20 + */
10.21 +package org.apidesign.bck2brwsr.core;
10.22 +
10.23 +import java.lang.annotation.ElementType;
10.24 +import java.lang.annotation.Retention;
10.25 +import java.lang.annotation.RetentionPolicy;
10.26 +import java.lang.annotation.Target;
10.27 +
10.28 +/** Don't include given field or method in generated JavaScript. Rather
10.29 + * generate completely independent JavaScript code.
10.30 + *
10.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
10.32 + */
10.33 +@Retention(RetentionPolicy.CLASS)
10.34 +@Target({ ElementType.METHOD, ElementType.FIELD })
10.35 +public @interface JavaScriptOnly {
10.36 + /** name of the variable to assign given value to */
10.37 + String name() default "";
10.38 + /** value to assign to given field */
10.39 + String value() default "";
10.40 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/core/src/main/java/org/apidesign/bck2brwsr/core/JavaScriptPrototype.java Wed Jan 23 20:16:48 2013 +0100
11.3 @@ -0,0 +1,44 @@
11.4 +/**
11.5 + * Back 2 Browser Bytecode Translator
11.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
11.7 + *
11.8 + * This program is free software: you can redistribute it and/or modify
11.9 + * it under the terms of the GNU General Public License as published by
11.10 + * the Free Software Foundation, version 2 of the License.
11.11 + *
11.12 + * This program is distributed in the hope that it will be useful,
11.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11.15 + * GNU General Public License for more details.
11.16 + *
11.17 + * You should have received a copy of the GNU General Public License
11.18 + * along with this program. Look for COPYING file in the top folder.
11.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
11.20 + */
11.21 +package org.apidesign.bck2brwsr.core;
11.22 +
11.23 +import java.lang.annotation.ElementType;
11.24 +import java.lang.annotation.Retention;
11.25 +import java.lang.annotation.RetentionPolicy;
11.26 +import java.lang.annotation.Target;
11.27 +
11.28 +/** Controls how JavaScript inheritance should be handled.
11.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
11.30 + */
11.31 +@Retention(RetentionPolicy.CLASS)
11.32 +@Target({ ElementType.TYPE })
11.33 +public @interface JavaScriptPrototype {
11.34 + /** Expression that identifies the function where all methods
11.35 + * should be added into. If this attribute is unspecified
11.36 + * all methods are added to the same object specified by
11.37 + * {@link #prototype()}.
11.38 + *
11.39 + * @return name of function to contain methods found in given class
11.40 + */
11.41 + String container() default "";
11.42 + /** Expression that defines the way to construct prototype for this
11.43 + * class.
11.44 + * @return expression to construct prototype
11.45 + */
11.46 + String prototype();
11.47 +}
12.1 --- a/core/src/main/java/org/apidesign/bck2brwsr/core/NoJavaScript.java Thu Oct 11 06:15:22 2012 -0700
12.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
12.3 @@ -1,16 +0,0 @@
12.4 -package org.apidesign.bck2brwsr.core;
12.5 -
12.6 -import java.lang.annotation.ElementType;
12.7 -import java.lang.annotation.Retention;
12.8 -import java.lang.annotation.RetentionPolicy;
12.9 -import java.lang.annotation.Target;
12.10 -
12.11 -/** Don't include given field or method in generated JavaScript.
12.12 - *
12.13 - * @author Jaroslav Tulach <jtulach@netbeans.org>
12.14 - */
12.15 -@Retention(RetentionPolicy.CLASS)
12.16 -@Target({ ElementType.METHOD, ElementType.FIELD })
12.17 -public @interface NoJavaScript {
12.18 -
12.19 -}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
13.2 +++ b/core/src/main/java/org/apidesign/bck2brwsr/core/impl/JavaScriptProcesor.java Wed Jan 23 20:16:48 2013 +0100
13.3 @@ -0,0 +1,92 @@
13.4 +/**
13.5 + * Back 2 Browser Bytecode Translator
13.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
13.7 + *
13.8 + * This program is free software: you can redistribute it and/or modify
13.9 + * it under the terms of the GNU General Public License as published by
13.10 + * the Free Software Foundation, version 2 of the License.
13.11 + *
13.12 + * This program is distributed in the hope that it will be useful,
13.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13.15 + * GNU General Public License for more details.
13.16 + *
13.17 + * You should have received a copy of the GNU General Public License
13.18 + * along with this program. Look for COPYING file in the top folder.
13.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
13.20 + */
13.21 +package org.apidesign.bck2brwsr.core.impl;
13.22 +
13.23 +import java.util.Collections;
13.24 +import java.util.HashSet;
13.25 +import java.util.List;
13.26 +import java.util.Set;
13.27 +import javax.annotation.processing.AbstractProcessor;
13.28 +import javax.annotation.processing.Completion;
13.29 +import javax.annotation.processing.Completions;
13.30 +import javax.annotation.processing.Processor;
13.31 +import javax.annotation.processing.RoundEnvironment;
13.32 +import javax.lang.model.element.AnnotationMirror;
13.33 +import javax.lang.model.element.Element;
13.34 +import javax.lang.model.element.ElementKind;
13.35 +import javax.lang.model.element.ExecutableElement;
13.36 +import javax.lang.model.element.Modifier;
13.37 +import javax.lang.model.element.TypeElement;
13.38 +import javax.lang.model.element.VariableElement;
13.39 +import javax.tools.Diagnostic;
13.40 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
13.41 +import org.openide.util.lookup.ServiceProvider;
13.42 +
13.43 +/**
13.44 + *
13.45 + * @author Jaroslav Tulach <jtulach@netbeans.org>
13.46 + */
13.47 +@ServiceProvider(service = Processor.class)
13.48 +public final class JavaScriptProcesor extends AbstractProcessor {
13.49 + @Override
13.50 + public Set<String> getSupportedAnnotationTypes() {
13.51 + Set<String> set = new HashSet<>();
13.52 + set.add(JavaScriptBody.class.getName());
13.53 + return set;
13.54 + }
13.55 +
13.56 + @Override
13.57 + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
13.58 + for (Element e : roundEnv.getElementsAnnotatedWith(JavaScriptBody.class)) {
13.59 + if (e.getKind() != ElementKind.METHOD && e.getKind() != ElementKind.CONSTRUCTOR) {
13.60 + continue;
13.61 + }
13.62 + ExecutableElement ee = (ExecutableElement)e;
13.63 + List<? extends VariableElement> params = ee.getParameters();
13.64 +
13.65 + JavaScriptBody jsb = e.getAnnotation(JavaScriptBody.class);
13.66 + String[] arr = jsb.args();
13.67 + if (params.size() != arr.length) {
13.68 + processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Number of args arguments does not match real arguments!", e);
13.69 + }
13.70 + }
13.71 + return true;
13.72 + }
13.73 +
13.74 + @Override
13.75 + public Iterable<? extends Completion> getCompletions(Element e,
13.76 + AnnotationMirror annotation, ExecutableElement member, String userText
13.77 + ) {
13.78 + StringBuilder sb = new StringBuilder();
13.79 + if (e.getKind() == ElementKind.METHOD && member.getSimpleName().contentEquals("args")) {
13.80 + ExecutableElement ee = (ExecutableElement) e;
13.81 + String sep = "";
13.82 + sb.append("{ ");
13.83 + for (VariableElement ve : ee.getParameters()) {
13.84 + sb.append(sep).append('"').append(ve.getSimpleName())
13.85 + .append('"');
13.86 + sep = ", ";
13.87 + }
13.88 + sb.append(" }");
13.89 + return Collections.nCopies(1, Completions.of(sb.toString()));
13.90 + }
13.91 + return null;
13.92 + }
13.93 +
13.94 +
13.95 +}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
14.2 +++ b/dew/nbactions.xml Wed Jan 23 20:16:48 2013 +0100
14.3 @@ -0,0 +1,56 @@
14.4 +<?xml version="1.0" encoding="UTF-8"?>
14.5 +<!--
14.6 +
14.7 + Back 2 Browser Bytecode Translator
14.8 + Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
14.9 +
14.10 + This program is free software: you can redistribute it and/or modify
14.11 + it under the terms of the GNU General Public License as published by
14.12 + the Free Software Foundation, version 2 of the License.
14.13 +
14.14 + This program is distributed in the hope that it will be useful,
14.15 + but WITHOUT ANY WARRANTY; without even the implied warranty of
14.16 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14.17 + GNU General Public License for more details.
14.18 +
14.19 + You should have received a copy of the GNU General Public License
14.20 + along with this program. Look for COPYING file in the top folder.
14.21 + If not, see http://opensource.org/licenses/GPL-2.0.
14.22 +
14.23 +-->
14.24 +<actions>
14.25 + <action>
14.26 + <actionName>run</actionName>
14.27 + <goals>
14.28 + <goal>process-classes</goal>
14.29 + <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
14.30 + </goals>
14.31 + <properties>
14.32 + <exec.args>-classpath %classpath org.apidesign.bck2brwsr.dew.Dew</exec.args>
14.33 + <exec.executable>java</exec.executable>
14.34 + </properties>
14.35 + </action>
14.36 + <action>
14.37 + <actionName>debug</actionName>
14.38 + <goals>
14.39 + <goal>process-classes</goal>
14.40 + <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
14.41 + </goals>
14.42 + <properties>
14.43 + <exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath org.apidesign.bck2brwsr.dew.Dew</exec.args>
14.44 + <exec.executable>java</exec.executable>
14.45 + <jpda.listen>true</jpda.listen>
14.46 + </properties>
14.47 + </action>
14.48 + <action>
14.49 + <actionName>profile</actionName>
14.50 + <goals>
14.51 + <goal>process-classes</goal>
14.52 + <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
14.53 + </goals>
14.54 + <properties>
14.55 + <exec.args>${profiler.args} -classpath %classpath org.apidesign.bck2brwsr.dew.Dew</exec.args>
14.56 + <exec.executable>${profiler.java}</exec.executable>
14.57 + </properties>
14.58 + </action>
14.59 + </actions>
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
15.2 +++ b/dew/pom.xml Wed Jan 23 20:16:48 2013 +0100
15.3 @@ -0,0 +1,64 @@
15.4 +<?xml version="1.0"?>
15.5 +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
15.6 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
15.7 + <modelVersion>4.0.0</modelVersion>
15.8 + <parent>
15.9 + <groupId>org.apidesign</groupId>
15.10 + <artifactId>bck2brwsr</artifactId>
15.11 + <version>0.3-SNAPSHOT</version>
15.12 + </parent>
15.13 + <groupId>org.apidesign.bck2brwsr</groupId>
15.14 + <artifactId>dew</artifactId>
15.15 + <version>0.3-SNAPSHOT</version>
15.16 + <name>Development Environment for Web</name>
15.17 + <url>http://maven.apache.org</url>
15.18 + <build>
15.19 + <plugins>
15.20 + <plugin>
15.21 + <groupId>org.apache.maven.plugins</groupId>
15.22 + <artifactId>maven-compiler-plugin</artifactId>
15.23 + <version>2.3.2</version>
15.24 + <configuration>
15.25 + <source>1.7</source>
15.26 + <target>1.7</target>
15.27 + </configuration>
15.28 + </plugin>
15.29 + </plugins>
15.30 + </build>
15.31 + <properties>
15.32 + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15.33 + </properties>
15.34 + <dependencies>
15.35 + <dependency>
15.36 + <groupId>org.glassfish.grizzly</groupId>
15.37 + <artifactId>grizzly-http-server</artifactId>
15.38 + <version>2.2.19</version>
15.39 + </dependency>
15.40 + <dependency>
15.41 + <groupId>${project.groupId}</groupId>
15.42 + <artifactId>vm4brwsr</artifactId>
15.43 + <version>${project.version}</version>
15.44 + </dependency>
15.45 + <dependency>
15.46 + <groupId>org.json</groupId>
15.47 + <artifactId>json</artifactId>
15.48 + <version>20090211</version>
15.49 + </dependency>
15.50 + <dependency>
15.51 + <groupId>org.testng</groupId>
15.52 + <artifactId>testng</artifactId>
15.53 + <scope>test</scope>
15.54 + <exclusions>
15.55 + <exclusion>
15.56 + <artifactId>junit</artifactId>
15.57 + <groupId>junit</groupId>
15.58 + </exclusion>
15.59 + </exclusions>
15.60 + </dependency>
15.61 + <dependency>
15.62 + <groupId>${project.groupId}</groupId>
15.63 + <artifactId>javaquery.api</artifactId>
15.64 + <version>${project.version}</version>
15.65 + </dependency>
15.66 + </dependencies>
15.67 +</project>
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
16.2 +++ b/dew/src/main/java/org/apidesign/bck2brwsr/dew/Compile.java Wed Jan 23 20:16:48 2013 +0100
16.3 @@ -0,0 +1,196 @@
16.4 +/**
16.5 + * Back 2 Browser Bytecode Translator
16.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
16.7 + *
16.8 + * This program is free software: you can redistribute it and/or modify
16.9 + * it under the terms of the GNU General Public License as published by
16.10 + * the Free Software Foundation, version 2 of the License.
16.11 + *
16.12 + * This program is distributed in the hope that it will be useful,
16.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16.15 + * GNU General Public License for more details.
16.16 + *
16.17 + * You should have received a copy of the GNU General Public License
16.18 + * along with this program. Look for COPYING file in the top folder.
16.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
16.20 + */
16.21 +package org.apidesign.bck2brwsr.dew;
16.22 +
16.23 +import java.io.ByteArrayInputStream;
16.24 +import java.io.ByteArrayOutputStream;
16.25 +import java.io.IOException;
16.26 +import java.io.InputStream;
16.27 +import java.io.OutputStream;
16.28 +import java.net.URI;
16.29 +import java.net.URISyntaxException;
16.30 +import java.util.ArrayList;
16.31 +import java.util.Arrays;
16.32 +import java.util.HashMap;
16.33 +import java.util.List;
16.34 +import java.util.Map;
16.35 +import java.util.regex.Matcher;
16.36 +import java.util.regex.Pattern;
16.37 +import javax.tools.Diagnostic;
16.38 +import javax.tools.DiagnosticListener;
16.39 +import javax.tools.FileObject;
16.40 +import javax.tools.ForwardingJavaFileManager;
16.41 +import javax.tools.JavaFileManager;
16.42 +import javax.tools.JavaFileObject;
16.43 +import javax.tools.JavaFileObject.Kind;
16.44 +import javax.tools.SimpleJavaFileObject;
16.45 +import javax.tools.StandardJavaFileManager;
16.46 +import javax.tools.StandardLocation;
16.47 +import javax.tools.ToolProvider;
16.48 +
16.49 +/**
16.50 + *
16.51 + * @author Jaroslav Tulach <jtulach@netbeans.org>
16.52 + */
16.53 +final class Compile implements DiagnosticListener<JavaFileObject> {
16.54 + private final List<Diagnostic<? extends JavaFileObject>> errors = new ArrayList<>();
16.55 + private final Map<String, byte[]> classes;
16.56 + private final String pkg;
16.57 + private final String cls;
16.58 +
16.59 + private Compile(String html, String code) throws IOException {
16.60 + this.pkg = findPkg(code);
16.61 + this.cls = findCls(code);
16.62 + classes = compile(html, code);
16.63 + }
16.64 +
16.65 + /** Performs compilation of given HTML page and associated Java code
16.66 + */
16.67 + public static Compile create(String html, String code) throws IOException {
16.68 + return new Compile(html, code);
16.69 + }
16.70 +
16.71 + /** Checks for given class among compiled resources */
16.72 + public byte[] get(String res) {
16.73 + return classes.get(res);
16.74 + }
16.75 +
16.76 + /** Obtains errors created during compilation.
16.77 + */
16.78 + public List<Diagnostic<? extends JavaFileObject>> getErrors() {
16.79 + List<Diagnostic<? extends JavaFileObject>> err = new ArrayList<>();
16.80 + for (Diagnostic<? extends JavaFileObject> diagnostic : errors) {
16.81 + if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
16.82 + err.add(diagnostic);
16.83 + }
16.84 + }
16.85 + return err;
16.86 + }
16.87 +
16.88 + private Map<String, byte[]> compile(final String html, final String code) throws IOException {
16.89 + StandardJavaFileManager sjfm = ToolProvider.getSystemJavaCompiler().getStandardFileManager(this, null, null);
16.90 +
16.91 + final Map<String, ByteArrayOutputStream> class2BAOS = new HashMap<>();
16.92 +
16.93 + JavaFileObject file = new SimpleJavaFileObject(URI.create("mem://mem"), Kind.SOURCE) {
16.94 + @Override
16.95 + public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
16.96 + return code;
16.97 + }
16.98 + };
16.99 + final JavaFileObject htmlFile = new SimpleJavaFileObject(URI.create("mem://mem2"), Kind.OTHER) {
16.100 + @Override
16.101 + public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
16.102 + return html;
16.103 + }
16.104 +
16.105 + @Override
16.106 + public InputStream openInputStream() throws IOException {
16.107 + return new ByteArrayInputStream(html.getBytes());
16.108 + }
16.109 + };
16.110 +
16.111 + final URI scratch;
16.112 + try {
16.113 + scratch = new URI("mem://mem3");
16.114 + } catch (URISyntaxException ex) {
16.115 + throw new IOException(ex);
16.116 + }
16.117 +
16.118 + JavaFileManager jfm = new ForwardingJavaFileManager<JavaFileManager>(sjfm) {
16.119 + @Override
16.120 + public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling) throws IOException {
16.121 + if (kind == Kind.CLASS) {
16.122 + final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
16.123 +
16.124 + class2BAOS.put(className.replace('.', '/') + ".class", buffer);
16.125 + return new SimpleJavaFileObject(sibling.toUri(), kind) {
16.126 + @Override
16.127 + public OutputStream openOutputStream() throws IOException {
16.128 + return buffer;
16.129 + }
16.130 + };
16.131 + }
16.132 +
16.133 + if (kind == Kind.SOURCE) {
16.134 + return new SimpleJavaFileObject(scratch/*sibling.toUri()*/, kind) {
16.135 + private final ByteArrayOutputStream data = new ByteArrayOutputStream();
16.136 + @Override
16.137 + public OutputStream openOutputStream() throws IOException {
16.138 + return data;
16.139 + }
16.140 +
16.141 + @Override
16.142 + public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
16.143 + data.close();
16.144 + return new String(data.toByteArray());
16.145 + }
16.146 + };
16.147 + }
16.148 +
16.149 + throw new IllegalStateException();
16.150 + }
16.151 +
16.152 + @Override
16.153 + public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException {
16.154 + if (location == StandardLocation.SOURCE_PATH) {
16.155 + if (packageName.equals(pkg)) {
16.156 + return htmlFile;
16.157 + }
16.158 + }
16.159 +
16.160 + return null;
16.161 + }
16.162 +
16.163 + };
16.164 +
16.165 + ToolProvider.getSystemJavaCompiler().getTask(null, jfm, this, /*XXX:*/Arrays.asList("-source", "1.7", "-target", "1.7"), null, Arrays.asList(file)).call();
16.166 +
16.167 + Map<String, byte[]> result = new HashMap<>();
16.168 +
16.169 + for (Map.Entry<String, ByteArrayOutputStream> e : class2BAOS.entrySet()) {
16.170 + result.put(e.getKey(), e.getValue().toByteArray());
16.171 + }
16.172 +
16.173 + return result;
16.174 + }
16.175 +
16.176 +
16.177 + @Override
16.178 + public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
16.179 + errors.add(diagnostic);
16.180 + }
16.181 + private static String findPkg(String java) throws IOException {
16.182 + Pattern p = Pattern.compile("package\\p{javaWhitespace}*([\\p{Alnum}\\.]+)\\p{javaWhitespace}*;", Pattern.MULTILINE);
16.183 + Matcher m = p.matcher(java);
16.184 + if (!m.find()) {
16.185 + throw new IOException("Can't find package declaration in the java file");
16.186 + }
16.187 + String pkg = m.group(1);
16.188 + return pkg;
16.189 + }
16.190 + private static String findCls(String java) throws IOException {
16.191 + Pattern p = Pattern.compile("class\\p{javaWhitespace}*([\\p{Alnum}\\.]+)\\p{javaWhitespace}", Pattern.MULTILINE);
16.192 + Matcher m = p.matcher(java);
16.193 + if (!m.find()) {
16.194 + throw new IOException("Can't find package declaration in the java file");
16.195 + }
16.196 + String cls = m.group(1);
16.197 + return cls;
16.198 + }
16.199 +}
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
17.2 +++ b/dew/src/main/java/org/apidesign/bck2brwsr/dew/Dew.java Wed Jan 23 20:16:48 2013 +0100
17.3 @@ -0,0 +1,138 @@
17.4 +/**
17.5 + * Back 2 Browser Bytecode Translator
17.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
17.7 + *
17.8 + * This program is free software: you can redistribute it and/or modify
17.9 + * it under the terms of the GNU General Public License as published by
17.10 + * the Free Software Foundation, version 2 of the License.
17.11 + *
17.12 + * This program is distributed in the hope that it will be useful,
17.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17.15 + * GNU General Public License for more details.
17.16 + *
17.17 + * You should have received a copy of the GNU General Public License
17.18 + * along with this program. Look for COPYING file in the top folder.
17.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
17.20 + */
17.21 +package org.apidesign.bck2brwsr.dew;
17.22 +
17.23 +import java.io.ByteArrayInputStream;
17.24 +import java.io.IOException;
17.25 +import java.io.InputStream;
17.26 +import java.io.InputStreamReader;
17.27 +import java.io.OutputStream;
17.28 +import java.util.List;
17.29 +import java.util.Locale;
17.30 +import javax.tools.Diagnostic;
17.31 +import javax.tools.JavaFileObject;
17.32 +import org.apidesign.vm4brwsr.Bck2Brwsr;
17.33 +import org.glassfish.grizzly.http.Method;
17.34 +import org.glassfish.grizzly.http.server.HttpHandler;
17.35 +import org.glassfish.grizzly.http.server.HttpServer;
17.36 +import org.glassfish.grizzly.http.server.Request;
17.37 +import org.glassfish.grizzly.http.server.Response;
17.38 +import org.glassfish.grizzly.http.util.HttpStatus;
17.39 +import org.json.JSONArray;
17.40 +import org.json.JSONObject;
17.41 +import org.json.JSONTokener;
17.42 +
17.43 +/**
17.44 + *
17.45 + * @author phrebejk
17.46 + */
17.47 +final class Dew extends HttpHandler implements Bck2Brwsr.Resources {
17.48 + private String html = "";
17.49 + private Compile data;
17.50 +
17.51 + public static void main(String... args) throws Exception {
17.52 + DewLauncher l = new DewLauncher(null);
17.53 + l.addClassLoader(DewLauncher.class.getClassLoader());
17.54 + final Dew dew = new Dew();
17.55 + HttpServer s = l.initServer(dew);
17.56 + s.getServerConfiguration().addHttpHandler(dew, "/dew/");
17.57 + l.launchServerAndBrwsr(s, "/dew/");
17.58 + System.in.read();
17.59 + }
17.60 +
17.61 + @Override
17.62 + public void service(Request request, Response response) throws Exception {
17.63 +
17.64 + if ( request.getMethod() == Method.POST ) {
17.65 + InputStream is = request.getInputStream();
17.66 + JSONTokener tok = new JSONTokener(new InputStreamReader(is));
17.67 + JSONObject obj = new JSONObject(tok);
17.68 + String tmpHtml = obj.getString("html");
17.69 + String tmpJava = obj.getString("java");
17.70 +
17.71 + Compile res = Compile.create(tmpHtml, tmpJava);
17.72 + List<Diagnostic<? extends JavaFileObject>> err = res.getErrors();
17.73 + if (err.isEmpty()) {
17.74 + data = res;
17.75 + html = tmpHtml;
17.76 + response.getOutputStream().write("[]".getBytes());
17.77 + response.setStatus(HttpStatus.OK_200);
17.78 + } else {
17.79 +
17.80 + JSONArray errors = new JSONArray();
17.81 +
17.82 + for (Diagnostic<? extends JavaFileObject> d : err) {
17.83 + JSONObject e = new JSONObject();
17.84 + e.put("col", d.getColumnNumber());
17.85 + e.put("line", d.getLineNumber());
17.86 + e.put("kind", d.getKind().toString());
17.87 + e.put("msg", d.getMessage(Locale.ENGLISH));
17.88 + errors.put(e);
17.89 + }
17.90 +
17.91 + errors.write(response.getWriter());
17.92 + response.setStatus(HttpStatus.PRECONDITION_FAILED_412);
17.93 + }
17.94 +
17.95 + return;
17.96 + }
17.97 +
17.98 + String r = request.getHttpHandlerPath();
17.99 + if (r == null || r.equals("/")) {
17.100 + r = "index.html";
17.101 + }
17.102 + if (r.equals("/result.html")) {
17.103 + response.setContentType("text/html");
17.104 + response.getOutputBuffer().write(html);
17.105 + response.setStatus(HttpStatus.OK_200);
17.106 + return;
17.107 + }
17.108 +
17.109 + if (r.startsWith("/")) {
17.110 + r = r.substring(1);
17.111 + }
17.112 +
17.113 + if (r.endsWith(".html") || r.endsWith(".xhtml")) {
17.114 + response.setContentType("text/html");
17.115 + }
17.116 + OutputStream os = response.getOutputStream();
17.117 + try (InputStream is = Dew.class.getResourceAsStream(r) ) {
17.118 + copyStream(is, os, request.getRequestURL().toString() );
17.119 + } catch (IOException ex) {
17.120 + response.setDetailMessage(ex.getLocalizedMessage());
17.121 + response.setError();
17.122 + response.setStatus(404);
17.123 + }
17.124 + }
17.125 +
17.126 + static void copyStream(InputStream is, OutputStream os, String baseURL) throws IOException {
17.127 + for (;;) {
17.128 + int ch = is.read();
17.129 + if (ch == -1) {
17.130 + break;
17.131 + }
17.132 + os.write(ch);
17.133 + }
17.134 + }
17.135 +
17.136 + @Override
17.137 + public InputStream get(String r) throws IOException {
17.138 + byte[] arr = data == null ? null : data.get(r);
17.139 + return arr == null ? null : new ByteArrayInputStream(arr);
17.140 + }
17.141 +}
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
18.2 +++ b/dew/src/main/java/org/apidesign/bck2brwsr/dew/DewLauncher.java Wed Jan 23 20:16:48 2013 +0100
18.3 @@ -0,0 +1,201 @@
18.4 +/**
18.5 + * Back 2 Browser Bytecode Translator
18.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
18.7 + *
18.8 + * This program is free software: you can redistribute it and/or modify
18.9 + * it under the terms of the GNU General Public License as published by
18.10 + * the Free Software Foundation, version 2 of the License.
18.11 + *
18.12 + * This program is distributed in the hope that it will be useful,
18.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18.15 + * GNU General Public License for more details.
18.16 + *
18.17 + * You should have received a copy of the GNU General Public License
18.18 + * along with this program. Look for COPYING file in the top folder.
18.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
18.20 + */
18.21 +package org.apidesign.bck2brwsr.dew;
18.22 +
18.23 +import java.io.IOException;
18.24 +import java.io.InputStream;
18.25 +import java.io.Writer;
18.26 +import java.net.URI;
18.27 +import java.net.URISyntaxException;
18.28 +import java.net.URL;
18.29 +import java.util.Arrays;
18.30 +import java.util.Enumeration;
18.31 +import java.util.LinkedHashSet;
18.32 +import java.util.Set;
18.33 +import java.util.logging.Level;
18.34 +import java.util.logging.Logger;
18.35 +import org.apidesign.vm4brwsr.Bck2Brwsr;
18.36 +import org.glassfish.grizzly.PortRange;
18.37 +import org.glassfish.grizzly.http.server.HttpHandler;
18.38 +import org.glassfish.grizzly.http.server.HttpServer;
18.39 +import org.glassfish.grizzly.http.server.NetworkListener;
18.40 +import org.glassfish.grizzly.http.server.Request;
18.41 +import org.glassfish.grizzly.http.server.Response;
18.42 +import org.glassfish.grizzly.http.server.ServerConfiguration;
18.43 +
18.44 +/**
18.45 + * Lightweight server to launch dew - the Development Environment for Web.
18.46 + */
18.47 +final class DewLauncher {
18.48 + private static final Logger LOG = Logger.getLogger(DewLauncher.class.getName());
18.49 + private Set<ClassLoader> loaders = new LinkedHashSet<>();
18.50 + private Set<Bck2Brwsr.Resources> xRes = new LinkedHashSet<>();
18.51 + private final Res resources = new Res();
18.52 + private final String cmd;
18.53 +
18.54 + public DewLauncher(String cmd) {
18.55 + this.cmd = cmd;
18.56 + }
18.57 +
18.58 + public void addClassLoader(ClassLoader url) {
18.59 + this.loaders.add(url);
18.60 + }
18.61 +
18.62 + final HttpServer initServer(Bck2Brwsr.Resources... extraResources) {
18.63 + xRes.addAll(Arrays.asList(extraResources));
18.64 +
18.65 + HttpServer s = HttpServer.createSimpleServer(".", new PortRange(8080, 65535));
18.66 +
18.67 + final ServerConfiguration conf = s.getServerConfiguration();
18.68 + conf.addHttpHandler(new VM(resources), "/bck2brwsr.js");
18.69 + conf.addHttpHandler(new VMInit(), "/vm.js");
18.70 + conf.addHttpHandler(new Classes(resources), "/classes/");
18.71 + return s;
18.72 + }
18.73 +
18.74 + final Object[] launchServerAndBrwsr(HttpServer server, final String page) throws IOException, URISyntaxException, InterruptedException {
18.75 + server.start();
18.76 + NetworkListener listener = server.getListeners().iterator().next();
18.77 + int port = listener.getPort();
18.78 +
18.79 + URI uri = new URI("http://localhost:" + port + page);
18.80 + LOG.log(Level.INFO, "Showing {0}", uri);
18.81 + if (cmd == null) {
18.82 + try {
18.83 + LOG.log(Level.INFO, "Trying Desktop.browse on {0} {2} by {1}", new Object[] {
18.84 + System.getProperty("java.vm.name"),
18.85 + System.getProperty("java.vm.vendor"),
18.86 + System.getProperty("java.vm.version"),
18.87 + });
18.88 + java.awt.Desktop.getDesktop().browse(uri);
18.89 + LOG.log(Level.INFO, "Desktop.browse successfully finished");
18.90 + return null;
18.91 + } catch (UnsupportedOperationException ex) {
18.92 + LOG.log(Level.INFO, "Desktop.browse not supported: {0}", ex.getMessage());
18.93 + LOG.log(Level.FINE, null, ex);
18.94 + }
18.95 + }
18.96 + {
18.97 + String cmdName = cmd == null ? "xdg-open" : cmd;
18.98 + String[] cmdArr = {
18.99 + cmdName, uri.toString()
18.100 + };
18.101 + LOG.log(Level.INFO, "Launching {0}", Arrays.toString(cmdArr));
18.102 + final Process process = Runtime.getRuntime().exec(cmdArr);
18.103 + return new Object[] { process, null };
18.104 + }
18.105 + }
18.106 +
18.107 + private class Res implements Bck2Brwsr.Resources {
18.108 + @Override
18.109 + public InputStream get(String resource) throws IOException {
18.110 + for (ClassLoader l : loaders) {
18.111 + URL u = null;
18.112 + Enumeration<URL> en = l.getResources(resource);
18.113 + while (en.hasMoreElements()) {
18.114 + u = en.nextElement();
18.115 + }
18.116 + if (u != null) {
18.117 + return u.openStream();
18.118 + }
18.119 + }
18.120 + for (Bck2Brwsr.Resources r : xRes) {
18.121 + InputStream is = r.get(resource);
18.122 + if (is != null) {
18.123 + return is;
18.124 + }
18.125 + }
18.126 + throw new IOException("Can't find " + resource);
18.127 + }
18.128 + }
18.129 +
18.130 + private static class VM extends HttpHandler {
18.131 + private final Res loader;
18.132 +
18.133 + public VM(Res loader) {
18.134 + this.loader = loader;
18.135 + }
18.136 +
18.137 + @Override
18.138 + public void service(Request request, Response response) throws Exception {
18.139 + response.setCharacterEncoding("UTF-8");
18.140 + response.setContentType("text/javascript");
18.141 + Bck2Brwsr.generate(response.getWriter(), loader);
18.142 + }
18.143 + }
18.144 + private static class VMInit extends HttpHandler {
18.145 + public VMInit() {
18.146 + }
18.147 +
18.148 + @Override
18.149 + public void service(Request request, Response response) throws Exception {
18.150 + response.setCharacterEncoding("UTF-8");
18.151 + response.setContentType("text/javascript");
18.152 + response.getWriter().append(
18.153 + "function ldCls(res) {\n"
18.154 + + " var request = new XMLHttpRequest();\n"
18.155 + + " request.open('GET', '/classes/' + res, false);\n"
18.156 + + " request.send();\n"
18.157 + + " var arr = eval('(' + request.responseText + ')');\n"
18.158 + + " return arr;\n"
18.159 + + "}\n"
18.160 + + "var vm = new bck2brwsr(ldCls);\n");
18.161 + }
18.162 + }
18.163 +
18.164 + private static class Classes extends HttpHandler {
18.165 + private final Res loader;
18.166 +
18.167 + public Classes(Res loader) {
18.168 + this.loader = loader;
18.169 + }
18.170 +
18.171 + @Override
18.172 + public void service(Request request, Response response) throws Exception {
18.173 + String res = request.getHttpHandlerPath();
18.174 + if (res.startsWith("/")) {
18.175 + res = res.substring(1);
18.176 + }
18.177 + try (InputStream is = loader.get(res)) {
18.178 + response.setContentType("text/javascript");
18.179 + Writer w = response.getWriter();
18.180 + w.append("[");
18.181 + for (int i = 0;; i++) {
18.182 + int b = is.read();
18.183 + if (b == -1) {
18.184 + break;
18.185 + }
18.186 + if (i > 0) {
18.187 + w.append(", ");
18.188 + }
18.189 + if (i % 20 == 0) {
18.190 + w.write("\n");
18.191 + }
18.192 + if (b > 127) {
18.193 + b = b - 256;
18.194 + }
18.195 + w.append(Integer.toString(b));
18.196 + }
18.197 + w.append("\n]");
18.198 + } catch (IOException ex) {
18.199 + response.setError();
18.200 + response.setDetailMessage(ex.getMessage());
18.201 + }
18.202 + }
18.203 + }
18.204 +}
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
19.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/css/app.css Wed Jan 23 20:16:48 2013 +0100
19.3 @@ -0,0 +1,54 @@
19.4 +/* app css stylesheet */
19.5 +.code-editor, .mono-font, .CodeMirror {
19.6 + font-family: "Inconsolata","Monaco","Consolas","Andale Mono","Bitstream Vera Sans Mono","Courier New",Courier,monospace;
19.7 + font-size: 13px;
19.8 + line-height: 15px;
19.9 +}
19.10 +
19.11 +.CodeMirror {
19.12 + border: 1px solid #d9edf7;
19.13 + height: 300px;
19.14 +}
19.15 +
19.16 +.CodeMirror-scroll {
19.17 + overflow-y: auto;
19.18 + overflow-x: auto;
19.19 +}
19.20 +
19.21 +.error-hover:hover {
19.22 + text-decoration: underline;
19.23 + cursor: pointer;
19.24 +}
19.25 +
19.26 +.ic-html5 {
19.27 + display: inline-block;
19.28 + height: 20px;
19.29 + width: 20px;
19.30 + vertical-align: text-bottom;
19.31 + background-repeat: no-repeat;
19.32 + background-image: url("../img/html5.png");
19.33 +}
19.34 +
19.35 +.ic-java {
19.36 + display: inline-block;
19.37 + height: 20px;
19.38 + width: 20px;
19.39 + vertical-align: text-bottom;
19.40 + background-repeat: no-repeat;
19.41 + background-image: url("../img/java.png");
19.42 +
19.43 +}
19.44 +
19.45 +.issues {
19.46 + width: 16px;
19.47 +}
19.48 +
19.49 +.issue {
19.50 + height: 16px;
19.51 + width: 16px;
19.52 + vertical-align: middle;
19.53 + background-repeat: no-repeat;
19.54 + background-image: url("../img/error.png");
19.55 + /* color: #822; */
19.56 +}
19.57 +
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
20.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/css/bootstrap-combined.min.css Wed Jan 23 20:16:48 2013 +0100
20.3 @@ -0,0 +1,18 @@
20.4 +/*!
20.5 + * Bootstrap v2.2.2
20.6 + *
20.7 + * Copyright 2012 Twitter, Inc
20.8 + * Licensed under the Apache License v2.0
20.9 + * http://www.apache.org/licenses/LICENSE-2.0
20.10 + *
20.11 + * Designed and built with all the love in the world @twitter by @mdo and @fat.
20.12 + */article,aside,details,figcaption,figure,footer,header,hgroup,nav,section{display:block}audio,canvas,video{display:inline-block;*display:inline;*zoom:1}audio:not([controls]){display:none}html{font-size:100%;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}a:focus{outline:thin dotted #333;outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}a:hover,a:active{outline:0}sub,sup{position:relative;font-size:75%;line-height:0;vertical-align:baseline}sup{top:-0.5em}sub{bottom:-0.25em}img{width:auto\9;height:auto;max-width:100%;vertical-align:middle;border:0;-ms-interpolation-mode:bicubic}#map_canvas img,.google-maps img{max-width:none}button,input,select,textarea{margin:0;font-size:100%;vertical-align:middle}button,input{*overflow:visible;line-height:normal}button::-moz-focus-inner,input::-moz-focus-inner{padding:0;border:0}button,html input[type="button"],input[type="reset"],input[type="submit"]{cursor:pointer;-webkit-appearance:button}label,select,button,input[type="button"],input[type="reset"],input[type="submit"],input[type="radio"],input[type="checkbox"]{cursor:pointer}input[type="search"]{-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;-webkit-appearance:textfield}input[type="search"]::-webkit-search-decoration,input[type="search"]::-webkit-search-cancel-button{-webkit-appearance:none}textarea{overflow:auto;vertical-align:top}@media print{*{color:#000!important;text-shadow:none!important;background:transparent!important;box-shadow:none!important}a,a:visited{text-decoration:underline}a[href]:after{content:" (" attr(href) ")"}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100%!important}@page{margin:.5cm}p,h2,h3{orphans:3;widows:3}h2,h3{page-break-after:avoid}}.clearfix{*zoom:1}.clearfix:before,.clearfix:after{display:table;line-height:0;content:""}.clearfix:after{clear:both}.hide-text{font:0/0 a;color:transparent;text-shadow:none;background-color:transparent;border:0}.input-block-level{display:block;width:100%;min-height:30px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}body{margin:0;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px;line-height:20px;color:#333;background-color:#fff}a{color:#08c;text-decoration:none}a:hover{color:#005580;text-decoration:underline}.img-rounded{-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}.img-polaroid{padding:4px;background-color:#fff;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.2);-webkit-box-shadow:0 1px 3px rgba(0,0,0,0.1);-moz-box-shadow:0 1px 3px rgba(0,0,0,0.1);box-shadow:0 1px 3px rgba(0,0,0,0.1)}.img-circle{-webkit-border-radius:500px;-moz-border-radius:500px;border-radius:500px}.row{margin-left:-20px;*zoom:1}.row:before,.row:after{display:table;line-height:0;content:""}.row:after{clear:both}[class*="span"]{float:left;min-height:1px;margin-left:20px}.container,.navbar-static-top .container,.navbar-fixed-top .container,.navbar-fixed-bottom .container{width:940px}.span12{width:940px}.span11{width:860px}.span10{width:780px}.span9{width:700px}.span8{width:620px}.span7{width:540px}.span6{width:460px}.span5{width:380px}.span4{width:300px}.span3{width:220px}.span2{width:140px}.span1{width:60px}.offset12{margin-left:980px}.offset11{margin-left:900px}.offset10{margin-left:820px}.offset9{margin-left:740px}.offset8{margin-left:660px}.offset7{margin-left:580px}.offset6{margin-left:500px}.offset5{margin-left:420px}.offset4{margin-left:340px}.offset3{margin-left:260px}.offset2{margin-left:180px}.offset1{margin-left:100px}.row-fluid{width:100%;*zoom:1}.row-fluid:before,.row-fluid:after{display:table;line-height:0;content:""}.row-fluid:after{clear:both}.row-fluid [class*="span"]{display:block;float:left;width:100%;min-height:30px;margin-left:2.127659574468085%;*margin-left:2.074468085106383%;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.row-fluid [class*="span"]:first-child{margin-left:0}.row-fluid .controls-row [class*="span"]+[class*="span"]{margin-left:2.127659574468085%}.row-fluid .span12{width:100%;*width:99.94680851063829%}.row-fluid .span11{width:91.48936170212765%;*width:91.43617021276594%}.row-fluid .span10{width:82.97872340425532%;*width:82.92553191489361%}.row-fluid .span9{width:74.46808510638297%;*width:74.41489361702126%}.row-fluid .span8{width:65.95744680851064%;*width:65.90425531914893%}.row-fluid .span7{width:57.44680851063829%;*width:57.39361702127659%}.row-fluid .span6{width:48.93617021276595%;*width:48.88297872340425%}.row-fluid .span5{width:40.42553191489362%;*width:40.37234042553192%}.row-fluid .span4{width:31.914893617021278%;*width:31.861702127659576%}.row-fluid .span3{width:23.404255319148934%;*width:23.351063829787233%}.row-fluid .span2{width:14.893617021276595%;*width:14.840425531914894%}.row-fluid .span1{width:6.382978723404255%;*width:6.329787234042553%}.row-fluid .offset12{margin-left:104.25531914893617%;*margin-left:104.14893617021275%}.row-fluid .offset12:first-child{margin-left:102.12765957446808%;*margin-left:102.02127659574467%}.row-fluid .offset11{margin-left:95.74468085106382%;*margin-left:95.6382978723404%}.row-fluid .offset11:first-child{margin-left:93.61702127659574%;*margin-left:93.51063829787232%}.row-fluid .offset10{margin-left:87.23404255319149%;*margin-left:87.12765957446807%}.row-fluid .offset10:first-child{margin-left:85.1063829787234%;*margin-left:84.99999999999999%}.row-fluid .offset9{margin-left:78.72340425531914%;*margin-left:78.61702127659572%}.row-fluid .offset9:first-child{margin-left:76.59574468085106%;*margin-left:76.48936170212764%}.row-fluid .offset8{margin-left:70.2127659574468%;*margin-left:70.10638297872339%}.row-fluid .offset8:first-child{margin-left:68.08510638297872%;*margin-left:67.9787234042553%}.row-fluid .offset7{margin-left:61.70212765957446%;*margin-left:61.59574468085106%}.row-fluid .offset7:first-child{margin-left:59.574468085106375%;*margin-left:59.46808510638297%}.row-fluid .offset6{margin-left:53.191489361702125%;*margin-left:53.085106382978715%}.row-fluid .offset6:first-child{margin-left:51.063829787234035%;*margin-left:50.95744680851063%}.row-fluid .offset5{margin-left:44.68085106382979%;*margin-left:44.57446808510638%}.row-fluid .offset5:first-child{margin-left:42.5531914893617%;*margin-left:42.4468085106383%}.row-fluid .offset4{margin-left:36.170212765957444%;*margin-left:36.06382978723405%}.row-fluid .offset4:first-child{margin-left:34.04255319148936%;*margin-left:33.93617021276596%}.row-fluid .offset3{margin-left:27.659574468085104%;*margin-left:27.5531914893617%}.row-fluid .offset3:first-child{margin-left:25.53191489361702%;*margin-left:25.425531914893618%}.row-fluid .offset2{margin-left:19.148936170212764%;*margin-left:19.04255319148936%}.row-fluid .offset2:first-child{margin-left:17.02127659574468%;*margin-left:16.914893617021278%}.row-fluid .offset1{margin-left:10.638297872340425%;*margin-left:10.53191489361702%}.row-fluid .offset1:first-child{margin-left:8.51063829787234%;*margin-left:8.404255319148938%}[class*="span"].hide,.row-fluid [class*="span"].hide{display:none}[class*="span"].pull-right,.row-fluid [class*="span"].pull-right{float:right}.container{margin-right:auto;margin-left:auto;*zoom:1}.container:before,.container:after{display:table;line-height:0;content:""}.container:after{clear:both}.container-fluid{padding-right:20px;padding-left:20px;*zoom:1}.container-fluid:before,.container-fluid:after{display:table;line-height:0;content:""}.container-fluid:after{clear:both}p{margin:0 0 10px}.lead{margin-bottom:20px;font-size:21px;font-weight:200;line-height:30px}small{font-size:85%}strong{font-weight:bold}em{font-style:italic}cite{font-style:normal}.muted{color:#999}a.muted:hover{color:#808080}.text-warning{color:#c09853}a.text-warning:hover{color:#a47e3c}.text-error{color:#b94a48}a.text-error:hover{color:#953b39}.text-info{color:#3a87ad}a.text-info:hover{color:#2d6987}.text-success{color:#468847}a.text-success:hover{color:#356635}h1,h2,h3,h4,h5,h6{margin:10px 0;font-family:inherit;font-weight:bold;line-height:20px;color:inherit;text-rendering:optimizelegibility}h1 small,h2 small,h3 small,h4 small,h5 small,h6 small{font-weight:normal;line-height:1;color:#999}h1,h2,h3{line-height:40px}h1{font-size:38.5px}h2{font-size:31.5px}h3{font-size:24.5px}h4{font-size:17.5px}h5{font-size:14px}h6{font-size:11.9px}h1 small{font-size:24.5px}h2 small{font-size:17.5px}h3 small{font-size:14px}h4 small{font-size:14px}.page-header{padding-bottom:9px;margin:20px 0 30px;border-bottom:1px solid #eee}ul,ol{padding:0;margin:0 0 10px 25px}ul ul,ul ol,ol ol,ol ul{margin-bottom:0}li{line-height:20px}ul.unstyled,ol.unstyled{margin-left:0;list-style:none}ul.inline,ol.inline{margin-left:0;list-style:none}ul.inline>li,ol.inline>li{display:inline-block;padding-right:5px;padding-left:5px}dl{margin-bottom:20px}dt,dd{line-height:20px}dt{font-weight:bold}dd{margin-left:10px}.dl-horizontal{*zoom:1}.dl-horizontal:before,.dl-horizontal:after{display:table;line-height:0;content:""}.dl-horizontal:after{clear:both}.dl-horizontal dt{float:left;width:160px;overflow:hidden;clear:left;text-align:right;text-overflow:ellipsis;white-space:nowrap}.dl-horizontal dd{margin-left:180px}hr{margin:20px 0;border:0;border-top:1px solid #eee;border-bottom:1px solid #fff}abbr[title],abbr[data-original-title]{cursor:help;border-bottom:1px dotted #999}abbr.initialism{font-size:90%;text-transform:uppercase}blockquote{padding:0 0 0 15px;margin:0 0 20px;border-left:5px solid #eee}blockquote p{margin-bottom:0;font-size:16px;font-weight:300;line-height:25px}blockquote small{display:block;line-height:20px;color:#999}blockquote small:before{content:'\2014 \00A0'}blockquote.pull-right{float:right;padding-right:15px;padding-left:0;border-right:5px solid #eee;border-left:0}blockquote.pull-right p,blockquote.pull-right small{text-align:right}blockquote.pull-right small:before{content:''}blockquote.pull-right small:after{content:'\00A0 \2014'}q:before,q:after,blockquote:before,blockquote:after{content:""}address{display:block;margin-bottom:20px;font-style:normal;line-height:20px}code,pre{padding:0 3px 2px;font-family:Monaco,Menlo,Consolas,"Courier New",monospace;font-size:12px;color:#333;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}code{padding:2px 4px;color:#d14;white-space:nowrap;background-color:#f7f7f9;border:1px solid #e1e1e8}pre{display:block;padding:9.5px;margin:0 0 10px;font-size:13px;line-height:20px;word-break:break-all;word-wrap:break-word;white-space:pre;white-space:pre-wrap;background-color:#f5f5f5;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.15);-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}pre.prettyprint{margin-bottom:20px}pre code{padding:0;color:inherit;white-space:pre;white-space:pre-wrap;background-color:transparent;border:0}.pre-scrollable{max-height:340px;overflow-y:scroll}form{margin:0 0 20px}fieldset{padding:0;margin:0;border:0}legend{display:block;width:100%;padding:0;margin-bottom:20px;font-size:21px;line-height:40px;color:#333;border:0;border-bottom:1px solid #e5e5e5}legend small{font-size:15px;color:#999}label,input,button,select,textarea{font-size:14px;font-weight:normal;line-height:20px}input,button,select,textarea{font-family:"Helvetica Neue",Helvetica,Arial,sans-serif}label{display:block;margin-bottom:5px}select,textarea,input[type="text"],input[type="password"],input[type="datetime"],input[type="datetime-local"],input[type="date"],input[type="month"],input[type="time"],input[type="week"],input[type="number"],input[type="email"],input[type="url"],input[type="search"],input[type="tel"],input[type="color"],.uneditable-input{display:inline-block;height:20px;padding:4px 6px;margin-bottom:10px;font-size:14px;line-height:20px;color:#555;vertical-align:middle;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}input,textarea,.uneditable-input{width:206px}textarea{height:auto}textarea,input[type="text"],input[type="password"],input[type="datetime"],input[type="datetime-local"],input[type="date"],input[type="month"],input[type="time"],input[type="week"],input[type="number"],input[type="email"],input[type="url"],input[type="search"],input[type="tel"],input[type="color"],.uneditable-input{background-color:#fff;border:1px solid #ccc;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-webkit-transition:border linear .2s,box-shadow linear .2s;-moz-transition:border linear .2s,box-shadow linear .2s;-o-transition:border linear .2s,box-shadow linear .2s;transition:border linear .2s,box-shadow linear .2s}textarea:focus,input[type="text"]:focus,input[type="password"]:focus,input[type="datetime"]:focus,input[type="datetime-local"]:focus,input[type="date"]:focus,input[type="month"]:focus,input[type="time"]:focus,input[type="week"]:focus,input[type="number"]:focus,input[type="email"]:focus,input[type="url"]:focus,input[type="search"]:focus,input[type="tel"]:focus,input[type="color"]:focus,.uneditable-input:focus{border-color:rgba(82,168,236,0.8);outline:0;outline:thin dotted \9;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(82,168,236,0.6);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(82,168,236,0.6);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(82,168,236,0.6)}input[type="radio"],input[type="checkbox"]{margin:4px 0 0;margin-top:1px \9;*margin-top:0;line-height:normal}input[type="file"],input[type="image"],input[type="submit"],input[type="reset"],input[type="button"],input[type="radio"],input[type="checkbox"]{width:auto}select,input[type="file"]{height:30px;*margin-top:4px;line-height:30px}select{width:220px;background-color:#fff;border:1px solid #ccc}select[multiple],select[size]{height:auto}select:focus,input[type="file"]:focus,input[type="radio"]:focus,input[type="checkbox"]:focus{outline:thin dotted #333;outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}.uneditable-input,.uneditable-textarea{color:#999;cursor:not-allowed;background-color:#fcfcfc;border-color:#ccc;-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.025);-moz-box-shadow:inset 0 1px 2px rgba(0,0,0,0.025);box-shadow:inset 0 1px 2px rgba(0,0,0,0.025)}.uneditable-input{overflow:hidden;white-space:nowrap}.uneditable-textarea{width:auto;height:auto}input:-moz-placeholder,textarea:-moz-placeholder{color:#999}input:-ms-input-placeholder,textarea:-ms-input-placeholder{color:#999}input::-webkit-input-placeholder,textarea::-webkit-input-placeholder{color:#999}.radio,.checkbox{min-height:20px;padding-left:20px}.radio input[type="radio"],.checkbox input[type="checkbox"]{float:left;margin-left:-20px}.controls>.radio:first-child,.controls>.checkbox:first-child{padding-top:5px}.radio.inline,.checkbox.inline{display:inline-block;padding-top:5px;margin-bottom:0;vertical-align:middle}.radio.inline+.radio.inline,.checkbox.inline+.checkbox.inline{margin-left:10px}.input-mini{width:60px}.input-small{width:90px}.input-medium{width:150px}.input-large{width:210px}.input-xlarge{width:270px}.input-xxlarge{width:530px}input[class*="span"],select[class*="span"],textarea[class*="span"],.uneditable-input[class*="span"],.row-fluid input[class*="span"],.row-fluid select[class*="span"],.row-fluid textarea[class*="span"],.row-fluid .uneditable-input[class*="span"]{float:none;margin-left:0}.input-append input[class*="span"],.input-append .uneditable-input[class*="span"],.input-prepend input[class*="span"],.input-prepend .uneditable-input[class*="span"],.row-fluid input[class*="span"],.row-fluid select[class*="span"],.row-fluid textarea[class*="span"],.row-fluid .uneditable-input[class*="span"],.row-fluid .input-prepend [class*="span"],.row-fluid .input-append [class*="span"]{display:inline-block}input,textarea,.uneditable-input{margin-left:0}.controls-row [class*="span"]+[class*="span"]{margin-left:20px}input.span12,textarea.span12,.uneditable-input.span12{width:926px}input.span11,textarea.span11,.uneditable-input.span11{width:846px}input.span10,textarea.span10,.uneditable-input.span10{width:766px}input.span9,textarea.span9,.uneditable-input.span9{width:686px}input.span8,textarea.span8,.uneditable-input.span8{width:606px}input.span7,textarea.span7,.uneditable-input.span7{width:526px}input.span6,textarea.span6,.uneditable-input.span6{width:446px}input.span5,textarea.span5,.uneditable-input.span5{width:366px}input.span4,textarea.span4,.uneditable-input.span4{width:286px}input.span3,textarea.span3,.uneditable-input.span3{width:206px}input.span2,textarea.span2,.uneditable-input.span2{width:126px}input.span1,textarea.span1,.uneditable-input.span1{width:46px}.controls-row{*zoom:1}.controls-row:before,.controls-row:after{display:table;line-height:0;content:""}.controls-row:after{clear:both}.controls-row [class*="span"],.row-fluid .controls-row [class*="span"]{float:left}.controls-row .checkbox[class*="span"],.controls-row .radio[class*="span"]{padding-top:5px}input[disabled],select[disabled],textarea[disabled],input[readonly],select[readonly],textarea[readonly]{cursor:not-allowed;background-color:#eee}input[type="radio"][disabled],input[type="checkbox"][disabled],input[type="radio"][readonly],input[type="checkbox"][readonly]{background-color:transparent}.control-group.warning .control-label,.control-group.warning .help-block,.control-group.warning .help-inline{color:#c09853}.control-group.warning .checkbox,.control-group.warning .radio,.control-group.warning input,.control-group.warning select,.control-group.warning textarea{color:#c09853}.control-group.warning input,.control-group.warning select,.control-group.warning textarea{border-color:#c09853;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075)}.control-group.warning input:focus,.control-group.warning select:focus,.control-group.warning textarea:focus{border-color:#a47e3c;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #dbc59e;-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #dbc59e;box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #dbc59e}.control-group.warning .input-prepend .add-on,.control-group.warning .input-append .add-on{color:#c09853;background-color:#fcf8e3;border-color:#c09853}.control-group.error .control-label,.control-group.error .help-block,.control-group.error .help-inline{color:#b94a48}.control-group.error .checkbox,.control-group.error .radio,.control-group.error input,.control-group.error select,.control-group.error textarea{color:#b94a48}.control-group.error input,.control-group.error select,.control-group.error textarea{border-color:#b94a48;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075)}.control-group.error input:focus,.control-group.error select:focus,.control-group.error textarea:focus{border-color:#953b39;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #d59392;-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #d59392;box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #d59392}.control-group.error .input-prepend .add-on,.control-group.error .input-append .add-on{color:#b94a48;background-color:#f2dede;border-color:#b94a48}.control-group.success .control-label,.control-group.success .help-block,.control-group.success .help-inline{color:#468847}.control-group.success .checkbox,.control-group.success .radio,.control-group.success input,.control-group.success select,.control-group.success textarea{color:#468847}.control-group.success input,.control-group.success select,.control-group.success textarea{border-color:#468847;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075)}.control-group.success input:focus,.control-group.success select:focus,.control-group.success textarea:focus{border-color:#356635;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #7aba7b;-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #7aba7b;box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #7aba7b}.control-group.success .input-prepend .add-on,.control-group.success .input-append .add-on{color:#468847;background-color:#dff0d8;border-color:#468847}.control-group.info .control-label,.control-group.info .help-block,.control-group.info .help-inline{color:#3a87ad}.control-group.info .checkbox,.control-group.info .radio,.control-group.info input,.control-group.info select,.control-group.info textarea{color:#3a87ad}.control-group.info input,.control-group.info select,.control-group.info textarea{border-color:#3a87ad;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075)}.control-group.info input:focus,.control-group.info select:focus,.control-group.info textarea:focus{border-color:#2d6987;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #7ab5d3;-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #7ab5d3;box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #7ab5d3}.control-group.info .input-prepend .add-on,.control-group.info .input-append .add-on{color:#3a87ad;background-color:#d9edf7;border-color:#3a87ad}input:focus:invalid,textarea:focus:invalid,select:focus:invalid{color:#b94a48;border-color:#ee5f5b}input:focus:invalid:focus,textarea:focus:invalid:focus,select:focus:invalid:focus{border-color:#e9322d;-webkit-box-shadow:0 0 6px #f8b9b7;-moz-box-shadow:0 0 6px #f8b9b7;box-shadow:0 0 6px #f8b9b7}.form-actions{padding:19px 20px 20px;margin-top:20px;margin-bottom:20px;background-color:#f5f5f5;border-top:1px solid #e5e5e5;*zoom:1}.form-actions:before,.form-actions:after{display:table;line-height:0;content:""}.form-actions:after{clear:both}.help-block,.help-inline{color:#595959}.help-block{display:block;margin-bottom:10px}.help-inline{display:inline-block;*display:inline;padding-left:5px;vertical-align:middle;*zoom:1}.input-append,.input-prepend{margin-bottom:5px;font-size:0;white-space:nowrap}.input-append input,.input-prepend input,.input-append select,.input-prepend select,.input-append .uneditable-input,.input-prepend .uneditable-input,.input-append .dropdown-menu,.input-prepend .dropdown-menu{font-size:14px}.input-append input,.input-prepend input,.input-append select,.input-prepend select,.input-append .uneditable-input,.input-prepend .uneditable-input{position:relative;margin-bottom:0;*margin-left:0;vertical-align:top;-webkit-border-radius:0 4px 4px 0;-moz-border-radius:0 4px 4px 0;border-radius:0 4px 4px 0}.input-append input:focus,.input-prepend input:focus,.input-append select:focus,.input-prepend select:focus,.input-append .uneditable-input:focus,.input-prepend .uneditable-input:focus{z-index:2}.input-append .add-on,.input-prepend .add-on{display:inline-block;width:auto;height:20px;min-width:16px;padding:4px 5px;font-size:14px;font-weight:normal;line-height:20px;text-align:center;text-shadow:0 1px 0 #fff;background-color:#eee;border:1px solid #ccc}.input-append .add-on,.input-prepend .add-on,.input-append .btn,.input-prepend .btn,.input-append .btn-group>.dropdown-toggle,.input-prepend .btn-group>.dropdown-toggle{vertical-align:top;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.input-append .active,.input-prepend .active{background-color:#a9dba9;border-color:#46a546}.input-prepend .add-on,.input-prepend .btn{margin-right:-1px}.input-prepend .add-on:first-child,.input-prepend .btn:first-child{-webkit-border-radius:4px 0 0 4px;-moz-border-radius:4px 0 0 4px;border-radius:4px 0 0 4px}.input-append input,.input-append select,.input-append .uneditable-input{-webkit-border-radius:4px 0 0 4px;-moz-border-radius:4px 0 0 4px;border-radius:4px 0 0 4px}.input-append input+.btn-group .btn:last-child,.input-append select+.btn-group .btn:last-child,.input-append .uneditable-input+.btn-group .btn:last-child{-webkit-border-radius:0 4px 4px 0;-moz-border-radius:0 4px 4px 0;border-radius:0 4px 4px 0}.input-append .add-on,.input-append .btn,.input-append .btn-group{margin-left:-1px}.input-append .add-on:last-child,.input-append .btn:last-child,.input-append .btn-group:last-child>.dropdown-toggle{-webkit-border-radius:0 4px 4px 0;-moz-border-radius:0 4px 4px 0;border-radius:0 4px 4px 0}.input-prepend.input-append input,.input-prepend.input-append select,.input-prepend.input-append .uneditable-input{-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.input-prepend.input-append input+.btn-group .btn,.input-prepend.input-append select+.btn-group .btn,.input-prepend.input-append .uneditable-input+.btn-group .btn{-webkit-border-radius:0 4px 4px 0;-moz-border-radius:0 4px 4px 0;border-radius:0 4px 4px 0}.input-prepend.input-append .add-on:first-child,.input-prepend.input-append .btn:first-child{margin-right:-1px;-webkit-border-radius:4px 0 0 4px;-moz-border-radius:4px 0 0 4px;border-radius:4px 0 0 4px}.input-prepend.input-append .add-on:last-child,.input-prepend.input-append .btn:last-child{margin-left:-1px;-webkit-border-radius:0 4px 4px 0;-moz-border-radius:0 4px 4px 0;border-radius:0 4px 4px 0}.input-prepend.input-append .btn-group:first-child{margin-left:0}input.search-query{padding-right:14px;padding-right:4px \9;padding-left:14px;padding-left:4px \9;margin-bottom:0;-webkit-border-radius:15px;-moz-border-radius:15px;border-radius:15px}.form-search .input-append .search-query,.form-search .input-prepend .search-query{-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.form-search .input-append .search-query{-webkit-border-radius:14px 0 0 14px;-moz-border-radius:14px 0 0 14px;border-radius:14px 0 0 14px}.form-search .input-append .btn{-webkit-border-radius:0 14px 14px 0;-moz-border-radius:0 14px 14px 0;border-radius:0 14px 14px 0}.form-search .input-prepend .search-query{-webkit-border-radius:0 14px 14px 0;-moz-border-radius:0 14px 14px 0;border-radius:0 14px 14px 0}.form-search .input-prepend .btn{-webkit-border-radius:14px 0 0 14px;-moz-border-radius:14px 0 0 14px;border-radius:14px 0 0 14px}.form-search input,.form-inline input,.form-horizontal input,.form-search textarea,.form-inline textarea,.form-horizontal textarea,.form-search select,.form-inline select,.form-horizontal select,.form-search .help-inline,.form-inline .help-inline,.form-horizontal .help-inline,.form-search .uneditable-input,.form-inline .uneditable-input,.form-horizontal .uneditable-input,.form-search .input-prepend,.form-inline .input-prepend,.form-horizontal .input-prepend,.form-search .input-append,.form-inline .input-append,.form-horizontal .input-append{display:inline-block;*display:inline;margin-bottom:0;vertical-align:middle;*zoom:1}.form-search .hide,.form-inline .hide,.form-horizontal .hide{display:none}.form-search label,.form-inline label,.form-search .btn-group,.form-inline .btn-group{display:inline-block}.form-search .input-append,.form-inline .input-append,.form-search .input-prepend,.form-inline .input-prepend{margin-bottom:0}.form-search .radio,.form-search .checkbox,.form-inline .radio,.form-inline .checkbox{padding-left:0;margin-bottom:0;vertical-align:middle}.form-search .radio input[type="radio"],.form-search .checkbox input[type="checkbox"],.form-inline .radio input[type="radio"],.form-inline .checkbox input[type="checkbox"]{float:left;margin-right:3px;margin-left:0}.control-group{margin-bottom:10px}legend+.control-group{margin-top:20px;-webkit-margin-top-collapse:separate}.form-horizontal .control-group{margin-bottom:20px;*zoom:1}.form-horizontal .control-group:before,.form-horizontal .control-group:after{display:table;line-height:0;content:""}.form-horizontal .control-group:after{clear:both}.form-horizontal .control-label{float:left;width:160px;padding-top:5px;text-align:right}.form-horizontal .controls{*display:inline-block;*padding-left:20px;margin-left:180px;*margin-left:0}.form-horizontal .controls:first-child{*padding-left:180px}.form-horizontal .help-block{margin-bottom:0}.form-horizontal input+.help-block,.form-horizontal select+.help-block,.form-horizontal textarea+.help-block,.form-horizontal .uneditable-input+.help-block,.form-horizontal .input-prepend+.help-block,.form-horizontal .input-append+.help-block{margin-top:10px}.form-horizontal .form-actions{padding-left:180px}table{max-width:100%;background-color:transparent;border-collapse:collapse;border-spacing:0}.table{width:100%;margin-bottom:20px}.table th,.table td{padding:8px;line-height:20px;text-align:left;vertical-align:top;border-top:1px solid #ddd}.table th{font-weight:bold}.table thead th{vertical-align:bottom}.table caption+thead tr:first-child th,.table caption+thead tr:first-child td,.table colgroup+thead tr:first-child th,.table colgroup+thead tr:first-child td,.table thead:first-child tr:first-child th,.table thead:first-child tr:first-child td{border-top:0}.table tbody+tbody{border-top:2px solid #ddd}.table .table{background-color:#fff}.table-condensed th,.table-condensed td{padding:4px 5px}.table-bordered{border:1px solid #ddd;border-collapse:separate;*border-collapse:collapse;border-left:0;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.table-bordered th,.table-bordered td{border-left:1px solid #ddd}.table-bordered caption+thead tr:first-child th,.table-bordered caption+tbody tr:first-child th,.table-bordered caption+tbody tr:first-child td,.table-bordered colgroup+thead tr:first-child th,.table-bordered colgroup+tbody tr:first-child th,.table-bordered colgroup+tbody tr:first-child td,.table-bordered thead:first-child tr:first-child th,.table-bordered tbody:first-child tr:first-child th,.table-bordered tbody:first-child tr:first-child td{border-top:0}.table-bordered thead:first-child tr:first-child>th:first-child,.table-bordered tbody:first-child tr:first-child>td:first-child{-webkit-border-top-left-radius:4px;border-top-left-radius:4px;-moz-border-radius-topleft:4px}.table-bordered thead:first-child tr:first-child>th:last-child,.table-bordered tbody:first-child tr:first-child>td:last-child{-webkit-border-top-right-radius:4px;border-top-right-radius:4px;-moz-border-radius-topright:4px}.table-bordered thead:last-child tr:last-child>th:first-child,.table-bordered tbody:last-child tr:last-child>td:first-child,.table-bordered tfoot:last-child tr:last-child>td:first-child{-webkit-border-bottom-left-radius:4px;border-bottom-left-radius:4px;-moz-border-radius-bottomleft:4px}.table-bordered thead:last-child tr:last-child>th:last-child,.table-bordered tbody:last-child tr:last-child>td:last-child,.table-bordered tfoot:last-child tr:last-child>td:last-child{-webkit-border-bottom-right-radius:4px;border-bottom-right-radius:4px;-moz-border-radius-bottomright:4px}.table-bordered tfoot+tbody:last-child tr:last-child td:first-child{-webkit-border-bottom-left-radius:0;border-bottom-left-radius:0;-moz-border-radius-bottomleft:0}.table-bordered tfoot+tbody:last-child tr:last-child td:last-child{-webkit-border-bottom-right-radius:0;border-bottom-right-radius:0;-moz-border-radius-bottomright:0}.table-bordered caption+thead tr:first-child th:first-child,.table-bordered caption+tbody tr:first-child td:first-child,.table-bordered colgroup+thead tr:first-child th:first-child,.table-bordered colgroup+tbody tr:first-child td:first-child{-webkit-border-top-left-radius:4px;border-top-left-radius:4px;-moz-border-radius-topleft:4px}.table-bordered caption+thead tr:first-child th:last-child,.table-bordered caption+tbody tr:first-child td:last-child,.table-bordered colgroup+thead tr:first-child th:last-child,.table-bordered colgroup+tbody tr:first-child td:last-child{-webkit-border-top-right-radius:4px;border-top-right-radius:4px;-moz-border-radius-topright:4px}.table-striped tbody>tr:nth-child(odd)>td,.table-striped tbody>tr:nth-child(odd)>th{background-color:#f9f9f9}.table-hover tbody tr:hover td,.table-hover tbody tr:hover th{background-color:#f5f5f5}table td[class*="span"],table th[class*="span"],.row-fluid table td[class*="span"],.row-fluid table th[class*="span"]{display:table-cell;float:none;margin-left:0}.table td.span1,.table th.span1{float:none;width:44px;margin-left:0}.table td.span2,.table th.span2{float:none;width:124px;margin-left:0}.table td.span3,.table th.span3{float:none;width:204px;margin-left:0}.table td.span4,.table th.span4{float:none;width:284px;margin-left:0}.table td.span5,.table th.span5{float:none;width:364px;margin-left:0}.table td.span6,.table th.span6{float:none;width:444px;margin-left:0}.table td.span7,.table th.span7{float:none;width:524px;margin-left:0}.table td.span8,.table th.span8{float:none;width:604px;margin-left:0}.table td.span9,.table th.span9{float:none;width:684px;margin-left:0}.table td.span10,.table th.span10{float:none;width:764px;margin-left:0}.table td.span11,.table th.span11{float:none;width:844px;margin-left:0}.table td.span12,.table th.span12{float:none;width:924px;margin-left:0}.table tbody tr.success td{background-color:#dff0d8}.table tbody tr.error td{background-color:#f2dede}.table tbody tr.warning td{background-color:#fcf8e3}.table tbody tr.info td{background-color:#d9edf7}.table-hover tbody tr.success:hover td{background-color:#d0e9c6}.table-hover tbody tr.error:hover td{background-color:#ebcccc}.table-hover tbody tr.warning:hover td{background-color:#faf2cc}.table-hover tbody tr.info:hover td{background-color:#c4e3f3}[class^="icon-"],[class*=" icon-"]{display:inline-block;width:14px;height:14px;margin-top:1px;*margin-right:.3em;line-height:14px;vertical-align:text-top;background-image:url("../img/glyphicons-halflings.png");background-position:14px 14px;background-repeat:no-repeat}.icon-white,.nav-pills>.active>a>[class^="icon-"],.nav-pills>.active>a>[class*=" icon-"],.nav-list>.active>a>[class^="icon-"],.nav-list>.active>a>[class*=" icon-"],.navbar-inverse .nav>.active>a>[class^="icon-"],.navbar-inverse .nav>.active>a>[class*=" icon-"],.dropdown-menu>li>a:hover>[class^="icon-"],.dropdown-menu>li>a:hover>[class*=" icon-"],.dropdown-menu>.active>a>[class^="icon-"],.dropdown-menu>.active>a>[class*=" icon-"],.dropdown-submenu:hover>a>[class^="icon-"],.dropdown-submenu:hover>a>[class*=" icon-"]{background-image:url("../img/glyphicons-halflings-white.png")}.icon-glass{background-position:0 0}.icon-music{background-position:-24px 0}.icon-search{background-position:-48px 0}.icon-envelope{background-position:-72px 0}.icon-heart{background-position:-96px 0}.icon-star{background-position:-120px 0}.icon-star-empty{background-position:-144px 0}.icon-user{background-position:-168px 0}.icon-film{background-position:-192px 0}.icon-th-large{background-position:-216px 0}.icon-th{background-position:-240px 0}.icon-th-list{background-position:-264px 0}.icon-ok{background-position:-288px 0}.icon-remove{background-position:-312px 0}.icon-zoom-in{background-position:-336px 0}.icon-zoom-out{background-position:-360px 0}.icon-off{background-position:-384px 0}.icon-signal{background-position:-408px 0}.icon-cog{background-position:-432px 0}.icon-trash{background-position:-456px 0}.icon-home{background-position:0 -24px}.icon-file{background-position:-24px -24px}.icon-time{background-position:-48px -24px}.icon-road{background-position:-72px -24px}.icon-download-alt{background-position:-96px -24px}.icon-download{background-position:-120px -24px}.icon-upload{background-position:-144px -24px}.icon-inbox{background-position:-168px -24px}.icon-play-circle{background-position:-192px -24px}.icon-repeat{background-position:-216px -24px}.icon-refresh{background-position:-240px -24px}.icon-list-alt{background-position:-264px -24px}.icon-lock{background-position:-287px -24px}.icon-flag{background-position:-312px -24px}.icon-headphones{background-position:-336px -24px}.icon-volume-off{background-position:-360px -24px}.icon-volume-down{background-position:-384px -24px}.icon-volume-up{background-position:-408px -24px}.icon-qrcode{background-position:-432px -24px}.icon-barcode{background-position:-456px -24px}.icon-tag{background-position:0 -48px}.icon-tags{background-position:-25px -48px}.icon-book{background-position:-48px -48px}.icon-bookmark{background-position:-72px -48px}.icon-print{background-position:-96px -48px}.icon-camera{background-position:-120px -48px}.icon-font{background-position:-144px -48px}.icon-bold{background-position:-167px -48px}.icon-italic{background-position:-192px -48px}.icon-text-height{background-position:-216px -48px}.icon-text-width{background-position:-240px -48px}.icon-align-left{background-position:-264px -48px}.icon-align-center{background-position:-288px -48px}.icon-align-right{background-position:-312px -48px}.icon-align-justify{background-position:-336px -48px}.icon-list{background-position:-360px -48px}.icon-indent-left{background-position:-384px -48px}.icon-indent-right{background-position:-408px -48px}.icon-facetime-video{background-position:-432px -48px}.icon-picture{background-position:-456px -48px}.icon-pencil{background-position:0 -72px}.icon-map-marker{background-position:-24px -72px}.icon-adjust{background-position:-48px -72px}.icon-tint{background-position:-72px -72px}.icon-edit{background-position:-96px -72px}.icon-share{background-position:-120px -72px}.icon-check{background-position:-144px -72px}.icon-move{background-position:-168px -72px}.icon-step-backward{background-position:-192px -72px}.icon-fast-backward{background-position:-216px -72px}.icon-backward{background-position:-240px -72px}.icon-play{background-position:-264px -72px}.icon-pause{background-position:-288px -72px}.icon-stop{background-position:-312px -72px}.icon-forward{background-position:-336px -72px}.icon-fast-forward{background-position:-360px -72px}.icon-step-forward{background-position:-384px -72px}.icon-eject{background-position:-408px -72px}.icon-chevron-left{background-position:-432px -72px}.icon-chevron-right{background-position:-456px -72px}.icon-plus-sign{background-position:0 -96px}.icon-minus-sign{background-position:-24px -96px}.icon-remove-sign{background-position:-48px -96px}.icon-ok-sign{background-position:-72px -96px}.icon-question-sign{background-position:-96px -96px}.icon-info-sign{background-position:-120px -96px}.icon-screenshot{background-position:-144px -96px}.icon-remove-circle{background-position:-168px -96px}.icon-ok-circle{background-position:-192px -96px}.icon-ban-circle{background-position:-216px -96px}.icon-arrow-left{background-position:-240px -96px}.icon-arrow-right{background-position:-264px -96px}.icon-arrow-up{background-position:-289px -96px}.icon-arrow-down{background-position:-312px -96px}.icon-share-alt{background-position:-336px -96px}.icon-resize-full{background-position:-360px -96px}.icon-resize-small{background-position:-384px -96px}.icon-plus{background-position:-408px -96px}.icon-minus{background-position:-433px -96px}.icon-asterisk{background-position:-456px -96px}.icon-exclamation-sign{background-position:0 -120px}.icon-gift{background-position:-24px -120px}.icon-leaf{background-position:-48px -120px}.icon-fire{background-position:-72px -120px}.icon-eye-open{background-position:-96px -120px}.icon-eye-close{background-position:-120px -120px}.icon-warning-sign{background-position:-144px -120px}.icon-plane{background-position:-168px -120px}.icon-calendar{background-position:-192px -120px}.icon-random{width:16px;background-position:-216px -120px}.icon-comment{background-position:-240px -120px}.icon-magnet{background-position:-264px -120px}.icon-chevron-up{background-position:-288px -120px}.icon-chevron-down{background-position:-313px -119px}.icon-retweet{background-position:-336px -120px}.icon-shopping-cart{background-position:-360px -120px}.icon-folder-close{background-position:-384px -120px}.icon-folder-open{width:16px;background-position:-408px -120px}.icon-resize-vertical{background-position:-432px -119px}.icon-resize-horizontal{background-position:-456px -118px}.icon-hdd{background-position:0 -144px}.icon-bullhorn{background-position:-24px -144px}.icon-bell{background-position:-48px -144px}.icon-certificate{background-position:-72px -144px}.icon-thumbs-up{background-position:-96px -144px}.icon-thumbs-down{background-position:-120px -144px}.icon-hand-right{background-position:-144px -144px}.icon-hand-left{background-position:-168px -144px}.icon-hand-up{background-position:-192px -144px}.icon-hand-down{background-position:-216px -144px}.icon-circle-arrow-right{background-position:-240px -144px}.icon-circle-arrow-left{background-position:-264px -144px}.icon-circle-arrow-up{background-position:-288px -144px}.icon-circle-arrow-down{background-position:-312px -144px}.icon-globe{background-position:-336px -144px}.icon-wrench{background-position:-360px -144px}.icon-tasks{background-position:-384px -144px}.icon-filter{background-position:-408px -144px}.icon-briefcase{background-position:-432px -144px}.icon-fullscreen{background-position:-456px -144px}.dropup,.dropdown{position:relative}.dropdown-toggle{*margin-bottom:-3px}.dropdown-toggle:active,.open .dropdown-toggle{outline:0}.caret{display:inline-block;width:0;height:0;vertical-align:top;border-top:4px solid #000;border-right:4px solid transparent;border-left:4px solid transparent;content:""}.dropdown .caret{margin-top:8px;margin-left:2px}.dropdown-menu{position:absolute;top:100%;left:0;z-index:1000;display:none;float:left;min-width:160px;padding:5px 0;margin:2px 0 0;list-style:none;background-color:#fff;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.2);*border-right-width:2px;*border-bottom-width:2px;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px;-webkit-box-shadow:0 5px 10px rgba(0,0,0,0.2);-moz-box-shadow:0 5px 10px rgba(0,0,0,0.2);box-shadow:0 5px 10px rgba(0,0,0,0.2);-webkit-background-clip:padding-box;-moz-background-clip:padding;background-clip:padding-box}.dropdown-menu.pull-right{right:0;left:auto}.dropdown-menu .divider{*width:100%;height:1px;margin:9px 1px;*margin:-5px 0 5px;overflow:hidden;background-color:#e5e5e5;border-bottom:1px solid #fff}.dropdown-menu li>a{display:block;padding:3px 20px;clear:both;font-weight:normal;line-height:20px;color:#333;white-space:nowrap}.dropdown-menu li>a:hover,.dropdown-menu li>a:focus,.dropdown-submenu:hover>a{color:#fff;text-decoration:none;background-color:#0081c2;background-image:-moz-linear-gradient(top,#08c,#0077b3);background-image:-webkit-gradient(linear,0 0,0 100%,from(#08c),to(#0077b3));background-image:-webkit-linear-gradient(top,#08c,#0077b3);background-image:-o-linear-gradient(top,#08c,#0077b3);background-image:linear-gradient(to bottom,#08c,#0077b3);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0088cc',endColorstr='#ff0077b3',GradientType=0)}.dropdown-menu .active>a,.dropdown-menu .active>a:hover{color:#fff;text-decoration:none;background-color:#0081c2;background-image:-moz-linear-gradient(top,#08c,#0077b3);background-image:-webkit-gradient(linear,0 0,0 100%,from(#08c),to(#0077b3));background-image:-webkit-linear-gradient(top,#08c,#0077b3);background-image:-o-linear-gradient(top,#08c,#0077b3);background-image:linear-gradient(to bottom,#08c,#0077b3);background-repeat:repeat-x;outline:0;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0088cc',endColorstr='#ff0077b3',GradientType=0)}.dropdown-menu .disabled>a,.dropdown-menu .disabled>a:hover{color:#999}.dropdown-menu .disabled>a:hover{text-decoration:none;cursor:default;background-color:transparent;background-image:none;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.open{*z-index:1000}.open>.dropdown-menu{display:block}.pull-right>.dropdown-menu{right:0;left:auto}.dropup .caret,.navbar-fixed-bottom .dropdown .caret{border-top:0;border-bottom:4px solid #000;content:""}.dropup .dropdown-menu,.navbar-fixed-bottom .dropdown .dropdown-menu{top:auto;bottom:100%;margin-bottom:1px}.dropdown-submenu{position:relative}.dropdown-submenu>.dropdown-menu{top:0;left:100%;margin-top:-6px;margin-left:-1px;-webkit-border-radius:0 6px 6px 6px;-moz-border-radius:0 6px 6px 6px;border-radius:0 6px 6px 6px}.dropdown-submenu:hover>.dropdown-menu{display:block}.dropup .dropdown-submenu>.dropdown-menu{top:auto;bottom:0;margin-top:0;margin-bottom:-2px;-webkit-border-radius:5px 5px 5px 0;-moz-border-radius:5px 5px 5px 0;border-radius:5px 5px 5px 0}.dropdown-submenu>a:after{display:block;float:right;width:0;height:0;margin-top:5px;margin-right:-10px;border-color:transparent;border-left-color:#ccc;border-style:solid;border-width:5px 0 5px 5px;content:" "}.dropdown-submenu:hover>a:after{border-left-color:#fff}.dropdown-submenu.pull-left{float:none}.dropdown-submenu.pull-left>.dropdown-menu{left:-100%;margin-left:10px;-webkit-border-radius:6px 0 6px 6px;-moz-border-radius:6px 0 6px 6px;border-radius:6px 0 6px 6px}.dropdown .dropdown-menu .nav-header{padding-right:20px;padding-left:20px}.typeahead{z-index:1051;margin-top:2px;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.well{min-height:20px;padding:19px;margin-bottom:20px;background-color:#f5f5f5;border:1px solid #e3e3e3;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.05);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.05);box-shadow:inset 0 1px 1px rgba(0,0,0,0.05)}.well blockquote{border-color:#ddd;border-color:rgba(0,0,0,0.15)}.well-large{padding:24px;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}.well-small{padding:9px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.fade{opacity:0;-webkit-transition:opacity .15s linear;-moz-transition:opacity .15s linear;-o-transition:opacity .15s linear;transition:opacity .15s linear}.fade.in{opacity:1}.collapse{position:relative;height:0;overflow:hidden;-webkit-transition:height .35s ease;-moz-transition:height .35s ease;-o-transition:height .35s ease;transition:height .35s ease}.collapse.in{height:auto}.close{float:right;font-size:20px;font-weight:bold;line-height:20px;color:#000;text-shadow:0 1px 0 #fff;opacity:.2;filter:alpha(opacity=20)}.close:hover{color:#000;text-decoration:none;cursor:pointer;opacity:.4;filter:alpha(opacity=40)}button.close{padding:0;cursor:pointer;background:transparent;border:0;-webkit-appearance:none}.btn{display:inline-block;*display:inline;padding:4px 12px;margin-bottom:0;*margin-left:.3em;font-size:14px;line-height:20px;color:#333;text-align:center;text-shadow:0 1px 1px rgba(255,255,255,0.75);vertical-align:middle;cursor:pointer;background-color:#f5f5f5;*background-color:#e6e6e6;background-image:-moz-linear-gradient(top,#fff,#e6e6e6);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fff),to(#e6e6e6));background-image:-webkit-linear-gradient(top,#fff,#e6e6e6);background-image:-o-linear-gradient(top,#fff,#e6e6e6);background-image:linear-gradient(to bottom,#fff,#e6e6e6);background-repeat:repeat-x;border:1px solid #bbb;*border:0;border-color:#e6e6e6 #e6e6e6 #bfbfbf;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);border-bottom-color:#a2a2a2;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff',endColorstr='#ffe6e6e6',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);*zoom:1;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);box-shadow:inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05)}.btn:hover,.btn:active,.btn.active,.btn.disabled,.btn[disabled]{color:#333;background-color:#e6e6e6;*background-color:#d9d9d9}.btn:active,.btn.active{background-color:#ccc \9}.btn:first-child{*margin-left:0}.btn:hover{color:#333;text-decoration:none;background-position:0 -15px;-webkit-transition:background-position .1s linear;-moz-transition:background-position .1s linear;-o-transition:background-position .1s linear;transition:background-position .1s linear}.btn:focus{outline:thin dotted #333;outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}.btn.active,.btn:active{background-image:none;outline:0;-webkit-box-shadow:inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05);-moz-box-shadow:inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05);box-shadow:inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05)}.btn.disabled,.btn[disabled]{cursor:default;background-image:none;opacity:.65;filter:alpha(opacity=65);-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none}.btn-large{padding:11px 19px;font-size:17.5px;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}.btn-large [class^="icon-"],.btn-large [class*=" icon-"]{margin-top:4px}.btn-small{padding:2px 10px;font-size:11.9px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.btn-small [class^="icon-"],.btn-small [class*=" icon-"]{margin-top:0}.btn-mini [class^="icon-"],.btn-mini [class*=" icon-"]{margin-top:-1px}.btn-mini{padding:0 6px;font-size:10.5px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.btn-block{display:block;width:100%;padding-right:0;padding-left:0;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.btn-block+.btn-block{margin-top:5px}input[type="submit"].btn-block,input[type="reset"].btn-block,input[type="button"].btn-block{width:100%}.btn-primary.active,.btn-warning.active,.btn-danger.active,.btn-success.active,.btn-info.active,.btn-inverse.active{color:rgba(255,255,255,0.75)}.btn{border-color:#c5c5c5;border-color:rgba(0,0,0,0.15) rgba(0,0,0,0.15) rgba(0,0,0,0.25)}.btn-primary{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#006dcc;*background-color:#04c;background-image:-moz-linear-gradient(top,#08c,#04c);background-image:-webkit-gradient(linear,0 0,0 100%,from(#08c),to(#04c));background-image:-webkit-linear-gradient(top,#08c,#04c);background-image:-o-linear-gradient(top,#08c,#04c);background-image:linear-gradient(to bottom,#08c,#04c);background-repeat:repeat-x;border-color:#04c #04c #002a80;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0088cc',endColorstr='#ff0044cc',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-primary:hover,.btn-primary:active,.btn-primary.active,.btn-primary.disabled,.btn-primary[disabled]{color:#fff;background-color:#04c;*background-color:#003bb3}.btn-primary:active,.btn-primary.active{background-color:#039 \9}.btn-warning{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#faa732;*background-color:#f89406;background-image:-moz-linear-gradient(top,#fbb450,#f89406);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fbb450),to(#f89406));background-image:-webkit-linear-gradient(top,#fbb450,#f89406);background-image:-o-linear-gradient(top,#fbb450,#f89406);background-image:linear-gradient(to bottom,#fbb450,#f89406);background-repeat:repeat-x;border-color:#f89406 #f89406 #ad6704;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fffbb450',endColorstr='#fff89406',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-warning:hover,.btn-warning:active,.btn-warning.active,.btn-warning.disabled,.btn-warning[disabled]{color:#fff;background-color:#f89406;*background-color:#df8505}.btn-warning:active,.btn-warning.active{background-color:#c67605 \9}.btn-danger{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#da4f49;*background-color:#bd362f;background-image:-moz-linear-gradient(top,#ee5f5b,#bd362f);background-image:-webkit-gradient(linear,0 0,0 100%,from(#ee5f5b),to(#bd362f));background-image:-webkit-linear-gradient(top,#ee5f5b,#bd362f);background-image:-o-linear-gradient(top,#ee5f5b,#bd362f);background-image:linear-gradient(to bottom,#ee5f5b,#bd362f);background-repeat:repeat-x;border-color:#bd362f #bd362f #802420;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffee5f5b',endColorstr='#ffbd362f',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-danger:hover,.btn-danger:active,.btn-danger.active,.btn-danger.disabled,.btn-danger[disabled]{color:#fff;background-color:#bd362f;*background-color:#a9302a}.btn-danger:active,.btn-danger.active{background-color:#942a25 \9}.btn-success{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#5bb75b;*background-color:#51a351;background-image:-moz-linear-gradient(top,#62c462,#51a351);background-image:-webkit-gradient(linear,0 0,0 100%,from(#62c462),to(#51a351));background-image:-webkit-linear-gradient(top,#62c462,#51a351);background-image:-o-linear-gradient(top,#62c462,#51a351);background-image:linear-gradient(to bottom,#62c462,#51a351);background-repeat:repeat-x;border-color:#51a351 #51a351 #387038;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff62c462',endColorstr='#ff51a351',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-success:hover,.btn-success:active,.btn-success.active,.btn-success.disabled,.btn-success[disabled]{color:#fff;background-color:#51a351;*background-color:#499249}.btn-success:active,.btn-success.active{background-color:#408140 \9}.btn-info{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#49afcd;*background-color:#2f96b4;background-image:-moz-linear-gradient(top,#5bc0de,#2f96b4);background-image:-webkit-gradient(linear,0 0,0 100%,from(#5bc0de),to(#2f96b4));background-image:-webkit-linear-gradient(top,#5bc0de,#2f96b4);background-image:-o-linear-gradient(top,#5bc0de,#2f96b4);background-image:linear-gradient(to bottom,#5bc0de,#2f96b4);background-repeat:repeat-x;border-color:#2f96b4 #2f96b4 #1f6377;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5bc0de',endColorstr='#ff2f96b4',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-info:hover,.btn-info:active,.btn-info.active,.btn-info.disabled,.btn-info[disabled]{color:#fff;background-color:#2f96b4;*background-color:#2a85a0}.btn-info:active,.btn-info.active{background-color:#24748c \9}.btn-inverse{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#363636;*background-color:#222;background-image:-moz-linear-gradient(top,#444,#222);background-image:-webkit-gradient(linear,0 0,0 100%,from(#444),to(#222));background-image:-webkit-linear-gradient(top,#444,#222);background-image:-o-linear-gradient(top,#444,#222);background-image:linear-gradient(to bottom,#444,#222);background-repeat:repeat-x;border-color:#222 #222 #000;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff444444',endColorstr='#ff222222',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-inverse:hover,.btn-inverse:active,.btn-inverse.active,.btn-inverse.disabled,.btn-inverse[disabled]{color:#fff;background-color:#222;*background-color:#151515}.btn-inverse:active,.btn-inverse.active{background-color:#080808 \9}button.btn,input[type="submit"].btn{*padding-top:3px;*padding-bottom:3px}button.btn::-moz-focus-inner,input[type="submit"].btn::-moz-focus-inner{padding:0;border:0}button.btn.btn-large,input[type="submit"].btn.btn-large{*padding-top:7px;*padding-bottom:7px}button.btn.btn-small,input[type="submit"].btn.btn-small{*padding-top:3px;*padding-bottom:3px}button.btn.btn-mini,input[type="submit"].btn.btn-mini{*padding-top:1px;*padding-bottom:1px}.btn-link,.btn-link:active,.btn-link[disabled]{background-color:transparent;background-image:none;-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none}.btn-link{color:#08c;cursor:pointer;border-color:transparent;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.btn-link:hover{color:#005580;text-decoration:underline;background-color:transparent}.btn-link[disabled]:hover{color:#333;text-decoration:none}.btn-group{position:relative;display:inline-block;*display:inline;*margin-left:.3em;font-size:0;white-space:nowrap;vertical-align:middle;*zoom:1}.btn-group:first-child{*margin-left:0}.btn-group+.btn-group{margin-left:5px}.btn-toolbar{margin-top:10px;margin-bottom:10px;font-size:0}.btn-toolbar>.btn+.btn,.btn-toolbar>.btn-group+.btn,.btn-toolbar>.btn+.btn-group{margin-left:5px}.btn-group>.btn{position:relative;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.btn-group>.btn+.btn{margin-left:-1px}.btn-group>.btn,.btn-group>.dropdown-menu,.btn-group>.popover{font-size:14px}.btn-group>.btn-mini{font-size:10.5px}.btn-group>.btn-small{font-size:11.9px}.btn-group>.btn-large{font-size:17.5px}.btn-group>.btn:first-child{margin-left:0;-webkit-border-bottom-left-radius:4px;border-bottom-left-radius:4px;-webkit-border-top-left-radius:4px;border-top-left-radius:4px;-moz-border-radius-bottomleft:4px;-moz-border-radius-topleft:4px}.btn-group>.btn:last-child,.btn-group>.dropdown-toggle{-webkit-border-top-right-radius:4px;border-top-right-radius:4px;-webkit-border-bottom-right-radius:4px;border-bottom-right-radius:4px;-moz-border-radius-topright:4px;-moz-border-radius-bottomright:4px}.btn-group>.btn.large:first-child{margin-left:0;-webkit-border-bottom-left-radius:6px;border-bottom-left-radius:6px;-webkit-border-top-left-radius:6px;border-top-left-radius:6px;-moz-border-radius-bottomleft:6px;-moz-border-radius-topleft:6px}.btn-group>.btn.large:last-child,.btn-group>.large.dropdown-toggle{-webkit-border-top-right-radius:6px;border-top-right-radius:6px;-webkit-border-bottom-right-radius:6px;border-bottom-right-radius:6px;-moz-border-radius-topright:6px;-moz-border-radius-bottomright:6px}.btn-group>.btn:hover,.btn-group>.btn:focus,.btn-group>.btn:active,.btn-group>.btn.active{z-index:2}.btn-group .dropdown-toggle:active,.btn-group.open .dropdown-toggle{outline:0}.btn-group>.btn+.dropdown-toggle{*padding-top:5px;padding-right:8px;*padding-bottom:5px;padding-left:8px;-webkit-box-shadow:inset 1px 0 0 rgba(255,255,255,0.125),inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);-moz-box-shadow:inset 1px 0 0 rgba(255,255,255,0.125),inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);box-shadow:inset 1px 0 0 rgba(255,255,255,0.125),inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05)}.btn-group>.btn-mini+.dropdown-toggle{*padding-top:2px;padding-right:5px;*padding-bottom:2px;padding-left:5px}.btn-group>.btn-small+.dropdown-toggle{*padding-top:5px;*padding-bottom:4px}.btn-group>.btn-large+.dropdown-toggle{*padding-top:7px;padding-right:12px;*padding-bottom:7px;padding-left:12px}.btn-group.open .dropdown-toggle{background-image:none;-webkit-box-shadow:inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05);-moz-box-shadow:inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05);box-shadow:inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05)}.btn-group.open .btn.dropdown-toggle{background-color:#e6e6e6}.btn-group.open .btn-primary.dropdown-toggle{background-color:#04c}.btn-group.open .btn-warning.dropdown-toggle{background-color:#f89406}.btn-group.open .btn-danger.dropdown-toggle{background-color:#bd362f}.btn-group.open .btn-success.dropdown-toggle{background-color:#51a351}.btn-group.open .btn-info.dropdown-toggle{background-color:#2f96b4}.btn-group.open .btn-inverse.dropdown-toggle{background-color:#222}.btn .caret{margin-top:8px;margin-left:0}.btn-mini .caret,.btn-small .caret,.btn-large .caret{margin-top:6px}.btn-large .caret{border-top-width:5px;border-right-width:5px;border-left-width:5px}.dropup .btn-large .caret{border-bottom-width:5px}.btn-primary .caret,.btn-warning .caret,.btn-danger .caret,.btn-info .caret,.btn-success .caret,.btn-inverse .caret{border-top-color:#fff;border-bottom-color:#fff}.btn-group-vertical{display:inline-block;*display:inline;*zoom:1}.btn-group-vertical>.btn{display:block;float:none;max-width:100%;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.btn-group-vertical>.btn+.btn{margin-top:-1px;margin-left:0}.btn-group-vertical>.btn:first-child{-webkit-border-radius:4px 4px 0 0;-moz-border-radius:4px 4px 0 0;border-radius:4px 4px 0 0}.btn-group-vertical>.btn:last-child{-webkit-border-radius:0 0 4px 4px;-moz-border-radius:0 0 4px 4px;border-radius:0 0 4px 4px}.btn-group-vertical>.btn-large:first-child{-webkit-border-radius:6px 6px 0 0;-moz-border-radius:6px 6px 0 0;border-radius:6px 6px 0 0}.btn-group-vertical>.btn-large:last-child{-webkit-border-radius:0 0 6px 6px;-moz-border-radius:0 0 6px 6px;border-radius:0 0 6px 6px}.alert{padding:8px 35px 8px 14px;margin-bottom:20px;text-shadow:0 1px 0 rgba(255,255,255,0.5);background-color:#fcf8e3;border:1px solid #fbeed5;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.alert,.alert h4{color:#c09853}.alert h4{margin:0}.alert .close{position:relative;top:-2px;right:-21px;line-height:20px}.alert-success{color:#468847;background-color:#dff0d8;border-color:#d6e9c6}.alert-success h4{color:#468847}.alert-danger,.alert-error{color:#b94a48;background-color:#f2dede;border-color:#eed3d7}.alert-danger h4,.alert-error h4{color:#b94a48}.alert-info{color:#3a87ad;background-color:#d9edf7;border-color:#bce8f1}.alert-info h4{color:#3a87ad}.alert-block{padding-top:14px;padding-bottom:14px}.alert-block>p,.alert-block>ul{margin-bottom:0}.alert-block p+p{margin-top:5px}.nav{margin-bottom:20px;margin-left:0;list-style:none}.nav>li>a{display:block}.nav>li>a:hover{text-decoration:none;background-color:#eee}.nav>li>a>img{max-width:none}.nav>.pull-right{float:right}.nav-header{display:block;padding:3px 15px;font-size:11px;font-weight:bold;line-height:20px;color:#999;text-shadow:0 1px 0 rgba(255,255,255,0.5);text-transform:uppercase}.nav li+.nav-header{margin-top:9px}.nav-list{padding-right:15px;padding-left:15px;margin-bottom:0}.nav-list>li>a,.nav-list .nav-header{margin-right:-15px;margin-left:-15px;text-shadow:0 1px 0 rgba(255,255,255,0.5)}.nav-list>li>a{padding:3px 15px}.nav-list>.active>a,.nav-list>.active>a:hover{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.2);background-color:#08c}.nav-list [class^="icon-"],.nav-list [class*=" icon-"]{margin-right:2px}.nav-list .divider{*width:100%;height:1px;margin:9px 1px;*margin:-5px 0 5px;overflow:hidden;background-color:#e5e5e5;border-bottom:1px solid #fff}.nav-tabs,.nav-pills{*zoom:1}.nav-tabs:before,.nav-pills:before,.nav-tabs:after,.nav-pills:after{display:table;line-height:0;content:""}.nav-tabs:after,.nav-pills:after{clear:both}.nav-tabs>li,.nav-pills>li{float:left}.nav-tabs>li>a,.nav-pills>li>a{padding-right:12px;padding-left:12px;margin-right:2px;line-height:14px}.nav-tabs{border-bottom:1px solid #ddd}.nav-tabs>li{margin-bottom:-1px}.nav-tabs>li>a{padding-top:8px;padding-bottom:8px;line-height:20px;border:1px solid transparent;-webkit-border-radius:4px 4px 0 0;-moz-border-radius:4px 4px 0 0;border-radius:4px 4px 0 0}.nav-tabs>li>a:hover{border-color:#eee #eee #ddd}.nav-tabs>.active>a,.nav-tabs>.active>a:hover{color:#555;cursor:default;background-color:#fff;border:1px solid #ddd;border-bottom-color:transparent}.nav-pills>li>a{padding-top:8px;padding-bottom:8px;margin-top:2px;margin-bottom:2px;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px}.nav-pills>.active>a,.nav-pills>.active>a:hover{color:#fff;background-color:#08c}.nav-stacked>li{float:none}.nav-stacked>li>a{margin-right:0}.nav-tabs.nav-stacked{border-bottom:0}.nav-tabs.nav-stacked>li>a{border:1px solid #ddd;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.nav-tabs.nav-stacked>li:first-child>a{-webkit-border-top-right-radius:4px;border-top-right-radius:4px;-webkit-border-top-left-radius:4px;border-top-left-radius:4px;-moz-border-radius-topright:4px;-moz-border-radius-topleft:4px}.nav-tabs.nav-stacked>li:last-child>a{-webkit-border-bottom-right-radius:4px;border-bottom-right-radius:4px;-webkit-border-bottom-left-radius:4px;border-bottom-left-radius:4px;-moz-border-radius-bottomright:4px;-moz-border-radius-bottomleft:4px}.nav-tabs.nav-stacked>li>a:hover{z-index:2;border-color:#ddd}.nav-pills.nav-stacked>li>a{margin-bottom:3px}.nav-pills.nav-stacked>li:last-child>a{margin-bottom:1px}.nav-tabs .dropdown-menu{-webkit-border-radius:0 0 6px 6px;-moz-border-radius:0 0 6px 6px;border-radius:0 0 6px 6px}.nav-pills .dropdown-menu{-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}.nav .dropdown-toggle .caret{margin-top:6px;border-top-color:#08c;border-bottom-color:#08c}.nav .dropdown-toggle:hover .caret{border-top-color:#005580;border-bottom-color:#005580}.nav-tabs .dropdown-toggle .caret{margin-top:8px}.nav .active .dropdown-toggle .caret{border-top-color:#fff;border-bottom-color:#fff}.nav-tabs .active .dropdown-toggle .caret{border-top-color:#555;border-bottom-color:#555}.nav>.dropdown.active>a:hover{cursor:pointer}.nav-tabs .open .dropdown-toggle,.nav-pills .open .dropdown-toggle,.nav>li.dropdown.open.active>a:hover{color:#fff;background-color:#999;border-color:#999}.nav li.dropdown.open .caret,.nav li.dropdown.open.active .caret,.nav li.dropdown.open a:hover .caret{border-top-color:#fff;border-bottom-color:#fff;opacity:1;filter:alpha(opacity=100)}.tabs-stacked .open>a:hover{border-color:#999}.tabbable{*zoom:1}.tabbable:before,.tabbable:after{display:table;line-height:0;content:""}.tabbable:after{clear:both}.tab-content{overflow:auto}.tabs-below>.nav-tabs,.tabs-right>.nav-tabs,.tabs-left>.nav-tabs{border-bottom:0}.tab-content>.tab-pane,.pill-content>.pill-pane{display:none}.tab-content>.active,.pill-content>.active{display:block}.tabs-below>.nav-tabs{border-top:1px solid #ddd}.tabs-below>.nav-tabs>li{margin-top:-1px;margin-bottom:0}.tabs-below>.nav-tabs>li>a{-webkit-border-radius:0 0 4px 4px;-moz-border-radius:0 0 4px 4px;border-radius:0 0 4px 4px}.tabs-below>.nav-tabs>li>a:hover{border-top-color:#ddd;border-bottom-color:transparent}.tabs-below>.nav-tabs>.active>a,.tabs-below>.nav-tabs>.active>a:hover{border-color:transparent #ddd #ddd #ddd}.tabs-left>.nav-tabs>li,.tabs-right>.nav-tabs>li{float:none}.tabs-left>.nav-tabs>li>a,.tabs-right>.nav-tabs>li>a{min-width:74px;margin-right:0;margin-bottom:3px}.tabs-left>.nav-tabs{float:left;margin-right:19px;border-right:1px solid #ddd}.tabs-left>.nav-tabs>li>a{margin-right:-1px;-webkit-border-radius:4px 0 0 4px;-moz-border-radius:4px 0 0 4px;border-radius:4px 0 0 4px}.tabs-left>.nav-tabs>li>a:hover{border-color:#eee #ddd #eee #eee}.tabs-left>.nav-tabs .active>a,.tabs-left>.nav-tabs .active>a:hover{border-color:#ddd transparent #ddd #ddd;*border-right-color:#fff}.tabs-right>.nav-tabs{float:right;margin-left:19px;border-left:1px solid #ddd}.tabs-right>.nav-tabs>li>a{margin-left:-1px;-webkit-border-radius:0 4px 4px 0;-moz-border-radius:0 4px 4px 0;border-radius:0 4px 4px 0}.tabs-right>.nav-tabs>li>a:hover{border-color:#eee #eee #eee #ddd}.tabs-right>.nav-tabs .active>a,.tabs-right>.nav-tabs .active>a:hover{border-color:#ddd #ddd #ddd transparent;*border-left-color:#fff}.nav>.disabled>a{color:#999}.nav>.disabled>a:hover{text-decoration:none;cursor:default;background-color:transparent}.navbar{*position:relative;*z-index:2;margin-bottom:20px;overflow:visible}.navbar-inner{min-height:40px;padding-right:20px;padding-left:20px;background-color:#fafafa;background-image:-moz-linear-gradient(top,#fff,#f2f2f2);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fff),to(#f2f2f2));background-image:-webkit-linear-gradient(top,#fff,#f2f2f2);background-image:-o-linear-gradient(top,#fff,#f2f2f2);background-image:linear-gradient(to bottom,#fff,#f2f2f2);background-repeat:repeat-x;border:1px solid #d4d4d4;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff',endColorstr='#fff2f2f2',GradientType=0);*zoom:1;-webkit-box-shadow:0 1px 4px rgba(0,0,0,0.065);-moz-box-shadow:0 1px 4px rgba(0,0,0,0.065);box-shadow:0 1px 4px rgba(0,0,0,0.065)}.navbar-inner:before,.navbar-inner:after{display:table;line-height:0;content:""}.navbar-inner:after{clear:both}.navbar .container{width:auto}.nav-collapse.collapse{height:auto;overflow:visible}.navbar .brand{display:block;float:left;padding:10px 20px 10px;margin-left:-20px;font-size:20px;font-weight:200;color:#777;text-shadow:0 1px 0 #fff}.navbar .brand:hover{text-decoration:none}.navbar-text{margin-bottom:0;line-height:40px;color:#777}.navbar-link{color:#777}.navbar-link:hover{color:#333}.navbar .divider-vertical{height:40px;margin:0 9px;border-right:1px solid #fff;border-left:1px solid #f2f2f2}.navbar .btn,.navbar .btn-group{margin-top:5px}.navbar .btn-group .btn,.navbar .input-prepend .btn,.navbar .input-append .btn{margin-top:0}.navbar-form{margin-bottom:0;*zoom:1}.navbar-form:before,.navbar-form:after{display:table;line-height:0;content:""}.navbar-form:after{clear:both}.navbar-form input,.navbar-form select,.navbar-form .radio,.navbar-form .checkbox{margin-top:5px}.navbar-form input,.navbar-form select,.navbar-form .btn{display:inline-block;margin-bottom:0}.navbar-form input[type="image"],.navbar-form input[type="checkbox"],.navbar-form input[type="radio"]{margin-top:3px}.navbar-form .input-append,.navbar-form .input-prepend{margin-top:5px;white-space:nowrap}.navbar-form .input-append input,.navbar-form .input-prepend input{margin-top:0}.navbar-search{position:relative;float:left;margin-top:5px;margin-bottom:0}.navbar-search .search-query{padding:4px 14px;margin-bottom:0;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;font-weight:normal;line-height:1;-webkit-border-radius:15px;-moz-border-radius:15px;border-radius:15px}.navbar-static-top{position:static;margin-bottom:0}.navbar-static-top .navbar-inner{-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.navbar-fixed-top,.navbar-fixed-bottom{position:fixed;right:0;left:0;z-index:1030;margin-bottom:0}.navbar-fixed-top .navbar-inner,.navbar-static-top .navbar-inner{border-width:0 0 1px}.navbar-fixed-bottom .navbar-inner{border-width:1px 0 0}.navbar-fixed-top .navbar-inner,.navbar-fixed-bottom .navbar-inner{padding-right:0;padding-left:0;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.navbar-static-top .container,.navbar-fixed-top .container,.navbar-fixed-bottom .container{width:940px}.navbar-fixed-top{top:0}.navbar-fixed-top .navbar-inner,.navbar-static-top .navbar-inner{-webkit-box-shadow:0 1px 10px rgba(0,0,0,0.1);-moz-box-shadow:0 1px 10px rgba(0,0,0,0.1);box-shadow:0 1px 10px rgba(0,0,0,0.1)}.navbar-fixed-bottom{bottom:0}.navbar-fixed-bottom .navbar-inner{-webkit-box-shadow:0 -1px 10px rgba(0,0,0,0.1);-moz-box-shadow:0 -1px 10px rgba(0,0,0,0.1);box-shadow:0 -1px 10px rgba(0,0,0,0.1)}.navbar .nav{position:relative;left:0;display:block;float:left;margin:0 10px 0 0}.navbar .nav.pull-right{float:right;margin-right:0}.navbar .nav>li{float:left}.navbar .nav>li>a{float:none;padding:10px 15px 10px;color:#777;text-decoration:none;text-shadow:0 1px 0 #fff}.navbar .nav .dropdown-toggle .caret{margin-top:8px}.navbar .nav>li>a:focus,.navbar .nav>li>a:hover{color:#333;text-decoration:none;background-color:transparent}.navbar .nav>.active>a,.navbar .nav>.active>a:hover,.navbar .nav>.active>a:focus{color:#555;text-decoration:none;background-color:#e5e5e5;-webkit-box-shadow:inset 0 3px 8px rgba(0,0,0,0.125);-moz-box-shadow:inset 0 3px 8px rgba(0,0,0,0.125);box-shadow:inset 0 3px 8px rgba(0,0,0,0.125)}.navbar .btn-navbar{display:none;float:right;padding:7px 10px;margin-right:5px;margin-left:5px;color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#ededed;*background-color:#e5e5e5;background-image:-moz-linear-gradient(top,#f2f2f2,#e5e5e5);background-image:-webkit-gradient(linear,0 0,0 100%,from(#f2f2f2),to(#e5e5e5));background-image:-webkit-linear-gradient(top,#f2f2f2,#e5e5e5);background-image:-o-linear-gradient(top,#f2f2f2,#e5e5e5);background-image:linear-gradient(to bottom,#f2f2f2,#e5e5e5);background-repeat:repeat-x;border-color:#e5e5e5 #e5e5e5 #bfbfbf;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff2f2f2',endColorstr='#ffe5e5e5',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.075);-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.075);box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.075)}.navbar .btn-navbar:hover,.navbar .btn-navbar:active,.navbar .btn-navbar.active,.navbar .btn-navbar.disabled,.navbar .btn-navbar[disabled]{color:#fff;background-color:#e5e5e5;*background-color:#d9d9d9}.navbar .btn-navbar:active,.navbar .btn-navbar.active{background-color:#ccc \9}.navbar .btn-navbar .icon-bar{display:block;width:18px;height:2px;background-color:#f5f5f5;-webkit-border-radius:1px;-moz-border-radius:1px;border-radius:1px;-webkit-box-shadow:0 1px 0 rgba(0,0,0,0.25);-moz-box-shadow:0 1px 0 rgba(0,0,0,0.25);box-shadow:0 1px 0 rgba(0,0,0,0.25)}.btn-navbar .icon-bar+.icon-bar{margin-top:3px}.navbar .nav>li>.dropdown-menu:before{position:absolute;top:-7px;left:9px;display:inline-block;border-right:7px solid transparent;border-bottom:7px solid #ccc;border-left:7px solid transparent;border-bottom-color:rgba(0,0,0,0.2);content:''}.navbar .nav>li>.dropdown-menu:after{position:absolute;top:-6px;left:10px;display:inline-block;border-right:6px solid transparent;border-bottom:6px solid #fff;border-left:6px solid transparent;content:''}.navbar-fixed-bottom .nav>li>.dropdown-menu:before{top:auto;bottom:-7px;border-top:7px solid #ccc;border-bottom:0;border-top-color:rgba(0,0,0,0.2)}.navbar-fixed-bottom .nav>li>.dropdown-menu:after{top:auto;bottom:-6px;border-top:6px solid #fff;border-bottom:0}.navbar .nav li.dropdown>a:hover .caret{border-top-color:#555;border-bottom-color:#555}.navbar .nav li.dropdown.open>.dropdown-toggle,.navbar .nav li.dropdown.active>.dropdown-toggle,.navbar .nav li.dropdown.open.active>.dropdown-toggle{color:#555;background-color:#e5e5e5}.navbar .nav li.dropdown>.dropdown-toggle .caret{border-top-color:#777;border-bottom-color:#777}.navbar .nav li.dropdown.open>.dropdown-toggle .caret,.navbar .nav li.dropdown.active>.dropdown-toggle .caret,.navbar .nav li.dropdown.open.active>.dropdown-toggle .caret{border-top-color:#555;border-bottom-color:#555}.navbar .pull-right>li>.dropdown-menu,.navbar .nav>li>.dropdown-menu.pull-right{right:0;left:auto}.navbar .pull-right>li>.dropdown-menu:before,.navbar .nav>li>.dropdown-menu.pull-right:before{right:12px;left:auto}.navbar .pull-right>li>.dropdown-menu:after,.navbar .nav>li>.dropdown-menu.pull-right:after{right:13px;left:auto}.navbar .pull-right>li>.dropdown-menu .dropdown-menu,.navbar .nav>li>.dropdown-menu.pull-right .dropdown-menu{right:100%;left:auto;margin-right:-1px;margin-left:0;-webkit-border-radius:6px 0 6px 6px;-moz-border-radius:6px 0 6px 6px;border-radius:6px 0 6px 6px}.navbar-inverse .navbar-inner{background-color:#1b1b1b;background-image:-moz-linear-gradient(top,#222,#111);background-image:-webkit-gradient(linear,0 0,0 100%,from(#222),to(#111));background-image:-webkit-linear-gradient(top,#222,#111);background-image:-o-linear-gradient(top,#222,#111);background-image:linear-gradient(to bottom,#222,#111);background-repeat:repeat-x;border-color:#252525;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff222222',endColorstr='#ff111111',GradientType=0)}.navbar-inverse .brand,.navbar-inverse .nav>li>a{color:#999;text-shadow:0 -1px 0 rgba(0,0,0,0.25)}.navbar-inverse .brand:hover,.navbar-inverse .nav>li>a:hover{color:#fff}.navbar-inverse .brand{color:#999}.navbar-inverse .navbar-text{color:#999}.navbar-inverse .nav>li>a:focus,.navbar-inverse .nav>li>a:hover{color:#fff;background-color:transparent}.navbar-inverse .nav .active>a,.navbar-inverse .nav .active>a:hover,.navbar-inverse .nav .active>a:focus{color:#fff;background-color:#111}.navbar-inverse .navbar-link{color:#999}.navbar-inverse .navbar-link:hover{color:#fff}.navbar-inverse .divider-vertical{border-right-color:#222;border-left-color:#111}.navbar-inverse .nav li.dropdown.open>.dropdown-toggle,.navbar-inverse .nav li.dropdown.active>.dropdown-toggle,.navbar-inverse .nav li.dropdown.open.active>.dropdown-toggle{color:#fff;background-color:#111}.navbar-inverse .nav li.dropdown>a:hover .caret{border-top-color:#fff;border-bottom-color:#fff}.navbar-inverse .nav li.dropdown>.dropdown-toggle .caret{border-top-color:#999;border-bottom-color:#999}.navbar-inverse .nav li.dropdown.open>.dropdown-toggle .caret,.navbar-inverse .nav li.dropdown.active>.dropdown-toggle .caret,.navbar-inverse .nav li.dropdown.open.active>.dropdown-toggle .caret{border-top-color:#fff;border-bottom-color:#fff}.navbar-inverse .navbar-search .search-query{color:#fff;background-color:#515151;border-color:#111;-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.1),0 1px 0 rgba(255,255,255,0.15);-moz-box-shadow:inset 0 1px 2px rgba(0,0,0,0.1),0 1px 0 rgba(255,255,255,0.15);box-shadow:inset 0 1px 2px rgba(0,0,0,0.1),0 1px 0 rgba(255,255,255,0.15);-webkit-transition:none;-moz-transition:none;-o-transition:none;transition:none}.navbar-inverse .navbar-search .search-query:-moz-placeholder{color:#ccc}.navbar-inverse .navbar-search .search-query:-ms-input-placeholder{color:#ccc}.navbar-inverse .navbar-search .search-query::-webkit-input-placeholder{color:#ccc}.navbar-inverse .navbar-search .search-query:focus,.navbar-inverse .navbar-search .search-query.focused{padding:5px 15px;color:#333;text-shadow:0 1px 0 #fff;background-color:#fff;border:0;outline:0;-webkit-box-shadow:0 0 3px rgba(0,0,0,0.15);-moz-box-shadow:0 0 3px rgba(0,0,0,0.15);box-shadow:0 0 3px rgba(0,0,0,0.15)}.navbar-inverse .btn-navbar{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#0e0e0e;*background-color:#040404;background-image:-moz-linear-gradient(top,#151515,#040404);background-image:-webkit-gradient(linear,0 0,0 100%,from(#151515),to(#040404));background-image:-webkit-linear-gradient(top,#151515,#040404);background-image:-o-linear-gradient(top,#151515,#040404);background-image:linear-gradient(to bottom,#151515,#040404);background-repeat:repeat-x;border-color:#040404 #040404 #000;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff151515',endColorstr='#ff040404',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.navbar-inverse .btn-navbar:hover,.navbar-inverse .btn-navbar:active,.navbar-inverse .btn-navbar.active,.navbar-inverse .btn-navbar.disabled,.navbar-inverse .btn-navbar[disabled]{color:#fff;background-color:#040404;*background-color:#000}.navbar-inverse .btn-navbar:active,.navbar-inverse .btn-navbar.active{background-color:#000 \9}.breadcrumb{padding:8px 15px;margin:0 0 20px;list-style:none;background-color:#f5f5f5;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.breadcrumb>li{display:inline-block;*display:inline;text-shadow:0 1px 0 #fff;*zoom:1}.breadcrumb>li>.divider{padding:0 5px;color:#ccc}.breadcrumb>.active{color:#999}.pagination{margin:20px 0}.pagination ul{display:inline-block;*display:inline;margin-bottom:0;margin-left:0;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;*zoom:1;-webkit-box-shadow:0 1px 2px rgba(0,0,0,0.05);-moz-box-shadow:0 1px 2px rgba(0,0,0,0.05);box-shadow:0 1px 2px rgba(0,0,0,0.05)}.pagination ul>li{display:inline}.pagination ul>li>a,.pagination ul>li>span{float:left;padding:4px 12px;line-height:20px;text-decoration:none;background-color:#fff;border:1px solid #ddd;border-left-width:0}.pagination ul>li>a:hover,.pagination ul>.active>a,.pagination ul>.active>span{background-color:#f5f5f5}.pagination ul>.active>a,.pagination ul>.active>span{color:#999;cursor:default}.pagination ul>.disabled>span,.pagination ul>.disabled>a,.pagination ul>.disabled>a:hover{color:#999;cursor:default;background-color:transparent}.pagination ul>li:first-child>a,.pagination ul>li:first-child>span{border-left-width:1px;-webkit-border-bottom-left-radius:4px;border-bottom-left-radius:4px;-webkit-border-top-left-radius:4px;border-top-left-radius:4px;-moz-border-radius-bottomleft:4px;-moz-border-radius-topleft:4px}.pagination ul>li:last-child>a,.pagination ul>li:last-child>span{-webkit-border-top-right-radius:4px;border-top-right-radius:4px;-webkit-border-bottom-right-radius:4px;border-bottom-right-radius:4px;-moz-border-radius-topright:4px;-moz-border-radius-bottomright:4px}.pagination-centered{text-align:center}.pagination-right{text-align:right}.pagination-large ul>li>a,.pagination-large ul>li>span{padding:11px 19px;font-size:17.5px}.pagination-large ul>li:first-child>a,.pagination-large ul>li:first-child>span{-webkit-border-bottom-left-radius:6px;border-bottom-left-radius:6px;-webkit-border-top-left-radius:6px;border-top-left-radius:6px;-moz-border-radius-bottomleft:6px;-moz-border-radius-topleft:6px}.pagination-large ul>li:last-child>a,.pagination-large ul>li:last-child>span{-webkit-border-top-right-radius:6px;border-top-right-radius:6px;-webkit-border-bottom-right-radius:6px;border-bottom-right-radius:6px;-moz-border-radius-topright:6px;-moz-border-radius-bottomright:6px}.pagination-mini ul>li:first-child>a,.pagination-small ul>li:first-child>a,.pagination-mini ul>li:first-child>span,.pagination-small ul>li:first-child>span{-webkit-border-bottom-left-radius:3px;border-bottom-left-radius:3px;-webkit-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-bottomleft:3px;-moz-border-radius-topleft:3px}.pagination-mini ul>li:last-child>a,.pagination-small ul>li:last-child>a,.pagination-mini ul>li:last-child>span,.pagination-small ul>li:last-child>span{-webkit-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-border-bottom-right-radius:3px;border-bottom-right-radius:3px;-moz-border-radius-topright:3px;-moz-border-radius-bottomright:3px}.pagination-small ul>li>a,.pagination-small ul>li>span{padding:2px 10px;font-size:11.9px}.pagination-mini ul>li>a,.pagination-mini ul>li>span{padding:0 6px;font-size:10.5px}.pager{margin:20px 0;text-align:center;list-style:none;*zoom:1}.pager:before,.pager:after{display:table;line-height:0;content:""}.pager:after{clear:both}.pager li{display:inline}.pager li>a,.pager li>span{display:inline-block;padding:5px 14px;background-color:#fff;border:1px solid #ddd;-webkit-border-radius:15px;-moz-border-radius:15px;border-radius:15px}.pager li>a:hover{text-decoration:none;background-color:#f5f5f5}.pager .next>a,.pager .next>span{float:right}.pager .previous>a,.pager .previous>span{float:left}.pager .disabled>a,.pager .disabled>a:hover,.pager .disabled>span{color:#999;cursor:default;background-color:#fff}.modal-backdrop{position:fixed;top:0;right:0;bottom:0;left:0;z-index:1040;background-color:#000}.modal-backdrop.fade{opacity:0}.modal-backdrop,.modal-backdrop.fade.in{opacity:.8;filter:alpha(opacity=80)}.modal{position:fixed;top:10%;left:50%;z-index:1050;width:560px;margin-left:-280px;background-color:#fff;border:1px solid #999;border:1px solid rgba(0,0,0,0.3);*border:1px solid #999;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px;outline:0;-webkit-box-shadow:0 3px 7px rgba(0,0,0,0.3);-moz-box-shadow:0 3px 7px rgba(0,0,0,0.3);box-shadow:0 3px 7px rgba(0,0,0,0.3);-webkit-background-clip:padding-box;-moz-background-clip:padding-box;background-clip:padding-box}.modal.fade{top:-25%;-webkit-transition:opacity .3s linear,top .3s ease-out;-moz-transition:opacity .3s linear,top .3s ease-out;-o-transition:opacity .3s linear,top .3s ease-out;transition:opacity .3s linear,top .3s ease-out}.modal.fade.in{top:10%}.modal-header{padding:9px 15px;border-bottom:1px solid #eee}.modal-header .close{margin-top:2px}.modal-header h3{margin:0;line-height:30px}.modal-body{position:relative;max-height:400px;padding:15px;overflow-y:auto}.modal-form{margin-bottom:0}.modal-footer{padding:14px 15px 15px;margin-bottom:0;text-align:right;background-color:#f5f5f5;border-top:1px solid #ddd;-webkit-border-radius:0 0 6px 6px;-moz-border-radius:0 0 6px 6px;border-radius:0 0 6px 6px;*zoom:1;-webkit-box-shadow:inset 0 1px 0 #fff;-moz-box-shadow:inset 0 1px 0 #fff;box-shadow:inset 0 1px 0 #fff}.modal-footer:before,.modal-footer:after{display:table;line-height:0;content:""}.modal-footer:after{clear:both}.modal-footer .btn+.btn{margin-bottom:0;margin-left:5px}.modal-footer .btn-group .btn+.btn{margin-left:-1px}.modal-footer .btn-block+.btn-block{margin-left:0}.tooltip{position:absolute;z-index:1030;display:block;padding:5px;font-size:11px;opacity:0;filter:alpha(opacity=0);visibility:visible}.tooltip.in{opacity:.8;filter:alpha(opacity=80)}.tooltip.top{margin-top:-3px}.tooltip.right{margin-left:3px}.tooltip.bottom{margin-top:3px}.tooltip.left{margin-left:-3px}.tooltip-inner{max-width:200px;padding:3px 8px;color:#fff;text-align:center;text-decoration:none;background-color:#000;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.tooltip-arrow{position:absolute;width:0;height:0;border-color:transparent;border-style:solid}.tooltip.top .tooltip-arrow{bottom:0;left:50%;margin-left:-5px;border-top-color:#000;border-width:5px 5px 0}.tooltip.right .tooltip-arrow{top:50%;left:0;margin-top:-5px;border-right-color:#000;border-width:5px 5px 5px 0}.tooltip.left .tooltip-arrow{top:50%;right:0;margin-top:-5px;border-left-color:#000;border-width:5px 0 5px 5px}.tooltip.bottom .tooltip-arrow{top:0;left:50%;margin-left:-5px;border-bottom-color:#000;border-width:0 5px 5px}.popover{position:absolute;top:0;left:0;z-index:1010;display:none;width:236px;padding:1px;text-align:left;white-space:normal;background-color:#fff;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.2);-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px;-webkit-box-shadow:0 5px 10px rgba(0,0,0,0.2);-moz-box-shadow:0 5px 10px rgba(0,0,0,0.2);box-shadow:0 5px 10px rgba(0,0,0,0.2);-webkit-background-clip:padding-box;-moz-background-clip:padding;background-clip:padding-box}.popover.top{margin-top:-10px}.popover.right{margin-left:10px}.popover.bottom{margin-top:10px}.popover.left{margin-left:-10px}.popover-title{padding:8px 14px;margin:0;font-size:14px;font-weight:normal;line-height:18px;background-color:#f7f7f7;border-bottom:1px solid #ebebeb;-webkit-border-radius:5px 5px 0 0;-moz-border-radius:5px 5px 0 0;border-radius:5px 5px 0 0}.popover-content{padding:9px 14px}.popover .arrow,.popover .arrow:after{position:absolute;display:block;width:0;height:0;border-color:transparent;border-style:solid}.popover .arrow{border-width:11px}.popover .arrow:after{border-width:10px;content:""}.popover.top .arrow{bottom:-11px;left:50%;margin-left:-11px;border-top-color:#999;border-top-color:rgba(0,0,0,0.25);border-bottom-width:0}.popover.top .arrow:after{bottom:1px;margin-left:-10px;border-top-color:#fff;border-bottom-width:0}.popover.right .arrow{top:50%;left:-11px;margin-top:-11px;border-right-color:#999;border-right-color:rgba(0,0,0,0.25);border-left-width:0}.popover.right .arrow:after{bottom:-10px;left:1px;border-right-color:#fff;border-left-width:0}.popover.bottom .arrow{top:-11px;left:50%;margin-left:-11px;border-bottom-color:#999;border-bottom-color:rgba(0,0,0,0.25);border-top-width:0}.popover.bottom .arrow:after{top:1px;margin-left:-10px;border-bottom-color:#fff;border-top-width:0}.popover.left .arrow{top:50%;right:-11px;margin-top:-11px;border-left-color:#999;border-left-color:rgba(0,0,0,0.25);border-right-width:0}.popover.left .arrow:after{right:1px;bottom:-10px;border-left-color:#fff;border-right-width:0}.thumbnails{margin-left:-20px;list-style:none;*zoom:1}.thumbnails:before,.thumbnails:after{display:table;line-height:0;content:""}.thumbnails:after{clear:both}.row-fluid .thumbnails{margin-left:0}.thumbnails>li{float:left;margin-bottom:20px;margin-left:20px}.thumbnail{display:block;padding:4px;line-height:20px;border:1px solid #ddd;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;-webkit-box-shadow:0 1px 3px rgba(0,0,0,0.055);-moz-box-shadow:0 1px 3px rgba(0,0,0,0.055);box-shadow:0 1px 3px rgba(0,0,0,0.055);-webkit-transition:all .2s ease-in-out;-moz-transition:all .2s ease-in-out;-o-transition:all .2s ease-in-out;transition:all .2s ease-in-out}a.thumbnail:hover{border-color:#08c;-webkit-box-shadow:0 1px 4px rgba(0,105,214,0.25);-moz-box-shadow:0 1px 4px rgba(0,105,214,0.25);box-shadow:0 1px 4px rgba(0,105,214,0.25)}.thumbnail>img{display:block;max-width:100%;margin-right:auto;margin-left:auto}.thumbnail .caption{padding:9px;color:#555}.media,.media-body{overflow:hidden;*overflow:visible;zoom:1}.media,.media .media{margin-top:15px}.media:first-child{margin-top:0}.media-object{display:block}.media-heading{margin:0 0 5px}.media .pull-left{margin-right:10px}.media .pull-right{margin-left:10px}.media-list{margin-left:0;list-style:none}.label,.badge{display:inline-block;padding:2px 4px;font-size:11.844px;font-weight:bold;line-height:14px;color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);white-space:nowrap;vertical-align:baseline;background-color:#999}.label{-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.badge{padding-right:9px;padding-left:9px;-webkit-border-radius:9px;-moz-border-radius:9px;border-radius:9px}.label:empty,.badge:empty{display:none}a.label:hover,a.badge:hover{color:#fff;text-decoration:none;cursor:pointer}.label-important,.badge-important{background-color:#b94a48}.label-important[href],.badge-important[href]{background-color:#953b39}.label-warning,.badge-warning{background-color:#f89406}.label-warning[href],.badge-warning[href]{background-color:#c67605}.label-success,.badge-success{background-color:#468847}.label-success[href],.badge-success[href]{background-color:#356635}.label-info,.badge-info{background-color:#3a87ad}.label-info[href],.badge-info[href]{background-color:#2d6987}.label-inverse,.badge-inverse{background-color:#333}.label-inverse[href],.badge-inverse[href]{background-color:#1a1a1a}.btn .label,.btn .badge{position:relative;top:-1px}.btn-mini .label,.btn-mini .badge{top:0}@-webkit-keyframes progress-bar-stripes{from{background-position:40px 0}to{background-position:0 0}}@-moz-keyframes progress-bar-stripes{from{background-position:40px 0}to{background-position:0 0}}@-ms-keyframes progress-bar-stripes{from{background-position:40px 0}to{background-position:0 0}}@-o-keyframes progress-bar-stripes{from{background-position:0 0}to{background-position:40px 0}}@keyframes progress-bar-stripes{from{background-position:40px 0}to{background-position:0 0}}.progress{height:20px;margin-bottom:20px;overflow:hidden;background-color:#f7f7f7;background-image:-moz-linear-gradient(top,#f5f5f5,#f9f9f9);background-image:-webkit-gradient(linear,0 0,0 100%,from(#f5f5f5),to(#f9f9f9));background-image:-webkit-linear-gradient(top,#f5f5f5,#f9f9f9);background-image:-o-linear-gradient(top,#f5f5f5,#f9f9f9);background-image:linear-gradient(to bottom,#f5f5f5,#f9f9f9);background-repeat:repeat-x;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff5f5f5',endColorstr='#fff9f9f9',GradientType=0);-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.1);-moz-box-shadow:inset 0 1px 2px rgba(0,0,0,0.1);box-shadow:inset 0 1px 2px rgba(0,0,0,0.1)}.progress .bar{float:left;width:0;height:100%;font-size:12px;color:#fff;text-align:center;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#0e90d2;background-image:-moz-linear-gradient(top,#149bdf,#0480be);background-image:-webkit-gradient(linear,0 0,0 100%,from(#149bdf),to(#0480be));background-image:-webkit-linear-gradient(top,#149bdf,#0480be);background-image:-o-linear-gradient(top,#149bdf,#0480be);background-image:linear-gradient(to bottom,#149bdf,#0480be);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff149bdf',endColorstr='#ff0480be',GradientType=0);-webkit-box-shadow:inset 0 -1px 0 rgba(0,0,0,0.15);-moz-box-shadow:inset 0 -1px 0 rgba(0,0,0,0.15);box-shadow:inset 0 -1px 0 rgba(0,0,0,0.15);-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;-webkit-transition:width .6s ease;-moz-transition:width .6s ease;-o-transition:width .6s ease;transition:width .6s ease}.progress .bar+.bar{-webkit-box-shadow:inset 1px 0 0 rgba(0,0,0,0.15),inset 0 -1px 0 rgba(0,0,0,0.15);-moz-box-shadow:inset 1px 0 0 rgba(0,0,0,0.15),inset 0 -1px 0 rgba(0,0,0,0.15);box-shadow:inset 1px 0 0 rgba(0,0,0,0.15),inset 0 -1px 0 rgba(0,0,0,0.15)}.progress-striped .bar{background-color:#149bdf;background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);-webkit-background-size:40px 40px;-moz-background-size:40px 40px;-o-background-size:40px 40px;background-size:40px 40px}.progress.active .bar{-webkit-animation:progress-bar-stripes 2s linear infinite;-moz-animation:progress-bar-stripes 2s linear infinite;-ms-animation:progress-bar-stripes 2s linear infinite;-o-animation:progress-bar-stripes 2s linear infinite;animation:progress-bar-stripes 2s linear infinite}.progress-danger .bar,.progress .bar-danger{background-color:#dd514c;background-image:-moz-linear-gradient(top,#ee5f5b,#c43c35);background-image:-webkit-gradient(linear,0 0,0 100%,from(#ee5f5b),to(#c43c35));background-image:-webkit-linear-gradient(top,#ee5f5b,#c43c35);background-image:-o-linear-gradient(top,#ee5f5b,#c43c35);background-image:linear-gradient(to bottom,#ee5f5b,#c43c35);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffee5f5b',endColorstr='#ffc43c35',GradientType=0)}.progress-danger.progress-striped .bar,.progress-striped .bar-danger{background-color:#ee5f5b;background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent)}.progress-success .bar,.progress .bar-success{background-color:#5eb95e;background-image:-moz-linear-gradient(top,#62c462,#57a957);background-image:-webkit-gradient(linear,0 0,0 100%,from(#62c462),to(#57a957));background-image:-webkit-linear-gradient(top,#62c462,#57a957);background-image:-o-linear-gradient(top,#62c462,#57a957);background-image:linear-gradient(to bottom,#62c462,#57a957);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff62c462',endColorstr='#ff57a957',GradientType=0)}.progress-success.progress-striped .bar,.progress-striped .bar-success{background-color:#62c462;background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent)}.progress-info .bar,.progress .bar-info{background-color:#4bb1cf;background-image:-moz-linear-gradient(top,#5bc0de,#339bb9);background-image:-webkit-gradient(linear,0 0,0 100%,from(#5bc0de),to(#339bb9));background-image:-webkit-linear-gradient(top,#5bc0de,#339bb9);background-image:-o-linear-gradient(top,#5bc0de,#339bb9);background-image:linear-gradient(to bottom,#5bc0de,#339bb9);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5bc0de',endColorstr='#ff339bb9',GradientType=0)}.progress-info.progress-striped .bar,.progress-striped .bar-info{background-color:#5bc0de;background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent)}.progress-warning .bar,.progress .bar-warning{background-color:#faa732;background-image:-moz-linear-gradient(top,#fbb450,#f89406);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fbb450),to(#f89406));background-image:-webkit-linear-gradient(top,#fbb450,#f89406);background-image:-o-linear-gradient(top,#fbb450,#f89406);background-image:linear-gradient(to bottom,#fbb450,#f89406);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fffbb450',endColorstr='#fff89406',GradientType=0)}.progress-warning.progress-striped .bar,.progress-striped .bar-warning{background-color:#fbb450;background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent)}.accordion{margin-bottom:20px}.accordion-group{margin-bottom:2px;border:1px solid #e5e5e5;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.accordion-heading{border-bottom:0}.accordion-heading .accordion-toggle{display:block;padding:8px 15px}.accordion-toggle{cursor:pointer}.accordion-inner{padding:9px 15px;border-top:1px solid #e5e5e5}.carousel{position:relative;margin-bottom:20px;line-height:1}.carousel-inner{position:relative;width:100%;overflow:hidden}.carousel-inner>.item{position:relative;display:none;-webkit-transition:.6s ease-in-out left;-moz-transition:.6s ease-in-out left;-o-transition:.6s ease-in-out left;transition:.6s ease-in-out left}.carousel-inner>.item>img{display:block;line-height:1}.carousel-inner>.active,.carousel-inner>.next,.carousel-inner>.prev{display:block}.carousel-inner>.active{left:0}.carousel-inner>.next,.carousel-inner>.prev{position:absolute;top:0;width:100%}.carousel-inner>.next{left:100%}.carousel-inner>.prev{left:-100%}.carousel-inner>.next.left,.carousel-inner>.prev.right{left:0}.carousel-inner>.active.left{left:-100%}.carousel-inner>.active.right{left:100%}.carousel-control{position:absolute;top:40%;left:15px;width:40px;height:40px;margin-top:-20px;font-size:60px;font-weight:100;line-height:30px;color:#fff;text-align:center;background:#222;border:3px solid #fff;-webkit-border-radius:23px;-moz-border-radius:23px;border-radius:23px;opacity:.5;filter:alpha(opacity=50)}.carousel-control.right{right:15px;left:auto}.carousel-control:hover{color:#fff;text-decoration:none;opacity:.9;filter:alpha(opacity=90)}.carousel-caption{position:absolute;right:0;bottom:0;left:0;padding:15px;background:#333;background:rgba(0,0,0,0.75)}.carousel-caption h4,.carousel-caption p{line-height:20px;color:#fff}.carousel-caption h4{margin:0 0 5px}.carousel-caption p{margin-bottom:0}.hero-unit{padding:60px;margin-bottom:30px;font-size:18px;font-weight:200;line-height:30px;color:inherit;background-color:#eee;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}.hero-unit h1{margin-bottom:0;font-size:60px;line-height:1;letter-spacing:-1px;color:inherit}.hero-unit li{line-height:30px}.pull-right{float:right}.pull-left{float:left}.hide{display:none}.show{display:block}.invisible{visibility:hidden}.affix{position:fixed}
20.13 +/*!
20.14 + * Bootstrap Responsive v2.2.2
20.15 + *
20.16 + * Copyright 2012 Twitter, Inc
20.17 + * Licensed under the Apache License v2.0
20.18 + * http://www.apache.org/licenses/LICENSE-2.0
20.19 + *
20.20 + * Designed and built with all the love in the world @twitter by @mdo and @fat.
20.21 + */@-ms-viewport{width:device-width}.clearfix{*zoom:1}.clearfix:before,.clearfix:after{display:table;line-height:0;content:""}.clearfix:after{clear:both}.hide-text{font:0/0 a;color:transparent;text-shadow:none;background-color:transparent;border:0}.input-block-level{display:block;width:100%;min-height:30px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.hidden{display:none;visibility:hidden}.visible-phone{display:none!important}.visible-tablet{display:none!important}.hidden-desktop{display:none!important}.visible-desktop{display:inherit!important}@media(min-width:768px) and (max-width:979px){.hidden-desktop{display:inherit!important}.visible-desktop{display:none!important}.visible-tablet{display:inherit!important}.hidden-tablet{display:none!important}}@media(max-width:767px){.hidden-desktop{display:inherit!important}.visible-desktop{display:none!important}.visible-phone{display:inherit!important}.hidden-phone{display:none!important}}@media(min-width:1200px){.row{margin-left:-30px;*zoom:1}.row:before,.row:after{display:table;line-height:0;content:""}.row:after{clear:both}[class*="span"]{float:left;min-height:1px;margin-left:30px}.container,.navbar-static-top .container,.navbar-fixed-top .container,.navbar-fixed-bottom .container{width:1170px}.span12{width:1170px}.span11{width:1070px}.span10{width:970px}.span9{width:870px}.span8{width:770px}.span7{width:670px}.span6{width:570px}.span5{width:470px}.span4{width:370px}.span3{width:270px}.span2{width:170px}.span1{width:70px}.offset12{margin-left:1230px}.offset11{margin-left:1130px}.offset10{margin-left:1030px}.offset9{margin-left:930px}.offset8{margin-left:830px}.offset7{margin-left:730px}.offset6{margin-left:630px}.offset5{margin-left:530px}.offset4{margin-left:430px}.offset3{margin-left:330px}.offset2{margin-left:230px}.offset1{margin-left:130px}.row-fluid{width:100%;*zoom:1}.row-fluid:before,.row-fluid:after{display:table;line-height:0;content:""}.row-fluid:after{clear:both}.row-fluid [class*="span"]{display:block;float:left;width:100%;min-height:30px;margin-left:2.564102564102564%;*margin-left:2.5109110747408616%;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.row-fluid [class*="span"]:first-child{margin-left:0}.row-fluid .controls-row [class*="span"]+[class*="span"]{margin-left:2.564102564102564%}.row-fluid .span12{width:100%;*width:99.94680851063829%}.row-fluid .span11{width:91.45299145299145%;*width:91.39979996362975%}.row-fluid .span10{width:82.90598290598291%;*width:82.8527914166212%}.row-fluid .span9{width:74.35897435897436%;*width:74.30578286961266%}.row-fluid .span8{width:65.81196581196582%;*width:65.75877432260411%}.row-fluid .span7{width:57.26495726495726%;*width:57.21176577559556%}.row-fluid .span6{width:48.717948717948715%;*width:48.664757228587014%}.row-fluid .span5{width:40.17094017094017%;*width:40.11774868157847%}.row-fluid .span4{width:31.623931623931625%;*width:31.570740134569924%}.row-fluid .span3{width:23.076923076923077%;*width:23.023731587561375%}.row-fluid .span2{width:14.52991452991453%;*width:14.476723040552828%}.row-fluid .span1{width:5.982905982905983%;*width:5.929714493544281%}.row-fluid .offset12{margin-left:105.12820512820512%;*margin-left:105.02182214948171%}.row-fluid .offset12:first-child{margin-left:102.56410256410257%;*margin-left:102.45771958537915%}.row-fluid .offset11{margin-left:96.58119658119658%;*margin-left:96.47481360247316%}.row-fluid .offset11:first-child{margin-left:94.01709401709402%;*margin-left:93.91071103837061%}.row-fluid .offset10{margin-left:88.03418803418803%;*margin-left:87.92780505546462%}.row-fluid .offset10:first-child{margin-left:85.47008547008548%;*margin-left:85.36370249136206%}.row-fluid .offset9{margin-left:79.48717948717949%;*margin-left:79.38079650845607%}.row-fluid .offset9:first-child{margin-left:76.92307692307693%;*margin-left:76.81669394435352%}.row-fluid .offset8{margin-left:70.94017094017094%;*margin-left:70.83378796144753%}.row-fluid .offset8:first-child{margin-left:68.37606837606839%;*margin-left:68.26968539734497%}.row-fluid .offset7{margin-left:62.393162393162385%;*margin-left:62.28677941443899%}.row-fluid .offset7:first-child{margin-left:59.82905982905982%;*margin-left:59.72267685033642%}.row-fluid .offset6{margin-left:53.84615384615384%;*margin-left:53.739770867430444%}.row-fluid .offset6:first-child{margin-left:51.28205128205128%;*margin-left:51.175668303327875%}.row-fluid .offset5{margin-left:45.299145299145295%;*margin-left:45.1927623204219%}.row-fluid .offset5:first-child{margin-left:42.73504273504273%;*margin-left:42.62865975631933%}.row-fluid .offset4{margin-left:36.75213675213675%;*margin-left:36.645753773413354%}.row-fluid .offset4:first-child{margin-left:34.18803418803419%;*margin-left:34.081651209310785%}.row-fluid .offset3{margin-left:28.205128205128204%;*margin-left:28.0987452264048%}.row-fluid .offset3:first-child{margin-left:25.641025641025642%;*margin-left:25.53464266230224%}.row-fluid .offset2{margin-left:19.65811965811966%;*margin-left:19.551736679396257%}.row-fluid .offset2:first-child{margin-left:17.094017094017094%;*margin-left:16.98763411529369%}.row-fluid .offset1{margin-left:11.11111111111111%;*margin-left:11.004728132387708%}.row-fluid .offset1:first-child{margin-left:8.547008547008547%;*margin-left:8.440625568285142%}input,textarea,.uneditable-input{margin-left:0}.controls-row [class*="span"]+[class*="span"]{margin-left:30px}input.span12,textarea.span12,.uneditable-input.span12{width:1156px}input.span11,textarea.span11,.uneditable-input.span11{width:1056px}input.span10,textarea.span10,.uneditable-input.span10{width:956px}input.span9,textarea.span9,.uneditable-input.span9{width:856px}input.span8,textarea.span8,.uneditable-input.span8{width:756px}input.span7,textarea.span7,.uneditable-input.span7{width:656px}input.span6,textarea.span6,.uneditable-input.span6{width:556px}input.span5,textarea.span5,.uneditable-input.span5{width:456px}input.span4,textarea.span4,.uneditable-input.span4{width:356px}input.span3,textarea.span3,.uneditable-input.span3{width:256px}input.span2,textarea.span2,.uneditable-input.span2{width:156px}input.span1,textarea.span1,.uneditable-input.span1{width:56px}.thumbnails{margin-left:-30px}.thumbnails>li{margin-left:30px}.row-fluid .thumbnails{margin-left:0}}@media(min-width:768px) and (max-width:979px){.row{margin-left:-20px;*zoom:1}.row:before,.row:after{display:table;line-height:0;content:""}.row:after{clear:both}[class*="span"]{float:left;min-height:1px;margin-left:20px}.container,.navbar-static-top .container,.navbar-fixed-top .container,.navbar-fixed-bottom .container{width:724px}.span12{width:724px}.span11{width:662px}.span10{width:600px}.span9{width:538px}.span8{width:476px}.span7{width:414px}.span6{width:352px}.span5{width:290px}.span4{width:228px}.span3{width:166px}.span2{width:104px}.span1{width:42px}.offset12{margin-left:764px}.offset11{margin-left:702px}.offset10{margin-left:640px}.offset9{margin-left:578px}.offset8{margin-left:516px}.offset7{margin-left:454px}.offset6{margin-left:392px}.offset5{margin-left:330px}.offset4{margin-left:268px}.offset3{margin-left:206px}.offset2{margin-left:144px}.offset1{margin-left:82px}.row-fluid{width:100%;*zoom:1}.row-fluid:before,.row-fluid:after{display:table;line-height:0;content:""}.row-fluid:after{clear:both}.row-fluid [class*="span"]{display:block;float:left;width:100%;min-height:30px;margin-left:2.7624309392265194%;*margin-left:2.709239449864817%;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.row-fluid [class*="span"]:first-child{margin-left:0}.row-fluid .controls-row [class*="span"]+[class*="span"]{margin-left:2.7624309392265194%}.row-fluid .span12{width:100%;*width:99.94680851063829%}.row-fluid .span11{width:91.43646408839778%;*width:91.38327259903608%}.row-fluid .span10{width:82.87292817679558%;*width:82.81973668743387%}.row-fluid .span9{width:74.30939226519337%;*width:74.25620077583166%}.row-fluid .span8{width:65.74585635359117%;*width:65.69266486422946%}.row-fluid .span7{width:57.18232044198895%;*width:57.12912895262725%}.row-fluid .span6{width:48.61878453038674%;*width:48.56559304102504%}.row-fluid .span5{width:40.05524861878453%;*width:40.00205712942283%}.row-fluid .span4{width:31.491712707182323%;*width:31.43852121782062%}.row-fluid .span3{width:22.92817679558011%;*width:22.87498530621841%}.row-fluid .span2{width:14.3646408839779%;*width:14.311449394616199%}.row-fluid .span1{width:5.801104972375691%;*width:5.747913483013988%}.row-fluid .offset12{margin-left:105.52486187845304%;*margin-left:105.41847889972962%}.row-fluid .offset12:first-child{margin-left:102.76243093922652%;*margin-left:102.6560479605031%}.row-fluid .offset11{margin-left:96.96132596685082%;*margin-left:96.8549429881274%}.row-fluid .offset11:first-child{margin-left:94.1988950276243%;*margin-left:94.09251204890089%}.row-fluid .offset10{margin-left:88.39779005524862%;*margin-left:88.2914070765252%}.row-fluid .offset10:first-child{margin-left:85.6353591160221%;*margin-left:85.52897613729868%}.row-fluid .offset9{margin-left:79.8342541436464%;*margin-left:79.72787116492299%}.row-fluid .offset9:first-child{margin-left:77.07182320441989%;*margin-left:76.96544022569647%}.row-fluid .offset8{margin-left:71.2707182320442%;*margin-left:71.16433525332079%}.row-fluid .offset8:first-child{margin-left:68.50828729281768%;*margin-left:68.40190431409427%}.row-fluid .offset7{margin-left:62.70718232044199%;*margin-left:62.600799341718584%}.row-fluid .offset7:first-child{margin-left:59.94475138121547%;*margin-left:59.838368402492065%}.row-fluid .offset6{margin-left:54.14364640883978%;*margin-left:54.037263430116376%}.row-fluid .offset6:first-child{margin-left:51.38121546961326%;*margin-left:51.27483249088986%}.row-fluid .offset5{margin-left:45.58011049723757%;*margin-left:45.47372751851417%}.row-fluid .offset5:first-child{margin-left:42.81767955801105%;*margin-left:42.71129657928765%}.row-fluid .offset4{margin-left:37.01657458563536%;*margin-left:36.91019160691196%}.row-fluid .offset4:first-child{margin-left:34.25414364640884%;*margin-left:34.14776066768544%}.row-fluid .offset3{margin-left:28.45303867403315%;*margin-left:28.346655695309746%}.row-fluid .offset3:first-child{margin-left:25.69060773480663%;*margin-left:25.584224756083227%}.row-fluid .offset2{margin-left:19.88950276243094%;*margin-left:19.783119783707537%}.row-fluid .offset2:first-child{margin-left:17.12707182320442%;*margin-left:17.02068884448102%}.row-fluid .offset1{margin-left:11.32596685082873%;*margin-left:11.219583872105325%}.row-fluid .offset1:first-child{margin-left:8.56353591160221%;*margin-left:8.457152932878806%}input,textarea,.uneditable-input{margin-left:0}.controls-row [class*="span"]+[class*="span"]{margin-left:20px}input.span12,textarea.span12,.uneditable-input.span12{width:710px}input.span11,textarea.span11,.uneditable-input.span11{width:648px}input.span10,textarea.span10,.uneditable-input.span10{width:586px}input.span9,textarea.span9,.uneditable-input.span9{width:524px}input.span8,textarea.span8,.uneditable-input.span8{width:462px}input.span7,textarea.span7,.uneditable-input.span7{width:400px}input.span6,textarea.span6,.uneditable-input.span6{width:338px}input.span5,textarea.span5,.uneditable-input.span5{width:276px}input.span4,textarea.span4,.uneditable-input.span4{width:214px}input.span3,textarea.span3,.uneditable-input.span3{width:152px}input.span2,textarea.span2,.uneditable-input.span2{width:90px}input.span1,textarea.span1,.uneditable-input.span1{width:28px}}@media(max-width:767px){body{padding-right:20px;padding-left:20px}.navbar-fixed-top,.navbar-fixed-bottom,.navbar-static-top{margin-right:-20px;margin-left:-20px}.container-fluid{padding:0}.dl-horizontal dt{float:none;width:auto;clear:none;text-align:left}.dl-horizontal dd{margin-left:0}.container{width:auto}.row-fluid{width:100%}.row,.thumbnails{margin-left:0}.thumbnails>li{float:none;margin-left:0}[class*="span"],.uneditable-input[class*="span"],.row-fluid [class*="span"]{display:block;float:none;width:100%;margin-left:0;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.span12,.row-fluid .span12{width:100%;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.row-fluid [class*="offset"]:first-child{margin-left:0}.input-large,.input-xlarge,.input-xxlarge,input[class*="span"],select[class*="span"],textarea[class*="span"],.uneditable-input{display:block;width:100%;min-height:30px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.input-prepend input,.input-append input,.input-prepend input[class*="span"],.input-append input[class*="span"]{display:inline-block;width:auto}.controls-row [class*="span"]+[class*="span"]{margin-left:0}.modal{position:fixed;top:20px;right:20px;left:20px;width:auto;margin:0}.modal.fade{top:-100px}.modal.fade.in{top:20px}}@media(max-width:480px){.nav-collapse{-webkit-transform:translate3d(0,0,0)}.page-header h1 small{display:block;line-height:20px}input[type="checkbox"],input[type="radio"]{border:1px solid #ccc}.form-horizontal .control-label{float:none;width:auto;padding-top:0;text-align:left}.form-horizontal .controls{margin-left:0}.form-horizontal .control-list{padding-top:0}.form-horizontal .form-actions{padding-right:10px;padding-left:10px}.media .pull-left,.media .pull-right{display:block;float:none;margin-bottom:10px}.media-object{margin-right:0;margin-left:0}.modal{top:10px;right:10px;left:10px}.modal-header .close{padding:10px;margin:-10px}.carousel-caption{position:static}}@media(max-width:979px){body{padding-top:0}.navbar-fixed-top,.navbar-fixed-bottom{position:static}.navbar-fixed-top{margin-bottom:20px}.navbar-fixed-bottom{margin-top:20px}.navbar-fixed-top .navbar-inner,.navbar-fixed-bottom .navbar-inner{padding:5px}.navbar .container{width:auto;padding:0}.navbar .brand{padding-right:10px;padding-left:10px;margin:0 0 0 -5px}.nav-collapse{clear:both}.nav-collapse .nav{float:none;margin:0 0 10px}.nav-collapse .nav>li{float:none}.nav-collapse .nav>li>a{margin-bottom:2px}.nav-collapse .nav>.divider-vertical{display:none}.nav-collapse .nav .nav-header{color:#777;text-shadow:none}.nav-collapse .nav>li>a,.nav-collapse .dropdown-menu a{padding:9px 15px;font-weight:bold;color:#777;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.nav-collapse .btn{padding:4px 10px 4px;font-weight:normal;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.nav-collapse .dropdown-menu li+li a{margin-bottom:2px}.nav-collapse .nav>li>a:hover,.nav-collapse .dropdown-menu a:hover{background-color:#f2f2f2}.navbar-inverse .nav-collapse .nav>li>a,.navbar-inverse .nav-collapse .dropdown-menu a{color:#999}.navbar-inverse .nav-collapse .nav>li>a:hover,.navbar-inverse .nav-collapse .dropdown-menu a:hover{background-color:#111}.nav-collapse.in .btn-group{padding:0;margin-top:5px}.nav-collapse .dropdown-menu{position:static;top:auto;left:auto;display:none;float:none;max-width:none;padding:0;margin:0 15px;background-color:transparent;border:0;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0;-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none}.nav-collapse .open>.dropdown-menu{display:block}.nav-collapse .dropdown-menu:before,.nav-collapse .dropdown-menu:after{display:none}.nav-collapse .dropdown-menu .divider{display:none}.nav-collapse .nav>li>.dropdown-menu:before,.nav-collapse .nav>li>.dropdown-menu:after{display:none}.nav-collapse .navbar-form,.nav-collapse .navbar-search{float:none;padding:10px 15px;margin:10px 0;border-top:1px solid #f2f2f2;border-bottom:1px solid #f2f2f2;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.1);-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.1);box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.1)}.navbar-inverse .nav-collapse .navbar-form,.navbar-inverse .nav-collapse .navbar-search{border-top-color:#111;border-bottom-color:#111}.navbar .nav-collapse .nav.pull-right{float:none;margin-left:0}.nav-collapse,.nav-collapse.collapse{height:0;overflow:hidden}.navbar .btn-navbar{display:block}.navbar-static .navbar-inner{padding-right:10px;padding-left:10px}}@media(min-width:980px){.nav-collapse.collapse{height:auto!important;overflow:visible!important}}
21.1 Binary file dew/src/main/resources/org/apidesign/bck2brwsr/dew/img/error.png has changed
22.1 Binary file dew/src/main/resources/org/apidesign/bck2brwsr/dew/img/glyphicons-halflings-white.png has changed
23.1 Binary file dew/src/main/resources/org/apidesign/bck2brwsr/dew/img/glyphicons-halflings.png has changed
24.1 Binary file dew/src/main/resources/org/apidesign/bck2brwsr/dew/img/html5.png has changed
25.1 Binary file dew/src/main/resources/org/apidesign/bck2brwsr/dew/img/java.png has changed
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
26.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/index.html Wed Jan 23 20:16:48 2013 +0100
26.3 @@ -0,0 +1,98 @@
26.4 +<!--
26.5 +To change this template, choose Tools | Templates
26.6 +and open the template in the editor.
26.7 +-->
26.8 +<!DOCTYPE html>
26.9 +<html lang="en" ng-app="bck2brwsr" ng-controller="DevCtrl">
26.10 + <head>
26.11 + <title>Back2Browser - DEW</title>
26.12 + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
26.13 + <meta name="viewport" content="width=device-width, initial-scale=1.0">
26.14 + <link rel="stylesheet" href="css/bootstrap-combined.min.css"/>
26.15 + <link rel="stylesheet" href="js/codemirror/codemirror.css">
26.16 + <link rel="stylesheet" href="js/codemirror/theme/elegant.css"/>
26.17 + <link rel="stylesheet" href="css/app.css"/>
26.18 + </head>
26.19 + <body>
26.20 +
26.21 + <div class="navbar navbar-fixed-top" style="width: 100%">
26.22 + <div class="navbar-inner" style="padding-left: 12px; padding-right: 12px;">
26.23 + <!-- a class="brand" style="font-size: 100%"><span class="text-info"><b>Java and HTML5</b></span><small>- Together at Last!</small></a-->
26.24 + <form class="navbar-form pull-right">
26.25 + <!-- select class="span2"></select -->
26.26 + <button ng-click="post()" class="btn btn-warning">Rebuild</button>
26.27 + </form>
26.28 + <!-- ul class="nav">
26.29 + <li><select class="btn-small" type="text"></select></li>
26.30 + </ul -->
26.31 + <!-- form class="form form-horizontal pull-right">
26.32 + <button class="btn btn-warning btn-small pull-right top" ng-click="post()">Rebuild</button>
26.33 + </form -->
26.34 + <!-- ul class="nav pull-right">
26.35 +
26.36 + </ul-->
26.37 + </div>
26.38 + </div>
26.39 +
26.40 + <div class="container-fluid">
26.41 +
26.42 + <div style="height: 4em;"> </div>
26.43 +
26.44 + <div class="row-fluid">
26.45 + <div class="span6" style="margin-bottom: 10px;">
26.46 + <table class="table table-condensed" style="margin-bottom: 2px">
26.47 + <tr><td><i class="ic-html5"></i> HTML5</td></tr>
26.48 + </table>
26.49 + <div>
26.50 + <textarea ui-codemirror='{ lineNumbers : true, mode : "xml", theme : "elegant", matchBrackets : true, lineWrapping : true }' ng-model="html"></textarea>
26.51 + <div class="alert alert-error" ng-show="doc.modelError">
26.52 + <small>{{doc.modelError.toString()}}</small>
26.53 + </div>
26.54 + </div>
26.55 + </div>
26.56 +
26.57 + <div class="span6">
26.58 + <table class="table table-condensed" style="margin-bottom: 2px">
26.59 + <tr><td><i class="ic-java"></i> Java</td></tr>
26.60 + </table>
26.61 + <div>
26.62 + <textarea id="editorJava" ui-codemirror='{ lineNumbers : true, mode : "text/x-java", theme : "elegant", matchBrackets : true, lineWrapping : true, gutters: ["CodeMirror-linenumbers", "issues"] }' ng-model="java"></textarea>
26.63 + <div class="alert alert-error" ng-show="doc.modelError">
26.64 + <small>{{doc.modelError.toString()}}</small>
26.65 + </div>
26.66 + </div>
26.67 + </div>
26.68 +
26.69 + </div>
26.70 +
26.71 + <table class="table table-condensed">
26.72 + <tr ng-click="gotoError(e.line, e.col)" ng-repeat="e in errors" ng-class="errorClass(e.kind)">
26.73 + <td style="text-align: right">{{e.line}}</td>
26.74 + <td>:</td>
26.75 + <td style="text-align: left">{{e.col}}</td>
26.76 + <td width="100%" class="text-error error-hover">{{e.msg}} <i class="icon-play"/></td>
26.77 + </tr>
26.78 + </table>
26.79 +
26.80 +
26.81 + <div> </div>
26.82 +
26.83 + <ul class="nav nav-tabs">
26.84 + <li ng-class="'active'"><a href="#">Result</a></li>
26.85 + </ul>
26.86 +
26.87 +
26.88 + <!-- button class="btn" ng-click="reload()">Reload</button -->
26.89 + <iframe id="result" frameborder="0" scrolling="yes" width="100%" style="height: 1000px; overflow: auto; border: 1px solid #DFDFDF;" src="result.html">
26.90 + <p>Your browser does not support iframes.</p>
26.91 + </iframe>
26.92 +
26.93 + </div>
26.94 +
26.95 + <script src="js/angular/angular.min.js"></script>
26.96 + <script src="js/codemirror/codemirror.js"></script>
26.97 + <script src="js/codemirror/mode/xml.js"></script>
26.98 + <script src="js/codemirror/mode/clike.js"></script>
26.99 + <script src="js/app.js"></script>
26.100 + </body>
26.101 +</html>
27.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
27.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/js/angular/angular.min.js Wed Jan 23 20:16:48 2013 +0100
27.3 @@ -0,0 +1,159 @@
27.4 +/*
27.5 + AngularJS v1.0.3
27.6 + (c) 2010-2012 Google, Inc. http://angularjs.org
27.7 + License: MIT
27.8 +*/
27.9 +(function(U,ca,p){'use strict';function m(b,a,c){var d;if(b)if(N(b))for(d in b)d!="prototype"&&d!="length"&&d!="name"&&b.hasOwnProperty(d)&&a.call(c,b[d],d);else if(b.forEach&&b.forEach!==m)b.forEach(a,c);else if(L(b)&&wa(b.length))for(d=0;d<b.length;d++)a.call(c,b[d],d);else for(d in b)b.hasOwnProperty(d)&&a.call(c,b[d],d);return b}function lb(b){var a=[],c;for(c in b)b.hasOwnProperty(c)&&a.push(c);return a.sort()}function ec(b,a,c){for(var d=lb(b),e=0;e<d.length;e++)a.call(c,b[d[e]],d[e]);return d}
27.10 +function mb(b){return function(a,c){b(c,a)}}function xa(){for(var b=Z.length,a;b;){b--;a=Z[b].charCodeAt(0);if(a==57)return Z[b]="A",Z.join("");if(a==90)Z[b]="0";else return Z[b]=String.fromCharCode(a+1),Z.join("")}Z.unshift("0");return Z.join("")}function x(b){m(arguments,function(a){a!==b&&m(a,function(a,d){b[d]=a})});return b}function G(b){return parseInt(b,10)}function ya(b,a){return x(new (x(function(){},{prototype:b})),a)}function D(){}function ma(b){return b}function I(b){return function(){return b}}
27.11 +function t(b){return typeof b=="undefined"}function v(b){return typeof b!="undefined"}function L(b){return b!=null&&typeof b=="object"}function F(b){return typeof b=="string"}function wa(b){return typeof b=="number"}function na(b){return Sa.apply(b)=="[object Date]"}function J(b){return Sa.apply(b)=="[object Array]"}function N(b){return typeof b=="function"}function oa(b){return b&&b.document&&b.location&&b.alert&&b.setInterval}function R(b){return F(b)?b.replace(/^\s*/,"").replace(/\s*$/,""):b}function fc(b){return b&&
27.12 +(b.nodeName||b.bind&&b.find)}function Ta(b,a,c){var d=[];m(b,function(b,g,i){d.push(a.call(c,b,g,i))});return d}function gc(b,a){var c=0,d;if(J(b)||F(b))return b.length;else if(L(b))for(d in b)(!a||b.hasOwnProperty(d))&&c++;return c}function za(b,a){if(b.indexOf)return b.indexOf(a);for(var c=0;c<b.length;c++)if(a===b[c])return c;return-1}function Ua(b,a){var c=za(b,a);c>=0&&b.splice(c,1);return a}function V(b,a){if(oa(b)||b&&b.$evalAsync&&b.$watch)throw B("Can't copy Window or Scope");if(a){if(b===
27.13 +a)throw B("Can't copy equivalent objects or arrays");if(J(b)){for(;a.length;)a.pop();for(var c=0;c<b.length;c++)a.push(V(b[c]))}else for(c in m(a,function(b,c){delete a[c]}),b)a[c]=V(b[c])}else(a=b)&&(J(b)?a=V(b,[]):na(b)?a=new Date(b.getTime()):L(b)&&(a=V(b,{})));return a}function hc(b,a){var a=a||{},c;for(c in b)b.hasOwnProperty(c)&&c.substr(0,2)!=="$$"&&(a[c]=b[c]);return a}function ha(b,a){if(b===a)return!0;if(b===null||a===null)return!1;if(b!==b&&a!==a)return!0;var c=typeof b,d;if(c==typeof a&&
27.14 +c=="object")if(J(b)){if((c=b.length)==a.length){for(d=0;d<c;d++)if(!ha(b[d],a[d]))return!1;return!0}}else if(na(b))return na(a)&&b.getTime()==a.getTime();else{if(b&&b.$evalAsync&&b.$watch||a&&a.$evalAsync&&a.$watch||oa(b)||oa(a))return!1;c={};for(d in b){if(d.charAt(0)!=="$"&&!N(b[d])&&!ha(b[d],a[d]))return!1;c[d]=!0}for(d in a)if(!c[d]&&d.charAt(0)!=="$"&&!N(a[d]))return!1;return!0}return!1}function Va(b,a){var c=arguments.length>2?ia.call(arguments,2):[];return N(a)&&!(a instanceof RegExp)?c.length?
27.15 +function(){return arguments.length?a.apply(b,c.concat(ia.call(arguments,0))):a.apply(b,c)}:function(){return arguments.length?a.apply(b,arguments):a.call(b)}:a}function ic(b,a){var c=a;/^\$+/.test(b)?c=p:oa(a)?c="$WINDOW":a&&ca===a?c="$DOCUMENT":a&&a.$evalAsync&&a.$watch&&(c="$SCOPE");return c}function da(b,a){return JSON.stringify(b,ic,a?" ":null)}function nb(b){return F(b)?JSON.parse(b):b}function Wa(b){b&&b.length!==0?(b=E(""+b),b=!(b=="f"||b=="0"||b=="false"||b=="no"||b=="n"||b=="[]")):b=!1;
27.16 +return b}function pa(b){b=u(b).clone();try{b.html("")}catch(a){}return u("<div>").append(b).html().match(/^(<[^>]+>)/)[1].replace(/^<([\w\-]+)/,function(a,b){return"<"+E(b)})}function Xa(b){var a={},c,d;m((b||"").split("&"),function(b){b&&(c=b.split("="),d=decodeURIComponent(c[0]),a[d]=v(c[1])?decodeURIComponent(c[1]):!0)});return a}function ob(b){var a=[];m(b,function(b,d){a.push(Ya(d,!0)+(b===!0?"":"="+Ya(b,!0)))});return a.length?a.join("&"):""}function Za(b){return Ya(b,!0).replace(/%26/gi,"&").replace(/%3D/gi,
27.17 +"=").replace(/%2B/gi,"+")}function Ya(b,a){return encodeURIComponent(b).replace(/%40/gi,"@").replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(a?null:/%20/g,"+")}function jc(b,a){function c(a){a&&d.push(a)}var d=[b],e,g,i=["ng:app","ng-app","x-ng-app","data-ng-app"],f=/\sng[:\-]app(:\s*([\w\d_]+);?)?\s/;m(i,function(a){i[a]=!0;c(ca.getElementById(a));a=a.replace(":","\\:");b.querySelectorAll&&(m(b.querySelectorAll("."+a),c),m(b.querySelectorAll("."+a+"\\:"),c),m(b.querySelectorAll("["+
27.18 +a+"]"),c))});m(d,function(a){if(!e){var b=f.exec(" "+a.className+" ");b?(e=a,g=(b[2]||"").replace(/\s+/g,",")):m(a.attributes,function(b){if(!e&&i[b.name])e=a,g=b.value})}});e&&a(e,g?[g]:[])}function pb(b,a){b=u(b);a=a||[];a.unshift(["$provide",function(a){a.value("$rootElement",b)}]);a.unshift("ng");var c=qb(a);c.invoke(["$rootScope","$rootElement","$compile","$injector",function(a,b,c,i){a.$apply(function(){b.data("$injector",i);c(b)(a)})}]);return c}function $a(b,a){a=a||"_";return b.replace(kc,
27.19 +function(b,d){return(d?a:"")+b.toLowerCase()})}function qa(b,a,c){if(!b)throw new B("Argument '"+(a||"?")+"' is "+(c||"required"));return b}function ra(b,a,c){c&&J(b)&&(b=b[b.length-1]);qa(N(b),a,"not a function, got "+(b&&typeof b=="object"?b.constructor.name||"Object":typeof b));return b}function lc(b){function a(a,b,e){return a[b]||(a[b]=e())}return a(a(b,"angular",Object),"module",function(){var b={};return function(d,e,g){e&&b.hasOwnProperty(d)&&(b[d]=null);return a(b,d,function(){function a(c,
27.20 +d,e){return function(){b[e||"push"]([c,d,arguments]);return j}}if(!e)throw B("No module: "+d);var b=[],c=[],k=a("$injector","invoke"),j={_invokeQueue:b,_runBlocks:c,requires:e,name:d,provider:a("$provide","provider"),factory:a("$provide","factory"),service:a("$provide","service"),value:a("$provide","value"),constant:a("$provide","constant","unshift"),filter:a("$filterProvider","register"),controller:a("$controllerProvider","register"),directive:a("$compileProvider","directive"),config:k,run:function(a){c.push(a);
27.21 +return this}};g&&k(g);return j})}})}function rb(b){return b.replace(mc,function(a,b,d,e){return e?d.toUpperCase():d}).replace(nc,"Moz$1")}function ab(b,a){function c(){var e;for(var b=[this],c=a,i,f,h,k,j,l;b.length;){i=b.shift();f=0;for(h=i.length;f<h;f++){k=u(i[f]);c?k.triggerHandler("$destroy"):c=!c;j=0;for(e=(l=k.children()).length,k=e;j<k;j++)b.push(ja(l[j]))}}return d.apply(this,arguments)}var d=ja.fn[b],d=d.$original||d;c.$original=d;ja.fn[b]=c}function Q(b){if(b instanceof Q)return b;if(!(this instanceof
27.22 +Q)){if(F(b)&&b.charAt(0)!="<")throw B("selectors not implemented");return new Q(b)}if(F(b)){var a=ca.createElement("div");a.innerHTML="<div> </div>"+b;a.removeChild(a.firstChild);bb(this,a.childNodes);this.remove()}else bb(this,b)}function cb(b){return b.cloneNode(!0)}function sa(b){sb(b);for(var a=0,b=b.childNodes||[];a<b.length;a++)sa(b[a])}function tb(b,a,c){var d=$(b,"events");$(b,"handle")&&(t(a)?m(d,function(a,c){db(b,c,a);delete d[c]}):t(c)?(db(b,a,d[a]),delete d[a]):Ua(d[a],c))}function sb(b){var a=
27.23 +b[Aa],c=Ba[a];c&&(c.handle&&(c.events.$destroy&&c.handle({},"$destroy"),tb(b)),delete Ba[a],b[Aa]=p)}function $(b,a,c){var d=b[Aa],d=Ba[d||-1];if(v(c))d||(b[Aa]=d=++oc,d=Ba[d]={}),d[a]=c;else return d&&d[a]}function ub(b,a,c){var d=$(b,"data"),e=v(c),g=!e&&v(a),i=g&&!L(a);!d&&!i&&$(b,"data",d={});if(e)d[a]=c;else if(g)if(i)return d&&d[a];else x(d,a);else return d}function Ca(b,a){return(" "+b.className+" ").replace(/[\n\t]/g," ").indexOf(" "+a+" ")>-1}function vb(b,a){a&&m(a.split(" "),function(a){b.className=
27.24 +R((" "+b.className+" ").replace(/[\n\t]/g," ").replace(" "+R(a)+" "," "))})}function wb(b,a){a&&m(a.split(" "),function(a){if(!Ca(b,a))b.className=R(b.className+" "+R(a))})}function bb(b,a){if(a)for(var a=!a.nodeName&&v(a.length)&&!oa(a)?a:[a],c=0;c<a.length;c++)b.push(a[c])}function xb(b,a){return Da(b,"$"+(a||"ngController")+"Controller")}function Da(b,a,c){b=u(b);for(b[0].nodeType==9&&(b=b.find("html"));b.length;){if(c=b.data(a))return c;b=b.parent()}}function yb(b,a){var c=Ea[a.toLowerCase()];
27.25 +return c&&zb[b.nodeName]&&c}function pc(b,a){var c=function(c,e){if(!c.preventDefault)c.preventDefault=function(){c.returnValue=!1};if(!c.stopPropagation)c.stopPropagation=function(){c.cancelBubble=!0};if(!c.target)c.target=c.srcElement||ca;if(t(c.defaultPrevented)){var g=c.preventDefault;c.preventDefault=function(){c.defaultPrevented=!0;g.call(c)};c.defaultPrevented=!1}c.isDefaultPrevented=function(){return c.defaultPrevented};m(a[e||c.type],function(a){a.call(b,c)});aa<=8?(c.preventDefault=null,
27.26 +c.stopPropagation=null,c.isDefaultPrevented=null):(delete c.preventDefault,delete c.stopPropagation,delete c.isDefaultPrevented)};c.elem=b;return c}function ga(b){var a=typeof b,c;if(a=="object"&&b!==null)if(typeof(c=b.$$hashKey)=="function")c=b.$$hashKey();else{if(c===p)c=b.$$hashKey=xa()}else c=b;return a+":"+c}function Fa(b){m(b,this.put,this)}function eb(){}function Ab(b){var a,c;if(typeof b=="function"){if(!(a=b.$inject))a=[],c=b.toString().replace(qc,""),c=c.match(rc),m(c[1].split(sc),function(b){b.replace(tc,
27.27 +function(b,c,d){a.push(d)})}),b.$inject=a}else J(b)?(c=b.length-1,ra(b[c],"fn"),a=b.slice(0,c)):ra(b,"fn",!0);return a}function qb(b){function a(a){return function(b,c){if(L(b))m(b,mb(a));else return a(b,c)}}function c(a,b){N(b)&&(b=l.instantiate(b));if(!b.$get)throw B("Provider "+a+" must define $get factory method.");return j[a+f]=b}function d(a,b){return c(a,{$get:b})}function e(a){var b=[];m(a,function(a){if(!k.get(a))if(k.put(a,!0),F(a)){var c=ta(a);b=b.concat(e(c.requires)).concat(c._runBlocks);
27.28 +try{for(var d=c._invokeQueue,c=0,f=d.length;c<f;c++){var h=d[c],g=h[0]=="$injector"?l:l.get(h[0]);g[h[1]].apply(g,h[2])}}catch(n){throw n.message&&(n.message+=" from "+a),n;}}else if(N(a))try{b.push(l.invoke(a))}catch(i){throw i.message&&(i.message+=" from "+a),i;}else if(J(a))try{b.push(l.invoke(a))}catch(j){throw j.message&&(j.message+=" from "+String(a[a.length-1])),j;}else ra(a,"module")});return b}function g(a,b){function c(d){if(typeof d!=="string")throw B("Service name expected");if(a.hasOwnProperty(d)){if(a[d]===
27.29 +i)throw B("Circular dependency: "+h.join(" <- "));return a[d]}else try{return h.unshift(d),a[d]=i,a[d]=b(d)}finally{h.shift()}}function d(a,b,e){var f=[],k=Ab(a),g,n,i;n=0;for(g=k.length;n<g;n++)i=k[n],f.push(e&&e.hasOwnProperty(i)?e[i]:c(i,h));a.$inject||(a=a[g]);switch(b?-1:f.length){case 0:return a();case 1:return a(f[0]);case 2:return a(f[0],f[1]);case 3:return a(f[0],f[1],f[2]);case 4:return a(f[0],f[1],f[2],f[3]);case 5:return a(f[0],f[1],f[2],f[3],f[4]);case 6:return a(f[0],f[1],f[2],f[3],
27.30 +f[4],f[5]);case 7:return a(f[0],f[1],f[2],f[3],f[4],f[5],f[6]);case 8:return a(f[0],f[1],f[2],f[3],f[4],f[5],f[6],f[7]);case 9:return a(f[0],f[1],f[2],f[3],f[4],f[5],f[6],f[7],f[8]);case 10:return a(f[0],f[1],f[2],f[3],f[4],f[5],f[6],f[7],f[8],f[9]);default:return a.apply(b,f)}}return{invoke:d,instantiate:function(a,b){var c=function(){},e;c.prototype=(J(a)?a[a.length-1]:a).prototype;c=new c;e=d(a,c,b);return L(e)?e:c},get:c,annotate:Ab}}var i={},f="Provider",h=[],k=new Fa,j={$provide:{provider:a(c),
27.31 +factory:a(d),service:a(function(a,b){return d(a,["$injector",function(a){return a.instantiate(b)}])}),value:a(function(a,b){return d(a,I(b))}),constant:a(function(a,b){j[a]=b;o[a]=b}),decorator:function(a,b){var c=l.get(a+f),d=c.$get;c.$get=function(){var a=r.invoke(d,c);return r.invoke(b,null,{$delegate:a})}}}},l=g(j,function(){throw B("Unknown provider: "+h.join(" <- "));}),o={},r=o.$injector=g(o,function(a){a=l.get(a+f);return r.invoke(a.$get,a)});m(e(b),function(a){r.invoke(a||D)});return r}function uc(){var b=
27.32 +!0;this.disableAutoScrolling=function(){b=!1};this.$get=["$window","$location","$rootScope",function(a,c,d){function e(a){var b=null;m(a,function(a){!b&&E(a.nodeName)==="a"&&(b=a)});return b}function g(){var b=c.hash(),d;b?(d=i.getElementById(b))?d.scrollIntoView():(d=e(i.getElementsByName(b)))?d.scrollIntoView():b==="top"&&a.scrollTo(0,0):a.scrollTo(0,0)}var i=a.document;b&&d.$watch(function(){return c.hash()},function(){d.$evalAsync(g)});return g}]}function vc(b,a,c,d){function e(a){try{a.apply(null,
27.33 +ia.call(arguments,1))}finally{if(n--,n===0)for(;w.length;)try{w.pop()()}catch(b){c.error(b)}}}function g(a,b){(function ea(){m(q,function(a){a()});s=b(ea,a)})()}function i(){O!=f.url()&&(O=f.url(),m(A,function(a){a(f.url())}))}var f=this,h=a[0],k=b.location,j=b.history,l=b.setTimeout,o=b.clearTimeout,r={};f.isMock=!1;var n=0,w=[];f.$$completeOutstandingRequest=e;f.$$incOutstandingRequestCount=function(){n++};f.notifyWhenNoOutstandingRequests=function(a){m(q,function(a){a()});n===0?a():w.push(a)};
27.34 +var q=[],s;f.addPollFn=function(a){t(s)&&g(100,l);q.push(a);return a};var O=k.href,C=a.find("base");f.url=function(a,b){if(a){if(O!=a)return O=a,d.history?b?j.replaceState(null,"",a):(j.pushState(null,"",a),C.attr("href",C.attr("href"))):b?k.replace(a):k.href=a,f}else return k.href.replace(/%27/g,"'")};var A=[],K=!1;f.onUrlChange=function(a){K||(d.history&&u(b).bind("popstate",i),d.hashchange?u(b).bind("hashchange",i):f.addPollFn(i),K=!0);A.push(a);return a};f.baseHref=function(){var a=C.attr("href");
27.35 +return a?a.replace(/^https?\:\/\/[^\/]*/,""):a};var W={},y="",M=f.baseHref();f.cookies=function(a,b){var d,e,f,k;if(a)if(b===p)h.cookie=escape(a)+"=;path="+M+";expires=Thu, 01 Jan 1970 00:00:00 GMT";else{if(F(b))d=(h.cookie=escape(a)+"="+escape(b)+";path="+M).length+1,d>4096&&c.warn("Cookie '"+a+"' possibly not set or overflowed because it was too large ("+d+" > 4096 bytes)!"),W.length>20&&c.warn("Cookie '"+a+"' possibly not set or overflowed because too many cookies were already set ("+W.length+
27.36 +" > 20 )")}else{if(h.cookie!==y){y=h.cookie;d=y.split("; ");W={};for(f=0;f<d.length;f++)e=d[f],k=e.indexOf("="),k>0&&(W[unescape(e.substring(0,k))]=unescape(e.substring(k+1)))}return W}};f.defer=function(a,b){var c;n++;c=l(function(){delete r[c];e(a)},b||0);r[c]=!0;return c};f.defer.cancel=function(a){return r[a]?(delete r[a],o(a),e(D),!0):!1}}function wc(){this.$get=["$window","$log","$sniffer","$document",function(b,a,c,d){return new vc(b,d,a,c)}]}function xc(){this.$get=function(){function b(b,
27.37 +d){function e(a){if(a!=l){if(o){if(o==a)o=a.n}else o=a;g(a.n,a.p);g(a,l);l=a;l.n=null}}function g(a,b){if(a!=b){if(a)a.p=b;if(b)b.n=a}}if(b in a)throw B("cacheId "+b+" taken");var i=0,f=x({},d,{id:b}),h={},k=d&&d.capacity||Number.MAX_VALUE,j={},l=null,o=null;return a[b]={put:function(a,b){var c=j[a]||(j[a]={key:a});e(c);t(b)||(a in h||i++,h[a]=b,i>k&&this.remove(o.key))},get:function(a){var b=j[a];if(b)return e(b),h[a]},remove:function(a){var b=j[a];if(b){if(b==l)l=b.p;if(b==o)o=b.n;g(b.n,b.p);delete j[a];
27.38 +delete h[a];i--}},removeAll:function(){h={};i=0;j={};l=o=null},destroy:function(){j=f=h=null;delete a[b]},info:function(){return x({},f,{size:i})}}}var a={};b.info=function(){var b={};m(a,function(a,e){b[e]=a.info()});return b};b.get=function(b){return a[b]};return b}}function yc(){this.$get=["$cacheFactory",function(b){return b("templates")}]}function Bb(b){var a={},c="Directive",d=/^\s*directive\:\s*([\d\w\-_]+)\s+(.*)$/,e=/(([\d\w\-_]+)(?:\:([^;]+))?;?)/,g="Template must have exactly one root element. was: ";
27.39 +this.directive=function f(d,e){F(d)?(qa(e,"directive"),a.hasOwnProperty(d)||(a[d]=[],b.factory(d+c,["$injector","$exceptionHandler",function(b,c){var e=[];m(a[d],function(a){try{var f=b.invoke(a);if(N(f))f={compile:I(f)};else if(!f.compile&&f.link)f.compile=I(f.link);f.priority=f.priority||0;f.name=f.name||d;f.require=f.require||f.controller&&f.name;f.restrict=f.restrict||"A";e.push(f)}catch(k){c(k)}});return e}])),a[d].push(e)):m(d,mb(f));return this};this.$get=["$injector","$interpolate","$exceptionHandler",
27.40 +"$http","$templateCache","$parse","$controller","$rootScope",function(b,h,k,j,l,o,r,n){function w(a,b,c){a instanceof u||(a=u(a));m(a,function(b,c){b.nodeType==3&&(a[c]=u(b).wrap("<span></span>").parent()[0])});var d=s(a,b,a,c);return function(b,c){qa(b,"scope");var e=c?ua.clone.call(a):a;e.data("$scope",b);q(e,"ng-scope");c&&c(e,b);d&&d(b,e,e);return e}}function q(a,b){try{a.addClass(b)}catch(c){}}function s(a,b,c,d){function e(a,c,d,k){for(var g,h,j,n,o,l=0,r=0,q=f.length;l<q;r++)j=c[r],g=f[l++],
27.41 +h=f[l++],g?(g.scope?(n=a.$new(L(g.scope)),u(j).data("$scope",n)):n=a,(o=g.transclude)||!k&&b?g(h,n,j,d,function(b){return function(c){var d=a.$new();return b(d,c).bind("$destroy",Va(d,d.$destroy))}}(o||b)):g(h,n,j,p,k)):h&&h(a,j.childNodes,p,k)}for(var f=[],k,g,h,j=0;j<a.length;j++)g=new ea,k=O(a[j],[],g,d),g=(k=k.length?C(k,a[j],g,b,c):null)&&k.terminal||!a[j].childNodes.length?null:s(a[j].childNodes,k?k.transclude:b),f.push(k),f.push(g),h=h||k||g;return h?e:null}function O(a,b,c,f){var k=c.$attr,
27.42 +g;switch(a.nodeType){case 1:A(b,fa(Cb(a).toLowerCase()),"E",f);var h,j,n;g=a.attributes;for(var o=0,l=g&&g.length;o<l;o++)if(h=g[o],h.specified)j=h.name,n=fa(j.toLowerCase()),k[n]=j,c[n]=h=R(aa&&j=="href"?decodeURIComponent(a.getAttribute(j,2)):h.value),yb(a,n)&&(c[n]=!0),X(a,b,h,n),A(b,n,"A",f);a=a.className;if(F(a)&&a!=="")for(;g=e.exec(a);)n=fa(g[2]),A(b,n,"C",f)&&(c[n]=R(g[3])),a=a.substr(g.index+g[0].length);break;case 3:H(b,a.nodeValue);break;case 8:try{if(g=d.exec(a.nodeValue))n=fa(g[1]),A(b,
27.43 +n,"M",f)&&(c[n]=R(g[2]))}catch(r){}}b.sort(y);return b}function C(a,b,c,d,e){function f(a,b){if(a)a.require=z.require,l.push(a);if(b)b.require=z.require,ba.push(b)}function h(a,b){var c,d="data",e=!1;if(F(a)){for(;(c=a.charAt(0))=="^"||c=="?";)a=a.substr(1),c=="^"&&(d="inheritedData"),e=e||c=="?";c=b[d]("$"+a+"Controller");if(!c&&!e)throw B("No controller: "+a);}else J(a)&&(c=[],m(a,function(a){c.push(h(a,b))}));return c}function j(a,d,e,f,g){var n,q,w,K,s;n=b===e?c:hc(c,new ea(u(e),c.$attr));q=n.$$element;
27.44 +if(C){var zc=/^\s*([@=&])\s*(\w*)\s*$/,O=d.$parent||d;m(C.scope,function(a,b){var c=a.match(zc)||[],e=c[2]||b,f,g,k;switch(c[1]){case "@":n.$observe(e,function(a){d[b]=a});n.$$observers[e].$$scope=O;break;case "=":g=o(n[e]);k=g.assign||function(){f=d[b]=g(O);throw B(Db+n[e]+" (directive: "+C.name+")");};f=d[b]=g(O);d.$watch(function(){var a=g(O);a!==d[b]&&(a!==f?f=d[b]=a:k(O,a=f=d[b]));return a});break;case "&":g=o(n[e]);d[b]=function(a){return g(O,a)};break;default:throw B("Invalid isolate scope definition for directive "+
27.45 +C.name+": "+a);}})}t&&m(t,function(a){var b={$scope:d,$element:q,$attrs:n,$transclude:g};s=a.controller;s=="@"&&(s=n[a.name]);q.data("$"+a.name+"Controller",r(s,b))});f=0;for(w=l.length;f<w;f++)try{K=l[f],K(d,q,n,K.require&&h(K.require,q))}catch(y){k(y,pa(q))}a&&a(d,e.childNodes,p,g);f=0;for(w=ba.length;f<w;f++)try{K=ba[f],K(d,q,n,K.require&&h(K.require,q))}catch(Ha){k(Ha,pa(q))}}for(var n=-Number.MAX_VALUE,l=[],ba=[],s=null,C=null,A=null,y=c.$$element=u(b),z,H,X,D,v=d,t,x,Y,E=0,G=a.length;E<G;E++){z=
27.46 +a[E];X=p;if(n>z.priority)break;if(Y=z.scope)M("isolated scope",C,z,y),L(Y)&&(q(y,"ng-isolate-scope"),C=z),q(y,"ng-scope"),s=s||z;H=z.name;if(Y=z.controller)t=t||{},M("'"+H+"' controller",t[H],z,y),t[H]=z;if(Y=z.transclude)M("transclusion",D,z,y),D=z,n=z.priority,Y=="element"?(X=u(b),y=c.$$element=u("<\!-- "+H+": "+c[H]+" --\>"),b=y[0],Ga(e,u(X[0]),b),v=w(X,d,n)):(X=u(cb(b)).contents(),y.html(""),v=w(X,d));if(Y=z.template)if(M("template",A,z,y),A=z,Y=Ha(Y),z.replace){X=u("<div>"+R(Y)+"</div>").contents();
27.47 +b=X[0];if(X.length!=1||b.nodeType!==1)throw new B(g+Y);Ga(e,y,b);H={$attr:{}};a=a.concat(O(b,a.splice(E+1,a.length-(E+1)),H));K(c,H);G=a.length}else y.html(Y);if(z.templateUrl)M("template",A,z,y),A=z,j=W(a.splice(E,a.length-E),j,y,c,e,z.replace,v),G=a.length;else if(z.compile)try{x=z.compile(y,c,v),N(x)?f(null,x):x&&f(x.pre,x.post)}catch(I){k(I,pa(y))}if(z.terminal)j.terminal=!0,n=Math.max(n,z.priority)}j.scope=s&&s.scope;j.transclude=D&&v;return j}function A(d,e,g,h){var j=!1;if(a.hasOwnProperty(e))for(var n,
27.48 +e=b.get(e+c),o=0,l=e.length;o<l;o++)try{if(n=e[o],(h===p||h>n.priority)&&n.restrict.indexOf(g)!=-1)d.push(n),j=!0}catch(r){k(r)}return j}function K(a,b){var c=b.$attr,d=a.$attr,e=a.$$element;m(a,function(d,e){e.charAt(0)!="$"&&(b[e]&&(d+=(e==="style"?";":" ")+b[e]),a.$set(e,d,!0,c[e]))});m(b,function(b,f){f=="class"?(q(e,b),a["class"]=(a["class"]?a["class"]+" ":"")+b):f=="style"?e.attr("style",e.attr("style")+";"+b):f.charAt(0)!="$"&&!a.hasOwnProperty(f)&&(a[f]=b,d[f]=c[f])})}function W(a,b,c,d,e,
27.49 +f,k){var h=[],n,o,r=c[0],q=a.shift(),w=x({},q,{controller:null,templateUrl:null,transclude:null,scope:null});c.html("");j.get(q.templateUrl,{cache:l}).success(function(j){var l,q,j=Ha(j);if(f){q=u("<div>"+R(j)+"</div>").contents();l=q[0];if(q.length!=1||l.nodeType!==1)throw new B(g+j);j={$attr:{}};Ga(e,c,l);O(l,a,j);K(d,j)}else l=r,c.html(j);a.unshift(w);n=C(a,c,d,k);for(o=s(c.contents(),k);h.length;){var ba=h.pop(),j=h.pop();q=h.pop();var y=h.pop(),m=l;q!==r&&(m=cb(l),Ga(j,u(q),m));n(function(){b(o,
27.50 +y,m,e,ba)},y,m,e,ba)}h=null}).error(function(a,b,c,d){throw B("Failed to load template: "+d.url);});return function(a,c,d,e,f){h?(h.push(c),h.push(d),h.push(e),h.push(f)):n(function(){b(o,c,d,e,f)},c,d,e,f)}}function y(a,b){return b.priority-a.priority}function M(a,b,c,d){if(b)throw B("Multiple directives ["+b.name+", "+c.name+"] asking for "+a+" on: "+pa(d));}function H(a,b){var c=h(b,!0);c&&a.push({priority:0,compile:I(function(a,b){var d=b.parent(),e=d.data("$binding")||[];e.push(c);q(d.data("$binding",
27.51 +e),"ng-binding");a.$watch(c,function(a){b[0].nodeValue=a})})})}function X(a,b,c,d){var e=h(c,!0);e&&b.push({priority:100,compile:I(function(a,b,c){b=c.$$observers||(c.$$observers={});d==="class"&&(e=h(c[d],!0));c[d]=p;(b[d]||(b[d]=[])).$$inter=!0;(c.$$observers&&c.$$observers[d].$$scope||a).$watch(e,function(a){c.$set(d,a)})})})}function Ga(a,b,c){var d=b[0],e=d.parentNode,f,g;if(a){f=0;for(g=a.length;f<g;f++)if(a[f]==d){a[f]=c;break}}e&&e.replaceChild(c,d);c[u.expando]=d[u.expando];b[0]=c}var ea=
27.52 +function(a,b){this.$$element=a;this.$attr=b||{}};ea.prototype={$normalize:fa,$set:function(a,b,c,d){var e=yb(this.$$element[0],a),f=this.$$observers;e&&(this.$$element.prop(a,b),d=e);this[a]=b;d?this.$attr[a]=d:(d=this.$attr[a])||(this.$attr[a]=d=$a(a,"-"));c!==!1&&(b===null||b===p?this.$$element.removeAttr(d):this.$$element.attr(d,b));f&&m(f[a],function(a){try{a(b)}catch(c){k(c)}})},$observe:function(a,b){var c=this,d=c.$$observers||(c.$$observers={}),e=d[a]||(d[a]=[]);e.push(b);n.$evalAsync(function(){e.$$inter||
27.53 +b(c[a])});return b}};var D=h.startSymbol(),ba=h.endSymbol(),Ha=D=="{{"||ba=="}}"?ma:function(a){return a.replace(/\{\{/g,D).replace(/}}/g,ba)};return w}]}function fa(b){return rb(b.replace(Ac,""))}function Bc(){var b={};this.register=function(a,c){L(a)?x(b,a):b[a]=c};this.$get=["$injector","$window",function(a,c){return function(d,e){if(F(d)){var g=d,d=b.hasOwnProperty(g)?b[g]:fb(e.$scope,g,!0)||fb(c,g,!0);ra(d,g,!0)}return a.instantiate(d,e)}}]}function Cc(){this.$get=["$window",function(b){return u(b.document)}]}
27.54 +function Dc(){this.$get=["$log",function(b){return function(a,c){b.error.apply(b,arguments)}}]}function Ec(){var b="{{",a="}}";this.startSymbol=function(a){return a?(b=a,this):b};this.endSymbol=function(b){return b?(a=b,this):a};this.$get=["$parse",function(c){function d(d,f){for(var h,k,j=0,l=[],o=d.length,r=!1,n=[];j<o;)(h=d.indexOf(b,j))!=-1&&(k=d.indexOf(a,h+e))!=-1?(j!=h&&l.push(d.substring(j,h)),l.push(j=c(r=d.substring(h+e,k))),j.exp=r,j=k+g,r=!0):(j!=o&&l.push(d.substring(j)),j=o);if(!(o=
27.55 +l.length))l.push(""),o=1;if(!f||r)return n.length=o,j=function(a){for(var b=0,c=o,d;b<c;b++){if(typeof(d=l[b])=="function")d=d(a),d==null||d==p?d="":typeof d!="string"&&(d=da(d));n[b]=d}return n.join("")},j.exp=d,j.parts=l,j}var e=b.length,g=a.length;d.startSymbol=function(){return b};d.endSymbol=function(){return a};return d}]}function Eb(b){for(var b=b.split("/"),a=b.length;a--;)b[a]=Za(b[a]);return b.join("/")}function va(b,a){var c=Fb.exec(b),c={protocol:c[1],host:c[3],port:G(c[5])||Gb[c[1]]||
27.56 +null,path:c[6]||"/",search:c[8],hash:c[10]};if(a)a.$$protocol=c.protocol,a.$$host=c.host,a.$$port=c.port;return c}function ka(b,a,c){return b+"://"+a+(c==Gb[b]?"":":"+c)}function Fc(b,a,c){var d=va(b);return decodeURIComponent(d.path)!=a||t(d.hash)||d.hash.indexOf(c)!==0?b:ka(d.protocol,d.host,d.port)+a.substr(0,a.lastIndexOf("/"))+d.hash.substr(c.length)}function Gc(b,a,c){var d=va(b);if(decodeURIComponent(d.path)==a)return b;else{var e=d.search&&"?"+d.search||"",g=d.hash&&"#"+d.hash||"",i=a.substr(0,
27.57 +a.lastIndexOf("/")),f=d.path.substr(i.length);if(d.path.indexOf(i)!==0)throw B('Invalid url "'+b+'", missing path prefix "'+i+'" !');return ka(d.protocol,d.host,d.port)+a+"#"+c+f+e+g}}function gb(b,a,c){a=a||"";this.$$parse=function(b){var c=va(b,this);if(c.path.indexOf(a)!==0)throw B('Invalid url "'+b+'", missing path prefix "'+a+'" !');this.$$path=decodeURIComponent(c.path.substr(a.length));this.$$search=Xa(c.search);this.$$hash=c.hash&&decodeURIComponent(c.hash)||"";this.$$compose()};this.$$compose=
27.58 +function(){var b=ob(this.$$search),c=this.$$hash?"#"+Za(this.$$hash):"";this.$$url=Eb(this.$$path)+(b?"?"+b:"")+c;this.$$absUrl=ka(this.$$protocol,this.$$host,this.$$port)+a+this.$$url};this.$$rewriteAppUrl=function(a){if(a.indexOf(c)==0)return a};this.$$parse(b)}function Ia(b,a,c){var d;this.$$parse=function(b){var c=va(b,this);if(c.hash&&c.hash.indexOf(a)!==0)throw B('Invalid url "'+b+'", missing hash prefix "'+a+'" !');d=c.path+(c.search?"?"+c.search:"");c=Hc.exec((c.hash||"").substr(a.length));
27.59 +this.$$path=c[1]?(c[1].charAt(0)=="/"?"":"/")+decodeURIComponent(c[1]):"";this.$$search=Xa(c[3]);this.$$hash=c[5]&&decodeURIComponent(c[5])||"";this.$$compose()};this.$$compose=function(){var b=ob(this.$$search),c=this.$$hash?"#"+Za(this.$$hash):"";this.$$url=Eb(this.$$path)+(b?"?"+b:"")+c;this.$$absUrl=ka(this.$$protocol,this.$$host,this.$$port)+d+(this.$$url?"#"+a+this.$$url:"")};this.$$rewriteAppUrl=function(a){if(a.indexOf(c)==0)return a};this.$$parse(b)}function Hb(b,a,c,d){Ia.apply(this,arguments);
27.60 +this.$$rewriteAppUrl=function(b){if(b.indexOf(c)==0)return c+d+"#"+a+b.substr(c.length)}}function Ja(b){return function(){return this[b]}}function Ib(b,a){return function(c){if(t(c))return this[b];this[b]=a(c);this.$$compose();return this}}function Ic(){var b="",a=!1;this.hashPrefix=function(a){return v(a)?(b=a,this):b};this.html5Mode=function(b){return v(b)?(a=b,this):a};this.$get=["$rootScope","$browser","$sniffer","$rootElement",function(c,d,e,g){function i(a){c.$broadcast("$locationChangeSuccess",
27.61 +f.absUrl(),a)}var f,h,k,j=d.url(),l=va(j);a?(h=d.baseHref()||"/",k=h.substr(0,h.lastIndexOf("/")),l=ka(l.protocol,l.host,l.port)+k+"/",f=e.history?new gb(Fc(j,h,b),k,l):new Hb(Gc(j,h,b),b,l,h.substr(k.length+1))):(l=ka(l.protocol,l.host,l.port)+(l.path||"")+(l.search?"?"+l.search:"")+"#"+b+"/",f=new Ia(j,b,l));g.bind("click",function(a){if(!a.ctrlKey&&!(a.metaKey||a.which==2)){for(var b=u(a.target);E(b[0].nodeName)!=="a";)if(b[0]===g[0]||!(b=b.parent())[0])return;var d=b.prop("href"),e=f.$$rewriteAppUrl(d);
27.62 +d&&!b.attr("target")&&e&&(f.$$parse(e),c.$apply(),a.preventDefault(),U.angular["ff-684208-preventDefault"]=!0)}});f.absUrl()!=j&&d.url(f.absUrl(),!0);d.onUrlChange(function(a){f.absUrl()!=a&&(c.$evalAsync(function(){var b=f.absUrl();f.$$parse(a);i(b)}),c.$$phase||c.$digest())});var o=0;c.$watch(function(){var a=d.url(),b=f.$$replace;if(!o||a!=f.absUrl())o++,c.$evalAsync(function(){c.$broadcast("$locationChangeStart",f.absUrl(),a).defaultPrevented?f.$$parse(a):(d.url(f.absUrl(),b),i(a))});f.$$replace=
27.63 +!1;return o});return f}]}function Jc(){this.$get=["$window",function(b){function a(a){a instanceof B&&(a.stack?a=a.message&&a.stack.indexOf(a.message)===-1?"Error: "+a.message+"\n"+a.stack:a.stack:a.sourceURL&&(a=a.message+"\n"+a.sourceURL+":"+a.line));return a}function c(c){var e=b.console||{},g=e[c]||e.log||D;return g.apply?function(){var b=[];m(arguments,function(c){b.push(a(c))});return g.apply(e,b)}:function(a,b){g(a,b)}}return{log:c("log"),warn:c("warn"),info:c("info"),error:c("error")}}]}function Kc(b,
27.64 +a){function c(a){return a.indexOf(q)!=-1}function d(){return n+1<b.length?b.charAt(n+1):!1}function e(a){return"0"<=a&&a<="9"}function g(a){return a==" "||a=="\r"||a=="\t"||a=="\n"||a=="\u000b"||a=="\u00a0"}function i(a){return"a"<=a&&a<="z"||"A"<=a&&a<="Z"||"_"==a||a=="$"}function f(a){return a=="-"||a=="+"||e(a)}function h(a,c,d){d=d||n;throw B("Lexer Error: "+a+" at column"+(v(c)?"s "+c+"-"+n+" ["+b.substring(c,d)+"]":" "+d)+" in expression ["+b+"].");}function k(){for(var a="",c=n;n<b.length;){var k=
27.65 +E(b.charAt(n));if(k=="."||e(k))a+=k;else{var g=d();if(k=="e"&&f(g))a+=k;else if(f(k)&&g&&e(g)&&a.charAt(a.length-1)=="e")a+=k;else if(f(k)&&(!g||!e(g))&&a.charAt(a.length-1)=="e")h("Invalid exponent");else break}n++}a*=1;o.push({index:c,text:a,json:!0,fn:function(){return a}})}function j(){for(var c="",d=n,f,k,h;n<b.length;){var j=b.charAt(n);if(j=="."||i(j)||e(j))j=="."&&(f=n),c+=j;else break;n++}if(f)for(k=n;k<b.length;){j=b.charAt(k);if(j=="("){h=c.substr(f-d+1);c=c.substr(0,f-d);n=k;break}if(g(j))k++;
27.66 +else break}d={index:d,text:c};if(Ka.hasOwnProperty(c))d.fn=d.json=Ka[c];else{var l=Jb(c,a);d.fn=x(function(a,b){return l(a,b)},{assign:function(a,b){return Kb(a,c,b)}})}o.push(d);h&&(o.push({index:f,text:".",json:!1}),o.push({index:f+1,text:h,json:!1}))}function l(a){var c=n;n++;for(var d="",e=a,f=!1;n<b.length;){var k=b.charAt(n);e+=k;if(f)k=="u"?(k=b.substring(n+1,n+5),k.match(/[\da-f]{4}/i)||h("Invalid unicode escape [\\u"+k+"]"),n+=4,d+=String.fromCharCode(parseInt(k,16))):(f=Lc[k],d+=f?f:k),
27.67 +f=!1;else if(k=="\\")f=!0;else if(k==a){n++;o.push({index:c,text:e,string:d,json:!0,fn:function(){return d}});return}else d+=k;n++}h("Unterminated quote",c)}for(var o=[],r,n=0,w=[],q,s=":";n<b.length;){q=b.charAt(n);if(c("\"'"))l(q);else if(e(q)||c(".")&&e(d()))k();else if(i(q)){if(j(),"{,".indexOf(s)!=-1&&w[0]=="{"&&(r=o[o.length-1]))r.json=r.text.indexOf(".")==-1}else if(c("(){}[].,;:"))o.push({index:n,text:q,json:":[,".indexOf(s)!=-1&&c("{[")||c("}]:,")}),c("{[")&&w.unshift(q),c("}]")&&w.shift(),
27.68 +n++;else if(g(q)){n++;continue}else{var m=q+d(),C=Ka[q],A=Ka[m];A?(o.push({index:n,text:m,fn:A}),n+=2):C?(o.push({index:n,text:q,fn:C,json:"[,:".indexOf(s)!=-1&&c("+-")}),n+=1):h("Unexpected next character ",n,n+1)}s=q}return o}function Mc(b,a,c,d){function e(a,c){throw B("Syntax Error: Token '"+c.text+"' "+a+" at column "+(c.index+1)+" of the expression ["+b+"] starting at ["+b.substring(c.index)+"].");}function g(){if(M.length===0)throw B("Unexpected end of expression: "+b);return M[0]}function i(a,
27.69 +b,c,d){if(M.length>0){var e=M[0],f=e.text;if(f==a||f==b||f==c||f==d||!a&&!b&&!c&&!d)return e}return!1}function f(b,c,d,f){return(b=i(b,c,d,f))?(a&&!b.json&&e("is not valid json",b),M.shift(),b):!1}function h(a){f(a)||e("is unexpected, expecting ["+a+"]",i())}function k(a,b){return function(c,d){return a(c,d,b)}}function j(a,b,c){return function(d,e){return b(d,e,a,c)}}function l(){for(var a=[];;)if(M.length>0&&!i("}",")",";","]")&&a.push(v()),!f(";"))return a.length==1?a[0]:function(b,c){for(var d,
27.70 +e=0;e<a.length;e++){var f=a[e];f&&(d=f(b,c))}return d}}function o(){for(var a=f(),b=c(a.text),d=[];;)if(a=f(":"))d.push(H());else{var e=function(a,c,e){for(var e=[e],f=0;f<d.length;f++)e.push(d[f](a,c));return b.apply(a,e)};return function(){return e}}}function r(){for(var a=n(),b;;)if(b=f("||"))a=j(a,b.fn,n());else return a}function n(){var a=w(),b;if(b=f("&&"))a=j(a,b.fn,n());return a}function w(){var a=q(),b;if(b=f("==","!="))a=j(a,b.fn,w());return a}function q(){var a;a=s();for(var b;b=f("+",
27.71 +"-");)a=j(a,b.fn,s());if(b=f("<",">","<=",">="))a=j(a,b.fn,q());return a}function s(){for(var a=m(),b;b=f("*","/","%");)a=j(a,b.fn,m());return a}function m(){var a;return f("+")?C():(a=f("-"))?j(W,a.fn,m()):(a=f("!"))?k(a.fn,m()):C()}function C(){var a;if(f("("))a=v(),h(")");else if(f("["))a=A();else if(f("{"))a=K();else{var b=f();(a=b.fn)||e("not a primary expression",b)}for(var c;b=f("(","[",".");)b.text==="("?(a=u(a,c),c=null):b.text==="["?(c=a,a=ea(a)):b.text==="."?(c=a,a=t(a)):e("IMPOSSIBLE");
27.72 +return a}function A(){var a=[];if(g().text!="]"){do a.push(H());while(f(","))}h("]");return function(b,c){for(var d=[],e=0;e<a.length;e++)d.push(a[e](b,c));return d}}function K(){var a=[];if(g().text!="}"){do{var b=f(),b=b.string||b.text;h(":");var c=H();a.push({key:b,value:c})}while(f(","))}h("}");return function(b,c){for(var d={},e=0;e<a.length;e++){var f=a[e],k=f.value(b,c);d[f.key]=k}return d}}var W=I(0),y,M=Kc(b,d),H=function(){var a=r(),c,d;return(d=f("="))?(a.assign||e("implies assignment but ["+
27.73 +b.substring(0,d.index)+"] can not be assigned to",d),c=r(),function(b,d){return a.assign(b,c(b,d),d)}):a},u=function(a,b){var c=[];if(g().text!=")"){do c.push(H());while(f(","))}h(")");return function(d,e){for(var f=[],k=b?b(d,e):d,h=0;h<c.length;h++)f.push(c[h](d,e));h=a(d,e)||D;return h.apply?h.apply(k,f):h(f[0],f[1],f[2],f[3],f[4])}},t=function(a){var b=f().text,c=Jb(b,d);return x(function(b,d){return c(a(b,d),d)},{assign:function(c,d,e){return Kb(a(c,e),b,d)}})},ea=function(a){var b=H();h("]");
27.74 +return x(function(c,d){var e=a(c,d),f=b(c,d),k;if(!e)return p;if((e=e[f])&&e.then){k=e;if(!("$$v"in e))k.$$v=p,k.then(function(a){k.$$v=a});e=e.$$v}return e},{assign:function(c,d,e){return a(c,e)[b(c,e)]=d}})},v=function(){for(var a=H(),b;;)if(b=f("|"))a=j(a,b.fn,o());else return a};a?(H=r,u=t=ea=v=function(){e("is not valid json",{text:b,index:0})},y=C()):y=l();M.length!==0&&e("is an unexpected token",M[0]);return y}function Kb(b,a,c){for(var a=a.split("."),d=0;a.length>1;d++){var e=a.shift(),g=
27.75 +b[e];g||(g={},b[e]=g);b=g}return b[a.shift()]=c}function fb(b,a,c){if(!a)return b;for(var a=a.split("."),d,e=b,g=a.length,i=0;i<g;i++)d=a[i],b&&(b=(e=b)[d]);return!c&&N(b)?Va(e,b):b}function Lb(b,a,c,d,e){return function(g,i){var f=i&&i.hasOwnProperty(b)?i:g,h;if(f===null||f===p)return f;if((f=f[b])&&f.then){if(!("$$v"in f))h=f,h.$$v=p,h.then(function(a){h.$$v=a});f=f.$$v}if(!a||f===null||f===p)return f;if((f=f[a])&&f.then){if(!("$$v"in f))h=f,h.$$v=p,h.then(function(a){h.$$v=a});f=f.$$v}if(!c||f===
27.76 +null||f===p)return f;if((f=f[c])&&f.then){if(!("$$v"in f))h=f,h.$$v=p,h.then(function(a){h.$$v=a});f=f.$$v}if(!d||f===null||f===p)return f;if((f=f[d])&&f.then){if(!("$$v"in f))h=f,h.$$v=p,h.then(function(a){h.$$v=a});f=f.$$v}if(!e||f===null||f===p)return f;if((f=f[e])&&f.then){if(!("$$v"in f))h=f,h.$$v=p,h.then(function(a){h.$$v=a});f=f.$$v}return f}}function Jb(b,a){if(hb.hasOwnProperty(b))return hb[b];var c=b.split("."),d=c.length,e;if(a)e=d<6?Lb(c[0],c[1],c[2],c[3],c[4]):function(a,b){var e=0,
27.77 +k;do k=Lb(c[e++],c[e++],c[e++],c[e++],c[e++])(a,b),b=p,a=k;while(e<d);return k};else{var g="var l, fn, p;\n";m(c,function(a,b){g+="if(s === null || s === undefined) return s;\nl=s;\ns="+(b?"s":'((k&&k.hasOwnProperty("'+a+'"))?k:s)')+'["'+a+'"];\nif (s && s.then) {\n if (!("$$v" in s)) {\n p=s;\n p.$$v = undefined;\n p.then(function(v) {p.$$v=v;});\n}\n s=s.$$v\n}\n'});g+="return s;";e=Function("s","k",g);e.toString=function(){return g}}return hb[b]=e}function Nc(){var b={};this.$get=["$filter","$sniffer",
27.78 +function(a,c){return function(d){switch(typeof d){case "string":return b.hasOwnProperty(d)?b[d]:b[d]=Mc(d,!1,a,c.csp);case "function":return d;default:return D}}}]}function Oc(){this.$get=["$rootScope","$exceptionHandler",function(b,a){return Pc(function(a){b.$evalAsync(a)},a)}]}function Pc(b,a){function c(a){return a}function d(a){return i(a)}var e=function(){var f=[],h,k;return k={resolve:function(a){if(f){var c=f;f=p;h=g(a);c.length&&b(function(){for(var a,b=0,d=c.length;b<d;b++)a=c[b],h.then(a[0],
27.79 +a[1])})}},reject:function(a){k.resolve(i(a))},promise:{then:function(b,k){var g=e(),i=function(d){try{g.resolve((b||c)(d))}catch(e){a(e),g.reject(e)}},n=function(b){try{g.resolve((k||d)(b))}catch(c){a(c),g.reject(c)}};f?f.push([i,n]):h.then(i,n);return g.promise}}}},g=function(a){return a&&a.then?a:{then:function(c){var d=e();b(function(){d.resolve(c(a))});return d.promise}}},i=function(a){return{then:function(c,k){var g=e();b(function(){g.resolve((k||d)(a))});return g.promise}}};return{defer:e,reject:i,
27.80 +when:function(f,h,k){var j=e(),l,o=function(b){try{return(h||c)(b)}catch(d){return a(d),i(d)}},r=function(b){try{return(k||d)(b)}catch(c){return a(c),i(c)}};b(function(){g(f).then(function(a){l||(l=!0,j.resolve(g(a).then(o,r)))},function(a){l||(l=!0,j.resolve(r(a)))})});return j.promise},all:function(a){var b=e(),c=a.length,d=[];c?m(a,function(a,e){g(a).then(function(a){e in d||(d[e]=a,--c||b.resolve(d))},function(a){e in d||b.reject(a)})}):b.resolve(d);return b.promise}}}function Qc(){var b={};this.when=
27.81 +function(a,c){b[a]=x({reloadOnSearch:!0},c);if(a){var d=a[a.length-1]=="/"?a.substr(0,a.length-1):a+"/";b[d]={redirectTo:a}}return this};this.otherwise=function(a){this.when(null,a);return this};this.$get=["$rootScope","$location","$routeParams","$q","$injector","$http","$templateCache",function(a,c,d,e,g,i,f){function h(){var b=k(),h=r.current;if(b&&h&&b.$route===h.$route&&ha(b.pathParams,h.pathParams)&&!b.reloadOnSearch&&!o)h.params=b.params,V(h.params,d),a.$broadcast("$routeUpdate",h);else if(b||
27.82 +h)o=!1,a.$broadcast("$routeChangeStart",b,h),(r.current=b)&&b.redirectTo&&(F(b.redirectTo)?c.path(j(b.redirectTo,b.params)).search(b.params).replace():c.url(b.redirectTo(b.pathParams,c.path(),c.search())).replace()),e.when(b).then(function(){if(b){var a=[],c=[],d;m(b.resolve||{},function(b,d){a.push(d);c.push(F(b)?g.get(b):g.invoke(b))});if(!v(d=b.template))if(v(d=b.templateUrl))d=i.get(d,{cache:f}).then(function(a){return a.data});v(d)&&(a.push("$template"),c.push(d));return e.all(c).then(function(b){var c=
27.83 +{};m(b,function(b,d){c[a[d]]=b});return c})}}).then(function(c){if(b==r.current){if(b)b.locals=c,V(b.params,d);a.$broadcast("$routeChangeSuccess",b,h)}},function(c){b==r.current&&a.$broadcast("$routeChangeError",b,h,c)})}function k(){var a,d;m(b,function(b,e){if(!d&&(a=l(c.path(),e)))d=ya(b,{params:x({},c.search(),a),pathParams:a}),d.$route=b});return d||b[null]&&ya(b[null],{params:{},pathParams:{}})}function j(a,b){var c=[];m((a||"").split(":"),function(a,d){if(d==0)c.push(a);else{var e=a.match(/(\w+)(.*)/),
27.84 +f=e[1];c.push(b[f]);c.push(e[2]||"");delete b[f]}});return c.join("")}var l=function(a,b){var c="^"+b.replace(/([\.\\\(\)\^\$])/g,"\\$1")+"$",d=[],e={};m(b.split(/\W/),function(a){if(a){var b=RegExp(":"+a+"([\\W])");c.match(b)&&(c=c.replace(b,"([^\\/]*)$1"),d.push(a))}});var f=a.match(RegExp(c));f&&m(d,function(a,b){e[a]=f[b+1]});return f?e:null},o=!1,r={routes:b,reload:function(){o=!0;a.$evalAsync(h)}};a.$on("$locationChangeSuccess",h);return r}]}function Rc(){this.$get=I({})}function Sc(){var b=
27.85 +10;this.digestTtl=function(a){arguments.length&&(b=a);return b};this.$get=["$injector","$exceptionHandler","$parse",function(a,c,d){function e(){this.$id=xa();this.$$phase=this.$parent=this.$$watchers=this.$$nextSibling=this.$$prevSibling=this.$$childHead=this.$$childTail=null;this["this"]=this.$root=this;this.$$asyncQueue=[];this.$$listeners={}}function g(a){if(h.$$phase)throw B(h.$$phase+" already in progress");h.$$phase=a}function i(a,b){var c=d(a);ra(c,b);return c}function f(){}e.prototype={$new:function(a){if(N(a))throw B("API-CHANGE: Use $controller to instantiate controllers.");
27.86 +a?(a=new e,a.$root=this.$root):(a=function(){},a.prototype=this,a=new a,a.$id=xa());a["this"]=a;a.$$listeners={};a.$parent=this;a.$$asyncQueue=[];a.$$watchers=a.$$nextSibling=a.$$childHead=a.$$childTail=null;a.$$prevSibling=this.$$childTail;this.$$childHead?this.$$childTail=this.$$childTail.$$nextSibling=a:this.$$childHead=this.$$childTail=a;return a},$watch:function(a,b,c){var d=i(a,"watch"),e=this.$$watchers,g={fn:b,last:f,get:d,exp:a,eq:!!c};if(!N(b)){var h=i(b||D,"listener");g.fn=function(a,b,
27.87 +c){h(c)}}if(!e)e=this.$$watchers=[];e.unshift(g);return function(){Ua(e,g)}},$digest:function(){var a,d,e,i,r,n,m,q=b,s,p=[],C,A;g("$digest");do{m=!1;s=this;do{for(r=s.$$asyncQueue;r.length;)try{s.$eval(r.shift())}catch(K){c(K)}if(i=s.$$watchers)for(n=i.length;n--;)try{if(a=i[n],(d=a.get(s))!==(e=a.last)&&!(a.eq?ha(d,e):typeof d=="number"&&typeof e=="number"&&isNaN(d)&&isNaN(e)))m=!0,a.last=a.eq?V(d):d,a.fn(d,e===f?d:e,s),q<5&&(C=4-q,p[C]||(p[C]=[]),A=N(a.exp)?"fn: "+(a.exp.name||a.exp.toString()):
27.88 +a.exp,A+="; newVal: "+da(d)+"; oldVal: "+da(e),p[C].push(A))}catch(W){c(W)}if(!(i=s.$$childHead||s!==this&&s.$$nextSibling))for(;s!==this&&!(i=s.$$nextSibling);)s=s.$parent}while(s=i);if(m&&!q--)throw h.$$phase=null,B(b+" $digest() iterations reached. Aborting!\nWatchers fired in the last 5 iterations: "+da(p));}while(m||r.length);h.$$phase=null},$destroy:function(){if(h!=this){var a=this.$parent;this.$broadcast("$destroy");if(a.$$childHead==this)a.$$childHead=this.$$nextSibling;if(a.$$childTail==
27.89 +this)a.$$childTail=this.$$prevSibling;if(this.$$prevSibling)this.$$prevSibling.$$nextSibling=this.$$nextSibling;if(this.$$nextSibling)this.$$nextSibling.$$prevSibling=this.$$prevSibling;this.$parent=this.$$nextSibling=this.$$prevSibling=this.$$childHead=this.$$childTail=null}},$eval:function(a,b){return d(a)(this,b)},$evalAsync:function(a){this.$$asyncQueue.push(a)},$apply:function(a){try{return g("$apply"),this.$eval(a)}catch(b){c(b)}finally{h.$$phase=null;try{h.$digest()}catch(d){throw c(d),d;}}},
27.90 +$on:function(a,b){var c=this.$$listeners[a];c||(this.$$listeners[a]=c=[]);c.push(b);return function(){c[za(c,b)]=null}},$emit:function(a,b){var d=[],e,f=this,g=!1,h={name:a,targetScope:f,stopPropagation:function(){g=!0},preventDefault:function(){h.defaultPrevented=!0},defaultPrevented:!1},i=[h].concat(ia.call(arguments,1)),m,p;do{e=f.$$listeners[a]||d;h.currentScope=f;m=0;for(p=e.length;m<p;m++)if(e[m])try{if(e[m].apply(null,i),g)return h}catch(C){c(C)}else e.splice(m,1),m--,p--;f=f.$parent}while(f);
27.91 +return h},$broadcast:function(a,b){var d=this,e=this,f={name:a,targetScope:this,preventDefault:function(){f.defaultPrevented=!0},defaultPrevented:!1},g=[f].concat(ia.call(arguments,1)),h,i;do{d=e;f.currentScope=d;e=d.$$listeners[a]||[];h=0;for(i=e.length;h<i;h++)if(e[h])try{e[h].apply(null,g)}catch(m){c(m)}else e.splice(h,1),h--,i--;if(!(e=d.$$childHead||d!==this&&d.$$nextSibling))for(;d!==this&&!(e=d.$$nextSibling);)d=d.$parent}while(d=e);return f}};var h=new e;return h}]}function Tc(){this.$get=
27.92 +["$window",function(b){var a={},c=G((/android (\d+)/.exec(E(b.navigator.userAgent))||[])[1]);return{history:!(!b.history||!b.history.pushState||c<4),hashchange:"onhashchange"in b&&(!b.document.documentMode||b.document.documentMode>7),hasEvent:function(c){if(c=="input"&&aa==9)return!1;if(t(a[c])){var e=b.document.createElement("div");a[c]="on"+c in e}return a[c]},csp:!1}}]}function Uc(){this.$get=I(U)}function Mb(b){var a={},c,d,e;if(!b)return a;m(b.split("\n"),function(b){e=b.indexOf(":");c=E(R(b.substr(0,
27.93 +e)));d=R(b.substr(e+1));c&&(a[c]?a[c]+=", "+d:a[c]=d)});return a}function Nb(b){var a=L(b)?b:p;return function(c){a||(a=Mb(b));return c?a[E(c)]||null:a}}function Ob(b,a,c){if(N(c))return c(b,a);m(c,function(c){b=c(b,a)});return b}function Vc(){var b=/^\s*(\[|\{[^\{])/,a=/[\}\]]\s*$/,c=/^\)\]\}',?\n/,d=this.defaults={transformResponse:[function(d){F(d)&&(d=d.replace(c,""),b.test(d)&&a.test(d)&&(d=nb(d,!0)));return d}],transformRequest:[function(a){return L(a)&&Sa.apply(a)!=="[object File]"?da(a):a}],
27.94 +headers:{common:{Accept:"application/json, text/plain, */*","X-Requested-With":"XMLHttpRequest"},post:{"Content-Type":"application/json;charset=utf-8"},put:{"Content-Type":"application/json;charset=utf-8"}}},e=this.responseInterceptors=[];this.$get=["$httpBackend","$browser","$cacheFactory","$rootScope","$q","$injector",function(a,b,c,h,k,j){function l(a){function c(a){var b=x({},a,{data:Ob(a.data,a.headers,f)});return 200<=a.status&&a.status<300?b:k.reject(b)}a.method=la(a.method);var e=a.transformRequest||
27.95 +d.transformRequest,f=a.transformResponse||d.transformResponse,h=d.headers,h=x({"X-XSRF-TOKEN":b.cookies()["XSRF-TOKEN"]},h.common,h[E(a.method)],a.headers),e=Ob(a.data,Nb(h),e),g;t(a.data)&&delete h["Content-Type"];g=o(a,e,h);g=g.then(c,c);m(w,function(a){g=a(g)});g.success=function(b){g.then(function(c){b(c.data,c.status,c.headers,a)});return g};g.error=function(b){g.then(null,function(c){b(c.data,c.status,c.headers,a)});return g};return g}function o(b,c,d){function e(a,b,c){m&&(200<=a&&a<300?m.put(w,
27.96 +[a,b,Mb(c)]):m.remove(w));f(b,a,c);h.$apply()}function f(a,c,d){c=Math.max(c,0);(200<=c&&c<300?j.resolve:j.reject)({data:a,status:c,headers:Nb(d),config:b})}function i(){var a=za(l.pendingRequests,b);a!==-1&&l.pendingRequests.splice(a,1)}var j=k.defer(),o=j.promise,m,p,w=r(b.url,b.params);l.pendingRequests.push(b);o.then(i,i);b.cache&&b.method=="GET"&&(m=L(b.cache)?b.cache:n);if(m)if(p=m.get(w))if(p.then)return p.then(i,i),p;else J(p)?f(p[1],p[0],V(p[2])):f(p,200,{});else m.put(w,o);p||a(b.method,
27.97 +w,c,e,d,b.timeout,b.withCredentials);return o}function r(a,b){if(!b)return a;var c=[];ec(b,function(a,b){a==null||a==p||(L(a)&&(a=da(a)),c.push(encodeURIComponent(b)+"="+encodeURIComponent(a)))});return a+(a.indexOf("?")==-1?"?":"&")+c.join("&")}var n=c("$http"),w=[];m(e,function(a){w.push(F(a)?j.get(a):j.invoke(a))});l.pendingRequests=[];(function(a){m(arguments,function(a){l[a]=function(b,c){return l(x(c||{},{method:a,url:b}))}})})("get","delete","head","jsonp");(function(a){m(arguments,function(a){l[a]=
27.98 +function(b,c,d){return l(x(d||{},{method:a,url:b,data:c}))}})})("post","put");l.defaults=d;return l}]}function Wc(){this.$get=["$browser","$window","$document",function(b,a,c){return Xc(b,Yc,b.defer,a.angular.callbacks,c[0],a.location.protocol.replace(":",""))}]}function Xc(b,a,c,d,e,g){function i(a,b){var c=e.createElement("script"),d=function(){e.body.removeChild(c);b&&b()};c.type="text/javascript";c.src=a;aa?c.onreadystatechange=function(){/loaded|complete/.test(c.readyState)&&d()}:c.onload=c.onerror=
27.99 +d;e.body.appendChild(c)}return function(e,h,k,j,l,o,r){function n(a,c,d,e){c=(h.match(Fb)||["",g])[1]=="file"?d?200:404:c;a(c==1223?204:c,d,e);b.$$completeOutstandingRequest(D)}b.$$incOutstandingRequestCount();h=h||b.url();if(E(e)=="jsonp"){var p="_"+(d.counter++).toString(36);d[p]=function(a){d[p].data=a};i(h.replace("JSON_CALLBACK","angular.callbacks."+p),function(){d[p].data?n(j,200,d[p].data):n(j,-2);delete d[p]})}else{var q=new a;q.open(e,h,!0);m(l,function(a,b){a&&q.setRequestHeader(b,a)});
27.100 +var s;q.onreadystatechange=function(){q.readyState==4&&n(j,s||q.status,q.responseText,q.getAllResponseHeaders())};if(r)q.withCredentials=!0;q.send(k||"");o>0&&c(function(){s=-1;q.abort()},o)}}}function Zc(){this.$get=function(){return{id:"en-us",NUMBER_FORMATS:{DECIMAL_SEP:".",GROUP_SEP:",",PATTERNS:[{minInt:1,minFrac:0,maxFrac:3,posPre:"",posSuf:"",negPre:"-",negSuf:"",gSize:3,lgSize:3},{minInt:1,minFrac:2,maxFrac:2,posPre:"\u00a4",posSuf:"",negPre:"(\u00a4",negSuf:")",gSize:3,lgSize:3}],CURRENCY_SYM:"$"},
27.101 +DATETIME_FORMATS:{MONTH:"January,February,March,April,May,June,July,August,September,October,November,December".split(","),SHORTMONTH:"Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec".split(","),DAY:"Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday".split(","),SHORTDAY:"Sun,Mon,Tue,Wed,Thu,Fri,Sat".split(","),AMPMS:["AM","PM"],medium:"MMM d, y h:mm:ss a","short":"M/d/yy h:mm a",fullDate:"EEEE, MMMM d, y",longDate:"MMMM d, y",mediumDate:"MMM d, y",shortDate:"M/d/yy",mediumTime:"h:mm:ss a",
27.102 +shortTime:"h:mm a"},pluralCat:function(b){return b===1?"one":"other"}}}}function $c(){this.$get=["$rootScope","$browser","$q","$exceptionHandler",function(b,a,c,d){function e(e,f,h){var k=c.defer(),j=k.promise,l=v(h)&&!h,f=a.defer(function(){try{k.resolve(e())}catch(a){k.reject(a),d(a)}l||b.$apply()},f),h=function(){delete g[j.$$timeoutId]};j.$$timeoutId=f;g[f]=k;j.then(h,h);return j}var g={};e.cancel=function(b){return b&&b.$$timeoutId in g?(g[b.$$timeoutId].reject("canceled"),a.defer.cancel(b.$$timeoutId)):
27.103 +!1};return e}]}function Pb(b){function a(a,e){return b.factory(a+c,e)}var c="Filter";this.register=a;this.$get=["$injector",function(a){return function(b){return a.get(b+c)}}];a("currency",Qb);a("date",Rb);a("filter",ad);a("json",bd);a("limitTo",cd);a("lowercase",dd);a("number",Sb);a("orderBy",Tb);a("uppercase",ed)}function ad(){return function(b,a){if(!(b instanceof Array))return b;var c=[];c.check=function(a){for(var b=0;b<c.length;b++)if(!c[b](a))return!1;return!0};var d=function(a,b){if(b.charAt(0)===
27.104 +"!")return!d(a,b.substr(1));switch(typeof a){case "boolean":case "number":case "string":return(""+a).toLowerCase().indexOf(b)>-1;case "object":for(var c in a)if(c.charAt(0)!=="$"&&d(a[c],b))return!0;return!1;case "array":for(c=0;c<a.length;c++)if(d(a[c],b))return!0;return!1;default:return!1}};switch(typeof a){case "boolean":case "number":case "string":a={$:a};case "object":for(var e in a)e=="$"?function(){var b=(""+a[e]).toLowerCase();b&&c.push(function(a){return d(a,b)})}():function(){var b=e,f=
27.105 +(""+a[e]).toLowerCase();f&&c.push(function(a){return d(fb(a,b),f)})}();break;case "function":c.push(a);break;default:return b}for(var g=[],i=0;i<b.length;i++){var f=b[i];c.check(f)&&g.push(f)}return g}}function Qb(b){var a=b.NUMBER_FORMATS;return function(b,d){if(t(d))d=a.CURRENCY_SYM;return Ub(b,a.PATTERNS[1],a.GROUP_SEP,a.DECIMAL_SEP,2).replace(/\u00A4/g,d)}}function Sb(b){var a=b.NUMBER_FORMATS;return function(b,d){return Ub(b,a.PATTERNS[0],a.GROUP_SEP,a.DECIMAL_SEP,d)}}function Ub(b,a,c,d,e){if(isNaN(b)||
27.106 +!isFinite(b))return"";var g=b<0,b=Math.abs(b),i=b+"",f="",h=[],k=!1;if(i.indexOf("e")!==-1){var j=i.match(/([\d\.]+)e(-?)(\d+)/);j&&j[2]=="-"&&j[3]>e+1?i="0":(f=i,k=!0)}if(!k){i=(i.split(Vb)[1]||"").length;t(e)&&(e=Math.min(Math.max(a.minFrac,i),a.maxFrac));var i=Math.pow(10,e),b=Math.round(b*i)/i,b=(""+b).split(Vb),i=b[0],b=b[1]||"",k=0,j=a.lgSize,l=a.gSize;if(i.length>=j+l)for(var k=i.length-j,o=0;o<k;o++)(k-o)%l===0&&o!==0&&(f+=c),f+=i.charAt(o);for(o=k;o<i.length;o++)(i.length-o)%j===0&&o!==0&&
27.107 +(f+=c),f+=i.charAt(o);for(;b.length<e;)b+="0";e&&(f+=d+b.substr(0,e))}h.push(g?a.negPre:a.posPre);h.push(f);h.push(g?a.negSuf:a.posSuf);return h.join("")}function ib(b,a,c){var d="";b<0&&(d="-",b=-b);for(b=""+b;b.length<a;)b="0"+b;c&&(b=b.substr(b.length-a));return d+b}function P(b,a,c,d){return function(e){e=e["get"+b]();if(c>0||e>-c)e+=c;e===0&&c==-12&&(e=12);return ib(e,a,d)}}function La(b,a){return function(c,d){var e=c["get"+b](),g=la(a?"SHORT"+b:b);return d[g][e]}}function Rb(b){function a(a){var b;
27.108 +if(b=a.match(c)){var a=new Date(0),g=0,i=0;b[9]&&(g=G(b[9]+b[10]),i=G(b[9]+b[11]));a.setUTCFullYear(G(b[1]),G(b[2])-1,G(b[3]));a.setUTCHours(G(b[4]||0)-g,G(b[5]||0)-i,G(b[6]||0),G(b[7]||0))}return a}var c=/^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/;return function(c,e){var g="",i=[],f,h,e=e||"mediumDate",e=b.DATETIME_FORMATS[e]||e;F(c)&&(c=fd.test(c)?G(c):a(c));wa(c)&&(c=new Date(c));if(!na(c))return c;for(;e;)(h=gd.exec(e))?(i=i.concat(ia.call(h,
27.109 +1)),e=i.pop()):(i.push(e),e=null);m(i,function(a){f=hd[a];g+=f?f(c,b.DATETIME_FORMATS):a.replace(/(^'|'$)/g,"").replace(/''/g,"'")});return g}}function bd(){return function(b){return da(b,!0)}}function cd(){return function(b,a){if(!(b instanceof Array))return b;var a=G(a),c=[],d,e;if(!b||!(b instanceof Array))return c;a>b.length?a=b.length:a<-b.length&&(a=-b.length);a>0?(d=0,e=a):(d=b.length+a,e=b.length);for(;d<e;d++)c.push(b[d]);return c}}function Tb(b){return function(a,c,d){function e(a,b){return Wa(b)?
27.110 +function(b,c){return a(c,b)}:a}if(!(a instanceof Array))return a;if(!c)return a;for(var c=J(c)?c:[c],c=Ta(c,function(a){var c=!1,d=a||ma;if(F(a)){if(a.charAt(0)=="+"||a.charAt(0)=="-")c=a.charAt(0)=="-",a=a.substring(1);d=b(a)}return e(function(a,b){var c;c=d(a);var e=d(b),f=typeof c,g=typeof e;f==g?(f=="string"&&(c=c.toLowerCase()),f=="string"&&(e=e.toLowerCase()),c=c===e?0:c<e?-1:1):c=f<g?-1:1;return c},c)}),g=[],i=0;i<a.length;i++)g.push(a[i]);return g.sort(e(function(a,b){for(var d=0;d<c.length;d++){var e=
27.111 +c[d](a,b);if(e!==0)return e}return 0},d))}}function S(b){N(b)&&(b={link:b});b.restrict=b.restrict||"AC";return I(b)}function Wb(b,a){function c(a,c){c=c?"-"+$a(c,"-"):"";b.removeClass((a?Ma:Na)+c).addClass((a?Na:Ma)+c)}var d=this,e=b.parent().controller("form")||Oa,g=0,i=d.$error={};d.$name=a.name;d.$dirty=!1;d.$pristine=!0;d.$valid=!0;d.$invalid=!1;e.$addControl(d);b.addClass(Pa);c(!0);d.$addControl=function(a){a.$name&&!d.hasOwnProperty(a.$name)&&(d[a.$name]=a)};d.$removeControl=function(a){a.$name&&
27.112 +d[a.$name]===a&&delete d[a.$name];m(i,function(b,c){d.$setValidity(c,!0,a)})};d.$setValidity=function(a,b,k){var j=i[a];if(b){if(j&&(Ua(j,k),!j.length)){g--;if(!g)c(b),d.$valid=!0,d.$invalid=!1;i[a]=!1;c(!0,a);e.$setValidity(a,!0,d)}}else{g||c(b);if(j){if(za(j,k)!=-1)return}else i[a]=j=[],g++,c(!1,a),e.$setValidity(a,!1,d);j.push(k);d.$valid=!1;d.$invalid=!0}};d.$setDirty=function(){b.removeClass(Pa).addClass(Xb);d.$dirty=!0;d.$pristine=!1;e.$setDirty()}}function T(b){return t(b)||b===""||b===null||
27.113 +b!==b}function Qa(b,a,c,d,e,g){var i=function(){var c=R(a.val());d.$viewValue!==c&&b.$apply(function(){d.$setViewValue(c)})};if(e.hasEvent("input"))a.bind("input",i);else{var f;a.bind("keydown",function(a){a=a.keyCode;a===91||15<a&&a<19||37<=a&&a<=40||f||(f=g.defer(function(){i();f=null}))});a.bind("change",i)}d.$render=function(){a.val(T(d.$viewValue)?"":d.$viewValue)};var h=c.ngPattern,k=function(a,b){return T(b)||a.test(b)?(d.$setValidity("pattern",!0),b):(d.$setValidity("pattern",!1),p)};h&&(h.match(/^\/(.*)\/$/)?
27.114 +(h=RegExp(h.substr(1,h.length-2)),e=function(a){return k(h,a)}):e=function(a){var c=b.$eval(h);if(!c||!c.test)throw new B("Expected "+h+" to be a RegExp but was "+c);return k(c,a)},d.$formatters.push(e),d.$parsers.push(e));if(c.ngMinlength){var j=G(c.ngMinlength),e=function(a){return!T(a)&&a.length<j?(d.$setValidity("minlength",!1),p):(d.$setValidity("minlength",!0),a)};d.$parsers.push(e);d.$formatters.push(e)}if(c.ngMaxlength){var l=G(c.ngMaxlength),c=function(a){return!T(a)&&a.length>l?(d.$setValidity("maxlength",
27.115 +!1),p):(d.$setValidity("maxlength",!0),a)};d.$parsers.push(c);d.$formatters.push(c)}}function jb(b,a){b="ngClass"+b;return S(function(c,d,e){function g(b,d){if(a===!0||c.$index%2===a)d&&b!==d&&i(d),f(b)}function i(a){L(a)&&!J(a)&&(a=Ta(a,function(a,b){if(a)return b}));d.removeClass(J(a)?a.join(" "):a)}function f(a){L(a)&&!J(a)&&(a=Ta(a,function(a,b){if(a)return b}));a&&d.addClass(J(a)?a.join(" "):a)}c.$watch(e[b],g,!0);e.$observe("class",function(){var a=c.$eval(e[b]);g(a,a)});b!=="ngClass"&&c.$watch("$index",
27.116 +function(d,g){var j=d%2;j!==g%2&&(j==a?f(c.$eval(e[b])):i(c.$eval(e[b])))})})}var E=function(b){return F(b)?b.toLowerCase():b},la=function(b){return F(b)?b.toUpperCase():b},B=U.Error,aa=G((/msie (\d+)/.exec(E(navigator.userAgent))||[])[1]),u,ja,ia=[].slice,Ra=[].push,Sa=Object.prototype.toString,Yb=U.angular||(U.angular={}),ta,Cb,Z=["0","0","0"];D.$inject=[];ma.$inject=[];Cb=aa<9?function(b){b=b.nodeName?b:b[0];return b.scopeName&&b.scopeName!="HTML"?la(b.scopeName+":"+b.nodeName):b.nodeName}:function(b){return b.nodeName?
27.117 +b.nodeName:b[0].nodeName};var kc=/[A-Z]/g,id={full:"1.0.3",major:1,minor:0,dot:3,codeName:"bouncy-thunder"},Ba=Q.cache={},Aa=Q.expando="ng-"+(new Date).getTime(),oc=1,Zb=U.document.addEventListener?function(b,a,c){b.addEventListener(a,c,!1)}:function(b,a,c){b.attachEvent("on"+a,c)},db=U.document.removeEventListener?function(b,a,c){b.removeEventListener(a,c,!1)}:function(b,a,c){b.detachEvent("on"+a,c)},mc=/([\:\-\_]+(.))/g,nc=/^moz([A-Z])/,ua=Q.prototype={ready:function(b){function a(){c||(c=!0,b())}
27.118 +var c=!1;this.bind("DOMContentLoaded",a);Q(U).bind("load",a)},toString:function(){var b=[];m(this,function(a){b.push(""+a)});return"["+b.join(", ")+"]"},eq:function(b){return b>=0?u(this[b]):u(this[this.length+b])},length:0,push:Ra,sort:[].sort,splice:[].splice},Ea={};m("multiple,selected,checked,disabled,readOnly,required".split(","),function(b){Ea[E(b)]=b});var zb={};m("input,select,option,textarea,button,form".split(","),function(b){zb[la(b)]=!0});m({data:ub,inheritedData:Da,scope:function(b){return Da(b,
27.119 +"$scope")},controller:xb,injector:function(b){return Da(b,"$injector")},removeAttr:function(b,a){b.removeAttribute(a)},hasClass:Ca,css:function(b,a,c){a=rb(a);if(v(c))b.style[a]=c;else{var d;aa<=8&&(d=b.currentStyle&&b.currentStyle[a],d===""&&(d="auto"));d=d||b.style[a];aa<=8&&(d=d===""?p:d);return d}},attr:function(b,a,c){var d=E(a);if(Ea[d])if(v(c))c?(b[a]=!0,b.setAttribute(a,d)):(b[a]=!1,b.removeAttribute(d));else return b[a]||(b.attributes.getNamedItem(a)||D).specified?d:p;else if(v(c))b.setAttribute(a,
27.120 +c);else if(b.getAttribute)return b=b.getAttribute(a,2),b===null?p:b},prop:function(b,a,c){if(v(c))b[a]=c;else return b[a]},text:x(aa<9?function(b,a){if(b.nodeType==1){if(t(a))return b.innerText;b.innerText=a}else{if(t(a))return b.nodeValue;b.nodeValue=a}}:function(b,a){if(t(a))return b.textContent;b.textContent=a},{$dv:""}),val:function(b,a){if(t(a))return b.value;b.value=a},html:function(b,a){if(t(a))return b.innerHTML;for(var c=0,d=b.childNodes;c<d.length;c++)sa(d[c]);b.innerHTML=a}},function(b,
27.121 +a){Q.prototype[a]=function(a,d){var e,g;if((b.length==2&&b!==Ca&&b!==xb?a:d)===p)if(L(a)){for(e=0;e<this.length;e++)if(b===ub)b(this[e],a);else for(g in a)b(this[e],g,a[g]);return this}else{if(this.length)return b(this[0],a,d)}else{for(e=0;e<this.length;e++)b(this[e],a,d);return this}return b.$dv}});m({removeData:sb,dealoc:sa,bind:function a(c,d,e){var g=$(c,"events"),i=$(c,"handle");g||$(c,"events",g={});i||$(c,"handle",i=pc(c,g));m(d.split(" "),function(d){var h=g[d];if(!h){if(d=="mouseenter"||
27.122 +d=="mouseleave"){var k=0;g.mouseenter=[];g.mouseleave=[];a(c,"mouseover",function(a){k++;k==1&&i(a,"mouseenter")});a(c,"mouseout",function(a){k--;k==0&&i(a,"mouseleave")})}else Zb(c,d,i),g[d]=[];h=g[d]}h.push(e)})},unbind:tb,replaceWith:function(a,c){var d,e=a.parentNode;sa(a);m(new Q(c),function(c){d?e.insertBefore(c,d.nextSibling):e.replaceChild(c,a);d=c})},children:function(a){var c=[];m(a.childNodes,function(a){a.nodeName!="#text"&&c.push(a)});return c},contents:function(a){return a.childNodes},
27.123 +append:function(a,c){m(new Q(c),function(c){a.nodeType===1&&a.appendChild(c)})},prepend:function(a,c){if(a.nodeType===1){var d=a.firstChild;m(new Q(c),function(c){d?a.insertBefore(c,d):(a.appendChild(c),d=c)})}},wrap:function(a,c){var c=u(c)[0],d=a.parentNode;d&&d.replaceChild(c,a);c.appendChild(a)},remove:function(a){sa(a);var c=a.parentNode;c&&c.removeChild(a)},after:function(a,c){var d=a,e=a.parentNode;m(new Q(c),function(a){e.insertBefore(a,d.nextSibling);d=a})},addClass:wb,removeClass:vb,toggleClass:function(a,
27.124 +c,d){t(d)&&(d=!Ca(a,c));(d?wb:vb)(a,c)},parent:function(a){return(a=a.parentNode)&&a.nodeType!==11?a:null},next:function(a){return a.nextSibling},find:function(a,c){return a.getElementsByTagName(c)},clone:cb,triggerHandler:function(a,c){var d=($(a,"events")||{})[c];m(d,function(c){c.call(a,null)})}},function(a,c){Q.prototype[c]=function(c,e){for(var g,i=0;i<this.length;i++)g==p?(g=a(this[i],c,e),g!==p&&(g=u(g))):bb(g,a(this[i],c,e));return g==p?this:g}});Fa.prototype={put:function(a,c){this[ga(a)]=
27.125 +c},get:function(a){return this[ga(a)]},remove:function(a){var c=this[a=ga(a)];delete this[a];return c}};eb.prototype={push:function(a,c){var d=this[a=ga(a)];d?d.push(c):this[a]=[c]},shift:function(a){var c=this[a=ga(a)];if(c)return c.length==1?(delete this[a],c[0]):c.shift()},peek:function(a){if(a=this[ga(a)])return a[0]}};var rc=/^function\s*[^\(]*\(\s*([^\)]*)\)/m,sc=/,/,tc=/^\s*(_?)(\S+?)\1\s*$/,qc=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg,Db="Non-assignable model expression: ";Bb.$inject=["$provide"];
27.126 +var Ac=/^(x[\:\-_]|data[\:\-_])/i,Fb=/^([^:]+):\/\/(\w+:{0,1}\w*@)?([\w\.-]*)(:([0-9]+))?(\/[^\?#]*)?(\?([^#]*))?(#(.*))?$/,$b=/^([^\?#]*)?(\?([^#]*))?(#(.*))?$/,Hc=$b,Gb={http:80,https:443,ftp:21};gb.prototype={$$replace:!1,absUrl:Ja("$$absUrl"),url:function(a,c){if(t(a))return this.$$url;var d=$b.exec(a);d[1]&&this.path(decodeURIComponent(d[1]));if(d[2]||d[1])this.search(d[3]||"");this.hash(d[5]||"",c);return this},protocol:Ja("$$protocol"),host:Ja("$$host"),port:Ja("$$port"),path:Ib("$$path",function(a){return a.charAt(0)==
27.127 +"/"?a:"/"+a}),search:function(a,c){if(t(a))return this.$$search;v(c)?c===null?delete this.$$search[a]:this.$$search[a]=c:this.$$search=F(a)?Xa(a):a;this.$$compose();return this},hash:Ib("$$hash",ma),replace:function(){this.$$replace=!0;return this}};Ia.prototype=ya(gb.prototype);Hb.prototype=ya(Ia.prototype);var Ka={"null":function(){return null},"true":function(){return!0},"false":function(){return!1},undefined:D,"+":function(a,c,d,e){d=d(a,c);e=e(a,c);return v(d)?v(e)?d+e:d:v(e)?e:p},"-":function(a,
27.128 +c,d,e){d=d(a,c);e=e(a,c);return(v(d)?d:0)-(v(e)?e:0)},"*":function(a,c,d,e){return d(a,c)*e(a,c)},"/":function(a,c,d,e){return d(a,c)/e(a,c)},"%":function(a,c,d,e){return d(a,c)%e(a,c)},"^":function(a,c,d,e){return d(a,c)^e(a,c)},"=":D,"==":function(a,c,d,e){return d(a,c)==e(a,c)},"!=":function(a,c,d,e){return d(a,c)!=e(a,c)},"<":function(a,c,d,e){return d(a,c)<e(a,c)},">":function(a,c,d,e){return d(a,c)>e(a,c)},"<=":function(a,c,d,e){return d(a,c)<=e(a,c)},">=":function(a,c,d,e){return d(a,c)>=e(a,
27.129 +c)},"&&":function(a,c,d,e){return d(a,c)&&e(a,c)},"||":function(a,c,d,e){return d(a,c)||e(a,c)},"&":function(a,c,d,e){return d(a,c)&e(a,c)},"|":function(a,c,d,e){return e(a,c)(a,c,d(a,c))},"!":function(a,c,d){return!d(a,c)}},Lc={n:"\n",f:"\u000c",r:"\r",t:"\t",v:"\u000b","'":"'",'"':'"'},hb={},Yc=U.XMLHttpRequest||function(){try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(c){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(d){}throw new B("This browser does not support XMLHttpRequest.");
27.130 +};Pb.$inject=["$provide"];Qb.$inject=["$locale"];Sb.$inject=["$locale"];var Vb=".",hd={yyyy:P("FullYear",4),yy:P("FullYear",2,0,!0),y:P("FullYear",1),MMMM:La("Month"),MMM:La("Month",!0),MM:P("Month",2,1),M:P("Month",1,1),dd:P("Date",2),d:P("Date",1),HH:P("Hours",2),H:P("Hours",1),hh:P("Hours",2,-12),h:P("Hours",1,-12),mm:P("Minutes",2),m:P("Minutes",1),ss:P("Seconds",2),s:P("Seconds",1),EEEE:La("Day"),EEE:La("Day",!0),a:function(a,c){return a.getHours()<12?c.AMPMS[0]:c.AMPMS[1]},Z:function(a){a=a.getTimezoneOffset();
27.131 +return ib(a/60,2)+ib(Math.abs(a%60),2)}},gd=/((?:[^yMdHhmsaZE']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+|H+|h+|m+|s+|a|Z))(.*)/,fd=/^\d+$/;Rb.$inject=["$locale"];var dd=I(E),ed=I(la);Tb.$inject=["$parse"];var jd=I({restrict:"E",compile:function(a,c){c.href||c.$set("href","");return function(a,c){c.bind("click",function(a){if(!c.attr("href"))return a.preventDefault(),!1})}}}),kb={};m(Ea,function(a,c){var d=fa("ng-"+c);kb[d]=function(){return{priority:100,compile:function(){return function(a,g,i){a.$watch(i[d],
27.132 +function(a){i.$set(c,!!a)})}}}}});m(["src","href"],function(a){var c=fa("ng-"+a);kb[c]=function(){return{priority:99,link:function(d,e,g){g.$observe(c,function(c){c&&(g.$set(a,c),aa&&e.prop(a,c))})}}}});var Oa={$addControl:D,$removeControl:D,$setValidity:D,$setDirty:D};Wb.$inject=["$element","$attrs","$scope"];var Ra=function(a){return["$timeout",function(c){var d={name:"form",restrict:"E",controller:Wb,compile:function(){return{pre:function(a,d,i,f){if(!i.action){var h=function(a){a.preventDefault?
27.133 +a.preventDefault():a.returnValue=!1};Zb(d[0],"submit",h);d.bind("$destroy",function(){c(function(){db(d[0],"submit",h)},0,!1)})}var k=d.parent().controller("form"),j=i.name||i.ngForm;j&&(a[j]=f);k&&d.bind("$destroy",function(){k.$removeControl(f);j&&(a[j]=p);x(f,Oa)})}}}};return a?x(V(d),{restrict:"EAC"}):d}]},kd=Ra(),ld=Ra(!0),md=/^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/,nd=/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/,od=/^\s*(\-|\+)?(\d+|(\d*(\.\d*)))\s*$/,
27.134 +ac={text:Qa,number:function(a,c,d,e,g,i){Qa(a,c,d,e,g,i);e.$parsers.push(function(a){var c=T(a);return c||od.test(a)?(e.$setValidity("number",!0),a===""?null:c?a:parseFloat(a)):(e.$setValidity("number",!1),p)});e.$formatters.push(function(a){return T(a)?"":""+a});if(d.min){var f=parseFloat(d.min),a=function(a){return!T(a)&&a<f?(e.$setValidity("min",!1),p):(e.$setValidity("min",!0),a)};e.$parsers.push(a);e.$formatters.push(a)}if(d.max){var h=parseFloat(d.max),d=function(a){return!T(a)&&a>h?(e.$setValidity("max",
27.135 +!1),p):(e.$setValidity("max",!0),a)};e.$parsers.push(d);e.$formatters.push(d)}e.$formatters.push(function(a){return T(a)||wa(a)?(e.$setValidity("number",!0),a):(e.$setValidity("number",!1),p)})},url:function(a,c,d,e,g,i){Qa(a,c,d,e,g,i);a=function(a){return T(a)||md.test(a)?(e.$setValidity("url",!0),a):(e.$setValidity("url",!1),p)};e.$formatters.push(a);e.$parsers.push(a)},email:function(a,c,d,e,g,i){Qa(a,c,d,e,g,i);a=function(a){return T(a)||nd.test(a)?(e.$setValidity("email",!0),a):(e.$setValidity("email",
27.136 +!1),p)};e.$formatters.push(a);e.$parsers.push(a)},radio:function(a,c,d,e){t(d.name)&&c.attr("name",xa());c.bind("click",function(){c[0].checked&&a.$apply(function(){e.$setViewValue(d.value)})});e.$render=function(){c[0].checked=d.value==e.$viewValue};d.$observe("value",e.$render)},checkbox:function(a,c,d,e){var g=d.ngTrueValue,i=d.ngFalseValue;F(g)||(g=!0);F(i)||(i=!1);c.bind("click",function(){a.$apply(function(){e.$setViewValue(c[0].checked)})});e.$render=function(){c[0].checked=e.$viewValue};e.$formatters.push(function(a){return a===
27.137 +g});e.$parsers.push(function(a){return a?g:i})},hidden:D,button:D,submit:D,reset:D},bc=["$browser","$sniffer",function(a,c){return{restrict:"E",require:"?ngModel",link:function(d,e,g,i){i&&(ac[E(g.type)]||ac.text)(d,e,g,i,c,a)}}}],Na="ng-valid",Ma="ng-invalid",Pa="ng-pristine",Xb="ng-dirty",pd=["$scope","$exceptionHandler","$attrs","$element","$parse",function(a,c,d,e,g){function i(a,c){c=c?"-"+$a(c,"-"):"";e.removeClass((a?Ma:Na)+c).addClass((a?Na:Ma)+c)}this.$modelValue=this.$viewValue=Number.NaN;
27.138 +this.$parsers=[];this.$formatters=[];this.$viewChangeListeners=[];this.$pristine=!0;this.$dirty=!1;this.$valid=!0;this.$invalid=!1;this.$name=d.name;var f=g(d.ngModel),h=f.assign;if(!h)throw B(Db+d.ngModel+" ("+pa(e)+")");this.$render=D;var k=e.inheritedData("$formController")||Oa,j=0,l=this.$error={};e.addClass(Pa);i(!0);this.$setValidity=function(a,c){if(l[a]!==!c){if(c){if(l[a]&&j--,!j)i(!0),this.$valid=!0,this.$invalid=!1}else i(!1),this.$invalid=!0,this.$valid=!1,j++;l[a]=!c;i(c,a);k.$setValidity(a,
27.139 +c,this)}};this.$setViewValue=function(d){this.$viewValue=d;if(this.$pristine)this.$dirty=!0,this.$pristine=!1,e.removeClass(Pa).addClass(Xb),k.$setDirty();m(this.$parsers,function(a){d=a(d)});if(this.$modelValue!==d)this.$modelValue=d,h(a,d),m(this.$viewChangeListeners,function(a){try{a()}catch(d){c(d)}})};var o=this;a.$watch(function(){var c=f(a);if(o.$modelValue!==c){var d=o.$formatters,e=d.length;for(o.$modelValue=c;e--;)c=d[e](c);if(o.$viewValue!==c)o.$viewValue=c,o.$render()}})}],qd=function(){return{require:["ngModel",
27.140 +"^?form"],controller:pd,link:function(a,c,d,e){var g=e[0],i=e[1]||Oa;i.$addControl(g);c.bind("$destroy",function(){i.$removeControl(g)})}}},rd=I({require:"ngModel",link:function(a,c,d,e){e.$viewChangeListeners.push(function(){a.$eval(d.ngChange)})}}),cc=function(){return{require:"?ngModel",link:function(a,c,d,e){if(e){d.required=!0;var g=function(a){if(d.required&&(T(a)||a===!1))e.$setValidity("required",!1);else return e.$setValidity("required",!0),a};e.$formatters.push(g);e.$parsers.unshift(g);
27.141 +d.$observe("required",function(){g(e.$viewValue)})}}}},sd=function(){return{require:"ngModel",link:function(a,c,d,e){var g=(a=/\/(.*)\//.exec(d.ngList))&&RegExp(a[1])||d.ngList||",";e.$parsers.push(function(a){var c=[];a&&m(a.split(g),function(a){a&&c.push(R(a))});return c});e.$formatters.push(function(a){return J(a)?a.join(", "):p})}}},td=/^(true|false|\d+)$/,ud=function(){return{priority:100,compile:function(a,c){return td.test(c.ngValue)?function(a,c,g){g.$set("value",a.$eval(g.ngValue))}:function(a,
27.142 +c,g){a.$watch(g.ngValue,function(a){g.$set("value",a,!1)})}}}},vd=S(function(a,c,d){c.addClass("ng-binding").data("$binding",d.ngBind);a.$watch(d.ngBind,function(a){c.text(a==p?"":a)})}),wd=["$interpolate",function(a){return function(c,d,e){c=a(d.attr(e.$attr.ngBindTemplate));d.addClass("ng-binding").data("$binding",c);e.$observe("ngBindTemplate",function(a){d.text(a)})}}],xd=[function(){return function(a,c,d){c.addClass("ng-binding").data("$binding",d.ngBindHtmlUnsafe);a.$watch(d.ngBindHtmlUnsafe,
27.143 +function(a){c.html(a||"")})}}],yd=jb("",!0),zd=jb("Odd",0),Ad=jb("Even",1),Bd=S({compile:function(a,c){c.$set("ngCloak",p);a.removeClass("ng-cloak")}}),Cd=[function(){return{scope:!0,controller:"@"}}],Dd=["$sniffer",function(a){return{priority:1E3,compile:function(){a.csp=!0}}}],dc={};m("click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave".split(" "),function(a){var c=fa("ng-"+a);dc[c]=["$parse",function(d){return function(e,g,i){var f=d(i[c]);g.bind(E(a),function(a){e.$apply(function(){f(e,
27.144 +{$event:a})})})}}]});var Ed=S(function(a,c,d){c.bind("submit",function(){a.$apply(d.ngSubmit)})}),Fd=["$http","$templateCache","$anchorScroll","$compile",function(a,c,d,e){return{restrict:"ECA",terminal:!0,compile:function(g,i){var f=i.ngInclude||i.src,h=i.onload||"",k=i.autoscroll;return function(g,i){var o=0,m,n=function(){m&&(m.$destroy(),m=null);i.html("")};g.$watch(f,function(f){var p=++o;f?a.get(f,{cache:c}).success(function(a){p===o&&(m&&m.$destroy(),m=g.$new(),i.html(a),e(i.contents())(m),
27.145 +v(k)&&(!k||g.$eval(k))&&d(),m.$emit("$includeContentLoaded"),g.$eval(h))}).error(function(){p===o&&n()}):n()})}}}}],Gd=S({compile:function(){return{pre:function(a,c,d){a.$eval(d.ngInit)}}}}),Hd=S({terminal:!0,priority:1E3}),Id=["$locale","$interpolate",function(a,c){var d=/{}/g;return{restrict:"EA",link:function(e,g,i){var f=i.count,h=g.attr(i.$attr.when),k=i.offset||0,j=e.$eval(h),l={},o=c.startSymbol(),r=c.endSymbol();m(j,function(a,e){l[e]=c(a.replace(d,o+f+"-"+k+r))});e.$watch(function(){var c=
27.146 +parseFloat(e.$eval(f));return isNaN(c)?"":(j[c]||(c=a.pluralCat(c-k)),l[c](e,g,!0))},function(a){g.text(a)})}}}],Jd=S({transclude:"element",priority:1E3,terminal:!0,compile:function(a,c,d){return function(a,c,i){var f=i.ngRepeat,i=f.match(/^\s*(.+)\s+in\s+(.*)\s*$/),h,k,j;if(!i)throw B("Expected ngRepeat in form of '_item_ in _collection_' but got '"+f+"'.");f=i[1];h=i[2];i=f.match(/^(?:([\$\w]+)|\(([\$\w]+)\s*,\s*([\$\w]+)\))$/);if(!i)throw B("'item' in 'item in collection' should be identifier or (key, value) but got '"+
27.147 +f+"'.");k=i[3]||i[1];j=i[2];var l=new eb;a.$watch(function(a){var e,f,i=a.$eval(h),m=gc(i,!0),p,u=new eb,C,A,v,t,y=c;if(J(i))v=i||[];else{v=[];for(C in i)i.hasOwnProperty(C)&&C.charAt(0)!="$"&&v.push(C);v.sort()}e=0;for(f=v.length;e<f;e++){C=i===v?e:v[e];A=i[C];if(t=l.shift(A)){p=t.scope;u.push(A,t);if(e!==t.index)t.index=e,y.after(t.element);y=t.element}else p=a.$new();p[k]=A;j&&(p[j]=C);p.$index=e;p.$first=e===0;p.$last=e===m-1;p.$middle=!(p.$first||p.$last);t||d(p,function(a){y.after(a);t={scope:p,
27.148 +element:y=a,index:e};u.push(A,t)})}for(C in l)if(l.hasOwnProperty(C))for(v=l[C];v.length;)A=v.pop(),A.element.remove(),A.scope.$destroy();l=u})}}}),Kd=S(function(a,c,d){a.$watch(d.ngShow,function(a){c.css("display",Wa(a)?"":"none")})}),Ld=S(function(a,c,d){a.$watch(d.ngHide,function(a){c.css("display",Wa(a)?"none":"")})}),Md=S(function(a,c,d){a.$watch(d.ngStyle,function(a,d){d&&a!==d&&m(d,function(a,d){c.css(d,"")});a&&c.css(a)},!0)}),Nd=I({restrict:"EA",compile:function(a,c){var d=c.ngSwitch||c.on,
27.149 +e={};a.data("ng-switch",e);return function(a,i){var f,h,k;a.$watch(d,function(d){h&&(k.$destroy(),h.remove(),h=k=null);if(f=e["!"+d]||e["?"])a.$eval(c.change),k=a.$new(),f(k,function(a){h=a;i.append(a)})})}}}),Od=S({transclude:"element",priority:500,compile:function(a,c,d){a=a.inheritedData("ng-switch");qa(a);a["!"+c.ngSwitchWhen]=d}}),Pd=S({transclude:"element",priority:500,compile:function(a,c,d){a=a.inheritedData("ng-switch");qa(a);a["?"]=d}}),Qd=S({controller:["$transclude","$element",function(a,
27.150 +c){a(function(a){c.append(a)})}]}),Rd=["$http","$templateCache","$route","$anchorScroll","$compile","$controller",function(a,c,d,e,g,i){return{restrict:"ECA",terminal:!0,link:function(a,c,k){function j(){var j=d.current&&d.current.locals,k=j&&j.$template;if(k){c.html(k);l&&(l.$destroy(),l=null);var k=g(c.contents()),p=d.current;l=p.scope=a.$new();if(p.controller)j.$scope=l,j=i(p.controller,j),c.contents().data("$ngControllerController",j);k(l);l.$emit("$viewContentLoaded");l.$eval(m);e()}else c.html(""),
27.151 +l&&(l.$destroy(),l=null)}var l,m=k.onload||"";a.$on("$routeChangeSuccess",j);j()}}}],Sd=["$templateCache",function(a){return{restrict:"E",terminal:!0,compile:function(c,d){d.type=="text/ng-template"&&a.put(d.id,c[0].text)}}}],Td=I({terminal:!0}),Ud=["$compile","$parse",function(a,c){var d=/^\s*(.*?)(?:\s+as\s+(.*?))?(?:\s+group\s+by\s+(.*))?\s+for\s+(?:([\$\w][\$\w\d]*)|(?:\(\s*([\$\w][\$\w\d]*)\s*,\s*([\$\w][\$\w\d]*)\s*\)))\s+in\s+(.*)$/,e={$setViewValue:D};return{restrict:"E",require:["select",
27.152 +"?ngModel"],controller:["$element","$scope","$attrs",function(a,c,d){var h=this,k={},j=e,l;h.databound=d.ngModel;h.init=function(a,c,d){j=a;l=d};h.addOption=function(c){k[c]=!0;j.$viewValue==c&&(a.val(c),l.parent()&&l.remove())};h.removeOption=function(a){this.hasOption(a)&&(delete k[a],j.$viewValue==a&&this.renderUnknownOption(a))};h.renderUnknownOption=function(c){c="? "+ga(c)+" ?";l.val(c);a.prepend(l);a.val(c);l.prop("selected",!0)};h.hasOption=function(a){return k.hasOwnProperty(a)};c.$on("$destroy",
27.153 +function(){h.renderUnknownOption=D})}],link:function(e,i,f,h){function k(a,c,d,e){d.$render=function(){var a=d.$viewValue;e.hasOption(a)?(A.parent()&&A.remove(),c.val(a),a===""&&s.prop("selected",!0)):t(a)&&s?c.val(""):e.renderUnknownOption(a)};c.bind("change",function(){a.$apply(function(){A.parent()&&A.remove();d.$setViewValue(c.val())})})}function j(a,c,d){var e;d.$render=function(){var a=new Fa(d.$viewValue);m(c.children(),function(c){c.selected=v(a.get(c.value))})};a.$watch(function(){ha(e,d.$viewValue)||
27.154 +(e=V(d.$viewValue),d.$render())});c.bind("change",function(){a.$apply(function(){var a=[];m(c.children(),function(c){c.selected&&a.push(c.value)});d.$setViewValue(a)})})}function l(e,f,g){function h(){var a={"":[]},c=[""],d,i,s,t,u;s=g.$modelValue;t=r(e)||[];var y=l?lb(t):t,A,w,x;w={};u=!1;var z,B;if(n)u=new Fa(s);else if(s===null||q)a[""].push({selected:s===null,id:"",label:""}),u=!0;for(x=0;A=y.length,x<A;x++){w[k]=t[l?w[l]=y[x]:x];d=m(e,w)||"";if(!(i=a[d]))i=a[d]=[],c.push(d);n?d=u.remove(o(e,
27.155 +w))!=p:(d=s===o(e,w),u=u||d);z=j(e,w);z=z===p?"":z;i.push({id:l?y[x]:x,label:z,selected:d})}!n&&!u&&a[""].unshift({id:"?",label:"",selected:!0});w=0;for(y=c.length;w<y;w++){d=c[w];i=a[d];if(v.length<=w)s={element:C.clone().attr("label",d),label:i.label},t=[s],v.push(t),f.append(s.element);else if(t=v[w],s=t[0],s.label!=d)s.element.attr("label",s.label=d);z=null;x=0;for(A=i.length;x<A;x++)if(d=i[x],u=t[x+1]){z=u.element;if(u.label!==d.label)z.text(u.label=d.label);if(u.id!==d.id)z.val(u.id=d.id);if(u.element.selected!==
27.156 +d.selected)z.prop("selected",u.selected=d.selected)}else d.id===""&&q?B=q:(B=D.clone()).val(d.id).attr("selected",d.selected).text(d.label),t.push({element:B,label:d.label,id:d.id,selected:d.selected}),z?z.after(B):s.element.append(B),z=B;for(x++;t.length>x;)t.pop().element.remove()}for(;v.length>w;)v.pop()[0].element.remove()}var i;if(!(i=w.match(d)))throw B("Expected ngOptions in form of '_select_ (as _label_)? for (_key_,)?_value_ in _collection_' but got '"+w+"'.");var j=c(i[2]||i[1]),k=i[4]||
27.157 +i[6],l=i[5],m=c(i[3]||""),o=c(i[2]?i[1]:k),r=c(i[7]),v=[[{element:f,label:""}]];q&&(a(q)(e),q.removeClass("ng-scope"),q.remove());f.html("");f.bind("change",function(){e.$apply(function(){var a,c=r(e)||[],d={},h,i,j,m,q,s;if(n){i=[];m=0;for(s=v.length;m<s;m++){a=v[m];j=1;for(q=a.length;j<q;j++)if((h=a[j].element)[0].selected)h=h.val(),l&&(d[l]=h),d[k]=c[h],i.push(o(e,d))}}else h=f.val(),h=="?"?i=p:h==""?i=null:(d[k]=c[h],l&&(d[l]=h),i=o(e,d));g.$setViewValue(i)})});g.$render=h;e.$watch(h)}if(h[1]){for(var o=
27.158 +h[0],r=h[1],n=f.multiple,w=f.ngOptions,q=!1,s,D=u(ca.createElement("option")),C=u(ca.createElement("optgroup")),A=D.clone(),h=0,x=i.children(),E=x.length;h<E;h++)if(x[h].value==""){s=q=x.eq(h);break}o.init(r,q,A);if(n&&(f.required||f.ngRequired)){var y=function(a){r.$setValidity("required",!f.required||a&&a.length);return a};r.$parsers.push(y);r.$formatters.unshift(y);f.$observe("required",function(){y(r.$viewValue)})}w?l(e,i,r):n?j(e,i,r):k(e,i,r,o)}}}}],Vd=["$interpolate",function(a){var c={addOption:D,
27.159 +removeOption:D};return{restrict:"E",priority:100,compile:function(d,e){if(t(e.value)){var g=a(d.text(),!0);g||e.$set("value",d.text())}return function(a,d,e){var k=d.parent(),j=k.data("$selectController")||k.parent().data("$selectController");j&&j.databound?d.prop("selected",!1):j=c;g?a.$watch(g,function(a,c){e.$set("value",a);a!==c&&j.removeOption(c);j.addOption(a)}):j.addOption(e.value);d.bind("$destroy",function(){j.removeOption(e.value)})}}}}],Wd=I({restrict:"E",terminal:!0});(ja=U.jQuery)?(u=
27.160 +ja,x(ja.fn,{scope:ua.scope,controller:ua.controller,injector:ua.injector,inheritedData:ua.inheritedData}),ab("remove",!0),ab("empty"),ab("html")):u=Q;Yb.element=u;(function(a){x(a,{bootstrap:pb,copy:V,extend:x,equals:ha,element:u,forEach:m,injector:qb,noop:D,bind:Va,toJson:da,fromJson:nb,identity:ma,isUndefined:t,isDefined:v,isString:F,isFunction:N,isObject:L,isNumber:wa,isElement:fc,isArray:J,version:id,isDate:na,lowercase:E,uppercase:la,callbacks:{counter:0}});ta=lc(U);try{ta("ngLocale")}catch(c){ta("ngLocale",
27.161 +[]).provider("$locale",Zc)}ta("ng",["ngLocale"],["$provide",function(a){a.provider("$compile",Bb).directive({a:jd,input:bc,textarea:bc,form:kd,script:Sd,select:Ud,style:Wd,option:Vd,ngBind:vd,ngBindHtmlUnsafe:xd,ngBindTemplate:wd,ngClass:yd,ngClassEven:Ad,ngClassOdd:zd,ngCsp:Dd,ngCloak:Bd,ngController:Cd,ngForm:ld,ngHide:Ld,ngInclude:Fd,ngInit:Gd,ngNonBindable:Hd,ngPluralize:Id,ngRepeat:Jd,ngShow:Kd,ngSubmit:Ed,ngStyle:Md,ngSwitch:Nd,ngSwitchWhen:Od,ngSwitchDefault:Pd,ngOptions:Td,ngView:Rd,ngTransclude:Qd,
27.162 +ngModel:qd,ngList:sd,ngChange:rd,required:cc,ngRequired:cc,ngValue:ud}).directive(kb).directive(dc);a.provider({$anchorScroll:uc,$browser:wc,$cacheFactory:xc,$controller:Bc,$document:Cc,$exceptionHandler:Dc,$filter:Pb,$interpolate:Ec,$http:Vc,$httpBackend:Wc,$location:Ic,$log:Jc,$parse:Nc,$route:Qc,$routeParams:Rc,$rootScope:Sc,$q:Oc,$sniffer:Tc,$templateCache:yc,$timeout:$c,$window:Uc})}])})(Yb);u(ca).ready(function(){jc(ca,pb)})})(window,document);angular.element(document).find("head").append('<style type="text/css">@charset "UTF-8";[ng\\:cloak],[ng-cloak],[data-ng-cloak],[x-ng-cloak],.ng-cloak,.x-ng-cloak{display:none;}ng\\:form{display:block;}</style>');
28.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
28.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/js/app.js Wed Jan 23 20:16:48 2013 +0100
28.3 @@ -0,0 +1,224 @@
28.4 +// 'use strict';
28.5 +
28.6 +// Declare app level module which depends on filters, and services
28.7 +angular.module('bck2brwsr', []).
28.8 + directive('uiCodemirror', ['$timeout', function($timeout) {
28.9 + 'use strict';
28.10 +
28.11 + var events = ["cursorActivity", "viewportChange", "gutterClick", "focus", "blur", "scroll", "update"];
28.12 + return {
28.13 + restrict: 'A',
28.14 + require: 'ngModel',
28.15 + link: function(scope, elm, attrs, ngModel) {
28.16 + var options, opts, onChange, deferCodeMirror, codeMirror, timeoutId, val;
28.17 +
28.18 + if (elm[0].type !== 'textarea') {
28.19 + throw new Error('uiCodemirror3 can only be applied to a textarea element');
28.20 + }
28.21 +
28.22 + options = /* uiConfig.codemirror || */ {};
28.23 + opts = angular.extend({}, options, scope.$eval(attrs.uiCodemirror));
28.24 +
28.25 + onChange = function(instance, changeObj) {
28.26 + val = instance.getValue();
28.27 + $timeout.cancel(timeoutId);
28.28 + timeoutId = $timeout(function() {
28.29 + ngModel.$setViewValue(val);
28.30 + }, 500);
28.31 + };
28.32 +
28.33 + deferCodeMirror = function() {
28.34 + codeMirror = CodeMirror.fromTextArea(elm[0], opts);
28.35 + elm[0].codeMirror = codeMirror;
28.36 + // codeMirror.on("change", onChange(opts.onChange));
28.37 + codeMirror.on("change", onChange);
28.38 +
28.39 + for (var i = 0, n = events.length, aEvent; i < n; ++i) {
28.40 + aEvent = opts["on" + events[i].charAt(0).toUpperCase() + events[i].slice(1)];
28.41 + if (aEvent === void 0)
28.42 + continue;
28.43 + if (typeof aEvent !== "function")
28.44 + continue;
28.45 +
28.46 + var bound = _.bind( aEvent, scope );
28.47 +
28.48 + codeMirror.on(events[i], bound);
28.49 + }
28.50 +
28.51 + // CodeMirror expects a string, so make sure it gets one.
28.52 + // This does not change the model.
28.53 + ngModel.$formatters.push(function(value) {
28.54 + if (angular.isUndefined(value) || value === null) {
28.55 + return '';
28.56 + }
28.57 + else if (angular.isObject(value) || angular.isArray(value)) {
28.58 + throw new Error('ui-codemirror cannot use an object or an array as a model');
28.59 + }
28.60 + return value;
28.61 + });
28.62 +
28.63 + // Override the ngModelController $render method, which is what gets called when the model is updated.
28.64 + // This takes care of the synchronizing the codeMirror element with the underlying model, in the case that it is changed by something else.
28.65 + ngModel.$render = function() {
28.66 + codeMirror.setValue(ngModel.$viewValue);
28.67 + };
28.68 +
28.69 + };
28.70 +
28.71 + $timeout(deferCodeMirror);
28.72 +
28.73 + }
28.74 + };
28.75 +}]);
28.76 +
28.77 +function DevCtrl( $scope, $http ) {
28.78 + var templateHtml =
28.79 +"<html><body>\n" +
28.80 +" <input data-bind=\"value: value, valueUpdate: 'afterkeydown'\" \n" +
28.81 +" value=\"0\" type=\"number\">\n" +
28.82 +" </input>\n" +
28.83 +" * <span data-bind=\"text: value\">0</span> \n" +
28.84 +" = <span data-bind=\"text: powerValue\">0</span>\n" +
28.85 +" <br/>\n" +
28.86 +" <button id='dupl'>Duplicate!</button>\n" +
28.87 +" <button id=\"clear\">Clear!</button>" +
28.88 +" <hr/>\n" +
28.89 +"\n" +
28.90 +"\n" +
28.91 +"\n" +
28.92 +"\n" +
28.93 +"\n" +
28.94 +"\n" +
28.95 +"\n" +
28.96 +"\n" +
28.97 +"\n" +
28.98 +"\n" +
28.99 +"\n" +
28.100 +"\n" +
28.101 +"\n" +
28.102 +"\n" +
28.103 +"\n" +
28.104 +"\n" +
28.105 +"\n" +
28.106 +"\n" +
28.107 +"\n" +
28.108 +"\n" +
28.109 +" <script src=\"/bck2brwsr.js\"></script>\n" +
28.110 +" <script type=\"text/javascript\">\n" +
28.111 +" function ldCls(res) {\n" +
28.112 +" var request = new XMLHttpRequest();\n" +
28.113 +" request.open('GET', '/classes/' + res, false);\n" +
28.114 +" request.send();\n" +
28.115 +" var arr = eval('(' + request.responseText + ')');\n" +
28.116 +" return arr;\n" +
28.117 +" }\n" +
28.118 +" var vm = new bck2brwsr(ldCls);\n" +
28.119 +" vm.loadClass('bck2brwsr.demo.YourFirstHTML5PageInRealLanguage');\n" +
28.120 +" </script>\n" +
28.121 +"</body></html>";
28.122 + var templateJava =
28.123 +"package bck2brwsr.demo;\n" +
28.124 +"import org.apidesign.bck2brwsr.htmlpage.api.*;\n" +
28.125 +"import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;\n" +
28.126 +"\n" +
28.127 +"@Page(xhtml=\"index.html\", className=\"Index\", properties={\n" +
28.128 +" @Property(name=\"value\", type=int.class)\n" +
28.129 +"})\n" +
28.130 +"class YourFirstHTML5PageInRealLanguage {\n" +
28.131 +" static { new Index().applyBindings(); }\n" +
28.132 +" @On(event=CLICK, id=\"dupl\") static void duplicateValue(Index m) {\n" +
28.133 +" m.setValue(m.getValue() * 2);\n" +
28.134 +" }\n" +
28.135 +" @On(event=CLICK, id=\"clear\") static void zeroTheValue(Index m) {\n" +
28.136 +" m.setValue(0);;\n" +
28.137 +" }\n" +
28.138 +" @ComputedProperty static int powerValue(int value) {\n" +
28.139 +" return value * value;\n" +
28.140 +" }\n" +
28.141 +"}";
28.142 +
28.143 +
28.144 + $scope.makeMarker = function( editor, line ) {
28.145 + var marker = document.createElement("div");
28.146 + marker.innerHTML = " ";
28.147 + marker.className = "issue";
28.148 +
28.149 + var info = editor.lineInfo(line);
28.150 + editor.setGutterMarker(line, "issues", info.markers ? null : marker);
28.151 +
28.152 + return marker;
28.153 + };
28.154 +
28.155 +
28.156 + // Returns a function, that, as long as it continues to be invoked, will not
28.157 + // be triggered. The function will be called after it stops being called for
28.158 + // N milliseconds. If `immediate` is passed, trigger the function on the
28.159 + // leading edge, instead of the trailing.
28.160 + $scope.debounce = function(func, wait, immediate) {
28.161 + var timeout, result;
28.162 + return function() {
28.163 + var context = this, args = arguments;
28.164 + var later = function() {
28.165 + timeout = null;
28.166 + if (!immediate) result = func.apply(context, args);
28.167 + };
28.168 + var callNow = immediate && !timeout;
28.169 + clearTimeout(timeout);
28.170 + timeout = setTimeout(later, wait);
28.171 + if (callNow) result = func.apply(context, args);
28.172 + return result;
28.173 + };
28.174 + };
28.175 +
28.176 + $scope.reload = function() {
28.177 + $scope.errors = null;
28.178 + var frame = document.getElementById("result");
28.179 + frame.src = "result.html";
28.180 + frame.contentDocument.location.reload(true);
28.181 + frame.contentWindow.location.reload();
28.182 + document.getElementById("editorJava").codeMirror.clearGutter("issues");
28.183 + };
28.184 +
28.185 + $scope.fail = function( data ) {
28.186 + $scope.errors = eval( data );
28.187 + var editor = document.getElementById("editorJava").codeMirror;
28.188 + editor.clearGutter( "issues" );
28.189 +
28.190 + for( var i = 0; i < $scope.errors.length; i ++ ) {
28.191 + $scope.makeMarker( editor, $scope.errors[i].line - 1 );
28.192 + }
28.193 +
28.194 + };
28.195 +
28.196 + $scope.post = function() {
28.197 + return $http({url: ".",
28.198 + method: "POST",
28.199 + //headers: this.headers,
28.200 + data: { html : $scope.html, java : $scope.java}
28.201 + }).success( $scope.reload ).error( $scope.fail );
28.202 + };
28.203 +
28.204 + $scope.errorClass = function( kind ) {
28.205 + switch( kind ) {
28.206 + case "ERROR" :
28.207 + return "error";
28.208 + default :
28.209 + return "warning";
28.210 + }
28.211 + };
28.212 +
28.213 + $scope.gotoError = function( line, col ) {
28.214 + var editor = document.getElementById("editorJava").codeMirror;
28.215 + editor.setCursor({ line: line - 1, ch : col - 1 });
28.216 + editor.focus();
28.217 + };
28.218 +
28.219 + $scope.tab = "html";
28.220 + $scope.html= templateHtml;
28.221 + $scope.java = templateJava;
28.222 +
28.223 + $scope.$watch( "html", $scope.debounce( $scope.post, 2000 ) );
28.224 + $scope.$watch( "java", $scope.debounce( $scope.post, 2000 ) );
28.225 + $scope.post();
28.226 +
28.227 +}
29.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
29.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/js/codemirror/codemirror.css Wed Jan 23 20:16:48 2013 +0100
29.3 @@ -0,0 +1,239 @@
29.4 +/* BASICS */
29.5 +
29.6 +.CodeMirror {
29.7 + /* Set height, width, borders, and global font properties here */
29.8 + font-family: monospace;
29.9 + height: 300px;
29.10 +}
29.11 +.CodeMirror-scroll {
29.12 + /* Set scrolling behaviour here */
29.13 + overflow: auto;
29.14 +}
29.15 +
29.16 +/* PADDING */
29.17 +
29.18 +.CodeMirror-lines {
29.19 + padding: 4px 0; /* Vertical padding around content */
29.20 +}
29.21 +.CodeMirror pre {
29.22 + padding: 0 4px; /* Horizontal padding of content */
29.23 +}
29.24 +
29.25 +.CodeMirror-scrollbar-filler {
29.26 + background-color: white; /* The little square between H and V scrollbars */
29.27 +}
29.28 +
29.29 +/* GUTTER */
29.30 +
29.31 +.CodeMirror-gutters {
29.32 + border-right: 1px solid #ddd;
29.33 + background-color: #f7f7f7;
29.34 +}
29.35 +.CodeMirror-linenumbers {}
29.36 +.CodeMirror-linenumber {
29.37 + padding: 0 3px 0 5px;
29.38 + min-width: 20px;
29.39 + text-align: right;
29.40 + color: #999;
29.41 +}
29.42 +
29.43 +/* CURSOR */
29.44 +
29.45 +.CodeMirror pre.CodeMirror-cursor {
29.46 + border-left: 1px solid black;
29.47 +}
29.48 +/* Shown when moving in bi-directional text */
29.49 +.CodeMirror pre.CodeMirror-secondarycursor {
29.50 + border-left: 1px solid silver;
29.51 +}
29.52 +.cm-keymap-fat-cursor pre.CodeMirror-cursor {
29.53 + width: auto;
29.54 + border: 0;
29.55 + background: transparent;
29.56 + background: rgba(0, 200, 0, .4);
29.57 + filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#6600c800, endColorstr=#4c00c800);
29.58 +}
29.59 +/* Kludge to turn off filter in ie9+, which also accepts rgba */
29.60 +.cm-keymap-fat-cursor pre.CodeMirror-cursor:not(#nonsense_id) {
29.61 + filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
29.62 +}
29.63 +/* Can style cursor different in overwrite (non-insert) mode */
29.64 +.CodeMirror pre.CodeMirror-cursor.CodeMirror-overwrite {}
29.65 +
29.66 +/* DEFAULT THEME */
29.67 +
29.68 +.cm-s-default .cm-keyword {color: #708;}
29.69 +.cm-s-default .cm-atom {color: #219;}
29.70 +.cm-s-default .cm-number {color: #164;}
29.71 +.cm-s-default .cm-def {color: #00f;}
29.72 +.cm-s-default .cm-variable {color: black;}
29.73 +.cm-s-default .cm-variable-2 {color: #05a;}
29.74 +.cm-s-default .cm-variable-3 {color: #085;}
29.75 +.cm-s-default .cm-property {color: black;}
29.76 +.cm-s-default .cm-operator {color: black;}
29.77 +.cm-s-default .cm-comment {color: #a50;}
29.78 +.cm-s-default .cm-string {color: #a11;}
29.79 +.cm-s-default .cm-string-2 {color: #f50;}
29.80 +.cm-s-default .cm-meta {color: #555;}
29.81 +.cm-s-default .cm-error {color: #f00;}
29.82 +.cm-s-default .cm-qualifier {color: #555;}
29.83 +.cm-s-default .cm-builtin {color: #30a;}
29.84 +.cm-s-default .cm-bracket {color: #997;}
29.85 +.cm-s-default .cm-tag {color: #170;}
29.86 +.cm-s-default .cm-attribute {color: #00c;}
29.87 +.cm-s-default .cm-header {color: blue;}
29.88 +.cm-s-default .cm-quote {color: #090;}
29.89 +.cm-s-default .cm-hr {color: #999;}
29.90 +.cm-s-default .cm-link {color: #00c;}
29.91 +
29.92 +.cm-negative {color: #d44;}
29.93 +.cm-positive {color: #292;}
29.94 +.cm-header, .cm-strong {font-weight: bold;}
29.95 +.cm-em {font-style: italic;}
29.96 +.cm-emstrong {font-style: italic; font-weight: bold;}
29.97 +.cm-link {text-decoration: underline;}
29.98 +
29.99 +.cm-invalidchar {color: #f00;}
29.100 +
29.101 +div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
29.102 +div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
29.103 +
29.104 +/* STOP */
29.105 +
29.106 +/* The rest of this file contains styles related to the mechanics of
29.107 + the editor. You probably shouldn't touch them. */
29.108 +
29.109 +.CodeMirror {
29.110 + line-height: 1;
29.111 + position: relative;
29.112 + overflow: hidden;
29.113 +}
29.114 +
29.115 +.CodeMirror-scroll {
29.116 + /* 30px is the magic margin used to hide the element's real scrollbars */
29.117 + /* See overflow: hidden in .CodeMirror, and the paddings in .CodeMirror-sizer */
29.118 + margin-bottom: -30px; margin-right: -30px;
29.119 + padding-bottom: 30px; padding-right: 30px;
29.120 + height: 100%;
29.121 + outline: none; /* Prevent dragging from highlighting the element */
29.122 + position: relative;
29.123 +}
29.124 +.CodeMirror-sizer {
29.125 + position: relative;
29.126 +}
29.127 +
29.128 +/* The fake, visible scrollbars. Used to force redraw during scrolling
29.129 + before actuall scrolling happens, thus preventing shaking and
29.130 + flickering artifacts. */
29.131 +.CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler {
29.132 + position: absolute;
29.133 + z-index: 6;
29.134 + display: none;
29.135 +}
29.136 +.CodeMirror-vscrollbar {
29.137 + right: 0; top: 0;
29.138 + overflow-x: hidden;
29.139 + overflow-y: scroll;
29.140 +}
29.141 +.CodeMirror-hscrollbar {
29.142 + bottom: 0; left: 0;
29.143 + overflow-y: hidden;
29.144 + overflow-x: scroll;
29.145 +}
29.146 +.CodeMirror-scrollbar-filler {
29.147 + right: 0; bottom: 0;
29.148 + z-index: 6;
29.149 +}
29.150 +
29.151 +.CodeMirror-gutters {
29.152 + position: absolute; left: 0; top: 0;
29.153 + height: 100%;
29.154 + z-index: 3;
29.155 +}
29.156 +.CodeMirror-gutter {
29.157 + height: 100%;
29.158 + display: inline-block;
29.159 + /* Hack to make IE7 behave */
29.160 + *zoom:1;
29.161 + *display:inline;
29.162 +}
29.163 +.CodeMirror-gutter-elt {
29.164 + position: absolute;
29.165 + cursor: default;
29.166 + z-index: 4;
29.167 +}
29.168 +
29.169 +.CodeMirror-lines {
29.170 + cursor: text;
29.171 +}
29.172 +.CodeMirror pre {
29.173 + /* Reset some styles that the rest of the page might have set */
29.174 + -moz-border-radius: 0; -webkit-border-radius: 0; -o-border-radius: 0; border-radius: 0;
29.175 + border-width: 0;
29.176 + background: transparent;
29.177 + font-family: inherit;
29.178 + font-size: inherit;
29.179 + margin: 0;
29.180 + white-space: pre;
29.181 + word-wrap: normal;
29.182 + line-height: inherit;
29.183 + color: inherit;
29.184 + z-index: 2;
29.185 + position: relative;
29.186 + overflow: visible;
29.187 +}
29.188 +.CodeMirror-wrap pre {
29.189 + word-wrap: break-word;
29.190 + white-space: pre-wrap;
29.191 + word-break: normal;
29.192 +}
29.193 +.CodeMirror-linebackground {
29.194 + position: absolute;
29.195 + left: 0; right: 0; top: 0; bottom: 0;
29.196 + z-index: 0;
29.197 +}
29.198 +
29.199 +.CodeMirror-linewidget {
29.200 + position: relative;
29.201 + z-index: 2;
29.202 +}
29.203 +
29.204 +.CodeMirror-wrap .CodeMirror-scroll {
29.205 + overflow-x: hidden;
29.206 +}
29.207 +
29.208 +.CodeMirror-measure {
29.209 + position: absolute;
29.210 + width: 100%; height: 0px;
29.211 + overflow: hidden;
29.212 + visibility: hidden;
29.213 +}
29.214 +.CodeMirror-measure pre { position: static; }
29.215 +
29.216 +.CodeMirror pre.CodeMirror-cursor {
29.217 + position: absolute;
29.218 + visibility: hidden;
29.219 + border-right: none;
29.220 + width: 0;
29.221 +}
29.222 +.CodeMirror-focused pre.CodeMirror-cursor {
29.223 + visibility: visible;
29.224 +}
29.225 +
29.226 +.CodeMirror-selected { background: #d9d9d9; }
29.227 +.CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
29.228 +
29.229 +.CodeMirror-searching {
29.230 + background: #ffa;
29.231 + background: rgba(255, 255, 0, .4);
29.232 +}
29.233 +
29.234 +/* IE7 hack to prevent it from returning funny offsetTops on the spans */
29.235 +.CodeMirror span { *vertical-align: text-bottom; }
29.236 +
29.237 +@media print {
29.238 + /* Hide the cursor when printing */
29.239 + .CodeMirror pre.CodeMirror-cursor {
29.240 + visibility: hidden;
29.241 + }
29.242 +}
30.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
30.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/js/codemirror/codemirror.js Wed Jan 23 20:16:48 2013 +0100
30.3 @@ -0,0 +1,4553 @@
30.4 +// CodeMirror version 3.0
30.5 +//
30.6 +// CodeMirror is the only global var we claim
30.7 +window.CodeMirror = (function() {
30.8 + "use strict";
30.9 +
30.10 + // BROWSER SNIFFING
30.11 +
30.12 + // Crude, but necessary to handle a number of hard-to-feature-detect
30.13 + // bugs and behavior differences.
30.14 + var gecko = /gecko\/\d/i.test(navigator.userAgent);
30.15 + var ie = /MSIE \d/.test(navigator.userAgent);
30.16 + var ie_lt8 = /MSIE [1-7]\b/.test(navigator.userAgent);
30.17 + var ie_lt9 = /MSIE [1-8]\b/.test(navigator.userAgent);
30.18 + var webkit = /WebKit\//.test(navigator.userAgent);
30.19 + var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(navigator.userAgent);
30.20 + var chrome = /Chrome\//.test(navigator.userAgent);
30.21 + var opera = /Opera\//.test(navigator.userAgent);
30.22 + var safari = /Apple Computer/.test(navigator.vendor);
30.23 + var khtml = /KHTML\//.test(navigator.userAgent);
30.24 + var mac_geLion = /Mac OS X 1\d\D([7-9]|\d\d)\D/.test(navigator.userAgent);
30.25 + var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(navigator.userAgent);
30.26 + var phantom = /PhantomJS/.test(navigator.userAgent);
30.27 +
30.28 + var ios = /AppleWebKit/.test(navigator.userAgent) && /Mobile\/\w+/.test(navigator.userAgent);
30.29 + // This is woefully incomplete. Suggestions for alternative methods welcome.
30.30 + var mobile = ios || /Android|webOS|BlackBerry|Opera Mini|IEMobile/i.test(navigator.userAgent);
30.31 + var mac = ios || /Mac/.test(navigator.platform);
30.32 +
30.33 + // Optimize some code when these features are not used
30.34 + var sawReadOnlySpans = false, sawCollapsedSpans = false;
30.35 +
30.36 + // CONSTRUCTOR
30.37 +
30.38 + function CodeMirror(place, options) {
30.39 + if (!(this instanceof CodeMirror)) return new CodeMirror(place, options);
30.40 +
30.41 + this.options = options = options || {};
30.42 + // Determine effective options based on given values and defaults.
30.43 + for (var opt in defaults) if (!options.hasOwnProperty(opt) && defaults.hasOwnProperty(opt))
30.44 + options[opt] = defaults[opt];
30.45 + setGuttersForLineNumbers(options);
30.46 +
30.47 + var display = this.display = makeDisplay(place);
30.48 + display.wrapper.CodeMirror = this;
30.49 + updateGutters(this);
30.50 + if (options.autofocus && !mobile) focusInput(this);
30.51 +
30.52 + this.view = makeView(new BranchChunk([new LeafChunk([makeLine("", null, textHeight(display))])]));
30.53 + this.nextOpId = 0;
30.54 + loadMode(this);
30.55 + themeChanged(this);
30.56 + if (options.lineWrapping)
30.57 + this.display.wrapper.className += " CodeMirror-wrap";
30.58 +
30.59 + // Initialize the content.
30.60 + this.setValue(options.value || "");
30.61 + // Override magic textarea content restore that IE sometimes does
30.62 + // on our hidden textarea on reload
30.63 + if (ie) setTimeout(bind(resetInput, this, true), 20);
30.64 + this.view.history = makeHistory();
30.65 +
30.66 + registerEventHandlers(this);
30.67 + // IE throws unspecified error in certain cases, when
30.68 + // trying to access activeElement before onload
30.69 + var hasFocus; try { hasFocus = (document.activeElement == display.input); } catch(e) { }
30.70 + if (hasFocus || (options.autofocus && !mobile)) setTimeout(bind(onFocus, this), 20);
30.71 + else onBlur(this);
30.72 +
30.73 + operation(this, function() {
30.74 + for (var opt in optionHandlers)
30.75 + if (optionHandlers.propertyIsEnumerable(opt))
30.76 + optionHandlers[opt](this, options[opt], Init);
30.77 + for (var i = 0; i < initHooks.length; ++i) initHooks[i](this);
30.78 + })();
30.79 + }
30.80 +
30.81 + // DISPLAY CONSTRUCTOR
30.82 +
30.83 + function makeDisplay(place) {
30.84 + var d = {};
30.85 + var input = d.input = elt("textarea", null, null, "position: absolute; padding: 0; width: 1px; height: 1em; outline: none;");
30.86 + input.setAttribute("wrap", "off"); input.setAttribute("autocorrect", "off"); input.setAttribute("autocapitalize", "off");
30.87 + // Wraps and hides input textarea
30.88 + d.inputDiv = elt("div", [input], null, "overflow: hidden; position: relative; width: 3px; height: 0px;");
30.89 + // The actual fake scrollbars.
30.90 + d.scrollbarH = elt("div", [elt("div", null, null, "height: 1px")], "CodeMirror-hscrollbar");
30.91 + d.scrollbarV = elt("div", [elt("div", null, null, "width: 1px")], "CodeMirror-vscrollbar");
30.92 + d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler");
30.93 + // DIVs containing the selection and the actual code
30.94 + d.lineDiv = elt("div");
30.95 + d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1");
30.96 + // Blinky cursor, and element used to ensure cursor fits at the end of a line
30.97 + d.cursor = elt("pre", "\u00a0", "CodeMirror-cursor");
30.98 + // Secondary cursor, shown when on a 'jump' in bi-directional text
30.99 + d.otherCursor = elt("pre", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor");
30.100 + // Used to measure text size
30.101 + d.measure = elt("div", null, "CodeMirror-measure");
30.102 + // Wraps everything that needs to exist inside the vertically-padded coordinate system
30.103 + d.lineSpace = elt("div", [d.measure, d.selectionDiv, d.lineDiv, d.cursor, d.otherCursor],
30.104 + null, "position: relative; outline: none");
30.105 + // Moved around its parent to cover visible view
30.106 + d.mover = elt("div", [elt("div", [d.lineSpace], "CodeMirror-lines")], null, "position: relative");
30.107 + // Set to the height of the text, causes scrolling
30.108 + d.sizer = elt("div", [d.mover], "CodeMirror-sizer");
30.109 + // D is needed because behavior of elts with overflow: auto and padding is inconsistent across browsers
30.110 + d.heightForcer = elt("div", "\u00a0", null, "position: absolute; height: " + scrollerCutOff + "px");
30.111 + // Will contain the gutters, if any
30.112 + d.gutters = elt("div", null, "CodeMirror-gutters");
30.113 + d.lineGutter = null;
30.114 + // Helper element to properly size the gutter backgrounds
30.115 + var scrollerInner = elt("div", [d.sizer, d.heightForcer, d.gutters], null, "position: relative; min-height: 100%");
30.116 + // Provides scrolling
30.117 + d.scroller = elt("div", [scrollerInner], "CodeMirror-scroll");
30.118 + d.scroller.setAttribute("tabIndex", "-1");
30.119 + // The element in which the editor lives.
30.120 + d.wrapper = elt("div", [d.inputDiv, d.scrollbarH, d.scrollbarV,
30.121 + d.scrollbarFiller, d.scroller], "CodeMirror");
30.122 + // Work around IE7 z-index bug
30.123 + if (ie_lt8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0; }
30.124 + if (place.appendChild) place.appendChild(d.wrapper); else place(d.wrapper);
30.125 +
30.126 + // Needed to hide big blue blinking cursor on Mobile Safari
30.127 + if (ios) input.style.width = "0px";
30.128 + if (!webkit) d.scroller.draggable = true;
30.129 + // Needed to handle Tab key in KHTML
30.130 + if (khtml) { d.inputDiv.style.height = "1px"; d.inputDiv.style.position = "absolute"; }
30.131 + // Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
30.132 + else if (ie_lt8) d.scrollbarH.style.minWidth = d.scrollbarV.style.minWidth = "18px";
30.133 +
30.134 + // Current visible range (may be bigger than the view window).
30.135 + d.viewOffset = d.showingFrom = d.showingTo = d.lastSizeC = 0;
30.136 +
30.137 + // Used to only resize the line number gutter when necessary (when
30.138 + // the amount of lines crosses a boundary that makes its width change)
30.139 + d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null;
30.140 + // See readInput and resetInput
30.141 + d.prevInput = "";
30.142 + // Set to true when a non-horizontal-scrolling widget is added. As
30.143 + // an optimization, widget aligning is skipped when d is false.
30.144 + d.alignWidgets = false;
30.145 + // Flag that indicates whether we currently expect input to appear
30.146 + // (after some event like 'keypress' or 'input') and are polling
30.147 + // intensively.
30.148 + d.pollingFast = false;
30.149 + // Self-resetting timeout for the poller
30.150 + d.poll = new Delayed();
30.151 + // True when a drag from the editor is active
30.152 + d.draggingText = false;
30.153 +
30.154 + d.cachedCharWidth = d.cachedTextHeight = null;
30.155 + d.measureLineCache = [];
30.156 + d.measureLineCachePos = 0;
30.157 +
30.158 + // Tracks when resetInput has punted to just putting a short
30.159 + // string instead of the (large) selection.
30.160 + d.inaccurateSelection = false;
30.161 +
30.162 + // Used to adjust overwrite behaviour when a paste has been
30.163 + // detected
30.164 + d.pasteIncoming = false;
30.165 +
30.166 + return d;
30.167 + }
30.168 +
30.169 + // VIEW CONSTRUCTOR
30.170 +
30.171 + function makeView(doc) {
30.172 + var selPos = {line: 0, ch: 0};
30.173 + return {
30.174 + doc: doc,
30.175 + // frontier is the point up to which the content has been parsed,
30.176 + frontier: 0, highlight: new Delayed(),
30.177 + sel: {from: selPos, to: selPos, head: selPos, anchor: selPos, shift: false, extend: false},
30.178 + scrollTop: 0, scrollLeft: 0,
30.179 + overwrite: false, focused: false,
30.180 + // Tracks the maximum line length so that
30.181 + // the horizontal scrollbar can be kept
30.182 + // static when scrolling.
30.183 + maxLine: getLine(doc, 0),
30.184 + maxLineLength: 0,
30.185 + maxLineChanged: false,
30.186 + suppressEdits: false,
30.187 + goalColumn: null,
30.188 + cantEdit: false,
30.189 + keyMaps: []
30.190 + };
30.191 + }
30.192 +
30.193 + // STATE UPDATES
30.194 +
30.195 + // Used to get the editor into a consistent state again when options change.
30.196 +
30.197 + function loadMode(cm) {
30.198 + var doc = cm.view.doc;
30.199 + cm.view.mode = CodeMirror.getMode(cm.options, cm.options.mode);
30.200 + doc.iter(0, doc.size, function(line) { line.stateAfter = null; });
30.201 + cm.view.frontier = 0;
30.202 + startWorker(cm, 100);
30.203 + }
30.204 +
30.205 + function wrappingChanged(cm) {
30.206 + var doc = cm.view.doc, th = textHeight(cm.display);
30.207 + if (cm.options.lineWrapping) {
30.208 + cm.display.wrapper.className += " CodeMirror-wrap";
30.209 + var perLine = cm.display.scroller.clientWidth / charWidth(cm.display) - 3;
30.210 + doc.iter(0, doc.size, function(line) {
30.211 + if (line.height == 0) return;
30.212 + var guess = Math.ceil(line.text.length / perLine) || 1;
30.213 + if (guess != 1) updateLineHeight(line, guess * th);
30.214 + });
30.215 + cm.display.sizer.style.minWidth = "";
30.216 + } else {
30.217 + cm.display.wrapper.className = cm.display.wrapper.className.replace(" CodeMirror-wrap", "");
30.218 + computeMaxLength(cm.view);
30.219 + doc.iter(0, doc.size, function(line) {
30.220 + if (line.height != 0) updateLineHeight(line, th);
30.221 + });
30.222 + }
30.223 + regChange(cm, 0, doc.size);
30.224 + clearCaches(cm);
30.225 + setTimeout(function(){updateScrollbars(cm.display, cm.view.doc.height);}, 100);
30.226 + }
30.227 +
30.228 + function keyMapChanged(cm) {
30.229 + var style = keyMap[cm.options.keyMap].style;
30.230 + cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-keymap-\S+/g, "") +
30.231 + (style ? " cm-keymap-" + style : "");
30.232 + }
30.233 +
30.234 + function themeChanged(cm) {
30.235 + cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") +
30.236 + cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-");
30.237 + clearCaches(cm);
30.238 + }
30.239 +
30.240 + function guttersChanged(cm) {
30.241 + updateGutters(cm);
30.242 + updateDisplay(cm, true);
30.243 + }
30.244 +
30.245 + function updateGutters(cm) {
30.246 + var gutters = cm.display.gutters, specs = cm.options.gutters;
30.247 + removeChildren(gutters);
30.248 + for (var i = 0; i < specs.length; ++i) {
30.249 + var gutterClass = specs[i];
30.250 + var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + gutterClass));
30.251 + if (gutterClass == "CodeMirror-linenumbers") {
30.252 + cm.display.lineGutter = gElt;
30.253 + gElt.style.width = (cm.display.lineNumWidth || 1) + "px";
30.254 + }
30.255 + }
30.256 + gutters.style.display = i ? "" : "none";
30.257 + }
30.258 +
30.259 + function lineLength(doc, line) {
30.260 + if (line.height == 0) return 0;
30.261 + var len = line.text.length, merged, cur = line;
30.262 + while (merged = collapsedSpanAtStart(cur)) {
30.263 + var found = merged.find();
30.264 + cur = getLine(doc, found.from.line);
30.265 + len += found.from.ch - found.to.ch;
30.266 + }
30.267 + cur = line;
30.268 + while (merged = collapsedSpanAtEnd(cur)) {
30.269 + var found = merged.find();
30.270 + len -= cur.text.length - found.from.ch;
30.271 + cur = getLine(doc, found.to.line);
30.272 + len += cur.text.length - found.to.ch;
30.273 + }
30.274 + return len;
30.275 + }
30.276 +
30.277 + function computeMaxLength(view) {
30.278 + view.maxLine = getLine(view.doc, 0);
30.279 + view.maxLineLength = lineLength(view.doc, view.maxLine);
30.280 + view.maxLineChanged = true;
30.281 + view.doc.iter(1, view.doc.size, function(line) {
30.282 + var len = lineLength(view.doc, line);
30.283 + if (len > view.maxLineLength) {
30.284 + view.maxLineLength = len;
30.285 + view.maxLine = line;
30.286 + }
30.287 + });
30.288 + }
30.289 +
30.290 + // Make sure the gutters options contains the element
30.291 + // "CodeMirror-linenumbers" when the lineNumbers option is true.
30.292 + function setGuttersForLineNumbers(options) {
30.293 + var found = false;
30.294 + for (var i = 0; i < options.gutters.length; ++i) {
30.295 + if (options.gutters[i] == "CodeMirror-linenumbers") {
30.296 + if (options.lineNumbers) found = true;
30.297 + else options.gutters.splice(i--, 1);
30.298 + }
30.299 + }
30.300 + if (!found && options.lineNumbers)
30.301 + options.gutters.push("CodeMirror-linenumbers");
30.302 + }
30.303 +
30.304 + // SCROLLBARS
30.305 +
30.306 + // Re-synchronize the fake scrollbars with the actual size of the
30.307 + // content. Optionally force a scrollTop.
30.308 + function updateScrollbars(d /* display */, docHeight) {
30.309 + var totalHeight = docHeight + 2 * paddingTop(d);
30.310 + d.sizer.style.minHeight = d.heightForcer.style.top = totalHeight + "px";
30.311 + var scrollHeight = Math.max(totalHeight, d.scroller.scrollHeight);
30.312 + var needsH = d.scroller.scrollWidth > d.scroller.clientWidth;
30.313 + var needsV = scrollHeight > d.scroller.clientHeight;
30.314 + if (needsV) {
30.315 + d.scrollbarV.style.display = "block";
30.316 + d.scrollbarV.style.bottom = needsH ? scrollbarWidth(d.measure) + "px" : "0";
30.317 + d.scrollbarV.firstChild.style.height =
30.318 + (scrollHeight - d.scroller.clientHeight + d.scrollbarV.clientHeight) + "px";
30.319 + } else d.scrollbarV.style.display = "";
30.320 + if (needsH) {
30.321 + d.scrollbarH.style.display = "block";
30.322 + d.scrollbarH.style.right = needsV ? scrollbarWidth(d.measure) + "px" : "0";
30.323 + d.scrollbarH.firstChild.style.width =
30.324 + (d.scroller.scrollWidth - d.scroller.clientWidth + d.scrollbarH.clientWidth) + "px";
30.325 + } else d.scrollbarH.style.display = "";
30.326 + if (needsH && needsV) {
30.327 + d.scrollbarFiller.style.display = "block";
30.328 + d.scrollbarFiller.style.height = d.scrollbarFiller.style.width = scrollbarWidth(d.measure) + "px";
30.329 + } else d.scrollbarFiller.style.display = "";
30.330 +
30.331 + if (mac_geLion && scrollbarWidth(d.measure) === 0)
30.332 + d.scrollbarV.style.minWidth = d.scrollbarH.style.minHeight = mac_geMountainLion ? "18px" : "12px";
30.333 + }
30.334 +
30.335 + function visibleLines(display, doc, viewPort) {
30.336 + var top = display.scroller.scrollTop, height = display.wrapper.clientHeight;
30.337 + if (typeof viewPort == "number") top = viewPort;
30.338 + else if (viewPort) {top = viewPort.top; height = viewPort.bottom - viewPort.top;}
30.339 + top = Math.floor(top - paddingTop(display));
30.340 + var bottom = Math.ceil(top + height);
30.341 + return {from: lineAtHeight(doc, top), to: lineAtHeight(doc, bottom)};
30.342 + }
30.343 +
30.344 + // LINE NUMBERS
30.345 +
30.346 + function alignHorizontally(cm) {
30.347 + var display = cm.display;
30.348 + if (!display.alignWidgets && !display.gutters.firstChild) return;
30.349 + var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.view.scrollLeft;
30.350 + var gutterW = display.gutters.offsetWidth, l = comp + "px";
30.351 + for (var n = display.lineDiv.firstChild; n; n = n.nextSibling) if (n.alignable) {
30.352 + for (var i = 0, a = n.alignable; i < a.length; ++i) a[i].style.left = l;
30.353 + }
30.354 + display.gutters.style.left = (comp + gutterW) + "px";
30.355 + }
30.356 +
30.357 + function maybeUpdateLineNumberWidth(cm) {
30.358 + if (!cm.options.lineNumbers) return false;
30.359 + var doc = cm.view.doc, last = lineNumberFor(cm.options, doc.size - 1), display = cm.display;
30.360 + if (last.length != display.lineNumChars) {
30.361 + var test = display.measure.appendChild(elt("div", [elt("div", last)],
30.362 + "CodeMirror-linenumber CodeMirror-gutter-elt"));
30.363 + var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW;
30.364 + display.lineGutter.style.width = "";
30.365 + display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding);
30.366 + display.lineNumWidth = display.lineNumInnerWidth + padding;
30.367 + display.lineNumChars = display.lineNumInnerWidth ? last.length : -1;
30.368 + display.lineGutter.style.width = display.lineNumWidth + "px";
30.369 + return true;
30.370 + }
30.371 + return false;
30.372 + }
30.373 +
30.374 + function lineNumberFor(options, i) {
30.375 + return String(options.lineNumberFormatter(i + options.firstLineNumber));
30.376 + }
30.377 + function compensateForHScroll(display) {
30.378 + return display.scroller.getBoundingClientRect().left - display.sizer.getBoundingClientRect().left;
30.379 + }
30.380 +
30.381 + // DISPLAY DRAWING
30.382 +
30.383 + function updateDisplay(cm, changes, viewPort) {
30.384 + var oldFrom = cm.display.showingFrom, oldTo = cm.display.showingTo;
30.385 + var updated = updateDisplayInner(cm, changes, viewPort);
30.386 + if (updated) {
30.387 + signalLater(cm, cm, "update", cm);
30.388 + if (cm.display.showingFrom != oldFrom || cm.display.showingTo != oldTo)
30.389 + signalLater(cm, cm, "viewportChange", cm, cm.display.showingFrom, cm.display.showingTo);
30.390 + }
30.391 + updateSelection(cm);
30.392 + updateScrollbars(cm.display, cm.view.doc.height);
30.393 +
30.394 + return updated;
30.395 + }
30.396 +
30.397 + // Uses a set of changes plus the current scroll position to
30.398 + // determine which DOM updates have to be made, and makes the
30.399 + // updates.
30.400 + function updateDisplayInner(cm, changes, viewPort) {
30.401 + var display = cm.display, doc = cm.view.doc;
30.402 + if (!display.wrapper.clientWidth) {
30.403 + display.showingFrom = display.showingTo = display.viewOffset = 0;
30.404 + return;
30.405 + }
30.406 +
30.407 + // Compute the new visible window
30.408 + // If scrollTop is specified, use that to determine which lines
30.409 + // to render instead of the current scrollbar position.
30.410 + var visible = visibleLines(display, doc, viewPort);
30.411 + // Bail out if the visible area is already rendered and nothing changed.
30.412 + if (changes !== true && changes.length == 0 &&
30.413 + visible.from > display.showingFrom && visible.to < display.showingTo)
30.414 + return;
30.415 +
30.416 + if (changes && maybeUpdateLineNumberWidth(cm))
30.417 + changes = true;
30.418 + display.sizer.style.marginLeft = display.scrollbarH.style.left = display.gutters.offsetWidth + "px";
30.419 +
30.420 + // When merged lines are present, the line that needs to be
30.421 + // redrawn might not be the one that was changed.
30.422 + if (changes !== true && sawCollapsedSpans)
30.423 + for (var i = 0; i < changes.length; ++i) {
30.424 + var ch = changes[i], merged;
30.425 + while (merged = collapsedSpanAtStart(getLine(doc, ch.from))) {
30.426 + var from = merged.find().from.line;
30.427 + if (ch.diff) ch.diff -= ch.from - from;
30.428 + ch.from = from;
30.429 + }
30.430 + }
30.431 +
30.432 + // Used to determine which lines need their line numbers updated
30.433 + var positionsChangedFrom = changes === true ? 0 : Infinity;
30.434 + if (cm.options.lineNumbers && changes && changes !== true)
30.435 + for (var i = 0; i < changes.length; ++i)
30.436 + if (changes[i].diff) { positionsChangedFrom = changes[i].from; break; }
30.437 +
30.438 + var from = Math.max(visible.from - cm.options.viewportMargin, 0);
30.439 + var to = Math.min(doc.size, visible.to + cm.options.viewportMargin);
30.440 + if (display.showingFrom < from && from - display.showingFrom < 20) from = display.showingFrom;
30.441 + if (display.showingTo > to && display.showingTo - to < 20) to = Math.min(doc.size, display.showingTo);
30.442 + if (sawCollapsedSpans) {
30.443 + from = lineNo(visualLine(doc, getLine(doc, from)));
30.444 + while (to < doc.size && lineIsHidden(getLine(doc, to))) ++to;
30.445 + }
30.446 +
30.447 + // Create a range of theoretically intact lines, and punch holes
30.448 + // in that using the change info.
30.449 + var intact = changes === true ? [] :
30.450 + computeIntact([{from: display.showingFrom, to: display.showingTo}], changes);
30.451 + // Clip off the parts that won't be visible
30.452 + var intactLines = 0;
30.453 + for (var i = 0; i < intact.length; ++i) {
30.454 + var range = intact[i];
30.455 + if (range.from < from) range.from = from;
30.456 + if (range.to > to) range.to = to;
30.457 + if (range.from >= range.to) intact.splice(i--, 1);
30.458 + else intactLines += range.to - range.from;
30.459 + }
30.460 + if (intactLines == to - from && from == display.showingFrom && to == display.showingTo)
30.461 + return;
30.462 + intact.sort(function(a, b) {return a.from - b.from;});
30.463 +
30.464 + if (intactLines < (to - from) * .7) display.lineDiv.style.display = "none";
30.465 + patchDisplay(cm, from, to, intact, positionsChangedFrom);
30.466 + display.lineDiv.style.display = "";
30.467 +
30.468 + var different = from != display.showingFrom || to != display.showingTo ||
30.469 + display.lastSizeC != display.wrapper.clientHeight;
30.470 + // This is just a bogus formula that detects when the editor is
30.471 + // resized or the font size changes.
30.472 + if (different) display.lastSizeC = display.wrapper.clientHeight;
30.473 + display.showingFrom = from; display.showingTo = to;
30.474 + startWorker(cm, 100);
30.475 +
30.476 + var prevBottom = display.lineDiv.offsetTop;
30.477 + for (var node = display.lineDiv.firstChild, height; node; node = node.nextSibling) if (node.lineObj) {
30.478 + if (ie_lt8) {
30.479 + var bot = node.offsetTop + node.offsetHeight;
30.480 + height = bot - prevBottom;
30.481 + prevBottom = bot;
30.482 + } else {
30.483 + var box = node.getBoundingClientRect();
30.484 + height = box.bottom - box.top;
30.485 + }
30.486 + var diff = node.lineObj.height - height;
30.487 + if (height < 2) height = textHeight(display);
30.488 + if (diff > .001 || diff < -.001)
30.489 + updateLineHeight(node.lineObj, height);
30.490 + }
30.491 + display.viewOffset = heightAtLine(cm, getLine(doc, from));
30.492 + // Position the mover div to align with the current virtual scroll position
30.493 + display.mover.style.top = display.viewOffset + "px";
30.494 + return true;
30.495 + }
30.496 +
30.497 + function computeIntact(intact, changes) {
30.498 + for (var i = 0, l = changes.length || 0; i < l; ++i) {
30.499 + var change = changes[i], intact2 = [], diff = change.diff || 0;
30.500 + for (var j = 0, l2 = intact.length; j < l2; ++j) {
30.501 + var range = intact[j];
30.502 + if (change.to <= range.from && change.diff) {
30.503 + intact2.push({from: range.from + diff, to: range.to + diff});
30.504 + } else if (change.to <= range.from || change.from >= range.to) {
30.505 + intact2.push(range);
30.506 + } else {
30.507 + if (change.from > range.from)
30.508 + intact2.push({from: range.from, to: change.from});
30.509 + if (change.to < range.to)
30.510 + intact2.push({from: change.to + diff, to: range.to + diff});
30.511 + }
30.512 + }
30.513 + intact = intact2;
30.514 + }
30.515 + return intact;
30.516 + }
30.517 +
30.518 + function getDimensions(cm) {
30.519 + var d = cm.display, left = {}, width = {};
30.520 + for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) {
30.521 + left[cm.options.gutters[i]] = n.offsetLeft;
30.522 + width[cm.options.gutters[i]] = n.offsetWidth;
30.523 + }
30.524 + return {fixedPos: compensateForHScroll(d),
30.525 + gutterTotalWidth: d.gutters.offsetWidth,
30.526 + gutterLeft: left,
30.527 + gutterWidth: width,
30.528 + wrapperWidth: d.wrapper.clientWidth};
30.529 + }
30.530 +
30.531 + function patchDisplay(cm, from, to, intact, updateNumbersFrom) {
30.532 + var dims = getDimensions(cm);
30.533 + var display = cm.display, lineNumbers = cm.options.lineNumbers;
30.534 + // IE does bad things to nodes when .innerHTML = "" is used on a parent
30.535 + // we still need widgets and markers intact to add back to the new content later
30.536 + if (!intact.length && !ie && (!webkit || !cm.display.currentWheelTarget))
30.537 + removeChildren(display.lineDiv);
30.538 + var container = display.lineDiv, cur = container.firstChild;
30.539 +
30.540 + function rm(node) {
30.541 + var next = node.nextSibling;
30.542 + if (webkit && mac && cm.display.currentWheelTarget == node) {
30.543 + node.style.display = "none";
30.544 + node.lineObj = null;
30.545 + } else {
30.546 + container.removeChild(node);
30.547 + }
30.548 + return next;
30.549 + }
30.550 +
30.551 + var nextIntact = intact.shift(), lineNo = from;
30.552 + cm.view.doc.iter(from, to, function(line) {
30.553 + if (nextIntact && nextIntact.to == lineNo) nextIntact = intact.shift();
30.554 + if (lineIsHidden(line)) {
30.555 + if (line.height != 0) updateLineHeight(line, 0);
30.556 + } else if (nextIntact && nextIntact.from <= lineNo && nextIntact.to > lineNo) {
30.557 + // This line is intact. Skip to the actual node. Update its
30.558 + // line number if needed.
30.559 + while (cur.lineObj != line) cur = rm(cur);
30.560 + if (lineNumbers && updateNumbersFrom <= lineNo && cur.lineNumber)
30.561 + setTextContent(cur.lineNumber, lineNumberFor(cm.options, lineNo));
30.562 + cur = cur.nextSibling;
30.563 + } else {
30.564 + // This line needs to be generated.
30.565 + var lineNode = buildLineElement(cm, line, lineNo, dims);
30.566 + container.insertBefore(lineNode, cur);
30.567 + lineNode.lineObj = line;
30.568 + }
30.569 + ++lineNo;
30.570 + });
30.571 + while (cur) cur = rm(cur);
30.572 + }
30.573 +
30.574 + function buildLineElement(cm, line, lineNo, dims) {
30.575 + var lineElement = lineContent(cm, line);
30.576 + var markers = line.gutterMarkers, display = cm.display;
30.577 +
30.578 + if (!cm.options.lineNumbers && !markers && !line.bgClass && !line.wrapClass &&
30.579 + (!line.widgets || !line.widgets.length)) return lineElement;
30.580 +
30.581 + // Lines with gutter elements or a background class need
30.582 + // to be wrapped again, and have the extra elements added
30.583 + // to the wrapper div
30.584 +
30.585 + var wrap = elt("div", null, line.wrapClass, "position: relative");
30.586 + if (cm.options.lineNumbers || markers) {
30.587 + var gutterWrap = wrap.appendChild(elt("div", null, null, "position: absolute; left: " +
30.588 + dims.fixedPos + "px"));
30.589 + wrap.alignable = [gutterWrap];
30.590 + if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"]))
30.591 + wrap.lineNumber = gutterWrap.appendChild(
30.592 + elt("div", lineNumberFor(cm.options, lineNo),
30.593 + "CodeMirror-linenumber CodeMirror-gutter-elt",
30.594 + "left: " + dims.gutterLeft["CodeMirror-linenumbers"] + "px; width: "
30.595 + + display.lineNumInnerWidth + "px"));
30.596 + if (markers)
30.597 + for (var k = 0; k < cm.options.gutters.length; ++k) {
30.598 + var id = cm.options.gutters[k], found = markers.hasOwnProperty(id) && markers[id];
30.599 + if (found)
30.600 + gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt", "left: " +
30.601 + dims.gutterLeft[id] + "px; width: " + dims.gutterWidth[id] + "px"));
30.602 + }
30.603 + }
30.604 + // Kludge to make sure the styled element lies behind the selection (by z-index)
30.605 + if (line.bgClass)
30.606 + wrap.appendChild(elt("div", "\u00a0", line.bgClass + " CodeMirror-linebackground"));
30.607 + wrap.appendChild(lineElement);
30.608 + if (line.widgets)
30.609 + for (var i = 0, ws = line.widgets; i < ws.length; ++i) {
30.610 + var widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget");
30.611 + node.widget = widget;
30.612 + if (widget.noHScroll) {
30.613 + (wrap.alignable || (wrap.alignable = [])).push(node);
30.614 + var width = dims.wrapperWidth;
30.615 + node.style.left = dims.fixedPos + "px";
30.616 + if (!widget.coverGutter) {
30.617 + width -= dims.gutterTotalWidth;
30.618 + node.style.paddingLeft = dims.gutterTotalWidth + "px";
30.619 + }
30.620 + node.style.width = width + "px";
30.621 + }
30.622 + if (widget.coverGutter) {
30.623 + node.style.zIndex = 5;
30.624 + node.style.position = "relative";
30.625 + if (!widget.noHScroll) node.style.marginLeft = -dims.gutterTotalWidth + "px";
30.626 + }
30.627 + if (widget.above)
30.628 + wrap.insertBefore(node, cm.options.lineNumbers && line.height != 0 ? gutterWrap : lineElement);
30.629 + else
30.630 + wrap.appendChild(node);
30.631 + }
30.632 +
30.633 + if (ie_lt8) wrap.style.zIndex = 2;
30.634 + return wrap;
30.635 + }
30.636 +
30.637 + // SELECTION / CURSOR
30.638 +
30.639 + function updateSelection(cm) {
30.640 + var display = cm.display;
30.641 + var collapsed = posEq(cm.view.sel.from, cm.view.sel.to);
30.642 + if (collapsed || cm.options.showCursorWhenSelecting)
30.643 + updateSelectionCursor(cm);
30.644 + else
30.645 + display.cursor.style.display = display.otherCursor.style.display = "none";
30.646 + if (!collapsed)
30.647 + updateSelectionRange(cm);
30.648 + else
30.649 + display.selectionDiv.style.display = "none";
30.650 +
30.651 + // Move the hidden textarea near the cursor to prevent scrolling artifacts
30.652 + var headPos = cursorCoords(cm, cm.view.sel.head, "div");
30.653 + var wrapOff = display.wrapper.getBoundingClientRect(), lineOff = display.lineDiv.getBoundingClientRect();
30.654 + display.inputDiv.style.top = Math.max(0, Math.min(display.wrapper.clientHeight - 10,
30.655 + headPos.top + lineOff.top - wrapOff.top)) + "px";
30.656 + display.inputDiv.style.left = Math.max(0, Math.min(display.wrapper.clientWidth - 10,
30.657 + headPos.left + lineOff.left - wrapOff.left)) + "px";
30.658 + }
30.659 +
30.660 + // No selection, plain cursor
30.661 + function updateSelectionCursor(cm) {
30.662 + var display = cm.display, pos = cursorCoords(cm, cm.view.sel.head, "div");
30.663 + display.cursor.style.left = pos.left + "px";
30.664 + display.cursor.style.top = pos.top + "px";
30.665 + display.cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px";
30.666 + display.cursor.style.display = "";
30.667 +
30.668 + if (pos.other) {
30.669 + display.otherCursor.style.display = "";
30.670 + display.otherCursor.style.left = pos.other.left + "px";
30.671 + display.otherCursor.style.top = pos.other.top + "px";
30.672 + display.otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px";
30.673 + } else { display.otherCursor.style.display = "none"; }
30.674 + }
30.675 +
30.676 + // Highlight selection
30.677 + function updateSelectionRange(cm) {
30.678 + var display = cm.display, doc = cm.view.doc, sel = cm.view.sel;
30.679 + var fragment = document.createDocumentFragment();
30.680 + var clientWidth = display.lineSpace.offsetWidth, pl = paddingLeft(cm.display);
30.681 +
30.682 + function add(left, top, width, bottom) {
30.683 + if (top < 0) top = 0;
30.684 + fragment.appendChild(elt("div", null, "CodeMirror-selected", "position: absolute; left: " + left +
30.685 + "px; top: " + top + "px; width: " + (width == null ? clientWidth - left : width) +
30.686 + "px; height: " + (bottom - top) + "px"));
30.687 + }
30.688 +
30.689 + function drawForLine(line, fromArg, toArg, retTop) {
30.690 + var lineObj = getLine(doc, line);
30.691 + var lineLen = lineObj.text.length, rVal = retTop ? Infinity : -Infinity;
30.692 + function coords(ch) {
30.693 + return charCoords(cm, {line: line, ch: ch}, "div", lineObj);
30.694 + }
30.695 +
30.696 + iterateBidiSections(getOrder(lineObj), fromArg || 0, toArg == null ? lineLen : toArg, function(from, to, dir) {
30.697 + var leftPos = coords(dir == "rtl" ? to - 1 : from);
30.698 + var rightPos = coords(dir == "rtl" ? from : to - 1);
30.699 + var left = leftPos.left, right = rightPos.right;
30.700 + if (rightPos.top - leftPos.top > 3) { // Different lines, draw top part
30.701 + add(left, leftPos.top, null, leftPos.bottom);
30.702 + left = pl;
30.703 + if (leftPos.bottom < rightPos.top) add(left, leftPos.bottom, null, rightPos.top);
30.704 + }
30.705 + if (toArg == null && to == lineLen) right = clientWidth;
30.706 + if (fromArg == null && from == 0) left = pl;
30.707 + rVal = retTop ? Math.min(rightPos.top, rVal) : Math.max(rightPos.bottom, rVal);
30.708 + if (left < pl + 1) left = pl;
30.709 + add(left, rightPos.top, right - left, rightPos.bottom);
30.710 + });
30.711 + return rVal;
30.712 + }
30.713 +
30.714 + if (sel.from.line == sel.to.line) {
30.715 + drawForLine(sel.from.line, sel.from.ch, sel.to.ch);
30.716 + } else {
30.717 + var fromObj = getLine(doc, sel.from.line);
30.718 + var cur = fromObj, merged, path = [sel.from.line, sel.from.ch], singleLine;
30.719 + while (merged = collapsedSpanAtEnd(cur)) {
30.720 + var found = merged.find();
30.721 + path.push(found.from.ch, found.to.line, found.to.ch);
30.722 + if (found.to.line == sel.to.line) {
30.723 + path.push(sel.to.ch);
30.724 + singleLine = true;
30.725 + break;
30.726 + }
30.727 + cur = getLine(doc, found.to.line);
30.728 + }
30.729 +
30.730 + // This is a single, merged line
30.731 + if (singleLine) {
30.732 + for (var i = 0; i < path.length; i += 3)
30.733 + drawForLine(path[i], path[i+1], path[i+2]);
30.734 + } else {
30.735 + var middleTop, middleBot, toObj = getLine(doc, sel.to.line);
30.736 + if (sel.from.ch)
30.737 + // Draw the first line of selection.
30.738 + middleTop = drawForLine(sel.from.line, sel.from.ch, null, false);
30.739 + else
30.740 + // Simply include it in the middle block.
30.741 + middleTop = heightAtLine(cm, fromObj) - display.viewOffset;
30.742 +
30.743 + if (!sel.to.ch)
30.744 + middleBot = heightAtLine(cm, toObj) - display.viewOffset;
30.745 + else
30.746 + middleBot = drawForLine(sel.to.line, collapsedSpanAtStart(toObj) ? null : 0, sel.to.ch, true);
30.747 +
30.748 + if (middleTop < middleBot) add(pl, middleTop, null, middleBot);
30.749 + }
30.750 + }
30.751 +
30.752 + removeChildrenAndAdd(display.selectionDiv, fragment);
30.753 + display.selectionDiv.style.display = "";
30.754 + }
30.755 +
30.756 + // Cursor-blinking
30.757 + function restartBlink(cm) {
30.758 + var display = cm.display;
30.759 + clearInterval(display.blinker);
30.760 + var on = true;
30.761 + display.cursor.style.visibility = display.otherCursor.style.visibility = "";
30.762 + display.blinker = setInterval(function() {
30.763 + if (!display.cursor.offsetHeight) return;
30.764 + display.cursor.style.visibility = display.otherCursor.style.visibility = (on = !on) ? "" : "hidden";
30.765 + }, cm.options.cursorBlinkRate);
30.766 + }
30.767 +
30.768 + // HIGHLIGHT WORKER
30.769 +
30.770 + function startWorker(cm, time) {
30.771 + if (cm.view.frontier < cm.display.showingTo)
30.772 + cm.view.highlight.set(time, bind(highlightWorker, cm));
30.773 + }
30.774 +
30.775 + function highlightWorker(cm) {
30.776 + var view = cm.view, doc = view.doc;
30.777 + if (view.frontier >= cm.display.showingTo) return;
30.778 + var end = +new Date + cm.options.workTime;
30.779 + var state = copyState(view.mode, getStateBefore(cm, view.frontier));
30.780 + var changed = [], prevChange;
30.781 + doc.iter(view.frontier, Math.min(doc.size, cm.display.showingTo + 500), function(line) {
30.782 + if (view.frontier >= cm.display.showingFrom) { // Visible
30.783 + if (highlightLine(cm, line, state) && view.frontier >= cm.display.showingFrom) {
30.784 + if (prevChange && prevChange.end == view.frontier) prevChange.end++;
30.785 + else changed.push(prevChange = {start: view.frontier, end: view.frontier + 1});
30.786 + }
30.787 + line.stateAfter = copyState(view.mode, state);
30.788 + } else {
30.789 + processLine(cm, line, state);
30.790 + line.stateAfter = view.frontier % 5 == 0 ? copyState(view.mode, state) : null;
30.791 + }
30.792 + ++view.frontier;
30.793 + if (+new Date > end) {
30.794 + startWorker(cm, cm.options.workDelay);
30.795 + return true;
30.796 + }
30.797 + });
30.798 + if (changed.length)
30.799 + operation(cm, function() {
30.800 + for (var i = 0; i < changed.length; ++i)
30.801 + regChange(this, changed[i].start, changed[i].end);
30.802 + })();
30.803 + }
30.804 +
30.805 + // Finds the line to start with when starting a parse. Tries to
30.806 + // find a line with a stateAfter, so that it can start with a
30.807 + // valid state. If that fails, it returns the line with the
30.808 + // smallest indentation, which tends to need the least context to
30.809 + // parse correctly.
30.810 + function findStartLine(cm, n) {
30.811 + var minindent, minline, doc = cm.view.doc;
30.812 + for (var search = n, lim = n - 100; search > lim; --search) {
30.813 + if (search == 0) return 0;
30.814 + var line = getLine(doc, search-1);
30.815 + if (line.stateAfter) return search;
30.816 + var indented = countColumn(line.text, null, cm.options.tabSize);
30.817 + if (minline == null || minindent > indented) {
30.818 + minline = search - 1;
30.819 + minindent = indented;
30.820 + }
30.821 + }
30.822 + return minline;
30.823 + }
30.824 +
30.825 + function getStateBefore(cm, n) {
30.826 + var view = cm.view;
30.827 + var pos = findStartLine(cm, n), state = pos && getLine(view.doc, pos-1).stateAfter;
30.828 + if (!state) state = startState(view.mode);
30.829 + else state = copyState(view.mode, state);
30.830 + view.doc.iter(pos, n, function(line) {
30.831 + processLine(cm, line, state);
30.832 + var save = pos == n - 1 || pos % 5 == 0 || pos >= view.showingFrom && pos < view.showingTo;
30.833 + line.stateAfter = save ? copyState(view.mode, state) : null;
30.834 + ++pos;
30.835 + });
30.836 + return state;
30.837 + }
30.838 +
30.839 + // POSITION MEASUREMENT
30.840 +
30.841 + function paddingTop(display) {return display.lineSpace.offsetTop;}
30.842 + function paddingLeft(display) {
30.843 + var e = removeChildrenAndAdd(display.measure, elt("pre")).appendChild(elt("span", "x"));
30.844 + return e.offsetLeft;
30.845 + }
30.846 +
30.847 + function measureChar(cm, line, ch, data) {
30.848 + var data = data || measureLine(cm, line), dir = -1;
30.849 + for (var pos = ch;; pos += dir) {
30.850 + var r = data[pos];
30.851 + if (r) break;
30.852 + if (dir < 0 && pos == 0) dir = 1;
30.853 + }
30.854 + return {left: pos < ch ? r.right : r.left,
30.855 + right: pos > ch ? r.left : r.right,
30.856 + top: r.top, bottom: r.bottom};
30.857 + }
30.858 +
30.859 + function measureLine(cm, line) {
30.860 + // First look in the cache
30.861 + var display = cm.display, cache = cm.display.measureLineCache;
30.862 + for (var i = 0; i < cache.length; ++i) {
30.863 + var memo = cache[i];
30.864 + if (memo.text == line.text && memo.markedSpans == line.markedSpans &&
30.865 + display.scroller.clientWidth == memo.width)
30.866 + return memo.measure;
30.867 + }
30.868 +
30.869 + var measure = measureLineInner(cm, line);
30.870 + // Store result in the cache
30.871 + var memo = {text: line.text, width: display.scroller.clientWidth,
30.872 + markedSpans: line.markedSpans, measure: measure};
30.873 + if (cache.length == 16) cache[++display.measureLineCachePos % 16] = memo;
30.874 + else cache.push(memo);
30.875 + return measure;
30.876 + }
30.877 +
30.878 + function measureLineInner(cm, line) {
30.879 + var display = cm.display, measure = emptyArray(line.text.length);
30.880 + var pre = lineContent(cm, line, measure);
30.881 +
30.882 + // IE does not cache element positions of inline elements between
30.883 + // calls to getBoundingClientRect. This makes the loop below,
30.884 + // which gathers the positions of all the characters on the line,
30.885 + // do an amount of layout work quadratic to the number of
30.886 + // characters. When line wrapping is off, we try to improve things
30.887 + // by first subdividing the line into a bunch of inline blocks, so
30.888 + // that IE can reuse most of the layout information from caches
30.889 + // for those blocks. This does interfere with line wrapping, so it
30.890 + // doesn't work when wrapping is on, but in that case the
30.891 + // situation is slightly better, since IE does cache line-wrapping
30.892 + // information and only recomputes per-line.
30.893 + if (ie && !ie_lt8 && !cm.options.lineWrapping && pre.childNodes.length > 100) {
30.894 + var fragment = document.createDocumentFragment();
30.895 + var chunk = 10, n = pre.childNodes.length;
30.896 + for (var i = 0, chunks = Math.ceil(n / chunk); i < chunks; ++i) {
30.897 + var wrap = elt("div", null, null, "display: inline-block");
30.898 + for (var j = 0; j < chunk && n; ++j) {
30.899 + wrap.appendChild(pre.firstChild);
30.900 + --n;
30.901 + }
30.902 + fragment.appendChild(wrap);
30.903 + }
30.904 + pre.appendChild(fragment);
30.905 + }
30.906 +
30.907 + removeChildrenAndAdd(display.measure, pre);
30.908 +
30.909 + var outer = display.lineDiv.getBoundingClientRect();
30.910 + var vranges = [], data = emptyArray(line.text.length), maxBot = pre.offsetHeight;
30.911 + for (var i = 0, cur; i < measure.length; ++i) if (cur = measure[i]) {
30.912 + var size = cur.getBoundingClientRect();
30.913 + var top = Math.max(0, size.top - outer.top), bot = Math.min(size.bottom - outer.top, maxBot);
30.914 + for (var j = 0; j < vranges.length; j += 2) {
30.915 + var rtop = vranges[j], rbot = vranges[j+1];
30.916 + if (rtop > bot || rbot < top) continue;
30.917 + if (rtop <= top && rbot >= bot ||
30.918 + top <= rtop && bot >= rbot ||
30.919 + Math.min(bot, rbot) - Math.max(top, rtop) >= (bot - top) >> 1) {
30.920 + vranges[j] = Math.min(top, rtop);
30.921 + vranges[j+1] = Math.max(bot, rbot);
30.922 + break;
30.923 + }
30.924 + }
30.925 + if (j == vranges.length) vranges.push(top, bot);
30.926 + data[i] = {left: size.left - outer.left, right: size.right - outer.left, top: j};
30.927 + }
30.928 + for (var i = 0, cur; i < data.length; ++i) if (cur = data[i]) {
30.929 + var vr = cur.top;
30.930 + cur.top = vranges[vr]; cur.bottom = vranges[vr+1];
30.931 + }
30.932 + return data;
30.933 + }
30.934 +
30.935 + function clearCaches(cm) {
30.936 + cm.display.measureLineCache.length = cm.display.measureLineCachePos = 0;
30.937 + cm.display.cachedCharWidth = cm.display.cachedTextHeight = null;
30.938 + cm.view.maxLineChanged = true;
30.939 + }
30.940 +
30.941 + // Context is one of "line", "div" (display.lineDiv), "local"/null (editor), or "page"
30.942 + function intoCoordSystem(cm, lineObj, rect, context) {
30.943 + if (lineObj.widgets) for (var i = 0; i < lineObj.widgets.length; ++i) if (lineObj.widgets[i].above) {
30.944 + var size = lineObj.widgets[i].node.offsetHeight;
30.945 + rect.top += size; rect.bottom += size;
30.946 + }
30.947 + if (context == "line") return rect;
30.948 + if (!context) context = "local";
30.949 + var yOff = heightAtLine(cm, lineObj);
30.950 + if (context != "local") yOff -= cm.display.viewOffset;
30.951 + if (context == "page") {
30.952 + var lOff = cm.display.lineSpace.getBoundingClientRect();
30.953 + yOff += lOff.top + (window.pageYOffset || (document.documentElement || document.body).scrollTop);
30.954 + var xOff = lOff.left + (window.pageXOffset || (document.documentElement || document.body).scrollLeft);
30.955 + rect.left += xOff; rect.right += xOff;
30.956 + }
30.957 + rect.top += yOff; rect.bottom += yOff;
30.958 + return rect;
30.959 + }
30.960 +
30.961 + function charCoords(cm, pos, context, lineObj) {
30.962 + if (!lineObj) lineObj = getLine(cm.view.doc, pos.line);
30.963 + return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch), context);
30.964 + }
30.965 +
30.966 + function cursorCoords(cm, pos, context, lineObj, measurement) {
30.967 + lineObj = lineObj || getLine(cm.view.doc, pos.line);
30.968 + if (!measurement) measurement = measureLine(cm, lineObj);
30.969 + function get(ch, right) {
30.970 + var m = measureChar(cm, lineObj, ch, measurement);
30.971 + if (right) m.left = m.right; else m.right = m.left;
30.972 + return intoCoordSystem(cm, lineObj, m, context);
30.973 + }
30.974 + var order = getOrder(lineObj), ch = pos.ch;
30.975 + if (!order) return get(ch);
30.976 + var main, other, linedir = order[0].level;
30.977 + for (var i = 0; i < order.length; ++i) {
30.978 + var part = order[i], rtl = part.level % 2, nb, here;
30.979 + if (part.from < ch && part.to > ch) return get(ch, rtl);
30.980 + var left = rtl ? part.to : part.from, right = rtl ? part.from : part.to;
30.981 + if (left == ch) {
30.982 + // Opera and IE return bogus offsets and widths for edges
30.983 + // where the direction flips, but only for the side with the
30.984 + // lower level. So we try to use the side with the higher
30.985 + // level.
30.986 + if (i && part.level < (nb = order[i-1]).level) here = get(nb.level % 2 ? nb.from : nb.to - 1, true);
30.987 + else here = get(rtl && part.from != part.to ? ch - 1 : ch);
30.988 + if (rtl == linedir) main = here; else other = here;
30.989 + } else if (right == ch) {
30.990 + var nb = i < order.length - 1 && order[i+1];
30.991 + if (!rtl && nb && nb.from == nb.to) continue;
30.992 + if (nb && part.level < nb.level) here = get(nb.level % 2 ? nb.to - 1 : nb.from);
30.993 + else here = get(rtl ? ch : ch - 1, true);
30.994 + if (rtl == linedir) main = here; else other = here;
30.995 + }
30.996 + }
30.997 + if (linedir && !ch) other = get(order[0].to - 1);
30.998 + if (!main) return other;
30.999 + if (other) main.other = other;
30.1000 + return main;
30.1001 + }
30.1002 +
30.1003 + // Coords must be lineSpace-local
30.1004 + function coordsChar(cm, x, y) {
30.1005 + var doc = cm.view.doc;
30.1006 + y += cm.display.viewOffset;
30.1007 + if (y < 0) return {line: 0, ch: 0, outside: true};
30.1008 + var lineNo = lineAtHeight(doc, y);
30.1009 + if (lineNo >= doc.size) return {line: doc.size - 1, ch: getLine(doc, doc.size - 1).text.length};
30.1010 + if (x < 0) x = 0;
30.1011 +
30.1012 + for (;;) {
30.1013 + var lineObj = getLine(doc, lineNo);
30.1014 + var found = coordsCharInner(cm, lineObj, lineNo, x, y);
30.1015 + var merged = collapsedSpanAtEnd(lineObj);
30.1016 + if (merged && found.ch == lineRight(lineObj))
30.1017 + lineNo = merged.find().to.line;
30.1018 + else
30.1019 + return found;
30.1020 + }
30.1021 + }
30.1022 +
30.1023 + function coordsCharInner(cm, lineObj, lineNo, x, y) {
30.1024 + var innerOff = y - heightAtLine(cm, lineObj);
30.1025 + var wrongLine = false, cWidth = cm.display.wrapper.clientWidth;
30.1026 + var measurement = measureLine(cm, lineObj);
30.1027 +
30.1028 + function getX(ch) {
30.1029 + var sp = cursorCoords(cm, {line: lineNo, ch: ch}, "line",
30.1030 + lineObj, measurement);
30.1031 + wrongLine = true;
30.1032 + if (innerOff > sp.bottom) return Math.max(0, sp.left - cWidth);
30.1033 + else if (innerOff < sp.top) return sp.left + cWidth;
30.1034 + else wrongLine = false;
30.1035 + return sp.left;
30.1036 + }
30.1037 +
30.1038 + var bidi = getOrder(lineObj), dist = lineObj.text.length;
30.1039 + var from = lineLeft(lineObj), to = lineRight(lineObj);
30.1040 + var fromX = paddingLeft(cm.display), toX = getX(to);
30.1041 +
30.1042 + if (x > toX) return {line: lineNo, ch: to, outside: wrongLine};
30.1043 + // Do a binary search between these bounds.
30.1044 + for (;;) {
30.1045 + if (bidi ? to == from || to == moveVisually(lineObj, from, 1) : to - from <= 1) {
30.1046 + var after = x - fromX < toX - x, ch = after ? from : to;
30.1047 + while (isExtendingChar.test(lineObj.text.charAt(ch))) ++ch;
30.1048 + return {line: lineNo, ch: ch, after: after, outside: wrongLine};
30.1049 + }
30.1050 + var step = Math.ceil(dist / 2), middle = from + step;
30.1051 + if (bidi) {
30.1052 + middle = from;
30.1053 + for (var i = 0; i < step; ++i) middle = moveVisually(lineObj, middle, 1);
30.1054 + }
30.1055 + var middleX = getX(middle);
30.1056 + if (middleX > x) {to = middle; toX = middleX; if (wrongLine) toX += 1000; dist -= step;}
30.1057 + else {from = middle; fromX = middleX; dist = step;}
30.1058 + }
30.1059 + }
30.1060 +
30.1061 + var measureText;
30.1062 + function textHeight(display) {
30.1063 + if (display.cachedTextHeight != null) return display.cachedTextHeight;
30.1064 + if (measureText == null) {
30.1065 + measureText = elt("pre");
30.1066 + // Measure a bunch of lines, for browsers that compute
30.1067 + // fractional heights.
30.1068 + for (var i = 0; i < 49; ++i) {
30.1069 + measureText.appendChild(document.createTextNode("x"));
30.1070 + measureText.appendChild(elt("br"));
30.1071 + }
30.1072 + measureText.appendChild(document.createTextNode("x"));
30.1073 + }
30.1074 + removeChildrenAndAdd(display.measure, measureText);
30.1075 + var height = measureText.offsetHeight / 50;
30.1076 + if (height > 3) display.cachedTextHeight = height;
30.1077 + removeChildren(display.measure);
30.1078 + return height || 1;
30.1079 + }
30.1080 +
30.1081 + function charWidth(display) {
30.1082 + if (display.cachedCharWidth != null) return display.cachedCharWidth;
30.1083 + var anchor = elt("span", "x");
30.1084 + var pre = elt("pre", [anchor]);
30.1085 + removeChildrenAndAdd(display.measure, pre);
30.1086 + var width = anchor.offsetWidth;
30.1087 + if (width > 2) display.cachedCharWidth = width;
30.1088 + return width || 10;
30.1089 + }
30.1090 +
30.1091 + // OPERATIONS
30.1092 +
30.1093 + // Operations are used to wrap changes in such a way that each
30.1094 + // change won't have to update the cursor and display (which would
30.1095 + // be awkward, slow, and error-prone), but instead updates are
30.1096 + // batched and then all combined and executed at once.
30.1097 +
30.1098 + function startOperation(cm) {
30.1099 + if (cm.curOp) ++cm.curOp.depth;
30.1100 + else cm.curOp = {
30.1101 + // Nested operations delay update until the outermost one
30.1102 + // finishes.
30.1103 + depth: 1,
30.1104 + // An array of ranges of lines that have to be updated. See
30.1105 + // updateDisplay.
30.1106 + changes: [],
30.1107 + delayedCallbacks: [],
30.1108 + updateInput: null,
30.1109 + userSelChange: null,
30.1110 + textChanged: null,
30.1111 + selectionChanged: false,
30.1112 + updateMaxLine: false,
30.1113 + id: ++cm.nextOpId
30.1114 + };
30.1115 + }
30.1116 +
30.1117 + function endOperation(cm) {
30.1118 + var op = cm.curOp;
30.1119 + if (--op.depth) return;
30.1120 + cm.curOp = null;
30.1121 + var view = cm.view, display = cm.display;
30.1122 + if (op.updateMaxLine) computeMaxLength(view);
30.1123 + if (view.maxLineChanged && !cm.options.lineWrapping) {
30.1124 + var width = measureChar(cm, view.maxLine, view.maxLine.text.length).right;
30.1125 + display.sizer.style.minWidth = (width + 3 + scrollerCutOff) + "px";
30.1126 + view.maxLineChanged = false;
30.1127 + }
30.1128 + var newScrollPos, updated;
30.1129 + if (op.selectionChanged) {
30.1130 + var coords = cursorCoords(cm, view.sel.head);
30.1131 + newScrollPos = calculateScrollPos(cm, coords.left, coords.top, coords.left, coords.bottom);
30.1132 + }
30.1133 + if (op.changes.length || newScrollPos && newScrollPos.scrollTop != null)
30.1134 + updated = updateDisplay(cm, op.changes, newScrollPos && newScrollPos.scrollTop);
30.1135 + if (!updated && op.selectionChanged) updateSelection(cm);
30.1136 + if (newScrollPos) scrollCursorIntoView(cm);
30.1137 + if (op.selectionChanged) restartBlink(cm);
30.1138 +
30.1139 + if (view.focused && op.updateInput)
30.1140 + resetInput(cm, op.userSelChange);
30.1141 +
30.1142 + if (op.textChanged)
30.1143 + signal(cm, "change", cm, op.textChanged);
30.1144 + if (op.selectionChanged) signal(cm, "cursorActivity", cm);
30.1145 + for (var i = 0; i < op.delayedCallbacks.length; ++i) op.delayedCallbacks[i](cm);
30.1146 + }
30.1147 +
30.1148 + // Wraps a function in an operation. Returns the wrapped function.
30.1149 + function operation(cm1, f) {
30.1150 + return function() {
30.1151 + var cm = cm1 || this;
30.1152 + startOperation(cm);
30.1153 + try {var result = f.apply(cm, arguments);}
30.1154 + finally {endOperation(cm);}
30.1155 + return result;
30.1156 + };
30.1157 + }
30.1158 +
30.1159 + function regChange(cm, from, to, lendiff) {
30.1160 + cm.curOp.changes.push({from: from, to: to, diff: lendiff});
30.1161 + }
30.1162 +
30.1163 + // INPUT HANDLING
30.1164 +
30.1165 + function slowPoll(cm) {
30.1166 + if (cm.view.pollingFast) return;
30.1167 + cm.display.poll.set(cm.options.pollInterval, function() {
30.1168 + readInput(cm);
30.1169 + if (cm.view.focused) slowPoll(cm);
30.1170 + });
30.1171 + }
30.1172 +
30.1173 + function fastPoll(cm) {
30.1174 + var missed = false;
30.1175 + cm.display.pollingFast = true;
30.1176 + function p() {
30.1177 + var changed = readInput(cm);
30.1178 + if (!changed && !missed) {missed = true; cm.display.poll.set(60, p);}
30.1179 + else {cm.display.pollingFast = false; slowPoll(cm);}
30.1180 + }
30.1181 + cm.display.poll.set(20, p);
30.1182 + }
30.1183 +
30.1184 + // prevInput is a hack to work with IME. If we reset the textarea
30.1185 + // on every change, that breaks IME. So we look for changes
30.1186 + // compared to the previous content instead. (Modern browsers have
30.1187 + // events that indicate IME taking place, but these are not widely
30.1188 + // supported or compatible enough yet to rely on.)
30.1189 + function readInput(cm) {
30.1190 + var input = cm.display.input, prevInput = cm.display.prevInput, view = cm.view, sel = view.sel;
30.1191 + if (!view.focused || hasSelection(input) || isReadOnly(cm)) return false;
30.1192 + var text = input.value;
30.1193 + if (text == prevInput && posEq(sel.from, sel.to)) return false;
30.1194 + startOperation(cm);
30.1195 + view.sel.shift = false;
30.1196 + var same = 0, l = Math.min(prevInput.length, text.length);
30.1197 + while (same < l && prevInput[same] == text[same]) ++same;
30.1198 + var from = sel.from, to = sel.to;
30.1199 + if (same < prevInput.length)
30.1200 + from = {line: from.line, ch: from.ch - (prevInput.length - same)};
30.1201 + else if (view.overwrite && posEq(from, to) && !cm.display.pasteIncoming)
30.1202 + to = {line: to.line, ch: Math.min(getLine(cm.view.doc, to.line).text.length, to.ch + (text.length - same))};
30.1203 + var updateInput = cm.curOp.updateInput;
30.1204 + updateDoc(cm, from, to, splitLines(text.slice(same)), "end",
30.1205 + cm.display.pasteIncoming ? "paste" : "input", {from: from, to: to});
30.1206 + cm.curOp.updateInput = updateInput;
30.1207 + if (text.length > 1000) input.value = cm.display.prevInput = "";
30.1208 + else cm.display.prevInput = text;
30.1209 + endOperation(cm);
30.1210 + cm.display.pasteIncoming = false;
30.1211 + return true;
30.1212 + }
30.1213 +
30.1214 + function resetInput(cm, user) {
30.1215 + var view = cm.view, minimal, selected;
30.1216 + if (!posEq(view.sel.from, view.sel.to)) {
30.1217 + cm.display.prevInput = "";
30.1218 + minimal = hasCopyEvent &&
30.1219 + (view.sel.to.line - view.sel.from.line > 100 || (selected = cm.getSelection()).length > 1000);
30.1220 + if (minimal) cm.display.input.value = "-";
30.1221 + else cm.display.input.value = selected || cm.getSelection();
30.1222 + if (view.focused) selectInput(cm.display.input);
30.1223 + } else if (user) cm.display.prevInput = cm.display.input.value = "";
30.1224 + cm.display.inaccurateSelection = minimal;
30.1225 + }
30.1226 +
30.1227 + function focusInput(cm) {
30.1228 + if (cm.options.readOnly != "nocursor" && (ie || document.activeElement != cm.display.input))
30.1229 + cm.display.input.focus();
30.1230 + }
30.1231 +
30.1232 + function isReadOnly(cm) {
30.1233 + return cm.options.readOnly || cm.view.cantEdit;
30.1234 + }
30.1235 +
30.1236 + // EVENT HANDLERS
30.1237 +
30.1238 + function registerEventHandlers(cm) {
30.1239 + var d = cm.display;
30.1240 + on(d.scroller, "mousedown", operation(cm, onMouseDown));
30.1241 + on(d.scroller, "dblclick", operation(cm, e_preventDefault));
30.1242 + on(d.lineSpace, "selectstart", function(e) {
30.1243 + if (!mouseEventInWidget(d, e)) e_preventDefault(e);
30.1244 + });
30.1245 + // Gecko browsers fire contextmenu *after* opening the menu, at
30.1246 + // which point we can't mess with it anymore. Context menu is
30.1247 + // handled in onMouseDown for Gecko.
30.1248 + if (!gecko) on(d.scroller, "contextmenu", function(e) {onContextMenu(cm, e);});
30.1249 +
30.1250 + on(d.scroller, "scroll", function() {
30.1251 + setScrollTop(cm, d.scroller.scrollTop);
30.1252 + setScrollLeft(cm, d.scroller.scrollLeft, true);
30.1253 + signal(cm, "scroll", cm);
30.1254 + });
30.1255 + on(d.scrollbarV, "scroll", function() {
30.1256 + setScrollTop(cm, d.scrollbarV.scrollTop);
30.1257 + });
30.1258 + on(d.scrollbarH, "scroll", function() {
30.1259 + setScrollLeft(cm, d.scrollbarH.scrollLeft);
30.1260 + });
30.1261 +
30.1262 + on(d.scroller, "mousewheel", function(e){onScrollWheel(cm, e);});
30.1263 + on(d.scroller, "DOMMouseScroll", function(e){onScrollWheel(cm, e);});
30.1264 +
30.1265 + function reFocus() { if (cm.view.focused) setTimeout(bind(focusInput, cm), 0); }
30.1266 + on(d.scrollbarH, "mousedown", reFocus);
30.1267 + on(d.scrollbarV, "mousedown", reFocus);
30.1268 + // Prevent wrapper from ever scrolling
30.1269 + on(d.wrapper, "scroll", function() { d.wrapper.scrollTop = d.wrapper.scrollLeft = 0; });
30.1270 + on(window, "resize", function resizeHandler() {
30.1271 + // Might be a text scaling operation, clear size caches.
30.1272 + d.cachedCharWidth = d.cachedTextHeight = null;
30.1273 + clearCaches(cm);
30.1274 + if (d.wrapper.parentNode) updateDisplay(cm, true);
30.1275 + else off(window, "resize", resizeHandler);
30.1276 + });
30.1277 +
30.1278 + on(d.input, "keyup", operation(cm, function(e) {
30.1279 + if (cm.options.onKeyEvent && cm.options.onKeyEvent(cm, addStop(e))) return;
30.1280 + if (e_prop(e, "keyCode") == 16) cm.view.sel.shift = false;
30.1281 + }));
30.1282 + on(d.input, "input", bind(fastPoll, cm));
30.1283 + on(d.input, "keydown", operation(cm, onKeyDown));
30.1284 + on(d.input, "keypress", operation(cm, onKeyPress));
30.1285 + on(d.input, "focus", bind(onFocus, cm));
30.1286 + on(d.input, "blur", bind(onBlur, cm));
30.1287 +
30.1288 + function drag_(e) {
30.1289 + if (cm.options.onDragEvent && cm.options.onDragEvent(cm, addStop(e))) return;
30.1290 + e_stop(e);
30.1291 + }
30.1292 + if (cm.options.dragDrop) {
30.1293 + on(d.scroller, "dragstart", function(e){onDragStart(cm, e);});
30.1294 + on(d.scroller, "dragenter", drag_);
30.1295 + on(d.scroller, "dragover", drag_);
30.1296 + on(d.scroller, "drop", operation(cm, onDrop));
30.1297 + }
30.1298 + on(d.scroller, "paste", function(){focusInput(cm); fastPoll(cm);});
30.1299 + on(d.input, "paste", function() {
30.1300 + d.pasteIncoming = true;
30.1301 + fastPoll(cm);
30.1302 + });
30.1303 +
30.1304 + function prepareCopy() {
30.1305 + if (d.inaccurateSelection) {
30.1306 + d.prevInput = "";
30.1307 + d.inaccurateSelection = false;
30.1308 + d.input.value = cm.getSelection();
30.1309 + selectInput(d.input);
30.1310 + }
30.1311 + }
30.1312 + on(d.input, "cut", prepareCopy);
30.1313 + on(d.input, "copy", prepareCopy);
30.1314 +
30.1315 + // Needed to handle Tab key in KHTML
30.1316 + if (khtml) on(d.sizer, "mouseup", function() {
30.1317 + if (document.activeElement == d.input) d.input.blur();
30.1318 + focusInput(cm);
30.1319 + });
30.1320 + }
30.1321 +
30.1322 + function mouseEventInWidget(display, e) {
30.1323 + for (var n = e_target(e); n != display.wrapper; n = n.parentNode)
30.1324 + if (/\bCodeMirror-(?:line)?widget\b/.test(n.className) ||
30.1325 + n.parentNode == display.sizer && n != display.mover) return true;
30.1326 + }
30.1327 +
30.1328 + function posFromMouse(cm, e, liberal) {
30.1329 + var display = cm.display;
30.1330 + if (!liberal) {
30.1331 + var target = e_target(e);
30.1332 + if (target == display.scrollbarH || target == display.scrollbarH.firstChild ||
30.1333 + target == display.scrollbarV || target == display.scrollbarV.firstChild ||
30.1334 + target == display.scrollbarFiller) return null;
30.1335 + }
30.1336 + var x, y, space = display.lineSpace.getBoundingClientRect();
30.1337 + // Fails unpredictably on IE[67] when mouse is dragged around quickly.
30.1338 + try { x = e.clientX; y = e.clientY; } catch (e) { return null; }
30.1339 + return coordsChar(cm, x - space.left, y - space.top);
30.1340 + }
30.1341 +
30.1342 + var lastClick, lastDoubleClick;
30.1343 + function onMouseDown(e) {
30.1344 + var cm = this, display = cm.display, view = cm.view, sel = view.sel, doc = view.doc;
30.1345 + sel.shift = e_prop(e, "shiftKey");
30.1346 +
30.1347 + if (mouseEventInWidget(display, e)) {
30.1348 + if (!webkit) {
30.1349 + display.scroller.draggable = false;
30.1350 + setTimeout(function(){display.scroller.draggable = true;}, 100);
30.1351 + }
30.1352 + return;
30.1353 + }
30.1354 + if (clickInGutter(cm, e)) return;
30.1355 + var start = posFromMouse(cm, e);
30.1356 +
30.1357 + switch (e_button(e)) {
30.1358 + case 3:
30.1359 + if (gecko) onContextMenu.call(cm, cm, e);
30.1360 + return;
30.1361 + case 2:
30.1362 + if (start) extendSelection(cm, start);
30.1363 + setTimeout(bind(focusInput, cm), 20);
30.1364 + e_preventDefault(e);
30.1365 + return;
30.1366 + }
30.1367 + // For button 1, if it was clicked inside the editor
30.1368 + // (posFromMouse returning non-null), we have to adjust the
30.1369 + // selection.
30.1370 + if (!start) {if (e_target(e) == display.scroller) e_preventDefault(e); return;}
30.1371 +
30.1372 + if (!view.focused) onFocus(cm);
30.1373 +
30.1374 + var now = +new Date, type = "single";
30.1375 + if (lastDoubleClick && lastDoubleClick.time > now - 400 && posEq(lastDoubleClick.pos, start)) {
30.1376 + type = "triple";
30.1377 + e_preventDefault(e);
30.1378 + setTimeout(bind(focusInput, cm), 20);
30.1379 + selectLine(cm, start.line);
30.1380 + } else if (lastClick && lastClick.time > now - 400 && posEq(lastClick.pos, start)) {
30.1381 + type = "double";
30.1382 + lastDoubleClick = {time: now, pos: start};
30.1383 + e_preventDefault(e);
30.1384 + var word = findWordAt(getLine(doc, start.line).text, start);
30.1385 + extendSelection(cm, word.from, word.to);
30.1386 + } else { lastClick = {time: now, pos: start}; }
30.1387 +
30.1388 + var last = start;
30.1389 + if (cm.options.dragDrop && dragAndDrop && !isReadOnly(cm) && !posEq(sel.from, sel.to) &&
30.1390 + !posLess(start, sel.from) && !posLess(sel.to, start) && type == "single") {
30.1391 + var dragEnd = operation(cm, function(e2) {
30.1392 + if (webkit) display.scroller.draggable = false;
30.1393 + view.draggingText = false;
30.1394 + off(document, "mouseup", dragEnd);
30.1395 + off(display.scroller, "drop", dragEnd);
30.1396 + if (Math.abs(e.clientX - e2.clientX) + Math.abs(e.clientY - e2.clientY) < 10) {
30.1397 + e_preventDefault(e2);
30.1398 + extendSelection(cm, start);
30.1399 + focusInput(cm);
30.1400 + }
30.1401 + });
30.1402 + // Let the drag handler handle this.
30.1403 + if (webkit) display.scroller.draggable = true;
30.1404 + view.draggingText = dragEnd;
30.1405 + // IE's approach to draggable
30.1406 + if (display.scroller.dragDrop) display.scroller.dragDrop();
30.1407 + on(document, "mouseup", dragEnd);
30.1408 + on(display.scroller, "drop", dragEnd);
30.1409 + return;
30.1410 + }
30.1411 + e_preventDefault(e);
30.1412 + if (type == "single") extendSelection(cm, clipPos(doc, start));
30.1413 +
30.1414 + var startstart = sel.from, startend = sel.to;
30.1415 +
30.1416 + function doSelect(cur) {
30.1417 + if (type == "single") {
30.1418 + extendSelection(cm, clipPos(doc, start), cur);
30.1419 + return;
30.1420 + }
30.1421 +
30.1422 + startstart = clipPos(doc, startstart);
30.1423 + startend = clipPos(doc, startend);
30.1424 + if (type == "double") {
30.1425 + var word = findWordAt(getLine(doc, cur.line).text, cur);
30.1426 + if (posLess(cur, startstart)) extendSelection(cm, word.from, startend);
30.1427 + else extendSelection(cm, startstart, word.to);
30.1428 + } else if (type == "triple") {
30.1429 + if (posLess(cur, startstart)) extendSelection(cm, startend, clipPos(doc, {line: cur.line, ch: 0}));
30.1430 + else extendSelection(cm, startstart, clipPos(doc, {line: cur.line + 1, ch: 0}));
30.1431 + }
30.1432 + }
30.1433 +
30.1434 + var editorSize = display.wrapper.getBoundingClientRect();
30.1435 + // Used to ensure timeout re-tries don't fire when another extend
30.1436 + // happened in the meantime (clearTimeout isn't reliable -- at
30.1437 + // least on Chrome, the timeouts still happen even when cleared,
30.1438 + // if the clear happens after their scheduled firing time).
30.1439 + var counter = 0;
30.1440 +
30.1441 + function extend(e) {
30.1442 + var curCount = ++counter;
30.1443 + var cur = posFromMouse(cm, e, true);
30.1444 + if (!cur) return;
30.1445 + if (!posEq(cur, last)) {
30.1446 + if (!view.focused) onFocus(cm);
30.1447 + last = cur;
30.1448 + doSelect(cur);
30.1449 + var visible = visibleLines(display, doc);
30.1450 + if (cur.line >= visible.to || cur.line < visible.from)
30.1451 + setTimeout(operation(cm, function(){if (counter == curCount) extend(e);}), 150);
30.1452 + } else {
30.1453 + var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0;
30.1454 + if (outside) setTimeout(operation(cm, function() {
30.1455 + if (counter != curCount) return;
30.1456 + display.scroller.scrollTop += outside;
30.1457 + extend(e);
30.1458 + }), 50);
30.1459 + }
30.1460 + }
30.1461 +
30.1462 + function done(e) {
30.1463 + counter = Infinity;
30.1464 + var cur = posFromMouse(cm, e);
30.1465 + if (cur) doSelect(cur);
30.1466 + e_preventDefault(e);
30.1467 + focusInput(cm);
30.1468 + off(document, "mousemove", move);
30.1469 + off(document, "mouseup", up);
30.1470 + }
30.1471 +
30.1472 + var move = operation(cm, function(e) {
30.1473 + if (!ie && !e_button(e)) done(e);
30.1474 + else extend(e);
30.1475 + });
30.1476 + var up = operation(cm, done);
30.1477 + on(document, "mousemove", move);
30.1478 + on(document, "mouseup", up);
30.1479 + }
30.1480 +
30.1481 + function onDrop(e) {
30.1482 + var cm = this;
30.1483 + if (cm.options.onDragEvent && cm.options.onDragEvent(cm, addStop(e))) return;
30.1484 + e_preventDefault(e);
30.1485 + var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files;
30.1486 + if (!pos || isReadOnly(cm)) return;
30.1487 + if (files && files.length && window.FileReader && window.File) {
30.1488 + var n = files.length, text = Array(n), read = 0;
30.1489 + var loadFile = function(file, i) {
30.1490 + var reader = new FileReader;
30.1491 + reader.onload = function() {
30.1492 + text[i] = reader.result;
30.1493 + if (++read == n) {
30.1494 + pos = clipPos(cm.view.doc, pos);
30.1495 + operation(cm, function() {
30.1496 + var end = replaceRange(cm, text.join(""), pos, pos, "paste");
30.1497 + setSelection(cm, pos, end);
30.1498 + })();
30.1499 + }
30.1500 + };
30.1501 + reader.readAsText(file);
30.1502 + };
30.1503 + for (var i = 0; i < n; ++i) loadFile(files[i], i);
30.1504 + } else {
30.1505 + // Don't do a replace if the drop happened inside of the selected text.
30.1506 + if (cm.view.draggingText && !(posLess(pos, cm.view.sel.from) || posLess(cm.view.sel.to, pos))) {
30.1507 + cm.view.draggingText(e);
30.1508 + if (ie) setTimeout(bind(focusInput, cm), 50);
30.1509 + return;
30.1510 + }
30.1511 + try {
30.1512 + var text = e.dataTransfer.getData("Text");
30.1513 + if (text) {
30.1514 + var curFrom = cm.view.sel.from, curTo = cm.view.sel.to;
30.1515 + setSelection(cm, pos, pos);
30.1516 + if (cm.view.draggingText) replaceRange(cm, "", curFrom, curTo, "paste");
30.1517 + cm.replaceSelection(text, null, "paste");
30.1518 + focusInput(cm);
30.1519 + onFocus(cm);
30.1520 + }
30.1521 + }
30.1522 + catch(e){}
30.1523 + }
30.1524 + }
30.1525 +
30.1526 + function clickInGutter(cm, e) {
30.1527 + var display = cm.display;
30.1528 + try { var mX = e.clientX, mY = e.clientY; }
30.1529 + catch(e) { return false; }
30.1530 +
30.1531 + if (mX >= Math.floor(display.gutters.getBoundingClientRect().right)) return false;
30.1532 + e_preventDefault(e);
30.1533 + if (!hasHandler(cm, "gutterClick")) return true;
30.1534 +
30.1535 + var lineBox = display.lineDiv.getBoundingClientRect();
30.1536 + if (mY > lineBox.bottom) return true;
30.1537 + mY -= lineBox.top - display.viewOffset;
30.1538 +
30.1539 + for (var i = 0; i < cm.options.gutters.length; ++i) {
30.1540 + var g = display.gutters.childNodes[i];
30.1541 + if (g && g.getBoundingClientRect().right >= mX) {
30.1542 + var line = lineAtHeight(cm.view.doc, mY);
30.1543 + var gutter = cm.options.gutters[i];
30.1544 + signalLater(cm, cm, "gutterClick", cm, line, gutter, e);
30.1545 + break;
30.1546 + }
30.1547 + }
30.1548 + return true;
30.1549 + }
30.1550 +
30.1551 + function onDragStart(cm, e) {
30.1552 + var txt = cm.getSelection();
30.1553 + e.dataTransfer.setData("Text", txt);
30.1554 +
30.1555 + // Use dummy image instead of default browsers image.
30.1556 + // Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there.
30.1557 + if (e.dataTransfer.setDragImage && !safari)
30.1558 + e.dataTransfer.setDragImage(elt('img'), 0, 0);
30.1559 + }
30.1560 +
30.1561 + function setScrollTop(cm, val) {
30.1562 + if (Math.abs(cm.view.scrollTop - val) < 2) return;
30.1563 + cm.view.scrollTop = val;
30.1564 + if (!gecko) updateDisplay(cm, [], val);
30.1565 + if (cm.display.scroller.scrollTop != val) cm.display.scroller.scrollTop = val;
30.1566 + if (cm.display.scrollbarV.scrollTop != val) cm.display.scrollbarV.scrollTop = val;
30.1567 + if (gecko) updateDisplay(cm, []);
30.1568 + }
30.1569 + function setScrollLeft(cm, val, isScroller) {
30.1570 + if (isScroller ? val == cm.view.scrollLeft : Math.abs(cm.view.scrollLeft - val) < 2) return;
30.1571 + cm.view.scrollLeft = val;
30.1572 + alignHorizontally(cm);
30.1573 + if (cm.display.scroller.scrollLeft != val) cm.display.scroller.scrollLeft = val;
30.1574 + if (cm.display.scrollbarH.scrollLeft != val) cm.display.scrollbarH.scrollLeft = val;
30.1575 + }
30.1576 +
30.1577 + // Since the delta values reported on mouse wheel events are
30.1578 + // unstandardized between browsers and even browser versions, and
30.1579 + // generally horribly unpredictable, this code starts by measuring
30.1580 + // the scroll effect that the first few mouse wheel events have,
30.1581 + // and, from that, detects the way it can convert deltas to pixel
30.1582 + // offsets afterwards.
30.1583 + //
30.1584 + // The reason we want to know the amount a wheel event will scroll
30.1585 + // is that it gives us a chance to update the display before the
30.1586 + // actual scrolling happens, reducing flickering.
30.1587 +
30.1588 + var wheelSamples = 0, wheelDX, wheelDY, wheelStartX, wheelStartY, wheelPixelsPerUnit = null;
30.1589 + // Fill in a browser-detected starting value on browsers where we
30.1590 + // know one. These don't have to be accurate -- the result of them
30.1591 + // being wrong would just be a slight flicker on the first wheel
30.1592 + // scroll (if it is large enough).
30.1593 + if (ie) wheelPixelsPerUnit = -.53;
30.1594 + else if (gecko) wheelPixelsPerUnit = 15;
30.1595 + else if (chrome) wheelPixelsPerUnit = -.7;
30.1596 + else if (safari) wheelPixelsPerUnit = -1/3;
30.1597 +
30.1598 + function onScrollWheel(cm, e) {
30.1599 + var dx = e.wheelDeltaX, dy = e.wheelDeltaY;
30.1600 + if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) dx = e.detail;
30.1601 + if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) dy = e.detail;
30.1602 + else if (dy == null) dy = e.wheelDelta;
30.1603 +
30.1604 + // Webkit browsers on OS X abort momentum scrolls when the target
30.1605 + // of the scroll event is removed from the scrollable element.
30.1606 + // This hack (see related code in patchDisplay) makes sure the
30.1607 + // element is kept around.
30.1608 + if (dy && mac && webkit) {
30.1609 + for (var cur = e.target; cur != scroll; cur = cur.parentNode) {
30.1610 + if (cur.lineObj) {
30.1611 + cm.display.currentWheelTarget = cur;
30.1612 + break;
30.1613 + }
30.1614 + }
30.1615 + }
30.1616 +
30.1617 + var scroll = cm.display.scroller;
30.1618 + // On some browsers, horizontal scrolling will cause redraws to
30.1619 + // happen before the gutter has been realigned, causing it to
30.1620 + // wriggle around in a most unseemly way. When we have an
30.1621 + // estimated pixels/delta value, we just handle horizontal
30.1622 + // scrolling entirely here. It'll be slightly off from native, but
30.1623 + // better than glitching out.
30.1624 + if (dx && !gecko && !opera && wheelPixelsPerUnit != null) {
30.1625 + if (dy)
30.1626 + setScrollTop(cm, Math.max(0, Math.min(scroll.scrollTop + dy * wheelPixelsPerUnit, scroll.scrollHeight - scroll.clientHeight)));
30.1627 + setScrollLeft(cm, Math.max(0, Math.min(scroll.scrollLeft + dx * wheelPixelsPerUnit, scroll.scrollWidth - scroll.clientWidth)));
30.1628 + e_preventDefault(e);
30.1629 + wheelStartX = null; // Abort measurement, if in progress
30.1630 + return;
30.1631 + }
30.1632 +
30.1633 + if (dy && wheelPixelsPerUnit != null) {
30.1634 + var pixels = dy * wheelPixelsPerUnit;
30.1635 + var top = cm.view.scrollTop, bot = top + cm.display.wrapper.clientHeight;
30.1636 + if (pixels < 0) top = Math.max(0, top + pixels - 50);
30.1637 + else bot = Math.min(cm.view.doc.height, bot + pixels + 50);
30.1638 + updateDisplay(cm, [], {top: top, bottom: bot});
30.1639 + }
30.1640 +
30.1641 + if (wheelSamples < 20) {
30.1642 + if (wheelStartX == null) {
30.1643 + wheelStartX = scroll.scrollLeft; wheelStartY = scroll.scrollTop;
30.1644 + wheelDX = dx; wheelDY = dy;
30.1645 + setTimeout(function() {
30.1646 + if (wheelStartX == null) return;
30.1647 + var movedX = scroll.scrollLeft - wheelStartX;
30.1648 + var movedY = scroll.scrollTop - wheelStartY;
30.1649 + var sample = (movedY && wheelDY && movedY / wheelDY) ||
30.1650 + (movedX && wheelDX && movedX / wheelDX);
30.1651 + wheelStartX = wheelStartY = null;
30.1652 + if (!sample) return;
30.1653 + wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1);
30.1654 + ++wheelSamples;
30.1655 + }, 200);
30.1656 + } else {
30.1657 + wheelDX += dx; wheelDY += dy;
30.1658 + }
30.1659 + }
30.1660 + }
30.1661 +
30.1662 + function doHandleBinding(cm, bound, dropShift) {
30.1663 + if (typeof bound == "string") {
30.1664 + bound = commands[bound];
30.1665 + if (!bound) return false;
30.1666 + }
30.1667 + // Ensure previous input has been read, so that the handler sees a
30.1668 + // consistent view of the document
30.1669 + if (cm.display.pollingFast && readInput(cm)) cm.display.pollingFast = false;
30.1670 + var view = cm.view, prevShift = view.sel.shift;
30.1671 + try {
30.1672 + if (isReadOnly(cm)) view.suppressEdits = true;
30.1673 + if (dropShift) view.sel.shift = false;
30.1674 + bound(cm);
30.1675 + } catch(e) {
30.1676 + if (e != Pass) throw e;
30.1677 + return false;
30.1678 + } finally {
30.1679 + view.sel.shift = prevShift;
30.1680 + view.suppressEdits = false;
30.1681 + }
30.1682 + return true;
30.1683 + }
30.1684 +
30.1685 + function allKeyMaps(cm) {
30.1686 + var maps = cm.view.keyMaps.slice(0);
30.1687 + maps.push(cm.options.keyMap);
30.1688 + if (cm.options.extraKeys) maps.unshift(cm.options.extraKeys);
30.1689 + return maps;
30.1690 + }
30.1691 +
30.1692 + var maybeTransition;
30.1693 + function handleKeyBinding(cm, e) {
30.1694 + // Handle auto keymap transitions
30.1695 + var startMap = getKeyMap(cm.options.keyMap), next = startMap.auto;
30.1696 + clearTimeout(maybeTransition);
30.1697 + if (next && !isModifierKey(e)) maybeTransition = setTimeout(function() {
30.1698 + if (getKeyMap(cm.options.keyMap) == startMap)
30.1699 + cm.options.keyMap = (next.call ? next.call(null, cm) : next);
30.1700 + }, 50);
30.1701 +
30.1702 + var name = keyNames[e_prop(e, "keyCode")], handled = false;
30.1703 + var flipCtrlCmd = mac && (opera || qtwebkit);
30.1704 + if (name == null || e.altGraphKey) return false;
30.1705 + if (e_prop(e, "altKey")) name = "Alt-" + name;
30.1706 + if (e_prop(e, flipCtrlCmd ? "metaKey" : "ctrlKey")) name = "Ctrl-" + name;
30.1707 + if (e_prop(e, flipCtrlCmd ? "ctrlKey" : "metaKey")) name = "Cmd-" + name;
30.1708 +
30.1709 + var stopped = false;
30.1710 + function stop() { stopped = true; }
30.1711 + var keymaps = allKeyMaps(cm);
30.1712 +
30.1713 + if (e_prop(e, "shiftKey")) {
30.1714 + handled = lookupKey("Shift-" + name, keymaps,
30.1715 + function(b) {return doHandleBinding(cm, b, true);}, stop)
30.1716 + || lookupKey(name, keymaps, function(b) {
30.1717 + if (typeof b == "string" && /^go[A-Z]/.test(b)) return doHandleBinding(cm, b);
30.1718 + }, stop);
30.1719 + } else {
30.1720 + handled = lookupKey(name, keymaps,
30.1721 + function(b) { return doHandleBinding(cm, b); }, stop);
30.1722 + }
30.1723 + if (stopped) handled = false;
30.1724 + if (handled) {
30.1725 + e_preventDefault(e);
30.1726 + restartBlink(cm);
30.1727 + if (ie_lt9) { e.oldKeyCode = e.keyCode; e.keyCode = 0; }
30.1728 + }
30.1729 + return handled;
30.1730 + }
30.1731 +
30.1732 + function handleCharBinding(cm, e, ch) {
30.1733 + var handled = lookupKey("'" + ch + "'", allKeyMaps(cm),
30.1734 + function(b) { return doHandleBinding(cm, b, true); });
30.1735 + if (handled) {
30.1736 + e_preventDefault(e);
30.1737 + restartBlink(cm);
30.1738 + }
30.1739 + return handled;
30.1740 + }
30.1741 +
30.1742 + var lastStoppedKey = null;
30.1743 + function onKeyDown(e) {
30.1744 + var cm = this;
30.1745 + if (!cm.view.focused) onFocus(cm);
30.1746 + if (ie && e.keyCode == 27) { e.returnValue = false; }
30.1747 + if (cm.options.onKeyEvent && cm.options.onKeyEvent(cm, addStop(e))) return;
30.1748 + var code = e_prop(e, "keyCode");
30.1749 + // IE does strange things with escape.
30.1750 + cm.view.sel.shift = code == 16 || e_prop(e, "shiftKey");
30.1751 + // First give onKeyEvent option a chance to handle this.
30.1752 + var handled = handleKeyBinding(cm, e);
30.1753 + if (opera) {
30.1754 + lastStoppedKey = handled ? code : null;
30.1755 + // Opera has no cut event... we try to at least catch the key combo
30.1756 + if (!handled && code == 88 && !hasCopyEvent && e_prop(e, mac ? "metaKey" : "ctrlKey"))
30.1757 + cm.replaceSelection("");
30.1758 + }
30.1759 + }
30.1760 +
30.1761 + function onKeyPress(e) {
30.1762 + var cm = this;
30.1763 + if (cm.options.onKeyEvent && cm.options.onKeyEvent(cm, addStop(e))) return;
30.1764 + var keyCode = e_prop(e, "keyCode"), charCode = e_prop(e, "charCode");
30.1765 + if (opera && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return;}
30.1766 + if (((opera && (!e.which || e.which < 10)) || khtml) && handleKeyBinding(cm, e)) return;
30.1767 + var ch = String.fromCharCode(charCode == null ? keyCode : charCode);
30.1768 + if (this.options.electricChars && this.view.mode.electricChars &&
30.1769 + this.options.smartIndent && !isReadOnly(this) &&
30.1770 + this.view.mode.electricChars.indexOf(ch) > -1)
30.1771 + setTimeout(operation(cm, function() {indentLine(cm, cm.view.sel.to.line, "smart");}), 75);
30.1772 + if (handleCharBinding(cm, e, ch)) return;
30.1773 + fastPoll(cm);
30.1774 + }
30.1775 +
30.1776 + function onFocus(cm) {
30.1777 + if (cm.options.readOnly == "nocursor") return;
30.1778 + if (!cm.view.focused) {
30.1779 + signal(cm, "focus", cm);
30.1780 + cm.view.focused = true;
30.1781 + if (cm.display.scroller.className.search(/\bCodeMirror-focused\b/) == -1)
30.1782 + cm.display.scroller.className += " CodeMirror-focused";
30.1783 + resetInput(cm, true);
30.1784 + }
30.1785 + slowPoll(cm);
30.1786 + restartBlink(cm);
30.1787 + }
30.1788 + function onBlur(cm) {
30.1789 + if (cm.view.focused) {
30.1790 + signal(cm, "blur", cm);
30.1791 + cm.view.focused = false;
30.1792 + cm.display.scroller.className = cm.display.scroller.className.replace(" CodeMirror-focused", "");
30.1793 + }
30.1794 + clearInterval(cm.display.blinker);
30.1795 + setTimeout(function() {if (!cm.view.focused) cm.view.sel.shift = false;}, 150);
30.1796 + }
30.1797 +
30.1798 + var detectingSelectAll;
30.1799 + function onContextMenu(cm, e) {
30.1800 + var display = cm.display, sel = cm.view.sel;
30.1801 + var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop;
30.1802 + if (!pos || opera) return; // Opera is difficult.
30.1803 + if (posEq(sel.from, sel.to) || posLess(pos, sel.from) || !posLess(pos, sel.to))
30.1804 + operation(cm, setSelection)(cm, pos, pos);
30.1805 +
30.1806 + var oldCSS = display.input.style.cssText;
30.1807 + display.inputDiv.style.position = "absolute";
30.1808 + display.input.style.cssText = "position: fixed; width: 30px; height: 30px; top: " + (e.clientY - 5) +
30.1809 + "px; left: " + (e.clientX - 5) + "px; z-index: 1000; background: white; outline: none;" +
30.1810 + "border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);";
30.1811 + focusInput(cm);
30.1812 + resetInput(cm, true);
30.1813 + // Adds "Select all" to context menu in FF
30.1814 + if (posEq(sel.from, sel.to)) display.input.value = display.prevInput = " ";
30.1815 +
30.1816 + function rehide() {
30.1817 + display.inputDiv.style.position = "relative";
30.1818 + display.input.style.cssText = oldCSS;
30.1819 + if (ie_lt9) display.scrollbarV.scrollTop = display.scroller.scrollTop = scrollPos;
30.1820 + slowPoll(cm);
30.1821 +
30.1822 + // Try to detect the user choosing select-all
30.1823 + if (display.input.selectionStart != null) {
30.1824 + clearTimeout(detectingSelectAll);
30.1825 + var extval = display.input.value = " " + (posEq(sel.from, sel.to) ? "" : display.input.value), i = 0;
30.1826 + display.prevInput = " ";
30.1827 + display.input.selectionStart = 1; display.input.selectionEnd = extval.length;
30.1828 + detectingSelectAll = setTimeout(function poll(){
30.1829 + if (display.prevInput == " " && display.input.selectionStart == 0)
30.1830 + operation(cm, commands.selectAll)(cm);
30.1831 + else if (i++ < 10) detectingSelectAll = setTimeout(poll, 500);
30.1832 + else resetInput(cm);
30.1833 + }, 200);
30.1834 + }
30.1835 + }
30.1836 +
30.1837 + if (gecko) {
30.1838 + e_stop(e);
30.1839 + on(window, "mouseup", function mouseup() {
30.1840 + off(window, "mouseup", mouseup);
30.1841 + setTimeout(rehide, 20);
30.1842 + });
30.1843 + } else {
30.1844 + setTimeout(rehide, 50);
30.1845 + }
30.1846 + }
30.1847 +
30.1848 + // UPDATING
30.1849 +
30.1850 + // Replace the range from from to to by the strings in newText.
30.1851 + // Afterwards, set the selection to selFrom, selTo.
30.1852 + function updateDoc(cm, from, to, newText, selUpdate, origin) {
30.1853 + // Possibly split or suppress the update based on the presence
30.1854 + // of read-only spans in its range.
30.1855 + var split = sawReadOnlySpans &&
30.1856 + removeReadOnlyRanges(cm.view.doc, from, to);
30.1857 + if (split) {
30.1858 + for (var i = split.length - 1; i >= 1; --i)
30.1859 + updateDocInner(cm, split[i].from, split[i].to, [""], origin);
30.1860 + if (split.length)
30.1861 + return updateDocInner(cm, split[0].from, split[0].to, newText, selUpdate, origin);
30.1862 + } else {
30.1863 + return updateDocInner(cm, from, to, newText, selUpdate, origin);
30.1864 + }
30.1865 + }
30.1866 +
30.1867 + function updateDocInner(cm, from, to, newText, selUpdate, origin) {
30.1868 + if (cm.view.suppressEdits) return;
30.1869 +
30.1870 + var view = cm.view, doc = view.doc, old = [];
30.1871 + doc.iter(from.line, to.line + 1, function(line) {
30.1872 + old.push(newHL(line.text, line.markedSpans));
30.1873 + });
30.1874 + var startSelFrom = view.sel.from, startSelTo = view.sel.to;
30.1875 + var lines = updateMarkedSpans(hlSpans(old[0]), hlSpans(lst(old)), from.ch, to.ch, newText);
30.1876 + var retval = updateDocNoUndo(cm, from, to, lines, selUpdate, origin);
30.1877 + if (view.history) addChange(cm, from.line, newText.length, old, origin,
30.1878 + startSelFrom, startSelTo, view.sel.from, view.sel.to);
30.1879 + return retval;
30.1880 + }
30.1881 +
30.1882 + function unredoHelper(cm, type) {
30.1883 + var doc = cm.view.doc, hist = cm.view.history;
30.1884 + var set = (type == "undo" ? hist.done : hist.undone).pop();
30.1885 + if (!set) return;
30.1886 + var anti = {events: [], fromBefore: set.fromAfter, toBefore: set.toAfter,
30.1887 + fromAfter: set.fromBefore, toAfter: set.toBefore};
30.1888 + for (var i = set.events.length - 1; i >= 0; i -= 1) {
30.1889 + hist.dirtyCounter += type == "undo" ? -1 : 1;
30.1890 + var change = set.events[i];
30.1891 + var replaced = [], end = change.start + change.added;
30.1892 + doc.iter(change.start, end, function(line) { replaced.push(newHL(line.text, line.markedSpans)); });
30.1893 + anti.events.push({start: change.start, added: change.old.length, old: replaced});
30.1894 + var selPos = i ? null : {from: set.fromBefore, to: set.toBefore};
30.1895 + updateDocNoUndo(cm, {line: change.start, ch: 0}, {line: end - 1, ch: getLine(doc, end-1).text.length},
30.1896 + change.old, selPos, type);
30.1897 + }
30.1898 + (type == "undo" ? hist.undone : hist.done).push(anti);
30.1899 + }
30.1900 +
30.1901 + function updateDocNoUndo(cm, from, to, lines, selUpdate, origin) {
30.1902 + var view = cm.view, doc = view.doc, display = cm.display;
30.1903 + if (view.suppressEdits) return;
30.1904 +
30.1905 + var nlines = to.line - from.line, firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line);
30.1906 + var recomputeMaxLength = false, checkWidthStart = from.line;
30.1907 + if (!cm.options.lineWrapping) {
30.1908 + checkWidthStart = lineNo(visualLine(doc, firstLine));
30.1909 + doc.iter(checkWidthStart, to.line + 1, function(line) {
30.1910 + if (lineLength(doc, line) == view.maxLineLength) {
30.1911 + recomputeMaxLength = true;
30.1912 + return true;
30.1913 + }
30.1914 + });
30.1915 + }
30.1916 +
30.1917 + var lastHL = lst(lines), th = textHeight(display);
30.1918 +
30.1919 + // First adjust the line structure
30.1920 + if (from.ch == 0 && to.ch == 0 && hlText(lastHL) == "") {
30.1921 + // This is a whole-line replace. Treated specially to make
30.1922 + // sure line objects move the way they are supposed to.
30.1923 + var added = [];
30.1924 + for (var i = 0, e = lines.length - 1; i < e; ++i)
30.1925 + added.push(makeLine(hlText(lines[i]), hlSpans(lines[i]), th));
30.1926 + updateLine(cm, lastLine, lastLine.text, hlSpans(lastHL));
30.1927 + if (nlines) doc.remove(from.line, nlines, cm);
30.1928 + if (added.length) doc.insert(from.line, added);
30.1929 + } else if (firstLine == lastLine) {
30.1930 + if (lines.length == 1) {
30.1931 + updateLine(cm, firstLine, firstLine.text.slice(0, from.ch) + hlText(lines[0]) +
30.1932 + firstLine.text.slice(to.ch), hlSpans(lines[0]));
30.1933 + } else {
30.1934 + for (var added = [], i = 1, e = lines.length - 1; i < e; ++i)
30.1935 + added.push(makeLine(hlText(lines[i]), hlSpans(lines[i]), th));
30.1936 + added.push(makeLine(hlText(lastHL) + firstLine.text.slice(to.ch), hlSpans(lastHL), th));
30.1937 + updateLine(cm, firstLine, firstLine.text.slice(0, from.ch) + hlText(lines[0]), hlSpans(lines[0]));
30.1938 + doc.insert(from.line + 1, added);
30.1939 + }
30.1940 + } else if (lines.length == 1) {
30.1941 + updateLine(cm, firstLine, firstLine.text.slice(0, from.ch) + hlText(lines[0]) +
30.1942 + lastLine.text.slice(to.ch), hlSpans(lines[0]));
30.1943 + doc.remove(from.line + 1, nlines, cm);
30.1944 + } else {
30.1945 + var added = [];
30.1946 + updateLine(cm, firstLine, firstLine.text.slice(0, from.ch) + hlText(lines[0]), hlSpans(lines[0]));
30.1947 + updateLine(cm, lastLine, hlText(lastHL) + lastLine.text.slice(to.ch), hlSpans(lastHL));
30.1948 + for (var i = 1, e = lines.length - 1; i < e; ++i)
30.1949 + added.push(makeLine(hlText(lines[i]), hlSpans(lines[i]), th));
30.1950 + if (nlines > 1) doc.remove(from.line + 1, nlines - 1, cm);
30.1951 + doc.insert(from.line + 1, added);
30.1952 + }
30.1953 +
30.1954 + if (cm.options.lineWrapping) {
30.1955 + var perLine = Math.max(5, display.scroller.clientWidth / charWidth(display) - 3);
30.1956 + doc.iter(from.line, from.line + lines.length, function(line) {
30.1957 + if (line.height == 0) return;
30.1958 + var guess = (Math.ceil(line.text.length / perLine) || 1) * th;
30.1959 + if (guess != line.height) updateLineHeight(line, guess);
30.1960 + });
30.1961 + } else {
30.1962 + doc.iter(checkWidthStart, from.line + lines.length, function(line) {
30.1963 + var len = lineLength(doc, line);
30.1964 + if (len > view.maxLineLength) {
30.1965 + view.maxLine = line;
30.1966 + view.maxLineLength = len;
30.1967 + view.maxLineChanged = true;
30.1968 + recomputeMaxLength = false;
30.1969 + }
30.1970 + });
30.1971 + if (recomputeMaxLength) cm.curOp.updateMaxLine = true;
30.1972 + }
30.1973 +
30.1974 + // Adjust frontier, schedule worker
30.1975 + view.frontier = Math.min(view.frontier, from.line);
30.1976 + startWorker(cm, 400);
30.1977 +
30.1978 + var lendiff = lines.length - nlines - 1;
30.1979 + // Remember that these lines changed, for updating the display
30.1980 + regChange(cm, from.line, to.line + 1, lendiff);
30.1981 + if (hasHandler(cm, "change")) {
30.1982 + // Normalize lines to contain only strings, since that's what
30.1983 + // the change event handler expects
30.1984 + for (var i = 0; i < lines.length; ++i)
30.1985 + if (typeof lines[i] != "string") lines[i] = lines[i].text;
30.1986 + var changeObj = {from: from, to: to, text: lines, origin: origin};
30.1987 + if (cm.curOp.textChanged) {
30.1988 + for (var cur = cm.curOp.textChanged; cur.next; cur = cur.next) {}
30.1989 + cur.next = changeObj;
30.1990 + } else cm.curOp.textChanged = changeObj;
30.1991 + }
30.1992 +
30.1993 + // Update the selection
30.1994 + var newSelFrom, newSelTo, end = {line: from.line + lines.length - 1,
30.1995 + ch: hlText(lastHL).length + (lines.length == 1 ? from.ch : 0)};
30.1996 + if (selUpdate && typeof selUpdate != "string") {
30.1997 + if (selUpdate.from) { newSelFrom = selUpdate.from; newSelTo = selUpdate.to; }
30.1998 + else newSelFrom = newSelTo = selUpdate;
30.1999 + } else if (selUpdate == "end") {
30.2000 + newSelFrom = newSelTo = end;
30.2001 + } else if (selUpdate == "start") {
30.2002 + newSelFrom = newSelTo = from;
30.2003 + } else if (selUpdate == "around") {
30.2004 + newSelFrom = from; newSelTo = end;
30.2005 + } else {
30.2006 + var adjustPos = function(pos) {
30.2007 + if (posLess(pos, from)) return pos;
30.2008 + if (!posLess(to, pos)) return end;
30.2009 + var line = pos.line + lendiff;
30.2010 + var ch = pos.ch;
30.2011 + if (pos.line == to.line)
30.2012 + ch += hlText(lastHL).length - (to.ch - (to.line == from.line ? from.ch : 0));
30.2013 + return {line: line, ch: ch};
30.2014 + };
30.2015 + newSelFrom = adjustPos(view.sel.from);
30.2016 + newSelTo = adjustPos(view.sel.to);
30.2017 + }
30.2018 + setSelection(cm, newSelFrom, newSelTo, null, true);
30.2019 + return end;
30.2020 + }
30.2021 +
30.2022 + function replaceRange(cm, code, from, to, origin) {
30.2023 + if (!to) to = from;
30.2024 + if (posLess(to, from)) { var tmp = to; to = from; from = tmp; }
30.2025 + return updateDoc(cm, from, to, splitLines(code), null, origin);
30.2026 + }
30.2027 +
30.2028 + // SELECTION
30.2029 +
30.2030 + function posEq(a, b) {return a.line == b.line && a.ch == b.ch;}
30.2031 + function posLess(a, b) {return a.line < b.line || (a.line == b.line && a.ch < b.ch);}
30.2032 + function copyPos(x) {return {line: x.line, ch: x.ch};}
30.2033 +
30.2034 + function clipLine(doc, n) {return Math.max(0, Math.min(n, doc.size-1));}
30.2035 + function clipPos(doc, pos) {
30.2036 + if (pos.line < 0) return {line: 0, ch: 0};
30.2037 + if (pos.line >= doc.size) return {line: doc.size-1, ch: getLine(doc, doc.size-1).text.length};
30.2038 + var ch = pos.ch, linelen = getLine(doc, pos.line).text.length;
30.2039 + if (ch == null || ch > linelen) return {line: pos.line, ch: linelen};
30.2040 + else if (ch < 0) return {line: pos.line, ch: 0};
30.2041 + else return pos;
30.2042 + }
30.2043 + function isLine(doc, l) {return l >= 0 && l < doc.size;}
30.2044 +
30.2045 + // If shift is held, this will move the selection anchor. Otherwise,
30.2046 + // it'll set the whole selection.
30.2047 + function extendSelection(cm, pos, other, bias) {
30.2048 + var sel = cm.view.sel;
30.2049 + if (sel.shift || sel.extend) {
30.2050 + var anchor = sel.anchor;
30.2051 + if (other) {
30.2052 + var posBefore = posLess(pos, anchor);
30.2053 + if (posBefore != posLess(other, anchor)) {
30.2054 + anchor = pos;
30.2055 + pos = other;
30.2056 + } else if (posBefore != posLess(pos, other)) {
30.2057 + pos = other;
30.2058 + }
30.2059 + }
30.2060 + setSelection(cm, anchor, pos, bias);
30.2061 + } else {
30.2062 + setSelection(cm, pos, other || pos, bias);
30.2063 + }
30.2064 + cm.curOp.userSelChange = true;
30.2065 + }
30.2066 +
30.2067 + // Update the selection. Last two args are only used by
30.2068 + // updateDoc, since they have to be expressed in the line
30.2069 + // numbers before the update.
30.2070 + function setSelection(cm, anchor, head, bias, checkAtomic) {
30.2071 + cm.view.goalColumn = null;
30.2072 + var sel = cm.view.sel;
30.2073 + // Skip over atomic spans.
30.2074 + if (checkAtomic || !posEq(anchor, sel.anchor))
30.2075 + anchor = skipAtomic(cm, anchor, bias, checkAtomic != "push");
30.2076 + if (checkAtomic || !posEq(head, sel.head))
30.2077 + head = skipAtomic(cm, head, bias, checkAtomic != "push");
30.2078 +
30.2079 + if (posEq(sel.anchor, anchor) && posEq(sel.head, head)) return;
30.2080 +
30.2081 + sel.anchor = anchor; sel.head = head;
30.2082 + var inv = posLess(head, anchor);
30.2083 + sel.from = inv ? head : anchor;
30.2084 + sel.to = inv ? anchor : head;
30.2085 +
30.2086 + cm.curOp.updateInput = true;
30.2087 + cm.curOp.selectionChanged = true;
30.2088 + }
30.2089 +
30.2090 + function reCheckSelection(cm) {
30.2091 + setSelection(cm, cm.view.sel.from, cm.view.sel.to, null, "push");
30.2092 + }
30.2093 +
30.2094 + function skipAtomic(cm, pos, bias, mayClear) {
30.2095 + var doc = cm.view.doc, flipped = false, curPos = pos;
30.2096 + var dir = bias || 1;
30.2097 + cm.view.cantEdit = false;
30.2098 + search: for (;;) {
30.2099 + var line = getLine(doc, curPos.line), toClear;
30.2100 + if (line.markedSpans) {
30.2101 + for (var i = 0; i < line.markedSpans.length; ++i) {
30.2102 + var sp = line.markedSpans[i], m = sp.marker;
30.2103 + if ((sp.from == null || (m.inclusiveLeft ? sp.from <= curPos.ch : sp.from < curPos.ch)) &&
30.2104 + (sp.to == null || (m.inclusiveRight ? sp.to >= curPos.ch : sp.to > curPos.ch))) {
30.2105 + if (mayClear && m.clearOnEnter) {
30.2106 + (toClear || (toClear = [])).push(m);
30.2107 + continue;
30.2108 + } else if (!m.atomic) continue;
30.2109 + var newPos = m.find()[dir < 0 ? "from" : "to"];
30.2110 + if (posEq(newPos, curPos)) {
30.2111 + newPos.ch += dir;
30.2112 + if (newPos.ch < 0) {
30.2113 + if (newPos.line) newPos = clipPos(doc, {line: newPos.line - 1});
30.2114 + else newPos = null;
30.2115 + } else if (newPos.ch > line.text.length) {
30.2116 + if (newPos.line < doc.size - 1) newPos = {line: newPos.line + 1, ch: 0};
30.2117 + else newPos = null;
30.2118 + }
30.2119 + if (!newPos) {
30.2120 + if (flipped) {
30.2121 + // Driven in a corner -- no valid cursor position found at all
30.2122 + // -- try again *with* clearing, if we didn't already
30.2123 + if (!mayClear) return skipAtomic(cm, pos, bias, true);
30.2124 + // Otherwise, turn off editing until further notice, and return the start of the doc
30.2125 + cm.view.cantEdit = true;
30.2126 + return {line: 0, ch: 0};
30.2127 + }
30.2128 + flipped = true; newPos = pos; dir = -dir;
30.2129 + }
30.2130 + }
30.2131 + curPos = newPos;
30.2132 + continue search;
30.2133 + }
30.2134 + }
30.2135 + if (toClear) for (var i = 0; i < toClear.length; ++i) toClear[i].clear();
30.2136 + }
30.2137 + return curPos;
30.2138 + }
30.2139 + }
30.2140 +
30.2141 + // SCROLLING
30.2142 +
30.2143 + function scrollCursorIntoView(cm) {
30.2144 + var view = cm.view;
30.2145 + var coords = scrollPosIntoView(cm, view.sel.head);
30.2146 + if (!view.focused) return;
30.2147 + var display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null;
30.2148 + if (coords.top + box.top < 0) doScroll = true;
30.2149 + else if (coords.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) doScroll = false;
30.2150 + if (doScroll != null && !phantom) {
30.2151 + var hidden = display.cursor.style.display == "none";
30.2152 + if (hidden) {
30.2153 + display.cursor.style.display = "";
30.2154 + display.cursor.style.left = coords.left + "px";
30.2155 + display.cursor.style.top = (coords.top - display.viewOffset) + "px";
30.2156 + }
30.2157 + display.cursor.scrollIntoView(doScroll);
30.2158 + if (hidden) display.cursor.style.display = "none";
30.2159 + }
30.2160 + }
30.2161 +
30.2162 + function scrollPosIntoView(cm, pos) {
30.2163 + for (;;) {
30.2164 + var changed = false, coords = cursorCoords(cm, pos);
30.2165 + var scrollPos = calculateScrollPos(cm, coords.left, coords.top, coords.left, coords.bottom);
30.2166 + var startTop = cm.view.scrollTop, startLeft = cm.view.scrollLeft;
30.2167 + if (scrollPos.scrollTop != null) {
30.2168 + setScrollTop(cm, scrollPos.scrollTop);
30.2169 + if (Math.abs(cm.view.scrollTop - startTop) > 1) changed = true;
30.2170 + }
30.2171 + if (scrollPos.scrollLeft != null) {
30.2172 + setScrollLeft(cm, scrollPos.scrollLeft);
30.2173 + if (Math.abs(cm.view.scrollLeft - startLeft) > 1) changed = true;
30.2174 + }
30.2175 + if (!changed) return coords;
30.2176 + }
30.2177 + }
30.2178 +
30.2179 + function scrollIntoView(cm, x1, y1, x2, y2) {
30.2180 + var scrollPos = calculateScrollPos(cm, x1, y1, x2, y2);
30.2181 + if (scrollPos.scrollTop != null) setScrollTop(cm, scrollPos.scrollTop);
30.2182 + if (scrollPos.scrollLeft != null) setScrollLeft(cm, scrollPos.scrollLeft);
30.2183 + }
30.2184 +
30.2185 + function calculateScrollPos(cm, x1, y1, x2, y2) {
30.2186 + var display = cm.display, pt = paddingTop(display);
30.2187 + y1 += pt; y2 += pt;
30.2188 + var screen = display.scroller.clientHeight - scrollerCutOff, screentop = display.scroller.scrollTop, result = {};
30.2189 + var docBottom = cm.view.doc.height + 2 * pt;
30.2190 + var atTop = y1 < pt + 10, atBottom = y2 + pt > docBottom - 10;
30.2191 + if (y1 < screentop) result.scrollTop = atTop ? 0 : Math.max(0, y1);
30.2192 + else if (y2 > screentop + screen) result.scrollTop = (atBottom ? docBottom : y2) - screen;
30.2193 +
30.2194 + var screenw = display.scroller.clientWidth - scrollerCutOff, screenleft = display.scroller.scrollLeft;
30.2195 + x1 += display.gutters.offsetWidth; x2 += display.gutters.offsetWidth;
30.2196 + var gutterw = display.gutters.offsetWidth;
30.2197 + var atLeft = x1 < gutterw + 10;
30.2198 + if (x1 < screenleft + gutterw || atLeft) {
30.2199 + if (atLeft) x1 = 0;
30.2200 + result.scrollLeft = Math.max(0, x1 - 10 - gutterw);
30.2201 + } else if (x2 > screenw + screenleft - 3) {
30.2202 + result.scrollLeft = x2 + 10 - screenw;
30.2203 + }
30.2204 + return result;
30.2205 + }
30.2206 +
30.2207 + // API UTILITIES
30.2208 +
30.2209 + function indentLine(cm, n, how, aggressive) {
30.2210 + var doc = cm.view.doc;
30.2211 + if (!how) how = "add";
30.2212 + if (how == "smart") {
30.2213 + if (!cm.view.mode.indent) how = "prev";
30.2214 + else var state = getStateBefore(cm, n);
30.2215 + }
30.2216 +
30.2217 + var tabSize = cm.options.tabSize;
30.2218 + var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize);
30.2219 + var curSpaceString = line.text.match(/^\s*/)[0], indentation;
30.2220 + if (how == "smart") {
30.2221 + indentation = cm.view.mode.indent(state, line.text.slice(curSpaceString.length), line.text);
30.2222 + if (indentation == Pass) {
30.2223 + if (!aggressive) return;
30.2224 + how = "prev";
30.2225 + }
30.2226 + }
30.2227 + if (how == "prev") {
30.2228 + if (n) indentation = countColumn(getLine(doc, n-1).text, null, tabSize);
30.2229 + else indentation = 0;
30.2230 + }
30.2231 + else if (how == "add") indentation = curSpace + cm.options.indentUnit;
30.2232 + else if (how == "subtract") indentation = curSpace - cm.options.indentUnit;
30.2233 + indentation = Math.max(0, indentation);
30.2234 +
30.2235 + var indentString = "", pos = 0;
30.2236 + if (cm.options.indentWithTabs)
30.2237 + for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t";}
30.2238 + if (pos < indentation) indentString += spaceStr(indentation - pos);
30.2239 +
30.2240 + if (indentString != curSpaceString)
30.2241 + replaceRange(cm, indentString, {line: n, ch: 0}, {line: n, ch: curSpaceString.length}, "input");
30.2242 + line.stateAfter = null;
30.2243 + }
30.2244 +
30.2245 + function changeLine(cm, handle, op) {
30.2246 + var no = handle, line = handle, doc = cm.view.doc;
30.2247 + if (typeof handle == "number") line = getLine(doc, clipLine(doc, handle));
30.2248 + else no = lineNo(handle);
30.2249 + if (no == null) return null;
30.2250 + if (op(line, no)) regChange(cm, no, no + 1);
30.2251 + else return null;
30.2252 + return line;
30.2253 + }
30.2254 +
30.2255 + function findPosH(cm, dir, unit, visually) {
30.2256 + var doc = cm.view.doc, end = cm.view.sel.head, line = end.line, ch = end.ch;
30.2257 + var lineObj = getLine(doc, line);
30.2258 + function findNextLine() {
30.2259 + var l = line + dir;
30.2260 + if (l < 0 || l == doc.size) return false;
30.2261 + line = l;
30.2262 + return lineObj = getLine(doc, l);
30.2263 + }
30.2264 + function moveOnce(boundToLine) {
30.2265 + var next = (visually ? moveVisually : moveLogically)(lineObj, ch, dir, true);
30.2266 + if (next == null) {
30.2267 + if (!boundToLine && findNextLine()) {
30.2268 + if (visually) ch = (dir < 0 ? lineRight : lineLeft)(lineObj);
30.2269 + else ch = dir < 0 ? lineObj.text.length : 0;
30.2270 + } else return false;
30.2271 + } else ch = next;
30.2272 + return true;
30.2273 + }
30.2274 + if (unit == "char") moveOnce();
30.2275 + else if (unit == "column") moveOnce(true);
30.2276 + else if (unit == "word") {
30.2277 + var sawWord = false;
30.2278 + for (;;) {
30.2279 + if (dir < 0) if (!moveOnce()) break;
30.2280 + if (isWordChar(lineObj.text.charAt(ch))) sawWord = true;
30.2281 + else if (sawWord) {if (dir < 0) {dir = 1; moveOnce();} break;}
30.2282 + if (dir > 0) if (!moveOnce()) break;
30.2283 + }
30.2284 + }
30.2285 + return skipAtomic(cm, {line: line, ch: ch}, dir, true);
30.2286 + }
30.2287 +
30.2288 + function findWordAt(line, pos) {
30.2289 + var start = pos.ch, end = pos.ch;
30.2290 + if (line) {
30.2291 + if (pos.after === false || end == line.length) --start; else ++end;
30.2292 + var startChar = line.charAt(start);
30.2293 + var check = isWordChar(startChar) ? isWordChar :
30.2294 + /\s/.test(startChar) ? function(ch) {return /\s/.test(ch);} :
30.2295 + function(ch) {return !/\s/.test(ch) && !isWordChar(ch);};
30.2296 + while (start > 0 && check(line.charAt(start - 1))) --start;
30.2297 + while (end < line.length && check(line.charAt(end))) ++end;
30.2298 + }
30.2299 + return {from: {line: pos.line, ch: start}, to: {line: pos.line, ch: end}};
30.2300 + }
30.2301 +
30.2302 + function selectLine(cm, line) {
30.2303 + extendSelection(cm, {line: line, ch: 0}, clipPos(cm.view.doc, {line: line + 1, ch: 0}));
30.2304 + }
30.2305 +
30.2306 + // PROTOTYPE
30.2307 +
30.2308 + // The publicly visible API. Note that operation(null, f) means
30.2309 + // 'wrap f in an operation, performed on its `this` parameter'
30.2310 +
30.2311 + CodeMirror.prototype = {
30.2312 + getValue: function(lineSep) {
30.2313 + var text = [], doc = this.view.doc;
30.2314 + doc.iter(0, doc.size, function(line) { text.push(line.text); });
30.2315 + return text.join(lineSep || "\n");
30.2316 + },
30.2317 +
30.2318 + setValue: operation(null, function(code) {
30.2319 + var doc = this.view.doc, top = {line: 0, ch: 0}, lastLen = getLine(doc, doc.size-1).text.length;
30.2320 + updateDocInner(this, top, {line: doc.size - 1, ch: lastLen}, splitLines(code), top, top, "setValue");
30.2321 + }),
30.2322 +
30.2323 + getSelection: function(lineSep) { return this.getRange(this.view.sel.from, this.view.sel.to, lineSep); },
30.2324 +
30.2325 + replaceSelection: operation(null, function(code, collapse, origin) {
30.2326 + var sel = this.view.sel;
30.2327 + updateDoc(this, sel.from, sel.to, splitLines(code), collapse || "around", origin);
30.2328 + }),
30.2329 +
30.2330 + focus: function(){window.focus(); focusInput(this); onFocus(this); fastPoll(this);},
30.2331 +
30.2332 + setOption: function(option, value) {
30.2333 + var options = this.options, old = options[option];
30.2334 + if (options[option] == value && option != "mode") return;
30.2335 + options[option] = value;
30.2336 + if (optionHandlers.hasOwnProperty(option))
30.2337 + operation(this, optionHandlers[option])(this, value, old);
30.2338 + },
30.2339 +
30.2340 + getOption: function(option) {return this.options[option];},
30.2341 +
30.2342 + getMode: function() {return this.view.mode;},
30.2343 +
30.2344 + addKeyMap: function(map) {
30.2345 + this.view.keyMaps.push(map);
30.2346 + },
30.2347 +
30.2348 + removeKeyMap: function(map) {
30.2349 + var maps = this.view.keyMaps;
30.2350 + for (var i = 0; i < maps.length; ++i)
30.2351 + if ((typeof map == "string" ? maps[i].name : maps[i]) == map) {
30.2352 + maps.splice(i, 1);
30.2353 + return true;
30.2354 + }
30.2355 + },
30.2356 +
30.2357 + undo: operation(null, function() {unredoHelper(this, "undo");}),
30.2358 + redo: operation(null, function() {unredoHelper(this, "redo");}),
30.2359 +
30.2360 + indentLine: operation(null, function(n, dir, aggressive) {
30.2361 + if (typeof dir != "string") {
30.2362 + if (dir == null) dir = this.options.smartIndent ? "smart" : "prev";
30.2363 + else dir = dir ? "add" : "subtract";
30.2364 + }
30.2365 + if (isLine(this.view.doc, n)) indentLine(this, n, dir, aggressive);
30.2366 + }),
30.2367 +
30.2368 + indentSelection: operation(null, function(how) {
30.2369 + var sel = this.view.sel;
30.2370 + if (posEq(sel.from, sel.to)) return indentLine(this, sel.from.line, how);
30.2371 + var e = sel.to.line - (sel.to.ch ? 0 : 1);
30.2372 + for (var i = sel.from.line; i <= e; ++i) indentLine(this, i, how);
30.2373 + }),
30.2374 +
30.2375 + historySize: function() {
30.2376 + var hist = this.view.history;
30.2377 + return {undo: hist.done.length, redo: hist.undone.length};
30.2378 + },
30.2379 +
30.2380 + clearHistory: function() {this.view.history = makeHistory();},
30.2381 +
30.2382 + markClean: function() {
30.2383 + this.view.history.dirtyCounter = 0;
30.2384 + this.view.history.lastOp = this.view.history.lastOrigin = null;
30.2385 + },
30.2386 +
30.2387 + isClean: function () {return this.view.history.dirtyCounter == 0;},
30.2388 +
30.2389 + getHistory: function() {
30.2390 + var hist = this.view.history;
30.2391 + function cp(arr) {
30.2392 + for (var i = 0, nw = [], nwelt; i < arr.length; ++i) {
30.2393 + var set = arr[i];
30.2394 + nw.push({events: nwelt = [], fromBefore: set.fromBefore, toBefore: set.toBefore,
30.2395 + fromAfter: set.fromAfter, toAfter: set.toAfter});
30.2396 + for (var j = 0, elt = set.events; j < elt.length; ++j) {
30.2397 + var old = [], cur = elt[j];
30.2398 + nwelt.push({start: cur.start, added: cur.added, old: old});
30.2399 + for (var k = 0; k < cur.old.length; ++k) old.push(hlText(cur.old[k]));
30.2400 + }
30.2401 + }
30.2402 + return nw;
30.2403 + }
30.2404 + return {done: cp(hist.done), undone: cp(hist.undone)};
30.2405 + },
30.2406 +
30.2407 + setHistory: function(histData) {
30.2408 + var hist = this.view.history = makeHistory();
30.2409 + hist.done = histData.done;
30.2410 + hist.undone = histData.undone;
30.2411 + },
30.2412 +
30.2413 + // Fetch the parser token for a given character. Useful for hacks
30.2414 + // that want to inspect the mode state (say, for completion).
30.2415 + getTokenAt: function(pos) {
30.2416 + var doc = this.view.doc;
30.2417 + pos = clipPos(doc, pos);
30.2418 + var state = getStateBefore(this, pos.line), mode = this.view.mode;
30.2419 + var line = getLine(doc, pos.line);
30.2420 + var stream = new StringStream(line.text, this.options.tabSize);
30.2421 + while (stream.pos < pos.ch && !stream.eol()) {
30.2422 + stream.start = stream.pos;
30.2423 + var style = mode.token(stream, state);
30.2424 + }
30.2425 + return {start: stream.start,
30.2426 + end: stream.pos,
30.2427 + string: stream.current(),
30.2428 + className: style || null, // Deprecated, use 'type' instead
30.2429 + type: style || null,
30.2430 + state: state};
30.2431 + },
30.2432 +
30.2433 + getStateAfter: function(line) {
30.2434 + var doc = this.view.doc;
30.2435 + line = clipLine(doc, line == null ? doc.size - 1: line);
30.2436 + return getStateBefore(this, line + 1);
30.2437 + },
30.2438 +
30.2439 + cursorCoords: function(start, mode) {
30.2440 + var pos, sel = this.view.sel;
30.2441 + if (start == null) pos = sel.head;
30.2442 + else if (typeof start == "object") pos = clipPos(this.view.doc, start);
30.2443 + else pos = start ? sel.from : sel.to;
30.2444 + return cursorCoords(this, pos, mode || "page");
30.2445 + },
30.2446 +
30.2447 + charCoords: function(pos, mode) {
30.2448 + return charCoords(this, clipPos(this.view.doc, pos), mode || "page");
30.2449 + },
30.2450 +
30.2451 + coordsChar: function(coords) {
30.2452 + var off = this.display.lineSpace.getBoundingClientRect();
30.2453 + return coordsChar(this, coords.left - off.left, coords.top - off.top);
30.2454 + },
30.2455 +
30.2456 + defaultTextHeight: function() { return textHeight(this.display); },
30.2457 +
30.2458 + markText: operation(null, function(from, to, options) {
30.2459 + return markText(this, clipPos(this.view.doc, from), clipPos(this.view.doc, to),
30.2460 + options, "range");
30.2461 + }),
30.2462 +
30.2463 + setBookmark: operation(null, function(pos, widget) {
30.2464 + pos = clipPos(this.view.doc, pos);
30.2465 + return markText(this, pos, pos, widget ? {replacedWith: widget} : {}, "bookmark");
30.2466 + }),
30.2467 +
30.2468 + findMarksAt: function(pos) {
30.2469 + var doc = this.view.doc;
30.2470 + pos = clipPos(doc, pos);
30.2471 + var markers = [], spans = getLine(doc, pos.line).markedSpans;
30.2472 + if (spans) for (var i = 0; i < spans.length; ++i) {
30.2473 + var span = spans[i];
30.2474 + if ((span.from == null || span.from <= pos.ch) &&
30.2475 + (span.to == null || span.to >= pos.ch))
30.2476 + markers.push(span.marker);
30.2477 + }
30.2478 + return markers;
30.2479 + },
30.2480 +
30.2481 + setGutterMarker: operation(null, function(line, gutterID, value) {
30.2482 + return changeLine(this, line, function(line) {
30.2483 + var markers = line.gutterMarkers || (line.gutterMarkers = {});
30.2484 + markers[gutterID] = value;
30.2485 + if (!value && isEmpty(markers)) line.gutterMarkers = null;
30.2486 + return true;
30.2487 + });
30.2488 + }),
30.2489 +
30.2490 + clearGutter: operation(null, function(gutterID) {
30.2491 + var i = 0, cm = this, doc = cm.view.doc;
30.2492 + doc.iter(0, doc.size, function(line) {
30.2493 + if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
30.2494 + line.gutterMarkers[gutterID] = null;
30.2495 + regChange(cm, i, i + 1);
30.2496 + if (isEmpty(line.gutterMarkers)) line.gutterMarkers = null;
30.2497 + }
30.2498 + ++i;
30.2499 + });
30.2500 + }),
30.2501 +
30.2502 + addLineClass: operation(null, function(handle, where, cls) {
30.2503 + return changeLine(this, handle, function(line) {
30.2504 + var prop = where == "text" ? "textClass" : where == "background" ? "bgClass" : "wrapClass";
30.2505 + if (!line[prop]) line[prop] = cls;
30.2506 + else if (new RegExp("\\b" + cls + "\\b").test(line[prop])) return false;
30.2507 + else line[prop] += " " + cls;
30.2508 + return true;
30.2509 + });
30.2510 + }),
30.2511 +
30.2512 + removeLineClass: operation(null, function(handle, where, cls) {
30.2513 + return changeLine(this, handle, function(line) {
30.2514 + var prop = where == "text" ? "textClass" : where == "background" ? "bgClass" : "wrapClass";
30.2515 + var cur = line[prop];
30.2516 + if (!cur) return false;
30.2517 + else if (cls == null) line[prop] = null;
30.2518 + else {
30.2519 + var upd = cur.replace(new RegExp("^" + cls + "\\b\\s*|\\s*\\b" + cls + "\\b"), "");
30.2520 + if (upd == cur) return false;
30.2521 + line[prop] = upd || null;
30.2522 + }
30.2523 + return true;
30.2524 + });
30.2525 + }),
30.2526 +
30.2527 + addLineWidget: operation(null, function(handle, node, options) {
30.2528 + var widget = options || {};
30.2529 + widget.node = node;
30.2530 + if (widget.noHScroll) this.display.alignWidgets = true;
30.2531 + changeLine(this, handle, function(line) {
30.2532 + (line.widgets || (line.widgets = [])).push(widget);
30.2533 + widget.line = line;
30.2534 + return true;
30.2535 + });
30.2536 + return widget;
30.2537 + }),
30.2538 +
30.2539 + removeLineWidget: operation(null, function(widget) {
30.2540 + var ws = widget.line.widgets, no = lineNo(widget.line);
30.2541 + if (no == null) return;
30.2542 + for (var i = 0; i < ws.length; ++i) if (ws[i] == widget) ws.splice(i--, 1);
30.2543 + regChange(this, no, no + 1);
30.2544 + }),
30.2545 +
30.2546 + lineInfo: function(line) {
30.2547 + if (typeof line == "number") {
30.2548 + if (!isLine(this.view.doc, line)) return null;
30.2549 + var n = line;
30.2550 + line = getLine(this.view.doc, line);
30.2551 + if (!line) return null;
30.2552 + } else {
30.2553 + var n = lineNo(line);
30.2554 + if (n == null) return null;
30.2555 + }
30.2556 + return {line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers,
30.2557 + textClass: line.textClass, bgClass: line.bgClass, wrapClass: line.wrapClass,
30.2558 + widgets: line.widgets};
30.2559 + },
30.2560 +
30.2561 + getViewport: function() { return {from: this.display.showingFrom, to: this.display.showingTo};},
30.2562 +
30.2563 + addWidget: function(pos, node, scroll, vert, horiz) {
30.2564 + var display = this.display;
30.2565 + pos = cursorCoords(this, clipPos(this.view.doc, pos));
30.2566 + var top = pos.top, left = pos.left;
30.2567 + node.style.position = "absolute";
30.2568 + display.sizer.appendChild(node);
30.2569 + if (vert == "over") top = pos.top;
30.2570 + else if (vert == "near") {
30.2571 + var vspace = Math.max(display.wrapper.clientHeight, this.view.doc.height),
30.2572 + hspace = Math.max(display.sizer.clientWidth, display.lineSpace.clientWidth);
30.2573 + if (pos.bottom + node.offsetHeight > vspace && pos.top > node.offsetHeight)
30.2574 + top = pos.top - node.offsetHeight;
30.2575 + if (left + node.offsetWidth > hspace)
30.2576 + left = hspace - node.offsetWidth;
30.2577 + }
30.2578 + node.style.top = (top + paddingTop(display)) + "px";
30.2579 + node.style.left = node.style.right = "";
30.2580 + if (horiz == "right") {
30.2581 + left = display.sizer.clientWidth - node.offsetWidth;
30.2582 + node.style.right = "0px";
30.2583 + } else {
30.2584 + if (horiz == "left") left = 0;
30.2585 + else if (horiz == "middle") left = (display.sizer.clientWidth - node.offsetWidth) / 2;
30.2586 + node.style.left = left + "px";
30.2587 + }
30.2588 + if (scroll)
30.2589 + scrollIntoView(this, left, top, left + node.offsetWidth, top + node.offsetHeight);
30.2590 + },
30.2591 +
30.2592 + lineCount: function() {return this.view.doc.size;},
30.2593 +
30.2594 + clipPos: function(pos) {return clipPos(this.view.doc, pos);},
30.2595 +
30.2596 + getCursor: function(start) {
30.2597 + var sel = this.view.sel, pos;
30.2598 + if (start == null || start == "head") pos = sel.head;
30.2599 + else if (start == "anchor") pos = sel.anchor;
30.2600 + else if (start == "end" || start === false) pos = sel.to;
30.2601 + else pos = sel.from;
30.2602 + return copyPos(pos);
30.2603 + },
30.2604 +
30.2605 + somethingSelected: function() {return !posEq(this.view.sel.from, this.view.sel.to);},
30.2606 +
30.2607 + setCursor: operation(null, function(line, ch, extend) {
30.2608 + var pos = clipPos(this.view.doc, typeof line == "number" ? {line: line, ch: ch || 0} : line);
30.2609 + if (extend) extendSelection(this, pos);
30.2610 + else setSelection(this, pos, pos);
30.2611 + }),
30.2612 +
30.2613 + setSelection: operation(null, function(anchor, head) {
30.2614 + var doc = this.view.doc;
30.2615 + setSelection(this, clipPos(doc, anchor), clipPos(doc, head || anchor));
30.2616 + }),
30.2617 +
30.2618 + extendSelection: operation(null, function(from, to) {
30.2619 + var doc = this.view.doc;
30.2620 + extendSelection(this, clipPos(doc, from), to && clipPos(doc, to));
30.2621 + }),
30.2622 +
30.2623 + setExtending: function(val) {this.view.sel.extend = val;},
30.2624 +
30.2625 + getLine: function(line) {var l = this.getLineHandle(line); return l && l.text;},
30.2626 +
30.2627 + getLineHandle: function(line) {
30.2628 + var doc = this.view.doc;
30.2629 + if (isLine(doc, line)) return getLine(doc, line);
30.2630 + },
30.2631 +
30.2632 + getLineNumber: function(line) {return lineNo(line);},
30.2633 +
30.2634 + setLine: operation(null, function(line, text) {
30.2635 + if (isLine(this.view.doc, line))
30.2636 + replaceRange(this, text, {line: line, ch: 0}, {line: line, ch: getLine(this.view.doc, line).text.length});
30.2637 + }),
30.2638 +
30.2639 + removeLine: operation(null, function(line) {
30.2640 + if (isLine(this.view.doc, line))
30.2641 + replaceRange(this, "", {line: line, ch: 0}, clipPos(this.view.doc, {line: line+1, ch: 0}));
30.2642 + }),
30.2643 +
30.2644 + replaceRange: operation(null, function(code, from, to) {
30.2645 + var doc = this.view.doc;
30.2646 + from = clipPos(doc, from);
30.2647 + to = to ? clipPos(doc, to) : from;
30.2648 + return replaceRange(this, code, from, to);
30.2649 + }),
30.2650 +
30.2651 + getRange: function(from, to, lineSep) {
30.2652 + var doc = this.view.doc;
30.2653 + from = clipPos(doc, from); to = clipPos(doc, to);
30.2654 + var l1 = from.line, l2 = to.line;
30.2655 + if (l1 == l2) return getLine(doc, l1).text.slice(from.ch, to.ch);
30.2656 + var code = [getLine(doc, l1).text.slice(from.ch)];
30.2657 + doc.iter(l1 + 1, l2, function(line) { code.push(line.text); });
30.2658 + code.push(getLine(doc, l2).text.slice(0, to.ch));
30.2659 + return code.join(lineSep || "\n");
30.2660 + },
30.2661 +
30.2662 + triggerOnKeyDown: operation(null, onKeyDown),
30.2663 +
30.2664 + execCommand: function(cmd) {return commands[cmd](this);},
30.2665 +
30.2666 + // Stuff used by commands, probably not much use to outside code.
30.2667 + moveH: operation(null, function(dir, unit) {
30.2668 + var sel = this.view.sel, pos = dir < 0 ? sel.from : sel.to;
30.2669 + if (sel.shift || sel.extend || posEq(sel.from, sel.to)) pos = findPosH(this, dir, unit, true);
30.2670 + extendSelection(this, pos, pos, dir);
30.2671 + }),
30.2672 +
30.2673 + deleteH: operation(null, function(dir, unit) {
30.2674 + var sel = this.view.sel;
30.2675 + if (!posEq(sel.from, sel.to)) replaceRange(this, "", sel.from, sel.to, "delete");
30.2676 + else replaceRange(this, "", sel.from, findPosH(this, dir, unit, false), "delete");
30.2677 + this.curOp.userSelChange = true;
30.2678 + }),
30.2679 +
30.2680 + moveV: operation(null, function(dir, unit) {
30.2681 + var view = this.view, doc = view.doc, display = this.display;
30.2682 + var cur = view.sel.head, pos = cursorCoords(this, cur, "div");
30.2683 + var x = pos.left, y;
30.2684 + if (view.goalColumn != null) x = view.goalColumn;
30.2685 + if (unit == "page") {
30.2686 + var pageSize = Math.min(display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight);
30.2687 + y = pos.top + dir * pageSize;
30.2688 + } else if (unit == "line") {
30.2689 + y = dir > 0 ? pos.bottom + 3 : pos.top - 3;
30.2690 + }
30.2691 + do {
30.2692 + var target = coordsChar(this, x, y);
30.2693 + y += dir * 5;
30.2694 + } while (target.outside && (dir < 0 ? y > 0 : y < doc.height));
30.2695 +
30.2696 + if (unit == "page") display.scrollbarV.scrollTop += charCoords(this, target, "div").top - pos.top;
30.2697 + extendSelection(this, target, target, dir);
30.2698 + view.goalColumn = x;
30.2699 + }),
30.2700 +
30.2701 + toggleOverwrite: function() {
30.2702 + if (this.view.overwrite = !this.view.overwrite)
30.2703 + this.display.cursor.className += " CodeMirror-overwrite";
30.2704 + else
30.2705 + this.display.cursor.className = this.display.cursor.className.replace(" CodeMirror-overwrite", "");
30.2706 + },
30.2707 +
30.2708 + posFromIndex: function(off) {
30.2709 + var lineNo = 0, ch, doc = this.view.doc;
30.2710 + doc.iter(0, doc.size, function(line) {
30.2711 + var sz = line.text.length + 1;
30.2712 + if (sz > off) { ch = off; return true; }
30.2713 + off -= sz;
30.2714 + ++lineNo;
30.2715 + });
30.2716 + return clipPos(doc, {line: lineNo, ch: ch});
30.2717 + },
30.2718 + indexFromPos: function (coords) {
30.2719 + if (coords.line < 0 || coords.ch < 0) return 0;
30.2720 + var index = coords.ch;
30.2721 + this.view.doc.iter(0, coords.line, function (line) {
30.2722 + index += line.text.length + 1;
30.2723 + });
30.2724 + return index;
30.2725 + },
30.2726 +
30.2727 + scrollTo: function(x, y) {
30.2728 + if (x != null) this.display.scrollbarH.scrollLeft = this.display.scroller.scrollLeft = x;
30.2729 + if (y != null) this.display.scrollbarV.scrollTop = this.display.scroller.scrollTop = y;
30.2730 + updateDisplay(this, []);
30.2731 + },
30.2732 + getScrollInfo: function() {
30.2733 + var scroller = this.display.scroller, co = scrollerCutOff;
30.2734 + return {left: scroller.scrollLeft, top: scroller.scrollTop,
30.2735 + height: scroller.scrollHeight - co, width: scroller.scrollWidth - co,
30.2736 + clientHeight: scroller.clientHeight - co, clientWidth: scroller.clientWidth - co};
30.2737 + },
30.2738 +
30.2739 + scrollIntoView: function(pos) {
30.2740 + if (typeof pos == "number") pos = {line: pos, ch: 0};
30.2741 + pos = pos ? clipPos(this.view.doc, pos) : this.view.sel.head;
30.2742 + scrollPosIntoView(this, pos);
30.2743 + },
30.2744 +
30.2745 + setSize: function(width, height) {
30.2746 + function interpret(val) {
30.2747 + return typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val;
30.2748 + }
30.2749 + if (width != null) this.display.wrapper.style.width = interpret(width);
30.2750 + if (height != null) this.display.wrapper.style.height = interpret(height);
30.2751 + this.refresh();
30.2752 + },
30.2753 +
30.2754 + on: function(type, f) {on(this, type, f);},
30.2755 + off: function(type, f) {off(this, type, f);},
30.2756 +
30.2757 + operation: function(f){return operation(this, f)();},
30.2758 +
30.2759 + refresh: function() {
30.2760 + clearCaches(this);
30.2761 + if (this.display.scroller.scrollHeight > this.view.scrollTop)
30.2762 + this.display.scrollbarV.scrollTop = this.display.scroller.scrollTop = this.view.scrollTop;
30.2763 + updateDisplay(this, true);
30.2764 + },
30.2765 +
30.2766 + getInputField: function(){return this.display.input;},
30.2767 + getWrapperElement: function(){return this.display.wrapper;},
30.2768 + getScrollerElement: function(){return this.display.scroller;},
30.2769 + getGutterElement: function(){return this.display.gutters;}
30.2770 + };
30.2771 +
30.2772 + // OPTION DEFAULTS
30.2773 +
30.2774 + var optionHandlers = CodeMirror.optionHandlers = {};
30.2775 +
30.2776 + // The default configuration options.
30.2777 + var defaults = CodeMirror.defaults = {};
30.2778 +
30.2779 + function option(name, deflt, handle, notOnInit) {
30.2780 + CodeMirror.defaults[name] = deflt;
30.2781 + if (handle) optionHandlers[name] =
30.2782 + notOnInit ? function(cm, val, old) {if (old != Init) handle(cm, val, old);} : handle;
30.2783 + }
30.2784 +
30.2785 + var Init = CodeMirror.Init = {toString: function(){return "CodeMirror.Init";}};
30.2786 +
30.2787 + // These two are, on init, called from the constructor because they
30.2788 + // have to be initialized before the editor can start at all.
30.2789 + option("value", "", function(cm, val) {cm.setValue(val);}, true);
30.2790 + option("mode", null, loadMode, true);
30.2791 +
30.2792 + option("indentUnit", 2, loadMode, true);
30.2793 + option("indentWithTabs", false);
30.2794 + option("smartIndent", true);
30.2795 + option("tabSize", 4, function(cm) {
30.2796 + loadMode(cm);
30.2797 + clearCaches(cm);
30.2798 + updateDisplay(cm, true);
30.2799 + }, true);
30.2800 + option("electricChars", true);
30.2801 +
30.2802 + option("theme", "default", function(cm) {
30.2803 + themeChanged(cm);
30.2804 + guttersChanged(cm);
30.2805 + }, true);
30.2806 + option("keyMap", "default", keyMapChanged);
30.2807 + option("extraKeys", null);
30.2808 +
30.2809 + option("onKeyEvent", null);
30.2810 + option("onDragEvent", null);
30.2811 +
30.2812 + option("lineWrapping", false, wrappingChanged, true);
30.2813 + option("gutters", [], function(cm) {
30.2814 + setGuttersForLineNumbers(cm.options);
30.2815 + guttersChanged(cm);
30.2816 + }, true);
30.2817 + option("lineNumbers", false, function(cm) {
30.2818 + setGuttersForLineNumbers(cm.options);
30.2819 + guttersChanged(cm);
30.2820 + }, true);
30.2821 + option("firstLineNumber", 1, guttersChanged, true);
30.2822 + option("lineNumberFormatter", function(integer) {return integer;}, guttersChanged, true);
30.2823 + option("showCursorWhenSelecting", false, updateSelection, true);
30.2824 +
30.2825 + option("readOnly", false, function(cm, val) {
30.2826 + if (val == "nocursor") {onBlur(cm); cm.display.input.blur();}
30.2827 + else if (!val) resetInput(cm, true);
30.2828 + });
30.2829 + option("dragDrop", true);
30.2830 +
30.2831 + option("cursorBlinkRate", 530);
30.2832 + option("cursorHeight", 1);
30.2833 + option("workTime", 100);
30.2834 + option("workDelay", 100);
30.2835 + option("flattenSpans", true);
30.2836 + option("pollInterval", 100);
30.2837 + option("undoDepth", 40);
30.2838 + option("viewportMargin", 10, function(cm){cm.refresh();}, true);
30.2839 +
30.2840 + option("tabindex", null, function(cm, val) {
30.2841 + cm.display.input.tabIndex = val || "";
30.2842 + });
30.2843 + option("autofocus", null);
30.2844 +
30.2845 + // MODE DEFINITION AND QUERYING
30.2846 +
30.2847 + // Known modes, by name and by MIME
30.2848 + var modes = CodeMirror.modes = {}, mimeModes = CodeMirror.mimeModes = {};
30.2849 +
30.2850 + CodeMirror.defineMode = function(name, mode) {
30.2851 + if (!CodeMirror.defaults.mode && name != "null") CodeMirror.defaults.mode = name;
30.2852 + if (arguments.length > 2) {
30.2853 + mode.dependencies = [];
30.2854 + for (var i = 2; i < arguments.length; ++i) mode.dependencies.push(arguments[i]);
30.2855 + }
30.2856 + modes[name] = mode;
30.2857 + };
30.2858 +
30.2859 + CodeMirror.defineMIME = function(mime, spec) {
30.2860 + mimeModes[mime] = spec;
30.2861 + };
30.2862 +
30.2863 + CodeMirror.resolveMode = function(spec) {
30.2864 + if (typeof spec == "string" && mimeModes.hasOwnProperty(spec))
30.2865 + spec = mimeModes[spec];
30.2866 + else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec))
30.2867 + return CodeMirror.resolveMode("application/xml");
30.2868 + if (typeof spec == "string") return {name: spec};
30.2869 + else return spec || {name: "null"};
30.2870 + };
30.2871 +
30.2872 + CodeMirror.getMode = function(options, spec) {
30.2873 + var spec = CodeMirror.resolveMode(spec);
30.2874 + var mfactory = modes[spec.name];
30.2875 + if (!mfactory) return CodeMirror.getMode(options, "text/plain");
30.2876 + var modeObj = mfactory(options, spec);
30.2877 + if (modeExtensions.hasOwnProperty(spec.name)) {
30.2878 + var exts = modeExtensions[spec.name];
30.2879 + for (var prop in exts) {
30.2880 + if (!exts.hasOwnProperty(prop)) continue;
30.2881 + if (modeObj.hasOwnProperty(prop)) modeObj["_" + prop] = modeObj[prop];
30.2882 + modeObj[prop] = exts[prop];
30.2883 + }
30.2884 + }
30.2885 + modeObj.name = spec.name;
30.2886 + return modeObj;
30.2887 + };
30.2888 +
30.2889 + CodeMirror.defineMode("null", function() {
30.2890 + return {token: function(stream) {stream.skipToEnd();}};
30.2891 + });
30.2892 + CodeMirror.defineMIME("text/plain", "null");
30.2893 +
30.2894 + var modeExtensions = CodeMirror.modeExtensions = {};
30.2895 + CodeMirror.extendMode = function(mode, properties) {
30.2896 + var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {});
30.2897 + for (var prop in properties) if (properties.hasOwnProperty(prop))
30.2898 + exts[prop] = properties[prop];
30.2899 + };
30.2900 +
30.2901 + // EXTENSIONS
30.2902 +
30.2903 + CodeMirror.defineExtension = function(name, func) {
30.2904 + CodeMirror.prototype[name] = func;
30.2905 + };
30.2906 +
30.2907 + CodeMirror.defineOption = option;
30.2908 +
30.2909 + var initHooks = [];
30.2910 + CodeMirror.defineInitHook = function(f) {initHooks.push(f);};
30.2911 +
30.2912 + // MODE STATE HANDLING
30.2913 +
30.2914 + // Utility functions for working with state. Exported because modes
30.2915 + // sometimes need to do this.
30.2916 + function copyState(mode, state) {
30.2917 + if (state === true) return state;
30.2918 + if (mode.copyState) return mode.copyState(state);
30.2919 + var nstate = {};
30.2920 + for (var n in state) {
30.2921 + var val = state[n];
30.2922 + if (val instanceof Array) val = val.concat([]);
30.2923 + nstate[n] = val;
30.2924 + }
30.2925 + return nstate;
30.2926 + }
30.2927 + CodeMirror.copyState = copyState;
30.2928 +
30.2929 + function startState(mode, a1, a2) {
30.2930 + return mode.startState ? mode.startState(a1, a2) : true;
30.2931 + }
30.2932 + CodeMirror.startState = startState;
30.2933 +
30.2934 + CodeMirror.innerMode = function(mode, state) {
30.2935 + while (mode.innerMode) {
30.2936 + var info = mode.innerMode(state);
30.2937 + state = info.state;
30.2938 + mode = info.mode;
30.2939 + }
30.2940 + return info || {mode: mode, state: state};
30.2941 + };
30.2942 +
30.2943 + // STANDARD COMMANDS
30.2944 +
30.2945 + var commands = CodeMirror.commands = {
30.2946 + selectAll: function(cm) {cm.setSelection({line: 0, ch: 0}, {line: cm.lineCount() - 1});},
30.2947 + killLine: function(cm) {
30.2948 + var from = cm.getCursor(true), to = cm.getCursor(false), sel = !posEq(from, to);
30.2949 + if (!sel && cm.getLine(from.line).length == from.ch)
30.2950 + cm.replaceRange("", from, {line: from.line + 1, ch: 0}, "delete");
30.2951 + else cm.replaceRange("", from, sel ? to : {line: from.line}, "delete");
30.2952 + },
30.2953 + deleteLine: function(cm) {
30.2954 + var l = cm.getCursor().line;
30.2955 + cm.replaceRange("", {line: l, ch: 0}, {line: l}, "delete");
30.2956 + },
30.2957 + undo: function(cm) {cm.undo();},
30.2958 + redo: function(cm) {cm.redo();},
30.2959 + goDocStart: function(cm) {cm.extendSelection({line: 0, ch: 0});},
30.2960 + goDocEnd: function(cm) {cm.extendSelection({line: cm.lineCount() - 1});},
30.2961 + goLineStart: function(cm) {
30.2962 + cm.extendSelection(lineStart(cm, cm.getCursor().line));
30.2963 + },
30.2964 + goLineStartSmart: function(cm) {
30.2965 + var cur = cm.getCursor(), start = lineStart(cm, cur.line);
30.2966 + var line = cm.getLineHandle(start.line);
30.2967 + var order = getOrder(line);
30.2968 + if (!order || order[0].level == 0) {
30.2969 + var firstNonWS = Math.max(0, line.text.search(/\S/));
30.2970 + var inWS = cur.line == start.line && cur.ch <= firstNonWS && cur.ch;
30.2971 + cm.extendSelection({line: start.line, ch: inWS ? 0 : firstNonWS});
30.2972 + } else cm.extendSelection(start);
30.2973 + },
30.2974 + goLineEnd: function(cm) {
30.2975 + cm.extendSelection(lineEnd(cm, cm.getCursor().line));
30.2976 + },
30.2977 + goLineUp: function(cm) {cm.moveV(-1, "line");},
30.2978 + goLineDown: function(cm) {cm.moveV(1, "line");},
30.2979 + goPageUp: function(cm) {cm.moveV(-1, "page");},
30.2980 + goPageDown: function(cm) {cm.moveV(1, "page");},
30.2981 + goCharLeft: function(cm) {cm.moveH(-1, "char");},
30.2982 + goCharRight: function(cm) {cm.moveH(1, "char");},
30.2983 + goColumnLeft: function(cm) {cm.moveH(-1, "column");},
30.2984 + goColumnRight: function(cm) {cm.moveH(1, "column");},
30.2985 + goWordLeft: function(cm) {cm.moveH(-1, "word");},
30.2986 + goWordRight: function(cm) {cm.moveH(1, "word");},
30.2987 + delCharBefore: function(cm) {cm.deleteH(-1, "char");},
30.2988 + delCharAfter: function(cm) {cm.deleteH(1, "char");},
30.2989 + delWordBefore: function(cm) {cm.deleteH(-1, "word");},
30.2990 + delWordAfter: function(cm) {cm.deleteH(1, "word");},
30.2991 + indentAuto: function(cm) {cm.indentSelection("smart");},
30.2992 + indentMore: function(cm) {cm.indentSelection("add");},
30.2993 + indentLess: function(cm) {cm.indentSelection("subtract");},
30.2994 + insertTab: function(cm) {cm.replaceSelection("\t", "end", "input");},
30.2995 + defaultTab: function(cm) {
30.2996 + if (cm.somethingSelected()) cm.indentSelection("add");
30.2997 + else cm.replaceSelection("\t", "end", "input");
30.2998 + },
30.2999 + transposeChars: function(cm) {
30.3000 + var cur = cm.getCursor(), line = cm.getLine(cur.line);
30.3001 + if (cur.ch > 0 && cur.ch < line.length - 1)
30.3002 + cm.replaceRange(line.charAt(cur.ch) + line.charAt(cur.ch - 1),
30.3003 + {line: cur.line, ch: cur.ch - 1}, {line: cur.line, ch: cur.ch + 1});
30.3004 + },
30.3005 + newlineAndIndent: function(cm) {
30.3006 + operation(cm, function() {
30.3007 + cm.replaceSelection("\n", "end", "input");
30.3008 + cm.indentLine(cm.getCursor().line, null, true);
30.3009 + })();
30.3010 + },
30.3011 + toggleOverwrite: function(cm) {cm.toggleOverwrite();}
30.3012 + };
30.3013 +
30.3014 + // STANDARD KEYMAPS
30.3015 +
30.3016 + var keyMap = CodeMirror.keyMap = {};
30.3017 + keyMap.basic = {
30.3018 + "Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
30.3019 + "End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown",
30.3020 + "Delete": "delCharAfter", "Backspace": "delCharBefore", "Tab": "defaultTab", "Shift-Tab": "indentAuto",
30.3021 + "Enter": "newlineAndIndent", "Insert": "toggleOverwrite"
30.3022 + };
30.3023 + // Note that the save and find-related commands aren't defined by
30.3024 + // default. Unknown commands are simply ignored.
30.3025 + keyMap.pcDefault = {
30.3026 + "Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo",
30.3027 + "Ctrl-Home": "goDocStart", "Alt-Up": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Down": "goDocEnd",
30.3028 + "Ctrl-Left": "goWordLeft", "Ctrl-Right": "goWordRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd",
30.3029 + "Ctrl-Backspace": "delWordBefore", "Ctrl-Delete": "delWordAfter", "Ctrl-S": "save", "Ctrl-F": "find",
30.3030 + "Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll",
30.3031 + "Ctrl-[": "indentLess", "Ctrl-]": "indentMore",
30.3032 + fallthrough: "basic"
30.3033 + };
30.3034 + keyMap.macDefault = {
30.3035 + "Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
30.3036 + "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goWordLeft",
30.3037 + "Alt-Right": "goWordRight", "Cmd-Left": "goLineStart", "Cmd-Right": "goLineEnd", "Alt-Backspace": "delWordBefore",
30.3038 + "Ctrl-Alt-Backspace": "delWordAfter", "Alt-Delete": "delWordAfter", "Cmd-S": "save", "Cmd-F": "find",
30.3039 + "Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll",
30.3040 + "Cmd-[": "indentLess", "Cmd-]": "indentMore",
30.3041 + fallthrough: ["basic", "emacsy"]
30.3042 + };
30.3043 + keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault;
30.3044 + keyMap.emacsy = {
30.3045 + "Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
30.3046 + "Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
30.3047 + "Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharAfter", "Ctrl-H": "delCharBefore",
30.3048 + "Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars"
30.3049 + };
30.3050 +
30.3051 + // KEYMAP DISPATCH
30.3052 +
30.3053 + function getKeyMap(val) {
30.3054 + if (typeof val == "string") return keyMap[val];
30.3055 + else return val;
30.3056 + }
30.3057 +
30.3058 + function lookupKey(name, maps, handle, stop) {
30.3059 + function lookup(map) {
30.3060 + map = getKeyMap(map);
30.3061 + var found = map[name];
30.3062 + if (found === false) {
30.3063 + if (stop) stop();
30.3064 + return true;
30.3065 + }
30.3066 + if (found != null && handle(found)) return true;
30.3067 + if (map.nofallthrough) {
30.3068 + if (stop) stop();
30.3069 + return true;
30.3070 + }
30.3071 + var fallthrough = map.fallthrough;
30.3072 + if (fallthrough == null) return false;
30.3073 + if (Object.prototype.toString.call(fallthrough) != "[object Array]")
30.3074 + return lookup(fallthrough);
30.3075 + for (var i = 0, e = fallthrough.length; i < e; ++i) {
30.3076 + if (lookup(fallthrough[i])) return true;
30.3077 + }
30.3078 + return false;
30.3079 + }
30.3080 +
30.3081 + for (var i = 0; i < maps.length; ++i)
30.3082 + if (lookup(maps[i])) return true;
30.3083 + }
30.3084 + function isModifierKey(event) {
30.3085 + var name = keyNames[e_prop(event, "keyCode")];
30.3086 + return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod";
30.3087 + }
30.3088 + CodeMirror.isModifierKey = isModifierKey;
30.3089 +
30.3090 + // FROMTEXTAREA
30.3091 +
30.3092 + CodeMirror.fromTextArea = function(textarea, options) {
30.3093 + if (!options) options = {};
30.3094 + options.value = textarea.value;
30.3095 + if (!options.tabindex && textarea.tabindex)
30.3096 + options.tabindex = textarea.tabindex;
30.3097 + // Set autofocus to true if this textarea is focused, or if it has
30.3098 + // autofocus and no other element is focused.
30.3099 + if (options.autofocus == null) {
30.3100 + var hasFocus = document.body;
30.3101 + // doc.activeElement occasionally throws on IE
30.3102 + try { hasFocus = document.activeElement; } catch(e) {}
30.3103 + options.autofocus = hasFocus == textarea ||
30.3104 + textarea.getAttribute("autofocus") != null && hasFocus == document.body;
30.3105 + }
30.3106 +
30.3107 + function save() {textarea.value = cm.getValue();}
30.3108 + if (textarea.form) {
30.3109 + // Deplorable hack to make the submit method do the right thing.
30.3110 + on(textarea.form, "submit", save);
30.3111 + var form = textarea.form, realSubmit = form.submit;
30.3112 + try {
30.3113 + form.submit = function wrappedSubmit() {
30.3114 + save();
30.3115 + form.submit = realSubmit;
30.3116 + form.submit();
30.3117 + form.submit = wrappedSubmit;
30.3118 + };
30.3119 + } catch(e) {}
30.3120 + }
30.3121 +
30.3122 + textarea.style.display = "none";
30.3123 + var cm = CodeMirror(function(node) {
30.3124 + textarea.parentNode.insertBefore(node, textarea.nextSibling);
30.3125 + }, options);
30.3126 + cm.save = save;
30.3127 + cm.getTextArea = function() { return textarea; };
30.3128 + cm.toTextArea = function() {
30.3129 + save();
30.3130 + textarea.parentNode.removeChild(cm.getWrapperElement());
30.3131 + textarea.style.display = "";
30.3132 + if (textarea.form) {
30.3133 + off(textarea.form, "submit", save);
30.3134 + if (typeof textarea.form.submit == "function")
30.3135 + textarea.form.submit = realSubmit;
30.3136 + }
30.3137 + };
30.3138 + return cm;
30.3139 + };
30.3140 +
30.3141 + // STRING STREAM
30.3142 +
30.3143 + // Fed to the mode parsers, provides helper functions to make
30.3144 + // parsers more succinct.
30.3145 +
30.3146 + // The character stream used by a mode's parser.
30.3147 + function StringStream(string, tabSize) {
30.3148 + this.pos = this.start = 0;
30.3149 + this.string = string;
30.3150 + this.tabSize = tabSize || 8;
30.3151 + }
30.3152 +
30.3153 + StringStream.prototype = {
30.3154 + eol: function() {return this.pos >= this.string.length;},
30.3155 + sol: function() {return this.pos == 0;},
30.3156 + peek: function() {return this.string.charAt(this.pos) || undefined;},
30.3157 + next: function() {
30.3158 + if (this.pos < this.string.length)
30.3159 + return this.string.charAt(this.pos++);
30.3160 + },
30.3161 + eat: function(match) {
30.3162 + var ch = this.string.charAt(this.pos);
30.3163 + if (typeof match == "string") var ok = ch == match;
30.3164 + else var ok = ch && (match.test ? match.test(ch) : match(ch));
30.3165 + if (ok) {++this.pos; return ch;}
30.3166 + },
30.3167 + eatWhile: function(match) {
30.3168 + var start = this.pos;
30.3169 + while (this.eat(match)){}
30.3170 + return this.pos > start;
30.3171 + },
30.3172 + eatSpace: function() {
30.3173 + var start = this.pos;
30.3174 + while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos;
30.3175 + return this.pos > start;
30.3176 + },
30.3177 + skipToEnd: function() {this.pos = this.string.length;},
30.3178 + skipTo: function(ch) {
30.3179 + var found = this.string.indexOf(ch, this.pos);
30.3180 + if (found > -1) {this.pos = found; return true;}
30.3181 + },
30.3182 + backUp: function(n) {this.pos -= n;},
30.3183 + column: function() {return countColumn(this.string, this.start, this.tabSize);},
30.3184 + indentation: function() {return countColumn(this.string, null, this.tabSize);},
30.3185 + match: function(pattern, consume, caseInsensitive) {
30.3186 + if (typeof pattern == "string") {
30.3187 + var cased = function(str) {return caseInsensitive ? str.toLowerCase() : str;};
30.3188 + if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) {
30.3189 + if (consume !== false) this.pos += pattern.length;
30.3190 + return true;
30.3191 + }
30.3192 + } else {
30.3193 + var match = this.string.slice(this.pos).match(pattern);
30.3194 + if (match && match.index > 0) return null;
30.3195 + if (match && consume !== false) this.pos += match[0].length;
30.3196 + return match;
30.3197 + }
30.3198 + },
30.3199 + current: function(){return this.string.slice(this.start, this.pos);}
30.3200 + };
30.3201 + CodeMirror.StringStream = StringStream;
30.3202 +
30.3203 + // TEXTMARKERS
30.3204 +
30.3205 + function TextMarker(cm, type) {
30.3206 + this.lines = [];
30.3207 + this.type = type;
30.3208 + this.cm = cm;
30.3209 + }
30.3210 +
30.3211 + TextMarker.prototype.clear = function() {
30.3212 + if (this.explicitlyCleared) return;
30.3213 + startOperation(this.cm);
30.3214 + var min = null, max = null;
30.3215 + for (var i = 0; i < this.lines.length; ++i) {
30.3216 + var line = this.lines[i];
30.3217 + var span = getMarkedSpanFor(line.markedSpans, this);
30.3218 + if (span.to != null) max = lineNo(line);
30.3219 + line.markedSpans = removeMarkedSpan(line.markedSpans, span);
30.3220 + if (span.from != null)
30.3221 + min = lineNo(line);
30.3222 + else if (this.collapsed && !lineIsHidden(line))
30.3223 + updateLineHeight(line, textHeight(this.cm.display));
30.3224 + }
30.3225 + if (min != null) regChange(this.cm, min, max + 1);
30.3226 + this.lines.length = 0;
30.3227 + this.explicitlyCleared = true;
30.3228 + if (this.collapsed && this.cm.view.cantEdit) {
30.3229 + this.cm.view.cantEdit = false;
30.3230 + reCheckSelection(this.cm);
30.3231 + }
30.3232 + endOperation(this.cm);
30.3233 + signalLater(this.cm, this, "clear");
30.3234 + };
30.3235 +
30.3236 + TextMarker.prototype.find = function() {
30.3237 + var from, to;
30.3238 + for (var i = 0; i < this.lines.length; ++i) {
30.3239 + var line = this.lines[i];
30.3240 + var span = getMarkedSpanFor(line.markedSpans, this);
30.3241 + if (span.from != null || span.to != null) {
30.3242 + var found = lineNo(line);
30.3243 + if (span.from != null) from = {line: found, ch: span.from};
30.3244 + if (span.to != null) to = {line: found, ch: span.to};
30.3245 + }
30.3246 + }
30.3247 + if (this.type == "bookmark") return from;
30.3248 + return from && {from: from, to: to};
30.3249 + };
30.3250 +
30.3251 + function markText(cm, from, to, options, type) {
30.3252 + var doc = cm.view.doc;
30.3253 + var marker = new TextMarker(cm, type);
30.3254 + if (type == "range" && !posLess(from, to)) return marker;
30.3255 + if (options) for (var opt in options) if (options.hasOwnProperty(opt))
30.3256 + marker[opt] = options[opt];
30.3257 + if (marker.replacedWith) {
30.3258 + marker.collapsed = true;
30.3259 + marker.replacedWith = elt("span", [marker.replacedWith], "CodeMirror-widget");
30.3260 + }
30.3261 + if (marker.collapsed) sawCollapsedSpans = true;
30.3262 +
30.3263 + var curLine = from.line, size = 0, collapsedAtStart, collapsedAtEnd;
30.3264 + doc.iter(curLine, to.line + 1, function(line) {
30.3265 + var span = {from: null, to: null, marker: marker};
30.3266 + size += line.text.length;
30.3267 + if (curLine == from.line) {span.from = from.ch; size -= from.ch;}
30.3268 + if (curLine == to.line) {span.to = to.ch; size -= line.text.length - to.ch;}
30.3269 + if (marker.collapsed) {
30.3270 + if (curLine == to.line) collapsedAtEnd = collapsedSpanAt(line, to.ch);
30.3271 + if (curLine == from.line) collapsedAtStart = collapsedSpanAt(line, from.ch);
30.3272 + else updateLineHeight(line, 0);
30.3273 + }
30.3274 + addMarkedSpan(line, span);
30.3275 + if (marker.collapsed && curLine == from.line && lineIsHidden(line))
30.3276 + updateLineHeight(line, 0);
30.3277 + ++curLine;
30.3278 + });
30.3279 +
30.3280 + if (marker.readOnly) {
30.3281 + sawReadOnlySpans = true;
30.3282 + if (cm.view.history.done.length || cm.view.history.undone.length)
30.3283 + cm.clearHistory();
30.3284 + }
30.3285 + if (marker.collapsed) {
30.3286 + if (collapsedAtStart != collapsedAtEnd)
30.3287 + throw new Error("Inserting collapsed marker overlapping an existing one");
30.3288 + marker.size = size;
30.3289 + marker.atomic = true;
30.3290 + }
30.3291 + if (marker.className || marker.startStyle || marker.endStyle || marker.collapsed)
30.3292 + regChange(cm, from.line, to.line + 1);
30.3293 + if (marker.atomic) reCheckSelection(cm);
30.3294 + return marker;
30.3295 + }
30.3296 +
30.3297 + // TEXTMARKER SPANS
30.3298 +
30.3299 + function getMarkedSpanFor(spans, marker) {
30.3300 + if (spans) for (var i = 0; i < spans.length; ++i) {
30.3301 + var span = spans[i];
30.3302 + if (span.marker == marker) return span;
30.3303 + }
30.3304 + }
30.3305 + function removeMarkedSpan(spans, span) {
30.3306 + for (var r, i = 0; i < spans.length; ++i)
30.3307 + if (spans[i] != span) (r || (r = [])).push(spans[i]);
30.3308 + return r;
30.3309 + }
30.3310 + function addMarkedSpan(line, span) {
30.3311 + line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span];
30.3312 + span.marker.lines.push(line);
30.3313 + }
30.3314 +
30.3315 + function markedSpansBefore(old, startCh) {
30.3316 + if (old) for (var i = 0, nw; i < old.length; ++i) {
30.3317 + var span = old[i], marker = span.marker;
30.3318 + var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh);
30.3319 + if (startsBefore || marker.type == "bookmark" && span.from == startCh) {
30.3320 + var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh);
30.3321 + (nw || (nw = [])).push({from: span.from,
30.3322 + to: endsAfter ? null : span.to,
30.3323 + marker: marker});
30.3324 + }
30.3325 + }
30.3326 + return nw;
30.3327 + }
30.3328 +
30.3329 + function markedSpansAfter(old, startCh, endCh) {
30.3330 + if (old) for (var i = 0, nw; i < old.length; ++i) {
30.3331 + var span = old[i], marker = span.marker;
30.3332 + var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh);
30.3333 + if (endsAfter || marker.type == "bookmark" && span.from == endCh && span.from != startCh) {
30.3334 + var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh);
30.3335 + (nw || (nw = [])).push({from: startsBefore ? null : span.from - endCh,
30.3336 + to: span.to == null ? null : span.to - endCh,
30.3337 + marker: marker});
30.3338 + }
30.3339 + }
30.3340 + return nw;
30.3341 + }
30.3342 +
30.3343 + function updateMarkedSpans(oldFirst, oldLast, startCh, endCh, newText) {
30.3344 + if (!oldFirst && !oldLast) return newText;
30.3345 + // Get the spans that 'stick out' on both sides
30.3346 + var first = markedSpansBefore(oldFirst, startCh);
30.3347 + var last = markedSpansAfter(oldLast, startCh, endCh);
30.3348 +
30.3349 + // Next, merge those two ends
30.3350 + var sameLine = newText.length == 1, offset = lst(newText).length + (sameLine ? startCh : 0);
30.3351 + if (first) {
30.3352 + // Fix up .to properties of first
30.3353 + for (var i = 0; i < first.length; ++i) {
30.3354 + var span = first[i];
30.3355 + if (span.to == null) {
30.3356 + var found = getMarkedSpanFor(last, span.marker);
30.3357 + if (!found) span.to = startCh;
30.3358 + else if (sameLine) span.to = found.to == null ? null : found.to + offset;
30.3359 + }
30.3360 + }
30.3361 + }
30.3362 + if (last) {
30.3363 + // Fix up .from in last (or move them into first in case of sameLine)
30.3364 + for (var i = 0; i < last.length; ++i) {
30.3365 + var span = last[i];
30.3366 + if (span.to != null) span.to += offset;
30.3367 + if (span.from == null) {
30.3368 + var found = getMarkedSpanFor(first, span.marker);
30.3369 + if (!found) {
30.3370 + span.from = offset;
30.3371 + if (sameLine) (first || (first = [])).push(span);
30.3372 + }
30.3373 + } else {
30.3374 + span.from += offset;
30.3375 + if (sameLine) (first || (first = [])).push(span);
30.3376 + }
30.3377 + }
30.3378 + }
30.3379 +
30.3380 + var newMarkers = [newHL(newText[0], first)];
30.3381 + if (!sameLine) {
30.3382 + // Fill gap with whole-line-spans
30.3383 + var gap = newText.length - 2, gapMarkers;
30.3384 + if (gap > 0 && first)
30.3385 + for (var i = 0; i < first.length; ++i)
30.3386 + if (first[i].to == null)
30.3387 + (gapMarkers || (gapMarkers = [])).push({from: null, to: null, marker: first[i].marker});
30.3388 + for (var i = 0; i < gap; ++i)
30.3389 + newMarkers.push(newHL(newText[i+1], gapMarkers));
30.3390 + newMarkers.push(newHL(lst(newText), last));
30.3391 + }
30.3392 + return newMarkers;
30.3393 + }
30.3394 +
30.3395 + function removeReadOnlyRanges(doc, from, to) {
30.3396 + var markers = null;
30.3397 + doc.iter(from.line, to.line + 1, function(line) {
30.3398 + if (line.markedSpans) for (var i = 0; i < line.markedSpans.length; ++i) {
30.3399 + var mark = line.markedSpans[i].marker;
30.3400 + if (mark.readOnly && (!markers || indexOf(markers, mark) == -1))
30.3401 + (markers || (markers = [])).push(mark);
30.3402 + }
30.3403 + });
30.3404 + if (!markers) return null;
30.3405 + var parts = [{from: from, to: to}];
30.3406 + for (var i = 0; i < markers.length; ++i) {
30.3407 + var m = markers[i].find();
30.3408 + for (var j = 0; j < parts.length; ++j) {
30.3409 + var p = parts[j];
30.3410 + if (!posLess(m.from, p.to) || posLess(m.to, p.from)) continue;
30.3411 + var newParts = [j, 1];
30.3412 + if (posLess(p.from, m.from)) newParts.push({from: p.from, to: m.from});
30.3413 + if (posLess(m.to, p.to)) newParts.push({from: m.to, to: p.to});
30.3414 + parts.splice.apply(parts, newParts);
30.3415 + j += newParts.length - 1;
30.3416 + }
30.3417 + }
30.3418 + return parts;
30.3419 + }
30.3420 +
30.3421 + function collapsedSpanAt(line, ch) {
30.3422 + var sps = sawCollapsedSpans && line.markedSpans, found;
30.3423 + if (sps) for (var sp, i = 0; i < sps.length; ++i) {
30.3424 + sp = sps[i];
30.3425 + if (!sp.marker.collapsed) continue;
30.3426 + if ((sp.from == null || sp.from < ch) &&
30.3427 + (sp.to == null || sp.to > ch) &&
30.3428 + (!found || found.width < sp.marker.width))
30.3429 + found = sp.marker;
30.3430 + }
30.3431 + return found;
30.3432 + }
30.3433 + function collapsedSpanAtStart(line) { return collapsedSpanAt(line, -1); }
30.3434 + function collapsedSpanAtEnd(line) { return collapsedSpanAt(line, line.text.length + 1); }
30.3435 +
30.3436 + function visualLine(doc, line) {
30.3437 + var merged;
30.3438 + while (merged = collapsedSpanAtStart(line))
30.3439 + line = getLine(doc, merged.find().from.line);
30.3440 + return line;
30.3441 + }
30.3442 +
30.3443 + function lineIsHidden(line) {
30.3444 + var sps = sawCollapsedSpans && line.markedSpans;
30.3445 + if (sps) for (var sp, i = 0; i < sps.length; ++i) {
30.3446 + sp = sps[i];
30.3447 + if (!sp.marker.collapsed) continue;
30.3448 + if (sp.from == null) return true;
30.3449 + if (sp.from == 0 && sp.marker.inclusiveLeft && lineIsHiddenInner(line, sp))
30.3450 + return true;
30.3451 + }
30.3452 + }
30.3453 + window.lineIsHidden = lineIsHidden;
30.3454 + function lineIsHiddenInner(line, span) {
30.3455 + if (span.to == null || span.marker.inclusiveRight && span.to == line.text.length)
30.3456 + return true;
30.3457 + for (var sp, i = 0; i < line.markedSpans.length; ++i) {
30.3458 + sp = line.markedSpans[i];
30.3459 + if (sp.marker.collapsed && sp.from == span.to &&
30.3460 + (sp.marker.inclusiveLeft || span.marker.inclusiveRight) &&
30.3461 + lineIsHiddenInner(line, sp)) return true;
30.3462 + }
30.3463 + }
30.3464 +
30.3465 + // hl stands for history-line, a data structure that can be either a
30.3466 + // string (line without markers) or a {text, markedSpans} object.
30.3467 + function hlText(val) { return typeof val == "string" ? val : val.text; }
30.3468 + function hlSpans(val) {
30.3469 + if (typeof val == "string") return null;
30.3470 + var spans = val.markedSpans, out = null;
30.3471 + for (var i = 0; i < spans.length; ++i) {
30.3472 + if (spans[i].marker.explicitlyCleared) { if (!out) out = spans.slice(0, i); }
30.3473 + else if (out) out.push(spans[i]);
30.3474 + }
30.3475 + return !out ? spans : out.length ? out : null;
30.3476 + }
30.3477 + function newHL(text, spans) { return spans ? {text: text, markedSpans: spans} : text; }
30.3478 +
30.3479 + function detachMarkedSpans(line) {
30.3480 + var spans = line.markedSpans;
30.3481 + if (!spans) return;
30.3482 + for (var i = 0; i < spans.length; ++i) {
30.3483 + var lines = spans[i].marker.lines;
30.3484 + var ix = indexOf(lines, line);
30.3485 + lines.splice(ix, 1);
30.3486 + }
30.3487 + line.markedSpans = null;
30.3488 + }
30.3489 +
30.3490 + function attachMarkedSpans(line, spans) {
30.3491 + if (!spans) return;
30.3492 + for (var i = 0; i < spans.length; ++i)
30.3493 + spans[i].marker.lines.push(line);
30.3494 + line.markedSpans = spans;
30.3495 + }
30.3496 +
30.3497 + // LINE DATA STRUCTURE
30.3498 +
30.3499 + // Line objects. These hold state related to a line, including
30.3500 + // highlighting info (the styles array).
30.3501 + function makeLine(text, markedSpans, height) {
30.3502 + var line = {text: text, height: height};
30.3503 + attachMarkedSpans(line, markedSpans);
30.3504 + if (lineIsHidden(line)) line.height = 0;
30.3505 + return line;
30.3506 + }
30.3507 +
30.3508 + function updateLine(cm, line, text, markedSpans) {
30.3509 + line.text = text;
30.3510 + line.stateAfter = line.styles = null;
30.3511 + if (line.order != null) line.order = null;
30.3512 + detachMarkedSpans(line);
30.3513 + attachMarkedSpans(line, markedSpans);
30.3514 + if (lineIsHidden(line)) line.height = 0;
30.3515 + else if (!line.height) line.height = textHeight(cm.display);
30.3516 + signalLater(cm, line, "change");
30.3517 + }
30.3518 +
30.3519 + function cleanUpLine(line) {
30.3520 + line.parent = null;
30.3521 + detachMarkedSpans(line);
30.3522 + }
30.3523 +
30.3524 + // Run the given mode's parser over a line, update the styles
30.3525 + // array, which contains alternating fragments of text and CSS
30.3526 + // classes.
30.3527 + function highlightLine(cm, line, state) {
30.3528 + var mode = cm.view.mode, flattenSpans = cm.options.flattenSpans;
30.3529 + var changed = !line.styles, pos = 0, curText = "", curStyle = null;
30.3530 + var stream = new StringStream(line.text, cm.options.tabSize), st = line.styles || (line.styles = []);
30.3531 + if (line.text == "" && mode.blankLine) mode.blankLine(state);
30.3532 + while (!stream.eol()) {
30.3533 + var style = mode.token(stream, state), substr = stream.current();
30.3534 + stream.start = stream.pos;
30.3535 + if (!flattenSpans || curStyle != style) {
30.3536 + if (curText) {
30.3537 + changed = changed || pos >= st.length || curText != st[pos] || curStyle != st[pos+1];
30.3538 + st[pos++] = curText; st[pos++] = curStyle;
30.3539 + }
30.3540 + curText = substr; curStyle = style;
30.3541 + } else curText = curText + substr;
30.3542 + // Give up when line is ridiculously long
30.3543 + if (stream.pos > 5000) break;
30.3544 + }
30.3545 + if (curText) {
30.3546 + changed = changed || pos >= st.length || curText != st[pos] || curStyle != st[pos+1];
30.3547 + st[pos++] = curText; st[pos++] = curStyle;
30.3548 + }
30.3549 + if (stream.pos > 5000) { st[pos++] = line.text.slice(stream.pos); st[pos++] = null; }
30.3550 + if (pos != st.length) { st.length = pos; changed = true; }
30.3551 + return changed;
30.3552 + }
30.3553 +
30.3554 + // Lightweight form of highlight -- proceed over this line and
30.3555 + // update state, but don't save a style array.
30.3556 + function processLine(cm, line, state) {
30.3557 + var mode = cm.view.mode;
30.3558 + var stream = new StringStream(line.text, cm.options.tabSize);
30.3559 + if (line.text == "" && mode.blankLine) mode.blankLine(state);
30.3560 + while (!stream.eol() && stream.pos <= 5000) {
30.3561 + mode.token(stream, state);
30.3562 + stream.start = stream.pos;
30.3563 + }
30.3564 + }
30.3565 +
30.3566 + var styleToClassCache = {};
30.3567 + function styleToClass(style) {
30.3568 + if (!style) return null;
30.3569 + return styleToClassCache[style] ||
30.3570 + (styleToClassCache[style] = "cm-" + style.replace(/ +/g, " cm-"));
30.3571 + }
30.3572 +
30.3573 + function lineContent(cm, realLine, measure) {
30.3574 + var merged, line = realLine, lineBefore, sawBefore, simple = true;
30.3575 + while (merged = collapsedSpanAtStart(line)) {
30.3576 + simple = false;
30.3577 + line = getLine(cm.view.doc, merged.find().from.line);
30.3578 + if (!lineBefore) lineBefore = line;
30.3579 + }
30.3580 +
30.3581 + var builder = {pre: elt("pre"), col: 0, pos: 0, display: !measure,
30.3582 + measure: null, addedOne: false, cm: cm};
30.3583 + if (line.textClass) builder.pre.className = line.textClass;
30.3584 +
30.3585 + do {
30.3586 + if (!line.styles)
30.3587 + highlightLine(cm, line, line.stateAfter = getStateBefore(cm, lineNo(line)));
30.3588 + builder.measure = line == realLine && measure;
30.3589 + builder.pos = 0;
30.3590 + builder.addToken = builder.measure ? buildTokenMeasure : buildToken;
30.3591 + if (measure && sawBefore && line != realLine && !builder.addedOne) {
30.3592 + measure[0] = builder.pre.appendChild(zeroWidthElement(cm.display.measure));
30.3593 + builder.addedOne = true;
30.3594 + }
30.3595 + var next = insertLineContent(line, builder);
30.3596 + sawBefore = line == lineBefore;
30.3597 + if (next) {
30.3598 + line = getLine(cm.view.doc, next.to.line);
30.3599 + simple = false;
30.3600 + }
30.3601 + } while (next);
30.3602 +
30.3603 + if (measure && !builder.addedOne)
30.3604 + measure[0] = builder.pre.appendChild(simple ? elt("span", "\u00a0") : zeroWidthElement(cm.display.measure));
30.3605 + if (!builder.pre.firstChild && !lineIsHidden(realLine))
30.3606 + builder.pre.appendChild(document.createTextNode("\u00a0"));
30.3607 +
30.3608 + return builder.pre;
30.3609 + }
30.3610 +
30.3611 + var tokenSpecialChars = /[\t\u0000-\u0019\u200b\u2028\u2029\uFEFF]/g;
30.3612 + function buildToken(builder, text, style, startStyle, endStyle) {
30.3613 + if (!text) return;
30.3614 + if (!tokenSpecialChars.test(text)) {
30.3615 + builder.col += text.length;
30.3616 + var content = document.createTextNode(text);
30.3617 + } else {
30.3618 + var content = document.createDocumentFragment(), pos = 0;
30.3619 + while (true) {
30.3620 + tokenSpecialChars.lastIndex = pos;
30.3621 + var m = tokenSpecialChars.exec(text);
30.3622 + var skipped = m ? m.index - pos : text.length - pos;
30.3623 + if (skipped) {
30.3624 + content.appendChild(document.createTextNode(text.slice(pos, pos + skipped)));
30.3625 + builder.col += skipped;
30.3626 + }
30.3627 + if (!m) break;
30.3628 + pos += skipped + 1;
30.3629 + if (m[0] == "\t") {
30.3630 + var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize;
30.3631 + content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
30.3632 + builder.col += tabWidth;
30.3633 + } else {
30.3634 + var token = elt("span", "\u2022", "cm-invalidchar");
30.3635 + token.title = "\\u" + m[0].charCodeAt(0).toString(16);
30.3636 + content.appendChild(token);
30.3637 + builder.col += 1;
30.3638 + }
30.3639 + }
30.3640 + }
30.3641 + if (style || startStyle || endStyle || builder.measure) {
30.3642 + var fullStyle = style || "";
30.3643 + if (startStyle) fullStyle += startStyle;
30.3644 + if (endStyle) fullStyle += endStyle;
30.3645 + return builder.pre.appendChild(elt("span", [content], fullStyle));
30.3646 + }
30.3647 + builder.pre.appendChild(content);
30.3648 + }
30.3649 +
30.3650 + function buildTokenMeasure(builder, text, style, startStyle, endStyle) {
30.3651 + for (var i = 0; i < text.length; ++i) {
30.3652 + if (i && i < text.length - 1 &&
30.3653 + builder.cm.options.lineWrapping &&
30.3654 + spanAffectsWrapping.test(text.slice(i - 1, i + 1)))
30.3655 + builder.pre.appendChild(elt("wbr"));
30.3656 + builder.measure[builder.pos++] =
30.3657 + buildToken(builder, text.charAt(i), style,
30.3658 + i == 0 && startStyle, i == text.length - 1 && endStyle);
30.3659 + }
30.3660 + if (text.length) builder.addedOne = true;
30.3661 + }
30.3662 +
30.3663 + function buildCollapsedSpan(builder, size, widget) {
30.3664 + if (widget) {
30.3665 + if (!builder.display) widget = widget.cloneNode(true);
30.3666 + builder.pre.appendChild(widget);
30.3667 + if (builder.measure && size) {
30.3668 + builder.measure[builder.pos] = widget;
30.3669 + builder.addedOne = true;
30.3670 + }
30.3671 + }
30.3672 + builder.pos += size;
30.3673 + }
30.3674 +
30.3675 + // Outputs a number of spans to make up a line, taking highlighting
30.3676 + // and marked text into account.
30.3677 + function insertLineContent(line, builder) {
30.3678 + var st = line.styles, spans = line.markedSpans;
30.3679 + if (!spans) {
30.3680 + for (var i = 0; i < st.length; i+=2)
30.3681 + builder.addToken(builder, st[i], styleToClass(st[i+1]));
30.3682 + return;
30.3683 + }
30.3684 +
30.3685 + var allText = line.text, len = allText.length;
30.3686 + var pos = 0, i = 0, text = "", style;
30.3687 + var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, collapsed;
30.3688 + for (;;) {
30.3689 + if (nextChange == pos) { // Update current marker set
30.3690 + spanStyle = spanEndStyle = spanStartStyle = "";
30.3691 + collapsed = null; nextChange = Infinity;
30.3692 + var foundBookmark = null;
30.3693 + for (var j = 0; j < spans.length; ++j) {
30.3694 + var sp = spans[j], m = sp.marker;
30.3695 + if (sp.from <= pos && (sp.to == null || sp.to > pos)) {
30.3696 + if (sp.to != null && nextChange > sp.to) { nextChange = sp.to; spanEndStyle = ""; }
30.3697 + if (m.className) spanStyle += " " + m.className;
30.3698 + if (m.startStyle && sp.from == pos) spanStartStyle += " " + m.startStyle;
30.3699 + if (m.endStyle && sp.to == nextChange) spanEndStyle += " " + m.endStyle;
30.3700 + if (m.collapsed && (!collapsed || collapsed.marker.width < m.width))
30.3701 + collapsed = sp;
30.3702 + } else if (sp.from > pos && nextChange > sp.from) {
30.3703 + nextChange = sp.from;
30.3704 + }
30.3705 + if (m.type == "bookmark" && sp.from == pos && m.replacedWith)
30.3706 + foundBookmark = m.replacedWith;
30.3707 + }
30.3708 + if (collapsed && (collapsed.from || 0) == pos) {
30.3709 + buildCollapsedSpan(builder, (collapsed.to == null ? len : collapsed.to) - pos,
30.3710 + collapsed.from != null && collapsed.marker.replacedWith);
30.3711 + if (collapsed.to == null) return collapsed.marker.find();
30.3712 + }
30.3713 + if (foundBookmark && !collapsed) buildCollapsedSpan(builder, 0, foundBookmark);
30.3714 + }
30.3715 + if (pos >= len) break;
30.3716 +
30.3717 + var upto = Math.min(len, nextChange);
30.3718 + while (true) {
30.3719 + if (text) {
30.3720 + var end = pos + text.length;
30.3721 + if (!collapsed) {
30.3722 + var tokenText = end > upto ? text.slice(0, upto - pos) : text;
30.3723 + builder.addToken(builder, tokenText, style + spanStyle,
30.3724 + spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "");
30.3725 + }
30.3726 + if (end >= upto) {text = text.slice(upto - pos); pos = upto; break;}
30.3727 + pos = end;
30.3728 + spanStartStyle = "";
30.3729 + }
30.3730 + text = st[i++]; style = styleToClass(st[i++]);
30.3731 + }
30.3732 + }
30.3733 + }
30.3734 +
30.3735 + // DOCUMENT DATA STRUCTURE
30.3736 +
30.3737 + function LeafChunk(lines) {
30.3738 + this.lines = lines;
30.3739 + this.parent = null;
30.3740 + for (var i = 0, e = lines.length, height = 0; i < e; ++i) {
30.3741 + lines[i].parent = this;
30.3742 + height += lines[i].height;
30.3743 + }
30.3744 + this.height = height;
30.3745 + }
30.3746 +
30.3747 + LeafChunk.prototype = {
30.3748 + chunkSize: function() { return this.lines.length; },
30.3749 + remove: function(at, n, cm) {
30.3750 + for (var i = at, e = at + n; i < e; ++i) {
30.3751 + var line = this.lines[i];
30.3752 + this.height -= line.height;
30.3753 + cleanUpLine(line);
30.3754 + signalLater(cm, line, "delete");
30.3755 + }
30.3756 + this.lines.splice(at, n);
30.3757 + },
30.3758 + collapse: function(lines) {
30.3759 + lines.splice.apply(lines, [lines.length, 0].concat(this.lines));
30.3760 + },
30.3761 + insertHeight: function(at, lines, height) {
30.3762 + this.height += height;
30.3763 + this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at));
30.3764 + for (var i = 0, e = lines.length; i < e; ++i) lines[i].parent = this;
30.3765 + },
30.3766 + iterN: function(at, n, op) {
30.3767 + for (var e = at + n; at < e; ++at)
30.3768 + if (op(this.lines[at])) return true;
30.3769 + }
30.3770 + };
30.3771 +
30.3772 + function BranchChunk(children) {
30.3773 + this.children = children;
30.3774 + var size = 0, height = 0;
30.3775 + for (var i = 0, e = children.length; i < e; ++i) {
30.3776 + var ch = children[i];
30.3777 + size += ch.chunkSize(); height += ch.height;
30.3778 + ch.parent = this;
30.3779 + }
30.3780 + this.size = size;
30.3781 + this.height = height;
30.3782 + this.parent = null;
30.3783 + }
30.3784 +
30.3785 + BranchChunk.prototype = {
30.3786 + chunkSize: function() { return this.size; },
30.3787 + remove: function(at, n, callbacks) {
30.3788 + this.size -= n;
30.3789 + for (var i = 0; i < this.children.length; ++i) {
30.3790 + var child = this.children[i], sz = child.chunkSize();
30.3791 + if (at < sz) {
30.3792 + var rm = Math.min(n, sz - at), oldHeight = child.height;
30.3793 + child.remove(at, rm, callbacks);
30.3794 + this.height -= oldHeight - child.height;
30.3795 + if (sz == rm) { this.children.splice(i--, 1); child.parent = null; }
30.3796 + if ((n -= rm) == 0) break;
30.3797 + at = 0;
30.3798 + } else at -= sz;
30.3799 + }
30.3800 + if (this.size - n < 25) {
30.3801 + var lines = [];
30.3802 + this.collapse(lines);
30.3803 + this.children = [new LeafChunk(lines)];
30.3804 + this.children[0].parent = this;
30.3805 + }
30.3806 + },
30.3807 + collapse: function(lines) {
30.3808 + for (var i = 0, e = this.children.length; i < e; ++i) this.children[i].collapse(lines);
30.3809 + },
30.3810 + insert: function(at, lines) {
30.3811 + var height = 0;
30.3812 + for (var i = 0, e = lines.length; i < e; ++i) height += lines[i].height;
30.3813 + this.insertHeight(at, lines, height);
30.3814 + },
30.3815 + insertHeight: function(at, lines, height) {
30.3816 + this.size += lines.length;
30.3817 + this.height += height;
30.3818 + for (var i = 0, e = this.children.length; i < e; ++i) {
30.3819 + var child = this.children[i], sz = child.chunkSize();
30.3820 + if (at <= sz) {
30.3821 + child.insertHeight(at, lines, height);
30.3822 + if (child.lines && child.lines.length > 50) {
30.3823 + while (child.lines.length > 50) {
30.3824 + var spilled = child.lines.splice(child.lines.length - 25, 25);
30.3825 + var newleaf = new LeafChunk(spilled);
30.3826 + child.height -= newleaf.height;
30.3827 + this.children.splice(i + 1, 0, newleaf);
30.3828 + newleaf.parent = this;
30.3829 + }
30.3830 + this.maybeSpill();
30.3831 + }
30.3832 + break;
30.3833 + }
30.3834 + at -= sz;
30.3835 + }
30.3836 + },
30.3837 + maybeSpill: function() {
30.3838 + if (this.children.length <= 10) return;
30.3839 + var me = this;
30.3840 + do {
30.3841 + var spilled = me.children.splice(me.children.length - 5, 5);
30.3842 + var sibling = new BranchChunk(spilled);
30.3843 + if (!me.parent) { // Become the parent node
30.3844 + var copy = new BranchChunk(me.children);
30.3845 + copy.parent = me;
30.3846 + me.children = [copy, sibling];
30.3847 + me = copy;
30.3848 + } else {
30.3849 + me.size -= sibling.size;
30.3850 + me.height -= sibling.height;
30.3851 + var myIndex = indexOf(me.parent.children, me);
30.3852 + me.parent.children.splice(myIndex + 1, 0, sibling);
30.3853 + }
30.3854 + sibling.parent = me.parent;
30.3855 + } while (me.children.length > 10);
30.3856 + me.parent.maybeSpill();
30.3857 + },
30.3858 + iter: function(from, to, op) { this.iterN(from, to - from, op); },
30.3859 + iterN: function(at, n, op) {
30.3860 + for (var i = 0, e = this.children.length; i < e; ++i) {
30.3861 + var child = this.children[i], sz = child.chunkSize();
30.3862 + if (at < sz) {
30.3863 + var used = Math.min(n, sz - at);
30.3864 + if (child.iterN(at, used, op)) return true;
30.3865 + if ((n -= used) == 0) break;
30.3866 + at = 0;
30.3867 + } else at -= sz;
30.3868 + }
30.3869 + }
30.3870 + };
30.3871 +
30.3872 + // LINE UTILITIES
30.3873 +
30.3874 + function getLine(chunk, n) {
30.3875 + while (!chunk.lines) {
30.3876 + for (var i = 0;; ++i) {
30.3877 + var child = chunk.children[i], sz = child.chunkSize();
30.3878 + if (n < sz) { chunk = child; break; }
30.3879 + n -= sz;
30.3880 + }
30.3881 + }
30.3882 + return chunk.lines[n];
30.3883 + }
30.3884 +
30.3885 + function updateLineHeight(line, height) {
30.3886 + var diff = height - line.height;
30.3887 + for (var n = line; n; n = n.parent) n.height += diff;
30.3888 + }
30.3889 +
30.3890 + function lineNo(line) {
30.3891 + if (line.parent == null) return null;
30.3892 + var cur = line.parent, no = indexOf(cur.lines, line);
30.3893 + for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
30.3894 + for (var i = 0;; ++i) {
30.3895 + if (chunk.children[i] == cur) break;
30.3896 + no += chunk.children[i].chunkSize();
30.3897 + }
30.3898 + }
30.3899 + return no;
30.3900 + }
30.3901 +
30.3902 + function lineAtHeight(chunk, h) {
30.3903 + var n = 0;
30.3904 + outer: do {
30.3905 + for (var i = 0, e = chunk.children.length; i < e; ++i) {
30.3906 + var child = chunk.children[i], ch = child.height;
30.3907 + if (h < ch) { chunk = child; continue outer; }
30.3908 + h -= ch;
30.3909 + n += child.chunkSize();
30.3910 + }
30.3911 + return n;
30.3912 + } while (!chunk.lines);
30.3913 + for (var i = 0, e = chunk.lines.length; i < e; ++i) {
30.3914 + var line = chunk.lines[i], lh = line.height;
30.3915 + if (h < lh) break;
30.3916 + h -= lh;
30.3917 + }
30.3918 + return n + i;
30.3919 + }
30.3920 +
30.3921 + function heightAtLine(cm, lineObj) {
30.3922 + lineObj = visualLine(cm.view.doc, lineObj);
30.3923 +
30.3924 + var h = 0, chunk = lineObj.parent;
30.3925 + for (var i = 0; i < chunk.lines.length; ++i) {
30.3926 + var line = chunk.lines[i];
30.3927 + if (line == lineObj) break;
30.3928 + else h += line.height;
30.3929 + }
30.3930 + for (var p = chunk.parent; p; chunk = p, p = chunk.parent) {
30.3931 + for (var i = 0; i < p.children.length; ++i) {
30.3932 + var cur = p.children[i];
30.3933 + if (cur == chunk) break;
30.3934 + else h += cur.height;
30.3935 + }
30.3936 + }
30.3937 + return h;
30.3938 + }
30.3939 +
30.3940 + function getOrder(line) {
30.3941 + var order = line.order;
30.3942 + if (order == null) order = line.order = bidiOrdering(line.text);
30.3943 + return order;
30.3944 + }
30.3945 +
30.3946 + // HISTORY
30.3947 +
30.3948 + function makeHistory() {
30.3949 + return {
30.3950 + // Arrays of history events. Doing something adds an event to
30.3951 + // done and clears undo. Undoing moves events from done to
30.3952 + // undone, redoing moves them in the other direction.
30.3953 + done: [], undone: [],
30.3954 + // Used to track when changes can be merged into a single undo
30.3955 + // event
30.3956 + lastTime: 0, lastOp: null, lastOrigin: null,
30.3957 + // Used by the isClean() method
30.3958 + dirtyCounter: 0
30.3959 + };
30.3960 + }
30.3961 +
30.3962 + function addChange(cm, start, added, old, origin, fromBefore, toBefore, fromAfter, toAfter) {
30.3963 + var history = cm.view.history;
30.3964 + history.undone.length = 0;
30.3965 + var time = +new Date, cur = lst(history.done);
30.3966 +
30.3967 + if (cur &&
30.3968 + (history.lastOp == cm.curOp.id ||
30.3969 + history.lastOrigin == origin && (origin == "input" || origin == "delete") &&
30.3970 + history.lastTime > time - 600)) {
30.3971 + // Merge this change into the last event
30.3972 + var last = lst(cur.events);
30.3973 + if (last.start > start + old.length || last.start + last.added < start) {
30.3974 + // Doesn't intersect with last sub-event, add new sub-event
30.3975 + cur.events.push({start: start, added: added, old: old});
30.3976 + } else {
30.3977 + // Patch up the last sub-event
30.3978 + var startBefore = Math.max(0, last.start - start),
30.3979 + endAfter = Math.max(0, (start + old.length) - (last.start + last.added));
30.3980 + for (var i = startBefore; i > 0; --i) last.old.unshift(old[i - 1]);
30.3981 + for (var i = endAfter; i > 0; --i) last.old.push(old[old.length - i]);
30.3982 + if (startBefore) last.start = start;
30.3983 + last.added += added - (old.length - startBefore - endAfter);
30.3984 + }
30.3985 + cur.fromAfter = fromAfter; cur.toAfter = toAfter;
30.3986 + } else {
30.3987 + // Can not be merged, start a new event.
30.3988 + cur = {events: [{start: start, added: added, old: old}],
30.3989 + fromBefore: fromBefore, toBefore: toBefore, fromAfter: fromAfter, toAfter: toAfter};
30.3990 + history.done.push(cur);
30.3991 + while (history.done.length > cm.options.undoDepth)
30.3992 + history.done.shift();
30.3993 + if (history.dirtyCounter < 0)
30.3994 + // The user has made a change after undoing past the last clean state.
30.3995 + // We can never get back to a clean state now until markClean() is called.
30.3996 + history.dirtyCounter = NaN;
30.3997 + else
30.3998 + history.dirtyCounter++;
30.3999 + }
30.4000 + history.lastTime = time;
30.4001 + history.lastOp = cm.curOp.id;
30.4002 + history.lastOrigin = origin;
30.4003 + }
30.4004 +
30.4005 + // EVENT OPERATORS
30.4006 +
30.4007 + function stopMethod() {e_stop(this);}
30.4008 + // Ensure an event has a stop method.
30.4009 + function addStop(event) {
30.4010 + if (!event.stop) event.stop = stopMethod;
30.4011 + return event;
30.4012 + }
30.4013 +
30.4014 + function e_preventDefault(e) {
30.4015 + if (e.preventDefault) e.preventDefault();
30.4016 + else e.returnValue = false;
30.4017 + }
30.4018 + function e_stopPropagation(e) {
30.4019 + if (e.stopPropagation) e.stopPropagation();
30.4020 + else e.cancelBubble = true;
30.4021 + }
30.4022 + function e_stop(e) {e_preventDefault(e); e_stopPropagation(e);}
30.4023 + CodeMirror.e_stop = e_stop;
30.4024 + CodeMirror.e_preventDefault = e_preventDefault;
30.4025 + CodeMirror.e_stopPropagation = e_stopPropagation;
30.4026 +
30.4027 + function e_target(e) {return e.target || e.srcElement;}
30.4028 + function e_button(e) {
30.4029 + var b = e.which;
30.4030 + if (b == null) {
30.4031 + if (e.button & 1) b = 1;
30.4032 + else if (e.button & 2) b = 3;
30.4033 + else if (e.button & 4) b = 2;
30.4034 + }
30.4035 + if (mac && e.ctrlKey && b == 1) b = 3;
30.4036 + return b;
30.4037 + }
30.4038 +
30.4039 + // Allow 3rd-party code to override event properties by adding an override
30.4040 + // object to an event object.
30.4041 + function e_prop(e, prop) {
30.4042 + var overridden = e.override && e.override.hasOwnProperty(prop);
30.4043 + return overridden ? e.override[prop] : e[prop];
30.4044 + }
30.4045 +
30.4046 + // EVENT HANDLING
30.4047 +
30.4048 + function on(emitter, type, f) {
30.4049 + if (emitter.addEventListener)
30.4050 + emitter.addEventListener(type, f, false);
30.4051 + else if (emitter.attachEvent)
30.4052 + emitter.attachEvent("on" + type, f);
30.4053 + else {
30.4054 + var map = emitter._handlers || (emitter._handlers = {});
30.4055 + var arr = map[type] || (map[type] = []);
30.4056 + arr.push(f);
30.4057 + }
30.4058 + }
30.4059 +
30.4060 + function off(emitter, type, f) {
30.4061 + if (emitter.removeEventListener)
30.4062 + emitter.removeEventListener(type, f, false);
30.4063 + else if (emitter.detachEvent)
30.4064 + emitter.detachEvent("on" + type, f);
30.4065 + else {
30.4066 + var arr = emitter._handlers && emitter._handlers[type];
30.4067 + if (!arr) return;
30.4068 + for (var i = 0; i < arr.length; ++i)
30.4069 + if (arr[i] == f) { arr.splice(i, 1); break; }
30.4070 + }
30.4071 + }
30.4072 +
30.4073 + function signal(emitter, type /*, values...*/) {
30.4074 + var arr = emitter._handlers && emitter._handlers[type];
30.4075 + if (!arr) return;
30.4076 + var args = Array.prototype.slice.call(arguments, 2);
30.4077 + for (var i = 0; i < arr.length; ++i) arr[i].apply(null, args);
30.4078 + }
30.4079 +
30.4080 + function signalLater(cm, emitter, type /*, values...*/) {
30.4081 + var arr = emitter._handlers && emitter._handlers[type];
30.4082 + if (!arr) return;
30.4083 + var args = Array.prototype.slice.call(arguments, 3), flist = cm.curOp && cm.curOp.delayedCallbacks;
30.4084 + function bnd(f) {return function(){f.apply(null, args);};};
30.4085 + for (var i = 0; i < arr.length; ++i)
30.4086 + if (flist) flist.push(bnd(arr[i]));
30.4087 + else arr[i].apply(null, args);
30.4088 + }
30.4089 +
30.4090 + function hasHandler(emitter, type) {
30.4091 + var arr = emitter._handlers && emitter._handlers[type];
30.4092 + return arr && arr.length > 0;
30.4093 + }
30.4094 +
30.4095 + CodeMirror.on = on; CodeMirror.off = off; CodeMirror.signal = signal;
30.4096 +
30.4097 + // MISC UTILITIES
30.4098 +
30.4099 + // Number of pixels added to scroller and sizer to hide scrollbar
30.4100 + var scrollerCutOff = 30;
30.4101 +
30.4102 + // Returned or thrown by various protocols to signal 'I'm not
30.4103 + // handling this'.
30.4104 + var Pass = CodeMirror.Pass = {toString: function(){return "CodeMirror.Pass";}};
30.4105 +
30.4106 + function Delayed() {this.id = null;}
30.4107 + Delayed.prototype = {set: function(ms, f) {clearTimeout(this.id); this.id = setTimeout(f, ms);}};
30.4108 +
30.4109 + // Counts the column offset in a string, taking tabs into account.
30.4110 + // Used mostly to find indentation.
30.4111 + function countColumn(string, end, tabSize) {
30.4112 + if (end == null) {
30.4113 + end = string.search(/[^\s\u00a0]/);
30.4114 + if (end == -1) end = string.length;
30.4115 + }
30.4116 + for (var i = 0, n = 0; i < end; ++i) {
30.4117 + if (string.charAt(i) == "\t") n += tabSize - (n % tabSize);
30.4118 + else ++n;
30.4119 + }
30.4120 + return n;
30.4121 + }
30.4122 + CodeMirror.countColumn = countColumn;
30.4123 +
30.4124 + var spaceStrs = [""];
30.4125 + function spaceStr(n) {
30.4126 + while (spaceStrs.length <= n)
30.4127 + spaceStrs.push(lst(spaceStrs) + " ");
30.4128 + return spaceStrs[n];
30.4129 + }
30.4130 +
30.4131 + function lst(arr) { return arr[arr.length-1]; }
30.4132 +
30.4133 + function selectInput(node) {
30.4134 + if (ios) { // Mobile Safari apparently has a bug where select() is broken.
30.4135 + node.selectionStart = 0;
30.4136 + node.selectionEnd = node.value.length;
30.4137 + } else node.select();
30.4138 + }
30.4139 +
30.4140 + function indexOf(collection, elt) {
30.4141 + if (collection.indexOf) return collection.indexOf(elt);
30.4142 + for (var i = 0, e = collection.length; i < e; ++i)
30.4143 + if (collection[i] == elt) return i;
30.4144 + return -1;
30.4145 + }
30.4146 +
30.4147 + function emptyArray(size) {
30.4148 + for (var a = [], i = 0; i < size; ++i) a.push(undefined);
30.4149 + return a;
30.4150 + }
30.4151 +
30.4152 + function bind(f) {
30.4153 + var args = Array.prototype.slice.call(arguments, 1);
30.4154 + return function(){return f.apply(null, args);};
30.4155 + }
30.4156 +
30.4157 + var nonASCIISingleCaseWordChar = /[\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc]/;
30.4158 + function isWordChar(ch) {
30.4159 + return /\w/.test(ch) || ch > "\x80" &&
30.4160 + (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch));
30.4161 + }
30.4162 +
30.4163 + function isEmpty(obj) {
30.4164 + var c = 0;
30.4165 + for (var n in obj) if (obj.hasOwnProperty(n) && obj[n]) ++c;
30.4166 + return !c;
30.4167 + }
30.4168 +
30.4169 + var isExtendingChar = /[\u0300-\u036F\u0483-\u0487\u0488-\u0489\u0591-\u05BD\u05BF\u05C1-\u05C2\u05C4-\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7-\u06E8\u06EA-\u06ED\uA66F\uA670-\uA672\uA674-\uA67D\uA69F]/;
30.4170 +
30.4171 + // DOM UTILITIES
30.4172 +
30.4173 + function elt(tag, content, className, style) {
30.4174 + var e = document.createElement(tag);
30.4175 + if (className) e.className = className;
30.4176 + if (style) e.style.cssText = style;
30.4177 + if (typeof content == "string") setTextContent(e, content);
30.4178 + else if (content) for (var i = 0; i < content.length; ++i) e.appendChild(content[i]);
30.4179 + return e;
30.4180 + }
30.4181 +
30.4182 + function removeChildren(e) {
30.4183 + e.innerHTML = "";
30.4184 + return e;
30.4185 + }
30.4186 +
30.4187 + function removeChildrenAndAdd(parent, e) {
30.4188 + return removeChildren(parent).appendChild(e);
30.4189 + }
30.4190 +
30.4191 + function setTextContent(e, str) {
30.4192 + if (ie_lt9) {
30.4193 + e.innerHTML = "";
30.4194 + e.appendChild(document.createTextNode(str));
30.4195 + } else e.textContent = str;
30.4196 + }
30.4197 +
30.4198 + // FEATURE DETECTION
30.4199 +
30.4200 + // Detect drag-and-drop
30.4201 + var dragAndDrop = function() {
30.4202 + // There is *some* kind of drag-and-drop support in IE6-8, but I
30.4203 + // couldn't get it to work yet.
30.4204 + if (ie_lt9) return false;
30.4205 + var div = elt('div');
30.4206 + return "draggable" in div || "dragDrop" in div;
30.4207 + }();
30.4208 +
30.4209 + // For a reason I have yet to figure out, some browsers disallow
30.4210 + // word wrapping between certain characters *only* if a new inline
30.4211 + // element is started between them. This makes it hard to reliably
30.4212 + // measure the position of things, since that requires inserting an
30.4213 + // extra span. This terribly fragile set of regexps matches the
30.4214 + // character combinations that suffer from this phenomenon on the
30.4215 + // various browsers.
30.4216 + var spanAffectsWrapping = /^$/; // Won't match any two-character string
30.4217 + if (gecko) spanAffectsWrapping = /$'/;
30.4218 + else if (safari) spanAffectsWrapping = /\-[^ \-?]|\?[^ !'\"\),.\-\/:;\?\]\}]/;
30.4219 + else if (chrome) spanAffectsWrapping = /\-[^ \-\.?]|\?[^ \-\.?\]\}:;!'\"\),\/]|[\.!\"#&%\)*+,:;=>\]|\}~][\(\{\[<]|\$'/;
30.4220 +
30.4221 + var knownScrollbarWidth;
30.4222 + function scrollbarWidth(measure) {
30.4223 + if (knownScrollbarWidth != null) return knownScrollbarWidth;
30.4224 + var test = elt("div", null, null, "width: 50px; height: 50px; overflow-x: scroll");
30.4225 + removeChildrenAndAdd(measure, test);
30.4226 + if (test.offsetWidth)
30.4227 + knownScrollbarWidth = test.offsetHeight - test.clientHeight;
30.4228 + return knownScrollbarWidth || 0;
30.4229 + }
30.4230 +
30.4231 + var zwspSupported;
30.4232 + function zeroWidthElement(measure) {
30.4233 + if (zwspSupported == null) {
30.4234 + var test = elt("span", "\u200b");
30.4235 + removeChildrenAndAdd(measure, elt("span", [test, document.createTextNode("x")]));
30.4236 + if (measure.firstChild.offsetHeight != 0)
30.4237 + zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !ie_lt8;
30.4238 + }
30.4239 + if (zwspSupported) return elt("span", "\u200b");
30.4240 + else return elt("span", "\u00a0", null, "display: inline-block; width: 1px; margin-right: -1px");
30.4241 + }
30.4242 +
30.4243 + // See if "".split is the broken IE version, if so, provide an
30.4244 + // alternative way to split lines.
30.4245 + var splitLines = "\n\nb".split(/\n/).length != 3 ? function(string) {
30.4246 + var pos = 0, result = [], l = string.length;
30.4247 + while (pos <= l) {
30.4248 + var nl = string.indexOf("\n", pos);
30.4249 + if (nl == -1) nl = string.length;
30.4250 + var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl);
30.4251 + var rt = line.indexOf("\r");
30.4252 + if (rt != -1) {
30.4253 + result.push(line.slice(0, rt));
30.4254 + pos += rt + 1;
30.4255 + } else {
30.4256 + result.push(line);
30.4257 + pos = nl + 1;
30.4258 + }
30.4259 + }
30.4260 + return result;
30.4261 + } : function(string){return string.split(/\r\n?|\n/);};
30.4262 + CodeMirror.splitLines = splitLines;
30.4263 +
30.4264 + var hasSelection = window.getSelection ? function(te) {
30.4265 + try { return te.selectionStart != te.selectionEnd; }
30.4266 + catch(e) { return false; }
30.4267 + } : function(te) {
30.4268 + try {var range = te.ownerDocument.selection.createRange();}
30.4269 + catch(e) {}
30.4270 + if (!range || range.parentElement() != te) return false;
30.4271 + return range.compareEndPoints("StartToEnd", range) != 0;
30.4272 + };
30.4273 +
30.4274 + var hasCopyEvent = (function() {
30.4275 + var e = elt("div");
30.4276 + if ("oncopy" in e) return true;
30.4277 + e.setAttribute("oncopy", "return;");
30.4278 + return typeof e.oncopy == 'function';
30.4279 + })();
30.4280 +
30.4281 + // KEY NAMING
30.4282 +
30.4283 + var keyNames = {3: "Enter", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
30.4284 + 19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End",
30.4285 + 36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert",
30.4286 + 46: "Delete", 59: ";", 91: "Mod", 92: "Mod", 93: "Mod", 109: "-", 107: "=", 127: "Delete",
30.4287 + 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
30.4288 + 221: "]", 222: "'", 63276: "PageUp", 63277: "PageDown", 63275: "End", 63273: "Home",
30.4289 + 63234: "Left", 63232: "Up", 63235: "Right", 63233: "Down", 63302: "Insert", 63272: "Delete"};
30.4290 + CodeMirror.keyNames = keyNames;
30.4291 + (function() {
30.4292 + // Number keys
30.4293 + for (var i = 0; i < 10; i++) keyNames[i + 48] = String(i);
30.4294 + // Alphabetic keys
30.4295 + for (var i = 65; i <= 90; i++) keyNames[i] = String.fromCharCode(i);
30.4296 + // Function keys
30.4297 + for (var i = 1; i <= 12; i++) keyNames[i + 111] = keyNames[i + 63235] = "F" + i;
30.4298 + })();
30.4299 +
30.4300 + // BIDI HELPERS
30.4301 +
30.4302 + function iterateBidiSections(order, from, to, f) {
30.4303 + if (!order) return f(from, to, "ltr");
30.4304 + for (var i = 0; i < order.length; ++i) {
30.4305 + var part = order[i];
30.4306 + if (part.from < to && part.to > from)
30.4307 + f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr");
30.4308 + }
30.4309 + }
30.4310 +
30.4311 + function bidiLeft(part) { return part.level % 2 ? part.to : part.from; }
30.4312 + function bidiRight(part) { return part.level % 2 ? part.from : part.to; }
30.4313 +
30.4314 + function lineLeft(line) { var order = getOrder(line); return order ? bidiLeft(order[0]) : 0; }
30.4315 + function lineRight(line) {
30.4316 + var order = getOrder(line);
30.4317 + if (!order) return line.text.length;
30.4318 + return bidiRight(lst(order));
30.4319 + }
30.4320 +
30.4321 + function lineStart(cm, lineN) {
30.4322 + var line = getLine(cm.view.doc, lineN);
30.4323 + var visual = visualLine(cm.view.doc, line);
30.4324 + if (visual != line) lineN = lineNo(visual);
30.4325 + var order = getOrder(visual);
30.4326 + var ch = !order ? 0 : order[0].level % 2 ? lineRight(visual) : lineLeft(visual);
30.4327 + return {line: lineN, ch: ch};
30.4328 + }
30.4329 + function lineEnd(cm, lineNo) {
30.4330 + var merged, line;
30.4331 + while (merged = collapsedSpanAtEnd(line = getLine(cm.view.doc, lineNo)))
30.4332 + lineNo = merged.find().to.line;
30.4333 + var order = getOrder(line);
30.4334 + var ch = !order ? line.text.length : order[0].level % 2 ? lineLeft(line) : lineRight(line);
30.4335 + return {line: lineNo, ch: ch};
30.4336 + }
30.4337 +
30.4338 + // This is somewhat involved. It is needed in order to move
30.4339 + // 'visually' through bi-directional text -- i.e., pressing left
30.4340 + // should make the cursor go left, even when in RTL text. The
30.4341 + // tricky part is the 'jumps', where RTL and LTR text touch each
30.4342 + // other. This often requires the cursor offset to move more than
30.4343 + // one unit, in order to visually move one unit.
30.4344 + function moveVisually(line, start, dir, byUnit) {
30.4345 + var bidi = getOrder(line);
30.4346 + if (!bidi) return moveLogically(line, start, dir, byUnit);
30.4347 + var moveOneUnit = byUnit ? function(pos, dir) {
30.4348 + do pos += dir;
30.4349 + while (pos > 0 && isExtendingChar.test(line.text.charAt(pos)));
30.4350 + return pos;
30.4351 + } : function(pos, dir) { return pos + dir; };
30.4352 + var linedir = bidi[0].level;
30.4353 + for (var i = 0; i < bidi.length; ++i) {
30.4354 + var part = bidi[i], sticky = part.level % 2 == linedir;
30.4355 + if ((part.from < start && part.to > start) ||
30.4356 + (sticky && (part.from == start || part.to == start))) break;
30.4357 + }
30.4358 + var target = moveOneUnit(start, part.level % 2 ? -dir : dir);
30.4359 +
30.4360 + while (target != null) {
30.4361 + if (part.level % 2 == linedir) {
30.4362 + if (target < part.from || target > part.to) {
30.4363 + part = bidi[i += dir];
30.4364 + target = part && (dir > 0 == part.level % 2 ? moveOneUnit(part.to, -1) : moveOneUnit(part.from, 1));
30.4365 + } else break;
30.4366 + } else {
30.4367 + if (target == bidiLeft(part)) {
30.4368 + part = bidi[--i];
30.4369 + target = part && bidiRight(part);
30.4370 + } else if (target == bidiRight(part)) {
30.4371 + part = bidi[++i];
30.4372 + target = part && bidiLeft(part);
30.4373 + } else break;
30.4374 + }
30.4375 + }
30.4376 +
30.4377 + return target < 0 || target > line.text.length ? null : target;
30.4378 + }
30.4379 +
30.4380 + function moveLogically(line, start, dir, byUnit) {
30.4381 + var target = start + dir;
30.4382 + if (byUnit) while (target > 0 && isExtendingChar.test(line.text.charAt(target))) target += dir;
30.4383 + return target < 0 || target > line.text.length ? null : target;
30.4384 + }
30.4385 +
30.4386 + // Bidirectional ordering algorithm
30.4387 + // See http://unicode.org/reports/tr9/tr9-13.html for the algorithm
30.4388 + // that this (partially) implements.
30.4389 +
30.4390 + // One-char codes used for character types:
30.4391 + // L (L): Left-to-Right
30.4392 + // R (R): Right-to-Left
30.4393 + // r (AL): Right-to-Left Arabic
30.4394 + // 1 (EN): European Number
30.4395 + // + (ES): European Number Separator
30.4396 + // % (ET): European Number Terminator
30.4397 + // n (AN): Arabic Number
30.4398 + // , (CS): Common Number Separator
30.4399 + // m (NSM): Non-Spacing Mark
30.4400 + // b (BN): Boundary Neutral
30.4401 + // s (B): Paragraph Separator
30.4402 + // t (S): Segment Separator
30.4403 + // w (WS): Whitespace
30.4404 + // N (ON): Other Neutrals
30.4405 +
30.4406 + // Returns null if characters are ordered as they appear
30.4407 + // (left-to-right), or an array of sections ({from, to, level}
30.4408 + // objects) in the order in which they occur visually.
30.4409 + var bidiOrdering = (function() {
30.4410 + // Character types for codepoints 0 to 0xff
30.4411 + var lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLL";
30.4412 + // Character types for codepoints 0x600 to 0x6ff
30.4413 + var arabicTypes = "rrrrrrrrrrrr,rNNmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmrrrrrrrnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmNmmmmrrrrrrrrrrrrrrrrrr";
30.4414 + function charType(code) {
30.4415 + if (code <= 0xff) return lowTypes.charAt(code);
30.4416 + else if (0x590 <= code && code <= 0x5f4) return "R";
30.4417 + else if (0x600 <= code && code <= 0x6ff) return arabicTypes.charAt(code - 0x600);
30.4418 + else if (0x700 <= code && code <= 0x8ac) return "r";
30.4419 + else return "L";
30.4420 + }
30.4421 +
30.4422 + var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
30.4423 + var isNeutral = /[stwN]/, isStrong = /[LRr]/, countsAsLeft = /[Lb1n]/, countsAsNum = /[1n]/;
30.4424 +
30.4425 + return function charOrdering(str) {
30.4426 + if (!bidiRE.test(str)) return false;
30.4427 + var len = str.length, types = [], startType = null;
30.4428 + for (var i = 0, type; i < len; ++i) {
30.4429 + types.push(type = charType(str.charCodeAt(i)));
30.4430 + if (startType == null) {
30.4431 + if (type == "L") startType = "L";
30.4432 + else if (type == "R" || type == "r") startType = "R";
30.4433 + }
30.4434 + }
30.4435 + if (startType == null) startType = "L";
30.4436 +
30.4437 + // W1. Examine each non-spacing mark (NSM) in the level run, and
30.4438 + // change the type of the NSM to the type of the previous
30.4439 + // character. If the NSM is at the start of the level run, it will
30.4440 + // get the type of sor.
30.4441 + for (var i = 0, prev = startType; i < len; ++i) {
30.4442 + var type = types[i];
30.4443 + if (type == "m") types[i] = prev;
30.4444 + else prev = type;
30.4445 + }
30.4446 +
30.4447 + // W2. Search backwards from each instance of a European number
30.4448 + // until the first strong type (R, L, AL, or sor) is found. If an
30.4449 + // AL is found, change the type of the European number to Arabic
30.4450 + // number.
30.4451 + // W3. Change all ALs to R.
30.4452 + for (var i = 0, cur = startType; i < len; ++i) {
30.4453 + var type = types[i];
30.4454 + if (type == "1" && cur == "r") types[i] = "n";
30.4455 + else if (isStrong.test(type)) { cur = type; if (type == "r") types[i] = "R"; }
30.4456 + }
30.4457 +
30.4458 + // W4. A single European separator between two European numbers
30.4459 + // changes to a European number. A single common separator between
30.4460 + // two numbers of the same type changes to that type.
30.4461 + for (var i = 1, prev = types[0]; i < len - 1; ++i) {
30.4462 + var type = types[i];
30.4463 + if (type == "+" && prev == "1" && types[i+1] == "1") types[i] = "1";
30.4464 + else if (type == "," && prev == types[i+1] &&
30.4465 + (prev == "1" || prev == "n")) types[i] = prev;
30.4466 + prev = type;
30.4467 + }
30.4468 +
30.4469 + // W5. A sequence of European terminators adjacent to European
30.4470 + // numbers changes to all European numbers.
30.4471 + // W6. Otherwise, separators and terminators change to Other
30.4472 + // Neutral.
30.4473 + for (var i = 0; i < len; ++i) {
30.4474 + var type = types[i];
30.4475 + if (type == ",") types[i] = "N";
30.4476 + else if (type == "%") {
30.4477 + for (var end = i + 1; end < len && types[end] == "%"; ++end) {}
30.4478 + var replace = (i && types[i-1] == "!") || (end < len - 1 && types[end] == "1") ? "1" : "N";
30.4479 + for (var j = i; j < end; ++j) types[j] = replace;
30.4480 + i = end - 1;
30.4481 + }
30.4482 + }
30.4483 +
30.4484 + // W7. Search backwards from each instance of a European number
30.4485 + // until the first strong type (R, L, or sor) is found. If an L is
30.4486 + // found, then change the type of the European number to L.
30.4487 + for (var i = 0, cur = startType; i < len; ++i) {
30.4488 + var type = types[i];
30.4489 + if (cur == "L" && type == "1") types[i] = "L";
30.4490 + else if (isStrong.test(type)) cur = type;
30.4491 + }
30.4492 +
30.4493 + // N1. A sequence of neutrals takes the direction of the
30.4494 + // surrounding strong text if the text on both sides has the same
30.4495 + // direction. European and Arabic numbers act as if they were R in
30.4496 + // terms of their influence on neutrals. Start-of-level-run (sor)
30.4497 + // and end-of-level-run (eor) are used at level run boundaries.
30.4498 + // N2. Any remaining neutrals take the embedding direction.
30.4499 + for (var i = 0; i < len; ++i) {
30.4500 + if (isNeutral.test(types[i])) {
30.4501 + for (var end = i + 1; end < len && isNeutral.test(types[end]); ++end) {}
30.4502 + var before = (i ? types[i-1] : startType) == "L";
30.4503 + var after = (end < len - 1 ? types[end] : startType) == "L";
30.4504 + var replace = before || after ? "L" : "R";
30.4505 + for (var j = i; j < end; ++j) types[j] = replace;
30.4506 + i = end - 1;
30.4507 + }
30.4508 + }
30.4509 +
30.4510 + // Here we depart from the documented algorithm, in order to avoid
30.4511 + // building up an actual levels array. Since there are only three
30.4512 + // levels (0, 1, 2) in an implementation that doesn't take
30.4513 + // explicit embedding into account, we can build up the order on
30.4514 + // the fly, without following the level-based algorithm.
30.4515 + var order = [], m;
30.4516 + for (var i = 0; i < len;) {
30.4517 + if (countsAsLeft.test(types[i])) {
30.4518 + var start = i;
30.4519 + for (++i; i < len && countsAsLeft.test(types[i]); ++i) {}
30.4520 + order.push({from: start, to: i, level: 0});
30.4521 + } else {
30.4522 + var pos = i, at = order.length;
30.4523 + for (++i; i < len && types[i] != "L"; ++i) {}
30.4524 + for (var j = pos; j < i;) {
30.4525 + if (countsAsNum.test(types[j])) {
30.4526 + if (pos < j) order.splice(at, 0, {from: pos, to: j, level: 1});
30.4527 + var nstart = j;
30.4528 + for (++j; j < i && countsAsNum.test(types[j]); ++j) {}
30.4529 + order.splice(at, 0, {from: nstart, to: j, level: 2});
30.4530 + pos = j;
30.4531 + } else ++j;
30.4532 + }
30.4533 + if (pos < i) order.splice(at, 0, {from: pos, to: i, level: 1});
30.4534 + }
30.4535 + }
30.4536 + if (order[0].level == 1 && (m = str.match(/^\s+/))) {
30.4537 + order[0].from = m[0].length;
30.4538 + order.unshift({from: 0, to: m[0].length, level: 0});
30.4539 + }
30.4540 + if (lst(order).level == 1 && (m = str.match(/\s+$/))) {
30.4541 + lst(order).to -= m[0].length;
30.4542 + order.push({from: len - m[0].length, to: len, level: 0});
30.4543 + }
30.4544 + if (order[0].level != lst(order).level)
30.4545 + order.push({from: len, to: len, level: order[0].level});
30.4546 +
30.4547 + return order;
30.4548 + };
30.4549 + })();
30.4550 +
30.4551 + // THE END
30.4552 +
30.4553 + CodeMirror.version = "3.0";
30.4554 +
30.4555 + return CodeMirror;
30.4556 +})();
31.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
31.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/js/codemirror/mode/clike.js Wed Jan 23 20:16:48 2013 +0100
31.3 @@ -0,0 +1,300 @@
31.4 +CodeMirror.defineMode("clike", function(config, parserConfig) {
31.5 + var indentUnit = config.indentUnit,
31.6 + statementIndentUnit = parserConfig.statementIndentUnit || indentUnit,
31.7 + keywords = parserConfig.keywords || {},
31.8 + builtin = parserConfig.builtin || {},
31.9 + blockKeywords = parserConfig.blockKeywords || {},
31.10 + atoms = parserConfig.atoms || {},
31.11 + hooks = parserConfig.hooks || {},
31.12 + multiLineStrings = parserConfig.multiLineStrings;
31.13 + var isOperatorChar = /[+\-*&%=<>!?|\/]/;
31.14 +
31.15 + var curPunc;
31.16 +
31.17 + function tokenBase(stream, state) {
31.18 + var ch = stream.next();
31.19 + if (hooks[ch]) {
31.20 + var result = hooks[ch](stream, state);
31.21 + if (result !== false) return result;
31.22 + }
31.23 + if (ch == '"' || ch == "'") {
31.24 + state.tokenize = tokenString(ch);
31.25 + return state.tokenize(stream, state);
31.26 + }
31.27 + if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
31.28 + curPunc = ch;
31.29 + return null;
31.30 + }
31.31 + if (/\d/.test(ch)) {
31.32 + stream.eatWhile(/[\w\.]/);
31.33 + return "number";
31.34 + }
31.35 + if (ch == "/") {
31.36 + if (stream.eat("*")) {
31.37 + state.tokenize = tokenComment;
31.38 + return tokenComment(stream, state);
31.39 + }
31.40 + if (stream.eat("/")) {
31.41 + stream.skipToEnd();
31.42 + return "comment";
31.43 + }
31.44 + }
31.45 + if (isOperatorChar.test(ch)) {
31.46 + stream.eatWhile(isOperatorChar);
31.47 + return "operator";
31.48 + }
31.49 + stream.eatWhile(/[\w\$_]/);
31.50 + var cur = stream.current();
31.51 + if (keywords.propertyIsEnumerable(cur)) {
31.52 + if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
31.53 + return "keyword";
31.54 + }
31.55 + if (builtin.propertyIsEnumerable(cur)) {
31.56 + if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
31.57 + return "builtin";
31.58 + }
31.59 + if (atoms.propertyIsEnumerable(cur)) return "atom";
31.60 + return "variable";
31.61 + }
31.62 +
31.63 + function tokenString(quote) {
31.64 + return function(stream, state) {
31.65 + var escaped = false, next, end = false;
31.66 + while ((next = stream.next()) != null) {
31.67 + if (next == quote && !escaped) {end = true; break;}
31.68 + escaped = !escaped && next == "\\";
31.69 + }
31.70 + if (end || !(escaped || multiLineStrings))
31.71 + state.tokenize = null;
31.72 + return "string";
31.73 + };
31.74 + }
31.75 +
31.76 + function tokenComment(stream, state) {
31.77 + var maybeEnd = false, ch;
31.78 + while (ch = stream.next()) {
31.79 + if (ch == "/" && maybeEnd) {
31.80 + state.tokenize = null;
31.81 + break;
31.82 + }
31.83 + maybeEnd = (ch == "*");
31.84 + }
31.85 + return "comment";
31.86 + }
31.87 +
31.88 + function Context(indented, column, type, align, prev) {
31.89 + this.indented = indented;
31.90 + this.column = column;
31.91 + this.type = type;
31.92 + this.align = align;
31.93 + this.prev = prev;
31.94 + }
31.95 + function pushContext(state, col, type) {
31.96 + var indent = state.indented;
31.97 + if (state.context && state.context.type == "statement")
31.98 + indent = state.context.indented;
31.99 + return state.context = new Context(indent, col, type, null, state.context);
31.100 + }
31.101 + function popContext(state) {
31.102 + var t = state.context.type;
31.103 + if (t == ")" || t == "]" || t == "}")
31.104 + state.indented = state.context.indented;
31.105 + return state.context = state.context.prev;
31.106 + }
31.107 +
31.108 + // Interface
31.109 +
31.110 + return {
31.111 + startState: function(basecolumn) {
31.112 + return {
31.113 + tokenize: null,
31.114 + context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
31.115 + indented: 0,
31.116 + startOfLine: true
31.117 + };
31.118 + },
31.119 +
31.120 + token: function(stream, state) {
31.121 + var ctx = state.context;
31.122 + if (stream.sol()) {
31.123 + if (ctx.align == null) ctx.align = false;
31.124 + state.indented = stream.indentation();
31.125 + state.startOfLine = true;
31.126 + }
31.127 + if (stream.eatSpace()) return null;
31.128 + curPunc = null;
31.129 + var style = (state.tokenize || tokenBase)(stream, state);
31.130 + if (style == "comment" || style == "meta") return style;
31.131 + if (ctx.align == null) ctx.align = true;
31.132 +
31.133 + if ((curPunc == ";" || curPunc == ":" || curPunc == ",") && ctx.type == "statement") popContext(state);
31.134 + else if (curPunc == "{") pushContext(state, stream.column(), "}");
31.135 + else if (curPunc == "[") pushContext(state, stream.column(), "]");
31.136 + else if (curPunc == "(") pushContext(state, stream.column(), ")");
31.137 + else if (curPunc == "}") {
31.138 + while (ctx.type == "statement") ctx = popContext(state);
31.139 + if (ctx.type == "}") ctx = popContext(state);
31.140 + while (ctx.type == "statement") ctx = popContext(state);
31.141 + }
31.142 + else if (curPunc == ctx.type) popContext(state);
31.143 + else if (((ctx.type == "}" || ctx.type == "top") && curPunc != ';') || (ctx.type == "statement" && curPunc == "newstatement"))
31.144 + pushContext(state, stream.column(), "statement");
31.145 + state.startOfLine = false;
31.146 + return style;
31.147 + },
31.148 +
31.149 + indent: function(state, textAfter) {
31.150 + if (state.tokenize != tokenBase && state.tokenize != null) return CodeMirror.Pass;
31.151 + var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
31.152 + if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
31.153 + var closing = firstChar == ctx.type;
31.154 + if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit);
31.155 + else if (ctx.align) return ctx.column + (closing ? 0 : 1);
31.156 + else return ctx.indented + (closing ? 0 : indentUnit);
31.157 + },
31.158 +
31.159 + electricChars: "{}"
31.160 + };
31.161 +});
31.162 +
31.163 +(function() {
31.164 + function words(str) {
31.165 + var obj = {}, words = str.split(" ");
31.166 + for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
31.167 + return obj;
31.168 + }
31.169 + var cKeywords = "auto if break int case long char register continue return default short do sizeof " +
31.170 + "double static else struct entry switch extern typedef float union for unsigned " +
31.171 + "goto while enum void const signed volatile";
31.172 +
31.173 + function cppHook(stream, state) {
31.174 + if (!state.startOfLine) return false;
31.175 + for (;;) {
31.176 + if (stream.skipTo("\\")) {
31.177 + stream.next();
31.178 + if (stream.eol()) {
31.179 + state.tokenize = cppHook;
31.180 + break;
31.181 + }
31.182 + } else {
31.183 + stream.skipToEnd();
31.184 + state.tokenize = null;
31.185 + break;
31.186 + }
31.187 + }
31.188 + return "meta";
31.189 + }
31.190 +
31.191 + // C#-style strings where "" escapes a quote.
31.192 + function tokenAtString(stream, state) {
31.193 + var next;
31.194 + while ((next = stream.next()) != null) {
31.195 + if (next == '"' && !stream.eat('"')) {
31.196 + state.tokenize = null;
31.197 + break;
31.198 + }
31.199 + }
31.200 + return "string";
31.201 + }
31.202 +
31.203 + function mimes(ms, mode) {
31.204 + for (var i = 0; i < ms.length; ++i) CodeMirror.defineMIME(ms[i], mode);
31.205 + }
31.206 +
31.207 + mimes(["text/x-csrc", "text/x-c", "text/x-chdr"], {
31.208 + name: "clike",
31.209 + keywords: words(cKeywords),
31.210 + blockKeywords: words("case do else for if switch while struct"),
31.211 + atoms: words("null"),
31.212 + hooks: {"#": cppHook}
31.213 + });
31.214 + mimes(["text/x-c++src", "text/x-c++hdr"], {
31.215 + name: "clike",
31.216 + keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast try bool explicit new " +
31.217 + "static_cast typeid catch operator template typename class friend private " +
31.218 + "this using const_cast inline public throw virtual delete mutable protected " +
31.219 + "wchar_t"),
31.220 + blockKeywords: words("catch class do else finally for if struct switch try while"),
31.221 + atoms: words("true false null"),
31.222 + hooks: {"#": cppHook}
31.223 + });
31.224 + CodeMirror.defineMIME("text/x-java", {
31.225 + name: "clike",
31.226 + keywords: words("abstract assert boolean break byte case catch char class const continue default " +
31.227 + "do double else enum extends final finally float for goto if implements import " +
31.228 + "instanceof int interface long native new package private protected public " +
31.229 + "return short static strictfp super switch synchronized this throw throws transient " +
31.230 + "try void volatile while"),
31.231 + blockKeywords: words("catch class do else finally for if switch try while"),
31.232 + atoms: words("true false null"),
31.233 + hooks: {
31.234 + "@": function(stream) {
31.235 + stream.eatWhile(/[\w\$_]/);
31.236 + return "meta";
31.237 + }
31.238 + }
31.239 + });
31.240 + CodeMirror.defineMIME("text/x-csharp", {
31.241 + name: "clike",
31.242 + keywords: words("abstract as base break case catch checked class const continue" +
31.243 + " default delegate do else enum event explicit extern finally fixed for" +
31.244 + " foreach goto if implicit in interface internal is lock namespace new" +
31.245 + " operator out override params private protected public readonly ref return sealed" +
31.246 + " sizeof stackalloc static struct switch this throw try typeof unchecked" +
31.247 + " unsafe using virtual void volatile while add alias ascending descending dynamic from get" +
31.248 + " global group into join let orderby partial remove select set value var yield"),
31.249 + blockKeywords: words("catch class do else finally for foreach if struct switch try while"),
31.250 + builtin: words("Boolean Byte Char DateTime DateTimeOffset Decimal Double" +
31.251 + " Guid Int16 Int32 Int64 Object SByte Single String TimeSpan UInt16 UInt32" +
31.252 + " UInt64 bool byte char decimal double short int long object" +
31.253 + " sbyte float string ushort uint ulong"),
31.254 + atoms: words("true false null"),
31.255 + hooks: {
31.256 + "@": function(stream, state) {
31.257 + if (stream.eat('"')) {
31.258 + state.tokenize = tokenAtString;
31.259 + return tokenAtString(stream, state);
31.260 + }
31.261 + stream.eatWhile(/[\w\$_]/);
31.262 + return "meta";
31.263 + }
31.264 + }
31.265 + });
31.266 + CodeMirror.defineMIME("text/x-scala", {
31.267 + name: "clike",
31.268 + keywords: words(
31.269 +
31.270 + /* scala */
31.271 + "abstract case catch class def do else extends false final finally for forSome if " +
31.272 + "implicit import lazy match new null object override package private protected return " +
31.273 + "sealed super this throw trait try trye type val var while with yield _ : = => <- <: " +
31.274 + "<% >: # @ " +
31.275 +
31.276 + /* package scala */
31.277 + "assert assume require print println printf readLine readBoolean readByte readShort " +
31.278 + "readChar readInt readLong readFloat readDouble " +
31.279 +
31.280 + "AnyVal App Application Array BufferedIterator BigDecimal BigInt Char Console Either " +
31.281 + "Enumeration Equiv Error Exception Fractional Function IndexedSeq Integral Iterable " +
31.282 + "Iterator List Map Numeric Nil NotNull Option Ordered Ordering PartialFunction PartialOrdering " +
31.283 + "Product Proxy Range Responder Seq Serializable Set Specializable Stream StringBuilder " +
31.284 + "StringContext Symbol Throwable Traversable TraversableOnce Tuple Unit Vector :: #:: " +
31.285 +
31.286 + /* package java.lang */
31.287 + "Boolean Byte Character CharSequence Class ClassLoader Cloneable Comparable " +
31.288 + "Compiler Double Exception Float Integer Long Math Number Object Package Pair Process " +
31.289 + "Runtime Runnable SecurityManager Short StackTraceElement StrictMath String " +
31.290 + "StringBuffer System Thread ThreadGroup ThreadLocal Throwable Triple Void"
31.291 +
31.292 +
31.293 + ),
31.294 + blockKeywords: words("catch class do else finally for forSome if match switch try while"),
31.295 + atoms: words("true false null"),
31.296 + hooks: {
31.297 + "@": function(stream) {
31.298 + stream.eatWhile(/[\w\$_]/);
31.299 + return "meta";
31.300 + }
31.301 + }
31.302 + });
31.303 +}());
32.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
32.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/js/codemirror/mode/xml.js Wed Jan 23 20:16:48 2013 +0100
32.3 @@ -0,0 +1,324 @@
32.4 +CodeMirror.defineMode("xml", function(config, parserConfig) {
32.5 + var indentUnit = config.indentUnit;
32.6 + var Kludges = parserConfig.htmlMode ? {
32.7 + autoSelfClosers: {'area': true, 'base': true, 'br': true, 'col': true, 'command': true,
32.8 + 'embed': true, 'frame': true, 'hr': true, 'img': true, 'input': true,
32.9 + 'keygen': true, 'link': true, 'meta': true, 'param': true, 'source': true,
32.10 + 'track': true, 'wbr': true},
32.11 + implicitlyClosed: {'dd': true, 'li': true, 'optgroup': true, 'option': true, 'p': true,
32.12 + 'rp': true, 'rt': true, 'tbody': true, 'td': true, 'tfoot': true,
32.13 + 'th': true, 'tr': true},
32.14 + contextGrabbers: {
32.15 + 'dd': {'dd': true, 'dt': true},
32.16 + 'dt': {'dd': true, 'dt': true},
32.17 + 'li': {'li': true},
32.18 + 'option': {'option': true, 'optgroup': true},
32.19 + 'optgroup': {'optgroup': true},
32.20 + 'p': {'address': true, 'article': true, 'aside': true, 'blockquote': true, 'dir': true,
32.21 + 'div': true, 'dl': true, 'fieldset': true, 'footer': true, 'form': true,
32.22 + 'h1': true, 'h2': true, 'h3': true, 'h4': true, 'h5': true, 'h6': true,
32.23 + 'header': true, 'hgroup': true, 'hr': true, 'menu': true, 'nav': true, 'ol': true,
32.24 + 'p': true, 'pre': true, 'section': true, 'table': true, 'ul': true},
32.25 + 'rp': {'rp': true, 'rt': true},
32.26 + 'rt': {'rp': true, 'rt': true},
32.27 + 'tbody': {'tbody': true, 'tfoot': true},
32.28 + 'td': {'td': true, 'th': true},
32.29 + 'tfoot': {'tbody': true},
32.30 + 'th': {'td': true, 'th': true},
32.31 + 'thead': {'tbody': true, 'tfoot': true},
32.32 + 'tr': {'tr': true}
32.33 + },
32.34 + doNotIndent: {"pre": true},
32.35 + allowUnquoted: true,
32.36 + allowMissing: true
32.37 + } : {
32.38 + autoSelfClosers: {},
32.39 + implicitlyClosed: {},
32.40 + contextGrabbers: {},
32.41 + doNotIndent: {},
32.42 + allowUnquoted: false,
32.43 + allowMissing: false
32.44 + };
32.45 + var alignCDATA = parserConfig.alignCDATA;
32.46 +
32.47 + // Return variables for tokenizers
32.48 + var tagName, type;
32.49 +
32.50 + function inText(stream, state) {
32.51 + function chain(parser) {
32.52 + state.tokenize = parser;
32.53 + return parser(stream, state);
32.54 + }
32.55 +
32.56 + var ch = stream.next();
32.57 + if (ch == "<") {
32.58 + if (stream.eat("!")) {
32.59 + if (stream.eat("[")) {
32.60 + if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>"));
32.61 + else return null;
32.62 + }
32.63 + else if (stream.match("--")) return chain(inBlock("comment", "-->"));
32.64 + else if (stream.match("DOCTYPE", true, true)) {
32.65 + stream.eatWhile(/[\w\._\-]/);
32.66 + return chain(doctype(1));
32.67 + }
32.68 + else return null;
32.69 + }
32.70 + else if (stream.eat("?")) {
32.71 + stream.eatWhile(/[\w\._\-]/);
32.72 + state.tokenize = inBlock("meta", "?>");
32.73 + return "meta";
32.74 + }
32.75 + else {
32.76 + var isClose = stream.eat("/");
32.77 + tagName = "";
32.78 + var c;
32.79 + while ((c = stream.eat(/[^\s\u00a0=<>\"\'\/?]/))) tagName += c;
32.80 + if (!tagName) return "error";
32.81 + type = isClose ? "closeTag" : "openTag";
32.82 + state.tokenize = inTag;
32.83 + return "tag";
32.84 + }
32.85 + }
32.86 + else if (ch == "&") {
32.87 + var ok;
32.88 + if (stream.eat("#")) {
32.89 + if (stream.eat("x")) {
32.90 + ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";");
32.91 + } else {
32.92 + ok = stream.eatWhile(/[\d]/) && stream.eat(";");
32.93 + }
32.94 + } else {
32.95 + ok = stream.eatWhile(/[\w\.\-:]/) && stream.eat(";");
32.96 + }
32.97 + return ok ? "atom" : "error";
32.98 + }
32.99 + else {
32.100 + stream.eatWhile(/[^&<]/);
32.101 + return null;
32.102 + }
32.103 + }
32.104 +
32.105 + function inTag(stream, state) {
32.106 + var ch = stream.next();
32.107 + if (ch == ">" || (ch == "/" && stream.eat(">"))) {
32.108 + state.tokenize = inText;
32.109 + type = ch == ">" ? "endTag" : "selfcloseTag";
32.110 + return "tag";
32.111 + }
32.112 + else if (ch == "=") {
32.113 + type = "equals";
32.114 + return null;
32.115 + }
32.116 + else if (/[\'\"]/.test(ch)) {
32.117 + state.tokenize = inAttribute(ch);
32.118 + return state.tokenize(stream, state);
32.119 + }
32.120 + else {
32.121 + stream.eatWhile(/[^\s\u00a0=<>\"\']/);
32.122 + return "word";
32.123 + }
32.124 + }
32.125 +
32.126 + function inAttribute(quote) {
32.127 + return function(stream, state) {
32.128 + while (!stream.eol()) {
32.129 + if (stream.next() == quote) {
32.130 + state.tokenize = inTag;
32.131 + break;
32.132 + }
32.133 + }
32.134 + return "string";
32.135 + };
32.136 + }
32.137 +
32.138 + function inBlock(style, terminator) {
32.139 + return function(stream, state) {
32.140 + while (!stream.eol()) {
32.141 + if (stream.match(terminator)) {
32.142 + state.tokenize = inText;
32.143 + break;
32.144 + }
32.145 + stream.next();
32.146 + }
32.147 + return style;
32.148 + };
32.149 + }
32.150 + function doctype(depth) {
32.151 + return function(stream, state) {
32.152 + var ch;
32.153 + while ((ch = stream.next()) != null) {
32.154 + if (ch == "<") {
32.155 + state.tokenize = doctype(depth + 1);
32.156 + return state.tokenize(stream, state);
32.157 + } else if (ch == ">") {
32.158 + if (depth == 1) {
32.159 + state.tokenize = inText;
32.160 + break;
32.161 + } else {
32.162 + state.tokenize = doctype(depth - 1);
32.163 + return state.tokenize(stream, state);
32.164 + }
32.165 + }
32.166 + }
32.167 + return "meta";
32.168 + };
32.169 + }
32.170 +
32.171 + var curState, setStyle;
32.172 + function pass() {
32.173 + for (var i = arguments.length - 1; i >= 0; i--) curState.cc.push(arguments[i]);
32.174 + }
32.175 + function cont() {
32.176 + pass.apply(null, arguments);
32.177 + return true;
32.178 + }
32.179 +
32.180 + function pushContext(tagName, startOfLine) {
32.181 + var noIndent = Kludges.doNotIndent.hasOwnProperty(tagName) || (curState.context && curState.context.noIndent);
32.182 + curState.context = {
32.183 + prev: curState.context,
32.184 + tagName: tagName,
32.185 + indent: curState.indented,
32.186 + startOfLine: startOfLine,
32.187 + noIndent: noIndent
32.188 + };
32.189 + }
32.190 + function popContext() {
32.191 + if (curState.context) curState.context = curState.context.prev;
32.192 + }
32.193 +
32.194 + function element(type) {
32.195 + if (type == "openTag") {
32.196 + curState.tagName = tagName;
32.197 + return cont(attributes, endtag(curState.startOfLine));
32.198 + } else if (type == "closeTag") {
32.199 + var err = false;
32.200 + if (curState.context) {
32.201 + if (curState.context.tagName != tagName) {
32.202 + if (Kludges.implicitlyClosed.hasOwnProperty(curState.context.tagName.toLowerCase())) {
32.203 + popContext();
32.204 + }
32.205 + err = !curState.context || curState.context.tagName != tagName;
32.206 + }
32.207 + } else {
32.208 + err = true;
32.209 + }
32.210 + if (err) setStyle = "error";
32.211 + return cont(endclosetag(err));
32.212 + }
32.213 + return cont();
32.214 + }
32.215 + function endtag(startOfLine) {
32.216 + return function(type) {
32.217 + var tagName = curState.tagName;
32.218 + curState.tagName = null;
32.219 + if (type == "selfcloseTag" ||
32.220 + (type == "endTag" && Kludges.autoSelfClosers.hasOwnProperty(tagName.toLowerCase()))) {
32.221 + maybePopContext(tagName.toLowerCase());
32.222 + return cont();
32.223 + }
32.224 + if (type == "endTag") {
32.225 + maybePopContext(tagName.toLowerCase());
32.226 + pushContext(tagName, startOfLine);
32.227 + return cont();
32.228 + }
32.229 + return cont();
32.230 + };
32.231 + }
32.232 + function endclosetag(err) {
32.233 + return function(type) {
32.234 + if (err) setStyle = "error";
32.235 + if (type == "endTag") { popContext(); return cont(); }
32.236 + setStyle = "error";
32.237 + return cont(arguments.callee);
32.238 + };
32.239 + }
32.240 + function maybePopContext(nextTagName) {
32.241 + var parentTagName;
32.242 + while (true) {
32.243 + if (!curState.context) {
32.244 + return;
32.245 + }
32.246 + parentTagName = curState.context.tagName.toLowerCase();
32.247 + if (!Kludges.contextGrabbers.hasOwnProperty(parentTagName) ||
32.248 + !Kludges.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) {
32.249 + return;
32.250 + }
32.251 + popContext();
32.252 + }
32.253 + }
32.254 +
32.255 + function attributes(type) {
32.256 + if (type == "word") {setStyle = "attribute"; return cont(attribute, attributes);}
32.257 + if (type == "endTag" || type == "selfcloseTag") return pass();
32.258 + setStyle = "error";
32.259 + return cont(attributes);
32.260 + }
32.261 + function attribute(type) {
32.262 + if (type == "equals") return cont(attvalue, attributes);
32.263 + if (!Kludges.allowMissing) setStyle = "error";
32.264 + else if (type == "word") setStyle = "attribute";
32.265 + return (type == "endTag" || type == "selfcloseTag") ? pass() : cont();
32.266 + }
32.267 + function attvalue(type) {
32.268 + if (type == "string") return cont(attvaluemaybe);
32.269 + if (type == "word" && Kludges.allowUnquoted) {setStyle = "string"; return cont();}
32.270 + setStyle = "error";
32.271 + return (type == "endTag" || type == "selfCloseTag") ? pass() : cont();
32.272 + }
32.273 + function attvaluemaybe(type) {
32.274 + if (type == "string") return cont(attvaluemaybe);
32.275 + else return pass();
32.276 + }
32.277 +
32.278 + return {
32.279 + startState: function() {
32.280 + return {tokenize: inText, cc: [], indented: 0, startOfLine: true, tagName: null, context: null};
32.281 + },
32.282 +
32.283 + token: function(stream, state) {
32.284 + if (stream.sol()) {
32.285 + state.startOfLine = true;
32.286 + state.indented = stream.indentation();
32.287 + }
32.288 + if (stream.eatSpace()) return null;
32.289 +
32.290 + setStyle = type = tagName = null;
32.291 + var style = state.tokenize(stream, state);
32.292 + state.type = type;
32.293 + if ((style || type) && style != "comment") {
32.294 + curState = state;
32.295 + while (true) {
32.296 + var comb = state.cc.pop() || element;
32.297 + if (comb(type || style)) break;
32.298 + }
32.299 + }
32.300 + state.startOfLine = false;
32.301 + return setStyle || style;
32.302 + },
32.303 +
32.304 + indent: function(state, textAfter, fullLine) {
32.305 + var context = state.context;
32.306 + if ((state.tokenize != inTag && state.tokenize != inText) ||
32.307 + context && context.noIndent)
32.308 + return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0;
32.309 + if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
32.310 + if (context && /^<\//.test(textAfter))
32.311 + context = context.prev;
32.312 + while (context && !context.startOfLine)
32.313 + context = context.prev;
32.314 + if (context) return context.indent + indentUnit;
32.315 + else return 0;
32.316 + },
32.317 +
32.318 + electricChars: "/",
32.319 +
32.320 + configuration: parserConfig.htmlMode ? "html" : "xml"
32.321 + };
32.322 +});
32.323 +
32.324 +CodeMirror.defineMIME("text/xml", "xml");
32.325 +CodeMirror.defineMIME("application/xml", "xml");
32.326 +if (!CodeMirror.mimeModes.hasOwnProperty("text/html"))
32.327 + CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});
33.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
33.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/js/codemirror/theme/elegant.css Wed Jan 23 20:16:48 2013 +0100
33.3 @@ -0,0 +1,10 @@
33.4 +.cm-s-elegant span.cm-number, .cm-s-elegant span.cm-string, .cm-s-elegant span.cm-atom {color: #762;}
33.5 +.cm-s-elegant span.cm-comment {color: #262; font-style: italic; line-height: 1em;}
33.6 +.cm-s-elegant span.cm-meta {color: #555; font-style: italic; line-height: 1em;}
33.7 +.cm-s-elegant span.cm-variable {color: black;}
33.8 +.cm-s-elegant span.cm-variable-2 {color: #b11;}
33.9 +.cm-s-elegant span.cm-qualifier {color: #555;}
33.10 +.cm-s-elegant span.cm-keyword {color: #730;}
33.11 +.cm-s-elegant span.cm-builtin {color: #30a;}
33.12 +.cm-s-elegant span.cm-error {background-color: #fdd;}
33.13 +.cm-s-elegant span.cm-link {color: #762;}
34.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
34.2 +++ b/dew/src/test/java/org/apidesign/bck2brwsr/dew/CompileTest.java Wed Jan 23 20:16:48 2013 +0100
34.3 @@ -0,0 +1,45 @@
34.4 +/**
34.5 + * Back 2 Browser Bytecode Translator
34.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
34.7 + *
34.8 + * This program is free software: you can redistribute it and/or modify
34.9 + * it under the terms of the GNU General Public License as published by
34.10 + * the Free Software Foundation, version 2 of the License.
34.11 + *
34.12 + * This program is distributed in the hope that it will be useful,
34.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34.15 + * GNU General Public License for more details.
34.16 + *
34.17 + * You should have received a copy of the GNU General Public License
34.18 + * along with this program. Look for COPYING file in the top folder.
34.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
34.20 + */
34.21 +package org.apidesign.bck2brwsr.dew;
34.22 +
34.23 +import java.io.IOException;
34.24 +import static org.testng.Assert.*;
34.25 +import org.testng.annotations.Test;
34.26 +
34.27 +/**
34.28 + *
34.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
34.30 + */
34.31 +public class CompileTest {
34.32 + @Test public void testCompile() throws IOException {
34.33 + String html = "<html><body>"
34.34 + + " <button id='btn'>Hello!</button>"
34.35 + + "</body></html>";
34.36 + String java = "package x.y.z;"
34.37 + + "import org.apidesign.bck2brwsr.htmlpage.api.*;"
34.38 + + "import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;"
34.39 + + "@Page(xhtml=\"index.html\", className=\"Index\")"
34.40 + + "class X { "
34.41 + + " @On(event=CLICK, id=\"btn\") static void clcs() {}"
34.42 + + "}";
34.43 + Compile result = Compile.create(html, java);
34.44 +
34.45 + assertNotNull(result.get("x/y/z/X.class"), "Class X is compiled: " + result);
34.46 + assertNotNull(result.get("x/y/z/Index.class"), "Class Index is compiled: " + result);
34.47 + }
34.48 +}
35.1 --- a/emul/pom.xml Thu Oct 11 06:15:22 2012 -0700
35.2 +++ b/emul/pom.xml Wed Jan 23 20:16:48 2013 +0100
35.3 @@ -5,11 +5,11 @@
35.4 <parent>
35.5 <groupId>org.apidesign</groupId>
35.6 <artifactId>bck2brwsr</artifactId>
35.7 - <version>1.0-SNAPSHOT</version>
35.8 + <version>0.3-SNAPSHOT</version>
35.9 </parent>
35.10 <groupId>org.apidesign.bck2brwsr</groupId>
35.11 <artifactId>emul</artifactId>
35.12 - <version>1.0-SNAPSHOT</version>
35.13 + <version>0.3-SNAPSHOT</version>
35.14 <name>Java API Emulation</name>
35.15 <url>http://maven.apache.org</url>
35.16 <properties>
35.17 @@ -17,15 +17,9 @@
35.18 </properties>
35.19 <dependencies>
35.20 <dependency>
35.21 - <groupId>junit</groupId>
35.22 - <artifactId>junit</artifactId>
35.23 - <version>3.8.1</version>
35.24 - <scope>test</scope>
35.25 - </dependency>
35.26 - <dependency>
35.27 <groupId>org.apidesign.bck2brwsr</groupId>
35.28 <artifactId>core</artifactId>
35.29 - <version>1.0-SNAPSHOT</version>
35.30 + <version>0.3-SNAPSHOT</version>
35.31 <type>jar</type>
35.32 </dependency>
35.33 </dependencies>
36.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
36.2 +++ b/emul/src/main/java/java/io/ByteArrayInputStream.java Wed Jan 23 20:16:48 2013 +0100
36.3 @@ -0,0 +1,283 @@
36.4 +/*
36.5 + * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
36.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
36.7 + *
36.8 + * This code is free software; you can redistribute it and/or modify it
36.9 + * under the terms of the GNU General Public License version 2 only, as
36.10 + * published by the Free Software Foundation. Oracle designates this
36.11 + * particular file as subject to the "Classpath" exception as provided
36.12 + * by Oracle in the LICENSE file that accompanied this code.
36.13 + *
36.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
36.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
36.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
36.17 + * version 2 for more details (a copy is included in the LICENSE file that
36.18 + * accompanied this code).
36.19 + *
36.20 + * You should have received a copy of the GNU General Public License version
36.21 + * 2 along with this work; if not, write to the Free Software Foundation,
36.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
36.23 + *
36.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
36.25 + * or visit www.oracle.com if you need additional information or have any
36.26 + * questions.
36.27 + */
36.28 +
36.29 +package java.io;
36.30 +
36.31 +/**
36.32 + * A <code>ByteArrayInputStream</code> contains
36.33 + * an internal buffer that contains bytes that
36.34 + * may be read from the stream. An internal
36.35 + * counter keeps track of the next byte to
36.36 + * be supplied by the <code>read</code> method.
36.37 + * <p>
36.38 + * Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in
36.39 + * this class can be called after the stream has been closed without
36.40 + * generating an <tt>IOException</tt>.
36.41 + *
36.42 + * @author Arthur van Hoff
36.43 + * @see java.io.StringBufferInputStream
36.44 + * @since JDK1.0
36.45 + */
36.46 +public
36.47 +class ByteArrayInputStream extends InputStream {
36.48 +
36.49 + /**
36.50 + * An array of bytes that was provided
36.51 + * by the creator of the stream. Elements <code>buf[0]</code>
36.52 + * through <code>buf[count-1]</code> are the
36.53 + * only bytes that can ever be read from the
36.54 + * stream; element <code>buf[pos]</code> is
36.55 + * the next byte to be read.
36.56 + */
36.57 + protected byte buf[];
36.58 +
36.59 + /**
36.60 + * The index of the next character to read from the input stream buffer.
36.61 + * This value should always be nonnegative
36.62 + * and not larger than the value of <code>count</code>.
36.63 + * The next byte to be read from the input stream buffer
36.64 + * will be <code>buf[pos]</code>.
36.65 + */
36.66 + protected int pos;
36.67 +
36.68 + /**
36.69 + * The currently marked position in the stream.
36.70 + * ByteArrayInputStream objects are marked at position zero by
36.71 + * default when constructed. They may be marked at another
36.72 + * position within the buffer by the <code>mark()</code> method.
36.73 + * The current buffer position is set to this point by the
36.74 + * <code>reset()</code> method.
36.75 + * <p>
36.76 + * If no mark has been set, then the value of mark is the offset
36.77 + * passed to the constructor (or 0 if the offset was not supplied).
36.78 + *
36.79 + * @since JDK1.1
36.80 + */
36.81 + protected int mark = 0;
36.82 +
36.83 + /**
36.84 + * The index one greater than the last valid character in the input
36.85 + * stream buffer.
36.86 + * This value should always be nonnegative
36.87 + * and not larger than the length of <code>buf</code>.
36.88 + * It is one greater than the position of
36.89 + * the last byte within <code>buf</code> that
36.90 + * can ever be read from the input stream buffer.
36.91 + */
36.92 + protected int count;
36.93 +
36.94 + /**
36.95 + * Creates a <code>ByteArrayInputStream</code>
36.96 + * so that it uses <code>buf</code> as its
36.97 + * buffer array.
36.98 + * The buffer array is not copied.
36.99 + * The initial value of <code>pos</code>
36.100 + * is <code>0</code> and the initial value
36.101 + * of <code>count</code> is the length of
36.102 + * <code>buf</code>.
36.103 + *
36.104 + * @param buf the input buffer.
36.105 + */
36.106 + public ByteArrayInputStream(byte buf[]) {
36.107 + this.buf = buf;
36.108 + this.pos = 0;
36.109 + this.count = buf.length;
36.110 + }
36.111 +
36.112 + /**
36.113 + * Creates <code>ByteArrayInputStream</code>
36.114 + * that uses <code>buf</code> as its
36.115 + * buffer array. The initial value of <code>pos</code>
36.116 + * is <code>offset</code> and the initial value
36.117 + * of <code>count</code> is the minimum of <code>offset+length</code>
36.118 + * and <code>buf.length</code>.
36.119 + * The buffer array is not copied. The buffer's mark is
36.120 + * set to the specified offset.
36.121 + *
36.122 + * @param buf the input buffer.
36.123 + * @param offset the offset in the buffer of the first byte to read.
36.124 + * @param length the maximum number of bytes to read from the buffer.
36.125 + */
36.126 + public ByteArrayInputStream(byte buf[], int offset, int length) {
36.127 + this.buf = buf;
36.128 + this.pos = offset;
36.129 + this.count = Math.min(offset + length, buf.length);
36.130 + this.mark = offset;
36.131 + }
36.132 +
36.133 + /**
36.134 + * Reads the next byte of data from this input stream. The value
36.135 + * byte is returned as an <code>int</code> in the range
36.136 + * <code>0</code> to <code>255</code>. If no byte is available
36.137 + * because the end of the stream has been reached, the value
36.138 + * <code>-1</code> is returned.
36.139 + * <p>
36.140 + * This <code>read</code> method
36.141 + * cannot block.
36.142 + *
36.143 + * @return the next byte of data, or <code>-1</code> if the end of the
36.144 + * stream has been reached.
36.145 + */
36.146 + public synchronized int read() {
36.147 + return (pos < count) ? (buf[pos++] & 0xff) : -1;
36.148 + }
36.149 +
36.150 + /**
36.151 + * Reads up to <code>len</code> bytes of data into an array of bytes
36.152 + * from this input stream.
36.153 + * If <code>pos</code> equals <code>count</code>,
36.154 + * then <code>-1</code> is returned to indicate
36.155 + * end of file. Otherwise, the number <code>k</code>
36.156 + * of bytes read is equal to the smaller of
36.157 + * <code>len</code> and <code>count-pos</code>.
36.158 + * If <code>k</code> is positive, then bytes
36.159 + * <code>buf[pos]</code> through <code>buf[pos+k-1]</code>
36.160 + * are copied into <code>b[off]</code> through
36.161 + * <code>b[off+k-1]</code> in the manner performed
36.162 + * by <code>System.arraycopy</code>. The
36.163 + * value <code>k</code> is added into <code>pos</code>
36.164 + * and <code>k</code> is returned.
36.165 + * <p>
36.166 + * This <code>read</code> method cannot block.
36.167 + *
36.168 + * @param b the buffer into which the data is read.
36.169 + * @param off the start offset in the destination array <code>b</code>
36.170 + * @param len the maximum number of bytes read.
36.171 + * @return the total number of bytes read into the buffer, or
36.172 + * <code>-1</code> if there is no more data because the end of
36.173 + * the stream has been reached.
36.174 + * @exception NullPointerException If <code>b</code> is <code>null</code>.
36.175 + * @exception IndexOutOfBoundsException If <code>off</code> is negative,
36.176 + * <code>len</code> is negative, or <code>len</code> is greater than
36.177 + * <code>b.length - off</code>
36.178 + */
36.179 + public synchronized int read(byte b[], int off, int len) {
36.180 + if (b == null) {
36.181 + throw new NullPointerException();
36.182 + } else if (off < 0 || len < 0 || len > b.length - off) {
36.183 + throw new IndexOutOfBoundsException();
36.184 + }
36.185 +
36.186 + if (pos >= count) {
36.187 + return -1;
36.188 + }
36.189 +
36.190 + int avail = count - pos;
36.191 + if (len > avail) {
36.192 + len = avail;
36.193 + }
36.194 + if (len <= 0) {
36.195 + return 0;
36.196 + }
36.197 + PushbackInputStream.arraycopy(buf, pos, b, off, len);
36.198 + pos += len;
36.199 + return len;
36.200 + }
36.201 +
36.202 + /**
36.203 + * Skips <code>n</code> bytes of input from this input stream. Fewer
36.204 + * bytes might be skipped if the end of the input stream is reached.
36.205 + * The actual number <code>k</code>
36.206 + * of bytes to be skipped is equal to the smaller
36.207 + * of <code>n</code> and <code>count-pos</code>.
36.208 + * The value <code>k</code> is added into <code>pos</code>
36.209 + * and <code>k</code> is returned.
36.210 + *
36.211 + * @param n the number of bytes to be skipped.
36.212 + * @return the actual number of bytes skipped.
36.213 + */
36.214 + public synchronized long skip(long n) {
36.215 + long k = count - pos;
36.216 + if (n < k) {
36.217 + k = n < 0 ? 0 : n;
36.218 + }
36.219 +
36.220 + pos += k;
36.221 + return k;
36.222 + }
36.223 +
36.224 + /**
36.225 + * Returns the number of remaining bytes that can be read (or skipped over)
36.226 + * from this input stream.
36.227 + * <p>
36.228 + * The value returned is <code>count - pos</code>,
36.229 + * which is the number of bytes remaining to be read from the input buffer.
36.230 + *
36.231 + * @return the number of remaining bytes that can be read (or skipped
36.232 + * over) from this input stream without blocking.
36.233 + */
36.234 + public synchronized int available() {
36.235 + return count - pos;
36.236 + }
36.237 +
36.238 + /**
36.239 + * Tests if this <code>InputStream</code> supports mark/reset. The
36.240 + * <code>markSupported</code> method of <code>ByteArrayInputStream</code>
36.241 + * always returns <code>true</code>.
36.242 + *
36.243 + * @since JDK1.1
36.244 + */
36.245 + public boolean markSupported() {
36.246 + return true;
36.247 + }
36.248 +
36.249 + /**
36.250 + * Set the current marked position in the stream.
36.251 + * ByteArrayInputStream objects are marked at position zero by
36.252 + * default when constructed. They may be marked at another
36.253 + * position within the buffer by this method.
36.254 + * <p>
36.255 + * If no mark has been set, then the value of the mark is the
36.256 + * offset passed to the constructor (or 0 if the offset was not
36.257 + * supplied).
36.258 + *
36.259 + * <p> Note: The <code>readAheadLimit</code> for this class
36.260 + * has no meaning.
36.261 + *
36.262 + * @since JDK1.1
36.263 + */
36.264 + public void mark(int readAheadLimit) {
36.265 + mark = pos;
36.266 + }
36.267 +
36.268 + /**
36.269 + * Resets the buffer to the marked position. The marked position
36.270 + * is 0 unless another position was marked or an offset was specified
36.271 + * in the constructor.
36.272 + */
36.273 + public synchronized void reset() {
36.274 + pos = mark;
36.275 + }
36.276 +
36.277 + /**
36.278 + * Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in
36.279 + * this class can be called after the stream has been closed without
36.280 + * generating an <tt>IOException</tt>.
36.281 + * <p>
36.282 + */
36.283 + public void close() throws IOException {
36.284 + }
36.285 +
36.286 +}
37.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
37.2 +++ b/emul/src/main/java/java/io/Closeable.java Wed Jan 23 20:16:48 2013 +0100
37.3 @@ -0,0 +1,48 @@
37.4 +/*
37.5 + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
37.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
37.7 + *
37.8 + * This code is free software; you can redistribute it and/or modify it
37.9 + * under the terms of the GNU General Public License version 2 only, as
37.10 + * published by the Free Software Foundation. Oracle designates this
37.11 + * particular file as subject to the "Classpath" exception as provided
37.12 + * by Oracle in the LICENSE file that accompanied this code.
37.13 + *
37.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
37.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
37.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
37.17 + * version 2 for more details (a copy is included in the LICENSE file that
37.18 + * accompanied this code).
37.19 + *
37.20 + * You should have received a copy of the GNU General Public License version
37.21 + * 2 along with this work; if not, write to the Free Software Foundation,
37.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
37.23 + *
37.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
37.25 + * or visit www.oracle.com if you need additional information or have any
37.26 + * questions.
37.27 + */
37.28 +
37.29 +package java.io;
37.30 +
37.31 +import java.io.IOException;
37.32 +
37.33 +/**
37.34 + * A {@code Closeable} is a source or destination of data that can be closed.
37.35 + * The close method is invoked to release resources that the object is
37.36 + * holding (such as open files).
37.37 + *
37.38 + * @since 1.5
37.39 + */
37.40 +
37.41 +public interface Closeable extends AutoCloseable {
37.42 +
37.43 + /**
37.44 + * Closes this stream and releases any system resources associated
37.45 + * with it. If the stream is already closed then invoking this
37.46 + * method has no effect.
37.47 + *
37.48 + * @throws IOException if an I/O error occurs
37.49 + */
37.50 + public void close() throws IOException;
37.51 +}
38.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
38.2 +++ b/emul/src/main/java/java/io/DataInput.java Wed Jan 23 20:16:48 2013 +0100
38.3 @@ -0,0 +1,635 @@
38.4 +/*
38.5 + * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
38.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
38.7 + *
38.8 + * This code is free software; you can redistribute it and/or modify it
38.9 + * under the terms of the GNU General Public License version 2 only, as
38.10 + * published by the Free Software Foundation. Oracle designates this
38.11 + * particular file as subject to the "Classpath" exception as provided
38.12 + * by Oracle in the LICENSE file that accompanied this code.
38.13 + *
38.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
38.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
38.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
38.17 + * version 2 for more details (a copy is included in the LICENSE file that
38.18 + * accompanied this code).
38.19 + *
38.20 + * You should have received a copy of the GNU General Public License version
38.21 + * 2 along with this work; if not, write to the Free Software Foundation,
38.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
38.23 + *
38.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
38.25 + * or visit www.oracle.com if you need additional information or have any
38.26 + * questions.
38.27 + */
38.28 +
38.29 +package java.io;
38.30 +
38.31 +/**
38.32 + * The <code>DataInput</code> interface provides
38.33 + * for reading bytes from a binary stream and
38.34 + * reconstructing from them data in any of
38.35 + * the Java primitive types. There is also
38.36 + * a
38.37 + * facility for reconstructing a <code>String</code>
38.38 + * from data in
38.39 + * <a href="#modified-utf-8">modified UTF-8</a>
38.40 + * format.
38.41 + * <p>
38.42 + * It is generally true of all the reading
38.43 + * routines in this interface that if end of
38.44 + * file is reached before the desired number
38.45 + * of bytes has been read, an <code>EOFException</code>
38.46 + * (which is a kind of <code>IOException</code>)
38.47 + * is thrown. If any byte cannot be read for
38.48 + * any reason other than end of file, an <code>IOException</code>
38.49 + * other than <code>EOFException</code> is
38.50 + * thrown. In particular, an <code>IOException</code>
38.51 + * may be thrown if the input stream has been
38.52 + * closed.
38.53 + *
38.54 + * <h4><a name="modified-utf-8">Modified UTF-8</a></h4>
38.55 + * <p>
38.56 + * Implementations of the DataInput and DataOutput interfaces represent
38.57 + * Unicode strings in a format that is a slight modification of UTF-8.
38.58 + * (For information regarding the standard UTF-8 format, see section
38.59 + * <i>3.9 Unicode Encoding Forms</i> of <i>The Unicode Standard, Version
38.60 + * 4.0</i>).
38.61 + * Note that in the following tables, the most significant bit appears in the
38.62 + * far left-hand column.
38.63 + * <p>
38.64 + * All characters in the range <code>'\u0001'</code> to
38.65 + * <code>'\u007F'</code> are represented by a single byte:
38.66 + *
38.67 + * <blockquote>
38.68 + * <table border="1" cellspacing="0" cellpadding="8" width="50%"
38.69 + * summary="Bit values and bytes">
38.70 + * <tr>
38.71 + * <td></td>
38.72 + * <th id="bit">Bit Values</th>
38.73 + * </tr>
38.74 + * <tr>
38.75 + * <th id="byte1">Byte 1</th>
38.76 + * <td>
38.77 + * <table border="1" cellspacing="0" width="100%">
38.78 + * <tr>
38.79 + * <td width="12%"><center>0</center>
38.80 + * <td colspan="7"><center>bits 6-0</center>
38.81 + * </tr>
38.82 + * </table>
38.83 + * </td>
38.84 + * </tr>
38.85 + * </table>
38.86 + * </blockquote>
38.87 + *
38.88 + * <p>
38.89 + * The null character <code>'\u0000'</code> and characters in the
38.90 + * range <code>'\u0080'</code> to <code>'\u07FF'</code> are
38.91 + * represented by a pair of bytes:
38.92 + *
38.93 + * <blockquote>
38.94 + * <table border="1" cellspacing="0" cellpadding="8" width="50%"
38.95 + * summary="Bit values and bytes">
38.96 + * <tr>
38.97 + * <td></td>
38.98 + * <th id="bit">Bit Values</th>
38.99 + * </tr>
38.100 + * <tr>
38.101 + * <th id="byte1">Byte 1</th>
38.102 + * <td>
38.103 + * <table border="1" cellspacing="0" width="100%">
38.104 + * <tr>
38.105 + * <td width="12%"><center>1</center>
38.106 + * <td width="13%"><center>1</center>
38.107 + * <td width="12%"><center>0</center>
38.108 + * <td colspan="5"><center>bits 10-6</center>
38.109 + * </tr>
38.110 + * </table>
38.111 + * </td>
38.112 + * </tr>
38.113 + * <tr>
38.114 + * <th id="byte2">Byte 2</th>
38.115 + * <td>
38.116 + * <table border="1" cellspacing="0" width="100%">
38.117 + * <tr>
38.118 + * <td width="12%"><center>1</center>
38.119 + * <td width="13%"><center>0</center>
38.120 + * <td colspan="6"><center>bits 5-0</center>
38.121 + * </tr>
38.122 + * </table>
38.123 + * </td>
38.124 + * </tr>
38.125 + * </table>
38.126 + * </blockquote>
38.127 + *
38.128 + * <br>
38.129 + * <code>char</code> values in the range <code>'\u0800'</code> to
38.130 + * <code>'\uFFFF'</code> are represented by three bytes:
38.131 + *
38.132 + * <blockquote>
38.133 + * <table border="1" cellspacing="0" cellpadding="8" width="50%"
38.134 + * summary="Bit values and bytes">
38.135 + * <tr>
38.136 + * <td></td>
38.137 + * <th id="bit">Bit Values</th>
38.138 + * </tr>
38.139 + * <tr>
38.140 + * <th id="byte1">Byte 1</th>
38.141 + * <td>
38.142 + * <table border="1" cellspacing="0" width="100%">
38.143 + * <tr>
38.144 + * <td width="12%"><center>1</center>
38.145 + * <td width="13%"><center>1</center>
38.146 + * <td width="12%"><center>1</center>
38.147 + * <td width="13%"><center>0</center>
38.148 + * <td colspan="4"><center>bits 15-12</center>
38.149 + * </tr>
38.150 + * </table>
38.151 + * </td>
38.152 + * </tr>
38.153 + * <tr>
38.154 + * <th id="byte2">Byte 2</th>
38.155 + * <td>
38.156 + * <table border="1" cellspacing="0" width="100%">
38.157 + * <tr>
38.158 + * <td width="12%"><center>1</center>
38.159 + * <td width="13%"><center>0</center>
38.160 + * <td colspan="6"><center>bits 11-6</center>
38.161 + * </tr>
38.162 + * </table>
38.163 + * </td>
38.164 + * </tr>
38.165 + * <tr>
38.166 + * <th id="byte3">Byte 3</th>
38.167 + * <td>
38.168 + * <table border="1" cellspacing="0" width="100%">
38.169 + * <tr>
38.170 + * <td width="12%"><center>1</center>
38.171 + * <td width="13%"><center>0</center>
38.172 + * <td colspan="6"><center>bits 5-0</center>
38.173 + * </tr>
38.174 + * </table>
38.175 + * </td>
38.176 + * </tr>
38.177 + * </table>
38.178 + * </blockquote>
38.179 + *
38.180 + * <p>
38.181 + * The differences between this format and the
38.182 + * standard UTF-8 format are the following:
38.183 + * <ul>
38.184 + * <li>The null byte <code>'\u0000'</code> is encoded in 2-byte format
38.185 + * rather than 1-byte, so that the encoded strings never have
38.186 + * embedded nulls.
38.187 + * <li>Only the 1-byte, 2-byte, and 3-byte formats are used.
38.188 + * <li><a href="../lang/Character.html#unicode">Supplementary characters</a>
38.189 + * are represented in the form of surrogate pairs.
38.190 + * </ul>
38.191 + * @author Frank Yellin
38.192 + * @see java.io.DataInputStream
38.193 + * @see java.io.DataOutput
38.194 + * @since JDK1.0
38.195 + */
38.196 +public
38.197 +interface DataInput {
38.198 + /**
38.199 + * Reads some bytes from an input
38.200 + * stream and stores them into the buffer
38.201 + * array <code>b</code>. The number of bytes
38.202 + * read is equal
38.203 + * to the length of <code>b</code>.
38.204 + * <p>
38.205 + * This method blocks until one of the
38.206 + * following conditions occurs:<p>
38.207 + * <ul>
38.208 + * <li><code>b.length</code>
38.209 + * bytes of input data are available, in which
38.210 + * case a normal return is made.
38.211 + *
38.212 + * <li>End of
38.213 + * file is detected, in which case an <code>EOFException</code>
38.214 + * is thrown.
38.215 + *
38.216 + * <li>An I/O error occurs, in
38.217 + * which case an <code>IOException</code> other
38.218 + * than <code>EOFException</code> is thrown.
38.219 + * </ul>
38.220 + * <p>
38.221 + * If <code>b</code> is <code>null</code>,
38.222 + * a <code>NullPointerException</code> is thrown.
38.223 + * If <code>b.length</code> is zero, then
38.224 + * no bytes are read. Otherwise, the first
38.225 + * byte read is stored into element <code>b[0]</code>,
38.226 + * the next one into <code>b[1]</code>, and
38.227 + * so on.
38.228 + * If an exception is thrown from
38.229 + * this method, then it may be that some but
38.230 + * not all bytes of <code>b</code> have been
38.231 + * updated with data from the input stream.
38.232 + *
38.233 + * @param b the buffer into which the data is read.
38.234 + * @exception EOFException if this stream reaches the end before reading
38.235 + * all the bytes.
38.236 + * @exception IOException if an I/O error occurs.
38.237 + */
38.238 + void readFully(byte b[]) throws IOException;
38.239 +
38.240 + /**
38.241 + *
38.242 + * Reads <code>len</code>
38.243 + * bytes from
38.244 + * an input stream.
38.245 + * <p>
38.246 + * This method
38.247 + * blocks until one of the following conditions
38.248 + * occurs:<p>
38.249 + * <ul>
38.250 + * <li><code>len</code> bytes
38.251 + * of input data are available, in which case
38.252 + * a normal return is made.
38.253 + *
38.254 + * <li>End of file
38.255 + * is detected, in which case an <code>EOFException</code>
38.256 + * is thrown.
38.257 + *
38.258 + * <li>An I/O error occurs, in
38.259 + * which case an <code>IOException</code> other
38.260 + * than <code>EOFException</code> is thrown.
38.261 + * </ul>
38.262 + * <p>
38.263 + * If <code>b</code> is <code>null</code>,
38.264 + * a <code>NullPointerException</code> is thrown.
38.265 + * If <code>off</code> is negative, or <code>len</code>
38.266 + * is negative, or <code>off+len</code> is
38.267 + * greater than the length of the array <code>b</code>,
38.268 + * then an <code>IndexOutOfBoundsException</code>
38.269 + * is thrown.
38.270 + * If <code>len</code> is zero,
38.271 + * then no bytes are read. Otherwise, the first
38.272 + * byte read is stored into element <code>b[off]</code>,
38.273 + * the next one into <code>b[off+1]</code>,
38.274 + * and so on. The number of bytes read is,
38.275 + * at most, equal to <code>len</code>.
38.276 + *
38.277 + * @param b the buffer into which the data is read.
38.278 + * @param off an int specifying the offset into the data.
38.279 + * @param len an int specifying the number of bytes to read.
38.280 + * @exception EOFException if this stream reaches the end before reading
38.281 + * all the bytes.
38.282 + * @exception IOException if an I/O error occurs.
38.283 + */
38.284 + void readFully(byte b[], int off, int len) throws IOException;
38.285 +
38.286 + /**
38.287 + * Makes an attempt to skip over
38.288 + * <code>n</code> bytes
38.289 + * of data from the input
38.290 + * stream, discarding the skipped bytes. However,
38.291 + * it may skip
38.292 + * over some smaller number of
38.293 + * bytes, possibly zero. This may result from
38.294 + * any of a
38.295 + * number of conditions; reaching
38.296 + * end of file before <code>n</code> bytes
38.297 + * have been skipped is
38.298 + * only one possibility.
38.299 + * This method never throws an <code>EOFException</code>.
38.300 + * The actual
38.301 + * number of bytes skipped is returned.
38.302 + *
38.303 + * @param n the number of bytes to be skipped.
38.304 + * @return the number of bytes actually skipped.
38.305 + * @exception IOException if an I/O error occurs.
38.306 + */
38.307 + int skipBytes(int n) throws IOException;
38.308 +
38.309 + /**
38.310 + * Reads one input byte and returns
38.311 + * <code>true</code> if that byte is nonzero,
38.312 + * <code>false</code> if that byte is zero.
38.313 + * This method is suitable for reading
38.314 + * the byte written by the <code>writeBoolean</code>
38.315 + * method of interface <code>DataOutput</code>.
38.316 + *
38.317 + * @return the <code>boolean</code> value read.
38.318 + * @exception EOFException if this stream reaches the end before reading
38.319 + * all the bytes.
38.320 + * @exception IOException if an I/O error occurs.
38.321 + */
38.322 + boolean readBoolean() throws IOException;
38.323 +
38.324 + /**
38.325 + * Reads and returns one input byte.
38.326 + * The byte is treated as a signed value in
38.327 + * the range <code>-128</code> through <code>127</code>,
38.328 + * inclusive.
38.329 + * This method is suitable for
38.330 + * reading the byte written by the <code>writeByte</code>
38.331 + * method of interface <code>DataOutput</code>.
38.332 + *
38.333 + * @return the 8-bit value read.
38.334 + * @exception EOFException if this stream reaches the end before reading
38.335 + * all the bytes.
38.336 + * @exception IOException if an I/O error occurs.
38.337 + */
38.338 + byte readByte() throws IOException;
38.339 +
38.340 + /**
38.341 + * Reads one input byte, zero-extends
38.342 + * it to type <code>int</code>, and returns
38.343 + * the result, which is therefore in the range
38.344 + * <code>0</code>
38.345 + * through <code>255</code>.
38.346 + * This method is suitable for reading
38.347 + * the byte written by the <code>writeByte</code>
38.348 + * method of interface <code>DataOutput</code>
38.349 + * if the argument to <code>writeByte</code>
38.350 + * was intended to be a value in the range
38.351 + * <code>0</code> through <code>255</code>.
38.352 + *
38.353 + * @return the unsigned 8-bit value read.
38.354 + * @exception EOFException if this stream reaches the end before reading
38.355 + * all the bytes.
38.356 + * @exception IOException if an I/O error occurs.
38.357 + */
38.358 + int readUnsignedByte() throws IOException;
38.359 +
38.360 + /**
38.361 + * Reads two input bytes and returns
38.362 + * a <code>short</code> value. Let <code>a</code>
38.363 + * be the first byte read and <code>b</code>
38.364 + * be the second byte. The value
38.365 + * returned
38.366 + * is:
38.367 + * <p><pre><code>(short)((a << 8) | (b & 0xff))
38.368 + * </code></pre>
38.369 + * This method
38.370 + * is suitable for reading the bytes written
38.371 + * by the <code>writeShort</code> method of
38.372 + * interface <code>DataOutput</code>.
38.373 + *
38.374 + * @return the 16-bit value read.
38.375 + * @exception EOFException if this stream reaches the end before reading
38.376 + * all the bytes.
38.377 + * @exception IOException if an I/O error occurs.
38.378 + */
38.379 + short readShort() throws IOException;
38.380 +
38.381 + /**
38.382 + * Reads two input bytes and returns
38.383 + * an <code>int</code> value in the range <code>0</code>
38.384 + * through <code>65535</code>. Let <code>a</code>
38.385 + * be the first byte read and
38.386 + * <code>b</code>
38.387 + * be the second byte. The value returned is:
38.388 + * <p><pre><code>(((a & 0xff) << 8) | (b & 0xff))
38.389 + * </code></pre>
38.390 + * This method is suitable for reading the bytes
38.391 + * written by the <code>writeShort</code> method
38.392 + * of interface <code>DataOutput</code> if
38.393 + * the argument to <code>writeShort</code>
38.394 + * was intended to be a value in the range
38.395 + * <code>0</code> through <code>65535</code>.
38.396 + *
38.397 + * @return the unsigned 16-bit value read.
38.398 + * @exception EOFException if this stream reaches the end before reading
38.399 + * all the bytes.
38.400 + * @exception IOException if an I/O error occurs.
38.401 + */
38.402 + int readUnsignedShort() throws IOException;
38.403 +
38.404 + /**
38.405 + * Reads two input bytes and returns a <code>char</code> value.
38.406 + * Let <code>a</code>
38.407 + * be the first byte read and <code>b</code>
38.408 + * be the second byte. The value
38.409 + * returned is:
38.410 + * <p><pre><code>(char)((a << 8) | (b & 0xff))
38.411 + * </code></pre>
38.412 + * This method
38.413 + * is suitable for reading bytes written by
38.414 + * the <code>writeChar</code> method of interface
38.415 + * <code>DataOutput</code>.
38.416 + *
38.417 + * @return the <code>char</code> value read.
38.418 + * @exception EOFException if this stream reaches the end before reading
38.419 + * all the bytes.
38.420 + * @exception IOException if an I/O error occurs.
38.421 + */
38.422 + char readChar() throws IOException;
38.423 +
38.424 + /**
38.425 + * Reads four input bytes and returns an
38.426 + * <code>int</code> value. Let <code>a-d</code>
38.427 + * be the first through fourth bytes read. The value returned is:
38.428 + * <p><pre>
38.429 + * <code>
38.430 + * (((a & 0xff) << 24) | ((b & 0xff) << 16) |
38.431 + *  ((c & 0xff) << 8) | (d & 0xff))
38.432 + * </code></pre>
38.433 + * This method is suitable
38.434 + * for reading bytes written by the <code>writeInt</code>
38.435 + * method of interface <code>DataOutput</code>.
38.436 + *
38.437 + * @return the <code>int</code> value read.
38.438 + * @exception EOFException if this stream reaches the end before reading
38.439 + * all the bytes.
38.440 + * @exception IOException if an I/O error occurs.
38.441 + */
38.442 + int readInt() throws IOException;
38.443 +
38.444 + /**
38.445 + * Reads eight input bytes and returns
38.446 + * a <code>long</code> value. Let <code>a-h</code>
38.447 + * be the first through eighth bytes read.
38.448 + * The value returned is:
38.449 + * <p><pre> <code>
38.450 + * (((long)(a & 0xff) << 56) |
38.451 + * ((long)(b & 0xff) << 48) |
38.452 + * ((long)(c & 0xff) << 40) |
38.453 + * ((long)(d & 0xff) << 32) |
38.454 + * ((long)(e & 0xff) << 24) |
38.455 + * ((long)(f & 0xff) << 16) |
38.456 + * ((long)(g & 0xff) << 8) |
38.457 + * ((long)(h & 0xff)))
38.458 + * </code></pre>
38.459 + * <p>
38.460 + * This method is suitable
38.461 + * for reading bytes written by the <code>writeLong</code>
38.462 + * method of interface <code>DataOutput</code>.
38.463 + *
38.464 + * @return the <code>long</code> value read.
38.465 + * @exception EOFException if this stream reaches the end before reading
38.466 + * all the bytes.
38.467 + * @exception IOException if an I/O error occurs.
38.468 + */
38.469 + long readLong() throws IOException;
38.470 +
38.471 + /**
38.472 + * Reads four input bytes and returns
38.473 + * a <code>float</code> value. It does this
38.474 + * by first constructing an <code>int</code>
38.475 + * value in exactly the manner
38.476 + * of the <code>readInt</code>
38.477 + * method, then converting this <code>int</code>
38.478 + * value to a <code>float</code> in
38.479 + * exactly the manner of the method <code>Float.intBitsToFloat</code>.
38.480 + * This method is suitable for reading
38.481 + * bytes written by the <code>writeFloat</code>
38.482 + * method of interface <code>DataOutput</code>.
38.483 + *
38.484 + * @return the <code>float</code> value read.
38.485 + * @exception EOFException if this stream reaches the end before reading
38.486 + * all the bytes.
38.487 + * @exception IOException if an I/O error occurs.
38.488 + */
38.489 + float readFloat() throws IOException;
38.490 +
38.491 + /**
38.492 + * Reads eight input bytes and returns
38.493 + * a <code>double</code> value. It does this
38.494 + * by first constructing a <code>long</code>
38.495 + * value in exactly the manner
38.496 + * of the <code>readlong</code>
38.497 + * method, then converting this <code>long</code>
38.498 + * value to a <code>double</code> in exactly
38.499 + * the manner of the method <code>Double.longBitsToDouble</code>.
38.500 + * This method is suitable for reading
38.501 + * bytes written by the <code>writeDouble</code>
38.502 + * method of interface <code>DataOutput</code>.
38.503 + *
38.504 + * @return the <code>double</code> value read.
38.505 + * @exception EOFException if this stream reaches the end before reading
38.506 + * all the bytes.
38.507 + * @exception IOException if an I/O error occurs.
38.508 + */
38.509 + double readDouble() throws IOException;
38.510 +
38.511 + /**
38.512 + * Reads the next line of text from the input stream.
38.513 + * It reads successive bytes, converting
38.514 + * each byte separately into a character,
38.515 + * until it encounters a line terminator or
38.516 + * end of
38.517 + * file; the characters read are then
38.518 + * returned as a <code>String</code>. Note
38.519 + * that because this
38.520 + * method processes bytes,
38.521 + * it does not support input of the full Unicode
38.522 + * character set.
38.523 + * <p>
38.524 + * If end of file is encountered
38.525 + * before even one byte can be read, then <code>null</code>
38.526 + * is returned. Otherwise, each byte that is
38.527 + * read is converted to type <code>char</code>
38.528 + * by zero-extension. If the character <code>'\n'</code>
38.529 + * is encountered, it is discarded and reading
38.530 + * ceases. If the character <code>'\r'</code>
38.531 + * is encountered, it is discarded and, if
38.532 + * the following byte converts  to the
38.533 + * character <code>'\n'</code>, then that is
38.534 + * discarded also; reading then ceases. If
38.535 + * end of file is encountered before either
38.536 + * of the characters <code>'\n'</code> and
38.537 + * <code>'\r'</code> is encountered, reading
38.538 + * ceases. Once reading has ceased, a <code>String</code>
38.539 + * is returned that contains all the characters
38.540 + * read and not discarded, taken in order.
38.541 + * Note that every character in this string
38.542 + * will have a value less than <code>\u0100</code>,
38.543 + * that is, <code>(char)256</code>.
38.544 + *
38.545 + * @return the next line of text from the input stream,
38.546 + * or <CODE>null</CODE> if the end of file is
38.547 + * encountered before a byte can be read.
38.548 + * @exception IOException if an I/O error occurs.
38.549 + */
38.550 + String readLine() throws IOException;
38.551 +
38.552 + /**
38.553 + * Reads in a string that has been encoded using a
38.554 + * <a href="#modified-utf-8">modified UTF-8</a>
38.555 + * format.
38.556 + * The general contract of <code>readUTF</code>
38.557 + * is that it reads a representation of a Unicode
38.558 + * character string encoded in modified
38.559 + * UTF-8 format; this string of characters
38.560 + * is then returned as a <code>String</code>.
38.561 + * <p>
38.562 + * First, two bytes are read and used to
38.563 + * construct an unsigned 16-bit integer in
38.564 + * exactly the manner of the <code>readUnsignedShort</code>
38.565 + * method . This integer value is called the
38.566 + * <i>UTF length</i> and specifies the number
38.567 + * of additional bytes to be read. These bytes
38.568 + * are then converted to characters by considering
38.569 + * them in groups. The length of each group
38.570 + * is computed from the value of the first
38.571 + * byte of the group. The byte following a
38.572 + * group, if any, is the first byte of the
38.573 + * next group.
38.574 + * <p>
38.575 + * If the first byte of a group
38.576 + * matches the bit pattern <code>0xxxxxxx</code>
38.577 + * (where <code>x</code> means "may be <code>0</code>
38.578 + * or <code>1</code>"), then the group consists
38.579 + * of just that byte. The byte is zero-extended
38.580 + * to form a character.
38.581 + * <p>
38.582 + * If the first byte
38.583 + * of a group matches the bit pattern <code>110xxxxx</code>,
38.584 + * then the group consists of that byte <code>a</code>
38.585 + * and a second byte <code>b</code>. If there
38.586 + * is no byte <code>b</code> (because byte
38.587 + * <code>a</code> was the last of the bytes
38.588 + * to be read), or if byte <code>b</code> does
38.589 + * not match the bit pattern <code>10xxxxxx</code>,
38.590 + * then a <code>UTFDataFormatException</code>
38.591 + * is thrown. Otherwise, the group is converted
38.592 + * to the character:<p>
38.593 + * <pre><code>(char)(((a& 0x1F) << 6) | (b & 0x3F))
38.594 + * </code></pre>
38.595 + * If the first byte of a group
38.596 + * matches the bit pattern <code>1110xxxx</code>,
38.597 + * then the group consists of that byte <code>a</code>
38.598 + * and two more bytes <code>b</code> and <code>c</code>.
38.599 + * If there is no byte <code>c</code> (because
38.600 + * byte <code>a</code> was one of the last
38.601 + * two of the bytes to be read), or either
38.602 + * byte <code>b</code> or byte <code>c</code>
38.603 + * does not match the bit pattern <code>10xxxxxx</code>,
38.604 + * then a <code>UTFDataFormatException</code>
38.605 + * is thrown. Otherwise, the group is converted
38.606 + * to the character:<p>
38.607 + * <pre><code>
38.608 + * (char)(((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F))
38.609 + * </code></pre>
38.610 + * If the first byte of a group matches the
38.611 + * pattern <code>1111xxxx</code> or the pattern
38.612 + * <code>10xxxxxx</code>, then a <code>UTFDataFormatException</code>
38.613 + * is thrown.
38.614 + * <p>
38.615 + * If end of file is encountered
38.616 + * at any time during this entire process,
38.617 + * then an <code>EOFException</code> is thrown.
38.618 + * <p>
38.619 + * After every group has been converted to
38.620 + * a character by this process, the characters
38.621 + * are gathered, in the same order in which
38.622 + * their corresponding groups were read from
38.623 + * the input stream, to form a <code>String</code>,
38.624 + * which is returned.
38.625 + * <p>
38.626 + * The <code>writeUTF</code>
38.627 + * method of interface <code>DataOutput</code>
38.628 + * may be used to write data that is suitable
38.629 + * for reading by this method.
38.630 + * @return a Unicode string.
38.631 + * @exception EOFException if this stream reaches the end
38.632 + * before reading all the bytes.
38.633 + * @exception IOException if an I/O error occurs.
38.634 + * @exception UTFDataFormatException if the bytes do not represent a
38.635 + * valid modified UTF-8 encoding of a string.
38.636 + */
38.637 + String readUTF() throws IOException;
38.638 +}
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
39.2 +++ b/emul/src/main/java/java/io/DataInputStream.java Wed Jan 23 20:16:48 2013 +0100
39.3 @@ -0,0 +1,704 @@
39.4 +/*
39.5 + * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
39.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
39.7 + *
39.8 + * This code is free software; you can redistribute it and/or modify it
39.9 + * under the terms of the GNU General Public License version 2 only, as
39.10 + * published by the Free Software Foundation. Oracle designates this
39.11 + * particular file as subject to the "Classpath" exception as provided
39.12 + * by Oracle in the LICENSE file that accompanied this code.
39.13 + *
39.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
39.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
39.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
39.17 + * version 2 for more details (a copy is included in the LICENSE file that
39.18 + * accompanied this code).
39.19 + *
39.20 + * You should have received a copy of the GNU General Public License version
39.21 + * 2 along with this work; if not, write to the Free Software Foundation,
39.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
39.23 + *
39.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
39.25 + * or visit www.oracle.com if you need additional information or have any
39.26 + * questions.
39.27 + */
39.28 +
39.29 +package java.io;
39.30 +
39.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
39.32 +
39.33 +/**
39.34 + * A data input stream lets an application read primitive Java data
39.35 + * types from an underlying input stream in a machine-independent
39.36 + * way. An application uses a data output stream to write data that
39.37 + * can later be read by a data input stream.
39.38 + * <p>
39.39 + * DataInputStream is not necessarily safe for multithreaded access.
39.40 + * Thread safety is optional and is the responsibility of users of
39.41 + * methods in this class.
39.42 + *
39.43 + * @author Arthur van Hoff
39.44 + * @see java.io.DataOutputStream
39.45 + * @since JDK1.0
39.46 + */
39.47 +public
39.48 +class DataInputStream extends FilterInputStream implements DataInput {
39.49 +
39.50 + /**
39.51 + * Creates a DataInputStream that uses the specified
39.52 + * underlying InputStream.
39.53 + *
39.54 + * @param in the specified input stream
39.55 + */
39.56 + public DataInputStream(InputStream in) {
39.57 + super(in);
39.58 + }
39.59 +
39.60 + /**
39.61 + * working arrays initialized on demand by readUTF
39.62 + */
39.63 + private byte bytearr[] = new byte[80];
39.64 + private char chararr[] = new char[80];
39.65 +
39.66 + /**
39.67 + * Reads some number of bytes from the contained input stream and
39.68 + * stores them into the buffer array <code>b</code>. The number of
39.69 + * bytes actually read is returned as an integer. This method blocks
39.70 + * until input data is available, end of file is detected, or an
39.71 + * exception is thrown.
39.72 + *
39.73 + * <p>If <code>b</code> is null, a <code>NullPointerException</code> is
39.74 + * thrown. If the length of <code>b</code> is zero, then no bytes are
39.75 + * read and <code>0</code> is returned; otherwise, there is an attempt
39.76 + * to read at least one byte. If no byte is available because the
39.77 + * stream is at end of file, the value <code>-1</code> is returned;
39.78 + * otherwise, at least one byte is read and stored into <code>b</code>.
39.79 + *
39.80 + * <p>The first byte read is stored into element <code>b[0]</code>, the
39.81 + * next one into <code>b[1]</code>, and so on. The number of bytes read
39.82 + * is, at most, equal to the length of <code>b</code>. Let <code>k</code>
39.83 + * be the number of bytes actually read; these bytes will be stored in
39.84 + * elements <code>b[0]</code> through <code>b[k-1]</code>, leaving
39.85 + * elements <code>b[k]</code> through <code>b[b.length-1]</code>
39.86 + * unaffected.
39.87 + *
39.88 + * <p>The <code>read(b)</code> method has the same effect as:
39.89 + * <blockquote><pre>
39.90 + * read(b, 0, b.length)
39.91 + * </pre></blockquote>
39.92 + *
39.93 + * @param b the buffer into which the data is read.
39.94 + * @return the total number of bytes read into the buffer, or
39.95 + * <code>-1</code> if there is no more data because the end
39.96 + * of the stream has been reached.
39.97 + * @exception IOException if the first byte cannot be read for any reason
39.98 + * other than end of file, the stream has been closed and the underlying
39.99 + * input stream does not support reading after close, or another I/O
39.100 + * error occurs.
39.101 + * @see java.io.FilterInputStream#in
39.102 + * @see java.io.InputStream#read(byte[], int, int)
39.103 + */
39.104 + public final int read(byte b[]) throws IOException {
39.105 + return in.read(b, 0, b.length);
39.106 + }
39.107 +
39.108 + /**
39.109 + * Reads up to <code>len</code> bytes of data from the contained
39.110 + * input stream into an array of bytes. An attempt is made to read
39.111 + * as many as <code>len</code> bytes, but a smaller number may be read,
39.112 + * possibly zero. The number of bytes actually read is returned as an
39.113 + * integer.
39.114 + *
39.115 + * <p> This method blocks until input data is available, end of file is
39.116 + * detected, or an exception is thrown.
39.117 + *
39.118 + * <p> If <code>len</code> is zero, then no bytes are read and
39.119 + * <code>0</code> is returned; otherwise, there is an attempt to read at
39.120 + * least one byte. If no byte is available because the stream is at end of
39.121 + * file, the value <code>-1</code> is returned; otherwise, at least one
39.122 + * byte is read and stored into <code>b</code>.
39.123 + *
39.124 + * <p> The first byte read is stored into element <code>b[off]</code>, the
39.125 + * next one into <code>b[off+1]</code>, and so on. The number of bytes read
39.126 + * is, at most, equal to <code>len</code>. Let <i>k</i> be the number of
39.127 + * bytes actually read; these bytes will be stored in elements
39.128 + * <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>,
39.129 + * leaving elements <code>b[off+</code><i>k</i><code>]</code> through
39.130 + * <code>b[off+len-1]</code> unaffected.
39.131 + *
39.132 + * <p> In every case, elements <code>b[0]</code> through
39.133 + * <code>b[off]</code> and elements <code>b[off+len]</code> through
39.134 + * <code>b[b.length-1]</code> are unaffected.
39.135 + *
39.136 + * @param b the buffer into which the data is read.
39.137 + * @param off the start offset in the destination array <code>b</code>
39.138 + * @param len the maximum number of bytes read.
39.139 + * @return the total number of bytes read into the buffer, or
39.140 + * <code>-1</code> if there is no more data because the end
39.141 + * of the stream has been reached.
39.142 + * @exception NullPointerException If <code>b</code> is <code>null</code>.
39.143 + * @exception IndexOutOfBoundsException If <code>off</code> is negative,
39.144 + * <code>len</code> is negative, or <code>len</code> is greater than
39.145 + * <code>b.length - off</code>
39.146 + * @exception IOException if the first byte cannot be read for any reason
39.147 + * other than end of file, the stream has been closed and the underlying
39.148 + * input stream does not support reading after close, or another I/O
39.149 + * error occurs.
39.150 + * @see java.io.FilterInputStream#in
39.151 + * @see java.io.InputStream#read(byte[], int, int)
39.152 + */
39.153 + public final int read(byte b[], int off, int len) throws IOException {
39.154 + return in.read(b, off, len);
39.155 + }
39.156 +
39.157 + /**
39.158 + * See the general contract of the <code>readFully</code>
39.159 + * method of <code>DataInput</code>.
39.160 + * <p>
39.161 + * Bytes
39.162 + * for this operation are read from the contained
39.163 + * input stream.
39.164 + *
39.165 + * @param b the buffer into which the data is read.
39.166 + * @exception EOFException if this input stream reaches the end before
39.167 + * reading all the bytes.
39.168 + * @exception IOException the stream has been closed and the contained
39.169 + * input stream does not support reading after close, or
39.170 + * another I/O error occurs.
39.171 + * @see java.io.FilterInputStream#in
39.172 + */
39.173 + public final void readFully(byte b[]) throws IOException {
39.174 + readFully(b, 0, b.length);
39.175 + }
39.176 +
39.177 + /**
39.178 + * See the general contract of the <code>readFully</code>
39.179 + * method of <code>DataInput</code>.
39.180 + * <p>
39.181 + * Bytes
39.182 + * for this operation are read from the contained
39.183 + * input stream.
39.184 + *
39.185 + * @param b the buffer into which the data is read.
39.186 + * @param off the start offset of the data.
39.187 + * @param len the number of bytes to read.
39.188 + * @exception EOFException if this input stream reaches the end before
39.189 + * reading all the bytes.
39.190 + * @exception IOException the stream has been closed and the contained
39.191 + * input stream does not support reading after close, or
39.192 + * another I/O error occurs.
39.193 + * @see java.io.FilterInputStream#in
39.194 + */
39.195 + public final void readFully(byte b[], int off, int len) throws IOException {
39.196 + if (len < 0)
39.197 + throw new IndexOutOfBoundsException();
39.198 + int n = 0;
39.199 + while (n < len) {
39.200 + int count = in.read(b, off + n, len - n);
39.201 + if (count < 0)
39.202 + throw new EOFException();
39.203 + n += count;
39.204 + }
39.205 + }
39.206 +
39.207 + /**
39.208 + * See the general contract of the <code>skipBytes</code>
39.209 + * method of <code>DataInput</code>.
39.210 + * <p>
39.211 + * Bytes for this operation are read from the contained
39.212 + * input stream.
39.213 + *
39.214 + * @param n the number of bytes to be skipped.
39.215 + * @return the actual number of bytes skipped.
39.216 + * @exception IOException if the contained input stream does not support
39.217 + * seek, or the stream has been closed and
39.218 + * the contained input stream does not support
39.219 + * reading after close, or another I/O error occurs.
39.220 + */
39.221 + public final int skipBytes(int n) throws IOException {
39.222 + int total = 0;
39.223 + int cur = 0;
39.224 +
39.225 + while ((total<n) && ((cur = (int) in.skip(n-total)) > 0)) {
39.226 + total += cur;
39.227 + }
39.228 +
39.229 + return total;
39.230 + }
39.231 +
39.232 + /**
39.233 + * See the general contract of the <code>readBoolean</code>
39.234 + * method of <code>DataInput</code>.
39.235 + * <p>
39.236 + * Bytes for this operation are read from the contained
39.237 + * input stream.
39.238 + *
39.239 + * @return the <code>boolean</code> value read.
39.240 + * @exception EOFException if this input stream has reached the end.
39.241 + * @exception IOException the stream has been closed and the contained
39.242 + * input stream does not support reading after close, or
39.243 + * another I/O error occurs.
39.244 + * @see java.io.FilterInputStream#in
39.245 + */
39.246 + public final boolean readBoolean() throws IOException {
39.247 + int ch = in.read();
39.248 + if (ch < 0)
39.249 + throw new EOFException();
39.250 + return (ch != 0);
39.251 + }
39.252 +
39.253 + /**
39.254 + * See the general contract of the <code>readByte</code>
39.255 + * method of <code>DataInput</code>.
39.256 + * <p>
39.257 + * Bytes
39.258 + * for this operation are read from the contained
39.259 + * input stream.
39.260 + *
39.261 + * @return the next byte of this input stream as a signed 8-bit
39.262 + * <code>byte</code>.
39.263 + * @exception EOFException if this input stream has reached the end.
39.264 + * @exception IOException the stream has been closed and the contained
39.265 + * input stream does not support reading after close, or
39.266 + * another I/O error occurs.
39.267 + * @see java.io.FilterInputStream#in
39.268 + */
39.269 + public final byte readByte() throws IOException {
39.270 + int ch = in.read();
39.271 + if (ch < 0)
39.272 + throw new EOFException();
39.273 + return (byte)(ch);
39.274 + }
39.275 +
39.276 + /**
39.277 + * See the general contract of the <code>readUnsignedByte</code>
39.278 + * method of <code>DataInput</code>.
39.279 + * <p>
39.280 + * Bytes
39.281 + * for this operation are read from the contained
39.282 + * input stream.
39.283 + *
39.284 + * @return the next byte of this input stream, interpreted as an
39.285 + * unsigned 8-bit number.
39.286 + * @exception EOFException if this input stream has reached the end.
39.287 + * @exception IOException the stream has been closed and the contained
39.288 + * input stream does not support reading after close, or
39.289 + * another I/O error occurs.
39.290 + * @see java.io.FilterInputStream#in
39.291 + */
39.292 + public final int readUnsignedByte() throws IOException {
39.293 + int ch = in.read();
39.294 + if (ch < 0)
39.295 + throw new EOFException();
39.296 + return ch;
39.297 + }
39.298 +
39.299 + /**
39.300 + * See the general contract of the <code>readShort</code>
39.301 + * method of <code>DataInput</code>.
39.302 + * <p>
39.303 + * Bytes
39.304 + * for this operation are read from the contained
39.305 + * input stream.
39.306 + *
39.307 + * @return the next two bytes of this input stream, interpreted as a
39.308 + * signed 16-bit number.
39.309 + * @exception EOFException if this input stream reaches the end before
39.310 + * reading two bytes.
39.311 + * @exception IOException the stream has been closed and the contained
39.312 + * input stream does not support reading after close, or
39.313 + * another I/O error occurs.
39.314 + * @see java.io.FilterInputStream#in
39.315 + */
39.316 + public final short readShort() throws IOException {
39.317 + int ch1 = in.read();
39.318 + int ch2 = in.read();
39.319 + if ((ch1 | ch2) < 0)
39.320 + throw new EOFException();
39.321 + return (short)((ch1 << 8) + (ch2 << 0));
39.322 + }
39.323 +
39.324 + /**
39.325 + * See the general contract of the <code>readUnsignedShort</code>
39.326 + * method of <code>DataInput</code>.
39.327 + * <p>
39.328 + * Bytes
39.329 + * for this operation are read from the contained
39.330 + * input stream.
39.331 + *
39.332 + * @return the next two bytes of this input stream, interpreted as an
39.333 + * unsigned 16-bit integer.
39.334 + * @exception EOFException if this input stream reaches the end before
39.335 + * reading two bytes.
39.336 + * @exception IOException the stream has been closed and the contained
39.337 + * input stream does not support reading after close, or
39.338 + * another I/O error occurs.
39.339 + * @see java.io.FilterInputStream#in
39.340 + */
39.341 + public final int readUnsignedShort() throws IOException {
39.342 + int ch1 = in.read();
39.343 + int ch2 = in.read();
39.344 + if ((ch1 | ch2) < 0)
39.345 + throw new EOFException();
39.346 + return (ch1 << 8) + (ch2 << 0);
39.347 + }
39.348 +
39.349 + /**
39.350 + * See the general contract of the <code>readChar</code>
39.351 + * method of <code>DataInput</code>.
39.352 + * <p>
39.353 + * Bytes
39.354 + * for this operation are read from the contained
39.355 + * input stream.
39.356 + *
39.357 + * @return the next two bytes of this input stream, interpreted as a
39.358 + * <code>char</code>.
39.359 + * @exception EOFException if this input stream reaches the end before
39.360 + * reading two bytes.
39.361 + * @exception IOException the stream has been closed and the contained
39.362 + * input stream does not support reading after close, or
39.363 + * another I/O error occurs.
39.364 + * @see java.io.FilterInputStream#in
39.365 + */
39.366 + public final char readChar() throws IOException {
39.367 + int ch1 = in.read();
39.368 + int ch2 = in.read();
39.369 + if ((ch1 | ch2) < 0)
39.370 + throw new EOFException();
39.371 + return (char)((ch1 << 8) + (ch2 << 0));
39.372 + }
39.373 +
39.374 + /**
39.375 + * See the general contract of the <code>readInt</code>
39.376 + * method of <code>DataInput</code>.
39.377 + * <p>
39.378 + * Bytes
39.379 + * for this operation are read from the contained
39.380 + * input stream.
39.381 + *
39.382 + * @return the next four bytes of this input stream, interpreted as an
39.383 + * <code>int</code>.
39.384 + * @exception EOFException if this input stream reaches the end before
39.385 + * reading four bytes.
39.386 + * @exception IOException the stream has been closed and the contained
39.387 + * input stream does not support reading after close, or
39.388 + * another I/O error occurs.
39.389 + * @see java.io.FilterInputStream#in
39.390 + */
39.391 + public final int readInt() throws IOException {
39.392 + int ch1 = in.read();
39.393 + int ch2 = in.read();
39.394 + int ch3 = in.read();
39.395 + int ch4 = in.read();
39.396 + if ((ch1 | ch2 | ch3 | ch4) < 0)
39.397 + throw new EOFException();
39.398 + return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
39.399 + }
39.400 +
39.401 + private byte readBuffer[] = new byte[8];
39.402 +
39.403 + /**
39.404 + * See the general contract of the <code>readLong</code>
39.405 + * method of <code>DataInput</code>.
39.406 + * <p>
39.407 + * Bytes
39.408 + * for this operation are read from the contained
39.409 + * input stream.
39.410 + *
39.411 + * @return the next eight bytes of this input stream, interpreted as a
39.412 + * <code>long</code>.
39.413 + * @exception EOFException if this input stream reaches the end before
39.414 + * reading eight bytes.
39.415 + * @exception IOException the stream has been closed and the contained
39.416 + * input stream does not support reading after close, or
39.417 + * another I/O error occurs.
39.418 + * @see java.io.FilterInputStream#in
39.419 + */
39.420 + public final long readLong() throws IOException {
39.421 + readFully(readBuffer, 0, 8);
39.422 + return (((long)readBuffer[0] << 56) +
39.423 + ((long)(readBuffer[1] & 255) << 48) +
39.424 + ((long)(readBuffer[2] & 255) << 40) +
39.425 + ((long)(readBuffer[3] & 255) << 32) +
39.426 + ((long)(readBuffer[4] & 255) << 24) +
39.427 + ((readBuffer[5] & 255) << 16) +
39.428 + ((readBuffer[6] & 255) << 8) +
39.429 + ((readBuffer[7] & 255) << 0));
39.430 + }
39.431 +
39.432 + /**
39.433 + * See the general contract of the <code>readFloat</code>
39.434 + * method of <code>DataInput</code>.
39.435 + * <p>
39.436 + * Bytes
39.437 + * for this operation are read from the contained
39.438 + * input stream.
39.439 + *
39.440 + * @return the next four bytes of this input stream, interpreted as a
39.441 + * <code>float</code>.
39.442 + * @exception EOFException if this input stream reaches the end before
39.443 + * reading four bytes.
39.444 + * @exception IOException the stream has been closed and the contained
39.445 + * input stream does not support reading after close, or
39.446 + * another I/O error occurs.
39.447 + * @see java.io.DataInputStream#readInt()
39.448 + * @see java.lang.Float#intBitsToFloat(int)
39.449 + */
39.450 + public final float readFloat() throws IOException {
39.451 + return Float.intBitsToFloat(readInt());
39.452 + }
39.453 +
39.454 + /**
39.455 + * See the general contract of the <code>readDouble</code>
39.456 + * method of <code>DataInput</code>.
39.457 + * <p>
39.458 + * Bytes
39.459 + * for this operation are read from the contained
39.460 + * input stream.
39.461 + *
39.462 + * @return the next eight bytes of this input stream, interpreted as a
39.463 + * <code>double</code>.
39.464 + * @exception EOFException if this input stream reaches the end before
39.465 + * reading eight bytes.
39.466 + * @exception IOException the stream has been closed and the contained
39.467 + * input stream does not support reading after close, or
39.468 + * another I/O error occurs.
39.469 + * @see java.io.DataInputStream#readLong()
39.470 + * @see java.lang.Double#longBitsToDouble(long)
39.471 + */
39.472 + public final double readDouble() throws IOException {
39.473 + int hi = readInt();
39.474 + int low = readInt();
39.475 + return toDouble(hi, low);
39.476 + }
39.477 +
39.478 + @JavaScriptBody(args={ "hi", "low" },
39.479 + body=
39.480 + "if (low == 0) {\n"
39.481 + + " if (hi === 0x7ff00000) return Number.POSITIVE_INFINITY;\n"
39.482 + + " if (hi === 0xfff00000) return Number.NEGATIVE_INFINITY;\n"
39.483 + + "}\n"
39.484 + + "if (hi >= 0x7ff00000 && hi <= 0x7fffffff) return Number.NaN;\n"
39.485 + + "if (hi >= 0xfff00000 && hi <= 0xffffffff) return Number.NaN;\n"
39.486 + + "var s = (hi & 0x80000000) === 0 ? 1 : -1;\n"
39.487 + + "var e = (hi >> 20) & 0x7ff;\n"
39.488 + + "var to32 = low >> 0;\n"
39.489 + + "if (e === 0) {\n"
39.490 + + " if (to32 & 0x80000000) {\n"
39.491 + + " hi = hi << 1 + 1; low = low << 1;\n"
39.492 + + " } else {\n"
39.493 + + " hi = hi << 1; low = low << 1;\n"
39.494 + + " }\n"
39.495 + + "} else {\n"
39.496 + + " hi = (hi & 0xfffff) | 0x100000;\n"
39.497 + + "}\n"
39.498 + + "to32 = low >> 0;\n"
39.499 + + "var m = Math.pow(2.0, 32) * hi + to32;\n"
39.500 + + "var r = s * m * Math.pow(2.0, e - 1075);\n"
39.501 + + "//throw 'exp: ' + e + ' sign: ' + s + ' hi:' + hi + ' low: ' + low + ' m: ' + m + ' r: ' + r;\n"
39.502 + + "return r;\n"
39.503 + )
39.504 + private static double toDouble(int hi, int low) {
39.505 + long both = hi;
39.506 + both = (both << 32) & low;
39.507 + return Double.doubleToLongBits(both);
39.508 + }
39.509 +
39.510 + private char lineBuffer[];
39.511 +
39.512 + /**
39.513 + * See the general contract of the <code>readLine</code>
39.514 + * method of <code>DataInput</code>.
39.515 + * <p>
39.516 + * Bytes
39.517 + * for this operation are read from the contained
39.518 + * input stream.
39.519 + *
39.520 + * @deprecated This method does not properly convert bytes to characters.
39.521 + * As of JDK 1.1, the preferred way to read lines of text is via the
39.522 + * <code>BufferedReader.readLine()</code> method. Programs that use the
39.523 + * <code>DataInputStream</code> class to read lines can be converted to use
39.524 + * the <code>BufferedReader</code> class by replacing code of the form:
39.525 + * <blockquote><pre>
39.526 + * DataInputStream d = new DataInputStream(in);
39.527 + * </pre></blockquote>
39.528 + * with:
39.529 + * <blockquote><pre>
39.530 + * BufferedReader d
39.531 + * = new BufferedReader(new InputStreamReader(in));
39.532 + * </pre></blockquote>
39.533 + *
39.534 + * @return the next line of text from this input stream.
39.535 + * @exception IOException if an I/O error occurs.
39.536 + * @see java.io.BufferedReader#readLine()
39.537 + * @see java.io.FilterInputStream#in
39.538 + */
39.539 + @Deprecated
39.540 + public final String readLine() throws IOException {
39.541 + char buf[] = lineBuffer;
39.542 +
39.543 + if (buf == null) {
39.544 + buf = lineBuffer = new char[128];
39.545 + }
39.546 +
39.547 + int room = buf.length;
39.548 + int offset = 0;
39.549 + int c;
39.550 +
39.551 +loop: while (true) {
39.552 + switch (c = in.read()) {
39.553 + case -1:
39.554 + case '\n':
39.555 + break loop;
39.556 +
39.557 + case '\r':
39.558 + int c2 = in.read();
39.559 + if ((c2 != '\n') && (c2 != -1)) {
39.560 + if (!(in instanceof PushbackInputStream)) {
39.561 + this.in = new PushbackInputStream(in);
39.562 + }
39.563 + ((PushbackInputStream)in).unread(c2);
39.564 + }
39.565 + break loop;
39.566 +
39.567 + default:
39.568 + if (--room < 0) {
39.569 + buf = new char[offset + 128];
39.570 + room = buf.length - offset - 1;
39.571 + arraycopy(lineBuffer, 0, buf, 0, offset);
39.572 + lineBuffer = buf;
39.573 + }
39.574 + buf[offset++] = (char) c;
39.575 + break;
39.576 + }
39.577 + }
39.578 + if ((c == -1) && (offset == 0)) {
39.579 + return null;
39.580 + }
39.581 + return String.copyValueOf(buf, 0, offset);
39.582 + }
39.583 +
39.584 + /**
39.585 + * See the general contract of the <code>readUTF</code>
39.586 + * method of <code>DataInput</code>.
39.587 + * <p>
39.588 + * Bytes
39.589 + * for this operation are read from the contained
39.590 + * input stream.
39.591 + *
39.592 + * @return a Unicode string.
39.593 + * @exception EOFException if this input stream reaches the end before
39.594 + * reading all the bytes.
39.595 + * @exception IOException the stream has been closed and the contained
39.596 + * input stream does not support reading after close, or
39.597 + * another I/O error occurs.
39.598 + * @exception UTFDataFormatException if the bytes do not represent a valid
39.599 + * modified UTF-8 encoding of a string.
39.600 + * @see java.io.DataInputStream#readUTF(java.io.DataInput)
39.601 + */
39.602 + public final String readUTF() throws IOException {
39.603 + return readUTF(this);
39.604 + }
39.605 +
39.606 + /**
39.607 + * Reads from the
39.608 + * stream <code>in</code> a representation
39.609 + * of a Unicode character string encoded in
39.610 + * <a href="DataInput.html#modified-utf-8">modified UTF-8</a> format;
39.611 + * this string of characters is then returned as a <code>String</code>.
39.612 + * The details of the modified UTF-8 representation
39.613 + * are exactly the same as for the <code>readUTF</code>
39.614 + * method of <code>DataInput</code>.
39.615 + *
39.616 + * @param in a data input stream.
39.617 + * @return a Unicode string.
39.618 + * @exception EOFException if the input stream reaches the end
39.619 + * before all the bytes.
39.620 + * @exception IOException the stream has been closed and the contained
39.621 + * input stream does not support reading after close, or
39.622 + * another I/O error occurs.
39.623 + * @exception UTFDataFormatException if the bytes do not represent a
39.624 + * valid modified UTF-8 encoding of a Unicode string.
39.625 + * @see java.io.DataInputStream#readUnsignedShort()
39.626 + */
39.627 + public final static String readUTF(DataInput in) throws IOException {
39.628 + int utflen = in.readUnsignedShort();
39.629 + byte[] bytearr = null;
39.630 + char[] chararr = null;
39.631 + if (in instanceof DataInputStream) {
39.632 + DataInputStream dis = (DataInputStream)in;
39.633 + if (dis.bytearr.length < utflen){
39.634 + dis.bytearr = new byte[utflen*2];
39.635 + dis.chararr = new char[utflen*2];
39.636 + }
39.637 + chararr = dis.chararr;
39.638 + bytearr = dis.bytearr;
39.639 + } else {
39.640 + bytearr = new byte[utflen];
39.641 + chararr = new char[utflen];
39.642 + }
39.643 +
39.644 + int c, char2, char3;
39.645 + int count = 0;
39.646 + int chararr_count=0;
39.647 +
39.648 + in.readFully(bytearr, 0, utflen);
39.649 +
39.650 + while (count < utflen) {
39.651 + c = (int) bytearr[count] & 0xff;
39.652 + if (c > 127) break;
39.653 + count++;
39.654 + chararr[chararr_count++]=(char)c;
39.655 + }
39.656 +
39.657 + while (count < utflen) {
39.658 + c = (int) bytearr[count] & 0xff;
39.659 + switch (c >> 4) {
39.660 + case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
39.661 + /* 0xxxxxxx*/
39.662 + count++;
39.663 + chararr[chararr_count++]=(char)c;
39.664 + break;
39.665 + case 12: case 13:
39.666 + /* 110x xxxx 10xx xxxx*/
39.667 + count += 2;
39.668 + if (count > utflen)
39.669 + throw new UTFDataFormatException(
39.670 + "malformed input: partial character at end");
39.671 + char2 = (int) bytearr[count-1];
39.672 + if ((char2 & 0xC0) != 0x80)
39.673 + throw new UTFDataFormatException(
39.674 + "malformed input around byte " + count);
39.675 + chararr[chararr_count++]=(char)(((c & 0x1F) << 6) |
39.676 + (char2 & 0x3F));
39.677 + break;
39.678 + case 14:
39.679 + /* 1110 xxxx 10xx xxxx 10xx xxxx */
39.680 + count += 3;
39.681 + if (count > utflen)
39.682 + throw new UTFDataFormatException(
39.683 + "malformed input: partial character at end");
39.684 + char2 = (int) bytearr[count-2];
39.685 + char3 = (int) bytearr[count-1];
39.686 + if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
39.687 + throw new UTFDataFormatException(
39.688 + "malformed input around byte " + (count-1));
39.689 + chararr[chararr_count++]=(char)(((c & 0x0F) << 12) |
39.690 + ((char2 & 0x3F) << 6) |
39.691 + ((char3 & 0x3F) << 0));
39.692 + break;
39.693 + default:
39.694 + /* 10xx xxxx, 1111 xxxx */
39.695 + throw new UTFDataFormatException(
39.696 + "malformed input around byte " + count);
39.697 + }
39.698 + }
39.699 + // The number of chars produced may be less than utflen
39.700 + return new String(chararr, 0, chararr_count);
39.701 + }
39.702 + static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) {
39.703 + while (count-- > 0) {
39.704 + dst[dstBegin++] = value[srcBegin++];
39.705 + }
39.706 + }
39.707 +}
40.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
40.2 +++ b/emul/src/main/java/java/io/EOFException.java Wed Jan 23 20:16:48 2013 +0100
40.3 @@ -0,0 +1,65 @@
40.4 +/*
40.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
40.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
40.7 + *
40.8 + * This code is free software; you can redistribute it and/or modify it
40.9 + * under the terms of the GNU General Public License version 2 only, as
40.10 + * published by the Free Software Foundation. Oracle designates this
40.11 + * particular file as subject to the "Classpath" exception as provided
40.12 + * by Oracle in the LICENSE file that accompanied this code.
40.13 + *
40.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
40.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
40.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
40.17 + * version 2 for more details (a copy is included in the LICENSE file that
40.18 + * accompanied this code).
40.19 + *
40.20 + * You should have received a copy of the GNU General Public License version
40.21 + * 2 along with this work; if not, write to the Free Software Foundation,
40.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
40.23 + *
40.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
40.25 + * or visit www.oracle.com if you need additional information or have any
40.26 + * questions.
40.27 + */
40.28 +
40.29 +package java.io;
40.30 +
40.31 +/**
40.32 + * Signals that an end of file or end of stream has been reached
40.33 + * unexpectedly during input.
40.34 + * <p>
40.35 + * This exception is mainly used by data input streams to signal end of
40.36 + * stream. Note that many other input operations return a special value on
40.37 + * end of stream rather than throwing an exception.
40.38 + * <p>
40.39 + *
40.40 + * @author Frank Yellin
40.41 + * @see java.io.DataInputStream
40.42 + * @see java.io.IOException
40.43 + * @since JDK1.0
40.44 + */
40.45 +public
40.46 +class EOFException extends IOException {
40.47 + private static final long serialVersionUID = 6433858223774886977L;
40.48 +
40.49 + /**
40.50 + * Constructs an <code>EOFException</code> with <code>null</code>
40.51 + * as its error detail message.
40.52 + */
40.53 + public EOFException() {
40.54 + super();
40.55 + }
40.56 +
40.57 + /**
40.58 + * Constructs an <code>EOFException</code> with the specified detail
40.59 + * message. The string <code>s</code> may later be retrieved by the
40.60 + * <code>{@link java.lang.Throwable#getMessage}</code> method of class
40.61 + * <code>java.lang.Throwable</code>.
40.62 + *
40.63 + * @param s the detail message.
40.64 + */
40.65 + public EOFException(String s) {
40.66 + super(s);
40.67 + }
40.68 +}
41.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
41.2 +++ b/emul/src/main/java/java/io/FilterInputStream.java Wed Jan 23 20:16:48 2013 +0100
41.3 @@ -0,0 +1,245 @@
41.4 +/*
41.5 + * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
41.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
41.7 + *
41.8 + * This code is free software; you can redistribute it and/or modify it
41.9 + * under the terms of the GNU General Public License version 2 only, as
41.10 + * published by the Free Software Foundation. Oracle designates this
41.11 + * particular file as subject to the "Classpath" exception as provided
41.12 + * by Oracle in the LICENSE file that accompanied this code.
41.13 + *
41.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
41.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
41.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
41.17 + * version 2 for more details (a copy is included in the LICENSE file that
41.18 + * accompanied this code).
41.19 + *
41.20 + * You should have received a copy of the GNU General Public License version
41.21 + * 2 along with this work; if not, write to the Free Software Foundation,
41.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
41.23 + *
41.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
41.25 + * or visit www.oracle.com if you need additional information or have any
41.26 + * questions.
41.27 + */
41.28 +
41.29 +package java.io;
41.30 +
41.31 +/**
41.32 + * A <code>FilterInputStream</code> contains
41.33 + * some other input stream, which it uses as
41.34 + * its basic source of data, possibly transforming
41.35 + * the data along the way or providing additional
41.36 + * functionality. The class <code>FilterInputStream</code>
41.37 + * itself simply overrides all methods of
41.38 + * <code>InputStream</code> with versions that
41.39 + * pass all requests to the contained input
41.40 + * stream. Subclasses of <code>FilterInputStream</code>
41.41 + * may further override some of these methods
41.42 + * and may also provide additional methods
41.43 + * and fields.
41.44 + *
41.45 + * @author Jonathan Payne
41.46 + * @since JDK1.0
41.47 + */
41.48 +public
41.49 +class FilterInputStream extends InputStream {
41.50 + /**
41.51 + * The input stream to be filtered.
41.52 + */
41.53 + protected volatile InputStream in;
41.54 +
41.55 + /**
41.56 + * Creates a <code>FilterInputStream</code>
41.57 + * by assigning the argument <code>in</code>
41.58 + * to the field <code>this.in</code> so as
41.59 + * to remember it for later use.
41.60 + *
41.61 + * @param in the underlying input stream, or <code>null</code> if
41.62 + * this instance is to be created without an underlying stream.
41.63 + */
41.64 + protected FilterInputStream(InputStream in) {
41.65 + this.in = in;
41.66 + }
41.67 +
41.68 + /**
41.69 + * Reads the next byte of data from this input stream. The value
41.70 + * byte is returned as an <code>int</code> in the range
41.71 + * <code>0</code> to <code>255</code>. If no byte is available
41.72 + * because the end of the stream has been reached, the value
41.73 + * <code>-1</code> is returned. This method blocks until input data
41.74 + * is available, the end of the stream is detected, or an exception
41.75 + * is thrown.
41.76 + * <p>
41.77 + * This method
41.78 + * simply performs <code>in.read()</code> and returns the result.
41.79 + *
41.80 + * @return the next byte of data, or <code>-1</code> if the end of the
41.81 + * stream is reached.
41.82 + * @exception IOException if an I/O error occurs.
41.83 + * @see java.io.FilterInputStream#in
41.84 + */
41.85 + public int read() throws IOException {
41.86 + return in.read();
41.87 + }
41.88 +
41.89 + /**
41.90 + * Reads up to <code>byte.length</code> bytes of data from this
41.91 + * input stream into an array of bytes. This method blocks until some
41.92 + * input is available.
41.93 + * <p>
41.94 + * This method simply performs the call
41.95 + * <code>read(b, 0, b.length)</code> and returns
41.96 + * the result. It is important that it does
41.97 + * <i>not</i> do <code>in.read(b)</code> instead;
41.98 + * certain subclasses of <code>FilterInputStream</code>
41.99 + * depend on the implementation strategy actually
41.100 + * used.
41.101 + *
41.102 + * @param b the buffer into which the data is read.
41.103 + * @return the total number of bytes read into the buffer, or
41.104 + * <code>-1</code> if there is no more data because the end of
41.105 + * the stream has been reached.
41.106 + * @exception IOException if an I/O error occurs.
41.107 + * @see java.io.FilterInputStream#read(byte[], int, int)
41.108 + */
41.109 + public int read(byte b[]) throws IOException {
41.110 + return read(b, 0, b.length);
41.111 + }
41.112 +
41.113 + /**
41.114 + * Reads up to <code>len</code> bytes of data from this input stream
41.115 + * into an array of bytes. If <code>len</code> is not zero, the method
41.116 + * blocks until some input is available; otherwise, no
41.117 + * bytes are read and <code>0</code> is returned.
41.118 + * <p>
41.119 + * This method simply performs <code>in.read(b, off, len)</code>
41.120 + * and returns the result.
41.121 + *
41.122 + * @param b the buffer into which the data is read.
41.123 + * @param off the start offset in the destination array <code>b</code>
41.124 + * @param len the maximum number of bytes read.
41.125 + * @return the total number of bytes read into the buffer, or
41.126 + * <code>-1</code> if there is no more data because the end of
41.127 + * the stream has been reached.
41.128 + * @exception NullPointerException If <code>b</code> is <code>null</code>.
41.129 + * @exception IndexOutOfBoundsException If <code>off</code> is negative,
41.130 + * <code>len</code> is negative, or <code>len</code> is greater than
41.131 + * <code>b.length - off</code>
41.132 + * @exception IOException if an I/O error occurs.
41.133 + * @see java.io.FilterInputStream#in
41.134 + */
41.135 + public int read(byte b[], int off, int len) throws IOException {
41.136 + return in.read(b, off, len);
41.137 + }
41.138 +
41.139 + /**
41.140 + * Skips over and discards <code>n</code> bytes of data from the
41.141 + * input stream. The <code>skip</code> method may, for a variety of
41.142 + * reasons, end up skipping over some smaller number of bytes,
41.143 + * possibly <code>0</code>. The actual number of bytes skipped is
41.144 + * returned.
41.145 + * <p>
41.146 + * This method simply performs <code>in.skip(n)</code>.
41.147 + *
41.148 + * @param n the number of bytes to be skipped.
41.149 + * @return the actual number of bytes skipped.
41.150 + * @exception IOException if the stream does not support seek,
41.151 + * or if some other I/O error occurs.
41.152 + */
41.153 + public long skip(long n) throws IOException {
41.154 + return in.skip(n);
41.155 + }
41.156 +
41.157 + /**
41.158 + * Returns an estimate of the number of bytes that can be read (or
41.159 + * skipped over) from this input stream without blocking by the next
41.160 + * caller of a method for this input stream. The next caller might be
41.161 + * the same thread or another thread. A single read or skip of this
41.162 + * many bytes will not block, but may read or skip fewer bytes.
41.163 + * <p>
41.164 + * This method returns the result of {@link #in in}.available().
41.165 + *
41.166 + * @return an estimate of the number of bytes that can be read (or skipped
41.167 + * over) from this input stream without blocking.
41.168 + * @exception IOException if an I/O error occurs.
41.169 + */
41.170 + public int available() throws IOException {
41.171 + return in.available();
41.172 + }
41.173 +
41.174 + /**
41.175 + * Closes this input stream and releases any system resources
41.176 + * associated with the stream.
41.177 + * This
41.178 + * method simply performs <code>in.close()</code>.
41.179 + *
41.180 + * @exception IOException if an I/O error occurs.
41.181 + * @see java.io.FilterInputStream#in
41.182 + */
41.183 + public void close() throws IOException {
41.184 + in.close();
41.185 + }
41.186 +
41.187 + /**
41.188 + * Marks the current position in this input stream. A subsequent
41.189 + * call to the <code>reset</code> method repositions this stream at
41.190 + * the last marked position so that subsequent reads re-read the same bytes.
41.191 + * <p>
41.192 + * The <code>readlimit</code> argument tells this input stream to
41.193 + * allow that many bytes to be read before the mark position gets
41.194 + * invalidated.
41.195 + * <p>
41.196 + * This method simply performs <code>in.mark(readlimit)</code>.
41.197 + *
41.198 + * @param readlimit the maximum limit of bytes that can be read before
41.199 + * the mark position becomes invalid.
41.200 + * @see java.io.FilterInputStream#in
41.201 + * @see java.io.FilterInputStream#reset()
41.202 + */
41.203 + public synchronized void mark(int readlimit) {
41.204 + in.mark(readlimit);
41.205 + }
41.206 +
41.207 + /**
41.208 + * Repositions this stream to the position at the time the
41.209 + * <code>mark</code> method was last called on this input stream.
41.210 + * <p>
41.211 + * This method
41.212 + * simply performs <code>in.reset()</code>.
41.213 + * <p>
41.214 + * Stream marks are intended to be used in
41.215 + * situations where you need to read ahead a little to see what's in
41.216 + * the stream. Often this is most easily done by invoking some
41.217 + * general parser. If the stream is of the type handled by the
41.218 + * parse, it just chugs along happily. If the stream is not of
41.219 + * that type, the parser should toss an exception when it fails.
41.220 + * If this happens within readlimit bytes, it allows the outer
41.221 + * code to reset the stream and try another parser.
41.222 + *
41.223 + * @exception IOException if the stream has not been marked or if the
41.224 + * mark has been invalidated.
41.225 + * @see java.io.FilterInputStream#in
41.226 + * @see java.io.FilterInputStream#mark(int)
41.227 + */
41.228 + public synchronized void reset() throws IOException {
41.229 + in.reset();
41.230 + }
41.231 +
41.232 + /**
41.233 + * Tests if this input stream supports the <code>mark</code>
41.234 + * and <code>reset</code> methods.
41.235 + * This method
41.236 + * simply performs <code>in.markSupported()</code>.
41.237 + *
41.238 + * @return <code>true</code> if this stream type supports the
41.239 + * <code>mark</code> and <code>reset</code> method;
41.240 + * <code>false</code> otherwise.
41.241 + * @see java.io.FilterInputStream#in
41.242 + * @see java.io.InputStream#mark(int)
41.243 + * @see java.io.InputStream#reset()
41.244 + */
41.245 + public boolean markSupported() {
41.246 + return in.markSupported();
41.247 + }
41.248 +}
42.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
42.2 +++ b/emul/src/main/java/java/io/InputStream.java Wed Jan 23 20:16:48 2013 +0100
42.3 @@ -0,0 +1,370 @@
42.4 +/*
42.5 + * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
42.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
42.7 + *
42.8 + * This code is free software; you can redistribute it and/or modify it
42.9 + * under the terms of the GNU General Public License version 2 only, as
42.10 + * published by the Free Software Foundation. Oracle designates this
42.11 + * particular file as subject to the "Classpath" exception as provided
42.12 + * by Oracle in the LICENSE file that accompanied this code.
42.13 + *
42.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
42.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
42.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
42.17 + * version 2 for more details (a copy is included in the LICENSE file that
42.18 + * accompanied this code).
42.19 + *
42.20 + * You should have received a copy of the GNU General Public License version
42.21 + * 2 along with this work; if not, write to the Free Software Foundation,
42.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
42.23 + *
42.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
42.25 + * or visit www.oracle.com if you need additional information or have any
42.26 + * questions.
42.27 + */
42.28 +
42.29 +package java.io;
42.30 +
42.31 +/**
42.32 + * This abstract class is the superclass of all classes representing
42.33 + * an input stream of bytes.
42.34 + *
42.35 + * <p> Applications that need to define a subclass of <code>InputStream</code>
42.36 + * must always provide a method that returns the next byte of input.
42.37 + *
42.38 + * @author Arthur van Hoff
42.39 + * @see java.io.BufferedInputStream
42.40 + * @see java.io.ByteArrayInputStream
42.41 + * @see java.io.DataInputStream
42.42 + * @see java.io.FilterInputStream
42.43 + * @see java.io.InputStream#read()
42.44 + * @see java.io.OutputStream
42.45 + * @see java.io.PushbackInputStream
42.46 + * @since JDK1.0
42.47 + */
42.48 +public abstract class InputStream implements Closeable {
42.49 +
42.50 + // SKIP_BUFFER_SIZE is used to determine the size of skipBuffer
42.51 + private static final int SKIP_BUFFER_SIZE = 2048;
42.52 + // skipBuffer is initialized in skip(long), if needed.
42.53 + private static byte[] skipBuffer;
42.54 +
42.55 + /**
42.56 + * Reads the next byte of data from the input stream. The value byte is
42.57 + * returned as an <code>int</code> in the range <code>0</code> to
42.58 + * <code>255</code>. If no byte is available because the end of the stream
42.59 + * has been reached, the value <code>-1</code> is returned. This method
42.60 + * blocks until input data is available, the end of the stream is detected,
42.61 + * or an exception is thrown.
42.62 + *
42.63 + * <p> A subclass must provide an implementation of this method.
42.64 + *
42.65 + * @return the next byte of data, or <code>-1</code> if the end of the
42.66 + * stream is reached.
42.67 + * @exception IOException if an I/O error occurs.
42.68 + */
42.69 + public abstract int read() throws IOException;
42.70 +
42.71 + /**
42.72 + * Reads some number of bytes from the input stream and stores them into
42.73 + * the buffer array <code>b</code>. The number of bytes actually read is
42.74 + * returned as an integer. This method blocks until input data is
42.75 + * available, end of file is detected, or an exception is thrown.
42.76 + *
42.77 + * <p> If the length of <code>b</code> is zero, then no bytes are read and
42.78 + * <code>0</code> is returned; otherwise, there is an attempt to read at
42.79 + * least one byte. If no byte is available because the stream is at the
42.80 + * end of the file, the value <code>-1</code> is returned; otherwise, at
42.81 + * least one byte is read and stored into <code>b</code>.
42.82 + *
42.83 + * <p> The first byte read is stored into element <code>b[0]</code>, the
42.84 + * next one into <code>b[1]</code>, and so on. The number of bytes read is,
42.85 + * at most, equal to the length of <code>b</code>. Let <i>k</i> be the
42.86 + * number of bytes actually read; these bytes will be stored in elements
42.87 + * <code>b[0]</code> through <code>b[</code><i>k</i><code>-1]</code>,
42.88 + * leaving elements <code>b[</code><i>k</i><code>]</code> through
42.89 + * <code>b[b.length-1]</code> unaffected.
42.90 + *
42.91 + * <p> The <code>read(b)</code> method for class <code>InputStream</code>
42.92 + * has the same effect as: <pre><code> read(b, 0, b.length) </code></pre>
42.93 + *
42.94 + * @param b the buffer into which the data is read.
42.95 + * @return the total number of bytes read into the buffer, or
42.96 + * <code>-1</code> if there is no more data because the end of
42.97 + * the stream has been reached.
42.98 + * @exception IOException If the first byte cannot be read for any reason
42.99 + * other than the end of the file, if the input stream has been closed, or
42.100 + * if some other I/O error occurs.
42.101 + * @exception NullPointerException if <code>b</code> is <code>null</code>.
42.102 + * @see java.io.InputStream#read(byte[], int, int)
42.103 + */
42.104 + public int read(byte b[]) throws IOException {
42.105 + return read(b, 0, b.length);
42.106 + }
42.107 +
42.108 + /**
42.109 + * Reads up to <code>len</code> bytes of data from the input stream into
42.110 + * an array of bytes. An attempt is made to read as many as
42.111 + * <code>len</code> bytes, but a smaller number may be read.
42.112 + * The number of bytes actually read is returned as an integer.
42.113 + *
42.114 + * <p> This method blocks until input data is available, end of file is
42.115 + * detected, or an exception is thrown.
42.116 + *
42.117 + * <p> If <code>len</code> is zero, then no bytes are read and
42.118 + * <code>0</code> is returned; otherwise, there is an attempt to read at
42.119 + * least one byte. If no byte is available because the stream is at end of
42.120 + * file, the value <code>-1</code> is returned; otherwise, at least one
42.121 + * byte is read and stored into <code>b</code>.
42.122 + *
42.123 + * <p> The first byte read is stored into element <code>b[off]</code>, the
42.124 + * next one into <code>b[off+1]</code>, and so on. The number of bytes read
42.125 + * is, at most, equal to <code>len</code>. Let <i>k</i> be the number of
42.126 + * bytes actually read; these bytes will be stored in elements
42.127 + * <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>,
42.128 + * leaving elements <code>b[off+</code><i>k</i><code>]</code> through
42.129 + * <code>b[off+len-1]</code> unaffected.
42.130 + *
42.131 + * <p> In every case, elements <code>b[0]</code> through
42.132 + * <code>b[off]</code> and elements <code>b[off+len]</code> through
42.133 + * <code>b[b.length-1]</code> are unaffected.
42.134 + *
42.135 + * <p> The <code>read(b,</code> <code>off,</code> <code>len)</code> method
42.136 + * for class <code>InputStream</code> simply calls the method
42.137 + * <code>read()</code> repeatedly. If the first such call results in an
42.138 + * <code>IOException</code>, that exception is returned from the call to
42.139 + * the <code>read(b,</code> <code>off,</code> <code>len)</code> method. If
42.140 + * any subsequent call to <code>read()</code> results in a
42.141 + * <code>IOException</code>, the exception is caught and treated as if it
42.142 + * were end of file; the bytes read up to that point are stored into
42.143 + * <code>b</code> and the number of bytes read before the exception
42.144 + * occurred is returned. The default implementation of this method blocks
42.145 + * until the requested amount of input data <code>len</code> has been read,
42.146 + * end of file is detected, or an exception is thrown. Subclasses are encouraged
42.147 + * to provide a more efficient implementation of this method.
42.148 + *
42.149 + * @param b the buffer into which the data is read.
42.150 + * @param off the start offset in array <code>b</code>
42.151 + * at which the data is written.
42.152 + * @param len the maximum number of bytes to read.
42.153 + * @return the total number of bytes read into the buffer, or
42.154 + * <code>-1</code> if there is no more data because the end of
42.155 + * the stream has been reached.
42.156 + * @exception IOException If the first byte cannot be read for any reason
42.157 + * other than end of file, or if the input stream has been closed, or if
42.158 + * some other I/O error occurs.
42.159 + * @exception NullPointerException If <code>b</code> is <code>null</code>.
42.160 + * @exception IndexOutOfBoundsException If <code>off</code> is negative,
42.161 + * <code>len</code> is negative, or <code>len</code> is greater than
42.162 + * <code>b.length - off</code>
42.163 + * @see java.io.InputStream#read()
42.164 + */
42.165 + public int read(byte b[], int off, int len) throws IOException {
42.166 + if (b == null) {
42.167 + throw new NullPointerException();
42.168 + } else if (off < 0 || len < 0 || len > b.length - off) {
42.169 + throw new IndexOutOfBoundsException();
42.170 + } else if (len == 0) {
42.171 + return 0;
42.172 + }
42.173 +
42.174 + int c = read();
42.175 + if (c == -1) {
42.176 + return -1;
42.177 + }
42.178 + b[off] = (byte)c;
42.179 +
42.180 + int i = 1;
42.181 + try {
42.182 + for (; i < len ; i++) {
42.183 + c = read();
42.184 + if (c == -1) {
42.185 + break;
42.186 + }
42.187 + b[off + i] = (byte)c;
42.188 + }
42.189 + } catch (IOException ee) {
42.190 + }
42.191 + return i;
42.192 + }
42.193 +
42.194 + /**
42.195 + * Skips over and discards <code>n</code> bytes of data from this input
42.196 + * stream. The <code>skip</code> method may, for a variety of reasons, end
42.197 + * up skipping over some smaller number of bytes, possibly <code>0</code>.
42.198 + * This may result from any of a number of conditions; reaching end of file
42.199 + * before <code>n</code> bytes have been skipped is only one possibility.
42.200 + * The actual number of bytes skipped is returned. If <code>n</code> is
42.201 + * negative, no bytes are skipped.
42.202 + *
42.203 + * <p> The <code>skip</code> method of this class creates a
42.204 + * byte array and then repeatedly reads into it until <code>n</code> bytes
42.205 + * have been read or the end of the stream has been reached. Subclasses are
42.206 + * encouraged to provide a more efficient implementation of this method.
42.207 + * For instance, the implementation may depend on the ability to seek.
42.208 + *
42.209 + * @param n the number of bytes to be skipped.
42.210 + * @return the actual number of bytes skipped.
42.211 + * @exception IOException if the stream does not support seek,
42.212 + * or if some other I/O error occurs.
42.213 + */
42.214 + public long skip(long n) throws IOException {
42.215 +
42.216 + long remaining = n;
42.217 + int nr;
42.218 + if (skipBuffer == null)
42.219 + skipBuffer = new byte[SKIP_BUFFER_SIZE];
42.220 +
42.221 + byte[] localSkipBuffer = skipBuffer;
42.222 +
42.223 + if (n <= 0) {
42.224 + return 0;
42.225 + }
42.226 +
42.227 + while (remaining > 0) {
42.228 + nr = read(localSkipBuffer, 0,
42.229 + (int) Math.min(SKIP_BUFFER_SIZE, remaining));
42.230 + if (nr < 0) {
42.231 + break;
42.232 + }
42.233 + remaining -= nr;
42.234 + }
42.235 +
42.236 + return n - remaining;
42.237 + }
42.238 +
42.239 + /**
42.240 + * Returns an estimate of the number of bytes that can be read (or
42.241 + * skipped over) from this input stream without blocking by the next
42.242 + * invocation of a method for this input stream. The next invocation
42.243 + * might be the same thread or another thread. A single read or skip of this
42.244 + * many bytes will not block, but may read or skip fewer bytes.
42.245 + *
42.246 + * <p> Note that while some implementations of {@code InputStream} will return
42.247 + * the total number of bytes in the stream, many will not. It is
42.248 + * never correct to use the return value of this method to allocate
42.249 + * a buffer intended to hold all data in this stream.
42.250 + *
42.251 + * <p> A subclass' implementation of this method may choose to throw an
42.252 + * {@link IOException} if this input stream has been closed by
42.253 + * invoking the {@link #close()} method.
42.254 + *
42.255 + * <p> The {@code available} method for class {@code InputStream} always
42.256 + * returns {@code 0}.
42.257 + *
42.258 + * <p> This method should be overridden by subclasses.
42.259 + *
42.260 + * @return an estimate of the number of bytes that can be read (or skipped
42.261 + * over) from this input stream without blocking or {@code 0} when
42.262 + * it reaches the end of the input stream.
42.263 + * @exception IOException if an I/O error occurs.
42.264 + */
42.265 + public int available() throws IOException {
42.266 + return 0;
42.267 + }
42.268 +
42.269 + /**
42.270 + * Closes this input stream and releases any system resources associated
42.271 + * with the stream.
42.272 + *
42.273 + * <p> The <code>close</code> method of <code>InputStream</code> does
42.274 + * nothing.
42.275 + *
42.276 + * @exception IOException if an I/O error occurs.
42.277 + */
42.278 + public void close() throws IOException {}
42.279 +
42.280 + /**
42.281 + * Marks the current position in this input stream. A subsequent call to
42.282 + * the <code>reset</code> method repositions this stream at the last marked
42.283 + * position so that subsequent reads re-read the same bytes.
42.284 + *
42.285 + * <p> The <code>readlimit</code> arguments tells this input stream to
42.286 + * allow that many bytes to be read before the mark position gets
42.287 + * invalidated.
42.288 + *
42.289 + * <p> The general contract of <code>mark</code> is that, if the method
42.290 + * <code>markSupported</code> returns <code>true</code>, the stream somehow
42.291 + * remembers all the bytes read after the call to <code>mark</code> and
42.292 + * stands ready to supply those same bytes again if and whenever the method
42.293 + * <code>reset</code> is called. However, the stream is not required to
42.294 + * remember any data at all if more than <code>readlimit</code> bytes are
42.295 + * read from the stream before <code>reset</code> is called.
42.296 + *
42.297 + * <p> Marking a closed stream should not have any effect on the stream.
42.298 + *
42.299 + * <p> The <code>mark</code> method of <code>InputStream</code> does
42.300 + * nothing.
42.301 + *
42.302 + * @param readlimit the maximum limit of bytes that can be read before
42.303 + * the mark position becomes invalid.
42.304 + * @see java.io.InputStream#reset()
42.305 + */
42.306 + public synchronized void mark(int readlimit) {}
42.307 +
42.308 + /**
42.309 + * Repositions this stream to the position at the time the
42.310 + * <code>mark</code> method was last called on this input stream.
42.311 + *
42.312 + * <p> The general contract of <code>reset</code> is:
42.313 + *
42.314 + * <p><ul>
42.315 + *
42.316 + * <li> If the method <code>markSupported</code> returns
42.317 + * <code>true</code>, then:
42.318 + *
42.319 + * <ul><li> If the method <code>mark</code> has not been called since
42.320 + * the stream was created, or the number of bytes read from the stream
42.321 + * since <code>mark</code> was last called is larger than the argument
42.322 + * to <code>mark</code> at that last call, then an
42.323 + * <code>IOException</code> might be thrown.
42.324 + *
42.325 + * <li> If such an <code>IOException</code> is not thrown, then the
42.326 + * stream is reset to a state such that all the bytes read since the
42.327 + * most recent call to <code>mark</code> (or since the start of the
42.328 + * file, if <code>mark</code> has not been called) will be resupplied
42.329 + * to subsequent callers of the <code>read</code> method, followed by
42.330 + * any bytes that otherwise would have been the next input data as of
42.331 + * the time of the call to <code>reset</code>. </ul>
42.332 + *
42.333 + * <li> If the method <code>markSupported</code> returns
42.334 + * <code>false</code>, then:
42.335 + *
42.336 + * <ul><li> The call to <code>reset</code> may throw an
42.337 + * <code>IOException</code>.
42.338 + *
42.339 + * <li> If an <code>IOException</code> is not thrown, then the stream
42.340 + * is reset to a fixed state that depends on the particular type of the
42.341 + * input stream and how it was created. The bytes that will be supplied
42.342 + * to subsequent callers of the <code>read</code> method depend on the
42.343 + * particular type of the input stream. </ul></ul>
42.344 + *
42.345 + * <p>The method <code>reset</code> for class <code>InputStream</code>
42.346 + * does nothing except throw an <code>IOException</code>.
42.347 + *
42.348 + * @exception IOException if this stream has not been marked or if the
42.349 + * mark has been invalidated.
42.350 + * @see java.io.InputStream#mark(int)
42.351 + * @see java.io.IOException
42.352 + */
42.353 + public synchronized void reset() throws IOException {
42.354 + throw new IOException("mark/reset not supported");
42.355 + }
42.356 +
42.357 + /**
42.358 + * Tests if this input stream supports the <code>mark</code> and
42.359 + * <code>reset</code> methods. Whether or not <code>mark</code> and
42.360 + * <code>reset</code> are supported is an invariant property of a
42.361 + * particular input stream instance. The <code>markSupported</code> method
42.362 + * of <code>InputStream</code> returns <code>false</code>.
42.363 + *
42.364 + * @return <code>true</code> if this stream instance supports the mark
42.365 + * and reset methods; <code>false</code> otherwise.
42.366 + * @see java.io.InputStream#mark(int)
42.367 + * @see java.io.InputStream#reset()
42.368 + */
42.369 + public boolean markSupported() {
42.370 + return false;
42.371 + }
42.372 +
42.373 +}
43.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
43.2 +++ b/emul/src/main/java/java/io/PushbackInputStream.java Wed Jan 23 20:16:48 2013 +0100
43.3 @@ -0,0 +1,388 @@
43.4 +/*
43.5 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
43.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
43.7 + *
43.8 + * This code is free software; you can redistribute it and/or modify it
43.9 + * under the terms of the GNU General Public License version 2 only, as
43.10 + * published by the Free Software Foundation. Oracle designates this
43.11 + * particular file as subject to the "Classpath" exception as provided
43.12 + * by Oracle in the LICENSE file that accompanied this code.
43.13 + *
43.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
43.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
43.17 + * version 2 for more details (a copy is included in the LICENSE file that
43.18 + * accompanied this code).
43.19 + *
43.20 + * You should have received a copy of the GNU General Public License version
43.21 + * 2 along with this work; if not, write to the Free Software Foundation,
43.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
43.23 + *
43.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
43.25 + * or visit www.oracle.com if you need additional information or have any
43.26 + * questions.
43.27 + */
43.28 +
43.29 +package java.io;
43.30 +
43.31 +/**
43.32 + * A <code>PushbackInputStream</code> adds
43.33 + * functionality to another input stream, namely
43.34 + * the ability to "push back" or "unread"
43.35 + * one byte. This is useful in situations where
43.36 + * it is convenient for a fragment of code
43.37 + * to read an indefinite number of data bytes
43.38 + * that are delimited by a particular byte
43.39 + * value; after reading the terminating byte,
43.40 + * the code fragment can "unread" it, so that
43.41 + * the next read operation on the input stream
43.42 + * will reread the byte that was pushed back.
43.43 + * For example, bytes representing the characters
43.44 + * constituting an identifier might be terminated
43.45 + * by a byte representing an operator character;
43.46 + * a method whose job is to read just an identifier
43.47 + * can read until it sees the operator and
43.48 + * then push the operator back to be re-read.
43.49 + *
43.50 + * @author David Connelly
43.51 + * @author Jonathan Payne
43.52 + * @since JDK1.0
43.53 + */
43.54 +public
43.55 +class PushbackInputStream extends FilterInputStream {
43.56 + /**
43.57 + * The pushback buffer.
43.58 + * @since JDK1.1
43.59 + */
43.60 + protected byte[] buf;
43.61 +
43.62 + /**
43.63 + * The position within the pushback buffer from which the next byte will
43.64 + * be read. When the buffer is empty, <code>pos</code> is equal to
43.65 + * <code>buf.length</code>; when the buffer is full, <code>pos</code> is
43.66 + * equal to zero.
43.67 + *
43.68 + * @since JDK1.1
43.69 + */
43.70 + protected int pos;
43.71 +
43.72 + /**
43.73 + * Check to make sure that this stream has not been closed
43.74 + */
43.75 + private void ensureOpen() throws IOException {
43.76 + if (in == null)
43.77 + throw new IOException("Stream closed");
43.78 + }
43.79 +
43.80 + /**
43.81 + * Creates a <code>PushbackInputStream</code>
43.82 + * with a pushback buffer of the specified <code>size</code>,
43.83 + * and saves its argument, the input stream
43.84 + * <code>in</code>, for later use. Initially,
43.85 + * there is no pushed-back byte (the field
43.86 + * <code>pushBack</code> is initialized to
43.87 + * <code>-1</code>).
43.88 + *
43.89 + * @param in the input stream from which bytes will be read.
43.90 + * @param size the size of the pushback buffer.
43.91 + * @exception IllegalArgumentException if size is <= 0
43.92 + * @since JDK1.1
43.93 + */
43.94 + public PushbackInputStream(InputStream in, int size) {
43.95 + super(in);
43.96 + if (size <= 0) {
43.97 + throw new IllegalArgumentException("size <= 0");
43.98 + }
43.99 + this.buf = new byte[size];
43.100 + this.pos = size;
43.101 + }
43.102 +
43.103 + /**
43.104 + * Creates a <code>PushbackInputStream</code>
43.105 + * and saves its argument, the input stream
43.106 + * <code>in</code>, for later use. Initially,
43.107 + * there is no pushed-back byte (the field
43.108 + * <code>pushBack</code> is initialized to
43.109 + * <code>-1</code>).
43.110 + *
43.111 + * @param in the input stream from which bytes will be read.
43.112 + */
43.113 + public PushbackInputStream(InputStream in) {
43.114 + this(in, 1);
43.115 + }
43.116 +
43.117 + /**
43.118 + * Reads the next byte of data from this input stream. The value
43.119 + * byte is returned as an <code>int</code> in the range
43.120 + * <code>0</code> to <code>255</code>. If no byte is available
43.121 + * because the end of the stream has been reached, the value
43.122 + * <code>-1</code> is returned. This method blocks until input data
43.123 + * is available, the end of the stream is detected, or an exception
43.124 + * is thrown.
43.125 + *
43.126 + * <p> This method returns the most recently pushed-back byte, if there is
43.127 + * one, and otherwise calls the <code>read</code> method of its underlying
43.128 + * input stream and returns whatever value that method returns.
43.129 + *
43.130 + * @return the next byte of data, or <code>-1</code> if the end of the
43.131 + * stream has been reached.
43.132 + * @exception IOException if this input stream has been closed by
43.133 + * invoking its {@link #close()} method,
43.134 + * or an I/O error occurs.
43.135 + * @see java.io.InputStream#read()
43.136 + */
43.137 + public int read() throws IOException {
43.138 + ensureOpen();
43.139 + if (pos < buf.length) {
43.140 + return buf[pos++] & 0xff;
43.141 + }
43.142 + return super.read();
43.143 + }
43.144 +
43.145 + /**
43.146 + * Reads up to <code>len</code> bytes of data from this input stream into
43.147 + * an array of bytes. This method first reads any pushed-back bytes; after
43.148 + * that, if fewer than <code>len</code> bytes have been read then it
43.149 + * reads from the underlying input stream. If <code>len</code> is not zero, the method
43.150 + * blocks until at least 1 byte of input is available; otherwise, no
43.151 + * bytes are read and <code>0</code> is returned.
43.152 + *
43.153 + * @param b the buffer into which the data is read.
43.154 + * @param off the start offset in the destination array <code>b</code>
43.155 + * @param len the maximum number of bytes read.
43.156 + * @return the total number of bytes read into the buffer, or
43.157 + * <code>-1</code> if there is no more data because the end of
43.158 + * the stream has been reached.
43.159 + * @exception NullPointerException If <code>b</code> is <code>null</code>.
43.160 + * @exception IndexOutOfBoundsException If <code>off</code> is negative,
43.161 + * <code>len</code> is negative, or <code>len</code> is greater than
43.162 + * <code>b.length - off</code>
43.163 + * @exception IOException if this input stream has been closed by
43.164 + * invoking its {@link #close()} method,
43.165 + * or an I/O error occurs.
43.166 + * @see java.io.InputStream#read(byte[], int, int)
43.167 + */
43.168 + public int read(byte[] b, int off, int len) throws IOException {
43.169 + ensureOpen();
43.170 + if (b == null) {
43.171 + throw new NullPointerException();
43.172 + } else if (off < 0 || len < 0 || len > b.length - off) {
43.173 + throw new IndexOutOfBoundsException();
43.174 + } else if (len == 0) {
43.175 + return 0;
43.176 + }
43.177 +
43.178 + int avail = buf.length - pos;
43.179 + if (avail > 0) {
43.180 + if (len < avail) {
43.181 + avail = len;
43.182 + }
43.183 + arraycopy(buf, pos, b, off, avail);
43.184 + pos += avail;
43.185 + off += avail;
43.186 + len -= avail;
43.187 + }
43.188 + if (len > 0) {
43.189 + len = super.read(b, off, len);
43.190 + if (len == -1) {
43.191 + return avail == 0 ? -1 : avail;
43.192 + }
43.193 + return avail + len;
43.194 + }
43.195 + return avail;
43.196 + }
43.197 +
43.198 + /**
43.199 + * Pushes back a byte by copying it to the front of the pushback buffer.
43.200 + * After this method returns, the next byte to be read will have the value
43.201 + * <code>(byte)b</code>.
43.202 + *
43.203 + * @param b the <code>int</code> value whose low-order
43.204 + * byte is to be pushed back.
43.205 + * @exception IOException If there is not enough room in the pushback
43.206 + * buffer for the byte, or this input stream has been closed by
43.207 + * invoking its {@link #close()} method.
43.208 + */
43.209 + public void unread(int b) throws IOException {
43.210 + ensureOpen();
43.211 + if (pos == 0) {
43.212 + throw new IOException("Push back buffer is full");
43.213 + }
43.214 + buf[--pos] = (byte)b;
43.215 + }
43.216 +
43.217 + /**
43.218 + * Pushes back a portion of an array of bytes by copying it to the front
43.219 + * of the pushback buffer. After this method returns, the next byte to be
43.220 + * read will have the value <code>b[off]</code>, the byte after that will
43.221 + * have the value <code>b[off+1]</code>, and so forth.
43.222 + *
43.223 + * @param b the byte array to push back.
43.224 + * @param off the start offset of the data.
43.225 + * @param len the number of bytes to push back.
43.226 + * @exception IOException If there is not enough room in the pushback
43.227 + * buffer for the specified number of bytes,
43.228 + * or this input stream has been closed by
43.229 + * invoking its {@link #close()} method.
43.230 + * @since JDK1.1
43.231 + */
43.232 + public void unread(byte[] b, int off, int len) throws IOException {
43.233 + ensureOpen();
43.234 + if (len > pos) {
43.235 + throw new IOException("Push back buffer is full");
43.236 + }
43.237 + pos -= len;
43.238 + arraycopy(b, off, buf, pos, len);
43.239 + }
43.240 +
43.241 + /**
43.242 + * Pushes back an array of bytes by copying it to the front of the
43.243 + * pushback buffer. After this method returns, the next byte to be read
43.244 + * will have the value <code>b[0]</code>, the byte after that will have the
43.245 + * value <code>b[1]</code>, and so forth.
43.246 + *
43.247 + * @param b the byte array to push back
43.248 + * @exception IOException If there is not enough room in the pushback
43.249 + * buffer for the specified number of bytes,
43.250 + * or this input stream has been closed by
43.251 + * invoking its {@link #close()} method.
43.252 + * @since JDK1.1
43.253 + */
43.254 + public void unread(byte[] b) throws IOException {
43.255 + unread(b, 0, b.length);
43.256 + }
43.257 +
43.258 + /**
43.259 + * Returns an estimate of the number of bytes that can be read (or
43.260 + * skipped over) from this input stream without blocking by the next
43.261 + * invocation of a method for this input stream. The next invocation might be
43.262 + * the same thread or another thread. A single read or skip of this
43.263 + * many bytes will not block, but may read or skip fewer bytes.
43.264 + *
43.265 + * <p> The method returns the sum of the number of bytes that have been
43.266 + * pushed back and the value returned by {@link
43.267 + * java.io.FilterInputStream#available available}.
43.268 + *
43.269 + * @return the number of bytes that can be read (or skipped over) from
43.270 + * the input stream without blocking.
43.271 + * @exception IOException if this input stream has been closed by
43.272 + * invoking its {@link #close()} method,
43.273 + * or an I/O error occurs.
43.274 + * @see java.io.FilterInputStream#in
43.275 + * @see java.io.InputStream#available()
43.276 + */
43.277 + public int available() throws IOException {
43.278 + ensureOpen();
43.279 + int n = buf.length - pos;
43.280 + int avail = super.available();
43.281 + return n > (Integer.MAX_VALUE - avail)
43.282 + ? Integer.MAX_VALUE
43.283 + : n + avail;
43.284 + }
43.285 +
43.286 + /**
43.287 + * Skips over and discards <code>n</code> bytes of data from this
43.288 + * input stream. The <code>skip</code> method may, for a variety of
43.289 + * reasons, end up skipping over some smaller number of bytes,
43.290 + * possibly zero. If <code>n</code> is negative, no bytes are skipped.
43.291 + *
43.292 + * <p> The <code>skip</code> method of <code>PushbackInputStream</code>
43.293 + * first skips over the bytes in the pushback buffer, if any. It then
43.294 + * calls the <code>skip</code> method of the underlying input stream if
43.295 + * more bytes need to be skipped. The actual number of bytes skipped
43.296 + * is returned.
43.297 + *
43.298 + * @param n {@inheritDoc}
43.299 + * @return {@inheritDoc}
43.300 + * @exception IOException if the stream does not support seek,
43.301 + * or the stream has been closed by
43.302 + * invoking its {@link #close()} method,
43.303 + * or an I/O error occurs.
43.304 + * @see java.io.FilterInputStream#in
43.305 + * @see java.io.InputStream#skip(long n)
43.306 + * @since 1.2
43.307 + */
43.308 + public long skip(long n) throws IOException {
43.309 + ensureOpen();
43.310 + if (n <= 0) {
43.311 + return 0;
43.312 + }
43.313 +
43.314 + long pskip = buf.length - pos;
43.315 + if (pskip > 0) {
43.316 + if (n < pskip) {
43.317 + pskip = n;
43.318 + }
43.319 + pos += pskip;
43.320 + n -= pskip;
43.321 + }
43.322 + if (n > 0) {
43.323 + pskip += super.skip(n);
43.324 + }
43.325 + return pskip;
43.326 + }
43.327 +
43.328 + /**
43.329 + * Tests if this input stream supports the <code>mark</code> and
43.330 + * <code>reset</code> methods, which it does not.
43.331 + *
43.332 + * @return <code>false</code>, since this class does not support the
43.333 + * <code>mark</code> and <code>reset</code> methods.
43.334 + * @see java.io.InputStream#mark(int)
43.335 + * @see java.io.InputStream#reset()
43.336 + */
43.337 + public boolean markSupported() {
43.338 + return false;
43.339 + }
43.340 +
43.341 + /**
43.342 + * Marks the current position in this input stream.
43.343 + *
43.344 + * <p> The <code>mark</code> method of <code>PushbackInputStream</code>
43.345 + * does nothing.
43.346 + *
43.347 + * @param readlimit the maximum limit of bytes that can be read before
43.348 + * the mark position becomes invalid.
43.349 + * @see java.io.InputStream#reset()
43.350 + */
43.351 + public synchronized void mark(int readlimit) {
43.352 + }
43.353 +
43.354 + /**
43.355 + * Repositions this stream to the position at the time the
43.356 + * <code>mark</code> method was last called on this input stream.
43.357 + *
43.358 + * <p> The method <code>reset</code> for class
43.359 + * <code>PushbackInputStream</code> does nothing except throw an
43.360 + * <code>IOException</code>.
43.361 + *
43.362 + * @exception IOException if this method is invoked.
43.363 + * @see java.io.InputStream#mark(int)
43.364 + * @see java.io.IOException
43.365 + */
43.366 + public synchronized void reset() throws IOException {
43.367 + throw new IOException("mark/reset not supported");
43.368 + }
43.369 +
43.370 + /**
43.371 + * Closes this input stream and releases any system resources
43.372 + * associated with the stream.
43.373 + * Once the stream has been closed, further read(), unread(),
43.374 + * available(), reset(), or skip() invocations will throw an IOException.
43.375 + * Closing a previously closed stream has no effect.
43.376 + *
43.377 + * @exception IOException if an I/O error occurs.
43.378 + */
43.379 + public synchronized void close() throws IOException {
43.380 + if (in == null)
43.381 + return;
43.382 + in.close();
43.383 + in = null;
43.384 + buf = null;
43.385 + }
43.386 + static void arraycopy(byte[] value, int srcBegin, byte[] dst, int dstBegin, int count) {
43.387 + while (count-- > 0) {
43.388 + dst[dstBegin++] = value[srcBegin++];
43.389 + }
43.390 + }
43.391 +}
44.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
44.2 +++ b/emul/src/main/java/java/io/UTFDataFormatException.java Wed Jan 23 20:16:48 2013 +0100
44.3 @@ -0,0 +1,69 @@
44.4 +/*
44.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
44.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44.7 + *
44.8 + * This code is free software; you can redistribute it and/or modify it
44.9 + * under the terms of the GNU General Public License version 2 only, as
44.10 + * published by the Free Software Foundation. Oracle designates this
44.11 + * particular file as subject to the "Classpath" exception as provided
44.12 + * by Oracle in the LICENSE file that accompanied this code.
44.13 + *
44.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
44.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
44.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
44.17 + * version 2 for more details (a copy is included in the LICENSE file that
44.18 + * accompanied this code).
44.19 + *
44.20 + * You should have received a copy of the GNU General Public License version
44.21 + * 2 along with this work; if not, write to the Free Software Foundation,
44.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
44.23 + *
44.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
44.25 + * or visit www.oracle.com if you need additional information or have any
44.26 + * questions.
44.27 + */
44.28 +
44.29 +package java.io;
44.30 +
44.31 +/**
44.32 + * Signals that a malformed string in
44.33 + * <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
44.34 + * format has been read in a data
44.35 + * input stream or by any class that implements the data input
44.36 + * interface.
44.37 + * See the
44.38 + * <a href="DataInput.html#modified-utf-8"><code>DataInput</code></a>
44.39 + * class description for the format in
44.40 + * which modified UTF-8 strings are read and written.
44.41 + *
44.42 + * @author Frank Yellin
44.43 + * @see java.io.DataInput
44.44 + * @see java.io.DataInputStream#readUTF(java.io.DataInput)
44.45 + * @see java.io.IOException
44.46 + * @since JDK1.0
44.47 + */
44.48 +public
44.49 +class UTFDataFormatException extends IOException {
44.50 + private static final long serialVersionUID = 420743449228280612L;
44.51 +
44.52 + /**
44.53 + * Constructs a <code>UTFDataFormatException</code> with
44.54 + * <code>null</code> as its error detail message.
44.55 + */
44.56 + public UTFDataFormatException() {
44.57 + super();
44.58 + }
44.59 +
44.60 + /**
44.61 + * Constructs a <code>UTFDataFormatException</code> with the
44.62 + * specified detail message. The string <code>s</code> can be
44.63 + * retrieved later by the
44.64 + * <code>{@link java.lang.Throwable#getMessage}</code>
44.65 + * method of class <code>java.lang.Throwable</code>.
44.66 + *
44.67 + * @param s the detail message.
44.68 + */
44.69 + public UTFDataFormatException(String s) {
44.70 + super(s);
44.71 + }
44.72 +}
45.1 --- a/emul/src/main/java/java/lang/AbstractStringBuilder.java Thu Oct 11 06:15:22 2012 -0700
45.2 +++ b/emul/src/main/java/java/lang/AbstractStringBuilder.java Wed Jan 23 20:16:48 2013 +0100
45.3 @@ -25,8 +25,6 @@
45.4
45.5 package java.lang;
45.6
45.7 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
45.8 -
45.9 /**
45.10 * A mutable sequence of characters.
45.11 * <p>
45.12 @@ -126,7 +124,7 @@
45.13 throw new OutOfMemoryError();
45.14 newCapacity = Integer.MAX_VALUE;
45.15 }
45.16 - value = String.copyOf(value, newCapacity);
45.17 + value = copyOf(value, newCapacity);
45.18 }
45.19
45.20 /**
45.21 @@ -138,7 +136,7 @@
45.22 */
45.23 public void trimToSize() {
45.24 if (count < value.length) {
45.25 - value = String.copyOf(value, count);
45.26 + value = copyOf(value, count);
45.27 }
45.28 }
45.29
45.30 @@ -352,7 +350,7 @@
45.31 throw new StringIndexOutOfBoundsException(srcEnd);
45.32 if (srcBegin > srcEnd)
45.33 throw new StringIndexOutOfBoundsException("srcBegin > srcEnd");
45.34 - String.arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
45.35 + arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
45.36 }
45.37
45.38 /**
45.39 @@ -502,7 +500,7 @@
45.40 public AbstractStringBuilder append(char[] str) {
45.41 int len = str.length;
45.42 ensureCapacityInternal(count + len);
45.43 - String.arraycopy(str, 0, value, count, len);
45.44 + arraycopy(str, 0, value, count, len);
45.45 count += len;
45.46 return this;
45.47 }
45.48 @@ -532,7 +530,7 @@
45.49 public AbstractStringBuilder append(char str[], int offset, int len) {
45.50 if (len > 0) // let arraycopy report AIOOBE for len < 0
45.51 ensureCapacityInternal(count + len);
45.52 - String.arraycopy(str, offset, value, count, len);
45.53 + arraycopy(str, offset, value, count, len);
45.54 count += len;
45.55 return this;
45.56 }
45.57 @@ -600,22 +598,8 @@
45.58 * @param i an {@code int}.
45.59 * @return a reference to this object.
45.60 */
45.61 - @JavaScriptBody(
45.62 - args={ "self", "i" },
45.63 - body="return java_lang_AbstractStringBuilder_appendLjava_lang_AbstractStringBuilderLjava_lang_String(self,i.toString());"
45.64 - )
45.65 public AbstractStringBuilder append(int i) {
45.66 - if (i == Integer.MIN_VALUE) {
45.67 - append("-2147483648");
45.68 - return this;
45.69 - }
45.70 - int appendedLength = (i < 0) ? Integer.stringSize(-i) + 1
45.71 - : Integer.stringSize(i);
45.72 - int spaceNeeded = count + appendedLength;
45.73 - ensureCapacityInternal(spaceNeeded);
45.74 - Integer.getChars(i, spaceNeeded, value);
45.75 - count = spaceNeeded;
45.76 - return this;
45.77 + return append(Integer.toString(i));
45.78 }
45.79
45.80 /**
45.81 @@ -657,7 +641,7 @@
45.82 * @return a reference to this object.
45.83 */
45.84 public AbstractStringBuilder append(float f) {
45.85 - throw new UnsupportedOperationException();
45.86 + return append(Float.toString(f));
45.87 }
45.88
45.89 /**
45.90 @@ -673,7 +657,7 @@
45.91 * @return a reference to this object.
45.92 */
45.93 public AbstractStringBuilder append(double d) {
45.94 - throw new UnsupportedOperationException();
45.95 + return append(Double.toString(d));
45.96 }
45.97
45.98 /**
45.99 @@ -699,7 +683,7 @@
45.100 throw new StringIndexOutOfBoundsException();
45.101 int len = end - start;
45.102 if (len > 0) {
45.103 - String.arraycopy(value, start+len, value, start, count-end);
45.104 + arraycopy(value, start+len, value, start, count-end);
45.105 count -= len;
45.106 }
45.107 return this;
45.108 @@ -761,7 +745,7 @@
45.109 public AbstractStringBuilder deleteCharAt(int index) {
45.110 if ((index < 0) || (index >= count))
45.111 throw new StringIndexOutOfBoundsException(index);
45.112 - String.arraycopy(value, index+1, value, index, count-index-1);
45.113 + arraycopy(value, index+1, value, index, count-index-1);
45.114 count--;
45.115 return this;
45.116 }
45.117 @@ -799,7 +783,7 @@
45.118 int newCount = count + len - (end - start);
45.119 ensureCapacityInternal(newCount);
45.120
45.121 - String.arraycopy(value, end, value, start + len, count - end);
45.122 + arraycopy(value, end, value, start + len, count - end);
45.123 str.getChars(value, start);
45.124 count = newCount;
45.125 return this;
45.126 @@ -905,8 +889,8 @@
45.127 "offset " + offset + ", len " + len + ", str.length "
45.128 + str.length);
45.129 ensureCapacityInternal(count + len);
45.130 - String.arraycopy(value, index, value, index + len, count - index);
45.131 - String.arraycopy(str, offset, value, index, len);
45.132 + arraycopy(value, index, value, index + len, count - index);
45.133 + arraycopy(str, offset, value, index, len);
45.134 count += len;
45.135 return this;
45.136 }
45.137 @@ -972,7 +956,7 @@
45.138 str = "null";
45.139 int len = str.length();
45.140 ensureCapacityInternal(count + len);
45.141 - String.arraycopy(value, offset, value, offset + len, count - offset);
45.142 + arraycopy(value, offset, value, offset + len, count - offset);
45.143 str.getChars(value, offset);
45.144 count += len;
45.145 return this;
45.146 @@ -1007,8 +991,8 @@
45.147 throw new StringIndexOutOfBoundsException(offset);
45.148 int len = str.length;
45.149 ensureCapacityInternal(count + len);
45.150 - String.arraycopy(value, offset, value, offset + len, count - offset);
45.151 - String.arraycopy(str, 0, value, offset, len);
45.152 + arraycopy(value, offset, value, offset + len, count - offset);
45.153 + arraycopy(str, 0, value, offset, len);
45.154 count += len;
45.155 return this;
45.156 }
45.157 @@ -1098,7 +1082,7 @@
45.158 + s.length());
45.159 int len = end - start;
45.160 ensureCapacityInternal(count + len);
45.161 - String.arraycopy(value, dstOffset, value, dstOffset + len,
45.162 + arraycopy(value, dstOffset, value, dstOffset + len,
45.163 count - dstOffset);
45.164 for (int i=start; i<end; i++)
45.165 value[dstOffset++] = s.charAt(i);
45.166 @@ -1150,7 +1134,7 @@
45.167 */
45.168 public AbstractStringBuilder insert(int offset, char c) {
45.169 ensureCapacityInternal(count + 1);
45.170 - String.arraycopy(value, offset, value, offset + 1, count - offset);
45.171 + arraycopy(value, offset, value, offset + 1, count - offset);
45.172 value[offset] = c;
45.173 count += 1;
45.174 return this;
45.175 @@ -1287,8 +1271,7 @@
45.176 * <code>null</code>.
45.177 */
45.178 public int indexOf(String str, int fromIndex) {
45.179 - return String.indexOf(value, 0, count,
45.180 - str.toCharArray(), 0, str.length(), fromIndex);
45.181 + return toString().indexOf(str, fromIndex);
45.182 }
45.183
45.184 /**
45.185 @@ -1405,4 +1388,37 @@
45.186 return value;
45.187 }
45.188
45.189 + static char[] copyOfRange(char[] original, int from, int to) {
45.190 + int newLength = to - from;
45.191 + if (newLength < 0) {
45.192 + throw new IllegalArgumentException(from + " > " + to);
45.193 + }
45.194 + char[] copy = new char[newLength];
45.195 + arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength));
45.196 + return copy;
45.197 + }
45.198 +
45.199 + static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) {
45.200 + if (srcBegin < dstBegin) {
45.201 + while (count-- > 0) {
45.202 + dst[dstBegin + count] = value[srcBegin + count];
45.203 + }
45.204 + } else {
45.205 + while (count-- > 0) {
45.206 + dst[dstBegin++] = value[srcBegin++];
45.207 + }
45.208 + }
45.209 + }
45.210 +
45.211 + // access system property
45.212 + static String getProperty(String nm) {
45.213 + return null;
45.214 + }
45.215 +
45.216 + static char[] copyOf(char[] original, int newLength) {
45.217 + char[] copy = new char[newLength];
45.218 + arraycopy(original, 0, copy, 0, Math.min(original.length, newLength));
45.219 + return copy;
45.220 + }
45.221 +
45.222 }
46.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
46.2 +++ b/emul/src/main/java/java/lang/AutoCloseable.java Wed Jan 23 20:16:48 2013 +0100
46.3 @@ -0,0 +1,72 @@
46.4 +/*
46.5 + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
46.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
46.7 + *
46.8 + * This code is free software; you can redistribute it and/or modify it
46.9 + * under the terms of the GNU General Public License version 2 only, as
46.10 + * published by the Free Software Foundation. Oracle designates this
46.11 + * particular file as subject to the "Classpath" exception as provided
46.12 + * by Oracle in the LICENSE file that accompanied this code.
46.13 + *
46.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
46.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
46.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
46.17 + * version 2 for more details (a copy is included in the LICENSE file that
46.18 + * accompanied this code).
46.19 + *
46.20 + * You should have received a copy of the GNU General Public License version
46.21 + * 2 along with this work; if not, write to the Free Software Foundation,
46.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
46.23 + *
46.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
46.25 + * or visit www.oracle.com if you need additional information or have any
46.26 + * questions.
46.27 + */
46.28 +
46.29 +package java.lang;
46.30 +
46.31 +/**
46.32 + * A resource that must be closed when it is no longer needed.
46.33 + *
46.34 + * @author Josh Bloch
46.35 + * @since 1.7
46.36 + */
46.37 +public interface AutoCloseable {
46.38 + /**
46.39 + * Closes this resource, relinquishing any underlying resources.
46.40 + * This method is invoked automatically on objects managed by the
46.41 + * {@code try}-with-resources statement.
46.42 + *
46.43 + * <p>While this interface method is declared to throw {@code
46.44 + * Exception}, implementers are <em>strongly</em> encouraged to
46.45 + * declare concrete implementations of the {@code close} method to
46.46 + * throw more specific exceptions, or to throw no exception at all
46.47 + * if the close operation cannot fail.
46.48 + *
46.49 + * <p><em>Implementers of this interface are also strongly advised
46.50 + * to not have the {@code close} method throw {@link
46.51 + * InterruptedException}.</em>
46.52 + *
46.53 + * This exception interacts with a thread's interrupted status,
46.54 + * and runtime misbehavior is likely to occur if an {@code
46.55 + * InterruptedException} is {@linkplain Throwable#addSuppressed
46.56 + * suppressed}.
46.57 + *
46.58 + * More generally, if it would cause problems for an
46.59 + * exception to be suppressed, the {@code AutoCloseable.close}
46.60 + * method should not throw it.
46.61 + *
46.62 + * <p>Note that unlike the {@link java.io.Closeable#close close}
46.63 + * method of {@link java.io.Closeable}, this {@code close} method
46.64 + * is <em>not</em> required to be idempotent. In other words,
46.65 + * calling this {@code close} method more than once may have some
46.66 + * visible side effect, unlike {@code Closeable.close} which is
46.67 + * required to have no effect if called more than once.
46.68 + *
46.69 + * However, implementers of this interface are strongly encouraged
46.70 + * to make their {@code close} methods idempotent.
46.71 + *
46.72 + * @throws Exception if this resource cannot be closed
46.73 + */
46.74 + void close() throws Exception;
46.75 +}
47.1 --- a/emul/src/main/java/java/lang/Boolean.java Thu Oct 11 06:15:22 2012 -0700
47.2 +++ b/emul/src/main/java/java/lang/Boolean.java Wed Jan 23 20:16:48 2013 +0100
47.3 @@ -235,7 +235,7 @@
47.4 public static boolean getBoolean(String name) {
47.5 boolean result = false;
47.6 try {
47.7 - result = toBoolean(String.getProperty(name));
47.8 + result = toBoolean(AbstractStringBuilder.getProperty(name));
47.9 } catch (IllegalArgumentException e) {
47.10 } catch (NullPointerException e) {
47.11 }
48.1 --- a/emul/src/main/java/java/lang/Character.java Thu Oct 11 06:15:22 2012 -0700
48.2 +++ b/emul/src/main/java/java/lang/Character.java Wed Jan 23 20:16:48 2013 +0100
48.3 @@ -25,6 +25,8 @@
48.4
48.5 package java.lang;
48.6
48.7 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
48.8 +
48.9 /**
48.10 * The {@code Character} class wraps a value of the primitive
48.11 * type {@code char} in an object. An object of type
48.12 @@ -1525,7 +1527,7 @@
48.13 * @see Character#getType(char)
48.14 */
48.15 public static boolean isLowerCase(char ch) {
48.16 - throw new UnsupportedOperationException();
48.17 + return ch == toLowerCase(ch);
48.18 }
48.19
48.20 /**
48.21 @@ -1560,7 +1562,7 @@
48.22 * @since 1.0
48.23 */
48.24 public static boolean isUpperCase(char ch) {
48.25 - throw new UnsupportedOperationException();
48.26 + return ch == toUpperCase(ch);
48.27 }
48.28
48.29 /**
48.30 @@ -1676,7 +1678,7 @@
48.31 * @see Character#getType(char)
48.32 */
48.33 public static boolean isDigit(char ch) {
48.34 - return isDigit((int)ch);
48.35 + return String.valueOf(ch).matches("\\d");
48.36 }
48.37
48.38 /**
48.39 @@ -1710,8 +1712,11 @@
48.40 * @since 1.5
48.41 */
48.42 public static boolean isDigit(int codePoint) {
48.43 - return getType(codePoint) == Character.DECIMAL_DIGIT_NUMBER;
48.44 + return fromCodeChars(codePoint).matches("\\d");
48.45 }
48.46 +
48.47 + @JavaScriptBody(args = "c", body = "return String.fromCharCode(c);")
48.48 + private native static String fromCodeChars(int codePoint);
48.49
48.50 /**
48.51 * Determines if a character is defined in Unicode.
48.52 @@ -1802,7 +1807,7 @@
48.53 * @see Character#isUpperCase(char)
48.54 */
48.55 public static boolean isLetter(char ch) {
48.56 - return isLetter((int)ch);
48.57 + return String.valueOf(ch).matches("\\w") && !isDigit(ch);
48.58 }
48.59
48.60 /**
48.61 @@ -1835,12 +1840,7 @@
48.62 * @since 1.5
48.63 */
48.64 public static boolean isLetter(int codePoint) {
48.65 - return ((((1 << Character.UPPERCASE_LETTER) |
48.66 - (1 << Character.LOWERCASE_LETTER) |
48.67 - (1 << Character.TITLECASE_LETTER) |
48.68 - (1 << Character.MODIFIER_LETTER) |
48.69 - (1 << Character.OTHER_LETTER)) >> getType(codePoint)) & 1)
48.70 - != 0;
48.71 + return fromCodeChars(codePoint).matches("\\w") && !isDigit(codePoint);
48.72 }
48.73
48.74 /**
48.75 @@ -1868,7 +1868,7 @@
48.76 * @since 1.0.2
48.77 */
48.78 public static boolean isLetterOrDigit(char ch) {
48.79 - return isLetterOrDigit((int)ch);
48.80 + return String.valueOf(ch).matches("\\w");
48.81 }
48.82
48.83 /**
48.84 @@ -1889,13 +1889,7 @@
48.85 * @since 1.5
48.86 */
48.87 public static boolean isLetterOrDigit(int codePoint) {
48.88 - return ((((1 << Character.UPPERCASE_LETTER) |
48.89 - (1 << Character.LOWERCASE_LETTER) |
48.90 - (1 << Character.TITLECASE_LETTER) |
48.91 - (1 << Character.MODIFIER_LETTER) |
48.92 - (1 << Character.OTHER_LETTER) |
48.93 - (1 << Character.DECIMAL_DIGIT_NUMBER)) >> getType(codePoint)) & 1)
48.94 - != 0;
48.95 + return fromCodeChars(codePoint).matches("\\w");
48.96 }
48.97
48.98 static int getType(int x) {
48.99 @@ -1930,7 +1924,7 @@
48.100 * @see String#toLowerCase()
48.101 */
48.102 public static char toLowerCase(char ch) {
48.103 - throw new UnsupportedOperationException();
48.104 + return String.valueOf(ch).toLowerCase().charAt(0);
48.105 }
48.106
48.107 /**
48.108 @@ -1961,7 +1955,7 @@
48.109 * @see String#toUpperCase()
48.110 */
48.111 public static char toUpperCase(char ch) {
48.112 - throw new UnsupportedOperationException();
48.113 + return String.valueOf(ch).toUpperCase().charAt(0);
48.114 }
48.115
48.116 /**
49.1 --- a/emul/src/main/java/java/lang/Class.java Thu Oct 11 06:15:22 2012 -0700
49.2 +++ b/emul/src/main/java/java/lang/Class.java Wed Jan 23 20:16:48 2013 +0100
49.3 @@ -25,7 +25,15 @@
49.4
49.5 package java.lang;
49.6
49.7 +import java.io.ByteArrayInputStream;
49.8 +import org.apidesign.bck2brwsr.emul.AnnotationImpl;
49.9 +import java.io.InputStream;
49.10 import java.lang.annotation.Annotation;
49.11 +import java.lang.reflect.Field;
49.12 +import java.lang.reflect.Method;
49.13 +import java.lang.reflect.TypeVariable;
49.14 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
49.15 +import org.apidesign.bck2brwsr.emul.MethodImpl;
49.16
49.17 /**
49.18 * Instances of the class {@code Class} represent classes and
49.19 @@ -73,10 +81,10 @@
49.20 * @since JDK1.0
49.21 */
49.22 public final
49.23 - class Class<T> implements java.io.Serializable {
49.24 -// java.lang.reflect.GenericDeclaration,
49.25 -// java.lang.reflect.Type,
49.26 -// java.lang.reflect.AnnotatedElement {
49.27 + class Class<T> implements java.io.Serializable,
49.28 + java.lang.reflect.GenericDeclaration,
49.29 + java.lang.reflect.Type,
49.30 + java.lang.reflect.AnnotatedElement {
49.31 private static final int ANNOTATION= 0x00002000;
49.32 private static final int ENUM = 0x00004000;
49.33 private static final int SYNTHETIC = 0x00001000;
49.34 @@ -137,9 +145,31 @@
49.35 * @exception ClassNotFoundException if the class cannot be located
49.36 */
49.37 public static Class<?> forName(String className)
49.38 - throws ClassNotFoundException {
49.39 - throw new UnsupportedOperationException();
49.40 + throws ClassNotFoundException {
49.41 + if (className.startsWith("[")) {
49.42 + Class<?> arrType = defineArray(className);
49.43 + Class<?> c = arrType;
49.44 + while (c != null && c.isArray()) {
49.45 + c = c.getComponentType0(); // verify component type is sane
49.46 + }
49.47 + return arrType;
49.48 + }
49.49 + Class<?> c = loadCls(className, className.replace('.', '_'));
49.50 + if (c == null) {
49.51 + throw new ClassNotFoundException(className);
49.52 + }
49.53 + return c;
49.54 }
49.55 +
49.56 + @JavaScriptBody(args = {"n", "c" }, body =
49.57 + "if (vm[c]) return vm[c].$class;\n"
49.58 + + "if (vm.loadClass) {\n"
49.59 + + " vm.loadClass(n);\n"
49.60 + + " if (vm[c]) return vm[c].$class;\n"
49.61 + + "}\n"
49.62 + + "return null;"
49.63 + )
49.64 + private static native Class<?> loadCls(String n, String c);
49.65
49.66
49.67 /**
49.68 @@ -189,10 +219,32 @@
49.69 * </ul>
49.70 *
49.71 */
49.72 + @JavaScriptBody(args = { "self", "illegal" }, body =
49.73 + "\nvar c = self.cnstr;"
49.74 + + "\nif (c['cons__V']) {"
49.75 + + "\n if ((c.cons__V.access & 0x1) != 0) {"
49.76 + + "\n var inst = c();"
49.77 + + "\n c.cons__V.call(inst);"
49.78 + + "\n return inst;"
49.79 + + "\n }"
49.80 + + "\n return illegal;"
49.81 + + "\n}"
49.82 + + "\nreturn null;"
49.83 + )
49.84 + private static native Object newInstance0(Class<?> self, Object illegal);
49.85 +
49.86 public T newInstance()
49.87 throws InstantiationException, IllegalAccessException
49.88 {
49.89 - throw new UnsupportedOperationException("Should be somehow supported");
49.90 + Object illegal = new Object();
49.91 + Object inst = newInstance0(this, illegal);
49.92 + if (inst == null) {
49.93 + throw new InstantiationException(getName());
49.94 + }
49.95 + if (inst == illegal) {
49.96 + throw new IllegalAccessException();
49.97 + }
49.98 + return (T)inst;
49.99 }
49.100
49.101 /**
49.102 @@ -225,7 +277,15 @@
49.103 *
49.104 * @since JDK1.1
49.105 */
49.106 - public native boolean isInstance(Object obj);
49.107 + public boolean isInstance(Object obj) {
49.108 + String prop = "$instOf_" + getName().replace('.', '_');
49.109 + return hasProperty(obj, prop);
49.110 + }
49.111 +
49.112 + @JavaScriptBody(args = { "who", "prop" }, body =
49.113 + "if (who[prop]) return true; else return false;"
49.114 + )
49.115 + private static native boolean hasProperty(Object who, String prop);
49.116
49.117
49.118 /**
49.119 @@ -262,7 +322,12 @@
49.120 * @return {@code true} if this object represents an interface;
49.121 * {@code false} otherwise.
49.122 */
49.123 - public native boolean isInterface();
49.124 + public boolean isInterface() {
49.125 + return (getAccess() & 0x200) != 0;
49.126 + }
49.127 +
49.128 + @JavaScriptBody(args = {}, body = "return this.access;")
49.129 + private native int getAccess();
49.130
49.131
49.132 /**
49.133 @@ -272,7 +337,9 @@
49.134 * {@code false} otherwise.
49.135 * @since JDK1.1
49.136 */
49.137 - public native boolean isArray();
49.138 + public boolean isArray() {
49.139 + return hasProperty(this, "array"); // NOI18N
49.140 + }
49.141
49.142
49.143 /**
49.144 @@ -303,6 +370,10 @@
49.145 * @see java.lang.Void#TYPE
49.146 * @since JDK1.1
49.147 */
49.148 + @JavaScriptBody(args = {}, body =
49.149 + "if (this.primitive) return true;"
49.150 + + "else return false;"
49.151 + )
49.152 public native boolean isPrimitive();
49.153
49.154 /**
49.155 @@ -381,13 +452,32 @@
49.156 * represented by this object.
49.157 */
49.158 public String getName() {
49.159 - throw new UnsupportedOperationException();
49.160 -// String name = this.name;
49.161 -// if (name == null)
49.162 -// this.name = name = getName0();
49.163 -// return name;
49.164 + return jvmName().replace('/', '.');
49.165 }
49.166
49.167 + @JavaScriptBody(args = {}, body = "return this.jvmName;")
49.168 + private native String jvmName();
49.169 +
49.170 +
49.171 + /**
49.172 + * Returns an array of {@code TypeVariable} objects that represent the
49.173 + * type variables declared by the generic declaration represented by this
49.174 + * {@code GenericDeclaration} object, in declaration order. Returns an
49.175 + * array of length 0 if the underlying generic declaration declares no type
49.176 + * variables.
49.177 + *
49.178 + * @return an array of {@code TypeVariable} objects that represent
49.179 + * the type variables declared by this generic declaration
49.180 + * @throws java.lang.reflect.GenericSignatureFormatError if the generic
49.181 + * signature of this generic declaration does not conform to
49.182 + * the format specified in
49.183 + * <cite>The Java™ Virtual Machine Specification</cite>
49.184 + * @since 1.5
49.185 + */
49.186 + public TypeVariable<Class<T>>[] getTypeParameters() {
49.187 + throw new UnsupportedOperationException();
49.188 + }
49.189 +
49.190 /**
49.191 * Returns the {@code Class} representing the superclass of the entity
49.192 * (class, interface, primitive type or void) represented by this
49.193 @@ -399,6 +489,7 @@
49.194 *
49.195 * @return the superclass of the class represented by this object.
49.196 */
49.197 + @JavaScriptBody(args = {}, body = "return this.superclass;")
49.198 public native Class<? super T> getSuperclass();
49.199
49.200 /**
49.201 @@ -444,37 +535,290 @@
49.202 * @since 1.5
49.203 */
49.204 public String getSimpleName() {
49.205 - throw new UnsupportedOperationException();
49.206 -//// if (isArray())
49.207 -//// return getComponentType().getSimpleName()+"[]";
49.208 -////
49.209 -//// String simpleName = getSimpleBinaryName();
49.210 -//// if (simpleName == null) { // top level class
49.211 -//// simpleName = getName();
49.212 -//// return simpleName.substring(simpleName.lastIndexOf(".")+1); // strip the package name
49.213 -//// }
49.214 -//// // According to JLS3 "Binary Compatibility" (13.1) the binary
49.215 -//// // name of non-package classes (not top level) is the binary
49.216 -//// // name of the immediately enclosing class followed by a '$' followed by:
49.217 -//// // (for nested and inner classes): the simple name.
49.218 -//// // (for local classes): 1 or more digits followed by the simple name.
49.219 -//// // (for anonymous classes): 1 or more digits.
49.220 -////
49.221 -//// // Since getSimpleBinaryName() will strip the binary name of
49.222 -//// // the immediatly enclosing class, we are now looking at a
49.223 -//// // string that matches the regular expression "\$[0-9]*"
49.224 -//// // followed by a simple name (considering the simple of an
49.225 -//// // anonymous class to be the empty string).
49.226 -////
49.227 -//// // Remove leading "\$[0-9]*" from the name
49.228 -//// int length = simpleName.length();
49.229 -//// if (length < 1 || simpleName.charAt(0) != '$')
49.230 -//// throw new InternalError("Malformed class name");
49.231 -//// int index = 1;
49.232 -//// while (index < length && isAsciiDigit(simpleName.charAt(index)))
49.233 -//// index++;
49.234 -//// // Eventually, this is the empty string iff this is an anonymous class
49.235 -//// return simpleName.substring(index);
49.236 + if (isArray())
49.237 + return getComponentType().getSimpleName()+"[]";
49.238 +
49.239 + String simpleName = getSimpleBinaryName();
49.240 + if (simpleName == null) { // top level class
49.241 + simpleName = getName();
49.242 + return simpleName.substring(simpleName.lastIndexOf(".")+1); // strip the package name
49.243 + }
49.244 + // According to JLS3 "Binary Compatibility" (13.1) the binary
49.245 + // name of non-package classes (not top level) is the binary
49.246 + // name of the immediately enclosing class followed by a '$' followed by:
49.247 + // (for nested and inner classes): the simple name.
49.248 + // (for local classes): 1 or more digits followed by the simple name.
49.249 + // (for anonymous classes): 1 or more digits.
49.250 +
49.251 + // Since getSimpleBinaryName() will strip the binary name of
49.252 + // the immediatly enclosing class, we are now looking at a
49.253 + // string that matches the regular expression "\$[0-9]*"
49.254 + // followed by a simple name (considering the simple of an
49.255 + // anonymous class to be the empty string).
49.256 +
49.257 + // Remove leading "\$[0-9]*" from the name
49.258 + int length = simpleName.length();
49.259 + if (length < 1 || simpleName.charAt(0) != '$')
49.260 + throw new IllegalStateException("Malformed class name");
49.261 + int index = 1;
49.262 + while (index < length && isAsciiDigit(simpleName.charAt(index)))
49.263 + index++;
49.264 + // Eventually, this is the empty string iff this is an anonymous class
49.265 + return simpleName.substring(index);
49.266 + }
49.267 +
49.268 + /**
49.269 + * Returns the "simple binary name" of the underlying class, i.e.,
49.270 + * the binary name without the leading enclosing class name.
49.271 + * Returns {@code null} if the underlying class is a top level
49.272 + * class.
49.273 + */
49.274 + private String getSimpleBinaryName() {
49.275 + Class<?> enclosingClass = null; // XXX getEnclosingClass();
49.276 + if (enclosingClass == null) // top level class
49.277 + return null;
49.278 + // Otherwise, strip the enclosing class' name
49.279 + try {
49.280 + return getName().substring(enclosingClass.getName().length());
49.281 + } catch (IndexOutOfBoundsException ex) {
49.282 + throw new IllegalStateException("Malformed class name");
49.283 + }
49.284 + }
49.285 +
49.286 + /**
49.287 + * Returns an array containing {@code Field} objects reflecting all
49.288 + * the accessible public fields of the class or interface represented by
49.289 + * this {@code Class} object. The elements in the array returned are
49.290 + * not sorted and are not in any particular order. This method returns an
49.291 + * array of length 0 if the class or interface has no accessible public
49.292 + * fields, or if it represents an array class, a primitive type, or void.
49.293 + *
49.294 + * <p> Specifically, if this {@code Class} object represents a class,
49.295 + * this method returns the public fields of this class and of all its
49.296 + * superclasses. If this {@code Class} object represents an
49.297 + * interface, this method returns the fields of this interface and of all
49.298 + * its superinterfaces.
49.299 + *
49.300 + * <p> The implicit length field for array class is not reflected by this
49.301 + * method. User code should use the methods of class {@code Array} to
49.302 + * manipulate arrays.
49.303 + *
49.304 + * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
49.305 + *
49.306 + * @return the array of {@code Field} objects representing the
49.307 + * public fields
49.308 + * @exception SecurityException
49.309 + * If a security manager, <i>s</i>, is present and any of the
49.310 + * following conditions is met:
49.311 + *
49.312 + * <ul>
49.313 + *
49.314 + * <li> invocation of
49.315 + * {@link SecurityManager#checkMemberAccess
49.316 + * s.checkMemberAccess(this, Member.PUBLIC)} denies
49.317 + * access to the fields within this class
49.318 + *
49.319 + * <li> the caller's class loader is not the same as or an
49.320 + * ancestor of the class loader for the current class and
49.321 + * invocation of {@link SecurityManager#checkPackageAccess
49.322 + * s.checkPackageAccess()} denies access to the package
49.323 + * of this class
49.324 + *
49.325 + * </ul>
49.326 + *
49.327 + * @since JDK1.1
49.328 + */
49.329 + public Field[] getFields() throws SecurityException {
49.330 + throw new SecurityException();
49.331 + }
49.332 +
49.333 + /**
49.334 + * Returns an array containing {@code Method} objects reflecting all
49.335 + * the public <em>member</em> methods of the class or interface represented
49.336 + * by this {@code Class} object, including those declared by the class
49.337 + * or interface and those inherited from superclasses and
49.338 + * superinterfaces. Array classes return all the (public) member methods
49.339 + * inherited from the {@code Object} class. The elements in the array
49.340 + * returned are not sorted and are not in any particular order. This
49.341 + * method returns an array of length 0 if this {@code Class} object
49.342 + * represents a class or interface that has no public member methods, or if
49.343 + * this {@code Class} object represents a primitive type or void.
49.344 + *
49.345 + * <p> The class initialization method {@code <clinit>} is not
49.346 + * included in the returned array. If the class declares multiple public
49.347 + * member methods with the same parameter types, they are all included in
49.348 + * the returned array.
49.349 + *
49.350 + * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
49.351 + *
49.352 + * @return the array of {@code Method} objects representing the
49.353 + * public methods of this class
49.354 + * @exception SecurityException
49.355 + * If a security manager, <i>s</i>, is present and any of the
49.356 + * following conditions is met:
49.357 + *
49.358 + * <ul>
49.359 + *
49.360 + * <li> invocation of
49.361 + * {@link SecurityManager#checkMemberAccess
49.362 + * s.checkMemberAccess(this, Member.PUBLIC)} denies
49.363 + * access to the methods within this class
49.364 + *
49.365 + * <li> the caller's class loader is not the same as or an
49.366 + * ancestor of the class loader for the current class and
49.367 + * invocation of {@link SecurityManager#checkPackageAccess
49.368 + * s.checkPackageAccess()} denies access to the package
49.369 + * of this class
49.370 + *
49.371 + * </ul>
49.372 + *
49.373 + * @since JDK1.1
49.374 + */
49.375 + public Method[] getMethods() throws SecurityException {
49.376 + return MethodImpl.findMethods(this, 0x01);
49.377 + }
49.378 +
49.379 + /**
49.380 + * Returns a {@code Field} object that reflects the specified public
49.381 + * member field of the class or interface represented by this
49.382 + * {@code Class} object. The {@code name} parameter is a
49.383 + * {@code String} specifying the simple name of the desired field.
49.384 + *
49.385 + * <p> The field to be reflected is determined by the algorithm that
49.386 + * follows. Let C be the class represented by this object:
49.387 + * <OL>
49.388 + * <LI> If C declares a public field with the name specified, that is the
49.389 + * field to be reflected.</LI>
49.390 + * <LI> If no field was found in step 1 above, this algorithm is applied
49.391 + * recursively to each direct superinterface of C. The direct
49.392 + * superinterfaces are searched in the order they were declared.</LI>
49.393 + * <LI> If no field was found in steps 1 and 2 above, and C has a
49.394 + * superclass S, then this algorithm is invoked recursively upon S.
49.395 + * If C has no superclass, then a {@code NoSuchFieldException}
49.396 + * is thrown.</LI>
49.397 + * </OL>
49.398 + *
49.399 + * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
49.400 + *
49.401 + * @param name the field name
49.402 + * @return the {@code Field} object of this class specified by
49.403 + * {@code name}
49.404 + * @exception NoSuchFieldException if a field with the specified name is
49.405 + * not found.
49.406 + * @exception NullPointerException if {@code name} is {@code null}
49.407 + * @exception SecurityException
49.408 + * If a security manager, <i>s</i>, is present and any of the
49.409 + * following conditions is met:
49.410 + *
49.411 + * <ul>
49.412 + *
49.413 + * <li> invocation of
49.414 + * {@link SecurityManager#checkMemberAccess
49.415 + * s.checkMemberAccess(this, Member.PUBLIC)} denies
49.416 + * access to the field
49.417 + *
49.418 + * <li> the caller's class loader is not the same as or an
49.419 + * ancestor of the class loader for the current class and
49.420 + * invocation of {@link SecurityManager#checkPackageAccess
49.421 + * s.checkPackageAccess()} denies access to the package
49.422 + * of this class
49.423 + *
49.424 + * </ul>
49.425 + *
49.426 + * @since JDK1.1
49.427 + */
49.428 + public Field getField(String name)
49.429 + throws SecurityException {
49.430 + throw new SecurityException();
49.431 + }
49.432 +
49.433 +
49.434 + /**
49.435 + * Returns a {@code Method} object that reflects the specified public
49.436 + * member method of the class or interface represented by this
49.437 + * {@code Class} object. The {@code name} parameter is a
49.438 + * {@code String} specifying the simple name of the desired method. The
49.439 + * {@code parameterTypes} parameter is an array of {@code Class}
49.440 + * objects that identify the method's formal parameter types, in declared
49.441 + * order. If {@code parameterTypes} is {@code null}, it is
49.442 + * treated as if it were an empty array.
49.443 + *
49.444 + * <p> If the {@code name} is "{@code <init>};"or "{@code <clinit>}" a
49.445 + * {@code NoSuchMethodException} is raised. Otherwise, the method to
49.446 + * be reflected is determined by the algorithm that follows. Let C be the
49.447 + * class represented by this object:
49.448 + * <OL>
49.449 + * <LI> C is searched for any <I>matching methods</I>. If no matching
49.450 + * method is found, the algorithm of step 1 is invoked recursively on
49.451 + * the superclass of C.</LI>
49.452 + * <LI> If no method was found in step 1 above, the superinterfaces of C
49.453 + * are searched for a matching method. If any such method is found, it
49.454 + * is reflected.</LI>
49.455 + * </OL>
49.456 + *
49.457 + * To find a matching method in a class C: If C declares exactly one
49.458 + * public method with the specified name and exactly the same formal
49.459 + * parameter types, that is the method reflected. If more than one such
49.460 + * method is found in C, and one of these methods has a return type that is
49.461 + * more specific than any of the others, that method is reflected;
49.462 + * otherwise one of the methods is chosen arbitrarily.
49.463 + *
49.464 + * <p>Note that there may be more than one matching method in a
49.465 + * class because while the Java language forbids a class to
49.466 + * declare multiple methods with the same signature but different
49.467 + * return types, the Java virtual machine does not. This
49.468 + * increased flexibility in the virtual machine can be used to
49.469 + * implement various language features. For example, covariant
49.470 + * returns can be implemented with {@linkplain
49.471 + * java.lang.reflect.Method#isBridge bridge methods}; the bridge
49.472 + * method and the method being overridden would have the same
49.473 + * signature but different return types.
49.474 + *
49.475 + * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
49.476 + *
49.477 + * @param name the name of the method
49.478 + * @param parameterTypes the list of parameters
49.479 + * @return the {@code Method} object that matches the specified
49.480 + * {@code name} and {@code parameterTypes}
49.481 + * @exception NoSuchMethodException if a matching method is not found
49.482 + * or if the name is "<init>"or "<clinit>".
49.483 + * @exception NullPointerException if {@code name} is {@code null}
49.484 + * @exception SecurityException
49.485 + * If a security manager, <i>s</i>, is present and any of the
49.486 + * following conditions is met:
49.487 + *
49.488 + * <ul>
49.489 + *
49.490 + * <li> invocation of
49.491 + * {@link SecurityManager#checkMemberAccess
49.492 + * s.checkMemberAccess(this, Member.PUBLIC)} denies
49.493 + * access to the method
49.494 + *
49.495 + * <li> the caller's class loader is not the same as or an
49.496 + * ancestor of the class loader for the current class and
49.497 + * invocation of {@link SecurityManager#checkPackageAccess
49.498 + * s.checkPackageAccess()} denies access to the package
49.499 + * of this class
49.500 + *
49.501 + * </ul>
49.502 + *
49.503 + * @since JDK1.1
49.504 + */
49.505 + public Method getMethod(String name, Class<?>... parameterTypes)
49.506 + throws SecurityException, NoSuchMethodException {
49.507 + Method m = MethodImpl.findMethod(this, name, parameterTypes);
49.508 + if (m == null) {
49.509 + StringBuilder sb = new StringBuilder();
49.510 + sb.append(getName()).append('.').append(name).append('(');
49.511 + String sep = "";
49.512 + for (int i = 0; i < parameterTypes.length; i++) {
49.513 + sb.append(sep).append(parameterTypes[i].getName());
49.514 + sep = ", ";
49.515 + }
49.516 + sb.append(')');
49.517 + throw new NoSuchMethodException(sb.toString());
49.518 + }
49.519 + return m;
49.520 }
49.521
49.522 /**
49.523 @@ -496,25 +840,25 @@
49.524 * @since 1.5
49.525 */
49.526 public String getCanonicalName() {
49.527 - throw new UnsupportedOperationException();
49.528 -// if (isArray()) {
49.529 -// String canonicalName = getComponentType().getCanonicalName();
49.530 -// if (canonicalName != null)
49.531 -// return canonicalName + "[]";
49.532 -// else
49.533 -// return null;
49.534 -// }
49.535 + if (isArray()) {
49.536 + String canonicalName = getComponentType().getCanonicalName();
49.537 + if (canonicalName != null)
49.538 + return canonicalName + "[]";
49.539 + else
49.540 + return null;
49.541 + }
49.542 // if (isLocalOrAnonymousClass())
49.543 // return null;
49.544 // Class<?> enclosingClass = getEnclosingClass();
49.545 -// if (enclosingClass == null) { // top level class
49.546 -// return getName();
49.547 -// } else {
49.548 -// String enclosingName = enclosingClass.getCanonicalName();
49.549 -// if (enclosingName == null)
49.550 -// return null;
49.551 -// return enclosingName + "." + getSimpleName();
49.552 -// }
49.553 + Class<?> enclosingClass = null;
49.554 + if (enclosingClass == null) { // top level class
49.555 + return getName();
49.556 + } else {
49.557 + String enclosingName = enclosingClass.getCanonicalName();
49.558 + if (enclosingName == null)
49.559 + return null;
49.560 + return enclosingName + "." + getSimpleName();
49.561 + }
49.562 }
49.563
49.564 /**
49.565 @@ -552,15 +896,16 @@
49.566 * @throws NullPointerException If {@code name} is {@code null}
49.567 * @since JDK1.1
49.568 */
49.569 -// public InputStream getResourceAsStream(String name) {
49.570 -// name = resolveName(name);
49.571 -// ClassLoader cl = getClassLoader0();
49.572 -// if (cl==null) {
49.573 -// // A system class.
49.574 -// return ClassLoader.getSystemResourceAsStream(name);
49.575 -// }
49.576 -// return cl.getResourceAsStream(name);
49.577 -// }
49.578 + public InputStream getResourceAsStream(String name) {
49.579 + name = resolveName(name);
49.580 + byte[] arr = getResourceAsStream0(name);
49.581 + return arr == null ? null : new ByteArrayInputStream(arr);
49.582 + }
49.583 +
49.584 + @JavaScriptBody(args = "name", body =
49.585 + "return (vm.loadBytes) ? vm.loadBytes(name) : null;"
49.586 + )
49.587 + private static native byte[] getResourceAsStream0(String name);
49.588
49.589 /**
49.590 * Finds a resource with a given name. The rules for searching resources
49.591 @@ -596,19 +941,136 @@
49.592 * resource with this name is found
49.593 * @since JDK1.1
49.594 */
49.595 -// public java.net.URL getResource(String name) {
49.596 -// name = resolveName(name);
49.597 -// ClassLoader cl = getClassLoader0();
49.598 -// if (cl==null) {
49.599 -// // A system class.
49.600 -// return ClassLoader.getSystemResource(name);
49.601 -// }
49.602 -// return cl.getResource(name);
49.603 -// }
49.604 + public java.net.URL getResource(String name) {
49.605 + name = resolveName(name);
49.606 + ClassLoader cl = null;
49.607 + if (cl==null) {
49.608 + // A system class.
49.609 + return ClassLoader.getSystemResource(name);
49.610 + }
49.611 + return cl.getResource(name);
49.612 + }
49.613
49.614
49.615 + /**
49.616 + * Add a package name prefix if the name is not absolute Remove leading "/"
49.617 + * if name is absolute
49.618 + */
49.619 + private String resolveName(String name) {
49.620 + if (name == null) {
49.621 + return name;
49.622 + }
49.623 + if (!name.startsWith("/")) {
49.624 + Class<?> c = this;
49.625 + while (c.isArray()) {
49.626 + c = c.getComponentType();
49.627 + }
49.628 + String baseName = c.getName();
49.629 + int index = baseName.lastIndexOf('.');
49.630 + if (index != -1) {
49.631 + name = baseName.substring(0, index).replace('.', '/')
49.632 + +"/"+name;
49.633 + }
49.634 + } else {
49.635 + name = name.substring(1);
49.636 + }
49.637 + return name;
49.638 + }
49.639 +
49.640 + /**
49.641 + * Returns the class loader for the class. Some implementations may use
49.642 + * null to represent the bootstrap class loader. This method will return
49.643 + * null in such implementations if this class was loaded by the bootstrap
49.644 + * class loader.
49.645 + *
49.646 + * <p> If a security manager is present, and the caller's class loader is
49.647 + * not null and the caller's class loader is not the same as or an ancestor of
49.648 + * the class loader for the class whose class loader is requested, then
49.649 + * this method calls the security manager's {@code checkPermission}
49.650 + * method with a {@code RuntimePermission("getClassLoader")}
49.651 + * permission to ensure it's ok to access the class loader for the class.
49.652 + *
49.653 + * <p>If this object
49.654 + * represents a primitive type or void, null is returned.
49.655 + *
49.656 + * @return the class loader that loaded the class or interface
49.657 + * represented by this object.
49.658 + * @throws SecurityException
49.659 + * if a security manager exists and its
49.660 + * {@code checkPermission} method denies
49.661 + * access to the class loader for the class.
49.662 + * @see java.lang.ClassLoader
49.663 + * @see SecurityManager#checkPermission
49.664 + * @see java.lang.RuntimePermission
49.665 + */
49.666 + public ClassLoader getClassLoader() {
49.667 + throw new SecurityException();
49.668 + }
49.669 +
49.670 + /**
49.671 + * Returns the {@code Class} representing the component type of an
49.672 + * array. If this class does not represent an array class this method
49.673 + * returns null.
49.674 + *
49.675 + * @return the {@code Class} representing the component type of this
49.676 + * class if this class is an array
49.677 + * @see java.lang.reflect.Array
49.678 + * @since JDK1.1
49.679 + */
49.680 + public Class<?> getComponentType() {
49.681 + if (isArray()) {
49.682 + try {
49.683 + return getComponentType0();
49.684 + } catch (ClassNotFoundException cnfe) {
49.685 + throw new IllegalStateException(cnfe);
49.686 + }
49.687 + }
49.688 + return null;
49.689 + }
49.690
49.691 -
49.692 + private Class<?> getComponentType0() throws ClassNotFoundException {
49.693 + String n = getName().substring(1);
49.694 + switch (n.charAt(0)) {
49.695 + case 'L':
49.696 + n = n.substring(1, n.length() - 1);
49.697 + return Class.forName(n);
49.698 + case 'I':
49.699 + return Integer.TYPE;
49.700 + case 'J':
49.701 + return Long.TYPE;
49.702 + case 'D':
49.703 + return Double.TYPE;
49.704 + case 'F':
49.705 + return Float.TYPE;
49.706 + case 'B':
49.707 + return Byte.TYPE;
49.708 + case 'Z':
49.709 + return Boolean.TYPE;
49.710 + case 'S':
49.711 + return Short.TYPE;
49.712 + case 'V':
49.713 + return Void.TYPE;
49.714 + case 'C':
49.715 + return Character.TYPE;
49.716 + case '[':
49.717 + return defineArray(n);
49.718 + default:
49.719 + throw new ClassNotFoundException("Unknown component type of " + getName());
49.720 + }
49.721 + }
49.722 +
49.723 + @JavaScriptBody(args = { "sig" }, body =
49.724 + "var c = Array[sig];\n" +
49.725 + "if (c) return c;\n" +
49.726 + "c = vm.java_lang_Class(true);\n" +
49.727 + "c.jvmName = sig;\n" +
49.728 + "c.superclass = vm.java_lang_Object(false).$class;\n" +
49.729 + "c.array = true;\n" +
49.730 + "Array[sig] = c;\n" +
49.731 + "return c;"
49.732 + )
49.733 + private static native Class<?> defineArray(String sig);
49.734 +
49.735 /**
49.736 * Returns true if and only if this class was declared as an enum in the
49.737 * source code.
49.738 @@ -674,18 +1136,32 @@
49.739 throw new ClassCastException(this.toString());
49.740 }
49.741
49.742 + @JavaScriptBody(args = { "ac" },
49.743 + body =
49.744 + "if (this.anno) {"
49.745 + + " return this.anno['L' + ac.jvmName + ';'];"
49.746 + + "} else return null;"
49.747 + )
49.748 + private Object getAnnotationData(Class<?> annotationClass) {
49.749 + throw new UnsupportedOperationException();
49.750 + }
49.751 /**
49.752 * @throws NullPointerException {@inheritDoc}
49.753 * @since 1.5
49.754 */
49.755 public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
49.756 - throw new UnsupportedOperationException();
49.757 + Object data = getAnnotationData(annotationClass);
49.758 + return data == null ? null : AnnotationImpl.create(annotationClass, data);
49.759 }
49.760
49.761 /**
49.762 * @throws NullPointerException {@inheritDoc}
49.763 * @since 1.5
49.764 */
49.765 + @JavaScriptBody(args = { "ac" },
49.766 + body = "if (this.anno && this.anno['L' + ac.jvmName + ';']) { return true; }"
49.767 + + "else return false;"
49.768 + )
49.769 public boolean isAnnotationPresent(
49.770 Class<? extends Annotation> annotationClass) {
49.771 if (annotationClass == null)
49.772 @@ -694,12 +1170,17 @@
49.773 return getAnnotation(annotationClass) != null;
49.774 }
49.775
49.776 + @JavaScriptBody(args = {}, body = "return this.anno;")
49.777 + private Object getAnnotationData() {
49.778 + throw new UnsupportedOperationException();
49.779 + }
49.780
49.781 /**
49.782 * @since 1.5
49.783 */
49.784 public Annotation[] getAnnotations() {
49.785 - throw new UnsupportedOperationException();
49.786 + Object data = getAnnotationData();
49.787 + return data == null ? new Annotation[0] : AnnotationImpl.create(data);
49.788 }
49.789
49.790 /**
49.791 @@ -709,12 +1190,16 @@
49.792 throw new UnsupportedOperationException();
49.793 }
49.794
49.795 - static Class getPrimitiveClass(String type) {
49.796 - // XXX
49.797 - return Object.class;
49.798 - }
49.799 + @JavaScriptBody(args = "type", body = ""
49.800 + + "var c = vm.java_lang_Class(true);"
49.801 + + "c.jvmName = type;"
49.802 + + "c.primitive = true;"
49.803 + + "return c;"
49.804 + )
49.805 + native static Class getPrimitiveClass(String type);
49.806
49.807 - public boolean desiredAssertionStatus() {
49.808 - return false;
49.809 - }
49.810 + @JavaScriptBody(args = {}, body =
49.811 + "return vm.desiredAssertionStatus ? vm.desiredAssertionStatus : false;"
49.812 + )
49.813 + public native boolean desiredAssertionStatus();
49.814 }
50.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
50.2 +++ b/emul/src/main/java/java/lang/ClassFormatError.java Wed Jan 23 20:16:48 2013 +0100
50.3 @@ -0,0 +1,56 @@
50.4 +/*
50.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
50.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
50.7 + *
50.8 + * This code is free software; you can redistribute it and/or modify it
50.9 + * under the terms of the GNU General Public License version 2 only, as
50.10 + * published by the Free Software Foundation. Oracle designates this
50.11 + * particular file as subject to the "Classpath" exception as provided
50.12 + * by Oracle in the LICENSE file that accompanied this code.
50.13 + *
50.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
50.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
50.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
50.17 + * version 2 for more details (a copy is included in the LICENSE file that
50.18 + * accompanied this code).
50.19 + *
50.20 + * You should have received a copy of the GNU General Public License version
50.21 + * 2 along with this work; if not, write to the Free Software Foundation,
50.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
50.23 + *
50.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
50.25 + * or visit www.oracle.com if you need additional information or have any
50.26 + * questions.
50.27 + */
50.28 +
50.29 +package java.lang;
50.30 +
50.31 +/**
50.32 + * Thrown when the Java Virtual Machine attempts to read a class
50.33 + * file and determines that the file is malformed or otherwise cannot
50.34 + * be interpreted as a class file.
50.35 + *
50.36 + * @author unascribed
50.37 + * @since JDK1.0
50.38 + */
50.39 +public
50.40 +class ClassFormatError extends LinkageError {
50.41 + private static final long serialVersionUID = -8420114879011949195L;
50.42 +
50.43 + /**
50.44 + * Constructs a <code>ClassFormatError</code> with no detail message.
50.45 + */
50.46 + public ClassFormatError() {
50.47 + super();
50.48 + }
50.49 +
50.50 + /**
50.51 + * Constructs a <code>ClassFormatError</code> with the specified
50.52 + * detail message.
50.53 + *
50.54 + * @param s the detail message.
50.55 + */
50.56 + public ClassFormatError(String s) {
50.57 + super(s);
50.58 + }
50.59 +}
51.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
51.2 +++ b/emul/src/main/java/java/lang/ClassLoader.java Wed Jan 23 20:16:48 2013 +0100
51.3 @@ -0,0 +1,914 @@
51.4 +/*
51.5 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
51.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
51.7 + *
51.8 + * This code is free software; you can redistribute it and/or modify it
51.9 + * under the terms of the GNU General Public License version 2 only, as
51.10 + * published by the Free Software Foundation. Oracle designates this
51.11 + * particular file as subject to the "Classpath" exception as provided
51.12 + * by Oracle in the LICENSE file that accompanied this code.
51.13 + *
51.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
51.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
51.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
51.17 + * version 2 for more details (a copy is included in the LICENSE file that
51.18 + * accompanied this code).
51.19 + *
51.20 + * You should have received a copy of the GNU General Public License version
51.21 + * 2 along with this work; if not, write to the Free Software Foundation,
51.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
51.23 + *
51.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
51.25 + * or visit www.oracle.com if you need additional information or have any
51.26 + * questions.
51.27 + */
51.28 +package java.lang;
51.29 +
51.30 +import java.io.InputStream;
51.31 +import java.io.IOException;
51.32 +import java.net.URL;
51.33 +import java.util.Enumeration;
51.34 +import java.util.NoSuchElementException;
51.35 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
51.36 +
51.37 +/**
51.38 + * A class loader is an object that is responsible for loading classes. The
51.39 + * class <tt>ClassLoader</tt> is an abstract class. Given the <a
51.40 + * href="#name">binary name</a> of a class, a class loader should attempt to
51.41 + * locate or generate data that constitutes a definition for the class. A
51.42 + * typical strategy is to transform the name into a file name and then read a
51.43 + * "class file" of that name from a file system.
51.44 + *
51.45 + * <p> Every {@link Class <tt>Class</tt>} object contains a {@link
51.46 + * Class#getClassLoader() reference} to the <tt>ClassLoader</tt> that defined
51.47 + * it.
51.48 + *
51.49 + * <p> <tt>Class</tt> objects for array classes are not created by class
51.50 + * loaders, but are created automatically as required by the Java runtime.
51.51 + * The class loader for an array class, as returned by {@link
51.52 + * Class#getClassLoader()} is the same as the class loader for its element
51.53 + * type; if the element type is a primitive type, then the array class has no
51.54 + * class loader.
51.55 + *
51.56 + * <p> Applications implement subclasses of <tt>ClassLoader</tt> in order to
51.57 + * extend the manner in which the Java virtual machine dynamically loads
51.58 + * classes.
51.59 + *
51.60 + * <p> Class loaders may typically be used by security managers to indicate
51.61 + * security domains.
51.62 + *
51.63 + * <p> The <tt>ClassLoader</tt> class uses a delegation model to search for
51.64 + * classes and resources. Each instance of <tt>ClassLoader</tt> has an
51.65 + * associated parent class loader. When requested to find a class or
51.66 + * resource, a <tt>ClassLoader</tt> instance will delegate the search for the
51.67 + * class or resource to its parent class loader before attempting to find the
51.68 + * class or resource itself. The virtual machine's built-in class loader,
51.69 + * called the "bootstrap class loader", does not itself have a parent but may
51.70 + * serve as the parent of a <tt>ClassLoader</tt> instance.
51.71 + *
51.72 + * <p> Class loaders that support concurrent loading of classes are known as
51.73 + * <em>parallel capable</em> class loaders and are required to register
51.74 + * themselves at their class initialization time by invoking the
51.75 + * {@link
51.76 + * #registerAsParallelCapable <tt>ClassLoader.registerAsParallelCapable</tt>}
51.77 + * method. Note that the <tt>ClassLoader</tt> class is registered as parallel
51.78 + * capable by default. However, its subclasses still need to register themselves
51.79 + * if they are parallel capable. <br>
51.80 + * In environments in which the delegation model is not strictly
51.81 + * hierarchical, class loaders need to be parallel capable, otherwise class
51.82 + * loading can lead to deadlocks because the loader lock is held for the
51.83 + * duration of the class loading process (see {@link #loadClass
51.84 + * <tt>loadClass</tt>} methods).
51.85 + *
51.86 + * <p> Normally, the Java virtual machine loads classes from the local file
51.87 + * system in a platform-dependent manner. For example, on UNIX systems, the
51.88 + * virtual machine loads classes from the directory defined by the
51.89 + * <tt>CLASSPATH</tt> environment variable.
51.90 + *
51.91 + * <p> However, some classes may not originate from a file; they may originate
51.92 + * from other sources, such as the network, or they could be constructed by an
51.93 + * application. The method {@link #defineClass(String, byte[], int, int)
51.94 + * <tt>defineClass</tt>} converts an array of bytes into an instance of class
51.95 + * <tt>Class</tt>. Instances of this newly defined class can be created using
51.96 + * {@link Class#newInstance <tt>Class.newInstance</tt>}.
51.97 + *
51.98 + * <p> The methods and constructors of objects created by a class loader may
51.99 + * reference other classes. To determine the class(es) referred to, the Java
51.100 + * virtual machine invokes the {@link #loadClass <tt>loadClass</tt>} method of
51.101 + * the class loader that originally created the class.
51.102 + *
51.103 + * <p> For example, an application could create a network class loader to
51.104 + * download class files from a server. Sample code might look like:
51.105 + *
51.106 + * <blockquote><pre>
51.107 + * ClassLoader loader = new NetworkClassLoader(host, port);
51.108 + * Object main = loader.loadClass("Main", true).newInstance();
51.109 + * . . .
51.110 + * </pre></blockquote>
51.111 + *
51.112 + * <p> The network class loader subclass must define the methods {@link
51.113 + * #findClass <tt>findClass</tt>} and <tt>loadClassData</tt> to load a class
51.114 + * from the network. Once it has downloaded the bytes that make up the class,
51.115 + * it should use the method {@link #defineClass <tt>defineClass</tt>} to
51.116 + * create a class instance. A sample implementation is:
51.117 + *
51.118 + * <blockquote><pre>
51.119 + * class NetworkClassLoader extends ClassLoader {
51.120 + * String host;
51.121 + * int port;
51.122 + *
51.123 + * public Class findClass(String name) {
51.124 + * byte[] b = loadClassData(name);
51.125 + * return defineClass(name, b, 0, b.length);
51.126 + * }
51.127 + *
51.128 + * private byte[] loadClassData(String name) {
51.129 + * // load the class data from the connection
51.130 + * . . .
51.131 + * }
51.132 + * }
51.133 + * </pre></blockquote>
51.134 + *
51.135 + * <h4> <a name="name">Binary names</a> </h4>
51.136 + *
51.137 + * <p> Any class name provided as a {@link String} parameter to methods in
51.138 + * <tt>ClassLoader</tt> must be a binary name as defined by
51.139 + * <cite>The Java™ Language Specification</cite>.
51.140 + *
51.141 + * <p> Examples of valid class names include:
51.142 + * <blockquote><pre>
51.143 + * "java.lang.String"
51.144 + * "javax.swing.JSpinner$DefaultEditor"
51.145 + * "java.security.KeyStore$Builder$FileBuilder$1"
51.146 + * "java.net.URLClassLoader$3$1"
51.147 + * </pre></blockquote>
51.148 + *
51.149 + * @see #resolveClass(Class)
51.150 + * @since 1.0
51.151 + */
51.152 +public abstract class ClassLoader {
51.153 +
51.154 + @JavaScriptBody(args = {}, body = "")
51.155 + private static native void registerNatives();
51.156 + static {
51.157 + registerNatives();
51.158 + }
51.159 +
51.160 + // The parent class loader for delegation
51.161 + // Note: VM hardcoded the offset of this field, thus all new fields
51.162 + // must be added *after* it.
51.163 + private final ClassLoader parent;
51.164 +
51.165 +
51.166 + /**
51.167 + * Creates a new class loader using the specified parent class loader for
51.168 + * delegation.
51.169 + *
51.170 + * <p> If there is a security manager, its {@link
51.171 + * SecurityManager#checkCreateClassLoader()
51.172 + * <tt>checkCreateClassLoader</tt>} method is invoked. This may result in
51.173 + * a security exception. </p>
51.174 + *
51.175 + * @param parent
51.176 + * The parent class loader
51.177 + *
51.178 + * @throws SecurityException
51.179 + * If a security manager exists and its
51.180 + * <tt>checkCreateClassLoader</tt> method doesn't allow creation
51.181 + * of a new class loader.
51.182 + *
51.183 + * @since 1.2
51.184 + */
51.185 + protected ClassLoader(ClassLoader parent) {
51.186 + throw new SecurityException();
51.187 + }
51.188 +
51.189 + /**
51.190 + * Creates a new class loader using the <tt>ClassLoader</tt> returned by
51.191 + * the method {@link #getSystemClassLoader()
51.192 + * <tt>getSystemClassLoader()</tt>} as the parent class loader.
51.193 + *
51.194 + * <p> If there is a security manager, its {@link
51.195 + * SecurityManager#checkCreateClassLoader()
51.196 + * <tt>checkCreateClassLoader</tt>} method is invoked. This may result in
51.197 + * a security exception. </p>
51.198 + *
51.199 + * @throws SecurityException
51.200 + * If a security manager exists and its
51.201 + * <tt>checkCreateClassLoader</tt> method doesn't allow creation
51.202 + * of a new class loader.
51.203 + */
51.204 + protected ClassLoader() {
51.205 + throw new SecurityException();
51.206 + }
51.207 +
51.208 + // -- Class --
51.209 +
51.210 + /**
51.211 + * Loads the class with the specified <a href="#name">binary name</a>.
51.212 + * This method searches for classes in the same manner as the {@link
51.213 + * #loadClass(String, boolean)} method. It is invoked by the Java virtual
51.214 + * machine to resolve class references. Invoking this method is equivalent
51.215 + * to invoking {@link #loadClass(String, boolean) <tt>loadClass(name,
51.216 + * false)</tt>}. </p>
51.217 + *
51.218 + * @param name
51.219 + * The <a href="#name">binary name</a> of the class
51.220 + *
51.221 + * @return The resulting <tt>Class</tt> object
51.222 + *
51.223 + * @throws ClassNotFoundException
51.224 + * If the class was not found
51.225 + */
51.226 + public Class<?> loadClass(String name) throws ClassNotFoundException {
51.227 + return loadClass(name, false);
51.228 + }
51.229 +
51.230 + /**
51.231 + * Loads the class with the specified <a href="#name">binary name</a>. The
51.232 + * default implementation of this method searches for classes in the
51.233 + * following order:
51.234 + *
51.235 + * <p><ol>
51.236 + *
51.237 + * <li><p> Invoke {@link #findLoadedClass(String)} to check if the class
51.238 + * has already been loaded. </p></li>
51.239 + *
51.240 + * <li><p> Invoke the {@link #loadClass(String) <tt>loadClass</tt>} method
51.241 + * on the parent class loader. If the parent is <tt>null</tt> the class
51.242 + * loader built-in to the virtual machine is used, instead. </p></li>
51.243 + *
51.244 + * <li><p> Invoke the {@link #findClass(String)} method to find the
51.245 + * class. </p></li>
51.246 + *
51.247 + * </ol>
51.248 + *
51.249 + * <p> If the class was found using the above steps, and the
51.250 + * <tt>resolve</tt> flag is true, this method will then invoke the {@link
51.251 + * #resolveClass(Class)} method on the resulting <tt>Class</tt> object.
51.252 + *
51.253 + * <p> Subclasses of <tt>ClassLoader</tt> are encouraged to override {@link
51.254 + * #findClass(String)}, rather than this method. </p>
51.255 + *
51.256 + * <p> Unless overridden, this method synchronizes on the result of
51.257 + * {@link #getClassLoadingLock <tt>getClassLoadingLock</tt>} method
51.258 + * during the entire class loading process.
51.259 + *
51.260 + * @param name
51.261 + * The <a href="#name">binary name</a> of the class
51.262 + *
51.263 + * @param resolve
51.264 + * If <tt>true</tt> then resolve the class
51.265 + *
51.266 + * @return The resulting <tt>Class</tt> object
51.267 + *
51.268 + * @throws ClassNotFoundException
51.269 + * If the class could not be found
51.270 + */
51.271 + protected Class<?> loadClass(String name, boolean resolve)
51.272 + throws ClassNotFoundException
51.273 + {
51.274 + synchronized (getClassLoadingLock(name)) {
51.275 + // First, check if the class has already been loaded
51.276 + Class c = findLoadedClass(name);
51.277 + if (c == null) {
51.278 + try {
51.279 + if (parent != null) {
51.280 + c = parent.loadClass(name, false);
51.281 + } else {
51.282 + c = findBootstrapClassOrNull(name);
51.283 + }
51.284 + } catch (ClassNotFoundException e) {
51.285 + // ClassNotFoundException thrown if class not found
51.286 + // from the non-null parent class loader
51.287 + }
51.288 +
51.289 + if (c == null) {
51.290 + // If still not found, then invoke findClass in order
51.291 + // to find the class.
51.292 + c = findClass(name);
51.293 +
51.294 +// // this is the defining class loader; record the stats
51.295 +// sun.misc.PerfCounter.getParentDelegationTime().addTime(t1 - t0);
51.296 +// sun.misc.PerfCounter.getFindClassTime().addElapsedTimeFrom(t1);
51.297 +// sun.misc.PerfCounter.getFindClasses().increment();
51.298 + }
51.299 + }
51.300 + if (resolve) {
51.301 + resolveClass(c);
51.302 + }
51.303 + return c;
51.304 + }
51.305 + }
51.306 +
51.307 + /**
51.308 + * Returns the lock object for class loading operations.
51.309 + * For backward compatibility, the default implementation of this method
51.310 + * behaves as follows. If this ClassLoader object is registered as
51.311 + * parallel capable, the method returns a dedicated object associated
51.312 + * with the specified class name. Otherwise, the method returns this
51.313 + * ClassLoader object. </p>
51.314 + *
51.315 + * @param className
51.316 + * The name of the to-be-loaded class
51.317 + *
51.318 + * @return the lock for class loading operations
51.319 + *
51.320 + * @throws NullPointerException
51.321 + * If registered as parallel capable and <tt>className</tt> is null
51.322 + *
51.323 + * @see #loadClass(String, boolean)
51.324 + *
51.325 + * @since 1.7
51.326 + */
51.327 + protected Object getClassLoadingLock(String className) {
51.328 + Object lock = this;
51.329 + return lock;
51.330 + }
51.331 +
51.332 + /**
51.333 + * Finds the class with the specified <a href="#name">binary name</a>.
51.334 + * This method should be overridden by class loader implementations that
51.335 + * follow the delegation model for loading classes, and will be invoked by
51.336 + * the {@link #loadClass <tt>loadClass</tt>} method after checking the
51.337 + * parent class loader for the requested class. The default implementation
51.338 + * throws a <tt>ClassNotFoundException</tt>. </p>
51.339 + *
51.340 + * @param name
51.341 + * The <a href="#name">binary name</a> of the class
51.342 + *
51.343 + * @return The resulting <tt>Class</tt> object
51.344 + *
51.345 + * @throws ClassNotFoundException
51.346 + * If the class could not be found
51.347 + *
51.348 + * @since 1.2
51.349 + */
51.350 + protected Class<?> findClass(String name) throws ClassNotFoundException {
51.351 + throw new ClassNotFoundException(name);
51.352 + }
51.353 +
51.354 + /**
51.355 + * Converts an array of bytes into an instance of class <tt>Class</tt>.
51.356 + * Before the <tt>Class</tt> can be used it must be resolved. This method
51.357 + * is deprecated in favor of the version that takes a <a
51.358 + * href="#name">binary name</a> as its first argument, and is more secure.
51.359 + *
51.360 + * @param b
51.361 + * The bytes that make up the class data. The bytes in positions
51.362 + * <tt>off</tt> through <tt>off+len-1</tt> should have the format
51.363 + * of a valid class file as defined by
51.364 + * <cite>The Java™ Virtual Machine Specification</cite>.
51.365 + *
51.366 + * @param off
51.367 + * The start offset in <tt>b</tt> of the class data
51.368 + *
51.369 + * @param len
51.370 + * The length of the class data
51.371 + *
51.372 + * @return The <tt>Class</tt> object that was created from the specified
51.373 + * class data
51.374 + *
51.375 + * @throws ClassFormatError
51.376 + * If the data did not contain a valid class
51.377 + *
51.378 + * @throws IndexOutOfBoundsException
51.379 + * If either <tt>off</tt> or <tt>len</tt> is negative, or if
51.380 + * <tt>off+len</tt> is greater than <tt>b.length</tt>.
51.381 + *
51.382 + * @throws SecurityException
51.383 + * If an attempt is made to add this class to a package that
51.384 + * contains classes that were signed by a different set of
51.385 + * certificates than this class, or if an attempt is made
51.386 + * to define a class in a package with a fully-qualified name
51.387 + * that starts with "{@code java.}".
51.388 + *
51.389 + * @see #loadClass(String, boolean)
51.390 + * @see #resolveClass(Class)
51.391 + *
51.392 + * @deprecated Replaced by {@link #defineClass(String, byte[], int, int)
51.393 + * defineClass(String, byte[], int, int)}
51.394 + */
51.395 + @Deprecated
51.396 + protected final Class<?> defineClass(byte[] b, int off, int len)
51.397 + throws ClassFormatError
51.398 + {
51.399 + throw new SecurityException();
51.400 + }
51.401 +
51.402 + /**
51.403 + * Converts an array of bytes into an instance of class <tt>Class</tt>.
51.404 + * Before the <tt>Class</tt> can be used it must be resolved.
51.405 + *
51.406 + * <p> This method assigns a default {@link java.security.ProtectionDomain
51.407 + * <tt>ProtectionDomain</tt>} to the newly defined class. The
51.408 + * <tt>ProtectionDomain</tt> is effectively granted the same set of
51.409 + * permissions returned when {@link
51.410 + * java.security.Policy#getPermissions(java.security.CodeSource)
51.411 + * <tt>Policy.getPolicy().getPermissions(new CodeSource(null, null))</tt>}
51.412 + * is invoked. The default domain is created on the first invocation of
51.413 + * {@link #defineClass(String, byte[], int, int) <tt>defineClass</tt>},
51.414 + * and re-used on subsequent invocations.
51.415 + *
51.416 + * <p> To assign a specific <tt>ProtectionDomain</tt> to the class, use
51.417 + * the {@link #defineClass(String, byte[], int, int,
51.418 + * java.security.ProtectionDomain) <tt>defineClass</tt>} method that takes a
51.419 + * <tt>ProtectionDomain</tt> as one of its arguments. </p>
51.420 + *
51.421 + * @param name
51.422 + * The expected <a href="#name">binary name</a> of the class, or
51.423 + * <tt>null</tt> if not known
51.424 + *
51.425 + * @param b
51.426 + * The bytes that make up the class data. The bytes in positions
51.427 + * <tt>off</tt> through <tt>off+len-1</tt> should have the format
51.428 + * of a valid class file as defined by
51.429 + * <cite>The Java™ Virtual Machine Specification</cite>.
51.430 + *
51.431 + * @param off
51.432 + * The start offset in <tt>b</tt> of the class data
51.433 + *
51.434 + * @param len
51.435 + * The length of the class data
51.436 + *
51.437 + * @return The <tt>Class</tt> object that was created from the specified
51.438 + * class data.
51.439 + *
51.440 + * @throws ClassFormatError
51.441 + * If the data did not contain a valid class
51.442 + *
51.443 + * @throws IndexOutOfBoundsException
51.444 + * If either <tt>off</tt> or <tt>len</tt> is negative, or if
51.445 + * <tt>off+len</tt> is greater than <tt>b.length</tt>.
51.446 + *
51.447 + * @throws SecurityException
51.448 + * If an attempt is made to add this class to a package that
51.449 + * contains classes that were signed by a different set of
51.450 + * certificates than this class (which is unsigned), or if
51.451 + * <tt>name</tt> begins with "<tt>java.</tt>".
51.452 + *
51.453 + * @see #loadClass(String, boolean)
51.454 + * @see #resolveClass(Class)
51.455 + * @see java.security.CodeSource
51.456 + * @see java.security.SecureClassLoader
51.457 + *
51.458 + * @since 1.1
51.459 + */
51.460 + protected final Class<?> defineClass(String name, byte[] b, int off, int len)
51.461 + throws ClassFormatError
51.462 + {
51.463 + throw new SecurityException();
51.464 + }
51.465 +
51.466 + /**
51.467 + * Links the specified class. This (misleadingly named) method may be
51.468 + * used by a class loader to link a class. If the class <tt>c</tt> has
51.469 + * already been linked, then this method simply returns. Otherwise, the
51.470 + * class is linked as described in the "Execution" chapter of
51.471 + * <cite>The Java™ Language Specification</cite>.
51.472 + * </p>
51.473 + *
51.474 + * @param c
51.475 + * The class to link
51.476 + *
51.477 + * @throws NullPointerException
51.478 + * If <tt>c</tt> is <tt>null</tt>.
51.479 + *
51.480 + * @see #defineClass(String, byte[], int, int)
51.481 + */
51.482 + protected final void resolveClass(Class<?> c) {
51.483 + resolveClass0(c);
51.484 + }
51.485 +
51.486 + private native void resolveClass0(Class c);
51.487 +
51.488 +
51.489 + /**
51.490 + * Returns the class with the given <a href="#name">binary name</a> if this
51.491 + * loader has been recorded by the Java virtual machine as an initiating
51.492 + * loader of a class with that <a href="#name">binary name</a>. Otherwise
51.493 + * <tt>null</tt> is returned. </p>
51.494 + *
51.495 + * @param name
51.496 + * The <a href="#name">binary name</a> of the class
51.497 + *
51.498 + * @return The <tt>Class</tt> object, or <tt>null</tt> if the class has
51.499 + * not been loaded
51.500 + *
51.501 + * @since 1.1
51.502 + */
51.503 + protected final Class<?> findLoadedClass(String name) {
51.504 + if (!checkName(name))
51.505 + return null;
51.506 + return findLoadedClass0(name);
51.507 + }
51.508 +
51.509 + private native final Class findLoadedClass0(String name);
51.510 +
51.511 + /**
51.512 + * Sets the signers of a class. This should be invoked after defining a
51.513 + * class. </p>
51.514 + *
51.515 + * @param c
51.516 + * The <tt>Class</tt> object
51.517 + *
51.518 + * @param signers
51.519 + * The signers for the class
51.520 + *
51.521 + * @since 1.1
51.522 + */
51.523 + protected final void setSigners(Class<?> c, Object[] signers) {
51.524 + //c.setSigners(signers);
51.525 + throw new UnsupportedOperationException();
51.526 + }
51.527 +
51.528 +
51.529 + // -- Resource --
51.530 +
51.531 + /**
51.532 + * Finds the resource with the given name. A resource is some data
51.533 + * (images, audio, text, etc) that can be accessed by class code in a way
51.534 + * that is independent of the location of the code.
51.535 + *
51.536 + * <p> The name of a resource is a '<tt>/</tt>'-separated path name that
51.537 + * identifies the resource.
51.538 + *
51.539 + * <p> This method will first search the parent class loader for the
51.540 + * resource; if the parent is <tt>null</tt> the path of the class loader
51.541 + * built-in to the virtual machine is searched. That failing, this method
51.542 + * will invoke {@link #findResource(String)} to find the resource. </p>
51.543 + *
51.544 + * @param name
51.545 + * The resource name
51.546 + *
51.547 + * @return A <tt>URL</tt> object for reading the resource, or
51.548 + * <tt>null</tt> if the resource could not be found or the invoker
51.549 + * doesn't have adequate privileges to get the resource.
51.550 + *
51.551 + * @since 1.1
51.552 + */
51.553 + public URL getResource(String name) {
51.554 + URL url;
51.555 + if (parent != null) {
51.556 + url = parent.getResource(name);
51.557 + } else {
51.558 + url = getBootstrapResource(name);
51.559 + }
51.560 + if (url == null) {
51.561 + url = findResource(name);
51.562 + }
51.563 + return url;
51.564 + }
51.565 +
51.566 + /**
51.567 + * Finds all the resources with the given name. A resource is some data
51.568 + * (images, audio, text, etc) that can be accessed by class code in a way
51.569 + * that is independent of the location of the code.
51.570 + *
51.571 + * <p>The name of a resource is a <tt>/</tt>-separated path name that
51.572 + * identifies the resource.
51.573 + *
51.574 + * <p> The search order is described in the documentation for {@link
51.575 + * #getResource(String)}. </p>
51.576 + *
51.577 + * @param name
51.578 + * The resource name
51.579 + *
51.580 + * @return An enumeration of {@link java.net.URL <tt>URL</tt>} objects for
51.581 + * the resource. If no resources could be found, the enumeration
51.582 + * will be empty. Resources that the class loader doesn't have
51.583 + * access to will not be in the enumeration.
51.584 + *
51.585 + * @throws IOException
51.586 + * If I/O errors occur
51.587 + *
51.588 + * @see #findResources(String)
51.589 + *
51.590 + * @since 1.2
51.591 + */
51.592 + public Enumeration<URL> getResources(String name) throws IOException {
51.593 + Enumeration[] tmp = new Enumeration[2];
51.594 + if (parent != null) {
51.595 + tmp[0] = parent.getResources(name);
51.596 + } else {
51.597 + tmp[0] = getBootstrapResources(name);
51.598 + }
51.599 + tmp[1] = findResources(name);
51.600 +
51.601 + return new CompoundEnumeration(tmp);
51.602 + }
51.603 +
51.604 + /**
51.605 + * Finds the resource with the given name. Class loader implementations
51.606 + * should override this method to specify where to find resources. </p>
51.607 + *
51.608 + * @param name
51.609 + * The resource name
51.610 + *
51.611 + * @return A <tt>URL</tt> object for reading the resource, or
51.612 + * <tt>null</tt> if the resource could not be found
51.613 + *
51.614 + * @since 1.2
51.615 + */
51.616 + protected URL findResource(String name) {
51.617 + return null;
51.618 + }
51.619 +
51.620 + /**
51.621 + * Returns an enumeration of {@link java.net.URL <tt>URL</tt>} objects
51.622 + * representing all the resources with the given name. Class loader
51.623 + * implementations should override this method to specify where to load
51.624 + * resources from. </p>
51.625 + *
51.626 + * @param name
51.627 + * The resource name
51.628 + *
51.629 + * @return An enumeration of {@link java.net.URL <tt>URL</tt>} objects for
51.630 + * the resources
51.631 + *
51.632 + * @throws IOException
51.633 + * If I/O errors occur
51.634 + *
51.635 + * @since 1.2
51.636 + */
51.637 + protected Enumeration<URL> findResources(String name) throws IOException {
51.638 + return new CompoundEnumeration(new Enumeration[0]);
51.639 + }
51.640 +
51.641 + // index 0: java.lang.ClassLoader.class
51.642 + // index 1: the immediate caller of index 0.
51.643 + // index 2: the immediate caller of index 1.
51.644 + private static native Class<? extends ClassLoader> getCaller(int index);
51.645 +
51.646 + /**
51.647 + * Registers the caller as parallel capable.</p>
51.648 + * The registration succeeds if and only if all of the following
51.649 + * conditions are met: <br>
51.650 + * 1. no instance of the caller has been created</p>
51.651 + * 2. all of the super classes (except class Object) of the caller are
51.652 + * registered as parallel capable</p>
51.653 + * Note that once a class loader is registered as parallel capable, there
51.654 + * is no way to change it back. </p>
51.655 + *
51.656 + * @return true if the caller is successfully registered as
51.657 + * parallel capable and false if otherwise.
51.658 + *
51.659 + * @since 1.7
51.660 + */
51.661 +// protected static boolean registerAsParallelCapable() {
51.662 +// return false;
51.663 +// }
51.664 +
51.665 + /**
51.666 + * Find a resource of the specified name from the search path used to load
51.667 + * classes. This method locates the resource through the system class
51.668 + * loader (see {@link #getSystemClassLoader()}). </p>
51.669 + *
51.670 + * @param name
51.671 + * The resource name
51.672 + *
51.673 + * @return A {@link java.net.URL <tt>URL</tt>} object for reading the
51.674 + * resource, or <tt>null</tt> if the resource could not be found
51.675 + *
51.676 + * @since 1.1
51.677 + */
51.678 + public static URL getSystemResource(String name) {
51.679 + ClassLoader system = getSystemClassLoader();
51.680 + if (system == null) {
51.681 + return getBootstrapResource(name);
51.682 + }
51.683 + return system.getResource(name);
51.684 + }
51.685 +
51.686 + /**
51.687 + * Finds all resources of the specified name from the search path used to
51.688 + * load classes. The resources thus found are returned as an
51.689 + * {@link java.util.Enumeration <tt>Enumeration</tt>} of {@link
51.690 + * java.net.URL <tt>URL</tt>} objects.
51.691 + *
51.692 + * <p> The search order is described in the documentation for {@link
51.693 + * #getSystemResource(String)}. </p>
51.694 + *
51.695 + * @param name
51.696 + * The resource name
51.697 + *
51.698 + * @return An enumeration of resource {@link java.net.URL <tt>URL</tt>}
51.699 + * objects
51.700 + *
51.701 + * @throws IOException
51.702 + * If I/O errors occur
51.703 +
51.704 + * @since 1.2
51.705 + */
51.706 + public static Enumeration<URL> getSystemResources(String name)
51.707 + throws IOException
51.708 + {
51.709 + ClassLoader system = getSystemClassLoader();
51.710 + if (system == null) {
51.711 + return getBootstrapResources(name);
51.712 + }
51.713 + return system.getResources(name);
51.714 + }
51.715 +
51.716 +
51.717 +
51.718 + /**
51.719 + * Returns an input stream for reading the specified resource.
51.720 + *
51.721 + * <p> The search order is described in the documentation for {@link
51.722 + * #getResource(String)}. </p>
51.723 + *
51.724 + * @param name
51.725 + * The resource name
51.726 + *
51.727 + * @return An input stream for reading the resource, or <tt>null</tt>
51.728 + * if the resource could not be found
51.729 + *
51.730 + * @since 1.1
51.731 + */
51.732 + public InputStream getResourceAsStream(String name) {
51.733 + URL url = getResource(name);
51.734 + try {
51.735 + return url != null ? url.openStream() : null;
51.736 + } catch (IOException e) {
51.737 + return null;
51.738 + }
51.739 + }
51.740 +
51.741 + /**
51.742 + * Open for reading, a resource of the specified name from the search path
51.743 + * used to load classes. This method locates the resource through the
51.744 + * system class loader (see {@link #getSystemClassLoader()}). </p>
51.745 + *
51.746 + * @param name
51.747 + * The resource name
51.748 + *
51.749 + * @return An input stream for reading the resource, or <tt>null</tt>
51.750 + * if the resource could not be found
51.751 + *
51.752 + * @since 1.1
51.753 + */
51.754 + public static InputStream getSystemResourceAsStream(String name) {
51.755 + URL url = getSystemResource(name);
51.756 + try {
51.757 + return url != null ? url.openStream() : null;
51.758 + } catch (IOException e) {
51.759 + return null;
51.760 + }
51.761 + }
51.762 +
51.763 +
51.764 + // -- Hierarchy --
51.765 +
51.766 + /**
51.767 + * Returns the parent class loader for delegation. Some implementations may
51.768 + * use <tt>null</tt> to represent the bootstrap class loader. This method
51.769 + * will return <tt>null</tt> in such implementations if this class loader's
51.770 + * parent is the bootstrap class loader.
51.771 + *
51.772 + * <p> If a security manager is present, and the invoker's class loader is
51.773 + * not <tt>null</tt> and is not an ancestor of this class loader, then this
51.774 + * method invokes the security manager's {@link
51.775 + * SecurityManager#checkPermission(java.security.Permission)
51.776 + * <tt>checkPermission</tt>} method with a {@link
51.777 + * RuntimePermission#RuntimePermission(String)
51.778 + * <tt>RuntimePermission("getClassLoader")</tt>} permission to verify
51.779 + * access to the parent class loader is permitted. If not, a
51.780 + * <tt>SecurityException</tt> will be thrown. </p>
51.781 + *
51.782 + * @return The parent <tt>ClassLoader</tt>
51.783 + *
51.784 + * @throws SecurityException
51.785 + * If a security manager exists and its <tt>checkPermission</tt>
51.786 + * method doesn't allow access to this class loader's parent class
51.787 + * loader.
51.788 + *
51.789 + * @since 1.2
51.790 + */
51.791 + public final ClassLoader getParent() {
51.792 + throw new SecurityException();
51.793 + }
51.794 +
51.795 + /**
51.796 + * Returns the system class loader for delegation. This is the default
51.797 + * delegation parent for new <tt>ClassLoader</tt> instances, and is
51.798 + * typically the class loader used to start the application.
51.799 + *
51.800 + * <p> This method is first invoked early in the runtime's startup
51.801 + * sequence, at which point it creates the system class loader and sets it
51.802 + * as the context class loader of the invoking <tt>Thread</tt>.
51.803 + *
51.804 + * <p> The default system class loader is an implementation-dependent
51.805 + * instance of this class.
51.806 + *
51.807 + * <p> If the system property "<tt>java.system.class.loader</tt>" is defined
51.808 + * when this method is first invoked then the value of that property is
51.809 + * taken to be the name of a class that will be returned as the system
51.810 + * class loader. The class is loaded using the default system class loader
51.811 + * and must define a public constructor that takes a single parameter of
51.812 + * type <tt>ClassLoader</tt> which is used as the delegation parent. An
51.813 + * instance is then created using this constructor with the default system
51.814 + * class loader as the parameter. The resulting class loader is defined
51.815 + * to be the system class loader.
51.816 + *
51.817 + * <p> If a security manager is present, and the invoker's class loader is
51.818 + * not <tt>null</tt> and the invoker's class loader is not the same as or
51.819 + * an ancestor of the system class loader, then this method invokes the
51.820 + * security manager's {@link
51.821 + * SecurityManager#checkPermission(java.security.Permission)
51.822 + * <tt>checkPermission</tt>} method with a {@link
51.823 + * RuntimePermission#RuntimePermission(String)
51.824 + * <tt>RuntimePermission("getClassLoader")</tt>} permission to verify
51.825 + * access to the system class loader. If not, a
51.826 + * <tt>SecurityException</tt> will be thrown. </p>
51.827 + *
51.828 + * @return The system <tt>ClassLoader</tt> for delegation, or
51.829 + * <tt>null</tt> if none
51.830 + *
51.831 + * @throws SecurityException
51.832 + * If a security manager exists and its <tt>checkPermission</tt>
51.833 + * method doesn't allow access to the system class loader.
51.834 + *
51.835 + * @throws IllegalStateException
51.836 + * If invoked recursively during the construction of the class
51.837 + * loader specified by the "<tt>java.system.class.loader</tt>"
51.838 + * property.
51.839 + *
51.840 + * @throws Error
51.841 + * If the system property "<tt>java.system.class.loader</tt>"
51.842 + * is defined but the named class could not be loaded, the
51.843 + * provider class does not define the required constructor, or an
51.844 + * exception is thrown by that constructor when it is invoked. The
51.845 + * underlying cause of the error can be retrieved via the
51.846 + * {@link Throwable#getCause()} method.
51.847 + *
51.848 + * @revised 1.4
51.849 + */
51.850 + public static ClassLoader getSystemClassLoader() {
51.851 + throw new SecurityException();
51.852 + }
51.853 +
51.854 + // Returns true if the specified class loader can be found in this class
51.855 + // loader's delegation chain.
51.856 + boolean isAncestor(ClassLoader cl) {
51.857 + ClassLoader acl = this;
51.858 + do {
51.859 + acl = acl.parent;
51.860 + if (cl == acl) {
51.861 + return true;
51.862 + }
51.863 + } while (acl != null);
51.864 + return false;
51.865 + }
51.866 +
51.867 + private boolean checkName(String name) {
51.868 + throw new UnsupportedOperationException();
51.869 + }
51.870 +
51.871 + private Class findBootstrapClassOrNull(String name) {
51.872 + throw new UnsupportedOperationException();
51.873 + }
51.874 +
51.875 + private static URL getBootstrapResource(String name) {
51.876 + throw new UnsupportedOperationException();
51.877 + }
51.878 +
51.879 + private static Enumeration<URL> getBootstrapResources(String name) {
51.880 + throw new UnsupportedOperationException();
51.881 + }
51.882 +
51.883 + private static class CompoundEnumeration implements Enumeration<URL> {
51.884 + private URL next;
51.885 + private int index;
51.886 + private final Enumeration[] arr;
51.887 +
51.888 + public CompoundEnumeration(Enumeration[] arr) {
51.889 + this.arr = arr;
51.890 + this.index = 0;
51.891 + }
51.892 +
51.893 + public boolean hasMoreElements() {
51.894 + if (next == null) {
51.895 + if (arr[index].hasMoreElements()) {
51.896 + next = (URL) arr[index].nextElement();
51.897 + } else {
51.898 + if (index < arr.length) {
51.899 + index++;
51.900 + return hasMoreElements();
51.901 + }
51.902 + }
51.903 + }
51.904 + return next != null;
51.905 + }
51.906 +
51.907 + public URL nextElement() {
51.908 + if (!hasMoreElements()) {
51.909 + throw new NoSuchElementException();
51.910 + }
51.911 + URL r = next;
51.912 + next = null;
51.913 + return r;
51.914 + }
51.915 +
51.916 + }
51.917 +}
52.1 --- a/emul/src/main/java/java/lang/Double.java Thu Oct 11 06:15:22 2012 -0700
52.2 +++ b/emul/src/main/java/java/lang/Double.java Wed Jan 23 20:16:48 2013 +0100
52.3 @@ -25,6 +25,8 @@
52.4
52.5 package java.lang;
52.6
52.7 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
52.8 +
52.9 /**
52.10 * The {@code Double} class wraps a value of the primitive type
52.11 * {@code double} in an object. An object of type
52.12 @@ -188,6 +190,9 @@
52.13 * @param d the {@code double} to be converted.
52.14 * @return a string representation of the argument.
52.15 */
52.16 + @JavaScriptBody(args="d", body="var r = d.toString();"
52.17 + + "if (r.indexOf('.') === -1) r = r + '.0';"
52.18 + + "return r;")
52.19 public static String toString(double d) {
52.20 throw new UnsupportedOperationException();
52.21 }
52.22 @@ -497,6 +502,7 @@
52.23 * @throws NumberFormatException if the string does not contain a
52.24 * parsable number.
52.25 */
52.26 + @JavaScriptBody(args="s", body="return parseFloat(s);")
52.27 public static Double valueOf(String s) throws NumberFormatException {
52.28 throw new UnsupportedOperationException();
52.29 // return new Double(FloatingDecimal.readJavaFormatString(s).doubleValue());
52.30 @@ -534,6 +540,7 @@
52.31 * @see java.lang.Double#valueOf(String)
52.32 * @since 1.2
52.33 */
52.34 + @JavaScriptBody(args="s", body="return parseFloat(s);")
52.35 public static double parseDouble(String s) throws NumberFormatException {
52.36 throw new UnsupportedOperationException();
52.37 // return FloatingDecimal.readJavaFormatString(s).doubleValue();
52.38 @@ -767,8 +774,7 @@
52.39 */
52.40 public boolean equals(Object obj) {
52.41 return (obj instanceof Double)
52.42 - && (doubleToLongBits(((Double)obj).value) ==
52.43 - doubleToLongBits(value));
52.44 + && (((Double)obj).value) == value;
52.45 }
52.46
52.47 /**
53.1 --- a/emul/src/main/java/java/lang/Float.java Thu Oct 11 06:15:22 2012 -0700
53.2 +++ b/emul/src/main/java/java/lang/Float.java Wed Jan 23 20:16:48 2013 +0100
53.3 @@ -25,6 +25,8 @@
53.4
53.5 package java.lang;
53.6
53.7 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
53.8 +
53.9 /**
53.10 * The {@code Float} class wraps a value of primitive type
53.11 * {@code float} in an object. An object of type
53.12 @@ -191,8 +193,7 @@
53.13 * @return a string representation of the argument.
53.14 */
53.15 public static String toString(float f) {
53.16 - throw new UnsupportedOperationException();
53.17 -// return new FloatingDecimal(f).toJavaFormatString();
53.18 + return Double.toString(f);
53.19 }
53.20
53.21 /**
53.22 @@ -816,6 +817,18 @@
53.23 * @return the {@code float} floating-point value with the same bit
53.24 * pattern.
53.25 */
53.26 + @JavaScriptBody(args = "bits",
53.27 + body =
53.28 + "if (bits === 0x7f800000) return Number.POSITIVE_INFINITY;\n"
53.29 + + "if (bits === 0xff800000) return Number.NEGATIVE_INFINITY;\n"
53.30 + + "if (bits >= 0x7f800001 && bits <= 0xffffffff) return Number.NaN;\n"
53.31 + + "var s = ((bits >> 31) == 0) ? 1 : -1;\n"
53.32 + + "var e = ((bits >> 23) & 0xff);\n"
53.33 + + "var m = (e == 0) ?\n"
53.34 + + " (bits & 0x7fffff) << 1 :\n"
53.35 + + " (bits & 0x7fffff) | 0x800000;\n"
53.36 + + "return s * m * Math.pow(2.0, e - 150);\n"
53.37 + )
53.38 public static native float intBitsToFloat(int bits);
53.39
53.40 /**
54.1 --- a/emul/src/main/java/java/lang/Integer.java Thu Oct 11 06:15:22 2012 -0700
54.2 +++ b/emul/src/main/java/java/lang/Integer.java Wed Jan 23 20:16:48 2013 +0100
54.3 @@ -25,6 +25,8 @@
54.4
54.5 package java.lang;
54.6
54.7 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
54.8 +
54.9 /**
54.10 * The {@code Integer} class wraps a value of the primitive type
54.11 * {@code int} in an object. An object of type {@code Integer}
54.12 @@ -322,13 +324,14 @@
54.13 * @param i an integer to be converted.
54.14 * @return a string representation of the argument in base 10.
54.15 */
54.16 + @JavaScriptBody(args = "i", body = "return i.toString();")
54.17 public static String toString(int i) {
54.18 if (i == Integer.MIN_VALUE)
54.19 return "-2147483648";
54.20 int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
54.21 char[] buf = new char[size];
54.22 getChars(i, size, buf);
54.23 - return new String(0, size, buf);
54.24 + return new String(buf, 0, size);
54.25 }
54.26
54.27 /**
54.28 @@ -439,6 +442,7 @@
54.29 * @exception NumberFormatException if the {@code String}
54.30 * does not contain a parsable {@code int}.
54.31 */
54.32 + @JavaScriptBody(args={"s", "radix"}, body="return parseInt(s,radix);")
54.33 public static int parseInt(String s, int radix)
54.34 throws NumberFormatException
54.35 {
54.36 @@ -600,7 +604,7 @@
54.37 // high value may be configured by property
54.38 int h = 127;
54.39 String integerCacheHighPropValue =
54.40 - String.getProperty("java.lang.Integer.IntegerCache.high");
54.41 + AbstractStringBuilder.getProperty("java.lang.Integer.IntegerCache.high");
54.42 if (integerCacheHighPropValue != null) {
54.43 int i = parseInt(integerCacheHighPropValue);
54.44 i = Math.max(i, 127);
54.45 @@ -882,7 +886,7 @@
54.46 public static Integer getInteger(String nm, Integer val) {
54.47 String v = null;
54.48 try {
54.49 - v = String.getProperty(nm);
54.50 + v = AbstractStringBuilder.getProperty(nm);
54.51 } catch (IllegalArgumentException e) {
54.52 } catch (NullPointerException e) {
54.53 }
55.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
55.2 +++ b/emul/src/main/java/java/lang/LinkageError.java Wed Jan 23 20:16:48 2013 +0100
55.3 @@ -0,0 +1,69 @@
55.4 +/*
55.5 + * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
55.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55.7 + *
55.8 + * This code is free software; you can redistribute it and/or modify it
55.9 + * under the terms of the GNU General Public License version 2 only, as
55.10 + * published by the Free Software Foundation. Oracle designates this
55.11 + * particular file as subject to the "Classpath" exception as provided
55.12 + * by Oracle in the LICENSE file that accompanied this code.
55.13 + *
55.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
55.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
55.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
55.17 + * version 2 for more details (a copy is included in the LICENSE file that
55.18 + * accompanied this code).
55.19 + *
55.20 + * You should have received a copy of the GNU General Public License version
55.21 + * 2 along with this work; if not, write to the Free Software Foundation,
55.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
55.23 + *
55.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
55.25 + * or visit www.oracle.com if you need additional information or have any
55.26 + * questions.
55.27 + */
55.28 +
55.29 +package java.lang;
55.30 +
55.31 +/**
55.32 + * Subclasses of {@code LinkageError} indicate that a class has
55.33 + * some dependency on another class; however, the latter class has
55.34 + * incompatibly changed after the compilation of the former class.
55.35 + *
55.36 + *
55.37 + * @author Frank Yellin
55.38 + * @since JDK1.0
55.39 + */
55.40 +public
55.41 +class LinkageError extends Error {
55.42 + private static final long serialVersionUID = 3579600108157160122L;
55.43 +
55.44 + /**
55.45 + * Constructs a {@code LinkageError} with no detail message.
55.46 + */
55.47 + public LinkageError() {
55.48 + super();
55.49 + }
55.50 +
55.51 + /**
55.52 + * Constructs a {@code LinkageError} with the specified detail
55.53 + * message.
55.54 + *
55.55 + * @param s the detail message.
55.56 + */
55.57 + public LinkageError(String s) {
55.58 + super(s);
55.59 + }
55.60 +
55.61 + /**
55.62 + * Constructs a {@code LinkageError} with the specified detail
55.63 + * message and cause.
55.64 + *
55.65 + * @param s the detail message.
55.66 + * @param cause the cause, may be {@code null}
55.67 + * @since 1.7
55.68 + */
55.69 + public LinkageError(String s, Throwable cause) {
55.70 + super(s, cause);
55.71 + }
55.72 +}
56.1 --- a/emul/src/main/java/java/lang/Long.java Thu Oct 11 06:15:22 2012 -0700
56.2 +++ b/emul/src/main/java/java/lang/Long.java Wed Jan 23 20:16:48 2013 +0100
56.3 @@ -25,6 +25,8 @@
56.4
56.5 package java.lang;
56.6
56.7 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
56.8 +
56.9 /**
56.10 * The {@code Long} class wraps a value of the primitive type {@code
56.11 * long} in an object. An object of type {@code Long} contains a
56.12 @@ -260,13 +262,14 @@
56.13 * @param i a {@code long} to be converted.
56.14 * @return a string representation of the argument in base 10.
56.15 */
56.16 + @JavaScriptBody(args = "i", body = "return i.toString();")
56.17 public static String toString(long i) {
56.18 if (i == Long.MIN_VALUE)
56.19 return "-9223372036854775808";
56.20 int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
56.21 char[] buf = new char[size];
56.22 getChars(i, size, buf);
56.23 - return new String(0, size, buf);
56.24 + return new String(buf, 0, size);
56.25 }
56.26
56.27 /**
56.28 @@ -923,7 +926,7 @@
56.29 public static Long getLong(String nm, Long val) {
56.30 String v = null;
56.31 try {
56.32 - v = String.getProperty(nm);
56.33 + v = AbstractStringBuilder.getProperty(nm);
56.34 } catch (IllegalArgumentException e) {
56.35 } catch (NullPointerException e) {
56.36 }
57.1 --- a/emul/src/main/java/java/lang/Math.java Thu Oct 11 06:15:22 2012 -0700
57.2 +++ b/emul/src/main/java/java/lang/Math.java Wed Jan 23 20:16:48 2013 +0100
57.3 @@ -25,6 +25,8 @@
57.4
57.5 package java.lang;
57.6
57.7 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
57.8 +
57.9
57.10 /**
57.11 * The class {@code Math} contains methods for performing basic
57.12 @@ -116,8 +118,9 @@
57.13 * @param a an angle, in radians.
57.14 * @return the sine of the argument.
57.15 */
57.16 + @JavaScriptBody(args="a", body="return Math.sin(a);")
57.17 public static double sin(double a) {
57.18 - return StrictMath.sin(a); // default impl. delegates to StrictMath
57.19 + throw new UnsupportedOperationException();
57.20 }
57.21
57.22 /**
57.23 @@ -131,8 +134,9 @@
57.24 * @param a an angle, in radians.
57.25 * @return the cosine of the argument.
57.26 */
57.27 + @JavaScriptBody(args="a", body="return Math.cos(a);")
57.28 public static double cos(double a) {
57.29 - return StrictMath.cos(a); // default impl. delegates to StrictMath
57.30 + throw new UnsupportedOperationException();
57.31 }
57.32
57.33 /**
57.34 @@ -148,8 +152,9 @@
57.35 * @param a an angle, in radians.
57.36 * @return the tangent of the argument.
57.37 */
57.38 + @JavaScriptBody(args="a", body="return Math.tan(a);")
57.39 public static double tan(double a) {
57.40 - return StrictMath.tan(a); // default impl. delegates to StrictMath
57.41 + throw new UnsupportedOperationException();
57.42 }
57.43
57.44 /**
57.45 @@ -166,8 +171,9 @@
57.46 * @param a the value whose arc sine is to be returned.
57.47 * @return the arc sine of the argument.
57.48 */
57.49 + @JavaScriptBody(args="a", body="return Math.asin(a);")
57.50 public static double asin(double a) {
57.51 - return StrictMath.asin(a); // default impl. delegates to StrictMath
57.52 + throw new UnsupportedOperationException();
57.53 }
57.54
57.55 /**
57.56 @@ -182,8 +188,9 @@
57.57 * @param a the value whose arc cosine is to be returned.
57.58 * @return the arc cosine of the argument.
57.59 */
57.60 + @JavaScriptBody(args="a", body="return Math.acos(a);")
57.61 public static double acos(double a) {
57.62 - return StrictMath.acos(a); // default impl. delegates to StrictMath
57.63 + throw new UnsupportedOperationException();
57.64 }
57.65
57.66 /**
57.67 @@ -199,8 +206,9 @@
57.68 * @param a the value whose arc tangent is to be returned.
57.69 * @return the arc tangent of the argument.
57.70 */
57.71 + @JavaScriptBody(args="a", body="return Math.atan(a);")
57.72 public static double atan(double a) {
57.73 - return StrictMath.atan(a); // default impl. delegates to StrictMath
57.74 + throw new UnsupportedOperationException();
57.75 }
57.76
57.77 /**
57.78 @@ -249,8 +257,9 @@
57.79 * @return the value <i>e</i><sup>{@code a}</sup>,
57.80 * where <i>e</i> is the base of the natural logarithms.
57.81 */
57.82 + @JavaScriptBody(args="a", body="return Math.exp(a);")
57.83 public static double exp(double a) {
57.84 - return StrictMath.exp(a); // default impl. delegates to StrictMath
57.85 + throw new UnsupportedOperationException();
57.86 }
57.87
57.88 /**
57.89 @@ -270,8 +279,9 @@
57.90 * @return the value ln {@code a}, the natural logarithm of
57.91 * {@code a}.
57.92 */
57.93 + @JavaScriptBody(args="a", body="return Math.log(a);")
57.94 public static double log(double a) {
57.95 - return StrictMath.log(a); // default impl. delegates to StrictMath
57.96 + throw new UnsupportedOperationException();
57.97 }
57.98
57.99 /**
57.100 @@ -295,8 +305,9 @@
57.101 * @return the base 10 logarithm of {@code a}.
57.102 * @since 1.5
57.103 */
57.104 + @JavaScriptBody(args="a", body="return Math.log(a) / Math.LN10;")
57.105 public static double log10(double a) {
57.106 - return StrictMath.log10(a); // default impl. delegates to StrictMath
57.107 + throw new UnsupportedOperationException();
57.108 }
57.109
57.110 /**
57.111 @@ -316,69 +327,9 @@
57.112 * @return the positive square root of {@code a}.
57.113 * If the argument is NaN or less than zero, the result is NaN.
57.114 */
57.115 + @JavaScriptBody(args="a", body="return Math.sqrt(a);")
57.116 public static double sqrt(double a) {
57.117 - return StrictMath.sqrt(a); // default impl. delegates to StrictMath
57.118 - // Note that hardware sqrt instructions
57.119 - // frequently can be directly used by JITs
57.120 - // and should be much faster than doing
57.121 - // Math.sqrt in software.
57.122 - }
57.123 -
57.124 -
57.125 - /**
57.126 - * Returns the cube root of a {@code double} value. For
57.127 - * positive finite {@code x}, {@code cbrt(-x) ==
57.128 - * -cbrt(x)}; that is, the cube root of a negative value is
57.129 - * the negative of the cube root of that value's magnitude.
57.130 - *
57.131 - * Special cases:
57.132 - *
57.133 - * <ul>
57.134 - *
57.135 - * <li>If the argument is NaN, then the result is NaN.
57.136 - *
57.137 - * <li>If the argument is infinite, then the result is an infinity
57.138 - * with the same sign as the argument.
57.139 - *
57.140 - * <li>If the argument is zero, then the result is a zero with the
57.141 - * same sign as the argument.
57.142 - *
57.143 - * </ul>
57.144 - *
57.145 - * <p>The computed result must be within 1 ulp of the exact result.
57.146 - *
57.147 - * @param a a value.
57.148 - * @return the cube root of {@code a}.
57.149 - * @since 1.5
57.150 - */
57.151 - public static double cbrt(double a) {
57.152 - return StrictMath.cbrt(a);
57.153 - }
57.154 -
57.155 - /**
57.156 - * Computes the remainder operation on two arguments as prescribed
57.157 - * by the IEEE 754 standard.
57.158 - * The remainder value is mathematically equal to
57.159 - * <code>f1 - f2</code> × <i>n</i>,
57.160 - * where <i>n</i> is the mathematical integer closest to the exact
57.161 - * mathematical value of the quotient {@code f1/f2}, and if two
57.162 - * mathematical integers are equally close to {@code f1/f2},
57.163 - * then <i>n</i> is the integer that is even. If the remainder is
57.164 - * zero, its sign is the same as the sign of the first argument.
57.165 - * Special cases:
57.166 - * <ul><li>If either argument is NaN, or the first argument is infinite,
57.167 - * or the second argument is positive zero or negative zero, then the
57.168 - * result is NaN.
57.169 - * <li>If the first argument is finite and the second argument is
57.170 - * infinite, then the result is the same as the first argument.</ul>
57.171 - *
57.172 - * @param f1 the dividend.
57.173 - * @param f2 the divisor.
57.174 - * @return the remainder when {@code f1} is divided by
57.175 - * {@code f2}.
57.176 - */
57.177 - public static double IEEEremainder(double f1, double f2) {
57.178 - return StrictMath.IEEEremainder(f1, f2); // delegate to StrictMath
57.179 + throw new UnsupportedOperationException();
57.180 }
57.181
57.182 /**
57.183 @@ -400,8 +351,9 @@
57.184 * floating-point value that is greater than or equal to
57.185 * the argument and is equal to a mathematical integer.
57.186 */
57.187 + @JavaScriptBody(args="a", body="return Math.ceil(a);")
57.188 public static double ceil(double a) {
57.189 - return StrictMath.ceil(a); // default impl. delegates to StrictMath
57.190 + throw new UnsupportedOperationException();
57.191 }
57.192
57.193 /**
57.194 @@ -419,27 +371,9 @@
57.195 * floating-point value that less than or equal to the argument
57.196 * and is equal to a mathematical integer.
57.197 */
57.198 + @JavaScriptBody(args="a", body="return Math.floor(a);")
57.199 public static double floor(double a) {
57.200 - return StrictMath.floor(a); // default impl. delegates to StrictMath
57.201 - }
57.202 -
57.203 - /**
57.204 - * Returns the {@code double} value that is closest in value
57.205 - * to the argument and is equal to a mathematical integer. If two
57.206 - * {@code double} values that are mathematical integers are
57.207 - * equally close, the result is the integer value that is
57.208 - * even. Special cases:
57.209 - * <ul><li>If the argument value is already equal to a mathematical
57.210 - * integer, then the result is the same as the argument.
57.211 - * <li>If the argument is NaN or an infinity or positive zero or negative
57.212 - * zero, then the result is the same as the argument.</ul>
57.213 - *
57.214 - * @param a a {@code double} value.
57.215 - * @return the closest floating-point value to {@code a} that is
57.216 - * equal to a mathematical integer.
57.217 - */
57.218 - public static double rint(double a) {
57.219 - return StrictMath.rint(a); // default impl. delegates to StrictMath
57.220 + throw new UnsupportedOperationException();
57.221 }
57.222
57.223 /**
57.224 @@ -494,8 +428,9 @@
57.225 * in polar coordinates that corresponds to the point
57.226 * (<i>x</i>, <i>y</i>) in Cartesian coordinates.
57.227 */
57.228 + @JavaScriptBody(args={"y", "x"}, body="return Math.atan2(y, x);")
57.229 public static double atan2(double y, double x) {
57.230 - return StrictMath.atan2(y, x); // default impl. delegates to StrictMath
57.231 + throw new UnsupportedOperationException();
57.232 }
57.233
57.234 /**
57.235 @@ -621,8 +556,9 @@
57.236 * @param b the exponent.
57.237 * @return the value {@code a}<sup>{@code b}</sup>.
57.238 */
57.239 + @JavaScriptBody(args={"a", "b"}, body="return Math.pow(a, b);")
57.240 public static double pow(double a, double b) {
57.241 - return StrictMath.pow(a, b); // default impl. delegates to StrictMath
57.242 + throw new UnsupportedOperationException();
57.243 }
57.244
57.245 /**
57.246 @@ -645,11 +581,9 @@
57.247 * @see java.lang.Integer#MAX_VALUE
57.248 * @see java.lang.Integer#MIN_VALUE
57.249 */
57.250 + @JavaScriptBody(args="a", body="return Math.round(a);")
57.251 public static int round(float a) {
57.252 - if (a != 0x1.fffffep-2f) // greatest float value less than 0.5
57.253 - return (int)floor(a + 0.5f);
57.254 - else
57.255 - return 0;
57.256 + throw new UnsupportedOperationException();
57.257 }
57.258
57.259 /**
57.260 @@ -672,11 +606,9 @@
57.261 * @see java.lang.Long#MAX_VALUE
57.262 * @see java.lang.Long#MIN_VALUE
57.263 */
57.264 + @JavaScriptBody(args="a", body="return Math.round(a);")
57.265 public static long round(double a) {
57.266 - if (a != 0x1.fffffffffffffp-2) // greatest double value less than 0.5
57.267 - return (long)floor(a + 0.5d);
57.268 - else
57.269 - return 0;
57.270 + throw new UnsupportedOperationException();
57.271 }
57.272
57.273 // private static Random randomNumberGenerator;
57.274 @@ -709,6 +641,7 @@
57.275 * to {@code 0.0} and less than {@code 1.0}.
57.276 * @see Random#nextDouble()
57.277 */
57.278 + @JavaScriptBody(args={}, body="return Math.random();")
57.279 public static double random() {
57.280 throw new UnsupportedOperationException();
57.281 }
57.282 @@ -813,9 +746,6 @@
57.283 return (a >= b) ? a : b;
57.284 }
57.285
57.286 - private static long negativeZeroFloatBits = Float.floatToIntBits(-0.0f);
57.287 - private static long negativeZeroDoubleBits = Double.doubleToLongBits(-0.0d);
57.288 -
57.289 /**
57.290 * Returns the greater of two {@code float} values. That is,
57.291 * the result is the argument closer to positive infinity. If the
57.292 @@ -830,13 +760,11 @@
57.293 * @param b another argument.
57.294 * @return the larger of {@code a} and {@code b}.
57.295 */
57.296 + @JavaScriptBody(args={"a", "b"},
57.297 + body="return Math.max(a,b);"
57.298 + )
57.299 public static float max(float a, float b) {
57.300 - if (a != a) return a; // a is NaN
57.301 - if ((a == 0.0f) && (b == 0.0f)
57.302 - && (Float.floatToIntBits(a) == negativeZeroFloatBits)) {
57.303 - return b;
57.304 - }
57.305 - return (a >= b) ? a : b;
57.306 + throw new UnsupportedOperationException();
57.307 }
57.308
57.309 /**
57.310 @@ -853,13 +781,11 @@
57.311 * @param b another argument.
57.312 * @return the larger of {@code a} and {@code b}.
57.313 */
57.314 + @JavaScriptBody(args={"a", "b"},
57.315 + body="return Math.max(a,b);"
57.316 + )
57.317 public static double max(double a, double b) {
57.318 - if (a != a) return a; // a is NaN
57.319 - if ((a == 0.0d) && (b == 0.0d)
57.320 - && (Double.doubleToLongBits(a) == negativeZeroDoubleBits)) {
57.321 - return b;
57.322 - }
57.323 - return (a >= b) ? a : b;
57.324 + throw new UnsupportedOperationException();
57.325 }
57.326
57.327 /**
57.328 @@ -904,13 +830,11 @@
57.329 * @param b another argument.
57.330 * @return the smaller of {@code a} and {@code b}.
57.331 */
57.332 + @JavaScriptBody(args={"a", "b"},
57.333 + body="return Math.min(a,b);"
57.334 + )
57.335 public static float min(float a, float b) {
57.336 - if (a != a) return a; // a is NaN
57.337 - if ((a == 0.0f) && (b == 0.0f)
57.338 - && (Float.floatToIntBits(b) == negativeZeroFloatBits)) {
57.339 - return b;
57.340 - }
57.341 - return (a <= b) ? a : b;
57.342 + throw new UnsupportedOperationException();
57.343 }
57.344
57.345 /**
57.346 @@ -927,13 +851,11 @@
57.347 * @param b another argument.
57.348 * @return the smaller of {@code a} and {@code b}.
57.349 */
57.350 + @JavaScriptBody(args={"a", "b"},
57.351 + body="return Math.min(a,b);"
57.352 + )
57.353 public static double min(double a, double b) {
57.354 - if (a != a) return a; // a is NaN
57.355 - if ((a == 0.0d) && (b == 0.0d)
57.356 - && (Double.doubleToLongBits(b) == negativeZeroDoubleBits)) {
57.357 - return b;
57.358 - }
57.359 - return (a <= b) ? a : b;
57.360 + throw new UnsupportedOperationException();
57.361 }
57.362
57.363 /**
57.364 @@ -1033,207 +955,6 @@
57.365 // }
57.366
57.367 /**
57.368 - * Returns the hyperbolic sine of a {@code double} value.
57.369 - * The hyperbolic sine of <i>x</i> is defined to be
57.370 - * (<i>e<sup>x</sup> - e<sup>-x</sup></i>)/2
57.371 - * where <i>e</i> is {@linkplain Math#E Euler's number}.
57.372 - *
57.373 - * <p>Special cases:
57.374 - * <ul>
57.375 - *
57.376 - * <li>If the argument is NaN, then the result is NaN.
57.377 - *
57.378 - * <li>If the argument is infinite, then the result is an infinity
57.379 - * with the same sign as the argument.
57.380 - *
57.381 - * <li>If the argument is zero, then the result is a zero with the
57.382 - * same sign as the argument.
57.383 - *
57.384 - * </ul>
57.385 - *
57.386 - * <p>The computed result must be within 2.5 ulps of the exact result.
57.387 - *
57.388 - * @param x The number whose hyperbolic sine is to be returned.
57.389 - * @return The hyperbolic sine of {@code x}.
57.390 - * @since 1.5
57.391 - */
57.392 - public static double sinh(double x) {
57.393 - return StrictMath.sinh(x);
57.394 - }
57.395 -
57.396 - /**
57.397 - * Returns the hyperbolic cosine of a {@code double} value.
57.398 - * The hyperbolic cosine of <i>x</i> is defined to be
57.399 - * (<i>e<sup>x</sup> + e<sup>-x</sup></i>)/2
57.400 - * where <i>e</i> is {@linkplain Math#E Euler's number}.
57.401 - *
57.402 - * <p>Special cases:
57.403 - * <ul>
57.404 - *
57.405 - * <li>If the argument is NaN, then the result is NaN.
57.406 - *
57.407 - * <li>If the argument is infinite, then the result is positive
57.408 - * infinity.
57.409 - *
57.410 - * <li>If the argument is zero, then the result is {@code 1.0}.
57.411 - *
57.412 - * </ul>
57.413 - *
57.414 - * <p>The computed result must be within 2.5 ulps of the exact result.
57.415 - *
57.416 - * @param x The number whose hyperbolic cosine is to be returned.
57.417 - * @return The hyperbolic cosine of {@code x}.
57.418 - * @since 1.5
57.419 - */
57.420 - public static double cosh(double x) {
57.421 - return StrictMath.cosh(x);
57.422 - }
57.423 -
57.424 - /**
57.425 - * Returns the hyperbolic tangent of a {@code double} value.
57.426 - * The hyperbolic tangent of <i>x</i> is defined to be
57.427 - * (<i>e<sup>x</sup> - e<sup>-x</sup></i>)/(<i>e<sup>x</sup> + e<sup>-x</sup></i>),
57.428 - * in other words, {@linkplain Math#sinh
57.429 - * sinh(<i>x</i>)}/{@linkplain Math#cosh cosh(<i>x</i>)}. Note
57.430 - * that the absolute value of the exact tanh is always less than
57.431 - * 1.
57.432 - *
57.433 - * <p>Special cases:
57.434 - * <ul>
57.435 - *
57.436 - * <li>If the argument is NaN, then the result is NaN.
57.437 - *
57.438 - * <li>If the argument is zero, then the result is a zero with the
57.439 - * same sign as the argument.
57.440 - *
57.441 - * <li>If the argument is positive infinity, then the result is
57.442 - * {@code +1.0}.
57.443 - *
57.444 - * <li>If the argument is negative infinity, then the result is
57.445 - * {@code -1.0}.
57.446 - *
57.447 - * </ul>
57.448 - *
57.449 - * <p>The computed result must be within 2.5 ulps of the exact result.
57.450 - * The result of {@code tanh} for any finite input must have
57.451 - * an absolute value less than or equal to 1. Note that once the
57.452 - * exact result of tanh is within 1/2 of an ulp of the limit value
57.453 - * of ±1, correctly signed ±{@code 1.0} should
57.454 - * be returned.
57.455 - *
57.456 - * @param x The number whose hyperbolic tangent is to be returned.
57.457 - * @return The hyperbolic tangent of {@code x}.
57.458 - * @since 1.5
57.459 - */
57.460 - public static double tanh(double x) {
57.461 - return StrictMath.tanh(x);
57.462 - }
57.463 -
57.464 - /**
57.465 - * Returns sqrt(<i>x</i><sup>2</sup> +<i>y</i><sup>2</sup>)
57.466 - * without intermediate overflow or underflow.
57.467 - *
57.468 - * <p>Special cases:
57.469 - * <ul>
57.470 - *
57.471 - * <li> If either argument is infinite, then the result
57.472 - * is positive infinity.
57.473 - *
57.474 - * <li> If either argument is NaN and neither argument is infinite,
57.475 - * then the result is NaN.
57.476 - *
57.477 - * </ul>
57.478 - *
57.479 - * <p>The computed result must be within 1 ulp of the exact
57.480 - * result. If one parameter is held constant, the results must be
57.481 - * semi-monotonic in the other parameter.
57.482 - *
57.483 - * @param x a value
57.484 - * @param y a value
57.485 - * @return sqrt(<i>x</i><sup>2</sup> +<i>y</i><sup>2</sup>)
57.486 - * without intermediate overflow or underflow
57.487 - * @since 1.5
57.488 - */
57.489 - public static double hypot(double x, double y) {
57.490 - return StrictMath.hypot(x, y);
57.491 - }
57.492 -
57.493 - /**
57.494 - * Returns <i>e</i><sup>x</sup> -1. Note that for values of
57.495 - * <i>x</i> near 0, the exact sum of
57.496 - * {@code expm1(x)} + 1 is much closer to the true
57.497 - * result of <i>e</i><sup>x</sup> than {@code exp(x)}.
57.498 - *
57.499 - * <p>Special cases:
57.500 - * <ul>
57.501 - * <li>If the argument is NaN, the result is NaN.
57.502 - *
57.503 - * <li>If the argument is positive infinity, then the result is
57.504 - * positive infinity.
57.505 - *
57.506 - * <li>If the argument is negative infinity, then the result is
57.507 - * -1.0.
57.508 - *
57.509 - * <li>If the argument is zero, then the result is a zero with the
57.510 - * same sign as the argument.
57.511 - *
57.512 - * </ul>
57.513 - *
57.514 - * <p>The computed result must be within 1 ulp of the exact result.
57.515 - * Results must be semi-monotonic. The result of
57.516 - * {@code expm1} for any finite input must be greater than or
57.517 - * equal to {@code -1.0}. Note that once the exact result of
57.518 - * <i>e</i><sup>{@code x}</sup> - 1 is within 1/2
57.519 - * ulp of the limit value -1, {@code -1.0} should be
57.520 - * returned.
57.521 - *
57.522 - * @param x the exponent to raise <i>e</i> to in the computation of
57.523 - * <i>e</i><sup>{@code x}</sup> -1.
57.524 - * @return the value <i>e</i><sup>{@code x}</sup> - 1.
57.525 - * @since 1.5
57.526 - */
57.527 - public static double expm1(double x) {
57.528 - return StrictMath.expm1(x);
57.529 - }
57.530 -
57.531 - /**
57.532 - * Returns the natural logarithm of the sum of the argument and 1.
57.533 - * Note that for small values {@code x}, the result of
57.534 - * {@code log1p(x)} is much closer to the true result of ln(1
57.535 - * + {@code x}) than the floating-point evaluation of
57.536 - * {@code log(1.0+x)}.
57.537 - *
57.538 - * <p>Special cases:
57.539 - *
57.540 - * <ul>
57.541 - *
57.542 - * <li>If the argument is NaN or less than -1, then the result is
57.543 - * NaN.
57.544 - *
57.545 - * <li>If the argument is positive infinity, then the result is
57.546 - * positive infinity.
57.547 - *
57.548 - * <li>If the argument is negative one, then the result is
57.549 - * negative infinity.
57.550 - *
57.551 - * <li>If the argument is zero, then the result is a zero with the
57.552 - * same sign as the argument.
57.553 - *
57.554 - * </ul>
57.555 - *
57.556 - * <p>The computed result must be within 1 ulp of the exact result.
57.557 - * Results must be semi-monotonic.
57.558 - *
57.559 - * @param x a value
57.560 - * @return the value ln({@code x} + 1), the natural
57.561 - * log of {@code x} + 1
57.562 - * @since 1.5
57.563 - */
57.564 - public static double log1p(double x) {
57.565 - return StrictMath.log1p(x);
57.566 - }
57.567 -
57.568 - /**
57.569 * Returns the first floating-point argument with the sign of the
57.570 * second floating-point argument. Note that unlike the {@link
57.571 * StrictMath#copySign(double, double) StrictMath.copySign}
58.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
58.2 +++ b/emul/src/main/java/java/lang/NegativeArraySizeException.java Wed Jan 23 20:16:48 2013 +0100
58.3 @@ -0,0 +1,55 @@
58.4 +/*
58.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
58.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
58.7 + *
58.8 + * This code is free software; you can redistribute it and/or modify it
58.9 + * under the terms of the GNU General Public License version 2 only, as
58.10 + * published by the Free Software Foundation. Oracle designates this
58.11 + * particular file as subject to the "Classpath" exception as provided
58.12 + * by Oracle in the LICENSE file that accompanied this code.
58.13 + *
58.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
58.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
58.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
58.17 + * version 2 for more details (a copy is included in the LICENSE file that
58.18 + * accompanied this code).
58.19 + *
58.20 + * You should have received a copy of the GNU General Public License version
58.21 + * 2 along with this work; if not, write to the Free Software Foundation,
58.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
58.23 + *
58.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
58.25 + * or visit www.oracle.com if you need additional information or have any
58.26 + * questions.
58.27 + */
58.28 +
58.29 +package java.lang;
58.30 +
58.31 +/**
58.32 + * Thrown if an application tries to create an array with negative size.
58.33 + *
58.34 + * @author unascribed
58.35 + * @since JDK1.0
58.36 + */
58.37 +public
58.38 +class NegativeArraySizeException extends RuntimeException {
58.39 + private static final long serialVersionUID = -8960118058596991861L;
58.40 +
58.41 + /**
58.42 + * Constructs a <code>NegativeArraySizeException</code> with no
58.43 + * detail message.
58.44 + */
58.45 + public NegativeArraySizeException() {
58.46 + super();
58.47 + }
58.48 +
58.49 + /**
58.50 + * Constructs a <code>NegativeArraySizeException</code> with the
58.51 + * specified detail message.
58.52 + *
58.53 + * @param s the detail message.
58.54 + */
58.55 + public NegativeArraySizeException(String s) {
58.56 + super(s);
58.57 + }
58.58 +}
59.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
59.2 +++ b/emul/src/main/java/java/lang/NoSuchMethodException.java Wed Jan 23 20:16:48 2013 +0100
59.3 @@ -0,0 +1,53 @@
59.4 +/*
59.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
59.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
59.7 + *
59.8 + * This code is free software; you can redistribute it and/or modify it
59.9 + * under the terms of the GNU General Public License version 2 only, as
59.10 + * published by the Free Software Foundation. Oracle designates this
59.11 + * particular file as subject to the "Classpath" exception as provided
59.12 + * by Oracle in the LICENSE file that accompanied this code.
59.13 + *
59.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
59.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
59.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
59.17 + * version 2 for more details (a copy is included in the LICENSE file that
59.18 + * accompanied this code).
59.19 + *
59.20 + * You should have received a copy of the GNU General Public License version
59.21 + * 2 along with this work; if not, write to the Free Software Foundation,
59.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
59.23 + *
59.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
59.25 + * or visit www.oracle.com if you need additional information or have any
59.26 + * questions.
59.27 + */
59.28 +
59.29 +package java.lang;
59.30 +
59.31 +/**
59.32 + * Thrown when a particular method cannot be found.
59.33 + *
59.34 + * @author unascribed
59.35 + * @since JDK1.0
59.36 + */
59.37 +public
59.38 +class NoSuchMethodException extends ReflectiveOperationException {
59.39 + private static final long serialVersionUID = 5034388446362600923L;
59.40 +
59.41 + /**
59.42 + * Constructs a <code>NoSuchMethodException</code> without a detail message.
59.43 + */
59.44 + public NoSuchMethodException() {
59.45 + super();
59.46 + }
59.47 +
59.48 + /**
59.49 + * Constructs a <code>NoSuchMethodException</code> with a detail message.
59.50 + *
59.51 + * @param s the detail message.
59.52 + */
59.53 + public NoSuchMethodException(String s) {
59.54 + super(s);
59.55 + }
59.56 +}
60.1 --- a/emul/src/main/java/java/lang/Number.java Thu Oct 11 06:15:22 2012 -0700
60.2 +++ b/emul/src/main/java/java/lang/Number.java Wed Jan 23 20:16:48 2013 +0100
60.3 @@ -25,6 +25,8 @@
60.4
60.5 package java.lang;
60.6
60.7 +import org.apidesign.bck2brwsr.core.ExtraJavaScript;
60.8 +
60.9 /**
60.10 * The abstract class <code>Number</code> is the superclass of classes
60.11 * <code>BigDecimal</code>, <code>BigInteger</code>,
60.12 @@ -46,6 +48,10 @@
60.13 * @see java.lang.Short
60.14 * @since JDK1.0
60.15 */
60.16 +@ExtraJavaScript(
60.17 + resource="/org/apidesign/vm4brwsr/emul/java_lang_Number.js",
60.18 + processByteCode=true
60.19 +)
60.20 public abstract class Number implements java.io.Serializable {
60.21 /**
60.22 * Returns the value of the specified number as an <code>int</code>.
61.1 --- a/emul/src/main/java/java/lang/Object.java Thu Oct 11 06:15:22 2012 -0700
61.2 +++ b/emul/src/main/java/java/lang/Object.java Wed Jan 23 20:16:48 2013 +0100
61.3 @@ -25,6 +25,10 @@
61.4
61.5 package java.lang;
61.6
61.7 +import java.lang.reflect.Array;
61.8 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
61.9 +import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
61.10 +
61.11 /**
61.12 * Class {@code Object} is the root of the class hierarchy.
61.13 * Every class has {@code Object} as a superclass. All objects,
61.14 @@ -34,9 +38,16 @@
61.15 * @see java.lang.Class
61.16 * @since JDK1.0
61.17 */
61.18 +@JavaScriptPrototype(container = "Object.prototype", prototype = "new Object")
61.19 public class Object {
61.20
61.21 - private static native void registerNatives();
61.22 + private static void registerNatives() {
61.23 + try {
61.24 + Array.get(null, 0);
61.25 + } catch (Throwable ex) {
61.26 + // ignore
61.27 + }
61.28 + }
61.29 static {
61.30 registerNatives();
61.31 }
61.32 @@ -61,6 +72,7 @@
61.33 * @see Class Literals, section 15.8.2 of
61.34 * <cite>The Java™ Language Specification</cite>.
61.35 */
61.36 + @JavaScriptBody(args={}, body="return this.constructor.$class;")
61.37 public final native Class<?> getClass();
61.38
61.39 /**
61.40 @@ -98,8 +110,16 @@
61.41 * @see java.lang.Object#equals(java.lang.Object)
61.42 * @see java.lang.System#identityHashCode
61.43 */
61.44 + @JavaScriptBody(args = {}, body =
61.45 + "if (this.$hashCode) return this.$hashCode;\n"
61.46 + + "var h = this.computeHashCode__I();\n"
61.47 + + "return this.$hashCode = h & h;"
61.48 + )
61.49 public native int hashCode();
61.50
61.51 + @JavaScriptBody(args = {}, body = "Math.random() * Math.pow(2, 32);")
61.52 + native int computeHashCode();
61.53 +
61.54 /**
61.55 * Indicates whether some other object is "equal to" this one.
61.56 * <p>
61.57 @@ -210,7 +230,28 @@
61.58 * be cloned.
61.59 * @see java.lang.Cloneable
61.60 */
61.61 - protected native Object clone() throws CloneNotSupportedException;
61.62 + protected Object clone() throws CloneNotSupportedException {
61.63 + Object ret = clone(this);
61.64 + if (ret == null) {
61.65 + throw new CloneNotSupportedException(getClass().getName());
61.66 + }
61.67 + return ret;
61.68 + }
61.69 +
61.70 + @JavaScriptBody(args = "self", body =
61.71 + "\nif (!self.$instOf_java_lang_Cloneable) {"
61.72 + + "\n return null;"
61.73 + + "\n} else {"
61.74 + + "\n var clone = self.constructor(true);"
61.75 + + "\n var props = Object.getOwnPropertyNames(self);"
61.76 + + "\n for (var i = 0; i < props.length; i++) {"
61.77 + + "\n var p = props[i];"
61.78 + + "\n clone[p] = self[p];"
61.79 + + "\n };"
61.80 + + "\n return clone;"
61.81 + + "\n}"
61.82 + )
61.83 + private static native Object clone(Object self) throws CloneNotSupportedException;
61.84
61.85 /**
61.86 * Returns a string representation of the object. In general, the
62.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
62.2 +++ b/emul/src/main/java/java/lang/Runnable.java Wed Jan 23 20:16:48 2013 +0100
62.3 @@ -0,0 +1,69 @@
62.4 +/*
62.5 + * Copyright (c) 1994, 2005, Oracle and/or its affiliates. All rights reserved.
62.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
62.7 + *
62.8 + * This code is free software; you can redistribute it and/or modify it
62.9 + * under the terms of the GNU General Public License version 2 only, as
62.10 + * published by the Free Software Foundation. Oracle designates this
62.11 + * particular file as subject to the "Classpath" exception as provided
62.12 + * by Oracle in the LICENSE file that accompanied this code.
62.13 + *
62.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
62.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
62.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
62.17 + * version 2 for more details (a copy is included in the LICENSE file that
62.18 + * accompanied this code).
62.19 + *
62.20 + * You should have received a copy of the GNU General Public License version
62.21 + * 2 along with this work; if not, write to the Free Software Foundation,
62.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
62.23 + *
62.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
62.25 + * or visit www.oracle.com if you need additional information or have any
62.26 + * questions.
62.27 + */
62.28 +
62.29 +package java.lang;
62.30 +
62.31 +/**
62.32 + * The <code>Runnable</code> interface should be implemented by any
62.33 + * class whose instances are intended to be executed by a thread. The
62.34 + * class must define a method of no arguments called <code>run</code>.
62.35 + * <p>
62.36 + * This interface is designed to provide a common protocol for objects that
62.37 + * wish to execute code while they are active. For example,
62.38 + * <code>Runnable</code> is implemented by class <code>Thread</code>.
62.39 + * Being active simply means that a thread has been started and has not
62.40 + * yet been stopped.
62.41 + * <p>
62.42 + * In addition, <code>Runnable</code> provides the means for a class to be
62.43 + * active while not subclassing <code>Thread</code>. A class that implements
62.44 + * <code>Runnable</code> can run without subclassing <code>Thread</code>
62.45 + * by instantiating a <code>Thread</code> instance and passing itself in
62.46 + * as the target. In most cases, the <code>Runnable</code> interface should
62.47 + * be used if you are only planning to override the <code>run()</code>
62.48 + * method and no other <code>Thread</code> methods.
62.49 + * This is important because classes should not be subclassed
62.50 + * unless the programmer intends on modifying or enhancing the fundamental
62.51 + * behavior of the class.
62.52 + *
62.53 + * @author Arthur van Hoff
62.54 + * @see java.lang.Thread
62.55 + * @see java.util.concurrent.Callable
62.56 + * @since JDK1.0
62.57 + */
62.58 +public
62.59 +interface Runnable {
62.60 + /**
62.61 + * When an object implementing interface <code>Runnable</code> is used
62.62 + * to create a thread, starting the thread causes the object's
62.63 + * <code>run</code> method to be called in that separately executing
62.64 + * thread.
62.65 + * <p>
62.66 + * The general contract of the method <code>run</code> is that it may
62.67 + * take any action whatsoever.
62.68 + *
62.69 + * @see java.lang.Thread#run()
62.70 + */
62.71 + public abstract void run();
62.72 +}
63.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
63.2 +++ b/emul/src/main/java/java/lang/SecurityException.java Wed Jan 23 20:16:48 2013 +0100
63.3 @@ -0,0 +1,84 @@
63.4 +/*
63.5 + * Copyright (c) 1995, 2003, Oracle and/or its affiliates. All rights reserved.
63.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
63.7 + *
63.8 + * This code is free software; you can redistribute it and/or modify it
63.9 + * under the terms of the GNU General Public License version 2 only, as
63.10 + * published by the Free Software Foundation. Oracle designates this
63.11 + * particular file as subject to the "Classpath" exception as provided
63.12 + * by Oracle in the LICENSE file that accompanied this code.
63.13 + *
63.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
63.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
63.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
63.17 + * version 2 for more details (a copy is included in the LICENSE file that
63.18 + * accompanied this code).
63.19 + *
63.20 + * You should have received a copy of the GNU General Public License version
63.21 + * 2 along with this work; if not, write to the Free Software Foundation,
63.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
63.23 + *
63.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
63.25 + * or visit www.oracle.com if you need additional information or have any
63.26 + * questions.
63.27 + */
63.28 +package java.lang;
63.29 +
63.30 +/**
63.31 + * Thrown by the security manager to indicate a security violation.
63.32 + *
63.33 + * @author unascribed
63.34 + * @see java.lang.SecurityManager
63.35 + * @since JDK1.0
63.36 + */
63.37 +public class SecurityException extends RuntimeException {
63.38 +
63.39 + private static final long serialVersionUID = 6878364983674394167L;
63.40 +
63.41 + /**
63.42 + * Constructs a <code>SecurityException</code> with no detail message.
63.43 + */
63.44 + public SecurityException() {
63.45 + super();
63.46 + }
63.47 +
63.48 + /**
63.49 + * Constructs a <code>SecurityException</code> with the specified
63.50 + * detail message.
63.51 + *
63.52 + * @param s the detail message.
63.53 + */
63.54 + public SecurityException(String s) {
63.55 + super(s);
63.56 + }
63.57 +
63.58 + /**
63.59 + * Creates a <code>SecurityException</code> with the specified
63.60 + * detail message and cause.
63.61 + *
63.62 + * @param message the detail message (which is saved for later retrieval
63.63 + * by the {@link #getMessage()} method).
63.64 + * @param cause the cause (which is saved for later retrieval by the
63.65 + * {@link #getCause()} method). (A <tt>null</tt> value is permitted,
63.66 + * and indicates that the cause is nonexistent or unknown.)
63.67 + * @since 1.5
63.68 + */
63.69 + public SecurityException(String message, Throwable cause) {
63.70 + super(message, cause);
63.71 + }
63.72 +
63.73 + /**
63.74 + * Creates a <code>SecurityException</code> with the specified cause
63.75 + * and a detail message of <tt>(cause==null ? null : cause.toString())</tt>
63.76 + * (which typically contains the class and detail message of
63.77 + * <tt>cause</tt>).
63.78 + *
63.79 + * @param cause the cause (which is saved for later retrieval by the
63.80 + * {@link #getCause()} method). (A <tt>null</tt> value is permitted,
63.81 + * and indicates that the cause is nonexistent or unknown.)
63.82 + * @since 1.5
63.83 + */
63.84 + public SecurityException(Throwable cause) {
63.85 + super(cause);
63.86 + }
63.87 +}
64.1 --- a/emul/src/main/java/java/lang/StrictMath.java Thu Oct 11 06:15:22 2012 -0700
64.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
64.3 @@ -1,1457 +0,0 @@
64.4 -/*
64.5 - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
64.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
64.7 - *
64.8 - * This code is free software; you can redistribute it and/or modify it
64.9 - * under the terms of the GNU General Public License version 2 only, as
64.10 - * published by the Free Software Foundation. Oracle designates this
64.11 - * particular file as subject to the "Classpath" exception as provided
64.12 - * by Oracle in the LICENSE file that accompanied this code.
64.13 - *
64.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
64.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
64.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
64.17 - * version 2 for more details (a copy is included in the LICENSE file that
64.18 - * accompanied this code).
64.19 - *
64.20 - * You should have received a copy of the GNU General Public License version
64.21 - * 2 along with this work; if not, write to the Free Software Foundation,
64.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
64.23 - *
64.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
64.25 - * or visit www.oracle.com if you need additional information or have any
64.26 - * questions.
64.27 - */
64.28 -
64.29 -package java.lang;
64.30 -
64.31 -/**
64.32 - * The class {@code StrictMath} contains methods for performing basic
64.33 - * numeric operations such as the elementary exponential, logarithm,
64.34 - * square root, and trigonometric functions.
64.35 - *
64.36 - * <p>To help ensure portability of Java programs, the definitions of
64.37 - * some of the numeric functions in this package require that they
64.38 - * produce the same results as certain published algorithms. These
64.39 - * algorithms are available from the well-known network library
64.40 - * {@code netlib} as the package "Freely Distributable Math
64.41 - * Library," <a
64.42 - * href="ftp://ftp.netlib.org/fdlibm.tar">{@code fdlibm}</a>. These
64.43 - * algorithms, which are written in the C programming language, are
64.44 - * then to be understood as executed with all floating-point
64.45 - * operations following the rules of Java floating-point arithmetic.
64.46 - *
64.47 - * <p>The Java math library is defined with respect to
64.48 - * {@code fdlibm} version 5.3. Where {@code fdlibm} provides
64.49 - * more than one definition for a function (such as
64.50 - * {@code acos}), use the "IEEE 754 core function" version
64.51 - * (residing in a file whose name begins with the letter
64.52 - * {@code e}). The methods which require {@code fdlibm}
64.53 - * semantics are {@code sin}, {@code cos}, {@code tan},
64.54 - * {@code asin}, {@code acos}, {@code atan},
64.55 - * {@code exp}, {@code log}, {@code log10},
64.56 - * {@code cbrt}, {@code atan2}, {@code pow},
64.57 - * {@code sinh}, {@code cosh}, {@code tanh},
64.58 - * {@code hypot}, {@code expm1}, and {@code log1p}.
64.59 - *
64.60 - * @author unascribed
64.61 - * @author Joseph D. Darcy
64.62 - * @since 1.3
64.63 - */
64.64 -
64.65 -public final class StrictMath {
64.66 -
64.67 - /**
64.68 - * Don't let anyone instantiate this class.
64.69 - */
64.70 - private StrictMath() {}
64.71 -
64.72 - /**
64.73 - * The {@code double} value that is closer than any other to
64.74 - * <i>e</i>, the base of the natural logarithms.
64.75 - */
64.76 - public static final double E = 2.7182818284590452354;
64.77 -
64.78 - /**
64.79 - * The {@code double} value that is closer than any other to
64.80 - * <i>pi</i>, the ratio of the circumference of a circle to its
64.81 - * diameter.
64.82 - */
64.83 - public static final double PI = 3.14159265358979323846;
64.84 -
64.85 - /**
64.86 - * Returns the trigonometric sine of an angle. Special cases:
64.87 - * <ul><li>If the argument is NaN or an infinity, then the
64.88 - * result is NaN.
64.89 - * <li>If the argument is zero, then the result is a zero with the
64.90 - * same sign as the argument.</ul>
64.91 - *
64.92 - * @param a an angle, in radians.
64.93 - * @return the sine of the argument.
64.94 - */
64.95 - public static native double sin(double a);
64.96 -
64.97 - /**
64.98 - * Returns the trigonometric cosine of an angle. Special cases:
64.99 - * <ul><li>If the argument is NaN or an infinity, then the
64.100 - * result is NaN.</ul>
64.101 - *
64.102 - * @param a an angle, in radians.
64.103 - * @return the cosine of the argument.
64.104 - */
64.105 - public static native double cos(double a);
64.106 -
64.107 - /**
64.108 - * Returns the trigonometric tangent of an angle. Special cases:
64.109 - * <ul><li>If the argument is NaN or an infinity, then the result
64.110 - * is NaN.
64.111 - * <li>If the argument is zero, then the result is a zero with the
64.112 - * same sign as the argument.</ul>
64.113 - *
64.114 - * @param a an angle, in radians.
64.115 - * @return the tangent of the argument.
64.116 - */
64.117 - public static native double tan(double a);
64.118 -
64.119 - /**
64.120 - * Returns the arc sine of a value; the returned angle is in the
64.121 - * range -<i>pi</i>/2 through <i>pi</i>/2. Special cases:
64.122 - * <ul><li>If the argument is NaN or its absolute value is greater
64.123 - * than 1, then the result is NaN.
64.124 - * <li>If the argument is zero, then the result is a zero with the
64.125 - * same sign as the argument.</ul>
64.126 - *
64.127 - * @param a the value whose arc sine is to be returned.
64.128 - * @return the arc sine of the argument.
64.129 - */
64.130 - public static native double asin(double a);
64.131 -
64.132 - /**
64.133 - * Returns the arc cosine of a value; the returned angle is in the
64.134 - * range 0.0 through <i>pi</i>. Special case:
64.135 - * <ul><li>If the argument is NaN or its absolute value is greater
64.136 - * than 1, then the result is NaN.</ul>
64.137 - *
64.138 - * @param a the value whose arc cosine is to be returned.
64.139 - * @return the arc cosine of the argument.
64.140 - */
64.141 - public static native double acos(double a);
64.142 -
64.143 - /**
64.144 - * Returns the arc tangent of a value; the returned angle is in the
64.145 - * range -<i>pi</i>/2 through <i>pi</i>/2. Special cases:
64.146 - * <ul><li>If the argument is NaN, then the result is NaN.
64.147 - * <li>If the argument is zero, then the result is a zero with the
64.148 - * same sign as the argument.</ul>
64.149 - *
64.150 - * @param a the value whose arc tangent is to be returned.
64.151 - * @return the arc tangent of the argument.
64.152 - */
64.153 - public static native double atan(double a);
64.154 -
64.155 - /**
64.156 - * Converts an angle measured in degrees to an approximately
64.157 - * equivalent angle measured in radians. The conversion from
64.158 - * degrees to radians is generally inexact.
64.159 - *
64.160 - * @param angdeg an angle, in degrees
64.161 - * @return the measurement of the angle {@code angdeg}
64.162 - * in radians.
64.163 - */
64.164 - public static strictfp double toRadians(double angdeg) {
64.165 - return angdeg / 180.0 * PI;
64.166 - }
64.167 -
64.168 - /**
64.169 - * Converts an angle measured in radians to an approximately
64.170 - * equivalent angle measured in degrees. The conversion from
64.171 - * radians to degrees is generally inexact; users should
64.172 - * <i>not</i> expect {@code cos(toRadians(90.0))} to exactly
64.173 - * equal {@code 0.0}.
64.174 - *
64.175 - * @param angrad an angle, in radians
64.176 - * @return the measurement of the angle {@code angrad}
64.177 - * in degrees.
64.178 - */
64.179 - public static strictfp double toDegrees(double angrad) {
64.180 - return angrad * 180.0 / PI;
64.181 - }
64.182 -
64.183 - /**
64.184 - * Returns Euler's number <i>e</i> raised to the power of a
64.185 - * {@code double} value. Special cases:
64.186 - * <ul><li>If the argument is NaN, the result is NaN.
64.187 - * <li>If the argument is positive infinity, then the result is
64.188 - * positive infinity.
64.189 - * <li>If the argument is negative infinity, then the result is
64.190 - * positive zero.</ul>
64.191 - *
64.192 - * @param a the exponent to raise <i>e</i> to.
64.193 - * @return the value <i>e</i><sup>{@code a}</sup>,
64.194 - * where <i>e</i> is the base of the natural logarithms.
64.195 - */
64.196 - public static native double exp(double a);
64.197 -
64.198 - /**
64.199 - * Returns the natural logarithm (base <i>e</i>) of a {@code double}
64.200 - * value. Special cases:
64.201 - * <ul><li>If the argument is NaN or less than zero, then the result
64.202 - * is NaN.
64.203 - * <li>If the argument is positive infinity, then the result is
64.204 - * positive infinity.
64.205 - * <li>If the argument is positive zero or negative zero, then the
64.206 - * result is negative infinity.</ul>
64.207 - *
64.208 - * @param a a value
64.209 - * @return the value ln {@code a}, the natural logarithm of
64.210 - * {@code a}.
64.211 - */
64.212 - public static native double log(double a);
64.213 -
64.214 -
64.215 - /**
64.216 - * Returns the base 10 logarithm of a {@code double} value.
64.217 - * Special cases:
64.218 - *
64.219 - * <ul><li>If the argument is NaN or less than zero, then the result
64.220 - * is NaN.
64.221 - * <li>If the argument is positive infinity, then the result is
64.222 - * positive infinity.
64.223 - * <li>If the argument is positive zero or negative zero, then the
64.224 - * result is negative infinity.
64.225 - * <li> If the argument is equal to 10<sup><i>n</i></sup> for
64.226 - * integer <i>n</i>, then the result is <i>n</i>.
64.227 - * </ul>
64.228 - *
64.229 - * @param a a value
64.230 - * @return the base 10 logarithm of {@code a}.
64.231 - * @since 1.5
64.232 - */
64.233 - public static native double log10(double a);
64.234 -
64.235 - /**
64.236 - * Returns the correctly rounded positive square root of a
64.237 - * {@code double} value.
64.238 - * Special cases:
64.239 - * <ul><li>If the argument is NaN or less than zero, then the result
64.240 - * is NaN.
64.241 - * <li>If the argument is positive infinity, then the result is positive
64.242 - * infinity.
64.243 - * <li>If the argument is positive zero or negative zero, then the
64.244 - * result is the same as the argument.</ul>
64.245 - * Otherwise, the result is the {@code double} value closest to
64.246 - * the true mathematical square root of the argument value.
64.247 - *
64.248 - * @param a a value.
64.249 - * @return the positive square root of {@code a}.
64.250 - */
64.251 - public static native double sqrt(double a);
64.252 -
64.253 - /**
64.254 - * Returns the cube root of a {@code double} value. For
64.255 - * positive finite {@code x}, {@code cbrt(-x) ==
64.256 - * -cbrt(x)}; that is, the cube root of a negative value is
64.257 - * the negative of the cube root of that value's magnitude.
64.258 - * Special cases:
64.259 - *
64.260 - * <ul>
64.261 - *
64.262 - * <li>If the argument is NaN, then the result is NaN.
64.263 - *
64.264 - * <li>If the argument is infinite, then the result is an infinity
64.265 - * with the same sign as the argument.
64.266 - *
64.267 - * <li>If the argument is zero, then the result is a zero with the
64.268 - * same sign as the argument.
64.269 - *
64.270 - * </ul>
64.271 - *
64.272 - * @param a a value.
64.273 - * @return the cube root of {@code a}.
64.274 - * @since 1.5
64.275 - */
64.276 - public static native double cbrt(double a);
64.277 -
64.278 - /**
64.279 - * Computes the remainder operation on two arguments as prescribed
64.280 - * by the IEEE 754 standard.
64.281 - * The remainder value is mathematically equal to
64.282 - * <code>f1 - f2</code> × <i>n</i>,
64.283 - * where <i>n</i> is the mathematical integer closest to the exact
64.284 - * mathematical value of the quotient {@code f1/f2}, and if two
64.285 - * mathematical integers are equally close to {@code f1/f2},
64.286 - * then <i>n</i> is the integer that is even. If the remainder is
64.287 - * zero, its sign is the same as the sign of the first argument.
64.288 - * Special cases:
64.289 - * <ul><li>If either argument is NaN, or the first argument is infinite,
64.290 - * or the second argument is positive zero or negative zero, then the
64.291 - * result is NaN.
64.292 - * <li>If the first argument is finite and the second argument is
64.293 - * infinite, then the result is the same as the first argument.</ul>
64.294 - *
64.295 - * @param f1 the dividend.
64.296 - * @param f2 the divisor.
64.297 - * @return the remainder when {@code f1} is divided by
64.298 - * {@code f2}.
64.299 - */
64.300 - public static native double IEEEremainder(double f1, double f2);
64.301 -
64.302 - /**
64.303 - * Returns the smallest (closest to negative infinity)
64.304 - * {@code double} value that is greater than or equal to the
64.305 - * argument and is equal to a mathematical integer. Special cases:
64.306 - * <ul><li>If the argument value is already equal to a
64.307 - * mathematical integer, then the result is the same as the
64.308 - * argument. <li>If the argument is NaN or an infinity or
64.309 - * positive zero or negative zero, then the result is the same as
64.310 - * the argument. <li>If the argument value is less than zero but
64.311 - * greater than -1.0, then the result is negative zero.</ul> Note
64.312 - * that the value of {@code StrictMath.ceil(x)} is exactly the
64.313 - * value of {@code -StrictMath.floor(-x)}.
64.314 - *
64.315 - * @param a a value.
64.316 - * @return the smallest (closest to negative infinity)
64.317 - * floating-point value that is greater than or equal to
64.318 - * the argument and is equal to a mathematical integer.
64.319 - */
64.320 - public static double ceil(double a) {
64.321 - return floorOrCeil(a, -0.0, 1.0, 1.0);
64.322 - }
64.323 -
64.324 - /**
64.325 - * Returns the largest (closest to positive infinity)
64.326 - * {@code double} value that is less than or equal to the
64.327 - * argument and is equal to a mathematical integer. Special cases:
64.328 - * <ul><li>If the argument value is already equal to a
64.329 - * mathematical integer, then the result is the same as the
64.330 - * argument. <li>If the argument is NaN or an infinity or
64.331 - * positive zero or negative zero, then the result is the same as
64.332 - * the argument.</ul>
64.333 - *
64.334 - * @param a a value.
64.335 - * @return the largest (closest to positive infinity)
64.336 - * floating-point value that less than or equal to the argument
64.337 - * and is equal to a mathematical integer.
64.338 - */
64.339 - public static double floor(double a) {
64.340 - return floorOrCeil(a, -1.0, 0.0, -1.0);
64.341 - }
64.342 -
64.343 - /**
64.344 - * Internal method to share logic between floor and ceil.
64.345 - *
64.346 - * @param a the value to be floored or ceiled
64.347 - * @param negativeBoundary result for values in (-1, 0)
64.348 - * @param positiveBoundary result for values in (0, 1)
64.349 - * @param increment value to add when the argument is non-integral
64.350 - */
64.351 - private static double floorOrCeil(double a,
64.352 - double negativeBoundary,
64.353 - double positiveBoundary,
64.354 - double sign) {
64.355 - int exponent = getExponent(a);
64.356 -
64.357 - if (exponent < 0) {
64.358 - /*
64.359 - * Absolute value of argument is less than 1.
64.360 - * floorOrceil(-0.0) => -0.0
64.361 - * floorOrceil(+0.0) => +0.0
64.362 - */
64.363 - return ((a == 0.0) ? a :
64.364 - ( (a < 0.0) ? negativeBoundary : positiveBoundary) );
64.365 - } else if (exponent >= 52) {
64.366 - /*
64.367 - * Infinity, NaN, or a value so large it must be integral.
64.368 - */
64.369 - return a;
64.370 - }
64.371 - // Else the argument is either an integral value already XOR it
64.372 - // has to be rounded to one.
64.373 - assert exponent >= 0 && exponent <= 51;
64.374 -
64.375 - long doppel = Double.doubleToRawLongBits(a);
64.376 - long mask = 0; // DoubleConsts.SIGNIF_BIT_MASK >> exponent;
64.377 -
64.378 - if ( (mask & doppel) == 0L )
64.379 - return a; // integral value
64.380 - else {
64.381 - double result = Double.longBitsToDouble(doppel & (~mask));
64.382 - if (sign*a > 0.0)
64.383 - result = result + sign;
64.384 - return result;
64.385 - }
64.386 - }
64.387 -
64.388 - /**
64.389 - * Returns the {@code double} value that is closest in value
64.390 - * to the argument and is equal to a mathematical integer. If two
64.391 - * {@code double} values that are mathematical integers are
64.392 - * equally close to the value of the argument, the result is the
64.393 - * integer value that is even. Special cases:
64.394 - * <ul><li>If the argument value is already equal to a mathematical
64.395 - * integer, then the result is the same as the argument.
64.396 - * <li>If the argument is NaN or an infinity or positive zero or negative
64.397 - * zero, then the result is the same as the argument.</ul>
64.398 - *
64.399 - * @param a a value.
64.400 - * @return the closest floating-point value to {@code a} that is
64.401 - * equal to a mathematical integer.
64.402 - * @author Joseph D. Darcy
64.403 - */
64.404 - public static double rint(double a) {
64.405 - throw new UnsupportedOperationException();
64.406 - /*
64.407 - * If the absolute value of a is not less than 2^52, it
64.408 - * is either a finite integer (the double format does not have
64.409 - * enough significand bits for a number that large to have any
64.410 - * fractional portion), an infinity, or a NaN. In any of
64.411 - * these cases, rint of the argument is the argument.
64.412 - *
64.413 - * Otherwise, the sum (twoToThe52 + a ) will properly round
64.414 - * away any fractional portion of a since ulp(twoToThe52) ==
64.415 - * 1.0; subtracting out twoToThe52 from this sum will then be
64.416 - * exact and leave the rounded integer portion of a.
64.417 - *
64.418 - * This method does *not* need to be declared strictfp to get
64.419 - * fully reproducible results. Whether or not a method is
64.420 - * declared strictfp can only make a difference in the
64.421 - * returned result if some operation would overflow or
64.422 - * underflow with strictfp semantics. The operation
64.423 - * (twoToThe52 + a ) cannot overflow since large values of a
64.424 - * are screened out; the add cannot underflow since twoToThe52
64.425 - * is too large. The subtraction ((twoToThe52 + a ) -
64.426 - * twoToThe52) will be exact as discussed above and thus
64.427 - * cannot overflow or meaningfully underflow. Finally, the
64.428 - * last multiply in the return statement is by plus or minus
64.429 - * 1.0, which is exact too.
64.430 - */
64.431 -// double twoToThe52 = (double)(1L << 52); // 2^52
64.432 -// double sign = FpUtils.rawCopySign(1.0, a); // preserve sign info
64.433 -// a = Math.abs(a);
64.434 -//
64.435 -// if (a < twoToThe52) { // E_min <= ilogb(a) <= 51
64.436 -// a = ((twoToThe52 + a ) - twoToThe52);
64.437 -// }
64.438 -//
64.439 -// return sign * a; // restore original sign
64.440 - }
64.441 -
64.442 - /**
64.443 - * Returns the angle <i>theta</i> from the conversion of rectangular
64.444 - * coordinates ({@code x}, {@code y}) to polar
64.445 - * coordinates (r, <i>theta</i>).
64.446 - * This method computes the phase <i>theta</i> by computing an arc tangent
64.447 - * of {@code y/x} in the range of -<i>pi</i> to <i>pi</i>. Special
64.448 - * cases:
64.449 - * <ul><li>If either argument is NaN, then the result is NaN.
64.450 - * <li>If the first argument is positive zero and the second argument
64.451 - * is positive, or the first argument is positive and finite and the
64.452 - * second argument is positive infinity, then the result is positive
64.453 - * zero.
64.454 - * <li>If the first argument is negative zero and the second argument
64.455 - * is positive, or the first argument is negative and finite and the
64.456 - * second argument is positive infinity, then the result is negative zero.
64.457 - * <li>If the first argument is positive zero and the second argument
64.458 - * is negative, or the first argument is positive and finite and the
64.459 - * second argument is negative infinity, then the result is the
64.460 - * {@code double} value closest to <i>pi</i>.
64.461 - * <li>If the first argument is negative zero and the second argument
64.462 - * is negative, or the first argument is negative and finite and the
64.463 - * second argument is negative infinity, then the result is the
64.464 - * {@code double} value closest to -<i>pi</i>.
64.465 - * <li>If the first argument is positive and the second argument is
64.466 - * positive zero or negative zero, or the first argument is positive
64.467 - * infinity and the second argument is finite, then the result is the
64.468 - * {@code double} value closest to <i>pi</i>/2.
64.469 - * <li>If the first argument is negative and the second argument is
64.470 - * positive zero or negative zero, or the first argument is negative
64.471 - * infinity and the second argument is finite, then the result is the
64.472 - * {@code double} value closest to -<i>pi</i>/2.
64.473 - * <li>If both arguments are positive infinity, then the result is the
64.474 - * {@code double} value closest to <i>pi</i>/4.
64.475 - * <li>If the first argument is positive infinity and the second argument
64.476 - * is negative infinity, then the result is the {@code double}
64.477 - * value closest to 3*<i>pi</i>/4.
64.478 - * <li>If the first argument is negative infinity and the second argument
64.479 - * is positive infinity, then the result is the {@code double} value
64.480 - * closest to -<i>pi</i>/4.
64.481 - * <li>If both arguments are negative infinity, then the result is the
64.482 - * {@code double} value closest to -3*<i>pi</i>/4.</ul>
64.483 - *
64.484 - * @param y the ordinate coordinate
64.485 - * @param x the abscissa coordinate
64.486 - * @return the <i>theta</i> component of the point
64.487 - * (<i>r</i>, <i>theta</i>)
64.488 - * in polar coordinates that corresponds to the point
64.489 - * (<i>x</i>, <i>y</i>) in Cartesian coordinates.
64.490 - */
64.491 - public static native double atan2(double y, double x);
64.492 -
64.493 -
64.494 - /**
64.495 - * Returns the value of the first argument raised to the power of the
64.496 - * second argument. Special cases:
64.497 - *
64.498 - * <ul><li>If the second argument is positive or negative zero, then the
64.499 - * result is 1.0.
64.500 - * <li>If the second argument is 1.0, then the result is the same as the
64.501 - * first argument.
64.502 - * <li>If the second argument is NaN, then the result is NaN.
64.503 - * <li>If the first argument is NaN and the second argument is nonzero,
64.504 - * then the result is NaN.
64.505 - *
64.506 - * <li>If
64.507 - * <ul>
64.508 - * <li>the absolute value of the first argument is greater than 1
64.509 - * and the second argument is positive infinity, or
64.510 - * <li>the absolute value of the first argument is less than 1 and
64.511 - * the second argument is negative infinity,
64.512 - * </ul>
64.513 - * then the result is positive infinity.
64.514 - *
64.515 - * <li>If
64.516 - * <ul>
64.517 - * <li>the absolute value of the first argument is greater than 1 and
64.518 - * the second argument is negative infinity, or
64.519 - * <li>the absolute value of the
64.520 - * first argument is less than 1 and the second argument is positive
64.521 - * infinity,
64.522 - * </ul>
64.523 - * then the result is positive zero.
64.524 - *
64.525 - * <li>If the absolute value of the first argument equals 1 and the
64.526 - * second argument is infinite, then the result is NaN.
64.527 - *
64.528 - * <li>If
64.529 - * <ul>
64.530 - * <li>the first argument is positive zero and the second argument
64.531 - * is greater than zero, or
64.532 - * <li>the first argument is positive infinity and the second
64.533 - * argument is less than zero,
64.534 - * </ul>
64.535 - * then the result is positive zero.
64.536 - *
64.537 - * <li>If
64.538 - * <ul>
64.539 - * <li>the first argument is positive zero and the second argument
64.540 - * is less than zero, or
64.541 - * <li>the first argument is positive infinity and the second
64.542 - * argument is greater than zero,
64.543 - * </ul>
64.544 - * then the result is positive infinity.
64.545 - *
64.546 - * <li>If
64.547 - * <ul>
64.548 - * <li>the first argument is negative zero and the second argument
64.549 - * is greater than zero but not a finite odd integer, or
64.550 - * <li>the first argument is negative infinity and the second
64.551 - * argument is less than zero but not a finite odd integer,
64.552 - * </ul>
64.553 - * then the result is positive zero.
64.554 - *
64.555 - * <li>If
64.556 - * <ul>
64.557 - * <li>the first argument is negative zero and the second argument
64.558 - * is a positive finite odd integer, or
64.559 - * <li>the first argument is negative infinity and the second
64.560 - * argument is a negative finite odd integer,
64.561 - * </ul>
64.562 - * then the result is negative zero.
64.563 - *
64.564 - * <li>If
64.565 - * <ul>
64.566 - * <li>the first argument is negative zero and the second argument
64.567 - * is less than zero but not a finite odd integer, or
64.568 - * <li>the first argument is negative infinity and the second
64.569 - * argument is greater than zero but not a finite odd integer,
64.570 - * </ul>
64.571 - * then the result is positive infinity.
64.572 - *
64.573 - * <li>If
64.574 - * <ul>
64.575 - * <li>the first argument is negative zero and the second argument
64.576 - * is a negative finite odd integer, or
64.577 - * <li>the first argument is negative infinity and the second
64.578 - * argument is a positive finite odd integer,
64.579 - * </ul>
64.580 - * then the result is negative infinity.
64.581 - *
64.582 - * <li>If the first argument is finite and less than zero
64.583 - * <ul>
64.584 - * <li> if the second argument is a finite even integer, the
64.585 - * result is equal to the result of raising the absolute value of
64.586 - * the first argument to the power of the second argument
64.587 - *
64.588 - * <li>if the second argument is a finite odd integer, the result
64.589 - * is equal to the negative of the result of raising the absolute
64.590 - * value of the first argument to the power of the second
64.591 - * argument
64.592 - *
64.593 - * <li>if the second argument is finite and not an integer, then
64.594 - * the result is NaN.
64.595 - * </ul>
64.596 - *
64.597 - * <li>If both arguments are integers, then the result is exactly equal
64.598 - * to the mathematical result of raising the first argument to the power
64.599 - * of the second argument if that result can in fact be represented
64.600 - * exactly as a {@code double} value.</ul>
64.601 - *
64.602 - * <p>(In the foregoing descriptions, a floating-point value is
64.603 - * considered to be an integer if and only if it is finite and a
64.604 - * fixed point of the method {@link #ceil ceil} or,
64.605 - * equivalently, a fixed point of the method {@link #floor
64.606 - * floor}. A value is a fixed point of a one-argument
64.607 - * method if and only if the result of applying the method to the
64.608 - * value is equal to the value.)
64.609 - *
64.610 - * @param a base.
64.611 - * @param b the exponent.
64.612 - * @return the value {@code a}<sup>{@code b}</sup>.
64.613 - */
64.614 - public static native double pow(double a, double b);
64.615 -
64.616 - /**
64.617 - * Returns the closest {@code int} to the argument, with ties
64.618 - * rounding up.
64.619 - *
64.620 - * <p>Special cases:
64.621 - * <ul><li>If the argument is NaN, the result is 0.
64.622 - * <li>If the argument is negative infinity or any value less than or
64.623 - * equal to the value of {@code Integer.MIN_VALUE}, the result is
64.624 - * equal to the value of {@code Integer.MIN_VALUE}.
64.625 - * <li>If the argument is positive infinity or any value greater than or
64.626 - * equal to the value of {@code Integer.MAX_VALUE}, the result is
64.627 - * equal to the value of {@code Integer.MAX_VALUE}.</ul>
64.628 - *
64.629 - * @param a a floating-point value to be rounded to an integer.
64.630 - * @return the value of the argument rounded to the nearest
64.631 - * {@code int} value.
64.632 - * @see java.lang.Integer#MAX_VALUE
64.633 - * @see java.lang.Integer#MIN_VALUE
64.634 - */
64.635 - public static int round(float a) {
64.636 - return Math.round(a);
64.637 - }
64.638 -
64.639 - /**
64.640 - * Returns the closest {@code long} to the argument, with ties
64.641 - * rounding up.
64.642 - *
64.643 - * <p>Special cases:
64.644 - * <ul><li>If the argument is NaN, the result is 0.
64.645 - * <li>If the argument is negative infinity or any value less than or
64.646 - * equal to the value of {@code Long.MIN_VALUE}, the result is
64.647 - * equal to the value of {@code Long.MIN_VALUE}.
64.648 - * <li>If the argument is positive infinity or any value greater than or
64.649 - * equal to the value of {@code Long.MAX_VALUE}, the result is
64.650 - * equal to the value of {@code Long.MAX_VALUE}.</ul>
64.651 - *
64.652 - * @param a a floating-point value to be rounded to a
64.653 - * {@code long}.
64.654 - * @return the value of the argument rounded to the nearest
64.655 - * {@code long} value.
64.656 - * @see java.lang.Long#MAX_VALUE
64.657 - * @see java.lang.Long#MIN_VALUE
64.658 - */
64.659 - public static long round(double a) {
64.660 - return Math.round(a);
64.661 - }
64.662 -
64.663 - /**
64.664 - * Returns a {@code double} value with a positive sign, greater
64.665 - * than or equal to {@code 0.0} and less than {@code 1.0}.
64.666 - * Returned values are chosen pseudorandomly with (approximately)
64.667 - * uniform distribution from that range.
64.668 - *
64.669 - * <p>When this method is first called, it creates a single new
64.670 - * pseudorandom-number generator, exactly as if by the expression
64.671 - *
64.672 - * <blockquote>{@code new java.util.Random()}</blockquote>
64.673 - *
64.674 - * This new pseudorandom-number generator is used thereafter for
64.675 - * all calls to this method and is used nowhere else.
64.676 - *
64.677 - * <p>This method is properly synchronized to allow correct use by
64.678 - * more than one thread. However, if many threads need to generate
64.679 - * pseudorandom numbers at a great rate, it may reduce contention
64.680 - * for each thread to have its own pseudorandom number generator.
64.681 - *
64.682 - * @return a pseudorandom {@code double} greater than or equal
64.683 - * to {@code 0.0} and less than {@code 1.0}.
64.684 - * @see Random#nextDouble()
64.685 - */
64.686 - public static double random() {
64.687 - throw new UnsupportedOperationException();
64.688 - }
64.689 -
64.690 - /**
64.691 - * Returns the absolute value of an {@code int} value..
64.692 - * If the argument is not negative, the argument is returned.
64.693 - * If the argument is negative, the negation of the argument is returned.
64.694 - *
64.695 - * <p>Note that if the argument is equal to the value of
64.696 - * {@link Integer#MIN_VALUE}, the most negative representable
64.697 - * {@code int} value, the result is that same value, which is
64.698 - * negative.
64.699 - *
64.700 - * @param a the argument whose absolute value is to be determined.
64.701 - * @return the absolute value of the argument.
64.702 - */
64.703 - public static int abs(int a) {
64.704 - return (a < 0) ? -a : a;
64.705 - }
64.706 -
64.707 - /**
64.708 - * Returns the absolute value of a {@code long} value.
64.709 - * If the argument is not negative, the argument is returned.
64.710 - * If the argument is negative, the negation of the argument is returned.
64.711 - *
64.712 - * <p>Note that if the argument is equal to the value of
64.713 - * {@link Long#MIN_VALUE}, the most negative representable
64.714 - * {@code long} value, the result is that same value, which
64.715 - * is negative.
64.716 - *
64.717 - * @param a the argument whose absolute value is to be determined.
64.718 - * @return the absolute value of the argument.
64.719 - */
64.720 - public static long abs(long a) {
64.721 - return (a < 0) ? -a : a;
64.722 - }
64.723 -
64.724 - /**
64.725 - * Returns the absolute value of a {@code float} value.
64.726 - * If the argument is not negative, the argument is returned.
64.727 - * If the argument is negative, the negation of the argument is returned.
64.728 - * Special cases:
64.729 - * <ul><li>If the argument is positive zero or negative zero, the
64.730 - * result is positive zero.
64.731 - * <li>If the argument is infinite, the result is positive infinity.
64.732 - * <li>If the argument is NaN, the result is NaN.</ul>
64.733 - * In other words, the result is the same as the value of the expression:
64.734 - * <p>{@code Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))}
64.735 - *
64.736 - * @param a the argument whose absolute value is to be determined
64.737 - * @return the absolute value of the argument.
64.738 - */
64.739 - public static float abs(float a) {
64.740 - return (a <= 0.0F) ? 0.0F - a : a;
64.741 - }
64.742 -
64.743 - /**
64.744 - * Returns the absolute value of a {@code double} value.
64.745 - * If the argument is not negative, the argument is returned.
64.746 - * If the argument is negative, the negation of the argument is returned.
64.747 - * Special cases:
64.748 - * <ul><li>If the argument is positive zero or negative zero, the result
64.749 - * is positive zero.
64.750 - * <li>If the argument is infinite, the result is positive infinity.
64.751 - * <li>If the argument is NaN, the result is NaN.</ul>
64.752 - * In other words, the result is the same as the value of the expression:
64.753 - * <p>{@code Double.longBitsToDouble((Double.doubleToLongBits(a)<<1)>>>1)}
64.754 - *
64.755 - * @param a the argument whose absolute value is to be determined
64.756 - * @return the absolute value of the argument.
64.757 - */
64.758 - public static double abs(double a) {
64.759 - return (a <= 0.0D) ? 0.0D - a : a;
64.760 - }
64.761 -
64.762 - /**
64.763 - * Returns the greater of two {@code int} values. That is, the
64.764 - * result is the argument closer to the value of
64.765 - * {@link Integer#MAX_VALUE}. If the arguments have the same value,
64.766 - * the result is that same value.
64.767 - *
64.768 - * @param a an argument.
64.769 - * @param b another argument.
64.770 - * @return the larger of {@code a} and {@code b}.
64.771 - */
64.772 - public static int max(int a, int b) {
64.773 - return (a >= b) ? a : b;
64.774 - }
64.775 -
64.776 - /**
64.777 - * Returns the greater of two {@code long} values. That is, the
64.778 - * result is the argument closer to the value of
64.779 - * {@link Long#MAX_VALUE}. If the arguments have the same value,
64.780 - * the result is that same value.
64.781 - *
64.782 - * @param a an argument.
64.783 - * @param b another argument.
64.784 - * @return the larger of {@code a} and {@code b}.
64.785 - */
64.786 - public static long max(long a, long b) {
64.787 - return (a >= b) ? a : b;
64.788 - }
64.789 -
64.790 - // Use raw bit-wise conversions on guaranteed non-NaN arguments.
64.791 - private static long negativeZeroFloatBits = Float.floatToRawIntBits(-0.0f);
64.792 - private static long negativeZeroDoubleBits = Double.doubleToRawLongBits(-0.0d);
64.793 -
64.794 - /**
64.795 - * Returns the greater of two {@code float} values. That is,
64.796 - * the result is the argument closer to positive infinity. If the
64.797 - * arguments have the same value, the result is that same
64.798 - * value. If either value is NaN, then the result is NaN. Unlike
64.799 - * the numerical comparison operators, this method considers
64.800 - * negative zero to be strictly smaller than positive zero. If one
64.801 - * argument is positive zero and the other negative zero, the
64.802 - * result is positive zero.
64.803 - *
64.804 - * @param a an argument.
64.805 - * @param b another argument.
64.806 - * @return the larger of {@code a} and {@code b}.
64.807 - */
64.808 - public static float max(float a, float b) {
64.809 - if (a != a)
64.810 - return a; // a is NaN
64.811 - if ((a == 0.0f) &&
64.812 - (b == 0.0f) &&
64.813 - (Float.floatToRawIntBits(a) == negativeZeroFloatBits)) {
64.814 - // Raw conversion ok since NaN can't map to -0.0.
64.815 - return b;
64.816 - }
64.817 - return (a >= b) ? a : b;
64.818 - }
64.819 -
64.820 - /**
64.821 - * Returns the greater of two {@code double} values. That
64.822 - * is, the result is the argument closer to positive infinity. If
64.823 - * the arguments have the same value, the result is that same
64.824 - * value. If either value is NaN, then the result is NaN. Unlike
64.825 - * the numerical comparison operators, this method considers
64.826 - * negative zero to be strictly smaller than positive zero. If one
64.827 - * argument is positive zero and the other negative zero, the
64.828 - * result is positive zero.
64.829 - *
64.830 - * @param a an argument.
64.831 - * @param b another argument.
64.832 - * @return the larger of {@code a} and {@code b}.
64.833 - */
64.834 - public static double max(double a, double b) {
64.835 - if (a != a)
64.836 - return a; // a is NaN
64.837 - if ((a == 0.0d) &&
64.838 - (b == 0.0d) &&
64.839 - (Double.doubleToRawLongBits(a) == negativeZeroDoubleBits)) {
64.840 - // Raw conversion ok since NaN can't map to -0.0.
64.841 - return b;
64.842 - }
64.843 - return (a >= b) ? a : b;
64.844 - }
64.845 -
64.846 - /**
64.847 - * Returns the smaller of two {@code int} values. That is,
64.848 - * the result the argument closer to the value of
64.849 - * {@link Integer#MIN_VALUE}. If the arguments have the same
64.850 - * value, the result is that same value.
64.851 - *
64.852 - * @param a an argument.
64.853 - * @param b another argument.
64.854 - * @return the smaller of {@code a} and {@code b}.
64.855 - */
64.856 - public static int min(int a, int b) {
64.857 - return (a <= b) ? a : b;
64.858 - }
64.859 -
64.860 - /**
64.861 - * Returns the smaller of two {@code long} values. That is,
64.862 - * the result is the argument closer to the value of
64.863 - * {@link Long#MIN_VALUE}. If the arguments have the same
64.864 - * value, the result is that same value.
64.865 - *
64.866 - * @param a an argument.
64.867 - * @param b another argument.
64.868 - * @return the smaller of {@code a} and {@code b}.
64.869 - */
64.870 - public static long min(long a, long b) {
64.871 - return (a <= b) ? a : b;
64.872 - }
64.873 -
64.874 - /**
64.875 - * Returns the smaller of two {@code float} values. That is,
64.876 - * the result is the value closer to negative infinity. If the
64.877 - * arguments have the same value, the result is that same
64.878 - * value. If either value is NaN, then the result is NaN. Unlike
64.879 - * the numerical comparison operators, this method considers
64.880 - * negative zero to be strictly smaller than positive zero. If
64.881 - * one argument is positive zero and the other is negative zero,
64.882 - * the result is negative zero.
64.883 - *
64.884 - * @param a an argument.
64.885 - * @param b another argument.
64.886 - * @return the smaller of {@code a} and {@code b.}
64.887 - */
64.888 - public static float min(float a, float b) {
64.889 - if (a != a)
64.890 - return a; // a is NaN
64.891 - if ((a == 0.0f) &&
64.892 - (b == 0.0f) &&
64.893 - (Float.floatToRawIntBits(b) == negativeZeroFloatBits)) {
64.894 - // Raw conversion ok since NaN can't map to -0.0.
64.895 - return b;
64.896 - }
64.897 - return (a <= b) ? a : b;
64.898 - }
64.899 -
64.900 - /**
64.901 - * Returns the smaller of two {@code double} values. That
64.902 - * is, the result is the value closer to negative infinity. If the
64.903 - * arguments have the same value, the result is that same
64.904 - * value. If either value is NaN, then the result is NaN. Unlike
64.905 - * the numerical comparison operators, this method considers
64.906 - * negative zero to be strictly smaller than positive zero. If one
64.907 - * argument is positive zero and the other is negative zero, the
64.908 - * result is negative zero.
64.909 - *
64.910 - * @param a an argument.
64.911 - * @param b another argument.
64.912 - * @return the smaller of {@code a} and {@code b}.
64.913 - */
64.914 - public static double min(double a, double b) {
64.915 - if (a != a)
64.916 - return a; // a is NaN
64.917 - if ((a == 0.0d) &&
64.918 - (b == 0.0d) &&
64.919 - (Double.doubleToRawLongBits(b) == negativeZeroDoubleBits)) {
64.920 - // Raw conversion ok since NaN can't map to -0.0.
64.921 - return b;
64.922 - }
64.923 - return (a <= b) ? a : b;
64.924 - }
64.925 -
64.926 - /**
64.927 - * Returns the size of an ulp of the argument. An ulp of a
64.928 - * {@code double} value is the positive distance between this
64.929 - * floating-point value and the {@code double} value next
64.930 - * larger in magnitude. Note that for non-NaN <i>x</i>,
64.931 - * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
64.932 - *
64.933 - * <p>Special Cases:
64.934 - * <ul>
64.935 - * <li> If the argument is NaN, then the result is NaN.
64.936 - * <li> If the argument is positive or negative infinity, then the
64.937 - * result is positive infinity.
64.938 - * <li> If the argument is positive or negative zero, then the result is
64.939 - * {@code Double.MIN_VALUE}.
64.940 - * <li> If the argument is ±{@code Double.MAX_VALUE}, then
64.941 - * the result is equal to 2<sup>971</sup>.
64.942 - * </ul>
64.943 - *
64.944 - * @param d the floating-point value whose ulp is to be returned
64.945 - * @return the size of an ulp of the argument
64.946 - * @author Joseph D. Darcy
64.947 - * @since 1.5
64.948 - */
64.949 - public static double ulp(double d) {
64.950 - throw new UnsupportedOperationException();
64.951 - }
64.952 -
64.953 - /**
64.954 - * Returns the size of an ulp of the argument. An ulp of a
64.955 - * {@code float} value is the positive distance between this
64.956 - * floating-point value and the {@code float} value next
64.957 - * larger in magnitude. Note that for non-NaN <i>x</i>,
64.958 - * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
64.959 - *
64.960 - * <p>Special Cases:
64.961 - * <ul>
64.962 - * <li> If the argument is NaN, then the result is NaN.
64.963 - * <li> If the argument is positive or negative infinity, then the
64.964 - * result is positive infinity.
64.965 - * <li> If the argument is positive or negative zero, then the result is
64.966 - * {@code Float.MIN_VALUE}.
64.967 - * <li> If the argument is ±{@code Float.MAX_VALUE}, then
64.968 - * the result is equal to 2<sup>104</sup>.
64.969 - * </ul>
64.970 - *
64.971 - * @param f the floating-point value whose ulp is to be returned
64.972 - * @return the size of an ulp of the argument
64.973 - * @author Joseph D. Darcy
64.974 - * @since 1.5
64.975 - */
64.976 - public static float ulp(float f) {
64.977 - throw new UnsupportedOperationException();
64.978 - }
64.979 -
64.980 - /**
64.981 - * Returns the signum function of the argument; zero if the argument
64.982 - * is zero, 1.0 if the argument is greater than zero, -1.0 if the
64.983 - * argument is less than zero.
64.984 - *
64.985 - * <p>Special Cases:
64.986 - * <ul>
64.987 - * <li> If the argument is NaN, then the result is NaN.
64.988 - * <li> If the argument is positive zero or negative zero, then the
64.989 - * result is the same as the argument.
64.990 - * </ul>
64.991 - *
64.992 - * @param d the floating-point value whose signum is to be returned
64.993 - * @return the signum function of the argument
64.994 - * @author Joseph D. Darcy
64.995 - * @since 1.5
64.996 - */
64.997 - public static double signum(double d) {
64.998 - throw new UnsupportedOperationException();
64.999 - }
64.1000 -
64.1001 - /**
64.1002 - * Returns the signum function of the argument; zero if the argument
64.1003 - * is zero, 1.0f if the argument is greater than zero, -1.0f if the
64.1004 - * argument is less than zero.
64.1005 - *
64.1006 - * <p>Special Cases:
64.1007 - * <ul>
64.1008 - * <li> If the argument is NaN, then the result is NaN.
64.1009 - * <li> If the argument is positive zero or negative zero, then the
64.1010 - * result is the same as the argument.
64.1011 - * </ul>
64.1012 - *
64.1013 - * @param f the floating-point value whose signum is to be returned
64.1014 - * @return the signum function of the argument
64.1015 - * @author Joseph D. Darcy
64.1016 - * @since 1.5
64.1017 - */
64.1018 - public static float signum(float f) {
64.1019 - throw new UnsupportedOperationException();
64.1020 - }
64.1021 -
64.1022 - /**
64.1023 - * Returns the hyperbolic sine of a {@code double} value.
64.1024 - * The hyperbolic sine of <i>x</i> is defined to be
64.1025 - * (<i>e<sup>x</sup> - e<sup>-x</sup></i>)/2
64.1026 - * where <i>e</i> is {@linkplain Math#E Euler's number}.
64.1027 - *
64.1028 - * <p>Special cases:
64.1029 - * <ul>
64.1030 - *
64.1031 - * <li>If the argument is NaN, then the result is NaN.
64.1032 - *
64.1033 - * <li>If the argument is infinite, then the result is an infinity
64.1034 - * with the same sign as the argument.
64.1035 - *
64.1036 - * <li>If the argument is zero, then the result is a zero with the
64.1037 - * same sign as the argument.
64.1038 - *
64.1039 - * </ul>
64.1040 - *
64.1041 - * @param x The number whose hyperbolic sine is to be returned.
64.1042 - * @return The hyperbolic sine of {@code x}.
64.1043 - * @since 1.5
64.1044 - */
64.1045 - public static native double sinh(double x);
64.1046 -
64.1047 - /**
64.1048 - * Returns the hyperbolic cosine of a {@code double} value.
64.1049 - * The hyperbolic cosine of <i>x</i> is defined to be
64.1050 - * (<i>e<sup>x</sup> + e<sup>-x</sup></i>)/2
64.1051 - * where <i>e</i> is {@linkplain Math#E Euler's number}.
64.1052 - *
64.1053 - * <p>Special cases:
64.1054 - * <ul>
64.1055 - *
64.1056 - * <li>If the argument is NaN, then the result is NaN.
64.1057 - *
64.1058 - * <li>If the argument is infinite, then the result is positive
64.1059 - * infinity.
64.1060 - *
64.1061 - * <li>If the argument is zero, then the result is {@code 1.0}.
64.1062 - *
64.1063 - * </ul>
64.1064 - *
64.1065 - * @param x The number whose hyperbolic cosine is to be returned.
64.1066 - * @return The hyperbolic cosine of {@code x}.
64.1067 - * @since 1.5
64.1068 - */
64.1069 - public static native double cosh(double x);
64.1070 -
64.1071 - /**
64.1072 - * Returns the hyperbolic tangent of a {@code double} value.
64.1073 - * The hyperbolic tangent of <i>x</i> is defined to be
64.1074 - * (<i>e<sup>x</sup> - e<sup>-x</sup></i>)/(<i>e<sup>x</sup> + e<sup>-x</sup></i>),
64.1075 - * in other words, {@linkplain Math#sinh
64.1076 - * sinh(<i>x</i>)}/{@linkplain Math#cosh cosh(<i>x</i>)}. Note
64.1077 - * that the absolute value of the exact tanh is always less than
64.1078 - * 1.
64.1079 - *
64.1080 - * <p>Special cases:
64.1081 - * <ul>
64.1082 - *
64.1083 - * <li>If the argument is NaN, then the result is NaN.
64.1084 - *
64.1085 - * <li>If the argument is zero, then the result is a zero with the
64.1086 - * same sign as the argument.
64.1087 - *
64.1088 - * <li>If the argument is positive infinity, then the result is
64.1089 - * {@code +1.0}.
64.1090 - *
64.1091 - * <li>If the argument is negative infinity, then the result is
64.1092 - * {@code -1.0}.
64.1093 - *
64.1094 - * </ul>
64.1095 - *
64.1096 - * @param x The number whose hyperbolic tangent is to be returned.
64.1097 - * @return The hyperbolic tangent of {@code x}.
64.1098 - * @since 1.5
64.1099 - */
64.1100 - public static native double tanh(double x);
64.1101 -
64.1102 - /**
64.1103 - * Returns sqrt(<i>x</i><sup>2</sup> +<i>y</i><sup>2</sup>)
64.1104 - * without intermediate overflow or underflow.
64.1105 - *
64.1106 - * <p>Special cases:
64.1107 - * <ul>
64.1108 - *
64.1109 - * <li> If either argument is infinite, then the result
64.1110 - * is positive infinity.
64.1111 - *
64.1112 - * <li> If either argument is NaN and neither argument is infinite,
64.1113 - * then the result is NaN.
64.1114 - *
64.1115 - * </ul>
64.1116 - *
64.1117 - * @param x a value
64.1118 - * @param y a value
64.1119 - * @return sqrt(<i>x</i><sup>2</sup> +<i>y</i><sup>2</sup>)
64.1120 - * without intermediate overflow or underflow
64.1121 - * @since 1.5
64.1122 - */
64.1123 - public static native double hypot(double x, double y);
64.1124 -
64.1125 - /**
64.1126 - * Returns <i>e</i><sup>x</sup> -1. Note that for values of
64.1127 - * <i>x</i> near 0, the exact sum of
64.1128 - * {@code expm1(x)} + 1 is much closer to the true
64.1129 - * result of <i>e</i><sup>x</sup> than {@code exp(x)}.
64.1130 - *
64.1131 - * <p>Special cases:
64.1132 - * <ul>
64.1133 - * <li>If the argument is NaN, the result is NaN.
64.1134 - *
64.1135 - * <li>If the argument is positive infinity, then the result is
64.1136 - * positive infinity.
64.1137 - *
64.1138 - * <li>If the argument is negative infinity, then the result is
64.1139 - * -1.0.
64.1140 - *
64.1141 - * <li>If the argument is zero, then the result is a zero with the
64.1142 - * same sign as the argument.
64.1143 - *
64.1144 - * </ul>
64.1145 - *
64.1146 - * @param x the exponent to raise <i>e</i> to in the computation of
64.1147 - * <i>e</i><sup>{@code x}</sup> -1.
64.1148 - * @return the value <i>e</i><sup>{@code x}</sup> - 1.
64.1149 - * @since 1.5
64.1150 - */
64.1151 - public static native double expm1(double x);
64.1152 -
64.1153 - /**
64.1154 - * Returns the natural logarithm of the sum of the argument and 1.
64.1155 - * Note that for small values {@code x}, the result of
64.1156 - * {@code log1p(x)} is much closer to the true result of ln(1
64.1157 - * + {@code x}) than the floating-point evaluation of
64.1158 - * {@code log(1.0+x)}.
64.1159 - *
64.1160 - * <p>Special cases:
64.1161 - * <ul>
64.1162 - *
64.1163 - * <li>If the argument is NaN or less than -1, then the result is
64.1164 - * NaN.
64.1165 - *
64.1166 - * <li>If the argument is positive infinity, then the result is
64.1167 - * positive infinity.
64.1168 - *
64.1169 - * <li>If the argument is negative one, then the result is
64.1170 - * negative infinity.
64.1171 - *
64.1172 - * <li>If the argument is zero, then the result is a zero with the
64.1173 - * same sign as the argument.
64.1174 - *
64.1175 - * </ul>
64.1176 - *
64.1177 - * @param x a value
64.1178 - * @return the value ln({@code x} + 1), the natural
64.1179 - * log of {@code x} + 1
64.1180 - * @since 1.5
64.1181 - */
64.1182 - public static native double log1p(double x);
64.1183 -
64.1184 - /**
64.1185 - * Returns the first floating-point argument with the sign of the
64.1186 - * second floating-point argument. For this method, a NaN
64.1187 - * {@code sign} argument is always treated as if it were
64.1188 - * positive.
64.1189 - *
64.1190 - * @param magnitude the parameter providing the magnitude of the result
64.1191 - * @param sign the parameter providing the sign of the result
64.1192 - * @return a value with the magnitude of {@code magnitude}
64.1193 - * and the sign of {@code sign}.
64.1194 - * @since 1.6
64.1195 - */
64.1196 - public static double copySign(double magnitude, double sign) {
64.1197 - throw new UnsupportedOperationException();
64.1198 - }
64.1199 -
64.1200 - /**
64.1201 - * Returns the first floating-point argument with the sign of the
64.1202 - * second floating-point argument. For this method, a NaN
64.1203 - * {@code sign} argument is always treated as if it were
64.1204 - * positive.
64.1205 - *
64.1206 - * @param magnitude the parameter providing the magnitude of the result
64.1207 - * @param sign the parameter providing the sign of the result
64.1208 - * @return a value with the magnitude of {@code magnitude}
64.1209 - * and the sign of {@code sign}.
64.1210 - * @since 1.6
64.1211 - */
64.1212 - public static float copySign(float magnitude, float sign) {
64.1213 - throw new UnsupportedOperationException();
64.1214 - }
64.1215 - /**
64.1216 - * Returns the unbiased exponent used in the representation of a
64.1217 - * {@code float}. Special cases:
64.1218 - *
64.1219 - * <ul>
64.1220 - * <li>If the argument is NaN or infinite, then the result is
64.1221 - * {@link Float#MAX_EXPONENT} + 1.
64.1222 - * <li>If the argument is zero or subnormal, then the result is
64.1223 - * {@link Float#MIN_EXPONENT} -1.
64.1224 - * </ul>
64.1225 - * @param f a {@code float} value
64.1226 - * @since 1.6
64.1227 - */
64.1228 - public static int getExponent(float f) {
64.1229 - throw new UnsupportedOperationException();
64.1230 - }
64.1231 -
64.1232 - /**
64.1233 - * Returns the unbiased exponent used in the representation of a
64.1234 - * {@code double}. Special cases:
64.1235 - *
64.1236 - * <ul>
64.1237 - * <li>If the argument is NaN or infinite, then the result is
64.1238 - * {@link Double#MAX_EXPONENT} + 1.
64.1239 - * <li>If the argument is zero or subnormal, then the result is
64.1240 - * {@link Double#MIN_EXPONENT} -1.
64.1241 - * </ul>
64.1242 - * @param d a {@code double} value
64.1243 - * @since 1.6
64.1244 - */
64.1245 - public static int getExponent(double d) {
64.1246 - throw new UnsupportedOperationException();
64.1247 - }
64.1248 -
64.1249 - /**
64.1250 - * Returns the floating-point number adjacent to the first
64.1251 - * argument in the direction of the second argument. If both
64.1252 - * arguments compare as equal the second argument is returned.
64.1253 - *
64.1254 - * <p>Special cases:
64.1255 - * <ul>
64.1256 - * <li> If either argument is a NaN, then NaN is returned.
64.1257 - *
64.1258 - * <li> If both arguments are signed zeros, {@code direction}
64.1259 - * is returned unchanged (as implied by the requirement of
64.1260 - * returning the second argument if the arguments compare as
64.1261 - * equal).
64.1262 - *
64.1263 - * <li> If {@code start} is
64.1264 - * ±{@link Double#MIN_VALUE} and {@code direction}
64.1265 - * has a value such that the result should have a smaller
64.1266 - * magnitude, then a zero with the same sign as {@code start}
64.1267 - * is returned.
64.1268 - *
64.1269 - * <li> If {@code start} is infinite and
64.1270 - * {@code direction} has a value such that the result should
64.1271 - * have a smaller magnitude, {@link Double#MAX_VALUE} with the
64.1272 - * same sign as {@code start} is returned.
64.1273 - *
64.1274 - * <li> If {@code start} is equal to ±
64.1275 - * {@link Double#MAX_VALUE} and {@code direction} has a
64.1276 - * value such that the result should have a larger magnitude, an
64.1277 - * infinity with same sign as {@code start} is returned.
64.1278 - * </ul>
64.1279 - *
64.1280 - * @param start starting floating-point value
64.1281 - * @param direction value indicating which of
64.1282 - * {@code start}'s neighbors or {@code start} should
64.1283 - * be returned
64.1284 - * @return The floating-point number adjacent to {@code start} in the
64.1285 - * direction of {@code direction}.
64.1286 - * @since 1.6
64.1287 - */
64.1288 - public static double nextAfter(double start, double direction) {
64.1289 - throw new UnsupportedOperationException();
64.1290 - }
64.1291 -
64.1292 - /**
64.1293 - * Returns the floating-point number adjacent to the first
64.1294 - * argument in the direction of the second argument. If both
64.1295 - * arguments compare as equal a value equivalent to the second argument
64.1296 - * is returned.
64.1297 - *
64.1298 - * <p>Special cases:
64.1299 - * <ul>
64.1300 - * <li> If either argument is a NaN, then NaN is returned.
64.1301 - *
64.1302 - * <li> If both arguments are signed zeros, a value equivalent
64.1303 - * to {@code direction} is returned.
64.1304 - *
64.1305 - * <li> If {@code start} is
64.1306 - * ±{@link Float#MIN_VALUE} and {@code direction}
64.1307 - * has a value such that the result should have a smaller
64.1308 - * magnitude, then a zero with the same sign as {@code start}
64.1309 - * is returned.
64.1310 - *
64.1311 - * <li> If {@code start} is infinite and
64.1312 - * {@code direction} has a value such that the result should
64.1313 - * have a smaller magnitude, {@link Float#MAX_VALUE} with the
64.1314 - * same sign as {@code start} is returned.
64.1315 - *
64.1316 - * <li> If {@code start} is equal to ±
64.1317 - * {@link Float#MAX_VALUE} and {@code direction} has a
64.1318 - * value such that the result should have a larger magnitude, an
64.1319 - * infinity with same sign as {@code start} is returned.
64.1320 - * </ul>
64.1321 - *
64.1322 - * @param start starting floating-point value
64.1323 - * @param direction value indicating which of
64.1324 - * {@code start}'s neighbors or {@code start} should
64.1325 - * be returned
64.1326 - * @return The floating-point number adjacent to {@code start} in the
64.1327 - * direction of {@code direction}.
64.1328 - * @since 1.6
64.1329 - */
64.1330 - public static float nextAfter(float start, double direction) {
64.1331 - throw new UnsupportedOperationException();
64.1332 - }
64.1333 -
64.1334 - /**
64.1335 - * Returns the floating-point value adjacent to {@code d} in
64.1336 - * the direction of positive infinity. This method is
64.1337 - * semantically equivalent to {@code nextAfter(d,
64.1338 - * Double.POSITIVE_INFINITY)}; however, a {@code nextUp}
64.1339 - * implementation may run faster than its equivalent
64.1340 - * {@code nextAfter} call.
64.1341 - *
64.1342 - * <p>Special Cases:
64.1343 - * <ul>
64.1344 - * <li> If the argument is NaN, the result is NaN.
64.1345 - *
64.1346 - * <li> If the argument is positive infinity, the result is
64.1347 - * positive infinity.
64.1348 - *
64.1349 - * <li> If the argument is zero, the result is
64.1350 - * {@link Double#MIN_VALUE}
64.1351 - *
64.1352 - * </ul>
64.1353 - *
64.1354 - * @param d starting floating-point value
64.1355 - * @return The adjacent floating-point value closer to positive
64.1356 - * infinity.
64.1357 - * @since 1.6
64.1358 - */
64.1359 - public static double nextUp(double d) {
64.1360 - throw new UnsupportedOperationException();
64.1361 - }
64.1362 -
64.1363 - /**
64.1364 - * Returns the floating-point value adjacent to {@code f} in
64.1365 - * the direction of positive infinity. This method is
64.1366 - * semantically equivalent to {@code nextAfter(f,
64.1367 - * Float.POSITIVE_INFINITY)}; however, a {@code nextUp}
64.1368 - * implementation may run faster than its equivalent
64.1369 - * {@code nextAfter} call.
64.1370 - *
64.1371 - * <p>Special Cases:
64.1372 - * <ul>
64.1373 - * <li> If the argument is NaN, the result is NaN.
64.1374 - *
64.1375 - * <li> If the argument is positive infinity, the result is
64.1376 - * positive infinity.
64.1377 - *
64.1378 - * <li> If the argument is zero, the result is
64.1379 - * {@link Float#MIN_VALUE}
64.1380 - *
64.1381 - * </ul>
64.1382 - *
64.1383 - * @param f starting floating-point value
64.1384 - * @return The adjacent floating-point value closer to positive
64.1385 - * infinity.
64.1386 - * @since 1.6
64.1387 - */
64.1388 - public static float nextUp(float f) {
64.1389 - throw new UnsupportedOperationException();
64.1390 - }
64.1391 -
64.1392 -
64.1393 - /**
64.1394 - * Return {@code d} ×
64.1395 - * 2<sup>{@code scaleFactor}</sup> rounded as if performed
64.1396 - * by a single correctly rounded floating-point multiply to a
64.1397 - * member of the double value set. See the Java
64.1398 - * Language Specification for a discussion of floating-point
64.1399 - * value sets. If the exponent of the result is between {@link
64.1400 - * Double#MIN_EXPONENT} and {@link Double#MAX_EXPONENT}, the
64.1401 - * answer is calculated exactly. If the exponent of the result
64.1402 - * would be larger than {@code Double.MAX_EXPONENT}, an
64.1403 - * infinity is returned. Note that if the result is subnormal,
64.1404 - * precision may be lost; that is, when {@code scalb(x, n)}
64.1405 - * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
64.1406 - * <i>x</i>. When the result is non-NaN, the result has the same
64.1407 - * sign as {@code d}.
64.1408 - *
64.1409 - * <p>Special cases:
64.1410 - * <ul>
64.1411 - * <li> If the first argument is NaN, NaN is returned.
64.1412 - * <li> If the first argument is infinite, then an infinity of the
64.1413 - * same sign is returned.
64.1414 - * <li> If the first argument is zero, then a zero of the same
64.1415 - * sign is returned.
64.1416 - * </ul>
64.1417 - *
64.1418 - * @param d number to be scaled by a power of two.
64.1419 - * @param scaleFactor power of 2 used to scale {@code d}
64.1420 - * @return {@code d} × 2<sup>{@code scaleFactor}</sup>
64.1421 - * @since 1.6
64.1422 - */
64.1423 - public static double scalb(double d, int scaleFactor) {
64.1424 - throw new UnsupportedOperationException();
64.1425 - }
64.1426 -
64.1427 - /**
64.1428 - * Return {@code f} ×
64.1429 - * 2<sup>{@code scaleFactor}</sup> rounded as if performed
64.1430 - * by a single correctly rounded floating-point multiply to a
64.1431 - * member of the float value set. See the Java
64.1432 - * Language Specification for a discussion of floating-point
64.1433 - * value sets. If the exponent of the result is between {@link
64.1434 - * Float#MIN_EXPONENT} and {@link Float#MAX_EXPONENT}, the
64.1435 - * answer is calculated exactly. If the exponent of the result
64.1436 - * would be larger than {@code Float.MAX_EXPONENT}, an
64.1437 - * infinity is returned. Note that if the result is subnormal,
64.1438 - * precision may be lost; that is, when {@code scalb(x, n)}
64.1439 - * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
64.1440 - * <i>x</i>. When the result is non-NaN, the result has the same
64.1441 - * sign as {@code f}.
64.1442 - *
64.1443 - * <p>Special cases:
64.1444 - * <ul>
64.1445 - * <li> If the first argument is NaN, NaN is returned.
64.1446 - * <li> If the first argument is infinite, then an infinity of the
64.1447 - * same sign is returned.
64.1448 - * <li> If the first argument is zero, then a zero of the same
64.1449 - * sign is returned.
64.1450 - * </ul>
64.1451 - *
64.1452 - * @param f number to be scaled by a power of two.
64.1453 - * @param scaleFactor power of 2 used to scale {@code f}
64.1454 - * @return {@code f} × 2<sup>{@code scaleFactor}</sup>
64.1455 - * @since 1.6
64.1456 - */
64.1457 - public static float scalb(float f, int scaleFactor) {
64.1458 - throw new UnsupportedOperationException();
64.1459 - }
64.1460 -}
65.1 --- a/emul/src/main/java/java/lang/String.java Thu Oct 11 06:15:22 2012 -0700
65.2 +++ b/emul/src/main/java/java/lang/String.java Wed Jan 23 20:16:48 2013 +0100
65.3 @@ -25,8 +25,11 @@
65.4
65.5 package java.lang;
65.6
65.7 +import java.util.Comparator;
65.8 import org.apidesign.bck2brwsr.core.ExtraJavaScript;
65.9 -import java.util.Comparator;
65.10 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
65.11 +import org.apidesign.bck2brwsr.core.JavaScriptOnly;
65.12 +import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
65.13
65.14 /**
65.15 * The <code>String</code> class represents character strings. All
65.16 @@ -99,25 +102,25 @@
65.17
65.18 @ExtraJavaScript(
65.19 resource="/org/apidesign/vm4brwsr/emul/java_lang_String.js",
65.20 - processByteCode=false
65.21 + processByteCode=true
65.22 )
65.23 +@JavaScriptPrototype(container = "String.prototype", prototype = "new String")
65.24 public final class String
65.25 implements java.io.Serializable, Comparable<String>, CharSequence
65.26 {
65.27 - /** The value is used for character storage. */
65.28 - private final char value[];
65.29 -
65.30 - /** The offset is the first index of the storage that is used. */
65.31 - private final int offset;
65.32 -
65.33 - /** The count is the number of characters in the String. */
65.34 - private final int count;
65.35 -
65.36 - /** Cache the hash code for the string */
65.37 - private int hash; // Default to 0
65.38 + /** real string to delegate to */
65.39 + private Object r;
65.40
65.41 /** use serialVersionUID from JDK 1.0.2 for interoperability */
65.42 private static final long serialVersionUID = -6849794470754667710L;
65.43 +
65.44 + @JavaScriptOnly(name="toString", value="function() { return this.fld_r; }")
65.45 + private static void jsToString() {
65.46 + }
65.47 +
65.48 + @JavaScriptOnly(name="valueOf", value="function() { return this.toString().valueOf(); }")
65.49 + private static void jsValudOf() {
65.50 + }
65.51
65.52 /**
65.53 * Class String is special cased within the Serialization Stream Protocol.
65.54 @@ -140,9 +143,7 @@
65.55 * unnecessary since Strings are immutable.
65.56 */
65.57 public String() {
65.58 - this.offset = 0;
65.59 - this.count = 0;
65.60 - this.value = new char[0];
65.61 + this.r = "";
65.62 }
65.63
65.64 /**
65.65 @@ -156,23 +157,7 @@
65.66 * A {@code String}
65.67 */
65.68 public String(String original) {
65.69 - int size = original.count;
65.70 - char[] originalValue = original.value;
65.71 - char[] v;
65.72 - if (originalValue.length > size) {
65.73 - // The array representing the String is bigger than the new
65.74 - // String itself. Perhaps this constructor is being called
65.75 - // in order to trim the baggage, so make a copy of the array.
65.76 - int off = original.offset;
65.77 - v = copyOfRange(originalValue, off, off+size);
65.78 - } else {
65.79 - // The array representing the String is the same
65.80 - // size as the String, so no point in making a copy.
65.81 - v = originalValue;
65.82 - }
65.83 - this.offset = 0;
65.84 - this.count = size;
65.85 - this.value = v;
65.86 + this.r = original.toString();
65.87 }
65.88
65.89 /**
65.90 @@ -184,11 +169,13 @@
65.91 * @param value
65.92 * The initial value of the string
65.93 */
65.94 + @JavaScriptBody(args = { "charArr" }, body=
65.95 + "for (var i = 0; i < charArr.length; i++) {\n"
65.96 + + " if (typeof charArr[i] === 'number') charArr[i] = String.fromCharCode(charArr[i]);\n"
65.97 + + "}\n"
65.98 + + "this.fld_r = charArr.join('');\n"
65.99 + )
65.100 public String(char value[]) {
65.101 - int size = value.length;
65.102 - this.offset = 0;
65.103 - this.count = size;
65.104 - this.value = copyOf(value, size);
65.105 }
65.106
65.107 /**
65.108 @@ -212,20 +199,14 @@
65.109 * If the {@code offset} and {@code count} arguments index
65.110 * characters outside the bounds of the {@code value} array
65.111 */
65.112 + @JavaScriptBody(args = { "charArr", "off", "cnt" }, body =
65.113 + "var up = off + cnt;\n" +
65.114 + "for (var i = off; i < up; i++) {\n" +
65.115 + " if (typeof charArr[i] === 'number') charArr[i] = String.fromCharCode(charArr[i]);\n" +
65.116 + "}\n" +
65.117 + "this.fld_r = charArr.slice(off, up).join(\"\");\n"
65.118 + )
65.119 public String(char value[], int offset, int count) {
65.120 - if (offset < 0) {
65.121 - throw new StringIndexOutOfBoundsException(offset);
65.122 - }
65.123 - if (count < 0) {
65.124 - throw new StringIndexOutOfBoundsException(count);
65.125 - }
65.126 - // Note: offset or count might be near -1>>>1.
65.127 - if (offset > value.length - count) {
65.128 - throw new StringIndexOutOfBoundsException(offset + count);
65.129 - }
65.130 - this.offset = 0;
65.131 - this.count = count;
65.132 - this.value = copyOfRange(value, offset, offset+count);
65.133 }
65.134
65.135 /**
65.136 @@ -292,9 +273,7 @@
65.137 Character.toSurrogates(c, v, j++);
65.138 }
65.139
65.140 - this.value = v;
65.141 - this.count = n;
65.142 - this.offset = 0;
65.143 + this.r = new String(v, 0, n);
65.144 }
65.145
65.146 /**
65.147 @@ -351,9 +330,7 @@
65.148 value[i] = (char) (hibyte | (ascii[i + offset] & 0xff));
65.149 }
65.150 }
65.151 - this.offset = 0;
65.152 - this.count = count;
65.153 - this.value = value;
65.154 + this.r = new String(value, 0, count);
65.155 }
65.156
65.157 /**
65.158 @@ -578,9 +555,7 @@
65.159 for (int i = 0; i < length; i++) {
65.160 v[i] = (char)bytes[offset++];
65.161 }
65.162 - this.offset = 0;
65.163 - this.count = v.length;
65.164 - this.value = v;
65.165 + this.r = new String(v, 0, v.length);
65.166 }
65.167
65.168 /**
65.169 @@ -613,10 +588,7 @@
65.170 * A {@code StringBuffer}
65.171 */
65.172 public String(StringBuffer buffer) {
65.173 - String result = buffer.toString();
65.174 - this.value = result.value;
65.175 - this.count = result.count;
65.176 - this.offset = result.offset;
65.177 + this.r = buffer.toString();
65.178 }
65.179
65.180 /**
65.181 @@ -635,18 +607,7 @@
65.182 * @since 1.5
65.183 */
65.184 public String(StringBuilder builder) {
65.185 - String result = builder.toString();
65.186 - this.value = result.value;
65.187 - this.count = result.count;
65.188 - this.offset = result.offset;
65.189 - }
65.190 -
65.191 -
65.192 - // Package private constructor which shares value array for speed.
65.193 - String(int offset, int count, char value[]) {
65.194 - this.value = value;
65.195 - this.offset = offset;
65.196 - this.count = count;
65.197 + this.r = builder.toString();
65.198 }
65.199
65.200 /**
65.201 @@ -657,8 +618,9 @@
65.202 * @return the length of the sequence of characters represented by this
65.203 * object.
65.204 */
65.205 + @JavaScriptBody(args = {}, body = "return this.toString().length;")
65.206 public int length() {
65.207 - return count;
65.208 + throw new UnsupportedOperationException();
65.209 }
65.210
65.211 /**
65.212 @@ -669,8 +631,9 @@
65.213 *
65.214 * @since 1.6
65.215 */
65.216 + @JavaScriptBody(args = {}, body="return this.toString().length === 0;")
65.217 public boolean isEmpty() {
65.218 - return count == 0;
65.219 + return length() == 0;
65.220 }
65.221
65.222 /**
65.223 @@ -691,11 +654,11 @@
65.224 * argument is negative or not less than the length of this
65.225 * string.
65.226 */
65.227 + @JavaScriptBody(args = { "index" },
65.228 + body = "return this.toString().charCodeAt(index);"
65.229 + )
65.230 public char charAt(int index) {
65.231 - if ((index < 0) || (index >= count)) {
65.232 - throw new StringIndexOutOfBoundsException(index);
65.233 - }
65.234 - return value[index + offset];
65.235 + throw new UnsupportedOperationException();
65.236 }
65.237
65.238 /**
65.239 @@ -721,10 +684,10 @@
65.240 * @since 1.5
65.241 */
65.242 public int codePointAt(int index) {
65.243 - if ((index < 0) || (index >= count)) {
65.244 + if ((index < 0) || (index >= length())) {
65.245 throw new StringIndexOutOfBoundsException(index);
65.246 }
65.247 - return Character.codePointAtImpl(value, offset + index, offset + count);
65.248 + return Character.codePointAtImpl(toCharArray(), offset() + index, offset() + length());
65.249 }
65.250
65.251 /**
65.252 @@ -751,10 +714,10 @@
65.253 */
65.254 public int codePointBefore(int index) {
65.255 int i = index - 1;
65.256 - if ((i < 0) || (i >= count)) {
65.257 + if ((i < 0) || (i >= length())) {
65.258 throw new StringIndexOutOfBoundsException(index);
65.259 }
65.260 - return Character.codePointBeforeImpl(value, offset + index, offset);
65.261 + return Character.codePointBeforeImpl(toCharArray(), offset() + index, offset());
65.262 }
65.263
65.264 /**
65.265 @@ -779,10 +742,10 @@
65.266 * @since 1.5
65.267 */
65.268 public int codePointCount(int beginIndex, int endIndex) {
65.269 - if (beginIndex < 0 || endIndex > count || beginIndex > endIndex) {
65.270 + if (beginIndex < 0 || endIndex > length() || beginIndex > endIndex) {
65.271 throw new IndexOutOfBoundsException();
65.272 }
65.273 - return Character.codePointCountImpl(value, offset+beginIndex, endIndex-beginIndex);
65.274 + return Character.codePointCountImpl(toCharArray(), offset()+beginIndex, endIndex-beginIndex);
65.275 }
65.276
65.277 /**
65.278 @@ -806,19 +769,25 @@
65.279 * @since 1.5
65.280 */
65.281 public int offsetByCodePoints(int index, int codePointOffset) {
65.282 - if (index < 0 || index > count) {
65.283 + if (index < 0 || index > length()) {
65.284 throw new IndexOutOfBoundsException();
65.285 }
65.286 - return Character.offsetByCodePointsImpl(value, offset, count,
65.287 - offset+index, codePointOffset) - offset;
65.288 + return Character.offsetByCodePointsImpl(toCharArray(), offset(), length(),
65.289 + offset()+index, codePointOffset) - offset();
65.290 }
65.291
65.292 /**
65.293 * Copy characters from this string into dst starting at dstBegin.
65.294 * This method doesn't perform any range checking.
65.295 */
65.296 + @JavaScriptBody(args = { "arr", "to" }, body =
65.297 + "var s = this.toString();\n" +
65.298 + "for (var i = 0; i < s.length; i++) {\n" +
65.299 + " arr[to++] = s[i];\n" +
65.300 + "}"
65.301 + )
65.302 void getChars(char dst[], int dstBegin) {
65.303 - arraycopy(value, offset, dst, dstBegin, count);
65.304 + AbstractStringBuilder.arraycopy(toCharArray(), offset(), dst, dstBegin, length());
65.305 }
65.306
65.307 /**
65.308 @@ -851,17 +820,23 @@
65.309 * <li><code>dstBegin+(srcEnd-srcBegin)</code> is larger than
65.310 * <code>dst.length</code></ul>
65.311 */
65.312 + @JavaScriptBody(args = { "beg", "end", "arr", "dst" }, body=
65.313 + "var s = this.toString();\n" +
65.314 + "while (beg < end) {\n" +
65.315 + " arr[dst++] = s[beg++];\n" +
65.316 + "}\n"
65.317 + )
65.318 public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
65.319 if (srcBegin < 0) {
65.320 throw new StringIndexOutOfBoundsException(srcBegin);
65.321 }
65.322 - if (srcEnd > count) {
65.323 + if (srcEnd > length()) {
65.324 throw new StringIndexOutOfBoundsException(srcEnd);
65.325 }
65.326 if (srcBegin > srcEnd) {
65.327 throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
65.328 }
65.329 - arraycopy(value, offset + srcBegin, dst, dstBegin,
65.330 + AbstractStringBuilder.arraycopy(toCharArray(), offset() + srcBegin, dst, dstBegin,
65.331 srcEnd - srcBegin);
65.332 }
65.333
65.334 @@ -913,16 +888,16 @@
65.335 if (srcBegin < 0) {
65.336 throw new StringIndexOutOfBoundsException(srcBegin);
65.337 }
65.338 - if (srcEnd > count) {
65.339 + if (srcEnd > length()) {
65.340 throw new StringIndexOutOfBoundsException(srcEnd);
65.341 }
65.342 if (srcBegin > srcEnd) {
65.343 throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
65.344 }
65.345 int j = dstBegin;
65.346 - int n = offset + srcEnd;
65.347 - int i = offset + srcBegin;
65.348 - char[] val = value; /* avoid getfield opcode */
65.349 + int n = offset() + srcEnd;
65.350 + int i = offset() + srcBegin;
65.351 + char[] val = toCharArray(); /* avoid getfield opcode */
65.352
65.353 while (i < n) {
65.354 dst[j++] = (byte)val[i++];
65.355 @@ -1018,18 +993,22 @@
65.356 * @see #compareTo(String)
65.357 * @see #equalsIgnoreCase(String)
65.358 */
65.359 + @JavaScriptBody(args = { "obj" }, body =
65.360 + "return obj != null && obj.$instOf_java_lang_String && "
65.361 + + "this.toString() === obj.toString();"
65.362 + )
65.363 public boolean equals(Object anObject) {
65.364 if (this == anObject) {
65.365 return true;
65.366 }
65.367 if (anObject instanceof String) {
65.368 String anotherString = (String)anObject;
65.369 - int n = count;
65.370 - if (n == anotherString.count) {
65.371 - char v1[] = value;
65.372 - char v2[] = anotherString.value;
65.373 - int i = offset;
65.374 - int j = anotherString.offset;
65.375 + int n = length();
65.376 + if (n == anotherString.length()) {
65.377 + char v1[] = toCharArray();
65.378 + char v2[] = anotherString.toCharArray();
65.379 + int i = offset();
65.380 + int j = anotherString.offset();
65.381 while (n-- != 0) {
65.382 if (v1[i++] != v2[j++])
65.383 return false;
65.384 @@ -1075,15 +1054,15 @@
65.385 * @since 1.5
65.386 */
65.387 public boolean contentEquals(CharSequence cs) {
65.388 - if (count != cs.length())
65.389 + if (length() != cs.length())
65.390 return false;
65.391 // Argument is a StringBuffer, StringBuilder
65.392 if (cs instanceof AbstractStringBuilder) {
65.393 - char v1[] = value;
65.394 + char v1[] = toCharArray();
65.395 char v2[] = ((AbstractStringBuilder)cs).getValue();
65.396 - int i = offset;
65.397 + int i = offset();
65.398 int j = 0;
65.399 - int n = count;
65.400 + int n = length();
65.401 while (n-- != 0) {
65.402 if (v1[i++] != v2[j++])
65.403 return false;
65.404 @@ -1094,10 +1073,10 @@
65.405 if (cs.equals(this))
65.406 return true;
65.407 // Argument is a generic CharSequence
65.408 - char v1[] = value;
65.409 - int i = offset;
65.410 + char v1[] = toCharArray();
65.411 + int i = offset();
65.412 int j = 0;
65.413 - int n = count;
65.414 + int n = length();
65.415 while (n-- != 0) {
65.416 if (v1[i++] != cs.charAt(j++))
65.417 return false;
65.418 @@ -1135,8 +1114,8 @@
65.419 */
65.420 public boolean equalsIgnoreCase(String anotherString) {
65.421 return (this == anotherString) ? true :
65.422 - (anotherString != null) && (anotherString.count == count) &&
65.423 - regionMatches(true, 0, anotherString, 0, count);
65.424 + (anotherString != null) && (anotherString.length() == length()) &&
65.425 + regionMatches(true, 0, anotherString, 0, length());
65.426 }
65.427
65.428 /**
65.429 @@ -1181,13 +1160,13 @@
65.430 * lexicographically greater than the string argument.
65.431 */
65.432 public int compareTo(String anotherString) {
65.433 - int len1 = count;
65.434 - int len2 = anotherString.count;
65.435 + int len1 = length();
65.436 + int len2 = anotherString.length();
65.437 int n = Math.min(len1, len2);
65.438 - char v1[] = value;
65.439 - char v2[] = anotherString.value;
65.440 - int i = offset;
65.441 - int j = anotherString.offset;
65.442 + char v1[] = toCharArray();
65.443 + char v2[] = anotherString.toCharArray();
65.444 + int i = offset();
65.445 + int j = anotherString.offset();
65.446
65.447 if (i == j) {
65.448 int k = i;
65.449 @@ -1226,6 +1205,11 @@
65.450 */
65.451 public static final Comparator<String> CASE_INSENSITIVE_ORDER
65.452 = new CaseInsensitiveComparator();
65.453 +
65.454 + private static int offset() {
65.455 + return 0;
65.456 + }
65.457 +
65.458 private static class CaseInsensitiveComparator
65.459 implements Comparator<String>, java.io.Serializable {
65.460 // use serialVersionUID from JDK 1.2.2 for interoperability
65.461 @@ -1312,13 +1296,13 @@
65.462 */
65.463 public boolean regionMatches(int toffset, String other, int ooffset,
65.464 int len) {
65.465 - char ta[] = value;
65.466 - int to = offset + toffset;
65.467 - char pa[] = other.value;
65.468 - int po = other.offset + ooffset;
65.469 + char ta[] = toCharArray();
65.470 + int to = offset() + toffset;
65.471 + char pa[] = other.toCharArray();
65.472 + int po = other.offset() + ooffset;
65.473 // Note: toffset, ooffset, or len might be near -1>>>1.
65.474 - if ((ooffset < 0) || (toffset < 0) || (toffset > (long)count - len)
65.475 - || (ooffset > (long)other.count - len)) {
65.476 + if ((ooffset < 0) || (toffset < 0) || (toffset > (long)length() - len)
65.477 + || (ooffset > (long)other.length() - len)) {
65.478 return false;
65.479 }
65.480 while (len-- > 0) {
65.481 @@ -1381,13 +1365,13 @@
65.482 */
65.483 public boolean regionMatches(boolean ignoreCase, int toffset,
65.484 String other, int ooffset, int len) {
65.485 - char ta[] = value;
65.486 - int to = offset + toffset;
65.487 - char pa[] = other.value;
65.488 - int po = other.offset + ooffset;
65.489 + char ta[] = toCharArray();
65.490 + int to = offset() + toffset;
65.491 + char pa[] = other.toCharArray();
65.492 + int po = other.offset() + ooffset;
65.493 // Note: toffset, ooffset, or len might be near -1>>>1.
65.494 - if ((ooffset < 0) || (toffset < 0) || (toffset > (long)count - len) ||
65.495 - (ooffset > (long)other.count - len)) {
65.496 + if ((ooffset < 0) || (toffset < 0) || (toffset > (long)length() - len) ||
65.497 + (ooffset > (long)other.length() - len)) {
65.498 return false;
65.499 }
65.500 while (len-- > 0) {
65.501 @@ -1436,14 +1420,18 @@
65.502 * this.substring(toffset).startsWith(prefix)
65.503 * </pre>
65.504 */
65.505 + @JavaScriptBody(args = { "find", "from" }, body=
65.506 + "find = find.toString();\n" +
65.507 + "return this.toString().substring(from, from + find.length) === find;\n"
65.508 + )
65.509 public boolean startsWith(String prefix, int toffset) {
65.510 - char ta[] = value;
65.511 - int to = offset + toffset;
65.512 - char pa[] = prefix.value;
65.513 - int po = prefix.offset;
65.514 - int pc = prefix.count;
65.515 + char ta[] = toCharArray();
65.516 + int to = offset() + toffset;
65.517 + char pa[] = prefix.toCharArray();
65.518 + int po = prefix.offset();
65.519 + int pc = prefix.length();
65.520 // Note: toffset might be near -1>>>1.
65.521 - if ((toffset < 0) || (toffset > count - pc)) {
65.522 + if ((toffset < 0) || (toffset > length() - pc)) {
65.523 return false;
65.524 }
65.525 while (--pc >= 0) {
65.526 @@ -1483,7 +1471,7 @@
65.527 * as determined by the {@link #equals(Object)} method.
65.528 */
65.529 public boolean endsWith(String suffix) {
65.530 - return startsWith(suffix, count - suffix.count);
65.531 + return startsWith(suffix, length() - suffix.length());
65.532 }
65.533
65.534 /**
65.535 @@ -1500,16 +1488,17 @@
65.536 * @return a hash code value for this object.
65.537 */
65.538 public int hashCode() {
65.539 - int h = hash;
65.540 - if (h == 0 && count > 0) {
65.541 - int off = offset;
65.542 - char val[] = value;
65.543 - int len = count;
65.544 + return super.hashCode();
65.545 + }
65.546 + int computeHashCode() {
65.547 + int h = 0;
65.548 + if (h == 0 && length() > 0) {
65.549 + int off = offset();
65.550 + int len = length();
65.551
65.552 for (int i = 0; i < len; i++) {
65.553 - h = 31*h + val[off++];
65.554 + h = 31*h + charAt(off++);
65.555 }
65.556 - hash = h;
65.557 }
65.558 return h;
65.559 }
65.560 @@ -1581,10 +1570,14 @@
65.561 * than or equal to <code>fromIndex</code>, or <code>-1</code>
65.562 * if the character does not occur.
65.563 */
65.564 + @JavaScriptBody(args = { "ch", "from" }, body =
65.565 + "if (typeof ch === 'number') ch = String.fromCharCode(ch);\n" +
65.566 + "return this.toString().indexOf(ch, from);\n"
65.567 + )
65.568 public int indexOf(int ch, int fromIndex) {
65.569 if (fromIndex < 0) {
65.570 fromIndex = 0;
65.571 - } else if (fromIndex >= count) {
65.572 + } else if (fromIndex >= length()) {
65.573 // Note: fromIndex might be near -1>>>1.
65.574 return -1;
65.575 }
65.576 @@ -1592,9 +1585,9 @@
65.577 if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
65.578 // handle most cases here (ch is a BMP code point or a
65.579 // negative value (invalid code point))
65.580 - final char[] value = this.value;
65.581 - final int offset = this.offset;
65.582 - final int max = offset + count;
65.583 + final char[] value = this.toCharArray();
65.584 + final int offset = this.offset();
65.585 + final int max = offset + length();
65.586 for (int i = offset + fromIndex; i < max ; i++) {
65.587 if (value[i] == ch) {
65.588 return i - offset;
65.589 @@ -1611,11 +1604,11 @@
65.590 */
65.591 private int indexOfSupplementary(int ch, int fromIndex) {
65.592 if (Character.isValidCodePoint(ch)) {
65.593 - final char[] value = this.value;
65.594 - final int offset = this.offset;
65.595 + final char[] value = this.toCharArray();
65.596 + final int offset = this.offset();
65.597 final char hi = Character.highSurrogate(ch);
65.598 final char lo = Character.lowSurrogate(ch);
65.599 - final int max = offset + count - 1;
65.600 + final int max = offset + length() - 1;
65.601 for (int i = offset + fromIndex; i < max; i++) {
65.602 if (value[i] == hi && value[i+1] == lo) {
65.603 return i - offset;
65.604 @@ -1649,7 +1642,7 @@
65.605 * <code>-1</code> if the character does not occur.
65.606 */
65.607 public int lastIndexOf(int ch) {
65.608 - return lastIndexOf(ch, count - 1);
65.609 + return lastIndexOf(ch, length() - 1);
65.610 }
65.611
65.612 /**
65.613 @@ -1686,13 +1679,17 @@
65.614 * than or equal to <code>fromIndex</code>, or <code>-1</code>
65.615 * if the character does not occur before that point.
65.616 */
65.617 + @JavaScriptBody(args = { "ch", "from" }, body =
65.618 + "if (typeof ch === 'number') ch = String.fromCharCode(ch);\n" +
65.619 + "return this.toString().lastIndexOf(ch, from);"
65.620 + )
65.621 public int lastIndexOf(int ch, int fromIndex) {
65.622 if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
65.623 // handle most cases here (ch is a BMP code point or a
65.624 // negative value (invalid code point))
65.625 - final char[] value = this.value;
65.626 - final int offset = this.offset;
65.627 - int i = offset + Math.min(fromIndex, count - 1);
65.628 + final char[] value = this.toCharArray();
65.629 + final int offset = this.offset();
65.630 + int i = offset + Math.min(fromIndex, length() - 1);
65.631 for (; i >= offset ; i--) {
65.632 if (value[i] == ch) {
65.633 return i - offset;
65.634 @@ -1709,11 +1706,11 @@
65.635 */
65.636 private int lastIndexOfSupplementary(int ch, int fromIndex) {
65.637 if (Character.isValidCodePoint(ch)) {
65.638 - final char[] value = this.value;
65.639 - final int offset = this.offset;
65.640 + final char[] value = this.toCharArray();
65.641 + final int offset = this.offset();
65.642 char hi = Character.highSurrogate(ch);
65.643 char lo = Character.lowSurrogate(ch);
65.644 - int i = offset + Math.min(fromIndex, count - 2);
65.645 + int i = offset + Math.min(fromIndex, length() - 2);
65.646 for (; i >= offset; i--) {
65.647 if (value[i] == hi && value[i+1] == lo) {
65.648 return i - offset;
65.649 @@ -1757,61 +1754,10 @@
65.650 * starting at the specified index,
65.651 * or {@code -1} if there is no such occurrence.
65.652 */
65.653 - public int indexOf(String str, int fromIndex) {
65.654 - return indexOf(value, offset, count,
65.655 - str.value, str.offset, str.count, fromIndex);
65.656 - }
65.657 -
65.658 - /**
65.659 - * Code shared by String and StringBuffer to do searches. The
65.660 - * source is the character array being searched, and the target
65.661 - * is the string being searched for.
65.662 - *
65.663 - * @param source the characters being searched.
65.664 - * @param sourceOffset offset of the source string.
65.665 - * @param sourceCount count of the source string.
65.666 - * @param target the characters being searched for.
65.667 - * @param targetOffset offset of the target string.
65.668 - * @param targetCount count of the target string.
65.669 - * @param fromIndex the index to begin searching from.
65.670 - */
65.671 - static int indexOf(char[] source, int sourceOffset, int sourceCount,
65.672 - char[] target, int targetOffset, int targetCount,
65.673 - int fromIndex) {
65.674 - if (fromIndex >= sourceCount) {
65.675 - return (targetCount == 0 ? sourceCount : -1);
65.676 - }
65.677 - if (fromIndex < 0) {
65.678 - fromIndex = 0;
65.679 - }
65.680 - if (targetCount == 0) {
65.681 - return fromIndex;
65.682 - }
65.683 -
65.684 - char first = target[targetOffset];
65.685 - int max = sourceOffset + (sourceCount - targetCount);
65.686 -
65.687 - for (int i = sourceOffset + fromIndex; i <= max; i++) {
65.688 - /* Look for first character. */
65.689 - if (source[i] != first) {
65.690 - while (++i <= max && source[i] != first);
65.691 - }
65.692 -
65.693 - /* Found first character, now look at the rest of v2 */
65.694 - if (i <= max) {
65.695 - int j = i + 1;
65.696 - int end = j + targetCount - 1;
65.697 - for (int k = targetOffset + 1; j < end && source[j] ==
65.698 - target[k]; j++, k++);
65.699 -
65.700 - if (j == end) {
65.701 - /* Found whole string. */
65.702 - return i - sourceOffset;
65.703 - }
65.704 - }
65.705 - }
65.706 - return -1;
65.707 - }
65.708 + @JavaScriptBody(args = { "str", "fromIndex" }, body =
65.709 + "return this.toString().indexOf(str.toString(), fromIndex);"
65.710 + )
65.711 + public native int indexOf(String str, int fromIndex);
65.712
65.713 /**
65.714 * Returns the index within this string of the last occurrence of the
65.715 @@ -1829,7 +1775,7 @@
65.716 * or {@code -1} if there is no such occurrence.
65.717 */
65.718 public int lastIndexOf(String str) {
65.719 - return lastIndexOf(str, count);
65.720 + return lastIndexOf(str, length());
65.721 }
65.722
65.723 /**
65.724 @@ -1848,9 +1794,11 @@
65.725 * searching backward from the specified index,
65.726 * or {@code -1} if there is no such occurrence.
65.727 */
65.728 + @JavaScriptBody(args = { "s", "from" }, body =
65.729 + "return this.toString().lastIndexOf(s.toString(), from);"
65.730 + )
65.731 public int lastIndexOf(String str, int fromIndex) {
65.732 - return lastIndexOf(value, offset, count,
65.733 - str.value, str.offset, str.count, fromIndex);
65.734 + return lastIndexOf(toCharArray(), offset(), length(), str.toCharArray(), str.offset(), str.length(), fromIndex);
65.735 }
65.736
65.737 /**
65.738 @@ -1930,7 +1878,7 @@
65.739 * length of this <code>String</code> object.
65.740 */
65.741 public String substring(int beginIndex) {
65.742 - return substring(beginIndex, count);
65.743 + return substring(beginIndex, length());
65.744 }
65.745
65.746 /**
65.747 @@ -1955,18 +1903,21 @@
65.748 * <code>beginIndex</code> is larger than
65.749 * <code>endIndex</code>.
65.750 */
65.751 + @JavaScriptBody(args = { "beginIndex", "endIndex" }, body =
65.752 + "return this.toString().substring(beginIndex, endIndex);"
65.753 + )
65.754 public String substring(int beginIndex, int endIndex) {
65.755 if (beginIndex < 0) {
65.756 throw new StringIndexOutOfBoundsException(beginIndex);
65.757 }
65.758 - if (endIndex > count) {
65.759 + if (endIndex > length()) {
65.760 throw new StringIndexOutOfBoundsException(endIndex);
65.761 }
65.762 if (beginIndex > endIndex) {
65.763 throw new StringIndexOutOfBoundsException(endIndex - beginIndex);
65.764 }
65.765 - return ((beginIndex == 0) && (endIndex == count)) ? this :
65.766 - new String(offset + beginIndex, endIndex - beginIndex, value);
65.767 + return ((beginIndex == 0) && (endIndex == length())) ? this :
65.768 + new String(toCharArray(), offset() + beginIndex, endIndex - beginIndex);
65.769 }
65.770
65.771 /**
65.772 @@ -2026,10 +1977,10 @@
65.773 if (otherLen == 0) {
65.774 return this;
65.775 }
65.776 - char buf[] = new char[count + otherLen];
65.777 - getChars(0, count, buf, 0);
65.778 - str.getChars(0, otherLen, buf, count);
65.779 - return new String(0, count + otherLen, buf);
65.780 + char buf[] = new char[length() + otherLen];
65.781 + getChars(0, length(), buf, 0);
65.782 + str.getChars(0, otherLen, buf, length());
65.783 + return new String(buf, 0, length() + otherLen);
65.784 }
65.785
65.786 /**
65.787 @@ -2061,12 +2012,24 @@
65.788 * @return a string derived from this string by replacing every
65.789 * occurrence of <code>oldChar</code> with <code>newChar</code>.
65.790 */
65.791 + @JavaScriptBody(args = { "arg1", "arg2" }, body =
65.792 + "if (typeof arg1 === 'number') arg1 = String.fromCharCode(arg1);\n" +
65.793 + "if (typeof arg2 === 'number') arg2 = String.fromCharCode(arg2);\n" +
65.794 + "var s = this.toString();\n" +
65.795 + "for (;;) {\n" +
65.796 + " var ret = s.replace(arg1, arg2);\n" +
65.797 + " if (ret === s) {\n" +
65.798 + " return ret;\n" +
65.799 + " }\n" +
65.800 + " s = ret;\n" +
65.801 + "}"
65.802 + )
65.803 public String replace(char oldChar, char newChar) {
65.804 if (oldChar != newChar) {
65.805 - int len = count;
65.806 + int len = length();
65.807 int i = -1;
65.808 - char[] val = value; /* avoid getfield opcode */
65.809 - int off = offset; /* avoid getfield opcode */
65.810 + char[] val = toCharArray(); /* avoid getfield opcode */
65.811 + int off = offset(); /* avoid getfield opcode */
65.812
65.813 while (++i < len) {
65.814 if (val[off + i] == oldChar) {
65.815 @@ -2083,7 +2046,7 @@
65.816 buf[i] = (c == oldChar) ? newChar : c;
65.817 i++;
65.818 }
65.819 - return new String(0, len, buf);
65.820 + return new String(buf, 0, len);
65.821 }
65.822 }
65.823 return this;
65.824 @@ -2115,6 +2078,12 @@
65.825 * @since 1.4
65.826 * @spec JSR-51
65.827 */
65.828 + @JavaScriptBody(args = { "regex" }, body =
65.829 + "var self = this.toString();\n"
65.830 + + "var re = new RegExp(regex.toString());\n"
65.831 + + "var r = re.exec(self);\n"
65.832 + + "return r != null && r.length > 0 && self.length == r[0].length;"
65.833 + )
65.834 public boolean matches(String regex) {
65.835 throw new UnsupportedOperationException();
65.836 }
65.837 @@ -2527,6 +2496,7 @@
65.838 * @return the <code>String</code>, converted to lowercase.
65.839 * @see java.lang.String#toLowerCase(Locale)
65.840 */
65.841 + @JavaScriptBody(args = {}, body = "return this.toLowerCase();")
65.842 public String toLowerCase() {
65.843 throw new UnsupportedOperationException("Should be supported but without connection to locale");
65.844 }
65.845 @@ -2692,6 +2662,7 @@
65.846 * @return the <code>String</code>, converted to uppercase.
65.847 * @see java.lang.String#toUpperCase(Locale)
65.848 */
65.849 + @JavaScriptBody(args = {}, body = "return this.toUpperCase();")
65.850 public String toUpperCase() {
65.851 throw new UnsupportedOperationException();
65.852 }
65.853 @@ -2728,10 +2699,10 @@
65.854 * trailing white space.
65.855 */
65.856 public String trim() {
65.857 - int len = count;
65.858 + int len = length();
65.859 int st = 0;
65.860 - int off = offset; /* avoid getfield opcode */
65.861 - char[] val = value; /* avoid getfield opcode */
65.862 + int off = offset(); /* avoid getfield opcode */
65.863 + char[] val = toCharArray(); /* avoid getfield opcode */
65.864
65.865 while ((st < len) && (val[off + st] <= ' ')) {
65.866 st++;
65.867 @@ -2739,7 +2710,7 @@
65.868 while ((st < len) && (val[off + len - 1] <= ' ')) {
65.869 len--;
65.870 }
65.871 - return ((st > 0) || (len < count)) ? substring(st, len) : this;
65.872 + return ((st > 0) || (len < length())) ? substring(st, len) : this;
65.873 }
65.874
65.875 /**
65.876 @@ -2747,6 +2718,7 @@
65.877 *
65.878 * @return the string itself.
65.879 */
65.880 + @JavaScriptBody(args = {}, body = "return this.toString();")
65.881 public String toString() {
65.882 return this;
65.883 }
65.884 @@ -2759,8 +2731,8 @@
65.885 * the character sequence represented by this string.
65.886 */
65.887 public char[] toCharArray() {
65.888 - char result[] = new char[count];
65.889 - getChars(0, count, result, 0);
65.890 + char result[] = new char[length()];
65.891 + getChars(0, length(), result, 0);
65.892 return result;
65.893 }
65.894
65.895 @@ -2951,7 +2923,7 @@
65.896 */
65.897 public static String valueOf(char c) {
65.898 char data[] = {c};
65.899 - return new String(0, 1, data);
65.900 + return new String(data, 0, 1);
65.901 }
65.902
65.903 /**
65.904 @@ -3034,32 +3006,4 @@
65.905 * guaranteed to be from a pool of unique strings.
65.906 */
65.907 public native String intern();
65.908 -
65.909 - static char[] copyOfRange(char[] original, int from, int to) {
65.910 - int newLength = to - from;
65.911 - if (newLength < 0) {
65.912 - throw new IllegalArgumentException(from + " > " + to);
65.913 - }
65.914 - char[] copy = new char[newLength];
65.915 - arraycopy(original, from, copy, 0,
65.916 - Math.min(original.length - from, newLength));
65.917 - return copy;
65.918 - }
65.919 - static char[] copyOf(char[] original, int newLength) {
65.920 - char[] copy = new char[newLength];
65.921 - arraycopy(original, 0, copy, 0,
65.922 - Math.min(original.length, newLength));
65.923 - return copy;
65.924 - }
65.925 - static void arraycopy(
65.926 - char[] value, int srcBegin, char[] dst, int dstBegin, int count
65.927 - ) {
65.928 - while (count-- > 0) {
65.929 - dst[dstBegin++] = value[srcBegin++];
65.930 - }
65.931 - }
65.932 - // access system property
65.933 - static String getProperty(String nm) {
65.934 - return null;
65.935 - }
65.936 }
66.1 --- a/emul/src/main/java/java/lang/StringBuffer.java Thu Oct 11 06:15:22 2012 -0700
66.2 +++ b/emul/src/main/java/java/lang/StringBuffer.java Wed Jan 23 20:16:48 2013 +0100
66.3 @@ -527,8 +527,7 @@
66.4 * @since 1.4
66.5 */
66.6 public synchronized int indexOf(String str, int fromIndex) {
66.7 - return String.indexOf(value, 0, count,
66.8 - str.toCharArray(), 0, str.length(), fromIndex);
66.9 + return super.indexOf(str, fromIndex);
66.10 }
66.11
66.12 /**
67.1 --- a/emul/src/main/java/java/lang/StringBuilder.java Thu Oct 11 06:15:22 2012 -0700
67.2 +++ b/emul/src/main/java/java/lang/StringBuilder.java Wed Jan 23 20:16:48 2013 +0100
67.3 @@ -376,8 +376,7 @@
67.4 * @throws NullPointerException {@inheritDoc}
67.5 */
67.6 public int indexOf(String str, int fromIndex) {
67.7 - return String.indexOf(value, 0, count,
67.8 - str.toCharArray(), 0, str.length(), fromIndex);
67.9 + return super.indexOf(str, fromIndex);
67.10 }
67.11
67.12 /**
68.1 --- a/emul/src/main/java/java/lang/Throwable.java Thu Oct 11 06:15:22 2012 -0700
68.2 +++ b/emul/src/main/java/java/lang/Throwable.java Wed Jan 23 20:16:48 2013 +0100
68.3 @@ -25,6 +25,8 @@
68.4
68.5 package java.lang;
68.6 import java.io.*;
68.7 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
68.8 +import org.apidesign.bck2brwsr.core.JavaScriptOnly;
68.9
68.10 /**
68.11 * The {@code Throwable} class is the superclass of all errors and
68.12 @@ -233,6 +235,13 @@
68.13 private static final String SELF_SUPPRESSION_MESSAGE = "Self-suppression not permitted";
68.14
68.15 /** Caption for labeling causative exception stack traces */
68.16 + @JavaScriptOnly(name="toString", value="function() { return this.toString__Ljava_lang_String_2().toString(); }")
68.17 + private static void jsToString() {
68.18 + }
68.19 +
68.20 + @JavaScriptOnly(name="valueOf", value="function() { return this.toString().valueOf(); }")
68.21 + private static void jsValudOf() {
68.22 + }
68.23 private static final String CAUSE_CAPTION = "Caused by: ";
68.24
68.25 /** Caption for labeling suppressed exception stack traces */
68.26 @@ -782,6 +791,7 @@
68.27 return this;
68.28 }
68.29
68.30 + @JavaScriptBody(args = { "dummy" }, body = "")
68.31 private native Throwable fillInStackTrace(int dummy);
68.32
68.33 /**
69.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
69.2 +++ b/emul/src/main/java/java/lang/Void.java Wed Jan 23 20:16:48 2013 +0100
69.3 @@ -0,0 +1,49 @@
69.4 +/*
69.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
69.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
69.7 + *
69.8 + * This code is free software; you can redistribute it and/or modify it
69.9 + * under the terms of the GNU General Public License version 2 only, as
69.10 + * published by the Free Software Foundation. Oracle designates this
69.11 + * particular file as subject to the "Classpath" exception as provided
69.12 + * by Oracle in the LICENSE file that accompanied this code.
69.13 + *
69.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
69.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
69.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
69.17 + * version 2 for more details (a copy is included in the LICENSE file that
69.18 + * accompanied this code).
69.19 + *
69.20 + * You should have received a copy of the GNU General Public License version
69.21 + * 2 along with this work; if not, write to the Free Software Foundation,
69.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
69.23 + *
69.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
69.25 + * or visit www.oracle.com if you need additional information or have any
69.26 + * questions.
69.27 + */
69.28 +
69.29 +package java.lang;
69.30 +
69.31 +/**
69.32 + * The {@code Void} class is an uninstantiable placeholder class to hold a
69.33 + * reference to the {@code Class} object representing the Java keyword
69.34 + * void.
69.35 + *
69.36 + * @author unascribed
69.37 + * @since JDK1.1
69.38 + */
69.39 +public final
69.40 +class Void {
69.41 +
69.42 + /**
69.43 + * The {@code Class} object representing the pseudo-type corresponding to
69.44 + * the keyword {@code void}.
69.45 + */
69.46 + public static final Class<Void> TYPE = Class.getPrimitiveClass("void");
69.47 +
69.48 + /*
69.49 + * The Void class cannot be instantiated.
69.50 + */
69.51 + private Void() {}
69.52 +}
70.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
70.2 +++ b/emul/src/main/java/java/lang/reflect/AccessibleObject.java Wed Jan 23 20:16:48 2013 +0100
70.3 @@ -0,0 +1,167 @@
70.4 +/*
70.5 + * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
70.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
70.7 + *
70.8 + * This code is free software; you can redistribute it and/or modify it
70.9 + * under the terms of the GNU General Public License version 2 only, as
70.10 + * published by the Free Software Foundation. Oracle designates this
70.11 + * particular file as subject to the "Classpath" exception as provided
70.12 + * by Oracle in the LICENSE file that accompanied this code.
70.13 + *
70.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
70.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
70.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
70.17 + * version 2 for more details (a copy is included in the LICENSE file that
70.18 + * accompanied this code).
70.19 + *
70.20 + * You should have received a copy of the GNU General Public License version
70.21 + * 2 along with this work; if not, write to the Free Software Foundation,
70.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
70.23 + *
70.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
70.25 + * or visit www.oracle.com if you need additional information or have any
70.26 + * questions.
70.27 + */
70.28 +
70.29 +package java.lang.reflect;
70.30 +
70.31 +import java.lang.annotation.Annotation;
70.32 +
70.33 +/**
70.34 + * The AccessibleObject class is the base class for Field, Method and
70.35 + * Constructor objects. It provides the ability to flag a reflected
70.36 + * object as suppressing default Java language access control checks
70.37 + * when it is used. The access checks--for public, default (package)
70.38 + * access, protected, and private members--are performed when Fields,
70.39 + * Methods or Constructors are used to set or get fields, to invoke
70.40 + * methods, or to create and initialize new instances of classes,
70.41 + * respectively.
70.42 + *
70.43 + * <p>Setting the {@code accessible} flag in a reflected object
70.44 + * permits sophisticated applications with sufficient privilege, such
70.45 + * as Java Object Serialization or other persistence mechanisms, to
70.46 + * manipulate objects in a manner that would normally be prohibited.
70.47 + *
70.48 + * <p>By default, a reflected object is <em>not</em> accessible.
70.49 + *
70.50 + * @see Field
70.51 + * @see Method
70.52 + * @see Constructor
70.53 + * @see ReflectPermission
70.54 + *
70.55 + * @since 1.2
70.56 + */
70.57 +public class AccessibleObject implements AnnotatedElement {
70.58 +
70.59 + /**
70.60 + * Convenience method to set the {@code accessible} flag for an
70.61 + * array of objects with a single security check (for efficiency).
70.62 + *
70.63 + * <p>First, if there is a security manager, its
70.64 + * {@code checkPermission} method is called with a
70.65 + * {@code ReflectPermission("suppressAccessChecks")} permission.
70.66 + *
70.67 + * <p>A {@code SecurityException} is raised if {@code flag} is
70.68 + * {@code true} but accessibility of any of the elements of the input
70.69 + * {@code array} may not be changed (for example, if the element
70.70 + * object is a {@link Constructor} object for the class {@link
70.71 + * java.lang.Class}). In the event of such a SecurityException, the
70.72 + * accessibility of objects is set to {@code flag} for array elements
70.73 + * upto (and excluding) the element for which the exception occurred; the
70.74 + * accessibility of elements beyond (and including) the element for which
70.75 + * the exception occurred is unchanged.
70.76 + *
70.77 + * @param array the array of AccessibleObjects
70.78 + * @param flag the new value for the {@code accessible} flag
70.79 + * in each object
70.80 + * @throws SecurityException if the request is denied.
70.81 + * @see SecurityManager#checkPermission
70.82 + * @see java.lang.RuntimePermission
70.83 + */
70.84 + public static void setAccessible(AccessibleObject[] array, boolean flag)
70.85 + throws SecurityException {
70.86 + throw new SecurityException();
70.87 + }
70.88 +
70.89 + /**
70.90 + * Set the {@code accessible} flag for this object to
70.91 + * the indicated boolean value. A value of {@code true} indicates that
70.92 + * the reflected object should suppress Java language access
70.93 + * checking when it is used. A value of {@code false} indicates
70.94 + * that the reflected object should enforce Java language access checks.
70.95 + *
70.96 + * <p>First, if there is a security manager, its
70.97 + * {@code checkPermission} method is called with a
70.98 + * {@code ReflectPermission("suppressAccessChecks")} permission.
70.99 + *
70.100 + * <p>A {@code SecurityException} is raised if {@code flag} is
70.101 + * {@code true} but accessibility of this object may not be changed
70.102 + * (for example, if this element object is a {@link Constructor} object for
70.103 + * the class {@link java.lang.Class}).
70.104 + *
70.105 + * <p>A {@code SecurityException} is raised if this object is a {@link
70.106 + * java.lang.reflect.Constructor} object for the class
70.107 + * {@code java.lang.Class}, and {@code flag} is true.
70.108 + *
70.109 + * @param flag the new value for the {@code accessible} flag
70.110 + * @throws SecurityException if the request is denied.
70.111 + * @see SecurityManager#checkPermission
70.112 + * @see java.lang.RuntimePermission
70.113 + */
70.114 + public void setAccessible(boolean flag) throws SecurityException {
70.115 + throw new SecurityException();
70.116 + }
70.117 +
70.118 + /**
70.119 + * Get the value of the {@code accessible} flag for this object.
70.120 + *
70.121 + * @return the value of the object's {@code accessible} flag
70.122 + */
70.123 + public boolean isAccessible() {
70.124 + return override;
70.125 + }
70.126 +
70.127 + /**
70.128 + * Constructor: only used by the Java Virtual Machine.
70.129 + */
70.130 + protected AccessibleObject() {}
70.131 +
70.132 + // Indicates whether language-level access checks are overridden
70.133 + // by this object. Initializes to "false". This field is used by
70.134 + // Field, Method, and Constructor.
70.135 + //
70.136 + // NOTE: for security purposes, this field must not be visible
70.137 + // outside this package.
70.138 + boolean override;
70.139 +
70.140 + /**
70.141 + * @throws NullPointerException {@inheritDoc}
70.142 + * @since 1.5
70.143 + */
70.144 + public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
70.145 + throw new AssertionError("All subclasses should override this method");
70.146 + }
70.147 +
70.148 + /**
70.149 + * @throws NullPointerException {@inheritDoc}
70.150 + * @since 1.5
70.151 + */
70.152 + public boolean isAnnotationPresent(
70.153 + Class<? extends Annotation> annotationClass) {
70.154 + return getAnnotation(annotationClass) != null;
70.155 + }
70.156 +
70.157 + /**
70.158 + * @since 1.5
70.159 + */
70.160 + public Annotation[] getAnnotations() {
70.161 + return getDeclaredAnnotations();
70.162 + }
70.163 +
70.164 + /**
70.165 + * @since 1.5
70.166 + */
70.167 + public Annotation[] getDeclaredAnnotations() {
70.168 + throw new AssertionError("All subclasses should override this method");
70.169 + }
70.170 +}
71.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
71.2 +++ b/emul/src/main/java/java/lang/reflect/AnnotatedElement.java Wed Jan 23 20:16:48 2013 +0100
71.3 @@ -0,0 +1,112 @@
71.4 +/*
71.5 + * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
71.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
71.7 + *
71.8 + * This code is free software; you can redistribute it and/or modify it
71.9 + * under the terms of the GNU General Public License version 2 only, as
71.10 + * published by the Free Software Foundation. Oracle designates this
71.11 + * particular file as subject to the "Classpath" exception as provided
71.12 + * by Oracle in the LICENSE file that accompanied this code.
71.13 + *
71.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
71.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
71.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
71.17 + * version 2 for more details (a copy is included in the LICENSE file that
71.18 + * accompanied this code).
71.19 + *
71.20 + * You should have received a copy of the GNU General Public License version
71.21 + * 2 along with this work; if not, write to the Free Software Foundation,
71.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
71.23 + *
71.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
71.25 + * or visit www.oracle.com if you need additional information or have any
71.26 + * questions.
71.27 + */
71.28 +
71.29 +package java.lang.reflect;
71.30 +
71.31 +import java.lang.annotation.Annotation;
71.32 +
71.33 +/**
71.34 + * Represents an annotated element of the program currently running in this
71.35 + * VM. This interface allows annotations to be read reflectively. All
71.36 + * annotations returned by methods in this interface are immutable and
71.37 + * serializable. It is permissible for the caller to modify the
71.38 + * arrays returned by accessors for array-valued enum members; it will
71.39 + * have no affect on the arrays returned to other callers.
71.40 + *
71.41 + * <p>If an annotation returned by a method in this interface contains
71.42 + * (directly or indirectly) a {@link Class}-valued member referring to
71.43 + * a class that is not accessible in this VM, attempting to read the class
71.44 + * by calling the relevant Class-returning method on the returned annotation
71.45 + * will result in a {@link TypeNotPresentException}.
71.46 + *
71.47 + * <p>Similarly, attempting to read an enum-valued member will result in
71.48 + * a {@link EnumConstantNotPresentException} if the enum constant in the
71.49 + * annotation is no longer present in the enum type.
71.50 + *
71.51 + * <p>Finally, Attempting to read a member whose definition has evolved
71.52 + * incompatibly will result in a {@link
71.53 + * java.lang.annotation.AnnotationTypeMismatchException} or an
71.54 + * {@link java.lang.annotation.IncompleteAnnotationException}.
71.55 + *
71.56 + * @see java.lang.EnumConstantNotPresentException
71.57 + * @see java.lang.TypeNotPresentException
71.58 + * @see java.lang.annotation.AnnotationFormatError
71.59 + * @see java.lang.annotation.AnnotationTypeMismatchException
71.60 + * @see java.lang.annotation.IncompleteAnnotationException
71.61 + * @since 1.5
71.62 + * @author Josh Bloch
71.63 + */
71.64 +public interface AnnotatedElement {
71.65 + /**
71.66 + * Returns true if an annotation for the specified type
71.67 + * is present on this element, else false. This method
71.68 + * is designed primarily for convenient access to marker annotations.
71.69 + *
71.70 + * @param annotationClass the Class object corresponding to the
71.71 + * annotation type
71.72 + * @return true if an annotation for the specified annotation
71.73 + * type is present on this element, else false
71.74 + * @throws NullPointerException if the given annotation class is null
71.75 + * @since 1.5
71.76 + */
71.77 + boolean isAnnotationPresent(Class<? extends Annotation> annotationClass);
71.78 +
71.79 + /**
71.80 + * Returns this element's annotation for the specified type if
71.81 + * such an annotation is present, else null.
71.82 + *
71.83 + * @param annotationClass the Class object corresponding to the
71.84 + * annotation type
71.85 + * @return this element's annotation for the specified annotation type if
71.86 + * present on this element, else null
71.87 + * @throws NullPointerException if the given annotation class is null
71.88 + * @since 1.5
71.89 + */
71.90 + <T extends Annotation> T getAnnotation(Class<T> annotationClass);
71.91 +
71.92 + /**
71.93 + * Returns all annotations present on this element. (Returns an array
71.94 + * of length zero if this element has no annotations.) The caller of
71.95 + * this method is free to modify the returned array; it will have no
71.96 + * effect on the arrays returned to other callers.
71.97 + *
71.98 + * @return all annotations present on this element
71.99 + * @since 1.5
71.100 + */
71.101 + Annotation[] getAnnotations();
71.102 +
71.103 + /**
71.104 + * Returns all annotations that are directly present on this
71.105 + * element. Unlike the other methods in this interface, this method
71.106 + * ignores inherited annotations. (Returns an array of length zero if
71.107 + * no annotations are directly present on this element.) The caller of
71.108 + * this method is free to modify the returned array; it will have no
71.109 + * effect on the arrays returned to other callers.
71.110 + *
71.111 + * @return All annotations directly present on this element
71.112 + * @since 1.5
71.113 + */
71.114 + Annotation[] getDeclaredAnnotations();
71.115 +}
72.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
72.2 +++ b/emul/src/main/java/java/lang/reflect/Array.java Wed Jan 23 20:16:48 2013 +0100
72.3 @@ -0,0 +1,659 @@
72.4 +/*
72.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
72.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
72.7 + *
72.8 + * This code is free software; you can redistribute it and/or modify it
72.9 + * under the terms of the GNU General Public License version 2 only, as
72.10 + * published by the Free Software Foundation. Oracle designates this
72.11 + * particular file as subject to the "Classpath" exception as provided
72.12 + * by Oracle in the LICENSE file that accompanied this code.
72.13 + *
72.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
72.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
72.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
72.17 + * version 2 for more details (a copy is included in the LICENSE file that
72.18 + * accompanied this code).
72.19 + *
72.20 + * You should have received a copy of the GNU General Public License version
72.21 + * 2 along with this work; if not, write to the Free Software Foundation,
72.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
72.23 + *
72.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
72.25 + * or visit www.oracle.com if you need additional information or have any
72.26 + * questions.
72.27 + */
72.28 +
72.29 +package java.lang.reflect;
72.30 +
72.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
72.32 +import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
72.33 +
72.34 +/**
72.35 + * The {@code Array} class provides static methods to dynamically create and
72.36 + * access Java arrays.
72.37 + *
72.38 + * <p>{@code Array} permits widening conversions to occur during a get or set
72.39 + * operation, but throws an {@code IllegalArgumentException} if a narrowing
72.40 + * conversion would occur.
72.41 + *
72.42 + * @author Nakul Saraiya
72.43 + */
72.44 +@JavaScriptPrototype(prototype = "new Array", container = "Array.prototype")
72.45 +public final
72.46 +class Array {
72.47 +
72.48 + /**
72.49 + * Constructor. Class Array is not instantiable.
72.50 + */
72.51 + private Array() {}
72.52 +
72.53 + /**
72.54 + * Creates a new array with the specified component type and
72.55 + * length.
72.56 + * Invoking this method is equivalent to creating an array
72.57 + * as follows:
72.58 + * <blockquote>
72.59 + * <pre>
72.60 + * int[] x = {length};
72.61 + * Array.newInstance(componentType, x);
72.62 + * </pre>
72.63 + * </blockquote>
72.64 + *
72.65 + * @param componentType the {@code Class} object representing the
72.66 + * component type of the new array
72.67 + * @param length the length of the new array
72.68 + * @return the new array
72.69 + * @exception NullPointerException if the specified
72.70 + * {@code componentType} parameter is null
72.71 + * @exception IllegalArgumentException if componentType is {@link Void#TYPE}
72.72 + * @exception NegativeArraySizeException if the specified {@code length}
72.73 + * is negative
72.74 + */
72.75 + public static Object newInstance(Class<?> componentType, int length)
72.76 + throws NegativeArraySizeException {
72.77 + if (length < 0) {
72.78 + throw new NegativeArraySizeException();
72.79 + }
72.80 + String sig = findSignature(componentType);
72.81 + return newArray(componentType.isPrimitive(), sig, length);
72.82 + }
72.83 +
72.84 + private static String findSignature(Class<?> type) {
72.85 + if (type == Integer.TYPE) {
72.86 + return "[I";
72.87 + }
72.88 + if (type == Long.TYPE) {
72.89 + return "[J";
72.90 + }
72.91 + if (type == Double.TYPE) {
72.92 + return "[D";
72.93 + }
72.94 + if (type == Float.TYPE) {
72.95 + return "[F";
72.96 + }
72.97 + if (type == Byte.TYPE) {
72.98 + return "[B";
72.99 + }
72.100 + if (type == Boolean.TYPE) {
72.101 + return "[Z";
72.102 + }
72.103 + if (type == Short.TYPE) {
72.104 + return "[S";
72.105 + }
72.106 + if (type == Character.TYPE) {
72.107 + return "[C";
72.108 + }
72.109 + if (type.getName().equals("void")) {
72.110 + throw new IllegalStateException("Can't create array for " + type);
72.111 + }
72.112 + return "[L" + type.getName() + ";";
72.113 + }
72.114 + /**
72.115 + * Creates a new array
72.116 + * with the specified component type and dimensions.
72.117 + * If {@code componentType}
72.118 + * represents a non-array class or interface, the new array
72.119 + * has {@code dimensions.length} dimensions and
72.120 + * {@code componentType} as its component type. If
72.121 + * {@code componentType} represents an array class, the
72.122 + * number of dimensions of the new array is equal to the sum
72.123 + * of {@code dimensions.length} and the number of
72.124 + * dimensions of {@code componentType}. In this case, the
72.125 + * component type of the new array is the component type of
72.126 + * {@code componentType}.
72.127 + *
72.128 + * <p>The number of dimensions of the new array must not
72.129 + * exceed the number of array dimensions supported by the
72.130 + * implementation (typically 255).
72.131 + *
72.132 + * @param componentType the {@code Class} object representing the component
72.133 + * type of the new array
72.134 + * @param dimensions an array of {@code int} representing the dimensions of
72.135 + * the new array
72.136 + * @return the new array
72.137 + * @exception NullPointerException if the specified
72.138 + * {@code componentType} argument is null
72.139 + * @exception IllegalArgumentException if the specified {@code dimensions}
72.140 + * argument is a zero-dimensional array, or if the number of
72.141 + * requested dimensions exceeds the limit on the number of array dimensions
72.142 + * supported by the implementation (typically 255), or if componentType
72.143 + * is {@link Void#TYPE}.
72.144 + * @exception NegativeArraySizeException if any of the components in
72.145 + * the specified {@code dimensions} argument is negative.
72.146 + */
72.147 + public static Object newInstance(Class<?> componentType, int... dimensions)
72.148 + throws IllegalArgumentException, NegativeArraySizeException {
72.149 + StringBuilder sig = new StringBuilder();
72.150 + for (int i = 1; i < dimensions.length; i++) {
72.151 + sig.append('[');
72.152 + }
72.153 + sig.append(findSignature(componentType));
72.154 + return multiNewArray(sig.toString(), dimensions, 0);
72.155 + }
72.156 +
72.157 + /**
72.158 + * Returns the length of the specified array object, as an {@code int}.
72.159 + *
72.160 + * @param array the array
72.161 + * @return the length of the array
72.162 + * @exception IllegalArgumentException if the object argument is not
72.163 + * an array
72.164 + */
72.165 + public static int getLength(Object array)
72.166 + throws IllegalArgumentException {
72.167 + if (!array.getClass().isArray()) {
72.168 + throw new IllegalArgumentException("Argument is not an array");
72.169 + }
72.170 + return length(array);
72.171 + }
72.172 +
72.173 + @JavaScriptBody(args = { "arr" }, body = "return arr.length;")
72.174 + private static native int length(Object arr);
72.175 +
72.176 + /**
72.177 + * Returns the value of the indexed component in the specified
72.178 + * array object. The value is automatically wrapped in an object
72.179 + * if it has a primitive type.
72.180 + *
72.181 + * @param array the array
72.182 + * @param index the index
72.183 + * @return the (possibly wrapped) value of the indexed component in
72.184 + * the specified array
72.185 + * @exception NullPointerException If the specified object is null
72.186 + * @exception IllegalArgumentException If the specified object is not
72.187 + * an array
72.188 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
72.189 + * argument is negative, or if it is greater than or equal to the
72.190 + * length of the specified array
72.191 + */
72.192 + public static Object get(Object array, int index)
72.193 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
72.194 + final Class<?> t = array.getClass().getComponentType();
72.195 + if (t.isPrimitive()) {
72.196 + return Array.fromPrimitive(t, array, index);
72.197 + } else {
72.198 + return ((Object[])array)[index];
72.199 + }
72.200 + }
72.201 +
72.202 + /**
72.203 + * Returns the value of the indexed component in the specified
72.204 + * array object, as a {@code boolean}.
72.205 + *
72.206 + * @param array the array
72.207 + * @param index the index
72.208 + * @return the value of the indexed component in the specified array
72.209 + * @exception NullPointerException If the specified object is null
72.210 + * @exception IllegalArgumentException If the specified object is not
72.211 + * an array, or if the indexed element cannot be converted to the
72.212 + * return type by an identity or widening conversion
72.213 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
72.214 + * argument is negative, or if it is greater than or equal to the
72.215 + * length of the specified array
72.216 + * @see Array#get
72.217 + */
72.218 + public static native boolean getBoolean(Object array, int index)
72.219 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
72.220 +
72.221 + /**
72.222 + * Returns the value of the indexed component in the specified
72.223 + * array object, as a {@code byte}.
72.224 + *
72.225 + * @param array the array
72.226 + * @param index the index
72.227 + * @return the value of the indexed component in the specified array
72.228 + * @exception NullPointerException If the specified object is null
72.229 + * @exception IllegalArgumentException If the specified object is not
72.230 + * an array, or if the indexed element cannot be converted to the
72.231 + * return type by an identity or widening conversion
72.232 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
72.233 + * argument is negative, or if it is greater than or equal to the
72.234 + * length of the specified array
72.235 + * @see Array#get
72.236 + */
72.237 + public static byte getByte(Object array, int index)
72.238 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
72.239 + if (array.getClass().getComponentType() != Byte.TYPE) {
72.240 + throw new IllegalArgumentException();
72.241 + }
72.242 + byte[] arr = (byte[]) array;
72.243 + return arr[index];
72.244 + }
72.245 +
72.246 + /**
72.247 + * Returns the value of the indexed component in the specified
72.248 + * array object, as a {@code char}.
72.249 + *
72.250 + * @param array the array
72.251 + * @param index the index
72.252 + * @return the value of the indexed component in the specified array
72.253 + * @exception NullPointerException If the specified object is null
72.254 + * @exception IllegalArgumentException If the specified object is not
72.255 + * an array, or if the indexed element cannot be converted to the
72.256 + * return type by an identity or widening conversion
72.257 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
72.258 + * argument is negative, or if it is greater than or equal to the
72.259 + * length of the specified array
72.260 + * @see Array#get
72.261 + */
72.262 + public static native char getChar(Object array, int index)
72.263 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
72.264 +
72.265 + /**
72.266 + * Returns the value of the indexed component in the specified
72.267 + * array object, as a {@code short}.
72.268 + *
72.269 + * @param array the array
72.270 + * @param index the index
72.271 + * @return the value of the indexed component in the specified array
72.272 + * @exception NullPointerException If the specified object is null
72.273 + * @exception IllegalArgumentException If the specified object is not
72.274 + * an array, or if the indexed element cannot be converted to the
72.275 + * return type by an identity or widening conversion
72.276 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
72.277 + * argument is negative, or if it is greater than or equal to the
72.278 + * length of the specified array
72.279 + * @see Array#get
72.280 + */
72.281 + public static short getShort(Object array, int index)
72.282 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
72.283 + final Class<?> t = array.getClass().getComponentType();
72.284 + if (t == Short.TYPE) {
72.285 + short[] arr = (short[]) array;
72.286 + return arr[index];
72.287 + }
72.288 + return getByte(array, index);
72.289 + }
72.290 +
72.291 + /**
72.292 + * Returns the value of the indexed component in the specified
72.293 + * array object, as an {@code int}.
72.294 + *
72.295 + * @param array the array
72.296 + * @param index the index
72.297 + * @return the value of the indexed component in the specified array
72.298 + * @exception NullPointerException If the specified object is null
72.299 + * @exception IllegalArgumentException If the specified object is not
72.300 + * an array, or if the indexed element cannot be converted to the
72.301 + * return type by an identity or widening conversion
72.302 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
72.303 + * argument is negative, or if it is greater than or equal to the
72.304 + * length of the specified array
72.305 + * @see Array#get
72.306 + */
72.307 + public static int getInt(Object array, int index)
72.308 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
72.309 + final Class<?> t = array.getClass().getComponentType();
72.310 + if (t == Integer.TYPE) {
72.311 + int[] arr = (int[]) array;
72.312 + return arr[index];
72.313 + }
72.314 + return getShort(array, index);
72.315 + }
72.316 +
72.317 + /**
72.318 + * Returns the value of the indexed component in the specified
72.319 + * array object, as a {@code long}.
72.320 + *
72.321 + * @param array the array
72.322 + * @param index the index
72.323 + * @return the value of the indexed component in the specified array
72.324 + * @exception NullPointerException If the specified object is null
72.325 + * @exception IllegalArgumentException If the specified object is not
72.326 + * an array, or if the indexed element cannot be converted to the
72.327 + * return type by an identity or widening conversion
72.328 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
72.329 + * argument is negative, or if it is greater than or equal to the
72.330 + * length of the specified array
72.331 + * @see Array#get
72.332 + */
72.333 + public static long getLong(Object array, int index)
72.334 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
72.335 + final Class<?> t = array.getClass().getComponentType();
72.336 + if (t == Long.TYPE) {
72.337 + long[] arr = (long[]) array;
72.338 + return arr[index];
72.339 + }
72.340 + return getInt(array, index);
72.341 + }
72.342 +
72.343 + /**
72.344 + * Returns the value of the indexed component in the specified
72.345 + * array object, as a {@code float}.
72.346 + *
72.347 + * @param array the array
72.348 + * @param index the index
72.349 + * @return the value of the indexed component in the specified array
72.350 + * @exception NullPointerException If the specified object is null
72.351 + * @exception IllegalArgumentException If the specified object is not
72.352 + * an array, or if the indexed element cannot be converted to the
72.353 + * return type by an identity or widening conversion
72.354 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
72.355 + * argument is negative, or if it is greater than or equal to the
72.356 + * length of the specified array
72.357 + * @see Array#get
72.358 + */
72.359 + public static float getFloat(Object array, int index)
72.360 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
72.361 + final Class<?> t = array.getClass().getComponentType();
72.362 + if (t == Float.TYPE) {
72.363 + float[] arr = (float[]) array;
72.364 + return arr[index];
72.365 + }
72.366 + return getLong(array, index);
72.367 + }
72.368 +
72.369 + /**
72.370 + * Returns the value of the indexed component in the specified
72.371 + * array object, as a {@code double}.
72.372 + *
72.373 + * @param array the array
72.374 + * @param index the index
72.375 + * @return the value of the indexed component in the specified array
72.376 + * @exception NullPointerException If the specified object is null
72.377 + * @exception IllegalArgumentException If the specified object is not
72.378 + * an array, or if the indexed element cannot be converted to the
72.379 + * return type by an identity or widening conversion
72.380 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
72.381 + * argument is negative, or if it is greater than or equal to the
72.382 + * length of the specified array
72.383 + * @see Array#get
72.384 + */
72.385 + public static double getDouble(Object array, int index)
72.386 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
72.387 + final Class<?> t = array.getClass().getComponentType();
72.388 + if (t == Double.TYPE) {
72.389 + double[] arr = (double[]) array;
72.390 + return arr[index];
72.391 + }
72.392 + return getFloat(array, index);
72.393 + }
72.394 +
72.395 + /**
72.396 + * Sets the value of the indexed component of the specified array
72.397 + * object to the specified new value. The new value is first
72.398 + * automatically unwrapped if the array has a primitive component
72.399 + * type.
72.400 + * @param array the array
72.401 + * @param index the index into the array
72.402 + * @param value the new value of the indexed component
72.403 + * @exception NullPointerException If the specified object argument
72.404 + * is null
72.405 + * @exception IllegalArgumentException If the specified object argument
72.406 + * is not an array, or if the array component type is primitive and
72.407 + * an unwrapping conversion fails
72.408 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
72.409 + * argument is negative, or if it is greater than or equal to
72.410 + * the length of the specified array
72.411 + */
72.412 + public static void set(Object array, int index, Object value)
72.413 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
72.414 + if (array.getClass().getComponentType().isPrimitive()) {
72.415 + throw new IllegalArgumentException();
72.416 + } else {
72.417 + Object[] arr = (Object[])array;
72.418 + arr[index] = value;
72.419 + }
72.420 + }
72.421 +
72.422 + /**
72.423 + * Sets the value of the indexed component of the specified array
72.424 + * object to the specified {@code boolean} value.
72.425 + * @param array the array
72.426 + * @param index the index into the array
72.427 + * @param z the new value of the indexed component
72.428 + * @exception NullPointerException If the specified object argument
72.429 + * is null
72.430 + * @exception IllegalArgumentException If the specified object argument
72.431 + * is not an array, or if the specified value cannot be converted
72.432 + * to the underlying array's component type by an identity or a
72.433 + * primitive widening conversion
72.434 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
72.435 + * argument is negative, or if it is greater than or equal to
72.436 + * the length of the specified array
72.437 + * @see Array#set
72.438 + */
72.439 + public static native void setBoolean(Object array, int index, boolean z)
72.440 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
72.441 +
72.442 + /**
72.443 + * Sets the value of the indexed component of the specified array
72.444 + * object to the specified {@code byte} value.
72.445 + * @param array the array
72.446 + * @param index the index into the array
72.447 + * @param b the new value of the indexed component
72.448 + * @exception NullPointerException If the specified object argument
72.449 + * is null
72.450 + * @exception IllegalArgumentException If the specified object argument
72.451 + * is not an array, or if the specified value cannot be converted
72.452 + * to the underlying array's component type by an identity or a
72.453 + * primitive widening conversion
72.454 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
72.455 + * argument is negative, or if it is greater than or equal to
72.456 + * the length of the specified array
72.457 + * @see Array#set
72.458 + */
72.459 + public static void setByte(Object array, int index, byte b)
72.460 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
72.461 + Class<?> t = array.getClass().getComponentType();
72.462 + if (t == Byte.TYPE) {
72.463 + byte[] arr = (byte[]) array;
72.464 + arr[index] = b;
72.465 + } else {
72.466 + setShort(array, index, b);
72.467 + }
72.468 + }
72.469 +
72.470 + /**
72.471 + * Sets the value of the indexed component of the specified array
72.472 + * object to the specified {@code char} value.
72.473 + * @param array the array
72.474 + * @param index the index into the array
72.475 + * @param c the new value of the indexed component
72.476 + * @exception NullPointerException If the specified object argument
72.477 + * is null
72.478 + * @exception IllegalArgumentException If the specified object argument
72.479 + * is not an array, or if the specified value cannot be converted
72.480 + * to the underlying array's component type by an identity or a
72.481 + * primitive widening conversion
72.482 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
72.483 + * argument is negative, or if it is greater than or equal to
72.484 + * the length of the specified array
72.485 + * @see Array#set
72.486 + */
72.487 + public static native void setChar(Object array, int index, char c)
72.488 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
72.489 +
72.490 + /**
72.491 + * Sets the value of the indexed component of the specified array
72.492 + * object to the specified {@code short} value.
72.493 + * @param array the array
72.494 + * @param index the index into the array
72.495 + * @param s the new value of the indexed component
72.496 + * @exception NullPointerException If the specified object argument
72.497 + * is null
72.498 + * @exception IllegalArgumentException If the specified object argument
72.499 + * is not an array, or if the specified value cannot be converted
72.500 + * to the underlying array's component type by an identity or a
72.501 + * primitive widening conversion
72.502 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
72.503 + * argument is negative, or if it is greater than or equal to
72.504 + * the length of the specified array
72.505 + * @see Array#set
72.506 + */
72.507 + public static void setShort(Object array, int index, short s)
72.508 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
72.509 + Class<?> t = array.getClass().getComponentType();
72.510 + if (t == Short.TYPE) {
72.511 + short[] arr = (short[]) array;
72.512 + arr[index] = s;
72.513 + } else {
72.514 + setInt(array, index, s);
72.515 + }
72.516 +
72.517 + }
72.518 +
72.519 + /**
72.520 + * Sets the value of the indexed component of the specified array
72.521 + * object to the specified {@code int} value.
72.522 + * @param array the array
72.523 + * @param index the index into the array
72.524 + * @param i the new value of the indexed component
72.525 + * @exception NullPointerException If the specified object argument
72.526 + * is null
72.527 + * @exception IllegalArgumentException If the specified object argument
72.528 + * is not an array, or if the specified value cannot be converted
72.529 + * to the underlying array's component type by an identity or a
72.530 + * primitive widening conversion
72.531 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
72.532 + * argument is negative, or if it is greater than or equal to
72.533 + * the length of the specified array
72.534 + * @see Array#set
72.535 + */
72.536 + public static void setInt(Object array, int index, int i)
72.537 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
72.538 + Class<?> t = array.getClass().getComponentType();
72.539 + if (t == Integer.TYPE) {
72.540 + long[] arr = (long[]) array;
72.541 + arr[index] = i;
72.542 + } else {
72.543 + setLong(array, index, i);
72.544 + }
72.545 + }
72.546 +
72.547 + /**
72.548 + * Sets the value of the indexed component of the specified array
72.549 + * object to the specified {@code long} value.
72.550 + * @param array the array
72.551 + * @param index the index into the array
72.552 + * @param l the new value of the indexed component
72.553 + * @exception NullPointerException If the specified object argument
72.554 + * is null
72.555 + * @exception IllegalArgumentException If the specified object argument
72.556 + * is not an array, or if the specified value cannot be converted
72.557 + * to the underlying array's component type by an identity or a
72.558 + * primitive widening conversion
72.559 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
72.560 + * argument is negative, or if it is greater than or equal to
72.561 + * the length of the specified array
72.562 + * @see Array#set
72.563 + */
72.564 + public static void setLong(Object array, int index, long l)
72.565 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
72.566 + Class<?> t = array.getClass().getComponentType();
72.567 + if (t == Long.TYPE) {
72.568 + long[] arr = (long[]) array;
72.569 + arr[index] = l;
72.570 + } else {
72.571 + setFloat(array, index, l);
72.572 + }
72.573 + }
72.574 +
72.575 + /**
72.576 + * Sets the value of the indexed component of the specified array
72.577 + * object to the specified {@code float} value.
72.578 + * @param array the array
72.579 + * @param index the index into the array
72.580 + * @param f the new value of the indexed component
72.581 + * @exception NullPointerException If the specified object argument
72.582 + * is null
72.583 + * @exception IllegalArgumentException If the specified object argument
72.584 + * is not an array, or if the specified value cannot be converted
72.585 + * to the underlying array's component type by an identity or a
72.586 + * primitive widening conversion
72.587 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
72.588 + * argument is negative, or if it is greater than or equal to
72.589 + * the length of the specified array
72.590 + * @see Array#set
72.591 + */
72.592 + public static void setFloat(Object array, int index, float f)
72.593 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
72.594 + Class<?> t = array.getClass().getComponentType();
72.595 + if (t == Float.TYPE) {
72.596 + float[] arr = (float[])array;
72.597 + arr[index] = f;
72.598 + } else {
72.599 + setDouble(array, index, f);
72.600 + }
72.601 + }
72.602 +
72.603 + /**
72.604 + * Sets the value of the indexed component of the specified array
72.605 + * object to the specified {@code double} value.
72.606 + * @param array the array
72.607 + * @param index the index into the array
72.608 + * @param d the new value of the indexed component
72.609 + * @exception NullPointerException If the specified object argument
72.610 + * is null
72.611 + * @exception IllegalArgumentException If the specified object argument
72.612 + * is not an array, or if the specified value cannot be converted
72.613 + * to the underlying array's component type by an identity or a
72.614 + * primitive widening conversion
72.615 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
72.616 + * argument is negative, or if it is greater than or equal to
72.617 + * the length of the specified array
72.618 + * @see Array#set
72.619 + */
72.620 + public static void setDouble(Object array, int index, double d)
72.621 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
72.622 + Class<?> t = array.getClass().getComponentType();
72.623 + if (t == Double.TYPE) {
72.624 + double[] arr = (double[])array;
72.625 + arr[index] = d;
72.626 + } else {
72.627 + throw new IllegalArgumentException("argument type mismatch");
72.628 + }
72.629 + }
72.630 +
72.631 + /*
72.632 + * Private
72.633 + */
72.634 +
72.635 + @JavaScriptBody(args = { "primitive", "sig", "length" }, body =
72.636 + "var arr = new Array(length);\n"
72.637 + + "var value = primitive ? 0 : null;\n"
72.638 + + "for(var i = 0; i < length; i++) arr[i] = value;\n"
72.639 + + "arr.jvmName = sig;\n"
72.640 + + "return arr;"
72.641 + )
72.642 + private static native Object newArray(boolean primitive, String sig, int length);
72.643 +
72.644 + private static Object multiNewArray(String sig, int[] dims, int index)
72.645 + throws IllegalArgumentException, NegativeArraySizeException {
72.646 + if (dims.length == index + 1) {
72.647 + return newArray(sig.length() == 2, sig, dims[index]);
72.648 + }
72.649 + Object[] arr = (Object[]) newArray(false, sig, dims[index]);
72.650 + String compsig = sig.substring(1);
72.651 + for (int i = 0; i < arr.length; i++) {
72.652 + arr[i] = multiNewArray(compsig, dims, index + 1);
72.653 + }
72.654 + return arr;
72.655 + }
72.656 + private static Object fromPrimitive(Class<?> t, Object array, int index) {
72.657 + return Method.fromPrimitive(t, atArray(array, index));
72.658 + }
72.659 +
72.660 + @JavaScriptBody(args = { "array", "index" }, body = "return array[index]")
72.661 + private static native Object atArray(Object array, int index);
72.662 +}
73.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
73.2 +++ b/emul/src/main/java/java/lang/reflect/Field.java Wed Jan 23 20:16:48 2013 +0100
73.3 @@ -0,0 +1,953 @@
73.4 +/*
73.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
73.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
73.7 + *
73.8 + * This code is free software; you can redistribute it and/or modify it
73.9 + * under the terms of the GNU General Public License version 2 only, as
73.10 + * published by the Free Software Foundation. Oracle designates this
73.11 + * particular file as subject to the "Classpath" exception as provided
73.12 + * by Oracle in the LICENSE file that accompanied this code.
73.13 + *
73.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
73.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
73.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
73.17 + * version 2 for more details (a copy is included in the LICENSE file that
73.18 + * accompanied this code).
73.19 + *
73.20 + * You should have received a copy of the GNU General Public License version
73.21 + * 2 along with this work; if not, write to the Free Software Foundation,
73.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
73.23 + *
73.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
73.25 + * or visit www.oracle.com if you need additional information or have any
73.26 + * questions.
73.27 + */
73.28 +
73.29 +package java.lang.reflect;
73.30 +
73.31 +import java.lang.annotation.Annotation;
73.32 +
73.33 +
73.34 +/**
73.35 + * A {@code Field} provides information about, and dynamic access to, a
73.36 + * single field of a class or an interface. The reflected field may
73.37 + * be a class (static) field or an instance field.
73.38 + *
73.39 + * <p>A {@code Field} permits widening conversions to occur during a get or
73.40 + * set access operation, but throws an {@code IllegalArgumentException} if a
73.41 + * narrowing conversion would occur.
73.42 + *
73.43 + * @see Member
73.44 + * @see java.lang.Class
73.45 + * @see java.lang.Class#getFields()
73.46 + * @see java.lang.Class#getField(String)
73.47 + * @see java.lang.Class#getDeclaredFields()
73.48 + * @see java.lang.Class#getDeclaredField(String)
73.49 + *
73.50 + * @author Kenneth Russell
73.51 + * @author Nakul Saraiya
73.52 + */
73.53 +public final
73.54 +class Field extends AccessibleObject implements Member {
73.55 +
73.56 + private Class<?> clazz;
73.57 + private int slot;
73.58 + // This is guaranteed to be interned by the VM in the 1.4
73.59 + // reflection implementation
73.60 + private String name;
73.61 + private Class<?> type;
73.62 + private int modifiers;
73.63 + // Generics and annotations support
73.64 + private transient String signature;
73.65 + private byte[] annotations;
73.66 + // For sharing of FieldAccessors. This branching structure is
73.67 + // currently only two levels deep (i.e., one root Field and
73.68 + // potentially many Field objects pointing to it.)
73.69 + private Field root;
73.70 +
73.71 + // Generics infrastructure
73.72 +
73.73 + private String getGenericSignature() {return signature;}
73.74 +
73.75 +
73.76 + /**
73.77 + * Package-private constructor used by ReflectAccess to enable
73.78 + * instantiation of these objects in Java code from the java.lang
73.79 + * package via sun.reflect.LangReflectAccess.
73.80 + */
73.81 + Field(Class<?> declaringClass,
73.82 + String name,
73.83 + Class<?> type,
73.84 + int modifiers,
73.85 + int slot,
73.86 + String signature,
73.87 + byte[] annotations)
73.88 + {
73.89 + this.clazz = declaringClass;
73.90 + this.name = name;
73.91 + this.type = type;
73.92 + this.modifiers = modifiers;
73.93 + this.slot = slot;
73.94 + this.signature = signature;
73.95 + this.annotations = annotations;
73.96 + }
73.97 +
73.98 + /**
73.99 + * Package-private routine (exposed to java.lang.Class via
73.100 + * ReflectAccess) which returns a copy of this Field. The copy's
73.101 + * "root" field points to this Field.
73.102 + */
73.103 + Field copy() {
73.104 + // This routine enables sharing of FieldAccessor objects
73.105 + // among Field objects which refer to the same underlying
73.106 + // method in the VM. (All of this contortion is only necessary
73.107 + // because of the "accessibility" bit in AccessibleObject,
73.108 + // which implicitly requires that new java.lang.reflect
73.109 + // objects be fabricated for each reflective call on Class
73.110 + // objects.)
73.111 + Field res = new Field(clazz, name, type, modifiers, slot, signature, annotations);
73.112 + res.root = this;
73.113 + return res;
73.114 + }
73.115 +
73.116 + /**
73.117 + * Returns the {@code Class} object representing the class or interface
73.118 + * that declares the field represented by this {@code Field} object.
73.119 + */
73.120 + public Class<?> getDeclaringClass() {
73.121 + return clazz;
73.122 + }
73.123 +
73.124 + /**
73.125 + * Returns the name of the field represented by this {@code Field} object.
73.126 + */
73.127 + public String getName() {
73.128 + return name;
73.129 + }
73.130 +
73.131 + /**
73.132 + * Returns the Java language modifiers for the field represented
73.133 + * by this {@code Field} object, as an integer. The {@code Modifier} class should
73.134 + * be used to decode the modifiers.
73.135 + *
73.136 + * @see Modifier
73.137 + */
73.138 + public int getModifiers() {
73.139 + return modifiers;
73.140 + }
73.141 +
73.142 + /**
73.143 + * Returns {@code true} if this field represents an element of
73.144 + * an enumerated type; returns {@code false} otherwise.
73.145 + *
73.146 + * @return {@code true} if and only if this field represents an element of
73.147 + * an enumerated type.
73.148 + * @since 1.5
73.149 + */
73.150 + public boolean isEnumConstant() {
73.151 + return (getModifiers() & Modifier.ENUM) != 0;
73.152 + }
73.153 +
73.154 + /**
73.155 + * Returns {@code true} if this field is a synthetic
73.156 + * field; returns {@code false} otherwise.
73.157 + *
73.158 + * @return true if and only if this field is a synthetic
73.159 + * field as defined by the Java Language Specification.
73.160 + * @since 1.5
73.161 + */
73.162 + public boolean isSynthetic() {
73.163 + return Modifier.isSynthetic(getModifiers());
73.164 + }
73.165 +
73.166 + /**
73.167 + * Returns a {@code Class} object that identifies the
73.168 + * declared type for the field represented by this
73.169 + * {@code Field} object.
73.170 + *
73.171 + * @return a {@code Class} object identifying the declared
73.172 + * type of the field represented by this object
73.173 + */
73.174 + public Class<?> getType() {
73.175 + return type;
73.176 + }
73.177 +
73.178 + /**
73.179 + * Returns a {@code Type} object that represents the declared type for
73.180 + * the field represented by this {@code Field} object.
73.181 + *
73.182 + * <p>If the {@code Type} is a parameterized type, the
73.183 + * {@code Type} object returned must accurately reflect the
73.184 + * actual type parameters used in the source code.
73.185 + *
73.186 + * <p>If the type of the underlying field is a type variable or a
73.187 + * parameterized type, it is created. Otherwise, it is resolved.
73.188 + *
73.189 + * @return a {@code Type} object that represents the declared type for
73.190 + * the field represented by this {@code Field} object
73.191 + * @throws GenericSignatureFormatError if the generic field
73.192 + * signature does not conform to the format specified in
73.193 + * <cite>The Java™ Virtual Machine Specification</cite>
73.194 + * @throws TypeNotPresentException if the generic type
73.195 + * signature of the underlying field refers to a non-existent
73.196 + * type declaration
73.197 + * @throws MalformedParameterizedTypeException if the generic
73.198 + * signature of the underlying field refers to a parameterized type
73.199 + * that cannot be instantiated for any reason
73.200 + * @since 1.5
73.201 + */
73.202 + public Type getGenericType() {
73.203 + throw new UnsupportedOperationException();
73.204 + }
73.205 +
73.206 +
73.207 + /**
73.208 + * Compares this {@code Field} against the specified object. Returns
73.209 + * true if the objects are the same. Two {@code Field} objects are the same if
73.210 + * they were declared by the same class and have the same name
73.211 + * and type.
73.212 + */
73.213 + public boolean equals(Object obj) {
73.214 + if (obj != null && obj instanceof Field) {
73.215 + Field other = (Field)obj;
73.216 + return (getDeclaringClass() == other.getDeclaringClass())
73.217 + && (getName() == other.getName())
73.218 + && (getType() == other.getType());
73.219 + }
73.220 + return false;
73.221 + }
73.222 +
73.223 + /**
73.224 + * Returns a hashcode for this {@code Field}. This is computed as the
73.225 + * exclusive-or of the hashcodes for the underlying field's
73.226 + * declaring class name and its name.
73.227 + */
73.228 + public int hashCode() {
73.229 + return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
73.230 + }
73.231 +
73.232 + /**
73.233 + * Returns a string describing this {@code Field}. The format is
73.234 + * the access modifiers for the field, if any, followed
73.235 + * by the field type, followed by a space, followed by
73.236 + * the fully-qualified name of the class declaring the field,
73.237 + * followed by a period, followed by the name of the field.
73.238 + * For example:
73.239 + * <pre>
73.240 + * public static final int java.lang.Thread.MIN_PRIORITY
73.241 + * private int java.io.FileDescriptor.fd
73.242 + * </pre>
73.243 + *
73.244 + * <p>The modifiers are placed in canonical order as specified by
73.245 + * "The Java Language Specification". This is {@code public},
73.246 + * {@code protected} or {@code private} first, and then other
73.247 + * modifiers in the following order: {@code static}, {@code final},
73.248 + * {@code transient}, {@code volatile}.
73.249 + */
73.250 + public String toString() {
73.251 + int mod = getModifiers();
73.252 + return (((mod == 0) ? "" : (Modifier.toString(mod) + " "))
73.253 + + getTypeName(getType()) + " "
73.254 + + getTypeName(getDeclaringClass()) + "."
73.255 + + getName());
73.256 + }
73.257 +
73.258 + /**
73.259 + * Returns a string describing this {@code Field}, including
73.260 + * its generic type. The format is the access modifiers for the
73.261 + * field, if any, followed by the generic field type, followed by
73.262 + * a space, followed by the fully-qualified name of the class
73.263 + * declaring the field, followed by a period, followed by the name
73.264 + * of the field.
73.265 + *
73.266 + * <p>The modifiers are placed in canonical order as specified by
73.267 + * "The Java Language Specification". This is {@code public},
73.268 + * {@code protected} or {@code private} first, and then other
73.269 + * modifiers in the following order: {@code static}, {@code final},
73.270 + * {@code transient}, {@code volatile}.
73.271 + *
73.272 + * @return a string describing this {@code Field}, including
73.273 + * its generic type
73.274 + *
73.275 + * @since 1.5
73.276 + */
73.277 + public String toGenericString() {
73.278 + int mod = getModifiers();
73.279 + Type fieldType = getGenericType();
73.280 + return (((mod == 0) ? "" : (Modifier.toString(mod) + " "))
73.281 + + ((fieldType instanceof Class) ?
73.282 + getTypeName((Class)fieldType): fieldType.toString())+ " "
73.283 + + getTypeName(getDeclaringClass()) + "."
73.284 + + getName());
73.285 + }
73.286 +
73.287 + /**
73.288 + * Returns the value of the field represented by this {@code Field}, on
73.289 + * the specified object. The value is automatically wrapped in an
73.290 + * object if it has a primitive type.
73.291 + *
73.292 + * <p>The underlying field's value is obtained as follows:
73.293 + *
73.294 + * <p>If the underlying field is a static field, the {@code obj} argument
73.295 + * is ignored; it may be null.
73.296 + *
73.297 + * <p>Otherwise, the underlying field is an instance field. If the
73.298 + * specified {@code obj} argument is null, the method throws a
73.299 + * {@code NullPointerException}. If the specified object is not an
73.300 + * instance of the class or interface declaring the underlying
73.301 + * field, the method throws an {@code IllegalArgumentException}.
73.302 + *
73.303 + * <p>If this {@code Field} object is enforcing Java language access control, and
73.304 + * the underlying field is inaccessible, the method throws an
73.305 + * {@code IllegalAccessException}.
73.306 + * If the underlying field is static, the class that declared the
73.307 + * field is initialized if it has not already been initialized.
73.308 + *
73.309 + * <p>Otherwise, the value is retrieved from the underlying instance
73.310 + * or static field. If the field has a primitive type, the value
73.311 + * is wrapped in an object before being returned, otherwise it is
73.312 + * returned as is.
73.313 + *
73.314 + * <p>If the field is hidden in the type of {@code obj},
73.315 + * the field's value is obtained according to the preceding rules.
73.316 + *
73.317 + * @param obj object from which the represented field's value is
73.318 + * to be extracted
73.319 + * @return the value of the represented field in object
73.320 + * {@code obj}; primitive values are wrapped in an appropriate
73.321 + * object before being returned
73.322 + *
73.323 + * @exception IllegalAccessException if this {@code Field} object
73.324 + * is enforcing Java language access control and the underlying
73.325 + * field is inaccessible.
73.326 + * @exception IllegalArgumentException if the specified object is not an
73.327 + * instance of the class or interface declaring the underlying
73.328 + * field (or a subclass or implementor thereof).
73.329 + * @exception NullPointerException if the specified object is null
73.330 + * and the field is an instance field.
73.331 + * @exception ExceptionInInitializerError if the initialization provoked
73.332 + * by this method fails.
73.333 + */
73.334 + public Object get(Object obj)
73.335 + throws IllegalArgumentException, IllegalAccessException
73.336 + {
73.337 + return getFieldAccessor(obj).get(obj);
73.338 + }
73.339 +
73.340 + /**
73.341 + * Gets the value of a static or instance {@code boolean} field.
73.342 + *
73.343 + * @param obj the object to extract the {@code boolean} value
73.344 + * from
73.345 + * @return the value of the {@code boolean} field
73.346 + *
73.347 + * @exception IllegalAccessException if this {@code Field} object
73.348 + * is enforcing Java language access control and the underlying
73.349 + * field is inaccessible.
73.350 + * @exception IllegalArgumentException if the specified object is not
73.351 + * an instance of the class or interface declaring the
73.352 + * underlying field (or a subclass or implementor
73.353 + * thereof), or if the field value cannot be
73.354 + * converted to the type {@code boolean} by a
73.355 + * widening conversion.
73.356 + * @exception NullPointerException if the specified object is null
73.357 + * and the field is an instance field.
73.358 + * @exception ExceptionInInitializerError if the initialization provoked
73.359 + * by this method fails.
73.360 + * @see Field#get
73.361 + */
73.362 + public boolean getBoolean(Object obj)
73.363 + throws IllegalArgumentException, IllegalAccessException
73.364 + {
73.365 + return getFieldAccessor(obj).getBoolean(obj);
73.366 + }
73.367 +
73.368 + /**
73.369 + * Gets the value of a static or instance {@code byte} field.
73.370 + *
73.371 + * @param obj the object to extract the {@code byte} value
73.372 + * from
73.373 + * @return the value of the {@code byte} field
73.374 + *
73.375 + * @exception IllegalAccessException if this {@code Field} object
73.376 + * is enforcing Java language access control and the underlying
73.377 + * field is inaccessible.
73.378 + * @exception IllegalArgumentException if the specified object is not
73.379 + * an instance of the class or interface declaring the
73.380 + * underlying field (or a subclass or implementor
73.381 + * thereof), or if the field value cannot be
73.382 + * converted to the type {@code byte} by a
73.383 + * widening conversion.
73.384 + * @exception NullPointerException if the specified object is null
73.385 + * and the field is an instance field.
73.386 + * @exception ExceptionInInitializerError if the initialization provoked
73.387 + * by this method fails.
73.388 + * @see Field#get
73.389 + */
73.390 + public byte getByte(Object obj)
73.391 + throws IllegalArgumentException, IllegalAccessException
73.392 + {
73.393 + return getFieldAccessor(obj).getByte(obj);
73.394 + }
73.395 +
73.396 + /**
73.397 + * Gets the value of a static or instance field of type
73.398 + * {@code char} or of another primitive type convertible to
73.399 + * type {@code char} via a widening conversion.
73.400 + *
73.401 + * @param obj the object to extract the {@code char} value
73.402 + * from
73.403 + * @return the value of the field converted to type {@code char}
73.404 + *
73.405 + * @exception IllegalAccessException if this {@code Field} object
73.406 + * is enforcing Java language access control and the underlying
73.407 + * field is inaccessible.
73.408 + * @exception IllegalArgumentException if the specified object is not
73.409 + * an instance of the class or interface declaring the
73.410 + * underlying field (or a subclass or implementor
73.411 + * thereof), or if the field value cannot be
73.412 + * converted to the type {@code char} by a
73.413 + * widening conversion.
73.414 + * @exception NullPointerException if the specified object is null
73.415 + * and the field is an instance field.
73.416 + * @exception ExceptionInInitializerError if the initialization provoked
73.417 + * by this method fails.
73.418 + * @see Field#get
73.419 + */
73.420 + public char getChar(Object obj)
73.421 + throws IllegalArgumentException, IllegalAccessException
73.422 + {
73.423 + return getFieldAccessor(obj).getChar(obj);
73.424 + }
73.425 +
73.426 + /**
73.427 + * Gets the value of a static or instance field of type
73.428 + * {@code short} or of another primitive type convertible to
73.429 + * type {@code short} via a widening conversion.
73.430 + *
73.431 + * @param obj the object to extract the {@code short} value
73.432 + * from
73.433 + * @return the value of the field converted to type {@code short}
73.434 + *
73.435 + * @exception IllegalAccessException if this {@code Field} object
73.436 + * is enforcing Java language access control and the underlying
73.437 + * field is inaccessible.
73.438 + * @exception IllegalArgumentException if the specified object is not
73.439 + * an instance of the class or interface declaring the
73.440 + * underlying field (or a subclass or implementor
73.441 + * thereof), or if the field value cannot be
73.442 + * converted to the type {@code short} by a
73.443 + * widening conversion.
73.444 + * @exception NullPointerException if the specified object is null
73.445 + * and the field is an instance field.
73.446 + * @exception ExceptionInInitializerError if the initialization provoked
73.447 + * by this method fails.
73.448 + * @see Field#get
73.449 + */
73.450 + public short getShort(Object obj)
73.451 + throws IllegalArgumentException, IllegalAccessException
73.452 + {
73.453 + return getFieldAccessor(obj).getShort(obj);
73.454 + }
73.455 +
73.456 + /**
73.457 + * Gets the value of a static or instance field of type
73.458 + * {@code int} or of another primitive type convertible to
73.459 + * type {@code int} via a widening conversion.
73.460 + *
73.461 + * @param obj the object to extract the {@code int} value
73.462 + * from
73.463 + * @return the value of the field converted to type {@code int}
73.464 + *
73.465 + * @exception IllegalAccessException if this {@code Field} object
73.466 + * is enforcing Java language access control and the underlying
73.467 + * field is inaccessible.
73.468 + * @exception IllegalArgumentException if the specified object is not
73.469 + * an instance of the class or interface declaring the
73.470 + * underlying field (or a subclass or implementor
73.471 + * thereof), or if the field value cannot be
73.472 + * converted to the type {@code int} by a
73.473 + * widening conversion.
73.474 + * @exception NullPointerException if the specified object is null
73.475 + * and the field is an instance field.
73.476 + * @exception ExceptionInInitializerError if the initialization provoked
73.477 + * by this method fails.
73.478 + * @see Field#get
73.479 + */
73.480 + public int getInt(Object obj)
73.481 + throws IllegalArgumentException, IllegalAccessException
73.482 + {
73.483 + return getFieldAccessor(obj).getInt(obj);
73.484 + }
73.485 +
73.486 + /**
73.487 + * Gets the value of a static or instance field of type
73.488 + * {@code long} or of another primitive type convertible to
73.489 + * type {@code long} via a widening conversion.
73.490 + *
73.491 + * @param obj the object to extract the {@code long} value
73.492 + * from
73.493 + * @return the value of the field converted to type {@code long}
73.494 + *
73.495 + * @exception IllegalAccessException if this {@code Field} object
73.496 + * is enforcing Java language access control and the underlying
73.497 + * field is inaccessible.
73.498 + * @exception IllegalArgumentException if the specified object is not
73.499 + * an instance of the class or interface declaring the
73.500 + * underlying field (or a subclass or implementor
73.501 + * thereof), or if the field value cannot be
73.502 + * converted to the type {@code long} by a
73.503 + * widening conversion.
73.504 + * @exception NullPointerException if the specified object is null
73.505 + * and the field is an instance field.
73.506 + * @exception ExceptionInInitializerError if the initialization provoked
73.507 + * by this method fails.
73.508 + * @see Field#get
73.509 + */
73.510 + public long getLong(Object obj)
73.511 + throws IllegalArgumentException, IllegalAccessException
73.512 + {
73.513 + return getFieldAccessor(obj).getLong(obj);
73.514 + }
73.515 +
73.516 + /**
73.517 + * Gets the value of a static or instance field of type
73.518 + * {@code float} or of another primitive type convertible to
73.519 + * type {@code float} via a widening conversion.
73.520 + *
73.521 + * @param obj the object to extract the {@code float} value
73.522 + * from
73.523 + * @return the value of the field converted to type {@code float}
73.524 + *
73.525 + * @exception IllegalAccessException if this {@code Field} object
73.526 + * is enforcing Java language access control and the underlying
73.527 + * field is inaccessible.
73.528 + * @exception IllegalArgumentException if the specified object is not
73.529 + * an instance of the class or interface declaring the
73.530 + * underlying field (or a subclass or implementor
73.531 + * thereof), or if the field value cannot be
73.532 + * converted to the type {@code float} by a
73.533 + * widening conversion.
73.534 + * @exception NullPointerException if the specified object is null
73.535 + * and the field is an instance field.
73.536 + * @exception ExceptionInInitializerError if the initialization provoked
73.537 + * by this method fails.
73.538 + * @see Field#get
73.539 + */
73.540 + public float getFloat(Object obj)
73.541 + throws IllegalArgumentException, IllegalAccessException
73.542 + {
73.543 + return getFieldAccessor(obj).getFloat(obj);
73.544 + }
73.545 +
73.546 + /**
73.547 + * Gets the value of a static or instance field of type
73.548 + * {@code double} or of another primitive type convertible to
73.549 + * type {@code double} via a widening conversion.
73.550 + *
73.551 + * @param obj the object to extract the {@code double} value
73.552 + * from
73.553 + * @return the value of the field converted to type {@code double}
73.554 + *
73.555 + * @exception IllegalAccessException if this {@code Field} object
73.556 + * is enforcing Java language access control and the underlying
73.557 + * field is inaccessible.
73.558 + * @exception IllegalArgumentException if the specified object is not
73.559 + * an instance of the class or interface declaring the
73.560 + * underlying field (or a subclass or implementor
73.561 + * thereof), or if the field value cannot be
73.562 + * converted to the type {@code double} by a
73.563 + * widening conversion.
73.564 + * @exception NullPointerException if the specified object is null
73.565 + * and the field is an instance field.
73.566 + * @exception ExceptionInInitializerError if the initialization provoked
73.567 + * by this method fails.
73.568 + * @see Field#get
73.569 + */
73.570 + public double getDouble(Object obj)
73.571 + throws IllegalArgumentException, IllegalAccessException
73.572 + {
73.573 + return getFieldAccessor(obj).getDouble(obj);
73.574 + }
73.575 +
73.576 + /**
73.577 + * Sets the field represented by this {@code Field} object on the
73.578 + * specified object argument to the specified new value. The new
73.579 + * value is automatically unwrapped if the underlying field has a
73.580 + * primitive type.
73.581 + *
73.582 + * <p>The operation proceeds as follows:
73.583 + *
73.584 + * <p>If the underlying field is static, the {@code obj} argument is
73.585 + * ignored; it may be null.
73.586 + *
73.587 + * <p>Otherwise the underlying field is an instance field. If the
73.588 + * specified object argument is null, the method throws a
73.589 + * {@code NullPointerException}. If the specified object argument is not
73.590 + * an instance of the class or interface declaring the underlying
73.591 + * field, the method throws an {@code IllegalArgumentException}.
73.592 + *
73.593 + * <p>If this {@code Field} object is enforcing Java language access control, and
73.594 + * the underlying field is inaccessible, the method throws an
73.595 + * {@code IllegalAccessException}.
73.596 + *
73.597 + * <p>If the underlying field is final, the method throws an
73.598 + * {@code IllegalAccessException} unless {@code setAccessible(true)}
73.599 + * has succeeded for this {@code Field} object
73.600 + * and the field is non-static. Setting a final field in this way
73.601 + * is meaningful only during deserialization or reconstruction of
73.602 + * instances of classes with blank final fields, before they are
73.603 + * made available for access by other parts of a program. Use in
73.604 + * any other context may have unpredictable effects, including cases
73.605 + * in which other parts of a program continue to use the original
73.606 + * value of this field.
73.607 + *
73.608 + * <p>If the underlying field is of a primitive type, an unwrapping
73.609 + * conversion is attempted to convert the new value to a value of
73.610 + * a primitive type. If this attempt fails, the method throws an
73.611 + * {@code IllegalArgumentException}.
73.612 + *
73.613 + * <p>If, after possible unwrapping, the new value cannot be
73.614 + * converted to the type of the underlying field by an identity or
73.615 + * widening conversion, the method throws an
73.616 + * {@code IllegalArgumentException}.
73.617 + *
73.618 + * <p>If the underlying field is static, the class that declared the
73.619 + * field is initialized if it has not already been initialized.
73.620 + *
73.621 + * <p>The field is set to the possibly unwrapped and widened new value.
73.622 + *
73.623 + * <p>If the field is hidden in the type of {@code obj},
73.624 + * the field's value is set according to the preceding rules.
73.625 + *
73.626 + * @param obj the object whose field should be modified
73.627 + * @param value the new value for the field of {@code obj}
73.628 + * being modified
73.629 + *
73.630 + * @exception IllegalAccessException if this {@code Field} object
73.631 + * is enforcing Java language access control and the underlying
73.632 + * field is either inaccessible or final.
73.633 + * @exception IllegalArgumentException if the specified object is not an
73.634 + * instance of the class or interface declaring the underlying
73.635 + * field (or a subclass or implementor thereof),
73.636 + * or if an unwrapping conversion fails.
73.637 + * @exception NullPointerException if the specified object is null
73.638 + * and the field is an instance field.
73.639 + * @exception ExceptionInInitializerError if the initialization provoked
73.640 + * by this method fails.
73.641 + */
73.642 + public void set(Object obj, Object value)
73.643 + throws IllegalArgumentException, IllegalAccessException
73.644 + {
73.645 + getFieldAccessor(obj).set(obj, value);
73.646 + }
73.647 +
73.648 + /**
73.649 + * Sets the value of a field as a {@code boolean} on the specified object.
73.650 + * This method is equivalent to
73.651 + * {@code set(obj, zObj)},
73.652 + * where {@code zObj} is a {@code Boolean} object and
73.653 + * {@code zObj.booleanValue() == z}.
73.654 + *
73.655 + * @param obj the object whose field should be modified
73.656 + * @param z the new value for the field of {@code obj}
73.657 + * being modified
73.658 + *
73.659 + * @exception IllegalAccessException if this {@code Field} object
73.660 + * is enforcing Java language access control and the underlying
73.661 + * field is either inaccessible or final.
73.662 + * @exception IllegalArgumentException if the specified object is not an
73.663 + * instance of the class or interface declaring the underlying
73.664 + * field (or a subclass or implementor thereof),
73.665 + * or if an unwrapping conversion fails.
73.666 + * @exception NullPointerException if the specified object is null
73.667 + * and the field is an instance field.
73.668 + * @exception ExceptionInInitializerError if the initialization provoked
73.669 + * by this method fails.
73.670 + * @see Field#set
73.671 + */
73.672 + public void setBoolean(Object obj, boolean z)
73.673 + throws IllegalArgumentException, IllegalAccessException
73.674 + {
73.675 + getFieldAccessor(obj).setBoolean(obj, z);
73.676 + }
73.677 +
73.678 + /**
73.679 + * Sets the value of a field as a {@code byte} on the specified object.
73.680 + * This method is equivalent to
73.681 + * {@code set(obj, bObj)},
73.682 + * where {@code bObj} is a {@code Byte} object and
73.683 + * {@code bObj.byteValue() == b}.
73.684 + *
73.685 + * @param obj the object whose field should be modified
73.686 + * @param b the new value for the field of {@code obj}
73.687 + * being modified
73.688 + *
73.689 + * @exception IllegalAccessException if this {@code Field} object
73.690 + * is enforcing Java language access control and the underlying
73.691 + * field is either inaccessible or final.
73.692 + * @exception IllegalArgumentException if the specified object is not an
73.693 + * instance of the class or interface declaring the underlying
73.694 + * field (or a subclass or implementor thereof),
73.695 + * or if an unwrapping conversion fails.
73.696 + * @exception NullPointerException if the specified object is null
73.697 + * and the field is an instance field.
73.698 + * @exception ExceptionInInitializerError if the initialization provoked
73.699 + * by this method fails.
73.700 + * @see Field#set
73.701 + */
73.702 + public void setByte(Object obj, byte b)
73.703 + throws IllegalArgumentException, IllegalAccessException
73.704 + {
73.705 + getFieldAccessor(obj).setByte(obj, b);
73.706 + }
73.707 +
73.708 + /**
73.709 + * Sets the value of a field as a {@code char} on the specified object.
73.710 + * This method is equivalent to
73.711 + * {@code set(obj, cObj)},
73.712 + * where {@code cObj} is a {@code Character} object and
73.713 + * {@code cObj.charValue() == c}.
73.714 + *
73.715 + * @param obj the object whose field should be modified
73.716 + * @param c the new value for the field of {@code obj}
73.717 + * being modified
73.718 + *
73.719 + * @exception IllegalAccessException if this {@code Field} object
73.720 + * is enforcing Java language access control and the underlying
73.721 + * field is either inaccessible or final.
73.722 + * @exception IllegalArgumentException if the specified object is not an
73.723 + * instance of the class or interface declaring the underlying
73.724 + * field (or a subclass or implementor thereof),
73.725 + * or if an unwrapping conversion fails.
73.726 + * @exception NullPointerException if the specified object is null
73.727 + * and the field is an instance field.
73.728 + * @exception ExceptionInInitializerError if the initialization provoked
73.729 + * by this method fails.
73.730 + * @see Field#set
73.731 + */
73.732 + public void setChar(Object obj, char c)
73.733 + throws IllegalArgumentException, IllegalAccessException
73.734 + {
73.735 + getFieldAccessor(obj).setChar(obj, c);
73.736 + }
73.737 +
73.738 + /**
73.739 + * Sets the value of a field as a {@code short} on the specified object.
73.740 + * This method is equivalent to
73.741 + * {@code set(obj, sObj)},
73.742 + * where {@code sObj} is a {@code Short} object and
73.743 + * {@code sObj.shortValue() == s}.
73.744 + *
73.745 + * @param obj the object whose field should be modified
73.746 + * @param s the new value for the field of {@code obj}
73.747 + * being modified
73.748 + *
73.749 + * @exception IllegalAccessException if this {@code Field} object
73.750 + * is enforcing Java language access control and the underlying
73.751 + * field is either inaccessible or final.
73.752 + * @exception IllegalArgumentException if the specified object is not an
73.753 + * instance of the class or interface declaring the underlying
73.754 + * field (or a subclass or implementor thereof),
73.755 + * or if an unwrapping conversion fails.
73.756 + * @exception NullPointerException if the specified object is null
73.757 + * and the field is an instance field.
73.758 + * @exception ExceptionInInitializerError if the initialization provoked
73.759 + * by this method fails.
73.760 + * @see Field#set
73.761 + */
73.762 + public void setShort(Object obj, short s)
73.763 + throws IllegalArgumentException, IllegalAccessException
73.764 + {
73.765 + getFieldAccessor(obj).setShort(obj, s);
73.766 + }
73.767 +
73.768 + /**
73.769 + * Sets the value of a field as an {@code int} on the specified object.
73.770 + * This method is equivalent to
73.771 + * {@code set(obj, iObj)},
73.772 + * where {@code iObj} is a {@code Integer} object and
73.773 + * {@code iObj.intValue() == i}.
73.774 + *
73.775 + * @param obj the object whose field should be modified
73.776 + * @param i the new value for the field of {@code obj}
73.777 + * being modified
73.778 + *
73.779 + * @exception IllegalAccessException if this {@code Field} object
73.780 + * is enforcing Java language access control and the underlying
73.781 + * field is either inaccessible or final.
73.782 + * @exception IllegalArgumentException if the specified object is not an
73.783 + * instance of the class or interface declaring the underlying
73.784 + * field (or a subclass or implementor thereof),
73.785 + * or if an unwrapping conversion fails.
73.786 + * @exception NullPointerException if the specified object is null
73.787 + * and the field is an instance field.
73.788 + * @exception ExceptionInInitializerError if the initialization provoked
73.789 + * by this method fails.
73.790 + * @see Field#set
73.791 + */
73.792 + public void setInt(Object obj, int i)
73.793 + throws IllegalArgumentException, IllegalAccessException
73.794 + {
73.795 + getFieldAccessor(obj).setInt(obj, i);
73.796 + }
73.797 +
73.798 + /**
73.799 + * Sets the value of a field as a {@code long} on the specified object.
73.800 + * This method is equivalent to
73.801 + * {@code set(obj, lObj)},
73.802 + * where {@code lObj} is a {@code Long} object and
73.803 + * {@code lObj.longValue() == l}.
73.804 + *
73.805 + * @param obj the object whose field should be modified
73.806 + * @param l the new value for the field of {@code obj}
73.807 + * being modified
73.808 + *
73.809 + * @exception IllegalAccessException if this {@code Field} object
73.810 + * is enforcing Java language access control and the underlying
73.811 + * field is either inaccessible or final.
73.812 + * @exception IllegalArgumentException if the specified object is not an
73.813 + * instance of the class or interface declaring the underlying
73.814 + * field (or a subclass or implementor thereof),
73.815 + * or if an unwrapping conversion fails.
73.816 + * @exception NullPointerException if the specified object is null
73.817 + * and the field is an instance field.
73.818 + * @exception ExceptionInInitializerError if the initialization provoked
73.819 + * by this method fails.
73.820 + * @see Field#set
73.821 + */
73.822 + public void setLong(Object obj, long l)
73.823 + throws IllegalArgumentException, IllegalAccessException
73.824 + {
73.825 + getFieldAccessor(obj).setLong(obj, l);
73.826 + }
73.827 +
73.828 + /**
73.829 + * Sets the value of a field as a {@code float} on the specified object.
73.830 + * This method is equivalent to
73.831 + * {@code set(obj, fObj)},
73.832 + * where {@code fObj} is a {@code Float} object and
73.833 + * {@code fObj.floatValue() == f}.
73.834 + *
73.835 + * @param obj the object whose field should be modified
73.836 + * @param f the new value for the field of {@code obj}
73.837 + * being modified
73.838 + *
73.839 + * @exception IllegalAccessException if this {@code Field} object
73.840 + * is enforcing Java language access control and the underlying
73.841 + * field is either inaccessible or final.
73.842 + * @exception IllegalArgumentException if the specified object is not an
73.843 + * instance of the class or interface declaring the underlying
73.844 + * field (or a subclass or implementor thereof),
73.845 + * or if an unwrapping conversion fails.
73.846 + * @exception NullPointerException if the specified object is null
73.847 + * and the field is an instance field.
73.848 + * @exception ExceptionInInitializerError if the initialization provoked
73.849 + * by this method fails.
73.850 + * @see Field#set
73.851 + */
73.852 + public void setFloat(Object obj, float f)
73.853 + throws IllegalArgumentException, IllegalAccessException
73.854 + {
73.855 + getFieldAccessor(obj).setFloat(obj, f);
73.856 + }
73.857 +
73.858 + /**
73.859 + * Sets the value of a field as a {@code double} on the specified object.
73.860 + * This method is equivalent to
73.861 + * {@code set(obj, dObj)},
73.862 + * where {@code dObj} is a {@code Double} object and
73.863 + * {@code dObj.doubleValue() == d}.
73.864 + *
73.865 + * @param obj the object whose field should be modified
73.866 + * @param d the new value for the field of {@code obj}
73.867 + * being modified
73.868 + *
73.869 + * @exception IllegalAccessException if this {@code Field} object
73.870 + * is enforcing Java language access control and the underlying
73.871 + * field is either inaccessible or final.
73.872 + * @exception IllegalArgumentException if the specified object is not an
73.873 + * instance of the class or interface declaring the underlying
73.874 + * field (or a subclass or implementor thereof),
73.875 + * or if an unwrapping conversion fails.
73.876 + * @exception NullPointerException if the specified object is null
73.877 + * and the field is an instance field.
73.878 + * @exception ExceptionInInitializerError if the initialization provoked
73.879 + * by this method fails.
73.880 + * @see Field#set
73.881 + */
73.882 + public void setDouble(Object obj, double d)
73.883 + throws IllegalArgumentException, IllegalAccessException
73.884 + {
73.885 + getFieldAccessor(obj).setDouble(obj, d);
73.886 + }
73.887 +
73.888 + // Convenience routine which performs security checks
73.889 + private FieldAccessor getFieldAccessor(Object obj)
73.890 + throws IllegalAccessException
73.891 + {
73.892 + throw new SecurityException();
73.893 + }
73.894 +
73.895 + private static abstract class FieldAccessor {
73.896 + abstract void setShort(Object obj, short s);
73.897 + abstract void setInt(Object obj, int i);
73.898 + abstract void setChar(Object obj, char c);
73.899 + abstract void setByte(Object obj, byte b);
73.900 + abstract void setBoolean(Object obj, boolean z);
73.901 + abstract void set(Object obj, Object value);
73.902 + abstract double getDouble(Object obj);
73.903 + abstract void setLong(Object obj, long l);
73.904 + abstract void setFloat(Object obj, float f);
73.905 + abstract void setDouble(Object obj, double d);
73.906 + abstract long getLong(Object obj);
73.907 + abstract int getInt(Object obj);
73.908 + abstract short getShort(Object obj);
73.909 + abstract char getChar(Object obj);
73.910 + abstract byte getByte(Object obj);
73.911 + abstract boolean getBoolean(Object obj);
73.912 + abstract Object get(Object obj);
73.913 + abstract float getFloat(Object obj);
73.914 + }
73.915 +
73.916 + /*
73.917 + * Utility routine to paper over array type names
73.918 + */
73.919 + static String getTypeName(Class<?> type) {
73.920 + if (type.isArray()) {
73.921 + try {
73.922 + Class<?> cl = type;
73.923 + int dimensions = 0;
73.924 + while (cl.isArray()) {
73.925 + dimensions++;
73.926 + cl = cl.getComponentType();
73.927 + }
73.928 + StringBuffer sb = new StringBuffer();
73.929 + sb.append(cl.getName());
73.930 + for (int i = 0; i < dimensions; i++) {
73.931 + sb.append("[]");
73.932 + }
73.933 + return sb.toString();
73.934 + } catch (Throwable e) { /*FALLTHRU*/ }
73.935 + }
73.936 + return type.getName();
73.937 + }
73.938 +
73.939 + /**
73.940 + * @throws NullPointerException {@inheritDoc}
73.941 + * @since 1.5
73.942 + */
73.943 + public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
73.944 + if (annotationClass == null)
73.945 + throw new NullPointerException();
73.946 +
73.947 + throw new UnsupportedOperationException();
73.948 + }
73.949 +
73.950 + /**
73.951 + * @since 1.5
73.952 + */
73.953 + public Annotation[] getDeclaredAnnotations() {
73.954 + throw new UnsupportedOperationException();
73.955 + }
73.956 +}
74.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
74.2 +++ b/emul/src/main/java/java/lang/reflect/GenericDeclaration.java Wed Jan 23 20:16:48 2013 +0100
74.3 @@ -0,0 +1,49 @@
74.4 +/*
74.5 + * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
74.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
74.7 + *
74.8 + * This code is free software; you can redistribute it and/or modify it
74.9 + * under the terms of the GNU General Public License version 2 only, as
74.10 + * published by the Free Software Foundation. Oracle designates this
74.11 + * particular file as subject to the "Classpath" exception as provided
74.12 + * by Oracle in the LICENSE file that accompanied this code.
74.13 + *
74.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
74.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
74.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
74.17 + * version 2 for more details (a copy is included in the LICENSE file that
74.18 + * accompanied this code).
74.19 + *
74.20 + * You should have received a copy of the GNU General Public License version
74.21 + * 2 along with this work; if not, write to the Free Software Foundation,
74.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
74.23 + *
74.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
74.25 + * or visit www.oracle.com if you need additional information or have any
74.26 + * questions.
74.27 + */
74.28 +
74.29 +package java.lang.reflect;
74.30 +
74.31 +/**
74.32 + * A common interface for all entities that declare type variables.
74.33 + *
74.34 + * @since 1.5
74.35 + */
74.36 +public interface GenericDeclaration {
74.37 + /**
74.38 + * Returns an array of {@code TypeVariable} objects that
74.39 + * represent the type variables declared by the generic
74.40 + * declaration represented by this {@code GenericDeclaration}
74.41 + * object, in declaration order. Returns an array of length 0 if
74.42 + * the underlying generic declaration declares no type variables.
74.43 + *
74.44 + * @return an array of {@code TypeVariable} objects that represent
74.45 + * the type variables declared by this generic declaration
74.46 + * @throws GenericSignatureFormatError if the generic
74.47 + * signature of this generic declaration does not conform to
74.48 + * the format specified in
74.49 + * <cite>The Java™ Virtual Machine Specification</cite>
74.50 + */
74.51 + public TypeVariable<?>[] getTypeParameters();
74.52 +}
75.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
75.2 +++ b/emul/src/main/java/java/lang/reflect/InvocationTargetException.java Wed Jan 23 20:16:48 2013 +0100
75.3 @@ -0,0 +1,111 @@
75.4 +/*
75.5 + * Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.
75.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
75.7 + *
75.8 + * This code is free software; you can redistribute it and/or modify it
75.9 + * under the terms of the GNU General Public License version 2 only, as
75.10 + * published by the Free Software Foundation. Oracle designates this
75.11 + * particular file as subject to the "Classpath" exception as provided
75.12 + * by Oracle in the LICENSE file that accompanied this code.
75.13 + *
75.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
75.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
75.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
75.17 + * version 2 for more details (a copy is included in the LICENSE file that
75.18 + * accompanied this code).
75.19 + *
75.20 + * You should have received a copy of the GNU General Public License version
75.21 + * 2 along with this work; if not, write to the Free Software Foundation,
75.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
75.23 + *
75.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
75.25 + * or visit www.oracle.com if you need additional information or have any
75.26 + * questions.
75.27 + */
75.28 +
75.29 +package java.lang.reflect;
75.30 +
75.31 +/**
75.32 + * InvocationTargetException is a checked exception that wraps
75.33 + * an exception thrown by an invoked method or constructor.
75.34 + *
75.35 + * <p>As of release 1.4, this exception has been retrofitted to conform to
75.36 + * the general purpose exception-chaining mechanism. The "target exception"
75.37 + * that is provided at construction time and accessed via the
75.38 + * {@link #getTargetException()} method is now known as the <i>cause</i>,
75.39 + * and may be accessed via the {@link Throwable#getCause()} method,
75.40 + * as well as the aforementioned "legacy method."
75.41 + *
75.42 + * @see Method
75.43 + * @see Constructor
75.44 + */
75.45 +public class InvocationTargetException extends ReflectiveOperationException {
75.46 + /**
75.47 + * Use serialVersionUID from JDK 1.1.X for interoperability
75.48 + */
75.49 + private static final long serialVersionUID = 4085088731926701167L;
75.50 +
75.51 + /**
75.52 + * This field holds the target if the
75.53 + * InvocationTargetException(Throwable target) constructor was
75.54 + * used to instantiate the object
75.55 + *
75.56 + * @serial
75.57 + *
75.58 + */
75.59 + private Throwable target;
75.60 +
75.61 + /**
75.62 + * Constructs an {@code InvocationTargetException} with
75.63 + * {@code null} as the target exception.
75.64 + */
75.65 + protected InvocationTargetException() {
75.66 + super((Throwable)null); // Disallow initCause
75.67 + }
75.68 +
75.69 + /**
75.70 + * Constructs a InvocationTargetException with a target exception.
75.71 + *
75.72 + * @param target the target exception
75.73 + */
75.74 + public InvocationTargetException(Throwable target) {
75.75 + super((Throwable)null); // Disallow initCause
75.76 + this.target = target;
75.77 + }
75.78 +
75.79 + /**
75.80 + * Constructs a InvocationTargetException with a target exception
75.81 + * and a detail message.
75.82 + *
75.83 + * @param target the target exception
75.84 + * @param s the detail message
75.85 + */
75.86 + public InvocationTargetException(Throwable target, String s) {
75.87 + super(s, null); // Disallow initCause
75.88 + this.target = target;
75.89 + }
75.90 +
75.91 + /**
75.92 + * Get the thrown target exception.
75.93 + *
75.94 + * <p>This method predates the general-purpose exception chaining facility.
75.95 + * The {@link Throwable#getCause()} method is now the preferred means of
75.96 + * obtaining this information.
75.97 + *
75.98 + * @return the thrown target exception (cause of this exception).
75.99 + */
75.100 + public Throwable getTargetException() {
75.101 + return target;
75.102 + }
75.103 +
75.104 + /**
75.105 + * Returns the cause of this exception (the thrown target exception,
75.106 + * which may be {@code null}).
75.107 + *
75.108 + * @return the cause of this exception.
75.109 + * @since 1.4
75.110 + */
75.111 + public Throwable getCause() {
75.112 + return target;
75.113 + }
75.114 +}
76.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
76.2 +++ b/emul/src/main/java/java/lang/reflect/Member.java Wed Jan 23 20:16:48 2013 +0100
76.3 @@ -0,0 +1,93 @@
76.4 +/*
76.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
76.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
76.7 + *
76.8 + * This code is free software; you can redistribute it and/or modify it
76.9 + * under the terms of the GNU General Public License version 2 only, as
76.10 + * published by the Free Software Foundation. Oracle designates this
76.11 + * particular file as subject to the "Classpath" exception as provided
76.12 + * by Oracle in the LICENSE file that accompanied this code.
76.13 + *
76.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
76.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
76.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
76.17 + * version 2 for more details (a copy is included in the LICENSE file that
76.18 + * accompanied this code).
76.19 + *
76.20 + * You should have received a copy of the GNU General Public License version
76.21 + * 2 along with this work; if not, write to the Free Software Foundation,
76.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
76.23 + *
76.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
76.25 + * or visit www.oracle.com if you need additional information or have any
76.26 + * questions.
76.27 + */
76.28 +
76.29 +package java.lang.reflect;
76.30 +
76.31 +/**
76.32 + * Member is an interface that reflects identifying information about
76.33 + * a single member (a field or a method) or a constructor.
76.34 + *
76.35 + * @see java.lang.Class
76.36 + * @see Field
76.37 + * @see Method
76.38 + * @see Constructor
76.39 + *
76.40 + * @author Nakul Saraiya
76.41 + */
76.42 +public
76.43 +interface Member {
76.44 +
76.45 + /**
76.46 + * Identifies the set of all public members of a class or interface,
76.47 + * including inherited members.
76.48 + * @see java.lang.SecurityManager#checkMemberAccess
76.49 + */
76.50 + public static final int PUBLIC = 0;
76.51 +
76.52 + /**
76.53 + * Identifies the set of declared members of a class or interface.
76.54 + * Inherited members are not included.
76.55 + * @see java.lang.SecurityManager#checkMemberAccess
76.56 + */
76.57 + public static final int DECLARED = 1;
76.58 +
76.59 + /**
76.60 + * Returns the Class object representing the class or interface
76.61 + * that declares the member or constructor represented by this Member.
76.62 + *
76.63 + * @return an object representing the declaring class of the
76.64 + * underlying member
76.65 + */
76.66 + public Class<?> getDeclaringClass();
76.67 +
76.68 + /**
76.69 + * Returns the simple name of the underlying member or constructor
76.70 + * represented by this Member.
76.71 + *
76.72 + * @return the simple name of the underlying member
76.73 + */
76.74 + public String getName();
76.75 +
76.76 + /**
76.77 + * Returns the Java language modifiers for the member or
76.78 + * constructor represented by this Member, as an integer. The
76.79 + * Modifier class should be used to decode the modifiers in
76.80 + * the integer.
76.81 + *
76.82 + * @return the Java language modifiers for the underlying member
76.83 + * @see Modifier
76.84 + */
76.85 + public int getModifiers();
76.86 +
76.87 + /**
76.88 + * Returns {@code true} if this member was introduced by
76.89 + * the compiler; returns {@code false} otherwise.
76.90 + *
76.91 + * @return true if and only if this member was introduced by
76.92 + * the compiler.
76.93 + * @since 1.5
76.94 + */
76.95 + public boolean isSynthetic();
76.96 +}
77.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
77.2 +++ b/emul/src/main/java/java/lang/reflect/Method.java Wed Jan 23 20:16:48 2013 +0100
77.3 @@ -0,0 +1,720 @@
77.4 +/*
77.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
77.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
77.7 + *
77.8 + * This code is free software; you can redistribute it and/or modify it
77.9 + * under the terms of the GNU General Public License version 2 only, as
77.10 + * published by the Free Software Foundation. Oracle designates this
77.11 + * particular file as subject to the "Classpath" exception as provided
77.12 + * by Oracle in the LICENSE file that accompanied this code.
77.13 + *
77.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
77.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
77.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
77.17 + * version 2 for more details (a copy is included in the LICENSE file that
77.18 + * accompanied this code).
77.19 + *
77.20 + * You should have received a copy of the GNU General Public License version
77.21 + * 2 along with this work; if not, write to the Free Software Foundation,
77.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
77.23 + *
77.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
77.25 + * or visit www.oracle.com if you need additional information or have any
77.26 + * questions.
77.27 + */
77.28 +
77.29 +package java.lang.reflect;
77.30 +
77.31 +import java.lang.annotation.Annotation;
77.32 +import java.util.Enumeration;
77.33 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
77.34 +import org.apidesign.bck2brwsr.emul.AnnotationImpl;
77.35 +import org.apidesign.bck2brwsr.emul.MethodImpl;
77.36 +
77.37 +/**
77.38 + * A {@code Method} provides information about, and access to, a single method
77.39 + * on a class or interface. The reflected method may be a class method
77.40 + * or an instance method (including an abstract method).
77.41 + *
77.42 + * <p>A {@code Method} permits widening conversions to occur when matching the
77.43 + * actual parameters to invoke with the underlying method's formal
77.44 + * parameters, but it throws an {@code IllegalArgumentException} if a
77.45 + * narrowing conversion would occur.
77.46 + *
77.47 + * @see Member
77.48 + * @see java.lang.Class
77.49 + * @see java.lang.Class#getMethods()
77.50 + * @see java.lang.Class#getMethod(String, Class[])
77.51 + * @see java.lang.Class#getDeclaredMethods()
77.52 + * @see java.lang.Class#getDeclaredMethod(String, Class[])
77.53 + *
77.54 + * @author Kenneth Russell
77.55 + * @author Nakul Saraiya
77.56 + */
77.57 +public final
77.58 + class Method extends AccessibleObject implements GenericDeclaration,
77.59 + Member {
77.60 + private final Class<?> clazz;
77.61 + private final String name;
77.62 + private final Object data;
77.63 + private final String sig;
77.64 +
77.65 + // Generics infrastructure
77.66 +
77.67 + private String getGenericSignature() {return null;}
77.68 +
77.69 + /**
77.70 + * Package-private constructor used by ReflectAccess to enable
77.71 + * instantiation of these objects in Java code from the java.lang
77.72 + * package via sun.reflect.LangReflectAccess.
77.73 + */
77.74 + Method(Class<?> declaringClass, String name, Object data, String sig)
77.75 + {
77.76 + this.clazz = declaringClass;
77.77 + this.name = name;
77.78 + this.data = data;
77.79 + this.sig = sig;
77.80 + }
77.81 +
77.82 + /**
77.83 + * Package-private routine (exposed to java.lang.Class via
77.84 + * ReflectAccess) which returns a copy of this Method. The copy's
77.85 + * "root" field points to this Method.
77.86 + */
77.87 + Method copy() {
77.88 + return this;
77.89 + }
77.90 +
77.91 + /**
77.92 + * Returns the {@code Class} object representing the class or interface
77.93 + * that declares the method represented by this {@code Method} object.
77.94 + */
77.95 + public Class<?> getDeclaringClass() {
77.96 + return clazz;
77.97 + }
77.98 +
77.99 + /**
77.100 + * Returns the name of the method represented by this {@code Method}
77.101 + * object, as a {@code String}.
77.102 + */
77.103 + public String getName() {
77.104 + return name;
77.105 + }
77.106 +
77.107 + /**
77.108 + * Returns the Java language modifiers for the method represented
77.109 + * by this {@code Method} object, as an integer. The {@code Modifier} class should
77.110 + * be used to decode the modifiers.
77.111 + *
77.112 + * @see Modifier
77.113 + */
77.114 + public int getModifiers() {
77.115 + return getAccess(data);
77.116 + }
77.117 +
77.118 + @JavaScriptBody(args = "self", body = "return self.access;")
77.119 + private static native int getAccess(Object self);
77.120 +
77.121 + /**
77.122 + * Returns an array of {@code TypeVariable} objects that represent the
77.123 + * type variables declared by the generic declaration represented by this
77.124 + * {@code GenericDeclaration} object, in declaration order. Returns an
77.125 + * array of length 0 if the underlying generic declaration declares no type
77.126 + * variables.
77.127 + *
77.128 + * @return an array of {@code TypeVariable} objects that represent
77.129 + * the type variables declared by this generic declaration
77.130 + * @throws GenericSignatureFormatError if the generic
77.131 + * signature of this generic declaration does not conform to
77.132 + * the format specified in
77.133 + * <cite>The Java™ Virtual Machine Specification</cite>
77.134 + * @since 1.5
77.135 + */
77.136 + public TypeVariable<Method>[] getTypeParameters() {
77.137 + throw new UnsupportedOperationException();
77.138 + }
77.139 +
77.140 + /**
77.141 + * Returns a {@code Class} object that represents the formal return type
77.142 + * of the method represented by this {@code Method} object.
77.143 + *
77.144 + * @return the return type for the method this object represents
77.145 + */
77.146 + public Class<?> getReturnType() {
77.147 + return MethodImpl.signatureParser(sig).nextElement();
77.148 + }
77.149 +
77.150 + /**
77.151 + * Returns a {@code Type} object that represents the formal return
77.152 + * type of the method represented by this {@code Method} object.
77.153 + *
77.154 + * <p>If the return type is a parameterized type,
77.155 + * the {@code Type} object returned must accurately reflect
77.156 + * the actual type parameters used in the source code.
77.157 + *
77.158 + * <p>If the return type is a type variable or a parameterized type, it
77.159 + * is created. Otherwise, it is resolved.
77.160 + *
77.161 + * @return a {@code Type} object that represents the formal return
77.162 + * type of the underlying method
77.163 + * @throws GenericSignatureFormatError
77.164 + * if the generic method signature does not conform to the format
77.165 + * specified in
77.166 + * <cite>The Java™ Virtual Machine Specification</cite>
77.167 + * @throws TypeNotPresentException if the underlying method's
77.168 + * return type refers to a non-existent type declaration
77.169 + * @throws MalformedParameterizedTypeException if the
77.170 + * underlying method's return typed refers to a parameterized
77.171 + * type that cannot be instantiated for any reason
77.172 + * @since 1.5
77.173 + */
77.174 + public Type getGenericReturnType() {
77.175 + throw new UnsupportedOperationException();
77.176 + }
77.177 +
77.178 +
77.179 + /**
77.180 + * Returns an array of {@code Class} objects that represent the formal
77.181 + * parameter types, in declaration order, of the method
77.182 + * represented by this {@code Method} object. Returns an array of length
77.183 + * 0 if the underlying method takes no parameters.
77.184 + *
77.185 + * @return the parameter types for the method this object
77.186 + * represents
77.187 + */
77.188 + public Class<?>[] getParameterTypes() {
77.189 + Class[] arr = new Class[MethodImpl.signatureElements(sig) - 1];
77.190 + Enumeration<Class> en = MethodImpl.signatureParser(sig);
77.191 + en.nextElement(); // return type
77.192 + for (int i = 0; i < arr.length; i++) {
77.193 + arr[i] = en.nextElement();
77.194 + }
77.195 + return arr;
77.196 + }
77.197 +
77.198 + /**
77.199 + * Returns an array of {@code Type} objects that represent the formal
77.200 + * parameter types, in declaration order, of the method represented by
77.201 + * this {@code Method} object. Returns an array of length 0 if the
77.202 + * underlying method takes no parameters.
77.203 + *
77.204 + * <p>If a formal parameter type is a parameterized type,
77.205 + * the {@code Type} object returned for it must accurately reflect
77.206 + * the actual type parameters used in the source code.
77.207 + *
77.208 + * <p>If a formal parameter type is a type variable or a parameterized
77.209 + * type, it is created. Otherwise, it is resolved.
77.210 + *
77.211 + * @return an array of Types that represent the formal
77.212 + * parameter types of the underlying method, in declaration order
77.213 + * @throws GenericSignatureFormatError
77.214 + * if the generic method signature does not conform to the format
77.215 + * specified in
77.216 + * <cite>The Java™ Virtual Machine Specification</cite>
77.217 + * @throws TypeNotPresentException if any of the parameter
77.218 + * types of the underlying method refers to a non-existent type
77.219 + * declaration
77.220 + * @throws MalformedParameterizedTypeException if any of
77.221 + * the underlying method's parameter types refer to a parameterized
77.222 + * type that cannot be instantiated for any reason
77.223 + * @since 1.5
77.224 + */
77.225 + public Type[] getGenericParameterTypes() {
77.226 + throw new UnsupportedOperationException();
77.227 + }
77.228 +
77.229 +
77.230 + /**
77.231 + * Returns an array of {@code Class} objects that represent
77.232 + * the types of the exceptions declared to be thrown
77.233 + * by the underlying method
77.234 + * represented by this {@code Method} object. Returns an array of length
77.235 + * 0 if the method declares no exceptions in its {@code throws} clause.
77.236 + *
77.237 + * @return the exception types declared as being thrown by the
77.238 + * method this object represents
77.239 + */
77.240 + public Class<?>[] getExceptionTypes() {
77.241 + throw new UnsupportedOperationException();
77.242 + //return (Class<?>[]) exceptionTypes.clone();
77.243 + }
77.244 +
77.245 + /**
77.246 + * Returns an array of {@code Type} objects that represent the
77.247 + * exceptions declared to be thrown by this {@code Method} object.
77.248 + * Returns an array of length 0 if the underlying method declares
77.249 + * no exceptions in its {@code throws} clause.
77.250 + *
77.251 + * <p>If an exception type is a type variable or a parameterized
77.252 + * type, it is created. Otherwise, it is resolved.
77.253 + *
77.254 + * @return an array of Types that represent the exception types
77.255 + * thrown by the underlying method
77.256 + * @throws GenericSignatureFormatError
77.257 + * if the generic method signature does not conform to the format
77.258 + * specified in
77.259 + * <cite>The Java™ Virtual Machine Specification</cite>
77.260 + * @throws TypeNotPresentException if the underlying method's
77.261 + * {@code throws} clause refers to a non-existent type declaration
77.262 + * @throws MalformedParameterizedTypeException if
77.263 + * the underlying method's {@code throws} clause refers to a
77.264 + * parameterized type that cannot be instantiated for any reason
77.265 + * @since 1.5
77.266 + */
77.267 + public Type[] getGenericExceptionTypes() {
77.268 + throw new UnsupportedOperationException();
77.269 + }
77.270 +
77.271 + /**
77.272 + * Compares this {@code Method} against the specified object. Returns
77.273 + * true if the objects are the same. Two {@code Methods} are the same if
77.274 + * they were declared by the same class and have the same name
77.275 + * and formal parameter types and return type.
77.276 + */
77.277 + public boolean equals(Object obj) {
77.278 + if (obj != null && obj instanceof Method) {
77.279 + Method other = (Method)obj;
77.280 + return data == other.data;
77.281 + }
77.282 + return false;
77.283 + }
77.284 +
77.285 + /**
77.286 + * Returns a hashcode for this {@code Method}. The hashcode is computed
77.287 + * as the exclusive-or of the hashcodes for the underlying
77.288 + * method's declaring class name and the method's name.
77.289 + */
77.290 + public int hashCode() {
77.291 + return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
77.292 + }
77.293 +
77.294 + /**
77.295 + * Returns a string describing this {@code Method}. The string is
77.296 + * formatted as the method access modifiers, if any, followed by
77.297 + * the method return type, followed by a space, followed by the
77.298 + * class declaring the method, followed by a period, followed by
77.299 + * the method name, followed by a parenthesized, comma-separated
77.300 + * list of the method's formal parameter types. If the method
77.301 + * throws checked exceptions, the parameter list is followed by a
77.302 + * space, followed by the word throws followed by a
77.303 + * comma-separated list of the thrown exception types.
77.304 + * For example:
77.305 + * <pre>
77.306 + * public boolean java.lang.Object.equals(java.lang.Object)
77.307 + * </pre>
77.308 + *
77.309 + * <p>The access modifiers are placed in canonical order as
77.310 + * specified by "The Java Language Specification". This is
77.311 + * {@code public}, {@code protected} or {@code private} first,
77.312 + * and then other modifiers in the following order:
77.313 + * {@code abstract}, {@code static}, {@code final},
77.314 + * {@code synchronized}, {@code native}, {@code strictfp}.
77.315 + */
77.316 + public String toString() {
77.317 + try {
77.318 + StringBuilder sb = new StringBuilder();
77.319 + int mod = getModifiers() & Modifier.methodModifiers();
77.320 + if (mod != 0) {
77.321 + sb.append(Modifier.toString(mod)).append(' ');
77.322 + }
77.323 + sb.append(Field.getTypeName(getReturnType())).append(' ');
77.324 + sb.append(Field.getTypeName(getDeclaringClass())).append('.');
77.325 + sb.append(getName()).append('(');
77.326 + Class<?>[] params = getParameterTypes(); // avoid clone
77.327 + for (int j = 0; j < params.length; j++) {
77.328 + sb.append(Field.getTypeName(params[j]));
77.329 + if (j < (params.length - 1))
77.330 + sb.append(',');
77.331 + }
77.332 + sb.append(')');
77.333 + /*
77.334 + Class<?>[] exceptions = exceptionTypes; // avoid clone
77.335 + if (exceptions.length > 0) {
77.336 + sb.append(" throws ");
77.337 + for (int k = 0; k < exceptions.length; k++) {
77.338 + sb.append(exceptions[k].getName());
77.339 + if (k < (exceptions.length - 1))
77.340 + sb.append(',');
77.341 + }
77.342 + }
77.343 + */
77.344 + return sb.toString();
77.345 + } catch (Exception e) {
77.346 + return "<" + e + ">";
77.347 + }
77.348 + }
77.349 +
77.350 + /**
77.351 + * Returns a string describing this {@code Method}, including
77.352 + * type parameters. The string is formatted as the method access
77.353 + * modifiers, if any, followed by an angle-bracketed
77.354 + * comma-separated list of the method's type parameters, if any,
77.355 + * followed by the method's generic return type, followed by a
77.356 + * space, followed by the class declaring the method, followed by
77.357 + * a period, followed by the method name, followed by a
77.358 + * parenthesized, comma-separated list of the method's generic
77.359 + * formal parameter types.
77.360 + *
77.361 + * If this method was declared to take a variable number of
77.362 + * arguments, instead of denoting the last parameter as
77.363 + * "<tt><i>Type</i>[]</tt>", it is denoted as
77.364 + * "<tt><i>Type</i>...</tt>".
77.365 + *
77.366 + * A space is used to separate access modifiers from one another
77.367 + * and from the type parameters or return type. If there are no
77.368 + * type parameters, the type parameter list is elided; if the type
77.369 + * parameter list is present, a space separates the list from the
77.370 + * class name. If the method is declared to throw exceptions, the
77.371 + * parameter list is followed by a space, followed by the word
77.372 + * throws followed by a comma-separated list of the generic thrown
77.373 + * exception types. If there are no type parameters, the type
77.374 + * parameter list is elided.
77.375 + *
77.376 + * <p>The access modifiers are placed in canonical order as
77.377 + * specified by "The Java Language Specification". This is
77.378 + * {@code public}, {@code protected} or {@code private} first,
77.379 + * and then other modifiers in the following order:
77.380 + * {@code abstract}, {@code static}, {@code final},
77.381 + * {@code synchronized}, {@code native}, {@code strictfp}.
77.382 + *
77.383 + * @return a string describing this {@code Method},
77.384 + * include type parameters
77.385 + *
77.386 + * @since 1.5
77.387 + */
77.388 + public String toGenericString() {
77.389 + try {
77.390 + StringBuilder sb = new StringBuilder();
77.391 + int mod = getModifiers() & Modifier.methodModifiers();
77.392 + if (mod != 0) {
77.393 + sb.append(Modifier.toString(mod)).append(' ');
77.394 + }
77.395 + TypeVariable<?>[] typeparms = getTypeParameters();
77.396 + if (typeparms.length > 0) {
77.397 + boolean first = true;
77.398 + sb.append('<');
77.399 + for(TypeVariable<?> typeparm: typeparms) {
77.400 + if (!first)
77.401 + sb.append(',');
77.402 + // Class objects can't occur here; no need to test
77.403 + // and call Class.getName().
77.404 + sb.append(typeparm.toString());
77.405 + first = false;
77.406 + }
77.407 + sb.append("> ");
77.408 + }
77.409 +
77.410 + Type genRetType = getGenericReturnType();
77.411 + sb.append( ((genRetType instanceof Class<?>)?
77.412 + Field.getTypeName((Class<?>)genRetType):genRetType.toString()))
77.413 + .append(' ');
77.414 +
77.415 + sb.append(Field.getTypeName(getDeclaringClass())).append('.');
77.416 + sb.append(getName()).append('(');
77.417 + Type[] params = getGenericParameterTypes();
77.418 + for (int j = 0; j < params.length; j++) {
77.419 + String param = (params[j] instanceof Class)?
77.420 + Field.getTypeName((Class)params[j]):
77.421 + (params[j].toString());
77.422 + if (isVarArgs() && (j == params.length - 1)) // replace T[] with T...
77.423 + param = param.replaceFirst("\\[\\]$", "...");
77.424 + sb.append(param);
77.425 + if (j < (params.length - 1))
77.426 + sb.append(',');
77.427 + }
77.428 + sb.append(')');
77.429 + Type[] exceptions = getGenericExceptionTypes();
77.430 + if (exceptions.length > 0) {
77.431 + sb.append(" throws ");
77.432 + for (int k = 0; k < exceptions.length; k++) {
77.433 + sb.append((exceptions[k] instanceof Class)?
77.434 + ((Class)exceptions[k]).getName():
77.435 + exceptions[k].toString());
77.436 + if (k < (exceptions.length - 1))
77.437 + sb.append(',');
77.438 + }
77.439 + }
77.440 + return sb.toString();
77.441 + } catch (Exception e) {
77.442 + return "<" + e + ">";
77.443 + }
77.444 + }
77.445 +
77.446 + /**
77.447 + * Invokes the underlying method represented by this {@code Method}
77.448 + * object, on the specified object with the specified parameters.
77.449 + * Individual parameters are automatically unwrapped to match
77.450 + * primitive formal parameters, and both primitive and reference
77.451 + * parameters are subject to method invocation conversions as
77.452 + * necessary.
77.453 + *
77.454 + * <p>If the underlying method is static, then the specified {@code obj}
77.455 + * argument is ignored. It may be null.
77.456 + *
77.457 + * <p>If the number of formal parameters required by the underlying method is
77.458 + * 0, the supplied {@code args} array may be of length 0 or null.
77.459 + *
77.460 + * <p>If the underlying method is an instance method, it is invoked
77.461 + * using dynamic method lookup as documented in The Java Language
77.462 + * Specification, Second Edition, section 15.12.4.4; in particular,
77.463 + * overriding based on the runtime type of the target object will occur.
77.464 + *
77.465 + * <p>If the underlying method is static, the class that declared
77.466 + * the method is initialized if it has not already been initialized.
77.467 + *
77.468 + * <p>If the method completes normally, the value it returns is
77.469 + * returned to the caller of invoke; if the value has a primitive
77.470 + * type, it is first appropriately wrapped in an object. However,
77.471 + * if the value has the type of an array of a primitive type, the
77.472 + * elements of the array are <i>not</i> wrapped in objects; in
77.473 + * other words, an array of primitive type is returned. If the
77.474 + * underlying method return type is void, the invocation returns
77.475 + * null.
77.476 + *
77.477 + * @param obj the object the underlying method is invoked from
77.478 + * @param args the arguments used for the method call
77.479 + * @return the result of dispatching the method represented by
77.480 + * this object on {@code obj} with parameters
77.481 + * {@code args}
77.482 + *
77.483 + * @exception IllegalAccessException if this {@code Method} object
77.484 + * is enforcing Java language access control and the underlying
77.485 + * method is inaccessible.
77.486 + * @exception IllegalArgumentException if the method is an
77.487 + * instance method and the specified object argument
77.488 + * is not an instance of the class or interface
77.489 + * declaring the underlying method (or of a subclass
77.490 + * or implementor thereof); if the number of actual
77.491 + * and formal parameters differ; if an unwrapping
77.492 + * conversion for primitive arguments fails; or if,
77.493 + * after possible unwrapping, a parameter value
77.494 + * cannot be converted to the corresponding formal
77.495 + * parameter type by a method invocation conversion.
77.496 + * @exception InvocationTargetException if the underlying method
77.497 + * throws an exception.
77.498 + * @exception NullPointerException if the specified object is null
77.499 + * and the method is an instance method.
77.500 + * @exception ExceptionInInitializerError if the initialization
77.501 + * provoked by this method fails.
77.502 + */
77.503 + public Object invoke(Object obj, Object... args)
77.504 + throws IllegalAccessException, IllegalArgumentException,
77.505 + InvocationTargetException
77.506 + {
77.507 + final boolean isStatic = (getModifiers() & Modifier.STATIC) == 0;
77.508 + if (isStatic && obj == null) {
77.509 + throw new NullPointerException();
77.510 + }
77.511 + Class[] types = getParameterTypes();
77.512 + if (types.length != args.length) {
77.513 + throw new IllegalArgumentException("Types len " + types.length + " args: " + args.length);
77.514 + } else {
77.515 + args = args.clone();
77.516 + for (int i = 0; i < types.length; i++) {
77.517 + Class c = types[i];
77.518 + if (c.isPrimitive()) {
77.519 + args[i] = toPrimitive(c, args[i]);
77.520 + }
77.521 + }
77.522 + }
77.523 + Object res = invoke0(isStatic, this, obj, args);
77.524 + if (getReturnType().isPrimitive()) {
77.525 + res = fromPrimitive(getReturnType(), res);
77.526 + }
77.527 + return res;
77.528 + }
77.529 +
77.530 + @JavaScriptBody(args = { "st", "method", "self", "args" }, body =
77.531 + "var p;\n"
77.532 + + "if (st) {\n"
77.533 + + " p = new Array(1);\n"
77.534 + + " p[0] = self;\n"
77.535 + + " p = p.concat(args);\n"
77.536 + + "} else {\n"
77.537 + + " p = args;\n"
77.538 + + "}\n"
77.539 + + "return method.fld_data.apply(self, p);\n"
77.540 + )
77.541 + private static native Object invoke0(boolean isStatic, Method m, Object self, Object[] args);
77.542 +
77.543 + static Object fromPrimitive(Class<?> type, Object o) {
77.544 + if (type == Integer.TYPE) {
77.545 + return fromRaw(Integer.class, "valueOf__Ljava_lang_Integer_2I", o);
77.546 + }
77.547 + if (type == Long.TYPE) {
77.548 + return fromRaw(Long.class, "valueOf__Ljava_lang_Long_2J", o);
77.549 + }
77.550 + if (type == Double.TYPE) {
77.551 + return fromRaw(Double.class, "valueOf__Ljava_lang_Double_2D", o);
77.552 + }
77.553 + if (type == Float.TYPE) {
77.554 + return fromRaw(Float.class, "valueOf__Ljava_lang_Float_2F", o);
77.555 + }
77.556 + if (type == Byte.TYPE) {
77.557 + return fromRaw(Byte.class, "valueOf__Ljava_lang_Byte_2B", o);
77.558 + }
77.559 + if (type == Boolean.TYPE) {
77.560 + return fromRaw(Boolean.class, "valueOf__Ljava_lang_Boolean_2Z", o);
77.561 + }
77.562 + if (type == Short.TYPE) {
77.563 + return fromRaw(Short.class, "valueOf__Ljava_lang_Short_2S", o);
77.564 + }
77.565 + if (type == Character.TYPE) {
77.566 + return fromRaw(Character.class, "valueOf__Ljava_lang_Character_2C", o);
77.567 + }
77.568 + if (type.getName().equals("void")) {
77.569 + return null;
77.570 + }
77.571 + throw new IllegalStateException("Can't convert " + o);
77.572 + }
77.573 +
77.574 + @JavaScriptBody(args = { "cls", "m", "o" },
77.575 + body = "return cls.cnstr(false)[m](o);"
77.576 + )
77.577 + private static native Integer fromRaw(Class<?> cls, String m, Object o);
77.578 +
77.579 + private static Object toPrimitive(Class<?> type, Object o) {
77.580 + if (type == Integer.TYPE) {
77.581 + return toRaw("intValue__I", o);
77.582 + }
77.583 + if (type == Long.TYPE) {
77.584 + return toRaw("longValue__J", o);
77.585 + }
77.586 + if (type == Double.TYPE) {
77.587 + return toRaw("doubleValue__D", o);
77.588 + }
77.589 + if (type == Float.TYPE) {
77.590 + return toRaw("floatValue__F", o);
77.591 + }
77.592 + if (type == Byte.TYPE) {
77.593 + return toRaw("byteValue__B", o);
77.594 + }
77.595 + if (type == Boolean.TYPE) {
77.596 + return toRaw("booleanValue__Z", o);
77.597 + }
77.598 + if (type == Short.TYPE) {
77.599 + return toRaw("shortValue__S", o);
77.600 + }
77.601 + if (type == Character.TYPE) {
77.602 + return toRaw("charValue__C", o);
77.603 + }
77.604 + if (type.getName().equals("void")) {
77.605 + return o;
77.606 + }
77.607 + throw new IllegalStateException("Can't convert " + o);
77.608 + }
77.609 +
77.610 + @JavaScriptBody(args = { "m", "o" },
77.611 + body = "return o[m](o);"
77.612 + )
77.613 + private static native Object toRaw(String m, Object o);
77.614 +
77.615 + /**
77.616 + * Returns {@code true} if this method is a bridge
77.617 + * method; returns {@code false} otherwise.
77.618 + *
77.619 + * @return true if and only if this method is a bridge
77.620 + * method as defined by the Java Language Specification.
77.621 + * @since 1.5
77.622 + */
77.623 + public boolean isBridge() {
77.624 + return (getModifiers() & Modifier.BRIDGE) != 0;
77.625 + }
77.626 +
77.627 + /**
77.628 + * Returns {@code true} if this method was declared to take
77.629 + * a variable number of arguments; returns {@code false}
77.630 + * otherwise.
77.631 + *
77.632 + * @return {@code true} if an only if this method was declared to
77.633 + * take a variable number of arguments.
77.634 + * @since 1.5
77.635 + */
77.636 + public boolean isVarArgs() {
77.637 + return (getModifiers() & Modifier.VARARGS) != 0;
77.638 + }
77.639 +
77.640 + /**
77.641 + * Returns {@code true} if this method is a synthetic
77.642 + * method; returns {@code false} otherwise.
77.643 + *
77.644 + * @return true if and only if this method is a synthetic
77.645 + * method as defined by the Java Language Specification.
77.646 + * @since 1.5
77.647 + */
77.648 + public boolean isSynthetic() {
77.649 + return Modifier.isSynthetic(getModifiers());
77.650 + }
77.651 +
77.652 + @JavaScriptBody(args = { "ac" },
77.653 + body =
77.654 + "if (this.fld_data.anno) {"
77.655 + + " return this.fld_data.anno['L' + ac.jvmName + ';'];"
77.656 + + "} else return null;"
77.657 + )
77.658 + private Object getAnnotationData(Class<?> annotationClass) {
77.659 + throw new UnsupportedOperationException();
77.660 + }
77.661 +
77.662 + /**
77.663 + * @throws NullPointerException {@inheritDoc}
77.664 + * @since 1.5
77.665 + */
77.666 + public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
77.667 + Object data = getAnnotationData(annotationClass);
77.668 + return data == null ? null : AnnotationImpl.create(annotationClass, data);
77.669 + }
77.670 +
77.671 + /**
77.672 + * @since 1.5
77.673 + */
77.674 + public Annotation[] getDeclaredAnnotations() {
77.675 + throw new UnsupportedOperationException();
77.676 + }
77.677 +
77.678 + /**
77.679 + * Returns the default value for the annotation member represented by
77.680 + * this {@code Method} instance. If the member is of a primitive type,
77.681 + * an instance of the corresponding wrapper type is returned. Returns
77.682 + * null if no default is associated with the member, or if the method
77.683 + * instance does not represent a declared member of an annotation type.
77.684 + *
77.685 + * @return the default value for the annotation member represented
77.686 + * by this {@code Method} instance.
77.687 + * @throws TypeNotPresentException if the annotation is of type
77.688 + * {@link Class} and no definition can be found for the
77.689 + * default class value.
77.690 + * @since 1.5
77.691 + */
77.692 + public Object getDefaultValue() {
77.693 + throw new UnsupportedOperationException();
77.694 + }
77.695 +
77.696 + /**
77.697 + * Returns an array of arrays that represent the annotations on the formal
77.698 + * parameters, in declaration order, of the method represented by
77.699 + * this {@code Method} object. (Returns an array of length zero if the
77.700 + * underlying method is parameterless. If the method has one or more
77.701 + * parameters, a nested array of length zero is returned for each parameter
77.702 + * with no annotations.) The annotation objects contained in the returned
77.703 + * arrays are serializable. The caller of this method is free to modify
77.704 + * the returned arrays; it will have no effect on the arrays returned to
77.705 + * other callers.
77.706 + *
77.707 + * @return an array of arrays that represent the annotations on the formal
77.708 + * parameters, in declaration order, of the method represented by this
77.709 + * Method object
77.710 + * @since 1.5
77.711 + */
77.712 + public Annotation[][] getParameterAnnotations() {
77.713 + throw new UnsupportedOperationException();
77.714 + }
77.715 +
77.716 + static {
77.717 + MethodImpl.INSTANCE = new MethodImpl() {
77.718 + protected Method create(Class<?> declaringClass, String name, Object data, String sig) {
77.719 + return new Method(declaringClass, name, data, sig);
77.720 + }
77.721 + };
77.722 + }
77.723 +}
78.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
78.2 +++ b/emul/src/main/java/java/lang/reflect/Modifier.java Wed Jan 23 20:16:48 2013 +0100
78.3 @@ -0,0 +1,437 @@
78.4 +/*
78.5 + * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
78.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
78.7 + *
78.8 + * This code is free software; you can redistribute it and/or modify it
78.9 + * under the terms of the GNU General Public License version 2 only, as
78.10 + * published by the Free Software Foundation. Oracle designates this
78.11 + * particular file as subject to the "Classpath" exception as provided
78.12 + * by Oracle in the LICENSE file that accompanied this code.
78.13 + *
78.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
78.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
78.17 + * version 2 for more details (a copy is included in the LICENSE file that
78.18 + * accompanied this code).
78.19 + *
78.20 + * You should have received a copy of the GNU General Public License version
78.21 + * 2 along with this work; if not, write to the Free Software Foundation,
78.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
78.23 + *
78.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
78.25 + * or visit www.oracle.com if you need additional information or have any
78.26 + * questions.
78.27 + */
78.28 +
78.29 +package java.lang.reflect;
78.30 +
78.31 +/**
78.32 + * The Modifier class provides {@code static} methods and
78.33 + * constants to decode class and member access modifiers. The sets of
78.34 + * modifiers are represented as integers with distinct bit positions
78.35 + * representing different modifiers. The values for the constants
78.36 + * representing the modifiers are taken from the tables in sections 4.1, 4.4, 4.5, and 4.7 of
78.37 + * <cite>The Java™ Virtual Machine Specification</cite>.
78.38 + *
78.39 + * @see Class#getModifiers()
78.40 + * @see Member#getModifiers()
78.41 + *
78.42 + * @author Nakul Saraiya
78.43 + * @author Kenneth Russell
78.44 + */
78.45 +public
78.46 +class Modifier {
78.47 +
78.48 + /**
78.49 + * Return {@code true} if the integer argument includes the
78.50 + * {@code public} modifier, {@code false} otherwise.
78.51 + *
78.52 + * @param mod a set of modifiers
78.53 + * @return {@code true} if {@code mod} includes the
78.54 + * {@code public} modifier; {@code false} otherwise.
78.55 + */
78.56 + public static boolean isPublic(int mod) {
78.57 + return (mod & PUBLIC) != 0;
78.58 + }
78.59 +
78.60 + /**
78.61 + * Return {@code true} if the integer argument includes the
78.62 + * {@code private} modifier, {@code false} otherwise.
78.63 + *
78.64 + * @param mod a set of modifiers
78.65 + * @return {@code true} if {@code mod} includes the
78.66 + * {@code private} modifier; {@code false} otherwise.
78.67 + */
78.68 + public static boolean isPrivate(int mod) {
78.69 + return (mod & PRIVATE) != 0;
78.70 + }
78.71 +
78.72 + /**
78.73 + * Return {@code true} if the integer argument includes the
78.74 + * {@code protected} modifier, {@code false} otherwise.
78.75 + *
78.76 + * @param mod a set of modifiers
78.77 + * @return {@code true} if {@code mod} includes the
78.78 + * {@code protected} modifier; {@code false} otherwise.
78.79 + */
78.80 + public static boolean isProtected(int mod) {
78.81 + return (mod & PROTECTED) != 0;
78.82 + }
78.83 +
78.84 + /**
78.85 + * Return {@code true} if the integer argument includes the
78.86 + * {@code static} modifier, {@code false} otherwise.
78.87 + *
78.88 + * @param mod a set of modifiers
78.89 + * @return {@code true} if {@code mod} includes the
78.90 + * {@code static} modifier; {@code false} otherwise.
78.91 + */
78.92 + public static boolean isStatic(int mod) {
78.93 + return (mod & STATIC) != 0;
78.94 + }
78.95 +
78.96 + /**
78.97 + * Return {@code true} if the integer argument includes the
78.98 + * {@code final} modifier, {@code false} otherwise.
78.99 + *
78.100 + * @param mod a set of modifiers
78.101 + * @return {@code true} if {@code mod} includes the
78.102 + * {@code final} modifier; {@code false} otherwise.
78.103 + */
78.104 + public static boolean isFinal(int mod) {
78.105 + return (mod & FINAL) != 0;
78.106 + }
78.107 +
78.108 + /**
78.109 + * Return {@code true} if the integer argument includes the
78.110 + * {@code synchronized} modifier, {@code false} otherwise.
78.111 + *
78.112 + * @param mod a set of modifiers
78.113 + * @return {@code true} if {@code mod} includes the
78.114 + * {@code synchronized} modifier; {@code false} otherwise.
78.115 + */
78.116 + public static boolean isSynchronized(int mod) {
78.117 + return (mod & SYNCHRONIZED) != 0;
78.118 + }
78.119 +
78.120 + /**
78.121 + * Return {@code true} if the integer argument includes the
78.122 + * {@code volatile} modifier, {@code false} otherwise.
78.123 + *
78.124 + * @param mod a set of modifiers
78.125 + * @return {@code true} if {@code mod} includes the
78.126 + * {@code volatile} modifier; {@code false} otherwise.
78.127 + */
78.128 + public static boolean isVolatile(int mod) {
78.129 + return (mod & VOLATILE) != 0;
78.130 + }
78.131 +
78.132 + /**
78.133 + * Return {@code true} if the integer argument includes the
78.134 + * {@code transient} modifier, {@code false} otherwise.
78.135 + *
78.136 + * @param mod a set of modifiers
78.137 + * @return {@code true} if {@code mod} includes the
78.138 + * {@code transient} modifier; {@code false} otherwise.
78.139 + */
78.140 + public static boolean isTransient(int mod) {
78.141 + return (mod & TRANSIENT) != 0;
78.142 + }
78.143 +
78.144 + /**
78.145 + * Return {@code true} if the integer argument includes the
78.146 + * {@code native} modifier, {@code false} otherwise.
78.147 + *
78.148 + * @param mod a set of modifiers
78.149 + * @return {@code true} if {@code mod} includes the
78.150 + * {@code native} modifier; {@code false} otherwise.
78.151 + */
78.152 + public static boolean isNative(int mod) {
78.153 + return (mod & NATIVE) != 0;
78.154 + }
78.155 +
78.156 + /**
78.157 + * Return {@code true} if the integer argument includes the
78.158 + * {@code interface} modifier, {@code false} otherwise.
78.159 + *
78.160 + * @param mod a set of modifiers
78.161 + * @return {@code true} if {@code mod} includes the
78.162 + * {@code interface} modifier; {@code false} otherwise.
78.163 + */
78.164 + public static boolean isInterface(int mod) {
78.165 + return (mod & INTERFACE) != 0;
78.166 + }
78.167 +
78.168 + /**
78.169 + * Return {@code true} if the integer argument includes the
78.170 + * {@code abstract} modifier, {@code false} otherwise.
78.171 + *
78.172 + * @param mod a set of modifiers
78.173 + * @return {@code true} if {@code mod} includes the
78.174 + * {@code abstract} modifier; {@code false} otherwise.
78.175 + */
78.176 + public static boolean isAbstract(int mod) {
78.177 + return (mod & ABSTRACT) != 0;
78.178 + }
78.179 +
78.180 + /**
78.181 + * Return {@code true} if the integer argument includes the
78.182 + * {@code strictfp} modifier, {@code false} otherwise.
78.183 + *
78.184 + * @param mod a set of modifiers
78.185 + * @return {@code true} if {@code mod} includes the
78.186 + * {@code strictfp} modifier; {@code false} otherwise.
78.187 + */
78.188 + public static boolean isStrict(int mod) {
78.189 + return (mod & STRICT) != 0;
78.190 + }
78.191 +
78.192 + /**
78.193 + * Return a string describing the access modifier flags in
78.194 + * the specified modifier. For example:
78.195 + * <blockquote><pre>
78.196 + * public final synchronized strictfp
78.197 + * </pre></blockquote>
78.198 + * The modifier names are returned in an order consistent with the
78.199 + * suggested modifier orderings given in sections 8.1.1, 8.3.1, 8.4.3, 8.8.3, and 9.1.1 of
78.200 + * <cite>The Java™ Language Specification</cite>.
78.201 + * The full modifier ordering used by this method is:
78.202 + * <blockquote> {@code
78.203 + * public protected private abstract static final transient
78.204 + * volatile synchronized native strictfp
78.205 + * interface } </blockquote>
78.206 + * The {@code interface} modifier discussed in this class is
78.207 + * not a true modifier in the Java language and it appears after
78.208 + * all other modifiers listed by this method. This method may
78.209 + * return a string of modifiers that are not valid modifiers of a
78.210 + * Java entity; in other words, no checking is done on the
78.211 + * possible validity of the combination of modifiers represented
78.212 + * by the input.
78.213 + *
78.214 + * Note that to perform such checking for a known kind of entity,
78.215 + * such as a constructor or method, first AND the argument of
78.216 + * {@code toString} with the appropriate mask from a method like
78.217 + * {@link #constructorModifiers} or {@link #methodModifiers}.
78.218 + *
78.219 + * @param mod a set of modifiers
78.220 + * @return a string representation of the set of modifiers
78.221 + * represented by {@code mod}
78.222 + */
78.223 + public static String toString(int mod) {
78.224 + StringBuffer sb = new StringBuffer();
78.225 + int len;
78.226 +
78.227 + if ((mod & PUBLIC) != 0) sb.append("public ");
78.228 + if ((mod & PROTECTED) != 0) sb.append("protected ");
78.229 + if ((mod & PRIVATE) != 0) sb.append("private ");
78.230 +
78.231 + /* Canonical order */
78.232 + if ((mod & ABSTRACT) != 0) sb.append("abstract ");
78.233 + if ((mod & STATIC) != 0) sb.append("static ");
78.234 + if ((mod & FINAL) != 0) sb.append("final ");
78.235 + if ((mod & TRANSIENT) != 0) sb.append("transient ");
78.236 + if ((mod & VOLATILE) != 0) sb.append("volatile ");
78.237 + if ((mod & SYNCHRONIZED) != 0) sb.append("synchronized ");
78.238 + if ((mod & NATIVE) != 0) sb.append("native ");
78.239 + if ((mod & STRICT) != 0) sb.append("strictfp ");
78.240 + if ((mod & INTERFACE) != 0) sb.append("interface ");
78.241 +
78.242 + if ((len = sb.length()) > 0) /* trim trailing space */
78.243 + return sb.toString().substring(0, len-1);
78.244 + return "";
78.245 + }
78.246 +
78.247 + /*
78.248 + * Access modifier flag constants from tables 4.1, 4.4, 4.5, and 4.7 of
78.249 + * <cite>The Java™ Virtual Machine Specification</cite>
78.250 + */
78.251 +
78.252 + /**
78.253 + * The {@code int} value representing the {@code public}
78.254 + * modifier.
78.255 + */
78.256 + public static final int PUBLIC = 0x00000001;
78.257 +
78.258 + /**
78.259 + * The {@code int} value representing the {@code private}
78.260 + * modifier.
78.261 + */
78.262 + public static final int PRIVATE = 0x00000002;
78.263 +
78.264 + /**
78.265 + * The {@code int} value representing the {@code protected}
78.266 + * modifier.
78.267 + */
78.268 + public static final int PROTECTED = 0x00000004;
78.269 +
78.270 + /**
78.271 + * The {@code int} value representing the {@code static}
78.272 + * modifier.
78.273 + */
78.274 + public static final int STATIC = 0x00000008;
78.275 +
78.276 + /**
78.277 + * The {@code int} value representing the {@code final}
78.278 + * modifier.
78.279 + */
78.280 + public static final int FINAL = 0x00000010;
78.281 +
78.282 + /**
78.283 + * The {@code int} value representing the {@code synchronized}
78.284 + * modifier.
78.285 + */
78.286 + public static final int SYNCHRONIZED = 0x00000020;
78.287 +
78.288 + /**
78.289 + * The {@code int} value representing the {@code volatile}
78.290 + * modifier.
78.291 + */
78.292 + public static final int VOLATILE = 0x00000040;
78.293 +
78.294 + /**
78.295 + * The {@code int} value representing the {@code transient}
78.296 + * modifier.
78.297 + */
78.298 + public static final int TRANSIENT = 0x00000080;
78.299 +
78.300 + /**
78.301 + * The {@code int} value representing the {@code native}
78.302 + * modifier.
78.303 + */
78.304 + public static final int NATIVE = 0x00000100;
78.305 +
78.306 + /**
78.307 + * The {@code int} value representing the {@code interface}
78.308 + * modifier.
78.309 + */
78.310 + public static final int INTERFACE = 0x00000200;
78.311 +
78.312 + /**
78.313 + * The {@code int} value representing the {@code abstract}
78.314 + * modifier.
78.315 + */
78.316 + public static final int ABSTRACT = 0x00000400;
78.317 +
78.318 + /**
78.319 + * The {@code int} value representing the {@code strictfp}
78.320 + * modifier.
78.321 + */
78.322 + public static final int STRICT = 0x00000800;
78.323 +
78.324 + // Bits not (yet) exposed in the public API either because they
78.325 + // have different meanings for fields and methods and there is no
78.326 + // way to distinguish between the two in this class, or because
78.327 + // they are not Java programming language keywords
78.328 + static final int BRIDGE = 0x00000040;
78.329 + static final int VARARGS = 0x00000080;
78.330 + static final int SYNTHETIC = 0x00001000;
78.331 + static final int ANNOTATION= 0x00002000;
78.332 + static final int ENUM = 0x00004000;
78.333 + static boolean isSynthetic(int mod) {
78.334 + return (mod & SYNTHETIC) != 0;
78.335 + }
78.336 +
78.337 + /**
78.338 + * See JLSv3 section 8.1.1.
78.339 + */
78.340 + private static final int CLASS_MODIFIERS =
78.341 + Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE |
78.342 + Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL |
78.343 + Modifier.STRICT;
78.344 +
78.345 + /**
78.346 + * See JLSv3 section 9.1.1.
78.347 + */
78.348 + private static final int INTERFACE_MODIFIERS =
78.349 + Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE |
78.350 + Modifier.ABSTRACT | Modifier.STATIC | Modifier.STRICT;
78.351 +
78.352 +
78.353 + /**
78.354 + * See JLSv3 section 8.8.3.
78.355 + */
78.356 + private static final int CONSTRUCTOR_MODIFIERS =
78.357 + Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE;
78.358 +
78.359 + /**
78.360 + * See JLSv3 section 8.4.3.
78.361 + */
78.362 + private static final int METHOD_MODIFIERS =
78.363 + Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE |
78.364 + Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL |
78.365 + Modifier.SYNCHRONIZED | Modifier.NATIVE | Modifier.STRICT;
78.366 +
78.367 + /**
78.368 + * See JLSv3 section 8.3.1.
78.369 + */
78.370 + private static final int FIELD_MODIFIERS =
78.371 + Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE |
78.372 + Modifier.STATIC | Modifier.FINAL | Modifier.TRANSIENT |
78.373 + Modifier.VOLATILE;
78.374 +
78.375 + /**
78.376 + * Return an {@code int} value OR-ing together the source language
78.377 + * modifiers that can be applied to a class.
78.378 + * @return an {@code int} value OR-ing together the source language
78.379 + * modifiers that can be applied to a class.
78.380 + *
78.381 + * @jls 8.1.1 Class Modifiers
78.382 + * @since 1.7
78.383 + */
78.384 + public static int classModifiers() {
78.385 + return CLASS_MODIFIERS;
78.386 + }
78.387 +
78.388 + /**
78.389 + * Return an {@code int} value OR-ing together the source language
78.390 + * modifiers that can be applied to an interface.
78.391 + * @return an {@code int} value OR-ing together the source language
78.392 + * modifiers that can be applied to an inteface.
78.393 + *
78.394 + * @jls 9.1.1 Interface Modifiers
78.395 + * @since 1.7
78.396 + */
78.397 + public static int interfaceModifiers() {
78.398 + return INTERFACE_MODIFIERS;
78.399 + }
78.400 +
78.401 + /**
78.402 + * Return an {@code int} value OR-ing together the source language
78.403 + * modifiers that can be applied to a constructor.
78.404 + * @return an {@code int} value OR-ing together the source language
78.405 + * modifiers that can be applied to a constructor.
78.406 + *
78.407 + * @jls 8.8.3 Constructor Modifiers
78.408 + * @since 1.7
78.409 + */
78.410 + public static int constructorModifiers() {
78.411 + return CONSTRUCTOR_MODIFIERS;
78.412 + }
78.413 +
78.414 + /**
78.415 + * Return an {@code int} value OR-ing together the source language
78.416 + * modifiers that can be applied to a method.
78.417 + * @return an {@code int} value OR-ing together the source language
78.418 + * modifiers that can be applied to a method.
78.419 + *
78.420 + * @jls 8.4.3 Method Modifiers
78.421 + * @since 1.7
78.422 + */
78.423 + public static int methodModifiers() {
78.424 + return METHOD_MODIFIERS;
78.425 + }
78.426 +
78.427 +
78.428 + /**
78.429 + * Return an {@code int} value OR-ing together the source language
78.430 + * modifiers that can be applied to a field.
78.431 + * @return an {@code int} value OR-ing together the source language
78.432 + * modifiers that can be applied to a field.
78.433 + *
78.434 + * @jls 8.3.1 Field Modifiers
78.435 + * @since 1.7
78.436 + */
78.437 + public static int fieldModifiers() {
78.438 + return FIELD_MODIFIERS;
78.439 + }
78.440 +}
79.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
79.2 +++ b/emul/src/main/java/java/lang/reflect/Type.java Wed Jan 23 20:16:48 2013 +0100
79.3 @@ -0,0 +1,37 @@
79.4 +/*
79.5 + * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
79.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
79.7 + *
79.8 + * This code is free software; you can redistribute it and/or modify it
79.9 + * under the terms of the GNU General Public License version 2 only, as
79.10 + * published by the Free Software Foundation. Oracle designates this
79.11 + * particular file as subject to the "Classpath" exception as provided
79.12 + * by Oracle in the LICENSE file that accompanied this code.
79.13 + *
79.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
79.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
79.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
79.17 + * version 2 for more details (a copy is included in the LICENSE file that
79.18 + * accompanied this code).
79.19 + *
79.20 + * You should have received a copy of the GNU General Public License version
79.21 + * 2 along with this work; if not, write to the Free Software Foundation,
79.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
79.23 + *
79.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
79.25 + * or visit www.oracle.com if you need additional information or have any
79.26 + * questions.
79.27 + */
79.28 +
79.29 +package java.lang.reflect;
79.30 +
79.31 +/**
79.32 + * Type is the common superinterface for all types in the Java
79.33 + * programming language. These include raw types, parameterized types,
79.34 + * array types, type variables and primitive types.
79.35 + *
79.36 + * @since 1.5
79.37 + */
79.38 +
79.39 +public interface Type {
79.40 +}
80.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
80.2 +++ b/emul/src/main/java/java/lang/reflect/TypeVariable.java Wed Jan 23 20:16:48 2013 +0100
80.3 @@ -0,0 +1,89 @@
80.4 +/*
80.5 + * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
80.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
80.7 + *
80.8 + * This code is free software; you can redistribute it and/or modify it
80.9 + * under the terms of the GNU General Public License version 2 only, as
80.10 + * published by the Free Software Foundation. Oracle designates this
80.11 + * particular file as subject to the "Classpath" exception as provided
80.12 + * by Oracle in the LICENSE file that accompanied this code.
80.13 + *
80.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
80.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
80.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
80.17 + * version 2 for more details (a copy is included in the LICENSE file that
80.18 + * accompanied this code).
80.19 + *
80.20 + * You should have received a copy of the GNU General Public License version
80.21 + * 2 along with this work; if not, write to the Free Software Foundation,
80.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
80.23 + *
80.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
80.25 + * or visit www.oracle.com if you need additional information or have any
80.26 + * questions.
80.27 + */
80.28 +
80.29 +package java.lang.reflect;
80.30 +
80.31 +/**
80.32 + * TypeVariable is the common superinterface for type variables of kinds.
80.33 + * A type variable is created the first time it is needed by a reflective
80.34 + * method, as specified in this package. If a type variable t is referenced
80.35 + * by a type (i.e, class, interface or annotation type) T, and T is declared
80.36 + * by the nth enclosing class of T (see JLS 8.1.2), then the creation of t
80.37 + * requires the resolution (see JVMS 5) of the ith enclosing class of T,
80.38 + * for i = 0 to n, inclusive. Creating a type variable must not cause the
80.39 + * creation of its bounds. Repeated creation of a type variable has no effect.
80.40 + *
80.41 + * <p>Multiple objects may be instantiated at run-time to
80.42 + * represent a given type variable. Even though a type variable is
80.43 + * created only once, this does not imply any requirement to cache
80.44 + * instances representing the type variable. However, all instances
80.45 + * representing a type variable must be equal() to each other.
80.46 + * As a consequence, users of type variables must not rely on the identity
80.47 + * of instances of classes implementing this interface.
80.48 + *
80.49 + * @param <D> the type of generic declaration that declared the
80.50 + * underlying type variable.
80.51 + *
80.52 + * @since 1.5
80.53 + */
80.54 +public interface TypeVariable<D extends GenericDeclaration> extends Type {
80.55 + /**
80.56 + * Returns an array of {@code Type} objects representing the
80.57 + * upper bound(s) of this type variable. Note that if no upper bound is
80.58 + * explicitly declared, the upper bound is {@code Object}.
80.59 + *
80.60 + * <p>For each upper bound B: <ul> <li>if B is a parameterized
80.61 + * type or a type variable, it is created, (see {@link
80.62 + * java.lang.reflect.ParameterizedType ParameterizedType} for the
80.63 + * details of the creation process for parameterized types).
80.64 + * <li>Otherwise, B is resolved. </ul>
80.65 + *
80.66 + * @throws TypeNotPresentException if any of the
80.67 + * bounds refers to a non-existent type declaration
80.68 + * @throws MalformedParameterizedTypeException if any of the
80.69 + * bounds refer to a parameterized type that cannot be instantiated
80.70 + * for any reason
80.71 + * @return an array of {@code Type}s representing the upper
80.72 + * bound(s) of this type variable
80.73 + */
80.74 + Type[] getBounds();
80.75 +
80.76 + /**
80.77 + * Returns the {@code GenericDeclaration} object representing the
80.78 + * generic declaration declared this type variable.
80.79 + *
80.80 + * @return the generic declaration declared for this type variable.
80.81 + *
80.82 + * @since 1.5
80.83 + */
80.84 + D getGenericDeclaration();
80.85 +
80.86 + /**
80.87 + * Returns the name of this type variable, as it occurs in the source code.
80.88 + *
80.89 + * @return the name of this type variable, as it appears in the source code
80.90 + */
80.91 + String getName();
80.92 +}
81.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
81.2 +++ b/emul/src/main/java/java/lang/reflect/package-info.java Wed Jan 23 20:16:48 2013 +0100
81.3 @@ -0,0 +1,49 @@
81.4 +/*
81.5 + * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
81.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
81.7 + *
81.8 + * This code is free software; you can redistribute it and/or modify it
81.9 + * under the terms of the GNU General Public License version 2 only, as
81.10 + * published by the Free Software Foundation. Oracle designates this
81.11 + * particular file as subject to the "Classpath" exception as provided
81.12 + * by Oracle in the LICENSE file that accompanied this code.
81.13 + *
81.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
81.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
81.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
81.17 + * version 2 for more details (a copy is included in the LICENSE file that
81.18 + * accompanied this code).
81.19 + *
81.20 + * You should have received a copy of the GNU General Public License version
81.21 + * 2 along with this work; if not, write to the Free Software Foundation,
81.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
81.23 + *
81.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
81.25 + * or visit www.oracle.com if you need additional information or have any
81.26 + * questions.
81.27 + */
81.28 +
81.29 +/**
81.30 + * Provides classes and interfaces for obtaining reflective
81.31 + * information about classes and objects. Reflection allows
81.32 + * programmatic access to information about the fields, methods and
81.33 + * constructors of loaded classes, and the use of reflected fields,
81.34 + * methods, and constructors to operate on their underlying
81.35 + * counterparts, within security restrictions.
81.36 + *
81.37 + * <p>{@code AccessibleObject} allows suppression of access checks if
81.38 + * the necessary {@code ReflectPermission} is available.
81.39 + *
81.40 + * <p>{@code Array} provides static methods to dynamically create and
81.41 + * access arrays.
81.42 + *
81.43 + * <p>Classes in this package, along with {@code java.lang.Class}
81.44 + * accommodate applications such as debuggers, interpreters, object
81.45 + * inspectors, class browsers, and services such as Object
81.46 + * Serialization and JavaBeans that need access to either the public
81.47 + * members of a target object (based on its runtime class) or the
81.48 + * members declared by a given class.
81.49 + *
81.50 + * @since JDK1.1
81.51 + */
81.52 +package java.lang.reflect;
82.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
82.2 +++ b/emul/src/main/java/java/net/MalformedURLException.java Wed Jan 23 20:16:48 2013 +0100
82.3 @@ -0,0 +1,56 @@
82.4 +/*
82.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
82.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
82.7 + *
82.8 + * This code is free software; you can redistribute it and/or modify it
82.9 + * under the terms of the GNU General Public License version 2 only, as
82.10 + * published by the Free Software Foundation. Oracle designates this
82.11 + * particular file as subject to the "Classpath" exception as provided
82.12 + * by Oracle in the LICENSE file that accompanied this code.
82.13 + *
82.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
82.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
82.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
82.17 + * version 2 for more details (a copy is included in the LICENSE file that
82.18 + * accompanied this code).
82.19 + *
82.20 + * You should have received a copy of the GNU General Public License version
82.21 + * 2 along with this work; if not, write to the Free Software Foundation,
82.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
82.23 + *
82.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
82.25 + * or visit www.oracle.com if you need additional information or have any
82.26 + * questions.
82.27 + */
82.28 +
82.29 +package java.net;
82.30 +
82.31 +import java.io.IOException;
82.32 +
82.33 +/**
82.34 + * Thrown to indicate that a malformed URL has occurred. Either no
82.35 + * legal protocol could be found in a specification string or the
82.36 + * string could not be parsed.
82.37 + *
82.38 + * @author Arthur van Hoff
82.39 + * @since JDK1.0
82.40 + */
82.41 +public class MalformedURLException extends IOException {
82.42 + private static final long serialVersionUID = -182787522200415866L;
82.43 +
82.44 + /**
82.45 + * Constructs a <code>MalformedURLException</code> with no detail message.
82.46 + */
82.47 + public MalformedURLException() {
82.48 + }
82.49 +
82.50 + /**
82.51 + * Constructs a <code>MalformedURLException</code> with the
82.52 + * specified detail message.
82.53 + *
82.54 + * @param msg the detail message.
82.55 + */
82.56 + public MalformedURLException(String msg) {
82.57 + super(msg);
82.58 + }
82.59 +}
83.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
83.2 +++ b/emul/src/main/java/java/net/URL.java Wed Jan 23 20:16:48 2013 +0100
83.3 @@ -0,0 +1,1037 @@
83.4 +/*
83.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
83.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
83.7 + *
83.8 + * This code is free software; you can redistribute it and/or modify it
83.9 + * under the terms of the GNU General Public License version 2 only, as
83.10 + * published by the Free Software Foundation. Oracle designates this
83.11 + * particular file as subject to the "Classpath" exception as provided
83.12 + * by Oracle in the LICENSE file that accompanied this code.
83.13 + *
83.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
83.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
83.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
83.17 + * version 2 for more details (a copy is included in the LICENSE file that
83.18 + * accompanied this code).
83.19 + *
83.20 + * You should have received a copy of the GNU General Public License version
83.21 + * 2 along with this work; if not, write to the Free Software Foundation,
83.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
83.23 + *
83.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
83.25 + * or visit www.oracle.com if you need additional information or have any
83.26 + * questions.
83.27 + */
83.28 +
83.29 +package java.net;
83.30 +
83.31 +import java.io.IOException;
83.32 +import java.io.InputStream;
83.33 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
83.34 +
83.35 +/**
83.36 + * Class <code>URL</code> represents a Uniform Resource
83.37 + * Locator, a pointer to a "resource" on the World
83.38 + * Wide Web. A resource can be something as simple as a file or a
83.39 + * directory, or it can be a reference to a more complicated object,
83.40 + * such as a query to a database or to a search engine. More
83.41 + * information on the types of URLs and their formats can be found at:
83.42 + * <blockquote>
83.43 + * <a href="http://www.socs.uts.edu.au/MosaicDocs-old/url-primer.html">
83.44 + * <i>http://www.socs.uts.edu.au/MosaicDocs-old/url-primer.html</i></a>
83.45 + * </blockquote>
83.46 + * <p>
83.47 + * In general, a URL can be broken into several parts. The previous
83.48 + * example of a URL indicates that the protocol to use is
83.49 + * <code>http</code> (HyperText Transfer Protocol) and that the
83.50 + * information resides on a host machine named
83.51 + * <code>www.socs.uts.edu.au</code>. The information on that host
83.52 + * machine is named <code>/MosaicDocs-old/url-primer.html</code>. The exact
83.53 + * meaning of this name on the host machine is both protocol
83.54 + * dependent and host dependent. The information normally resides in
83.55 + * a file, but it could be generated on the fly. This component of
83.56 + * the URL is called the <i>path</i> component.
83.57 + * <p>
83.58 + * A URL can optionally specify a "port", which is the
83.59 + * port number to which the TCP connection is made on the remote host
83.60 + * machine. If the port is not specified, the default port for
83.61 + * the protocol is used instead. For example, the default port for
83.62 + * <code>http</code> is <code>80</code>. An alternative port could be
83.63 + * specified as:
83.64 + * <blockquote><pre>
83.65 + * http://www.socs.uts.edu.au:80/MosaicDocs-old/url-primer.html
83.66 + * </pre></blockquote>
83.67 + * <p>
83.68 + * The syntax of <code>URL</code> is defined by <a
83.69 + * href="http://www.ietf.org/rfc/rfc2396.txt"><i>RFC 2396: Uniform
83.70 + * Resource Identifiers (URI): Generic Syntax</i></a>, amended by <a
83.71 + * href="http://www.ietf.org/rfc/rfc2732.txt"><i>RFC 2732: Format for
83.72 + * Literal IPv6 Addresses in URLs</i></a>. The Literal IPv6 address format
83.73 + * also supports scope_ids. The syntax and usage of scope_ids is described
83.74 + * <a href="Inet6Address.html#scoped">here</a>.
83.75 + * <p>
83.76 + * A URL may have appended to it a "fragment", also known
83.77 + * as a "ref" or a "reference". The fragment is indicated by the sharp
83.78 + * sign character "#" followed by more characters. For example,
83.79 + * <blockquote><pre>
83.80 + * http://java.sun.com/index.html#chapter1
83.81 + * </pre></blockquote>
83.82 + * <p>
83.83 + * This fragment is not technically part of the URL. Rather, it
83.84 + * indicates that after the specified resource is retrieved, the
83.85 + * application is specifically interested in that part of the
83.86 + * document that has the tag <code>chapter1</code> attached to it. The
83.87 + * meaning of a tag is resource specific.
83.88 + * <p>
83.89 + * An application can also specify a "relative URL",
83.90 + * which contains only enough information to reach the resource
83.91 + * relative to another URL. Relative URLs are frequently used within
83.92 + * HTML pages. For example, if the contents of the URL:
83.93 + * <blockquote><pre>
83.94 + * http://java.sun.com/index.html
83.95 + * </pre></blockquote>
83.96 + * contained within it the relative URL:
83.97 + * <blockquote><pre>
83.98 + * FAQ.html
83.99 + * </pre></blockquote>
83.100 + * it would be a shorthand for:
83.101 + * <blockquote><pre>
83.102 + * http://java.sun.com/FAQ.html
83.103 + * </pre></blockquote>
83.104 + * <p>
83.105 + * The relative URL need not specify all the components of a URL. If
83.106 + * the protocol, host name, or port number is missing, the value is
83.107 + * inherited from the fully specified URL. The file component must be
83.108 + * specified. The optional fragment is not inherited.
83.109 + * <p>
83.110 + * The URL class does not itself encode or decode any URL components
83.111 + * according to the escaping mechanism defined in RFC2396. It is the
83.112 + * responsibility of the caller to encode any fields, which need to be
83.113 + * escaped prior to calling URL, and also to decode any escaped fields,
83.114 + * that are returned from URL. Furthermore, because URL has no knowledge
83.115 + * of URL escaping, it does not recognise equivalence between the encoded
83.116 + * or decoded form of the same URL. For example, the two URLs:<br>
83.117 + * <pre> http://foo.com/hello world/ and http://foo.com/hello%20world</pre>
83.118 + * would be considered not equal to each other.
83.119 + * <p>
83.120 + * Note, the {@link java.net.URI} class does perform escaping of its
83.121 + * component fields in certain circumstances. The recommended way
83.122 + * to manage the encoding and decoding of URLs is to use {@link java.net.URI},
83.123 + * and to convert between these two classes using {@link #toURI()} and
83.124 + * {@link URI#toURL()}.
83.125 + * <p>
83.126 + * The {@link URLEncoder} and {@link URLDecoder} classes can also be
83.127 + * used, but only for HTML form encoding, which is not the same
83.128 + * as the encoding scheme defined in RFC2396.
83.129 + *
83.130 + * @author James Gosling
83.131 + * @since JDK1.0
83.132 + */
83.133 +public final class URL implements java.io.Serializable {
83.134 +
83.135 + static final long serialVersionUID = -7627629688361524110L;
83.136 +
83.137 + /**
83.138 + * The property which specifies the package prefix list to be scanned
83.139 + * for protocol handlers. The value of this property (if any) should
83.140 + * be a vertical bar delimited list of package names to search through
83.141 + * for a protocol handler to load. The policy of this class is that
83.142 + * all protocol handlers will be in a class called <protocolname>.Handler,
83.143 + * and each package in the list is examined in turn for a matching
83.144 + * handler. If none are found (or the property is not specified), the
83.145 + * default package prefix, sun.net.www.protocol, is used. The search
83.146 + * proceeds from the first package in the list to the last and stops
83.147 + * when a match is found.
83.148 + */
83.149 + private static final String protocolPathProp = "java.protocol.handler.pkgs";
83.150 +
83.151 + /**
83.152 + * The protocol to use (ftp, http, nntp, ... etc.) .
83.153 + * @serial
83.154 + */
83.155 + private String protocol;
83.156 +
83.157 + /**
83.158 + * The host name to connect to.
83.159 + * @serial
83.160 + */
83.161 + private String host;
83.162 +
83.163 + /**
83.164 + * The protocol port to connect to.
83.165 + * @serial
83.166 + */
83.167 + private int port = -1;
83.168 +
83.169 + /**
83.170 + * The specified file name on that host. <code>file</code> is
83.171 + * defined as <code>path[?query]</code>
83.172 + * @serial
83.173 + */
83.174 + private String file;
83.175 +
83.176 + /**
83.177 + * The query part of this URL.
83.178 + */
83.179 + private transient String query;
83.180 +
83.181 + /**
83.182 + * The authority part of this URL.
83.183 + * @serial
83.184 + */
83.185 + private String authority;
83.186 +
83.187 + /**
83.188 + * The path part of this URL.
83.189 + */
83.190 + private transient String path;
83.191 +
83.192 + /**
83.193 + * The userinfo part of this URL.
83.194 + */
83.195 + private transient String userInfo;
83.196 +
83.197 + /**
83.198 + * # reference.
83.199 + * @serial
83.200 + */
83.201 + private String ref;
83.202 +
83.203 + /**
83.204 + * The host's IP address, used in equals and hashCode.
83.205 + * Computed on demand. An uninitialized or unknown hostAddress is null.
83.206 + */
83.207 + transient Object hostAddress;
83.208 +
83.209 + /**
83.210 + * The URLStreamHandler for this URL.
83.211 + */
83.212 + transient URLStreamHandler handler;
83.213 +
83.214 + /* Our hash code.
83.215 + * @serial
83.216 + */
83.217 + private int hashCode = -1;
83.218 +
83.219 + /**
83.220 + * Creates a <code>URL</code> object from the specified
83.221 + * <code>protocol</code>, <code>host</code>, <code>port</code>
83.222 + * number, and <code>file</code>.<p>
83.223 + *
83.224 + * <code>host</code> can be expressed as a host name or a literal
83.225 + * IP address. If IPv6 literal address is used, it should be
83.226 + * enclosed in square brackets (<tt>'['</tt> and <tt>']'</tt>), as
83.227 + * specified by <a
83.228 + * href="http://www.ietf.org/rfc/rfc2732.txt">RFC 2732</a>;
83.229 + * However, the literal IPv6 address format defined in <a
83.230 + * href="http://www.ietf.org/rfc/rfc2373.txt"><i>RFC 2373: IP
83.231 + * Version 6 Addressing Architecture</i></a> is also accepted.<p>
83.232 + *
83.233 + * Specifying a <code>port</code> number of <code>-1</code>
83.234 + * indicates that the URL should use the default port for the
83.235 + * protocol.<p>
83.236 + *
83.237 + * If this is the first URL object being created with the specified
83.238 + * protocol, a <i>stream protocol handler</i> object, an instance of
83.239 + * class <code>URLStreamHandler</code>, is created for that protocol:
83.240 + * <ol>
83.241 + * <li>If the application has previously set up an instance of
83.242 + * <code>URLStreamHandlerFactory</code> as the stream handler factory,
83.243 + * then the <code>createURLStreamHandler</code> method of that instance
83.244 + * is called with the protocol string as an argument to create the
83.245 + * stream protocol handler.
83.246 + * <li>If no <code>URLStreamHandlerFactory</code> has yet been set up,
83.247 + * or if the factory's <code>createURLStreamHandler</code> method
83.248 + * returns <code>null</code>, then the constructor finds the
83.249 + * value of the system property:
83.250 + * <blockquote><pre>
83.251 + * java.protocol.handler.pkgs
83.252 + * </pre></blockquote>
83.253 + * If the value of that system property is not <code>null</code>,
83.254 + * it is interpreted as a list of packages separated by a vertical
83.255 + * slash character '<code>|</code>'. The constructor tries to load
83.256 + * the class named:
83.257 + * <blockquote><pre>
83.258 + * <<i>package</i>>.<<i>protocol</i>>.Handler
83.259 + * </pre></blockquote>
83.260 + * where <<i>package</i>> is replaced by the name of the package
83.261 + * and <<i>protocol</i>> is replaced by the name of the protocol.
83.262 + * If this class does not exist, or if the class exists but it is not
83.263 + * a subclass of <code>URLStreamHandler</code>, then the next package
83.264 + * in the list is tried.
83.265 + * <li>If the previous step fails to find a protocol handler, then the
83.266 + * constructor tries to load from a system default package.
83.267 + * <blockquote><pre>
83.268 + * <<i>system default package</i>>.<<i>protocol</i>>.Handler
83.269 + * </pre></blockquote>
83.270 + * If this class does not exist, or if the class exists but it is not a
83.271 + * subclass of <code>URLStreamHandler</code>, then a
83.272 + * <code>MalformedURLException</code> is thrown.
83.273 + * </ol>
83.274 + *
83.275 + * <p>Protocol handlers for the following protocols are guaranteed
83.276 + * to exist on the search path :-
83.277 + * <blockquote><pre>
83.278 + * http, https, ftp, file, and jar
83.279 + * </pre></blockquote>
83.280 + * Protocol handlers for additional protocols may also be
83.281 + * available.
83.282 + *
83.283 + * <p>No validation of the inputs is performed by this constructor.
83.284 + *
83.285 + * @param protocol the name of the protocol to use.
83.286 + * @param host the name of the host.
83.287 + * @param port the port number on the host.
83.288 + * @param file the file on the host
83.289 + * @exception MalformedURLException if an unknown protocol is specified.
83.290 + * @see java.lang.System#getProperty(java.lang.String)
83.291 + * @see java.net.URL#setURLStreamHandlerFactory(
83.292 + * java.net.URLStreamHandlerFactory)
83.293 + * @see java.net.URLStreamHandler
83.294 + * @see java.net.URLStreamHandlerFactory#createURLStreamHandler(
83.295 + * java.lang.String)
83.296 + */
83.297 + public URL(String protocol, String host, int port, String file)
83.298 + throws MalformedURLException
83.299 + {
83.300 + this(protocol, host, port, file, null);
83.301 + }
83.302 +
83.303 + /**
83.304 + * Creates a URL from the specified <code>protocol</code>
83.305 + * name, <code>host</code> name, and <code>file</code> name. The
83.306 + * default port for the specified protocol is used.
83.307 + * <p>
83.308 + * This method is equivalent to calling the four-argument
83.309 + * constructor with the arguments being <code>protocol</code>,
83.310 + * <code>host</code>, <code>-1</code>, and <code>file</code>.
83.311 + *
83.312 + * No validation of the inputs is performed by this constructor.
83.313 + *
83.314 + * @param protocol the name of the protocol to use.
83.315 + * @param host the name of the host.
83.316 + * @param file the file on the host.
83.317 + * @exception MalformedURLException if an unknown protocol is specified.
83.318 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
83.319 + * int, java.lang.String)
83.320 + */
83.321 + public URL(String protocol, String host, String file)
83.322 + throws MalformedURLException {
83.323 + this(protocol, host, -1, file);
83.324 + }
83.325 +
83.326 + /**
83.327 + * Creates a <code>URL</code> object from the specified
83.328 + * <code>protocol</code>, <code>host</code>, <code>port</code>
83.329 + * number, <code>file</code>, and <code>handler</code>. Specifying
83.330 + * a <code>port</code> number of <code>-1</code> indicates that
83.331 + * the URL should use the default port for the protocol. Specifying
83.332 + * a <code>handler</code> of <code>null</code> indicates that the URL
83.333 + * should use a default stream handler for the protocol, as outlined
83.334 + * for:
83.335 + * java.net.URL#URL(java.lang.String, java.lang.String, int,
83.336 + * java.lang.String)
83.337 + *
83.338 + * <p>If the handler is not null and there is a security manager,
83.339 + * the security manager's <code>checkPermission</code>
83.340 + * method is called with a
83.341 + * <code>NetPermission("specifyStreamHandler")</code> permission.
83.342 + * This may result in a SecurityException.
83.343 + *
83.344 + * No validation of the inputs is performed by this constructor.
83.345 + *
83.346 + * @param protocol the name of the protocol to use.
83.347 + * @param host the name of the host.
83.348 + * @param port the port number on the host.
83.349 + * @param file the file on the host
83.350 + * @param handler the stream handler for the URL.
83.351 + * @exception MalformedURLException if an unknown protocol is specified.
83.352 + * @exception SecurityException
83.353 + * if a security manager exists and its
83.354 + * <code>checkPermission</code> method doesn't allow
83.355 + * specifying a stream handler explicitly.
83.356 + * @see java.lang.System#getProperty(java.lang.String)
83.357 + * @see java.net.URL#setURLStreamHandlerFactory(
83.358 + * java.net.URLStreamHandlerFactory)
83.359 + * @see java.net.URLStreamHandler
83.360 + * @see java.net.URLStreamHandlerFactory#createURLStreamHandler(
83.361 + * java.lang.String)
83.362 + * @see SecurityManager#checkPermission
83.363 + * @see java.net.NetPermission
83.364 + */
83.365 + public URL(String protocol, String host, int port, String file,
83.366 + URLStreamHandler handler) throws MalformedURLException {
83.367 + if (handler != null) {
83.368 + throw new SecurityException();
83.369 + }
83.370 +
83.371 + protocol = protocol.toLowerCase();
83.372 + this.protocol = protocol;
83.373 + if (host != null) {
83.374 +
83.375 + /**
83.376 + * if host is a literal IPv6 address,
83.377 + * we will make it conform to RFC 2732
83.378 + */
83.379 + if (host.indexOf(':') >= 0 && !host.startsWith("[")) {
83.380 + host = "["+host+"]";
83.381 + }
83.382 + this.host = host;
83.383 +
83.384 + if (port < -1) {
83.385 + throw new MalformedURLException("Invalid port number :" +
83.386 + port);
83.387 + }
83.388 + this.port = port;
83.389 + authority = (port == -1) ? host : host + ":" + port;
83.390 + }
83.391 +
83.392 + Parts parts = new Parts(file);
83.393 + path = parts.getPath();
83.394 + query = parts.getQuery();
83.395 +
83.396 + if (query != null) {
83.397 + this.file = path + "?" + query;
83.398 + } else {
83.399 + this.file = path;
83.400 + }
83.401 + ref = parts.getRef();
83.402 +
83.403 + // Note: we don't do validation of the URL here. Too risky to change
83.404 + // right now, but worth considering for future reference. -br
83.405 + if (handler == null &&
83.406 + (handler = getURLStreamHandler(protocol)) == null) {
83.407 + throw new MalformedURLException("unknown protocol: " + protocol);
83.408 + }
83.409 + this.handler = handler;
83.410 + }
83.411 +
83.412 + /**
83.413 + * Creates a <code>URL</code> object from the <code>String</code>
83.414 + * representation.
83.415 + * <p>
83.416 + * This constructor is equivalent to a call to the two-argument
83.417 + * constructor with a <code>null</code> first argument.
83.418 + *
83.419 + * @param spec the <code>String</code> to parse as a URL.
83.420 + * @exception MalformedURLException if no protocol is specified, or an
83.421 + * unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
83.422 + * @see java.net.URL#URL(java.net.URL, java.lang.String)
83.423 + */
83.424 + public URL(String spec) throws MalformedURLException {
83.425 + this(null, spec);
83.426 + }
83.427 +
83.428 + /**
83.429 + * Creates a URL by parsing the given spec within a specified context.
83.430 + *
83.431 + * The new URL is created from the given context URL and the spec
83.432 + * argument as described in
83.433 + * RFC2396 "Uniform Resource Identifiers : Generic * Syntax" :
83.434 + * <blockquote><pre>
83.435 + * <scheme>://<authority><path>?<query>#<fragment>
83.436 + * </pre></blockquote>
83.437 + * The reference is parsed into the scheme, authority, path, query and
83.438 + * fragment parts. If the path component is empty and the scheme,
83.439 + * authority, and query components are undefined, then the new URL is a
83.440 + * reference to the current document. Otherwise, the fragment and query
83.441 + * parts present in the spec are used in the new URL.
83.442 + * <p>
83.443 + * If the scheme component is defined in the given spec and does not match
83.444 + * the scheme of the context, then the new URL is created as an absolute
83.445 + * URL based on the spec alone. Otherwise the scheme component is inherited
83.446 + * from the context URL.
83.447 + * <p>
83.448 + * If the authority component is present in the spec then the spec is
83.449 + * treated as absolute and the spec authority and path will replace the
83.450 + * context authority and path. If the authority component is absent in the
83.451 + * spec then the authority of the new URL will be inherited from the
83.452 + * context.
83.453 + * <p>
83.454 + * If the spec's path component begins with a slash character
83.455 + * "/" then the
83.456 + * path is treated as absolute and the spec path replaces the context path.
83.457 + * <p>
83.458 + * Otherwise, the path is treated as a relative path and is appended to the
83.459 + * context path, as described in RFC2396. Also, in this case,
83.460 + * the path is canonicalized through the removal of directory
83.461 + * changes made by occurences of ".." and ".".
83.462 + * <p>
83.463 + * For a more detailed description of URL parsing, refer to RFC2396.
83.464 + *
83.465 + * @param context the context in which to parse the specification.
83.466 + * @param spec the <code>String</code> to parse as a URL.
83.467 + * @exception MalformedURLException if no protocol is specified, or an
83.468 + * unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
83.469 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
83.470 + * int, java.lang.String)
83.471 + * @see java.net.URLStreamHandler
83.472 + * @see java.net.URLStreamHandler#parseURL(java.net.URL,
83.473 + * java.lang.String, int, int)
83.474 + */
83.475 + public URL(URL context, String spec) throws MalformedURLException {
83.476 + this(context, spec, null);
83.477 + }
83.478 +
83.479 + /**
83.480 + * Creates a URL by parsing the given spec with the specified handler
83.481 + * within a specified context. If the handler is null, the parsing
83.482 + * occurs as with the two argument constructor.
83.483 + *
83.484 + * @param context the context in which to parse the specification.
83.485 + * @param spec the <code>String</code> to parse as a URL.
83.486 + * @param handler the stream handler for the URL.
83.487 + * @exception MalformedURLException if no protocol is specified, or an
83.488 + * unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
83.489 + * @exception SecurityException
83.490 + * if a security manager exists and its
83.491 + * <code>checkPermission</code> method doesn't allow
83.492 + * specifying a stream handler.
83.493 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
83.494 + * int, java.lang.String)
83.495 + * @see java.net.URLStreamHandler
83.496 + * @see java.net.URLStreamHandler#parseURL(java.net.URL,
83.497 + * java.lang.String, int, int)
83.498 + */
83.499 + public URL(URL context, String spec, URLStreamHandler handler)
83.500 + throws MalformedURLException
83.501 + {
83.502 + String original = spec;
83.503 + int i, limit, c;
83.504 + int start = 0;
83.505 + String newProtocol = null;
83.506 + boolean aRef=false;
83.507 + boolean isRelative = false;
83.508 +
83.509 + // Check for permission to specify a handler
83.510 + if (handler != null) {
83.511 + throw new SecurityException();
83.512 + }
83.513 +
83.514 + try {
83.515 + limit = spec.length();
83.516 + while ((limit > 0) && (spec.charAt(limit - 1) <= ' ')) {
83.517 + limit--; //eliminate trailing whitespace
83.518 + }
83.519 + while ((start < limit) && (spec.charAt(start) <= ' ')) {
83.520 + start++; // eliminate leading whitespace
83.521 + }
83.522 +
83.523 + if (spec.regionMatches(true, start, "url:", 0, 4)) {
83.524 + start += 4;
83.525 + }
83.526 + if (start < spec.length() && spec.charAt(start) == '#') {
83.527 + /* we're assuming this is a ref relative to the context URL.
83.528 + * This means protocols cannot start w/ '#', but we must parse
83.529 + * ref URL's like: "hello:there" w/ a ':' in them.
83.530 + */
83.531 + aRef=true;
83.532 + }
83.533 + for (i = start ; !aRef && (i < limit) &&
83.534 + ((c = spec.charAt(i)) != '/') ; i++) {
83.535 + if (c == ':') {
83.536 +
83.537 + String s = spec.substring(start, i).toLowerCase();
83.538 + if (isValidProtocol(s)) {
83.539 + newProtocol = s;
83.540 + start = i + 1;
83.541 + }
83.542 + break;
83.543 + }
83.544 + }
83.545 +
83.546 + // Only use our context if the protocols match.
83.547 + protocol = newProtocol;
83.548 + if ((context != null) && ((newProtocol == null) ||
83.549 + newProtocol.equalsIgnoreCase(context.protocol))) {
83.550 + // inherit the protocol handler from the context
83.551 + // if not specified to the constructor
83.552 + if (handler == null) {
83.553 + handler = context.handler;
83.554 + }
83.555 +
83.556 + // If the context is a hierarchical URL scheme and the spec
83.557 + // contains a matching scheme then maintain backwards
83.558 + // compatibility and treat it as if the spec didn't contain
83.559 + // the scheme; see 5.2.3 of RFC2396
83.560 + if (context.path != null && context.path.startsWith("/"))
83.561 + newProtocol = null;
83.562 +
83.563 + if (newProtocol == null) {
83.564 + protocol = context.protocol;
83.565 + authority = context.authority;
83.566 + userInfo = context.userInfo;
83.567 + host = context.host;
83.568 + port = context.port;
83.569 + file = context.file;
83.570 + path = context.path;
83.571 + isRelative = true;
83.572 + }
83.573 + }
83.574 +
83.575 + if (protocol == null) {
83.576 + throw new MalformedURLException("no protocol: "+original);
83.577 + }
83.578 +
83.579 + // Get the protocol handler if not specified or the protocol
83.580 + // of the context could not be used
83.581 + if (handler == null &&
83.582 + (handler = getURLStreamHandler(protocol)) == null) {
83.583 + throw new MalformedURLException("unknown protocol: "+protocol);
83.584 + }
83.585 + this.handler = handler;
83.586 +
83.587 + i = spec.indexOf('#', start);
83.588 + if (i >= 0) {
83.589 +//thrw(protocol + " hnd: " + handler.getClass().getName() + " i: " + i);
83.590 + ref = spec.substring(i + 1, limit);
83.591 + limit = i;
83.592 + }
83.593 +
83.594 + /*
83.595 + * Handle special case inheritance of query and fragment
83.596 + * implied by RFC2396 section 5.2.2.
83.597 + */
83.598 + if (isRelative && start == limit) {
83.599 + query = context.query;
83.600 + if (ref == null) {
83.601 + ref = context.ref;
83.602 + }
83.603 + }
83.604 +
83.605 + handler.parseURL(this, spec, start, limit);
83.606 +
83.607 + } catch(MalformedURLException e) {
83.608 + throw e;
83.609 + } catch(Exception e) {
83.610 + MalformedURLException exception = new MalformedURLException(e.getMessage());
83.611 + exception.initCause(e);
83.612 + throw exception;
83.613 + }
83.614 + }
83.615 +
83.616 + /*
83.617 + * Returns true if specified string is a valid protocol name.
83.618 + */
83.619 + private boolean isValidProtocol(String protocol) {
83.620 + int len = protocol.length();
83.621 + if (len < 1)
83.622 + return false;
83.623 + char c = protocol.charAt(0);
83.624 + if (!Character.isLetter(c))
83.625 + return false;
83.626 + for (int i = 1; i < len; i++) {
83.627 + c = protocol.charAt(i);
83.628 + if (!Character.isLetterOrDigit(c) && c != '.' && c != '+' &&
83.629 + c != '-') {
83.630 + return false;
83.631 + }
83.632 + }
83.633 + return true;
83.634 + }
83.635 +
83.636 + /**
83.637 + * Sets the fields of the URL. This is not a public method so that
83.638 + * only URLStreamHandlers can modify URL fields. URLs are
83.639 + * otherwise constant.
83.640 + *
83.641 + * @param protocol the name of the protocol to use
83.642 + * @param host the name of the host
83.643 + @param port the port number on the host
83.644 + * @param file the file on the host
83.645 + * @param ref the internal reference in the URL
83.646 + */
83.647 + protected void set(String protocol, String host,
83.648 + int port, String file, String ref) {
83.649 + synchronized (this) {
83.650 + this.protocol = protocol;
83.651 + this.host = host;
83.652 + authority = port == -1 ? host : host + ":" + port;
83.653 + this.port = port;
83.654 + this.file = file;
83.655 + this.ref = ref;
83.656 + /* This is very important. We must recompute this after the
83.657 + * URL has been changed. */
83.658 + hashCode = -1;
83.659 + hostAddress = null;
83.660 + int q = file.lastIndexOf('?');
83.661 + if (q != -1) {
83.662 + query = file.substring(q+1);
83.663 + path = file.substring(0, q);
83.664 + } else
83.665 + path = file;
83.666 + }
83.667 + }
83.668 +
83.669 + /**
83.670 + * Sets the specified 8 fields of the URL. This is not a public method so
83.671 + * that only URLStreamHandlers can modify URL fields. URLs are otherwise
83.672 + * constant.
83.673 + *
83.674 + * @param protocol the name of the protocol to use
83.675 + * @param host the name of the host
83.676 + * @param port the port number on the host
83.677 + * @param authority the authority part for the url
83.678 + * @param userInfo the username and password
83.679 + * @param path the file on the host
83.680 + * @param ref the internal reference in the URL
83.681 + * @param query the query part of this URL
83.682 + * @since 1.3
83.683 + */
83.684 + protected void set(String protocol, String host, int port,
83.685 + String authority, String userInfo, String path,
83.686 + String query, String ref) {
83.687 + synchronized (this) {
83.688 + this.protocol = protocol;
83.689 + this.host = host;
83.690 + this.port = port;
83.691 + this.file = query == null ? path : path + "?" + query;
83.692 + this.userInfo = userInfo;
83.693 + this.path = path;
83.694 + this.ref = ref;
83.695 + /* This is very important. We must recompute this after the
83.696 + * URL has been changed. */
83.697 + hashCode = -1;
83.698 + hostAddress = null;
83.699 + this.query = query;
83.700 + this.authority = authority;
83.701 + }
83.702 + }
83.703 +
83.704 + /**
83.705 + * Gets the query part of this <code>URL</code>.
83.706 + *
83.707 + * @return the query part of this <code>URL</code>,
83.708 + * or <CODE>null</CODE> if one does not exist
83.709 + * @since 1.3
83.710 + */
83.711 + public String getQuery() {
83.712 + return query;
83.713 + }
83.714 +
83.715 + /**
83.716 + * Gets the path part of this <code>URL</code>.
83.717 + *
83.718 + * @return the path part of this <code>URL</code>, or an
83.719 + * empty string if one does not exist
83.720 + * @since 1.3
83.721 + */
83.722 + public String getPath() {
83.723 + return path;
83.724 + }
83.725 +
83.726 + /**
83.727 + * Gets the userInfo part of this <code>URL</code>.
83.728 + *
83.729 + * @return the userInfo part of this <code>URL</code>, or
83.730 + * <CODE>null</CODE> if one does not exist
83.731 + * @since 1.3
83.732 + */
83.733 + public String getUserInfo() {
83.734 + return userInfo;
83.735 + }
83.736 +
83.737 + /**
83.738 + * Gets the authority part of this <code>URL</code>.
83.739 + *
83.740 + * @return the authority part of this <code>URL</code>
83.741 + * @since 1.3
83.742 + */
83.743 + public String getAuthority() {
83.744 + return authority;
83.745 + }
83.746 +
83.747 + /**
83.748 + * Gets the port number of this <code>URL</code>.
83.749 + *
83.750 + * @return the port number, or -1 if the port is not set
83.751 + */
83.752 + public int getPort() {
83.753 + return port;
83.754 + }
83.755 +
83.756 + /**
83.757 + * Gets the default port number of the protocol associated
83.758 + * with this <code>URL</code>. If the URL scheme or the URLStreamHandler
83.759 + * for the URL do not define a default port number,
83.760 + * then -1 is returned.
83.761 + *
83.762 + * @return the port number
83.763 + * @since 1.4
83.764 + */
83.765 + public int getDefaultPort() {
83.766 + return handler.getDefaultPort();
83.767 + }
83.768 +
83.769 + /**
83.770 + * Gets the protocol name of this <code>URL</code>.
83.771 + *
83.772 + * @return the protocol of this <code>URL</code>.
83.773 + */
83.774 + public String getProtocol() {
83.775 + return protocol;
83.776 + }
83.777 +
83.778 + /**
83.779 + * Gets the host name of this <code>URL</code>, if applicable.
83.780 + * The format of the host conforms to RFC 2732, i.e. for a
83.781 + * literal IPv6 address, this method will return the IPv6 address
83.782 + * enclosed in square brackets (<tt>'['</tt> and <tt>']'</tt>).
83.783 + *
83.784 + * @return the host name of this <code>URL</code>.
83.785 + */
83.786 + public String getHost() {
83.787 + return host;
83.788 + }
83.789 +
83.790 + /**
83.791 + * Gets the file name of this <code>URL</code>.
83.792 + * The returned file portion will be
83.793 + * the same as <CODE>getPath()</CODE>, plus the concatenation of
83.794 + * the value of <CODE>getQuery()</CODE>, if any. If there is
83.795 + * no query portion, this method and <CODE>getPath()</CODE> will
83.796 + * return identical results.
83.797 + *
83.798 + * @return the file name of this <code>URL</code>,
83.799 + * or an empty string if one does not exist
83.800 + */
83.801 + public String getFile() {
83.802 + return file;
83.803 + }
83.804 +
83.805 + /**
83.806 + * Gets the anchor (also known as the "reference") of this
83.807 + * <code>URL</code>.
83.808 + *
83.809 + * @return the anchor (also known as the "reference") of this
83.810 + * <code>URL</code>, or <CODE>null</CODE> if one does not exist
83.811 + */
83.812 + public String getRef() {
83.813 + return ref;
83.814 + }
83.815 +
83.816 + /**
83.817 + * Compares this URL for equality with another object.<p>
83.818 + *
83.819 + * If the given object is not a URL then this method immediately returns
83.820 + * <code>false</code>.<p>
83.821 + *
83.822 + * Two URL objects are equal if they have the same protocol, reference
83.823 + * equivalent hosts, have the same port number on the host, and the same
83.824 + * file and fragment of the file.<p>
83.825 + *
83.826 + * Two hosts are considered equivalent if both host names can be resolved
83.827 + * into the same IP addresses; else if either host name can't be
83.828 + * resolved, the host names must be equal without regard to case; or both
83.829 + * host names equal to null.<p>
83.830 + *
83.831 + * Since hosts comparison requires name resolution, this operation is a
83.832 + * blocking operation. <p>
83.833 + *
83.834 + * Note: The defined behavior for <code>equals</code> is known to
83.835 + * be inconsistent with virtual hosting in HTTP.
83.836 + *
83.837 + * @param obj the URL to compare against.
83.838 + * @return <code>true</code> if the objects are the same;
83.839 + * <code>false</code> otherwise.
83.840 + */
83.841 + public boolean equals(Object obj) {
83.842 + if (!(obj instanceof URL))
83.843 + return false;
83.844 + URL u2 = (URL)obj;
83.845 +
83.846 + return handler.equals(this, u2);
83.847 + }
83.848 +
83.849 + /**
83.850 + * Creates an integer suitable for hash table indexing.<p>
83.851 + *
83.852 + * The hash code is based upon all the URL components relevant for URL
83.853 + * comparison. As such, this operation is a blocking operation.<p>
83.854 + *
83.855 + * @return a hash code for this <code>URL</code>.
83.856 + */
83.857 + public synchronized int hashCode() {
83.858 + if (hashCode != -1)
83.859 + return hashCode;
83.860 +
83.861 + hashCode = handler.hashCode(this);
83.862 + return hashCode;
83.863 + }
83.864 +
83.865 + /**
83.866 + * Compares two URLs, excluding the fragment component.<p>
83.867 + *
83.868 + * Returns <code>true</code> if this <code>URL</code> and the
83.869 + * <code>other</code> argument are equal without taking the
83.870 + * fragment component into consideration.
83.871 + *
83.872 + * @param other the <code>URL</code> to compare against.
83.873 + * @return <code>true</code> if they reference the same remote object;
83.874 + * <code>false</code> otherwise.
83.875 + */
83.876 + public boolean sameFile(URL other) {
83.877 + return handler.sameFile(this, other);
83.878 + }
83.879 +
83.880 + /**
83.881 + * Constructs a string representation of this <code>URL</code>. The
83.882 + * string is created by calling the <code>toExternalForm</code>
83.883 + * method of the stream protocol handler for this object.
83.884 + *
83.885 + * @return a string representation of this object.
83.886 + * @see java.net.URL#URL(java.lang.String, java.lang.String, int,
83.887 + * java.lang.String)
83.888 + * @see java.net.URLStreamHandler#toExternalForm(java.net.URL)
83.889 + */
83.890 + public String toString() {
83.891 + return toExternalForm();
83.892 + }
83.893 +
83.894 + /**
83.895 + * Constructs a string representation of this <code>URL</code>. The
83.896 + * string is created by calling the <code>toExternalForm</code>
83.897 + * method of the stream protocol handler for this object.
83.898 + *
83.899 + * @return a string representation of this object.
83.900 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
83.901 + * int, java.lang.String)
83.902 + * @see java.net.URLStreamHandler#toExternalForm(java.net.URL)
83.903 + */
83.904 + public String toExternalForm() {
83.905 + return handler.toExternalForm(this);
83.906 + }
83.907 +
83.908 + /**
83.909 + * Returns a {@link java.net.URLConnection URLConnection} instance that
83.910 + * represents a connection to the remote object referred to by the
83.911 + * {@code URL}.
83.912 + *
83.913 + * <P>A new instance of {@linkplain java.net.URLConnection URLConnection} is
83.914 + * created every time when invoking the
83.915 + * {@linkplain java.net.URLStreamHandler#openConnection(URL)
83.916 + * URLStreamHandler.openConnection(URL)} method of the protocol handler for
83.917 + * this URL.</P>
83.918 + *
83.919 + * <P>It should be noted that a URLConnection instance does not establish
83.920 + * the actual network connection on creation. This will happen only when
83.921 + * calling {@linkplain java.net.URLConnection#connect() URLConnection.connect()}.</P>
83.922 + *
83.923 + * <P>If for the URL's protocol (such as HTTP or JAR), there
83.924 + * exists a public, specialized URLConnection subclass belonging
83.925 + * to one of the following packages or one of their subpackages:
83.926 + * java.lang, java.io, java.util, java.net, the connection
83.927 + * returned will be of that subclass. For example, for HTTP an
83.928 + * HttpURLConnection will be returned, and for JAR a
83.929 + * JarURLConnection will be returned.</P>
83.930 + *
83.931 + * @return a {@link java.net.URLConnection URLConnection} linking
83.932 + * to the URL.
83.933 + * @exception IOException if an I/O exception occurs.
83.934 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
83.935 + * int, java.lang.String)
83.936 + */
83.937 +// public URLConnection openConnection() throws java.io.IOException {
83.938 +// return handler.openConnection(this);
83.939 +// }
83.940 +
83.941 +
83.942 + /**
83.943 + * Opens a connection to this <code>URL</code> and returns an
83.944 + * <code>InputStream</code> for reading from that connection. This
83.945 + * method is a shorthand for:
83.946 + * <blockquote><pre>
83.947 + * openConnection().getInputStream()
83.948 + * </pre></blockquote>
83.949 + *
83.950 + * @return an input stream for reading from the URL connection.
83.951 + * @exception IOException if an I/O exception occurs.
83.952 + * @see java.net.URL#openConnection()
83.953 + * @see java.net.URLConnection#getInputStream()
83.954 + */
83.955 + public final InputStream openStream() throws java.io.IOException {
83.956 + throw new IOException();
83.957 +// return openConnection().getInputStream();
83.958 + }
83.959 +
83.960 + /**
83.961 + * Gets the contents of this URL. This method is a shorthand for:
83.962 + * <blockquote><pre>
83.963 + * openConnection().getContent()
83.964 + * </pre></blockquote>
83.965 + *
83.966 + * @return the contents of this URL.
83.967 + * @exception IOException if an I/O exception occurs.
83.968 + * @see java.net.URLConnection#getContent()
83.969 + */
83.970 + public final Object getContent() throws java.io.IOException {
83.971 + return loadText(toExternalForm());
83.972 + }
83.973 +
83.974 + @JavaScriptBody(args = "url", body = ""
83.975 + + "var request = new XMLHttpRequest();\n"
83.976 + + "request.open('GET', url, false);\n"
83.977 + + "request.send();\n"
83.978 + + "return request.responseText;\n"
83.979 + )
83.980 + private static native String loadText(String url) throws IOException;
83.981 +
83.982 + /**
83.983 + * Gets the contents of this URL. This method is a shorthand for:
83.984 + * <blockquote><pre>
83.985 + * openConnection().getContent(Class[])
83.986 + * </pre></blockquote>
83.987 + *
83.988 + * @param classes an array of Java types
83.989 + * @return the content object of this URL that is the first match of
83.990 + * the types specified in the classes array.
83.991 + * null if none of the requested types are supported.
83.992 + * @exception IOException if an I/O exception occurs.
83.993 + * @see java.net.URLConnection#getContent(Class[])
83.994 + * @since 1.3
83.995 + */
83.996 + public final Object getContent(Class[] classes)
83.997 + throws java.io.IOException {
83.998 + for (Class<?> c : classes) {
83.999 + if (c == String.class) {
83.1000 + return getContent();
83.1001 + }
83.1002 + }
83.1003 + return null;
83.1004 + }
83.1005 +
83.1006 + static URLStreamHandler getURLStreamHandler(String protocol) {
83.1007 + URLStreamHandler universal = new URLStreamHandler() {};
83.1008 + return universal;
83.1009 + }
83.1010 +
83.1011 +}
83.1012 +
83.1013 +class Parts {
83.1014 + String path, query, ref;
83.1015 +
83.1016 + Parts(String file) {
83.1017 + int ind = file.indexOf('#');
83.1018 + ref = ind < 0 ? null: file.substring(ind + 1);
83.1019 + file = ind < 0 ? file: file.substring(0, ind);
83.1020 + int q = file.lastIndexOf('?');
83.1021 + if (q != -1) {
83.1022 + query = file.substring(q+1);
83.1023 + path = file.substring(0, q);
83.1024 + } else {
83.1025 + path = file;
83.1026 + }
83.1027 + }
83.1028 +
83.1029 + String getPath() {
83.1030 + return path;
83.1031 + }
83.1032 +
83.1033 + String getQuery() {
83.1034 + return query;
83.1035 + }
83.1036 +
83.1037 + String getRef() {
83.1038 + return ref;
83.1039 + }
83.1040 +}
84.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
84.2 +++ b/emul/src/main/java/java/net/URLStreamHandler.java Wed Jan 23 20:16:48 2013 +0100
84.3 @@ -0,0 +1,568 @@
84.4 +/*
84.5 + * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
84.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
84.7 + *
84.8 + * This code is free software; you can redistribute it and/or modify it
84.9 + * under the terms of the GNU General Public License version 2 only, as
84.10 + * published by the Free Software Foundation. Oracle designates this
84.11 + * particular file as subject to the "Classpath" exception as provided
84.12 + * by Oracle in the LICENSE file that accompanied this code.
84.13 + *
84.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
84.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
84.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
84.17 + * version 2 for more details (a copy is included in the LICENSE file that
84.18 + * accompanied this code).
84.19 + *
84.20 + * You should have received a copy of the GNU General Public License version
84.21 + * 2 along with this work; if not, write to the Free Software Foundation,
84.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
84.23 + *
84.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
84.25 + * or visit www.oracle.com if you need additional information or have any
84.26 + * questions.
84.27 + */
84.28 +
84.29 +package java.net;
84.30 +
84.31 +
84.32 +/**
84.33 + * The abstract class <code>URLStreamHandler</code> is the common
84.34 + * superclass for all stream protocol handlers. A stream protocol
84.35 + * handler knows how to make a connection for a particular protocol
84.36 + * type, such as <code>http</code>, <code>ftp</code>, or
84.37 + * <code>gopher</code>.
84.38 + * <p>
84.39 + * In most cases, an instance of a <code>URLStreamHandler</code>
84.40 + * subclass is not created directly by an application. Rather, the
84.41 + * first time a protocol name is encountered when constructing a
84.42 + * <code>URL</code>, the appropriate stream protocol handler is
84.43 + * automatically loaded.
84.44 + *
84.45 + * @author James Gosling
84.46 + * @see java.net.URL#URL(java.lang.String, java.lang.String, int, java.lang.String)
84.47 + * @since JDK1.0
84.48 + */
84.49 +public abstract class URLStreamHandler {
84.50 + /**
84.51 + * Opens a connection to the object referenced by the
84.52 + * <code>URL</code> argument.
84.53 + * This method should be overridden by a subclass.
84.54 + *
84.55 + * <p>If for the handler's protocol (such as HTTP or JAR), there
84.56 + * exists a public, specialized URLConnection subclass belonging
84.57 + * to one of the following packages or one of their subpackages:
84.58 + * java.lang, java.io, java.util, java.net, the connection
84.59 + * returned will be of that subclass. For example, for HTTP an
84.60 + * HttpURLConnection will be returned, and for JAR a
84.61 + * JarURLConnection will be returned.
84.62 + *
84.63 + * @param u the URL that this connects to.
84.64 + * @return a <code>URLConnection</code> object for the <code>URL</code>.
84.65 + * @exception IOException if an I/O error occurs while opening the
84.66 + * connection.
84.67 + */
84.68 +// abstract protected URLConnection openConnection(URL u) throws IOException;
84.69 +
84.70 + /**
84.71 + * Same as openConnection(URL), except that the connection will be
84.72 + * made through the specified proxy; Protocol handlers that do not
84.73 + * support proxying will ignore the proxy parameter and make a
84.74 + * normal connection.
84.75 + *
84.76 + * Calling this method preempts the system's default ProxySelector
84.77 + * settings.
84.78 + *
84.79 + * @param u the URL that this connects to.
84.80 + * @param p the proxy through which the connection will be made.
84.81 + * If direct connection is desired, Proxy.NO_PROXY
84.82 + * should be specified.
84.83 + * @return a <code>URLConnection</code> object for the <code>URL</code>.
84.84 + * @exception IOException if an I/O error occurs while opening the
84.85 + * connection.
84.86 + * @exception IllegalArgumentException if either u or p is null,
84.87 + * or p has the wrong type.
84.88 + * @exception UnsupportedOperationException if the subclass that
84.89 + * implements the protocol doesn't support this method.
84.90 + * @since 1.5
84.91 + */
84.92 +// protected URLConnection openConnection(URL u, Proxy p) throws IOException {
84.93 +// throw new UnsupportedOperationException("Method not implemented.");
84.94 +// }
84.95 +
84.96 + /**
84.97 + * Parses the string representation of a <code>URL</code> into a
84.98 + * <code>URL</code> object.
84.99 + * <p>
84.100 + * If there is any inherited context, then it has already been
84.101 + * copied into the <code>URL</code> argument.
84.102 + * <p>
84.103 + * The <code>parseURL</code> method of <code>URLStreamHandler</code>
84.104 + * parses the string representation as if it were an
84.105 + * <code>http</code> specification. Most URL protocol families have a
84.106 + * similar parsing. A stream protocol handler for a protocol that has
84.107 + * a different syntax must override this routine.
84.108 + *
84.109 + * @param u the <code>URL</code> to receive the result of parsing
84.110 + * the spec.
84.111 + * @param spec the <code>String</code> representing the URL that
84.112 + * must be parsed.
84.113 + * @param start the character index at which to begin parsing. This is
84.114 + * just past the '<code>:</code>' (if there is one) that
84.115 + * specifies the determination of the protocol name.
84.116 + * @param limit the character position to stop parsing at. This is the
84.117 + * end of the string or the position of the
84.118 + * "<code>#</code>" character, if present. All information
84.119 + * after the sharp sign indicates an anchor.
84.120 + */
84.121 + protected void parseURL(URL u, String spec, int start, int limit) {
84.122 + // These fields may receive context content if this was relative URL
84.123 + String protocol = u.getProtocol();
84.124 + String authority = u.getAuthority();
84.125 + String userInfo = u.getUserInfo();
84.126 + String host = u.getHost();
84.127 + int port = u.getPort();
84.128 + String path = u.getPath();
84.129 + String query = u.getQuery();
84.130 +
84.131 + // This field has already been parsed
84.132 + String ref = u.getRef();
84.133 +
84.134 + boolean isRelPath = false;
84.135 + boolean queryOnly = false;
84.136 +
84.137 +// FIX: should not assume query if opaque
84.138 + // Strip off the query part
84.139 + if (start < limit) {
84.140 + int queryStart = spec.indexOf('?');
84.141 + queryOnly = queryStart == start;
84.142 + if ((queryStart != -1) && (queryStart < limit)) {
84.143 + query = spec.substring(queryStart+1, limit);
84.144 + if (limit > queryStart)
84.145 + limit = queryStart;
84.146 + spec = spec.substring(0, queryStart);
84.147 + }
84.148 + }
84.149 +
84.150 + int i = 0;
84.151 + // Parse the authority part if any
84.152 + boolean isUNCName = (start <= limit - 4) &&
84.153 + (spec.charAt(start) == '/') &&
84.154 + (spec.charAt(start + 1) == '/') &&
84.155 + (spec.charAt(start + 2) == '/') &&
84.156 + (spec.charAt(start + 3) == '/');
84.157 + if (!isUNCName && (start <= limit - 2) && (spec.charAt(start) == '/') &&
84.158 + (spec.charAt(start + 1) == '/')) {
84.159 + start += 2;
84.160 + i = spec.indexOf('/', start);
84.161 + if (i < 0) {
84.162 + i = spec.indexOf('?', start);
84.163 + if (i < 0)
84.164 + i = limit;
84.165 + }
84.166 +
84.167 + host = authority = spec.substring(start, i);
84.168 +
84.169 + int ind = authority.indexOf('@');
84.170 + if (ind != -1) {
84.171 + userInfo = authority.substring(0, ind);
84.172 + host = authority.substring(ind+1);
84.173 + } else {
84.174 + userInfo = null;
84.175 + }
84.176 + if (host != null) {
84.177 + // If the host is surrounded by [ and ] then its an IPv6
84.178 + // literal address as specified in RFC2732
84.179 + if (host.length()>0 && (host.charAt(0) == '[')) {
84.180 + if ((ind = host.indexOf(']')) > 2) {
84.181 +
84.182 + String nhost = host ;
84.183 + host = nhost.substring(0,ind+1);
84.184 +// if (!IPAddressUtil.
84.185 +// isIPv6LiteralAddress(host.substring(1, ind))) {
84.186 +// throw new IllegalArgumentException(
84.187 +// "Invalid host: "+ host);
84.188 +// }
84.189 +
84.190 + port = -1 ;
84.191 + if (nhost.length() > ind+1) {
84.192 + if (nhost.charAt(ind+1) == ':') {
84.193 + ++ind ;
84.194 + // port can be null according to RFC2396
84.195 + if (nhost.length() > (ind + 1)) {
84.196 + port = Integer.parseInt(nhost.substring(ind+1));
84.197 + }
84.198 + } else {
84.199 + throw new IllegalArgumentException(
84.200 + "Invalid authority field: " + authority);
84.201 + }
84.202 + }
84.203 + } else {
84.204 + throw new IllegalArgumentException(
84.205 + "Invalid authority field: " + authority);
84.206 + }
84.207 + } else {
84.208 + ind = host.indexOf(':');
84.209 + port = -1;
84.210 + if (ind >= 0) {
84.211 + // port can be null according to RFC2396
84.212 + if (host.length() > (ind + 1)) {
84.213 + port = Integer.parseInt(host.substring(ind + 1));
84.214 + }
84.215 + host = host.substring(0, ind);
84.216 + }
84.217 + }
84.218 + } else {
84.219 + host = "";
84.220 + }
84.221 + if (port < -1)
84.222 + throw new IllegalArgumentException("Invalid port number :" +
84.223 + port);
84.224 + start = i;
84.225 + // If the authority is defined then the path is defined by the
84.226 + // spec only; See RFC 2396 Section 5.2.4.
84.227 + if (authority != null && authority.length() > 0)
84.228 + path = "";
84.229 + }
84.230 +
84.231 + if (host == null) {
84.232 + host = "";
84.233 + }
84.234 +
84.235 + // Parse the file path if any
84.236 + if (start < limit) {
84.237 + if (spec.charAt(start) == '/') {
84.238 + path = spec.substring(start, limit);
84.239 + } else if (path != null && path.length() > 0) {
84.240 + isRelPath = true;
84.241 + int ind = path.lastIndexOf('/');
84.242 + String seperator = "";
84.243 + if (ind == -1 && authority != null)
84.244 + seperator = "/";
84.245 + path = path.substring(0, ind + 1) + seperator +
84.246 + spec.substring(start, limit);
84.247 +
84.248 + } else {
84.249 + String seperator = (authority != null) ? "/" : "";
84.250 + path = seperator + spec.substring(start, limit);
84.251 + }
84.252 + } else if (queryOnly && path != null) {
84.253 + int ind = path.lastIndexOf('/');
84.254 + if (ind < 0)
84.255 + ind = 0;
84.256 + path = path.substring(0, ind) + "/";
84.257 + }
84.258 + if (path == null)
84.259 + path = "";
84.260 +
84.261 + if (isRelPath) {
84.262 + // Remove embedded /./
84.263 + while ((i = path.indexOf("/./")) >= 0) {
84.264 + path = path.substring(0, i) + path.substring(i + 2);
84.265 + }
84.266 + // Remove embedded /../ if possible
84.267 + i = 0;
84.268 + while ((i = path.indexOf("/../", i)) >= 0) {
84.269 + /*
84.270 + * A "/../" will cancel the previous segment and itself,
84.271 + * unless that segment is a "/../" itself
84.272 + * i.e. "/a/b/../c" becomes "/a/c"
84.273 + * but "/../../a" should stay unchanged
84.274 + */
84.275 + if (i > 0 && (limit = path.lastIndexOf('/', i - 1)) >= 0 &&
84.276 + (path.indexOf("/../", limit) != 0)) {
84.277 + path = path.substring(0, limit) + path.substring(i + 3);
84.278 + i = 0;
84.279 + } else {
84.280 + i = i + 3;
84.281 + }
84.282 + }
84.283 + // Remove trailing .. if possible
84.284 + while (path.endsWith("/..")) {
84.285 + i = path.indexOf("/..");
84.286 + if ((limit = path.lastIndexOf('/', i - 1)) >= 0) {
84.287 + path = path.substring(0, limit+1);
84.288 + } else {
84.289 + break;
84.290 + }
84.291 + }
84.292 + // Remove starting .
84.293 + if (path.startsWith("./") && path.length() > 2)
84.294 + path = path.substring(2);
84.295 +
84.296 + // Remove trailing .
84.297 + if (path.endsWith("/."))
84.298 + path = path.substring(0, path.length() -1);
84.299 + }
84.300 +
84.301 + setURL(u, protocol, host, port, authority, userInfo, path, query, ref);
84.302 + }
84.303 +
84.304 + /**
84.305 + * Returns the default port for a URL parsed by this handler. This method
84.306 + * is meant to be overidden by handlers with default port numbers.
84.307 + * @return the default port for a <code>URL</code> parsed by this handler.
84.308 + * @since 1.3
84.309 + */
84.310 + protected int getDefaultPort() {
84.311 + return -1;
84.312 + }
84.313 +
84.314 + /**
84.315 + * Provides the default equals calculation. May be overidden by handlers
84.316 + * for other protocols that have different requirements for equals().
84.317 + * This method requires that none of its arguments is null. This is
84.318 + * guaranteed by the fact that it is only called by java.net.URL class.
84.319 + * @param u1 a URL object
84.320 + * @param u2 a URL object
84.321 + * @return <tt>true</tt> if the two urls are
84.322 + * considered equal, ie. they refer to the same
84.323 + * fragment in the same file.
84.324 + * @since 1.3
84.325 + */
84.326 + protected boolean equals(URL u1, URL u2) {
84.327 + String ref1 = u1.getRef();
84.328 + String ref2 = u2.getRef();
84.329 + return (ref1 == ref2 || (ref1 != null && ref1.equals(ref2))) &&
84.330 + sameFile(u1, u2);
84.331 + }
84.332 +
84.333 + /**
84.334 + * Provides the default hash calculation. May be overidden by handlers for
84.335 + * other protocols that have different requirements for hashCode
84.336 + * calculation.
84.337 + * @param u a URL object
84.338 + * @return an <tt>int</tt> suitable for hash table indexing
84.339 + * @since 1.3
84.340 + */
84.341 + protected int hashCode(URL u) {
84.342 + int h = 0;
84.343 +
84.344 + // Generate the protocol part.
84.345 + String protocol = u.getProtocol();
84.346 + if (protocol != null)
84.347 + h += protocol.hashCode();
84.348 +
84.349 + // Generate the host part.
84.350 + Object addr = getHostAddress(u);
84.351 + if (addr != null) {
84.352 + h += addr.hashCode();
84.353 + } else {
84.354 + String host = u.getHost();
84.355 + if (host != null)
84.356 + h += host.toLowerCase().hashCode();
84.357 + }
84.358 +
84.359 + // Generate the file part.
84.360 + String file = u.getFile();
84.361 + if (file != null)
84.362 + h += file.hashCode();
84.363 +
84.364 + // Generate the port part.
84.365 + if (u.getPort() == -1)
84.366 + h += getDefaultPort();
84.367 + else
84.368 + h += u.getPort();
84.369 +
84.370 + // Generate the ref part.
84.371 + String ref = u.getRef();
84.372 + if (ref != null)
84.373 + h += ref.hashCode();
84.374 +
84.375 + return h;
84.376 + }
84.377 +
84.378 + /**
84.379 + * Compare two urls to see whether they refer to the same file,
84.380 + * i.e., having the same protocol, host, port, and path.
84.381 + * This method requires that none of its arguments is null. This is
84.382 + * guaranteed by the fact that it is only called indirectly
84.383 + * by java.net.URL class.
84.384 + * @param u1 a URL object
84.385 + * @param u2 a URL object
84.386 + * @return true if u1 and u2 refer to the same file
84.387 + * @since 1.3
84.388 + */
84.389 + protected boolean sameFile(URL u1, URL u2) {
84.390 + // Compare the protocols.
84.391 + if (!((u1.getProtocol() == u2.getProtocol()) ||
84.392 + (u1.getProtocol() != null &&
84.393 + u1.getProtocol().equalsIgnoreCase(u2.getProtocol()))))
84.394 + return false;
84.395 +
84.396 + // Compare the files.
84.397 + if (!(u1.getFile() == u2.getFile() ||
84.398 + (u1.getFile() != null && u1.getFile().equals(u2.getFile()))))
84.399 + return false;
84.400 +
84.401 + // Compare the ports.
84.402 + int port1, port2;
84.403 + port1 = (u1.getPort() != -1) ? u1.getPort() : u1.handler.getDefaultPort();
84.404 + port2 = (u2.getPort() != -1) ? u2.getPort() : u2.handler.getDefaultPort();
84.405 + if (port1 != port2)
84.406 + return false;
84.407 +
84.408 + // Compare the hosts.
84.409 + if (!hostsEqual(u1, u2))
84.410 + return false;
84.411 +
84.412 + return true;
84.413 + }
84.414 +
84.415 + /**
84.416 + * Get the IP address of our host. An empty host field or a DNS failure
84.417 + * will result in a null return.
84.418 + *
84.419 + * @param u a URL object
84.420 + * @return an <code>InetAddress</code> representing the host
84.421 + * IP address.
84.422 + * @since 1.3
84.423 + */
84.424 + private synchronized Object getHostAddress(URL u) {
84.425 + return u.hostAddress;
84.426 + }
84.427 +
84.428 + /**
84.429 + * Compares the host components of two URLs.
84.430 + * @param u1 the URL of the first host to compare
84.431 + * @param u2 the URL of the second host to compare
84.432 + * @return <tt>true</tt> if and only if they
84.433 + * are equal, <tt>false</tt> otherwise.
84.434 + * @since 1.3
84.435 + */
84.436 + protected boolean hostsEqual(URL u1, URL u2) {
84.437 + Object a1 = getHostAddress(u1);
84.438 + Object a2 = getHostAddress(u2);
84.439 + // if we have internet address for both, compare them
84.440 + if (a1 != null && a2 != null) {
84.441 + return a1.equals(a2);
84.442 + // else, if both have host names, compare them
84.443 + } else if (u1.getHost() != null && u2.getHost() != null)
84.444 + return u1.getHost().equalsIgnoreCase(u2.getHost());
84.445 + else
84.446 + return u1.getHost() == null && u2.getHost() == null;
84.447 + }
84.448 +
84.449 + /**
84.450 + * Converts a <code>URL</code> of a specific protocol to a
84.451 + * <code>String</code>.
84.452 + *
84.453 + * @param u the URL.
84.454 + * @return a string representation of the <code>URL</code> argument.
84.455 + */
84.456 + protected String toExternalForm(URL u) {
84.457 +
84.458 + // pre-compute length of StringBuffer
84.459 + int len = u.getProtocol().length() + 1;
84.460 + if (u.getAuthority() != null && u.getAuthority().length() > 0)
84.461 + len += 2 + u.getAuthority().length();
84.462 + if (u.getPath() != null) {
84.463 + len += u.getPath().length();
84.464 + }
84.465 + if (u.getQuery() != null) {
84.466 + len += 1 + u.getQuery().length();
84.467 + }
84.468 + if (u.getRef() != null)
84.469 + len += 1 + u.getRef().length();
84.470 +
84.471 + StringBuffer result = new StringBuffer(len);
84.472 + result.append(u.getProtocol());
84.473 + result.append(":");
84.474 + if (u.getAuthority() != null && u.getAuthority().length() > 0) {
84.475 + result.append("//");
84.476 + result.append(u.getAuthority());
84.477 + }
84.478 + if (u.getPath() != null) {
84.479 + result.append(u.getPath());
84.480 + }
84.481 + if (u.getQuery() != null) {
84.482 + result.append('?');
84.483 + result.append(u.getQuery());
84.484 + }
84.485 + if (u.getRef() != null) {
84.486 + result.append("#");
84.487 + result.append(u.getRef());
84.488 + }
84.489 + return result.toString();
84.490 + }
84.491 +
84.492 + /**
84.493 + * Sets the fields of the <code>URL</code> argument to the indicated values.
84.494 + * Only classes derived from URLStreamHandler are supposed to be able
84.495 + * to call the set method on a URL.
84.496 + *
84.497 + * @param u the URL to modify.
84.498 + * @param protocol the protocol name.
84.499 + * @param host the remote host value for the URL.
84.500 + * @param port the port on the remote machine.
84.501 + * @param authority the authority part for the URL.
84.502 + * @param userInfo the userInfo part of the URL.
84.503 + * @param path the path component of the URL.
84.504 + * @param query the query part for the URL.
84.505 + * @param ref the reference.
84.506 + * @exception SecurityException if the protocol handler of the URL is
84.507 + * different from this one
84.508 + * @see java.net.URL#set(java.lang.String, java.lang.String, int, java.lang.String, java.lang.String)
84.509 + * @since 1.3
84.510 + */
84.511 + protected void setURL(URL u, String protocol, String host, int port,
84.512 + String authority, String userInfo, String path,
84.513 + String query, String ref) {
84.514 + if (this != u.handler) {
84.515 + throw new SecurityException("handler for url different from " +
84.516 + "this handler");
84.517 + }
84.518 + // ensure that no one can reset the protocol on a given URL.
84.519 + u.set(u.getProtocol(), host, port, authority, userInfo, path, query, ref);
84.520 + }
84.521 +
84.522 + /**
84.523 + * Sets the fields of the <code>URL</code> argument to the indicated values.
84.524 + * Only classes derived from URLStreamHandler are supposed to be able
84.525 + * to call the set method on a URL.
84.526 + *
84.527 + * @param u the URL to modify.
84.528 + * @param protocol the protocol name. This value is ignored since 1.2.
84.529 + * @param host the remote host value for the URL.
84.530 + * @param port the port on the remote machine.
84.531 + * @param file the file.
84.532 + * @param ref the reference.
84.533 + * @exception SecurityException if the protocol handler of the URL is
84.534 + * different from this one
84.535 + * @deprecated Use setURL(URL, String, String, int, String, String, String,
84.536 + * String);
84.537 + */
84.538 + @Deprecated
84.539 + protected void setURL(URL u, String protocol, String host, int port,
84.540 + String file, String ref) {
84.541 + /*
84.542 + * Only old URL handlers call this, so assume that the host
84.543 + * field might contain "user:passwd@host". Fix as necessary.
84.544 + */
84.545 + String authority = null;
84.546 + String userInfo = null;
84.547 + if (host != null && host.length() != 0) {
84.548 + authority = (port == -1) ? host : host + ":" + port;
84.549 + int at = host.lastIndexOf('@');
84.550 + if (at != -1) {
84.551 + userInfo = host.substring(0, at);
84.552 + host = host.substring(at+1);
84.553 + }
84.554 + }
84.555 +
84.556 + /*
84.557 + * Assume file might contain query part. Fix as necessary.
84.558 + */
84.559 + String path = null;
84.560 + String query = null;
84.561 + if (file != null) {
84.562 + int q = file.lastIndexOf('?');
84.563 + if (q != -1) {
84.564 + query = file.substring(q+1);
84.565 + path = file.substring(0, q);
84.566 + } else
84.567 + path = file;
84.568 + }
84.569 + setURL(u, protocol, host, port, authority, userInfo, path, query, ref);
84.570 + }
84.571 +}
85.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
85.2 +++ b/emul/src/main/java/java/util/Enumeration.java Wed Jan 23 20:16:48 2013 +0100
85.3 @@ -0,0 +1,79 @@
85.4 +/*
85.5 + * Copyright (c) 1994, 2005, Oracle and/or its affiliates. All rights reserved.
85.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
85.7 + *
85.8 + * This code is free software; you can redistribute it and/or modify it
85.9 + * under the terms of the GNU General Public License version 2 only, as
85.10 + * published by the Free Software Foundation. Oracle designates this
85.11 + * particular file as subject to the "Classpath" exception as provided
85.12 + * by Oracle in the LICENSE file that accompanied this code.
85.13 + *
85.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
85.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
85.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
85.17 + * version 2 for more details (a copy is included in the LICENSE file that
85.18 + * accompanied this code).
85.19 + *
85.20 + * You should have received a copy of the GNU General Public License version
85.21 + * 2 along with this work; if not, write to the Free Software Foundation,
85.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
85.23 + *
85.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
85.25 + * or visit www.oracle.com if you need additional information or have any
85.26 + * questions.
85.27 + */
85.28 +
85.29 +package java.util;
85.30 +
85.31 +/**
85.32 + * An object that implements the Enumeration interface generates a
85.33 + * series of elements, one at a time. Successive calls to the
85.34 + * <code>nextElement</code> method return successive elements of the
85.35 + * series.
85.36 + * <p>
85.37 + * For example, to print all elements of a <tt>Vector<E></tt> <i>v</i>:
85.38 + * <pre>
85.39 + * for (Enumeration<E> e = v.elements(); e.hasMoreElements();)
85.40 + * System.out.println(e.nextElement());</pre>
85.41 + * <p>
85.42 + * Methods are provided to enumerate through the elements of a
85.43 + * vector, the keys of a hashtable, and the values in a hashtable.
85.44 + * Enumerations are also used to specify the input streams to a
85.45 + * <code>SequenceInputStream</code>.
85.46 + * <p>
85.47 + * NOTE: The functionality of this interface is duplicated by the Iterator
85.48 + * interface. In addition, Iterator adds an optional remove operation, and
85.49 + * has shorter method names. New implementations should consider using
85.50 + * Iterator in preference to Enumeration.
85.51 + *
85.52 + * @see java.util.Iterator
85.53 + * @see java.io.SequenceInputStream
85.54 + * @see java.util.Enumeration#nextElement()
85.55 + * @see java.util.Hashtable
85.56 + * @see java.util.Hashtable#elements()
85.57 + * @see java.util.Hashtable#keys()
85.58 + * @see java.util.Vector
85.59 + * @see java.util.Vector#elements()
85.60 + *
85.61 + * @author Lee Boynton
85.62 + * @since JDK1.0
85.63 + */
85.64 +public interface Enumeration<E> {
85.65 + /**
85.66 + * Tests if this enumeration contains more elements.
85.67 + *
85.68 + * @return <code>true</code> if and only if this enumeration object
85.69 + * contains at least one more element to provide;
85.70 + * <code>false</code> otherwise.
85.71 + */
85.72 + boolean hasMoreElements();
85.73 +
85.74 + /**
85.75 + * Returns the next element of this enumeration if this enumeration
85.76 + * object has at least one more element to provide.
85.77 + *
85.78 + * @return the next element of this enumeration.
85.79 + * @exception NoSuchElementException if no more elements exist.
85.80 + */
85.81 + E nextElement();
85.82 +}
86.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
86.2 +++ b/emul/src/main/java/java/util/NoSuchElementException.java Wed Jan 23 20:16:48 2013 +0100
86.3 @@ -0,0 +1,60 @@
86.4 +/*
86.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
86.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
86.7 + *
86.8 + * This code is free software; you can redistribute it and/or modify it
86.9 + * under the terms of the GNU General Public License version 2 only, as
86.10 + * published by the Free Software Foundation. Oracle designates this
86.11 + * particular file as subject to the "Classpath" exception as provided
86.12 + * by Oracle in the LICENSE file that accompanied this code.
86.13 + *
86.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
86.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
86.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
86.17 + * version 2 for more details (a copy is included in the LICENSE file that
86.18 + * accompanied this code).
86.19 + *
86.20 + * You should have received a copy of the GNU General Public License version
86.21 + * 2 along with this work; if not, write to the Free Software Foundation,
86.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
86.23 + *
86.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86.25 + * or visit www.oracle.com if you need additional information or have any
86.26 + * questions.
86.27 + */
86.28 +
86.29 +package java.util;
86.30 +
86.31 +/**
86.32 + * Thrown by the <code>nextElement</code> method of an
86.33 + * <code>Enumeration</code> to indicate that there are no more
86.34 + * elements in the enumeration.
86.35 + *
86.36 + * @author unascribed
86.37 + * @see java.util.Enumeration
86.38 + * @see java.util.Enumeration#nextElement()
86.39 + * @since JDK1.0
86.40 + */
86.41 +public
86.42 +class NoSuchElementException extends RuntimeException {
86.43 + private static final long serialVersionUID = 6769829250639411880L;
86.44 +
86.45 + /**
86.46 + * Constructs a <code>NoSuchElementException</code> with <tt>null</tt>
86.47 + * as its error message string.
86.48 + */
86.49 + public NoSuchElementException() {
86.50 + super();
86.51 + }
86.52 +
86.53 + /**
86.54 + * Constructs a <code>NoSuchElementException</code>, saving a reference
86.55 + * to the error message string <tt>s</tt> for later retrieval by the
86.56 + * <tt>getMessage</tt> method.
86.57 + *
86.58 + * @param s the detail message.
86.59 + */
86.60 + public NoSuchElementException(String s) {
86.61 + super(s);
86.62 + }
86.63 +}
87.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
87.2 +++ b/emul/src/main/java/org/apidesign/bck2brwsr/emul/AnnotationImpl.java Wed Jan 23 20:16:48 2013 +0100
87.3 @@ -0,0 +1,81 @@
87.4 +/**
87.5 + * Back 2 Browser Bytecode Translator
87.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
87.7 + *
87.8 + * This program is free software: you can redistribute it and/or modify
87.9 + * it under the terms of the GNU General Public License as published by
87.10 + * the Free Software Foundation, version 2 of the License.
87.11 + *
87.12 + * This program is distributed in the hope that it will be useful,
87.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
87.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
87.15 + * GNU General Public License for more details.
87.16 + *
87.17 + * You should have received a copy of the GNU General Public License
87.18 + * along with this program. Look for COPYING file in the top folder.
87.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
87.20 + */
87.21 +package org.apidesign.bck2brwsr.emul;
87.22 +
87.23 +import java.lang.annotation.Annotation;
87.24 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
87.25 +
87.26 +/**
87.27 + *
87.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
87.29 + */
87.30 +public final class AnnotationImpl implements Annotation {
87.31 + public Class<? extends Annotation> annotationType() {
87.32 + return getClass();
87.33 + }
87.34 +
87.35 + @JavaScriptBody(args = { "a", "n", "values" }, body = ""
87.36 + + "function f(v, p) {\n"
87.37 + + " var val = v;\n"
87.38 + + " var prop = p;\n"
87.39 + + " return function() {\n"
87.40 + + " return val[prop];\n"
87.41 + + " };\n"
87.42 + + "}\n"
87.43 + + "var props = Object.getOwnPropertyNames(values);\n"
87.44 + + "for (var i = 0; i < props.length; i++) {\n"
87.45 + + " var p = props[i];\n"
87.46 + + " a[p] = new f(values, p);\n"
87.47 + + "}\n"
87.48 + + "a['$instOf_' + n] = true;\n"
87.49 + + "return a;"
87.50 + )
87.51 + private static <T extends Annotation> T create(AnnotationImpl a, String n, Object values) {
87.52 + return null;
87.53 + }
87.54 + public static <T extends Annotation> T create(Class<T> annoClass, Object values) {
87.55 + return create(new AnnotationImpl(), annoClass.getName().replace('.', '_'), values);
87.56 + }
87.57 +
87.58 + public static Annotation[] create(Object anno) {
87.59 + String[] names = findNames(anno);
87.60 + Annotation[] ret = new Annotation[names.length];
87.61 + for (int i = 0; i < names.length; i++) {
87.62 + String n = names[i].substring(1, names[i].length() - 1).replace('/', '_');
87.63 + ret[i] = create(new AnnotationImpl(), n, findData(anno, names[i]));
87.64 + }
87.65 + return ret;
87.66 + }
87.67 + @JavaScriptBody(args = "anno", body =
87.68 + "var arr = new Array();"
87.69 + + "var props = Object.getOwnPropertyNames(anno);\n"
87.70 + + "for (var i = 0; i < props.length; i++) {\n"
87.71 + + " var p = props[i];\n"
87.72 + + " arr.push(p);"
87.73 + + "}"
87.74 + + "return arr;"
87.75 + )
87.76 + private static String[] findNames(Object anno) {
87.77 + throw new UnsupportedOperationException();
87.78 + }
87.79 +
87.80 + @JavaScriptBody(args={ "anno", "p"}, body="return anno[p];")
87.81 + private static Object findData(Object anno, String p) {
87.82 + throw new UnsupportedOperationException();
87.83 + }
87.84 +}
88.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
88.2 +++ b/emul/src/main/java/org/apidesign/bck2brwsr/emul/MethodImpl.java Wed Jan 23 20:16:48 2013 +0100
88.3 @@ -0,0 +1,164 @@
88.4 +/*
88.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
88.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
88.7 + *
88.8 + * This code is free software; you can redistribute it and/or modify it
88.9 + * under the terms of the GNU General Public License version 2 only, as
88.10 + * published by the Free Software Foundation. Oracle designates this
88.11 + * particular file as subject to the "Classpath" exception as provided
88.12 + * by Oracle in the LICENSE file that accompanied this code.
88.13 + *
88.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
88.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
88.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
88.17 + * version 2 for more details (a copy is included in the LICENSE file that
88.18 + * accompanied this code).
88.19 + *
88.20 + * You should have received a copy of the GNU General Public License version
88.21 + * 2 along with this work; if not, write to the Free Software Foundation,
88.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
88.23 + *
88.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
88.25 + * or visit www.oracle.com if you need additional information or have any
88.26 + * questions.
88.27 + */
88.28 +package org.apidesign.bck2brwsr.emul;
88.29 +
88.30 +import java.lang.reflect.Method;
88.31 +import java.util.Enumeration;
88.32 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
88.33 +
88.34 +/** Utilities to work on methods.
88.35 + *
88.36 + * @author Jaroslav Tulach <jtulach@netbeans.org>
88.37 + */
88.38 +public abstract class MethodImpl {
88.39 + public static MethodImpl INSTANCE;
88.40 + static {
88.41 + try {
88.42 + Class.forName(Method.class.getName());
88.43 + } catch (ClassNotFoundException ex) {
88.44 + throw new IllegalStateException(ex);
88.45 + }
88.46 + }
88.47 +
88.48 + protected abstract Method create(Class<?> declaringClass, String name, Object data, String sig);
88.49 +
88.50 +
88.51 + //
88.52 + // bck2brwsr implementation
88.53 + //
88.54 +
88.55 + @JavaScriptBody(args = {"clazz", "prefix"},
88.56 + body = ""
88.57 + + "var c = clazz.cnstr.prototype;"
88.58 + + "var arr = new Array();\n"
88.59 + + "for (m in c) {\n"
88.60 + + " if (m.indexOf(prefix) === 0) {\n"
88.61 + + " arr.push(m);\n"
88.62 + + " arr.push(c[m]);\n"
88.63 + + " }"
88.64 + + "}\n"
88.65 + + "return arr;")
88.66 + private static native Object[] findMethodData(
88.67 + Class<?> clazz, String prefix);
88.68 +
88.69 + public static Method findMethod(
88.70 + Class<?> clazz, String name, Class<?>... parameterTypes) {
88.71 + Object[] data = findMethodData(clazz, name + "__");
88.72 + BIG: for (int i = 0; i < data.length; i += 2) {
88.73 + String sig = ((String) data[0]).substring(name.length() + 2);
88.74 + Method tmp = INSTANCE.create(clazz, name, data[1], sig);
88.75 + Class<?>[] tmpParms = tmp.getParameterTypes();
88.76 + if (parameterTypes.length != tmpParms.length) {
88.77 + continue;
88.78 + }
88.79 + for (int j = 0; j < tmpParms.length; j++) {
88.80 + if (!parameterTypes[j].equals(tmpParms[j])) {
88.81 + continue BIG;
88.82 + }
88.83 + }
88.84 + return tmp;
88.85 + }
88.86 + return null;
88.87 + }
88.88 +
88.89 + public static Method[] findMethods(Class<?> clazz, int mask) {
88.90 + Object[] namesAndData = findMethodData(clazz, "");
88.91 + int cnt = 0;
88.92 + for (int i = 0; i < namesAndData.length; i += 2) {
88.93 + String sig = (String) namesAndData[i];
88.94 + Object data = namesAndData[i + 1];
88.95 + int middle = sig.indexOf("__");
88.96 + if (middle == -1) {
88.97 + continue;
88.98 + }
88.99 + String name = sig.substring(0, middle);
88.100 + sig = sig.substring(middle + 2);
88.101 + final Method m = INSTANCE.create(clazz, name, data, sig);
88.102 + if ((m.getModifiers() & mask) == 0) {
88.103 + continue;
88.104 + }
88.105 + namesAndData[cnt++] = m;
88.106 + }
88.107 + Method[] arr = new Method[cnt];
88.108 + for (int i = 0; i < cnt; i++) {
88.109 + arr[i] = (Method) namesAndData[i];
88.110 + }
88.111 + return arr;
88.112 + }
88.113 +
88.114 + public static int signatureElements(String sig) {
88.115 + Enumeration<Class> en = signatureParser(sig);
88.116 + int cnt = 0;
88.117 + while (en.hasMoreElements()) {
88.118 + en.nextElement();
88.119 + cnt++;
88.120 + }
88.121 + return cnt;
88.122 + }
88.123 +
88.124 + public static Enumeration<Class> signatureParser(final String sig) {
88.125 + class E implements Enumeration<Class> {
88.126 + int pos;
88.127 +
88.128 + public boolean hasMoreElements() {
88.129 + return pos < sig.length();
88.130 + }
88.131 +
88.132 + public Class nextElement() {
88.133 + switch (sig.charAt(pos++)) {
88.134 + case 'I':
88.135 + return Integer.TYPE;
88.136 + case 'J':
88.137 + return Long.TYPE;
88.138 + case 'D':
88.139 + return Double.TYPE;
88.140 + case 'F':
88.141 + return Float.TYPE;
88.142 + case 'B':
88.143 + return Byte.TYPE;
88.144 + case 'Z':
88.145 + return Boolean.TYPE;
88.146 + case 'S':
88.147 + return Short.TYPE;
88.148 + case 'V':
88.149 + return Void.TYPE;
88.150 + case 'C':
88.151 + return Character.TYPE;
88.152 + case 'L':
88.153 + try {
88.154 + int up = sig.indexOf("_2");
88.155 + String type = sig.substring(1, up);
88.156 + pos = up + 2;
88.157 + return Class.forName(type);
88.158 + } catch (ClassNotFoundException ex) {
88.159 + // should not happen
88.160 + }
88.161 + }
88.162 + throw new UnsupportedOperationException(sig + " at " + pos);
88.163 + }
88.164 + }
88.165 + return new E();
88.166 + }
88.167 +}
89.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
89.2 +++ b/emul/src/main/resources/org/apidesign/vm4brwsr/emul/java_lang_Number.js Wed Jan 23 20:16:48 2013 +0100
89.3 @@ -0,0 +1,9 @@
89.4 +// empty line needed here
89.5 +Number.prototype.add32 = function(x) { return (this + x) | 0; };
89.6 +Number.prototype.sub32 = function(x) { return (this - x) | 0; };
89.7 +Number.prototype.mul32 = function(x) {
89.8 + return (((this * (x >> 16)) << 16) + this * (x & 0xFFFF)) | 0;
89.9 +};
89.10 +
89.11 +Number.prototype.toInt8 = function() { return (this << 24) >> 24; };
89.12 +Number.prototype.toInt16 = function() { return (this << 16) >> 16; };
89.13 \ No newline at end of file
90.1 --- a/emul/src/main/resources/org/apidesign/vm4brwsr/emul/java_lang_String.js Thu Oct 11 06:15:22 2012 -0700
90.2 +++ b/emul/src/main/resources/org/apidesign/vm4brwsr/emul/java_lang_String.js Wed Jan 23 20:16:48 2013 +0100
90.3 @@ -1,2658 +1,26 @@
90.4 -/* */
90.5 +// initialize methods on arrays and String constants
90.6 +vm.java_lang_reflect_Array(false);
90.7 +vm.java_lang_String(false);
90.8
90.9 -
90.10 -function java_lang_String_consVAC(arg0,arg1) {
90.11 - arg0.r = arg1.join("");
90.12 -}
90.13 -
90.14 -function java_lang_String_consVACII(self, charArr, off, cnt) {
90.15 - self.r = charArr.slice(off, off + cnt).join("");
90.16 -}
90.17 -
90.18 -function java_lang_String_charAtCI(arg0,arg1) {
90.19 - return arg0.toString().charAt(arg1);
90.20 -}
90.21 -function java_lang_String_lengthI(arg0) {
90.22 - return arg0.toString().length;
90.23 -}
90.24 -function java_lang_String_isEmptyZ(arg0) {
90.25 - return arg0.toString().length === 0;
90.26 -}
90.27 -
90.28 -/*
90.29 -function java_lang_String_codePointAtII(arg0,arg1) {
90.30 - var arg2;
90.31 -;
90.32 - var stack = new Array(4);
90.33 - var gt = 0;
90.34 - for(;;) switch(gt) {
90.35 - case 0: stack.push(arg1); // 27
90.36 - case 1: if (stack.pop() < 0) { gt = 12; continue; } // 155 0 11
90.37 - case 4: stack.push(arg1); // 27
90.38 - case 5: stack.push(arg0); // 42
90.39 - case 6: stack.push(stack.pop().count); // 180 1 97
90.40 - case 9: if (stack.pop() > stack.pop()) { gt = 21; continue; } // 161 0 12
90.41 - case 12: stack.push(new java_lang_StringIndexOutOfBoundsException); // 187 0 206
90.42 - case 15: stack.push(stack[stack.length - 1]); // 89
90.43 - case 16: stack.push(arg1); // 27
90.44 - case 17: { var v0 = stack.pop(); java_lang_StringIndexOutOfBoundsException_consVI(stack.pop(), v0); } // 183 1 169
90.45 - case 20: // 191
90.46 - case 21: stack.push(arg0); // 42
90.47 - case 22: stack.push(stack.pop().value); // 180 1 100
90.48 - case 25: stack.push(arg0); // 42
90.49 - case 26: stack.push(stack.pop().offset); // 180 1 99
90.50 - case 29: stack.push(arg1); // 27
90.51 - case 30: stack.push(stack.pop() + stack.pop()); // 96
90.52 - case 31: stack.push(arg0); // 42
90.53 - case 32: stack.push(stack.pop().offset); // 180 1 99
90.54 - case 35: stack.push(arg0); // 42
90.55 - case 36: stack.push(stack.pop().count); // 180 1 97
90.56 - case 39: stack.push(stack.pop() + stack.pop()); // 96
90.57 - case 40: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_Character_codePointAtImplAIACAIAI(v0, v1, v2)); } // 184 1 113
90.58 - case 43: return stack.pop(); // 172
90.59 +Array.prototype.at = function(indx, value) {
90.60 + if (indx < 0 || indx > this.length) {
90.61 + var e = vm.java_lang_ArrayIndexOutOfBoundsException(true);
90.62 + e.constructor.cons__VLjava_lang_String_2.call(e, indx.toString());
90.63 + throw e;
90.64 }
90.65 -}
90.66 -function java_lang_String_codePointBeforeII(arg0,arg1) {
90.67 - var arg2;
90.68 - var arg3;
90.69 -;
90.70 - var stack = new Array(3);
90.71 - var gt = 0;
90.72 - for(;;) switch(gt) {
90.73 - case 0: stack.push(arg1); // 27
90.74 - case 1: stack.push(1); // 4
90.75 - case 2: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.76 - case 3: arg2 = stack.pop(); // 61
90.77 - case 4: stack.push(arg2); // 28
90.78 - case 5: if (stack.pop() < 0) { gt = 16; continue; } // 155 0 11
90.79 - case 8: stack.push(arg2); // 28
90.80 - case 9: stack.push(arg0); // 42
90.81 - case 10: stack.push(stack.pop().count); // 180 1 97
90.82 - case 13: if (stack.pop() > stack.pop()) { gt = 25; continue; } // 161 0 12
90.83 - case 16: stack.push(new java_lang_StringIndexOutOfBoundsException); // 187 0 206
90.84 - case 19: stack.push(stack[stack.length - 1]); // 89
90.85 - case 20: stack.push(arg1); // 27
90.86 - case 21: { var v0 = stack.pop(); java_lang_StringIndexOutOfBoundsException_consVI(stack.pop(), v0); } // 183 1 169
90.87 - case 24: // 191
90.88 - case 25: stack.push(arg0); // 42
90.89 - case 26: stack.push(stack.pop().value); // 180 1 100
90.90 - case 29: stack.push(arg0); // 42
90.91 - case 30: stack.push(stack.pop().offset); // 180 1 99
90.92 - case 33: stack.push(arg1); // 27
90.93 - case 34: stack.push(stack.pop() + stack.pop()); // 96
90.94 - case 35: stack.push(arg0); // 42
90.95 - case 36: stack.push(stack.pop().offset); // 180 1 99
90.96 - case 39: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_Character_codePointBeforeImplAIACAIAI(v0, v1, v2)); } // 184 1 114
90.97 - case 42: return stack.pop(); // 172
90.98 + if (arguments.length === 2) {
90.99 + this[indx] = value;
90.100 }
90.101 -}
90.102 -function java_lang_String_codePointCountIII(arg0,arg1,arg2) {
90.103 - var arg3;
90.104 -;
90.105 - var stack = new Array(4);
90.106 - var gt = 0;
90.107 - for(;;) switch(gt) {
90.108 - case 0: stack.push(arg1); // 27
90.109 - case 1: if (stack.pop() < 0) { gt = 17; continue; } // 155 0 16
90.110 - case 4: stack.push(arg2); // 28
90.111 - case 5: stack.push(arg0); // 42
90.112 - case 6: stack.push(stack.pop().count); // 180 1 97
90.113 - case 9: if (stack.pop() < stack.pop()) { gt = 17; continue; } // 163 0 8
90.114 - case 12: stack.push(arg1); // 27
90.115 - case 13: stack.push(arg2); // 28
90.116 - case 14: if (stack.pop() >= stack.pop()) { gt = 25; continue; } // 164 0 11
90.117 - case 17: stack.push(new java_lang_IndexOutOfBoundsException); // 187 0 194
90.118 - case 20: stack.push(stack[stack.length - 1]); // 89
90.119 - case 21: { java_lang_IndexOutOfBoundsException_consV(stack.pop()); } // 183 1 124
90.120 - case 24: // 191
90.121 - case 25: stack.push(arg0); // 42
90.122 - case 26: stack.push(stack.pop().value); // 180 1 100
90.123 - case 29: stack.push(arg0); // 42
90.124 - case 30: stack.push(stack.pop().offset); // 180 1 99
90.125 - case 33: stack.push(arg1); // 27
90.126 - case 34: stack.push(stack.pop() + stack.pop()); // 96
90.127 - case 35: stack.push(arg2); // 28
90.128 - case 36: stack.push(arg1); // 27
90.129 - case 37: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.130 - case 38: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_Character_codePointCountImplAIACAIAI(v0, v1, v2)); } // 184 1 115
90.131 - case 41: return stack.pop(); // 172
90.132 + return this[indx];
90.133 +};
90.134 +Array.prototype.getClass__Ljava_lang_Class_2 = function() {
90.135 + return vm.java_lang_Class(false).defineArray__Ljava_lang_Class_2Ljava_lang_String_2(this.jvmName);
90.136 +};
90.137 +Array.prototype.clone__Ljava_lang_Object_2 = function() {
90.138 + var s = this.length;
90.139 + var ret = new Array(s);
90.140 + for (var i = 0; i < s; i++) {
90.141 + ret[i] = this[i];
90.142 }
90.143 -}
90.144 -function java_lang_String_offsetByCodePointsIII(arg0,arg1,arg2) {
90.145 - var arg3;
90.146 -;
90.147 - var stack = new Array(5);
90.148 - var gt = 0;
90.149 - for(;;) switch(gt) {
90.150 - case 0: stack.push(arg1); // 27
90.151 - case 1: if (stack.pop() < 0) { gt = 12; continue; } // 155 0 11
90.152 - case 4: stack.push(arg1); // 27
90.153 - case 5: stack.push(arg0); // 42
90.154 - case 6: stack.push(stack.pop().count); // 180 1 97
90.155 - case 9: if (stack.pop() >= stack.pop()) { gt = 20; continue; } // 164 0 11
90.156 - case 12: stack.push(new java_lang_IndexOutOfBoundsException); // 187 0 194
90.157 - case 15: stack.push(stack[stack.length - 1]); // 89
90.158 - case 16: { java_lang_IndexOutOfBoundsException_consV(stack.pop()); } // 183 1 124
90.159 - case 19: // 191
90.160 - case 20: stack.push(arg0); // 42
90.161 - case 21: stack.push(stack.pop().value); // 180 1 100
90.162 - case 24: stack.push(arg0); // 42
90.163 - case 25: stack.push(stack.pop().offset); // 180 1 99
90.164 - case 28: stack.push(arg0); // 42
90.165 - case 29: stack.push(stack.pop().count); // 180 1 97
90.166 - case 32: stack.push(arg0); // 42
90.167 - case 33: stack.push(stack.pop().offset); // 180 1 99
90.168 - case 36: stack.push(arg1); // 27
90.169 - case 37: stack.push(stack.pop() + stack.pop()); // 96
90.170 - case 38: stack.push(arg2); // 28
90.171 - case 39: { var v4 = stack.pop(); var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_Character_offsetByCodePointsImplAIACAIAIAIAI(v0, v1, v2, v3, v4)); } // 184 1 116
90.172 - case 42: stack.push(arg0); // 42
90.173 - case 43: stack.push(stack.pop().offset); // 180 1 99
90.174 - case 46: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.175 - case 47: return stack.pop(); // 172
90.176 - }
90.177 -}
90.178 -*/
90.179 -
90.180 -// public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
90.181 -function java_lang_String_getCharsVIIACAI(arg0,arg1,arg2,arg3,arg4) {
90.182 - var s = arg0.toString();
90.183 - while (arg1 < arg2) {
90.184 - arg3[arg4++] = s[arg1++];
90.185 - }
90.186 -}
90.187 -
90.188 -/*
90.189 -function java_lang_String_getBytesVIIABI(arg0,arg1,arg2,arg3,arg4) {
90.190 - var arg5;
90.191 - var arg6;
90.192 - var arg7;
90.193 - var arg8;
90.194 - var arg9;
90.195 -;
90.196 - var stack = new Array(4);
90.197 - var gt = 0;
90.198 - for(;;) switch(gt) {
90.199 - case 0: stack.push(arg1); // 27
90.200 - case 1: if (stack.pop() >= 0) { gt = 13; continue; } // 156 0 12
90.201 - case 4: stack.push(new java_lang_StringIndexOutOfBoundsException); // 187 0 206
90.202 - case 7: stack.push(stack[stack.length - 1]); // 89
90.203 - case 8: stack.push(arg1); // 27
90.204 - case 9: { var v0 = stack.pop(); java_lang_StringIndexOutOfBoundsException_consVI(stack.pop(), v0); } // 183 1 169
90.205 - case 12: // 191
90.206 - case 13: stack.push(arg2); // 28
90.207 - case 14: stack.push(arg0); // 42
90.208 - case 15: stack.push(stack.pop().count); // 180 1 97
90.209 - case 18: if (stack.pop() >= stack.pop()) { gt = 30; continue; } // 164 0 12
90.210 - case 21: stack.push(new java_lang_StringIndexOutOfBoundsException); // 187 0 206
90.211 - case 24: stack.push(stack[stack.length - 1]); // 89
90.212 - case 25: stack.push(arg2); // 28
90.213 - case 26: { var v0 = stack.pop(); java_lang_StringIndexOutOfBoundsException_consVI(stack.pop(), v0); } // 183 1 169
90.214 - case 29: // 191
90.215 - case 30: stack.push(arg1); // 27
90.216 - case 31: stack.push(arg2); // 28
90.217 - case 32: if (stack.pop() >= stack.pop()) { gt = 46; continue; } // 164 0 14
90.218 - case 35: stack.push(new java_lang_StringIndexOutOfBoundsException); // 187 0 206
90.219 - case 38: stack.push(stack[stack.length - 1]); // 89
90.220 - case 39: stack.push(arg2); // 28
90.221 - case 40: stack.push(arg1); // 27
90.222 - case 41: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.223 - case 42: { var v0 = stack.pop(); java_lang_StringIndexOutOfBoundsException_consVI(stack.pop(), v0); } // 183 1 169
90.224 - case 45: // 191
90.225 - case 46: stack.push(arg4); // 21 4
90.226 - case 48: arg5 = stack.pop() // 54 5
90.227 - case 50: stack.push(arg0); // 42
90.228 - case 51: stack.push(stack.pop().offset); // 180 1 99
90.229 - case 54: stack.push(arg2); // 28
90.230 - case 55: stack.push(stack.pop() + stack.pop()); // 96
90.231 - case 56: arg6 = stack.pop() // 54 6
90.232 - case 58: stack.push(arg0); // 42
90.233 - case 59: stack.push(stack.pop().offset); // 180 1 99
90.234 - case 62: stack.push(arg1); // 27
90.235 - case 63: stack.push(stack.pop() + stack.pop()); // 96
90.236 - case 64: arg7 = stack.pop() // 54 7
90.237 - case 66: stack.push(arg0); // 42
90.238 - case 67: stack.push(stack.pop().value); // 180 1 100
90.239 - case 70: arg8 = stack.pop() // 58 8
90.240 - case 72: stack.push(arg7); // 21 7
90.241 - case 74: stack.push(arg6); // 21 6
90.242 - case 76: if (stack.pop() <= stack.pop()) { gt = 98; continue; } // 162 0 22
90.243 - case 79: stack.push(arg3); // 45
90.244 - case 80: stack.push(arg5); // 21 5
90.245 - case 82: arg5++; // 132 5 1
90.246 - case 85: stack.push(arg8); // 25 8
90.247 - case 87: stack.push(arg7); // 21 7
90.248 - case 89: arg7++; // 132 7 1
90.249 - case 92: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.250 - case 93: // number conversion // 145
90.251 - case 94: { var value = stack.pop(); var indx = stack.pop(); stack.pop()[indx] = value; } // 84
90.252 - case 95: gt = 72; continue; // 167 255 233
90.253 - case 98: return; // 177
90.254 - }
90.255 -}
90.256 -function java_lang_String_getBytesABLjava_lang_String(arg0,arg1) {
90.257 - var arg2;
90.258 -;
90.259 - var stack = new Array(4);
90.260 - var gt = 0;
90.261 - for(;;) switch(gt) {
90.262 - case 0: stack.push(arg1); // 43
90.263 - case 1: if (stack.pop()) { gt = 12; continue; } // 199 0 11
90.264 - case 4: stack.push(new java_lang_NullPointerException); // 187 0 198
90.265 - case 7: stack.push(stack[stack.length - 1]); // 89
90.266 - case 8: { java_lang_NullPointerException_consV(stack.pop()); } // 183 1 128
90.267 - case 11: // 191
90.268 - case 12: stack.push(arg1); // 43
90.269 - case 13: stack.push(arg0); // 42
90.270 - case 14: stack.push(stack.pop().value); // 180 1 100
90.271 - case 17: stack.push(arg0); // 42
90.272 - case 18: stack.push(stack.pop().offset); // 180 1 99
90.273 - case 21: stack.push(arg0); // 42
90.274 - case 22: stack.push(stack.pop().count); // 180 1 97
90.275 - case 25: { var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_StringCoding_encodeABLjava_lang_StringACAIAI(v0, v1, v2, v3)); } // 184 1 166
90.276 - case 28: return stack.pop(); // 176
90.277 - }
90.278 -}
90.279 -function java_lang_String_getBytesABLjava_nio_charset_Charset(arg0,arg1) {
90.280 - var arg2;
90.281 -;
90.282 - var stack = new Array(4);
90.283 - var gt = 0;
90.284 - for(;;) switch(gt) {
90.285 - case 0: stack.push(arg1); // 43
90.286 - case 1: if (stack.pop()) { gt = 12; continue; } // 199 0 11
90.287 - case 4: stack.push(new java_lang_NullPointerException); // 187 0 198
90.288 - case 7: stack.push(stack[stack.length - 1]); // 89
90.289 - case 8: { java_lang_NullPointerException_consV(stack.pop()); } // 183 1 128
90.290 - case 11: // 191
90.291 - case 12: stack.push(arg1); // 43
90.292 - case 13: stack.push(arg0); // 42
90.293 - case 14: stack.push(stack.pop().value); // 180 1 100
90.294 - case 17: stack.push(arg0); // 42
90.295 - case 18: stack.push(stack.pop().offset); // 180 1 99
90.296 - case 21: stack.push(arg0); // 42
90.297 - case 22: stack.push(stack.pop().count); // 180 1 97
90.298 - case 25: { var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_StringCoding_encodeABLjava_nio_charset_CharsetACAIAI(v0, v1, v2, v3)); } // 184 1 168
90.299 - case 28: return stack.pop(); // 176
90.300 - }
90.301 -}
90.302 -function java_lang_String_getBytesAB(arg0) {
90.303 - var arg1;
90.304 -;
90.305 - var stack = new Array(3);
90.306 - var gt = 0;
90.307 - for(;;) switch(gt) {
90.308 - case 0: stack.push(arg0); // 42
90.309 - case 1: stack.push(stack.pop().value); // 180 1 100
90.310 - case 4: stack.push(arg0); // 42
90.311 - case 5: stack.push(stack.pop().offset); // 180 1 99
90.312 - case 8: stack.push(arg0); // 42
90.313 - case 9: stack.push(stack.pop().count); // 180 1 97
90.314 - case 12: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_StringCoding_encodeABACAIAI(v0, v1, v2)); } // 184 1 164
90.315 - case 15: return stack.pop(); // 176
90.316 - }
90.317 -}
90.318 -function java_lang_String_equalsZLjava_lang_Object(arg0,arg1) {
90.319 - var arg2;
90.320 - var arg3;
90.321 - var arg4;
90.322 - var arg5;
90.323 - var arg6;
90.324 - var arg7;
90.325 - var arg8;
90.326 -;
90.327 - var stack = new Array(3);
90.328 - var gt = 0;
90.329 - for(;;) switch(gt) {
90.330 - case 0: stack.push(arg0); // 42
90.331 - case 1: stack.push(arg1); // 43
90.332 - case 2: // 166
90.333 - case 3: // 0
90.334 - case 4: stack.push(2); // 5
90.335 - case 5: stack.push(1); // 4
90.336 - case 6: return stack.pop(); // 172
90.337 - case 7: stack.push(arg1); // 43
90.338 - case 8: stack.push(stack.pop().$instOf_java_lang_String ? 1 : 0); // 193 0 200
90.339 - case 11: if (stack.pop() == 0) { gt = 86; continue; } // 153 0 75
90.340 - case 14: stack.push(arg1); // 43
90.341 - case 15: if(stack[stack.length - 1].$instOf_java_lang_String != 1) throw {}; // 192 0 200
90.342 - case 18: arg2 = stack.pop(); // 77
90.343 - case 19: stack.push(arg0); // 42
90.344 - case 20: stack.push(stack.pop().count); // 180 1 97
90.345 - case 23: arg3 = stack.pop(); // 62
90.346 - case 24: stack.push(arg3); // 29
90.347 - case 25: stack.push(arg2); // 44
90.348 - case 26: stack.push(stack.pop().count); // 180 1 97
90.349 - case 29: if (stack.pop() != stack.pop()) { gt = 86; continue; } // 160 0 57
90.350 - case 32: stack.push(arg0); // 42
90.351 - case 33: stack.push(stack.pop().value); // 180 1 100
90.352 - case 36: arg4 = stack.pop() // 58 4
90.353 - case 38: stack.push(arg2); // 44
90.354 - case 39: stack.push(stack.pop().value); // 180 1 100
90.355 - case 42: arg5 = stack.pop() // 58 5
90.356 - case 44: stack.push(arg0); // 42
90.357 - case 45: stack.push(stack.pop().offset); // 180 1 99
90.358 - case 48: arg6 = stack.pop() // 54 6
90.359 - case 50: stack.push(arg2); // 44
90.360 - case 51: stack.push(stack.pop().offset); // 180 1 99
90.361 - case 54: arg7 = stack.pop() // 54 7
90.362 - case 56: stack.push(arg3); // 29
90.363 - case 57: arg3 += 255; // 132 3 255
90.364 - case 60: if (stack.pop() == 0) { gt = 84; continue; } // 153 0 24
90.365 - case 63: stack.push(arg4); // 25 4
90.366 - case 65: stack.push(arg6); // 21 6
90.367 - case 67: arg6++; // 132 6 1
90.368 - case 70: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.369 - case 71: stack.push(arg5); // 25 5
90.370 - case 73: stack.push(arg7); // 21 7
90.371 - case 75: arg7++; // 132 7 1
90.372 - case 78: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.373 - case 79: if (stack.pop() == stack.pop()) { gt = 56; continue; } // 159 255 233
90.374 - case 82: stack.push(0); // 3
90.375 - case 83: return stack.pop(); // 172
90.376 - case 84: stack.push(1); // 4
90.377 - case 85: return stack.pop(); // 172
90.378 - case 86: stack.push(0); // 3
90.379 - case 87: return stack.pop(); // 172
90.380 - }
90.381 -}
90.382 -function java_lang_String_contentEqualsZLjava_lang_StringBuffer(arg0,arg1) {
90.383 - var arg2;
90.384 - var arg3;
90.385 - var arg4;
90.386 -;
90.387 - var stack = new Array(2);
90.388 - var gt = 0;
90.389 - for(;;) switch(gt) {
90.390 - case 0: stack.push(arg1); // 43
90.391 - case 1: stack.push(stack[stack.length - 1]); // 89
90.392 - case 2: arg2 = stack.pop(); // 77
90.393 - case 3: // 194
90.394 - case 4: stack.push(arg0); // 42
90.395 - case 5: stack.push(arg1); // 43
90.396 - case 6: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.contentEqualsZLjava_lang_CharSequence(self, v0)); } // 182 1 146
90.397 - case 9: stack.push(arg2); // 44
90.398 - case 10: // 195
90.399 - case 11: return stack.pop(); // 172
90.400 - case 12: arg3 = stack.pop(); // 78
90.401 - case 13: stack.push(arg2); // 44
90.402 - case 14: // 195
90.403 - case 15: stack.push(arg3); // 45
90.404 - case 16: // 191
90.405 - }
90.406 -}
90.407 -function java_lang_String_contentEqualsZLjava_lang_CharSequence(arg0,arg1) {
90.408 - var arg2;
90.409 - var arg3;
90.410 - var arg4;
90.411 - var arg5;
90.412 - var arg6;
90.413 - var arg7;
90.414 -;
90.415 - var stack = new Array(3);
90.416 - var gt = 0;
90.417 - for(;;) switch(gt) {
90.418 - case 0: stack.push(arg0); // 42
90.419 - case 1: stack.push(stack.pop().count); // 180 1 97
90.420 - case 4: stack.push(arg1); // 43
90.421 - case 5: { var self = stack.pop(); stack.push(self.lengthI(self)); } // 185 1 188
90.422 - case 8: // 1
90.423 - case 9: // 0
90.424 - case 10: if (stack.pop() == stack.pop()) { gt = 15; continue; } // 159 0 5
90.425 - case 13: stack.push(0); // 3
90.426 - case 14: return stack.pop(); // 172
90.427 - case 15: stack.push(arg1); // 43
90.428 - case 16: stack.push(stack.pop().$instOf_java_lang_AbstractStringBuilder ? 1 : 0); // 193 0 186
90.429 - case 19: if (stack.pop() == 0) { gt = 77; continue; } // 153 0 58
90.430 - case 22: stack.push(arg0); // 42
90.431 - case 23: stack.push(stack.pop().value); // 180 1 100
90.432 - case 26: arg2 = stack.pop(); // 77
90.433 - case 27: stack.push(arg1); // 43
90.434 - case 28: if(stack[stack.length - 1].$instOf_java_lang_AbstractStringBuilder != 1) throw {}; // 192 0 186
90.435 - case 31: { var self = stack.pop(); stack.push(self.getValueAC(self)); } // 182 1 103
90.436 - case 34: arg3 = stack.pop(); // 78
90.437 - case 35: stack.push(arg0); // 42
90.438 - case 36: stack.push(stack.pop().offset); // 180 1 99
90.439 - case 39: arg4 = stack.pop() // 54 4
90.440 - case 41: stack.push(0); // 3
90.441 - case 42: arg5 = stack.pop() // 54 5
90.442 - case 44: stack.push(arg0); // 42
90.443 - case 45: stack.push(stack.pop().count); // 180 1 97
90.444 - case 48: arg6 = stack.pop() // 54 6
90.445 - case 50: stack.push(arg6); // 21 6
90.446 - case 52: arg6 += 255; // 132 6 255
90.447 - case 55: if (stack.pop() == 0) { gt = 77; continue; } // 153 0 22
90.448 - case 58: stack.push(arg2); // 44
90.449 - case 59: stack.push(arg4); // 21 4
90.450 - case 61: arg4++; // 132 4 1
90.451 - case 64: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.452 - case 65: stack.push(arg3); // 45
90.453 - case 66: stack.push(arg5); // 21 5
90.454 - case 68: arg5++; // 132 5 1
90.455 - case 71: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.456 - case 72: if (stack.pop() == stack.pop()) { gt = 50; continue; } // 159 255 234
90.457 - case 75: stack.push(0); // 3
90.458 - case 76: return stack.pop(); // 172
90.459 - case 77: stack.push(arg1); // 43
90.460 - case 78: stack.push(arg0); // 42
90.461 - case 79: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.equalsZLjava_lang_Object(self, v0)); } // 182 1 131
90.462 - case 82: if (stack.pop() == 0) { gt = 87; continue; } // 153 0 5
90.463 - case 85: stack.push(1); // 4
90.464 - case 86: return stack.pop(); // 172
90.465 - case 87: stack.push(arg0); // 42
90.466 - case 88: stack.push(stack.pop().value); // 180 1 100
90.467 - case 91: arg2 = stack.pop(); // 77
90.468 - case 92: stack.push(arg0); // 42
90.469 - case 93: stack.push(stack.pop().offset); // 180 1 99
90.470 - case 96: arg3 = stack.pop(); // 62
90.471 - case 97: stack.push(0); // 3
90.472 - case 98: arg4 = stack.pop() // 54 4
90.473 - case 100: stack.push(arg0); // 42
90.474 - case 101: stack.push(stack.pop().count); // 180 1 97
90.475 - case 104: arg5 = stack.pop() // 54 5
90.476 - case 106: stack.push(arg5); // 21 5
90.477 - case 108: arg5 += 255; // 132 5 255
90.478 - case 111: if (stack.pop() == 0) { gt = 136; continue; } // 153 0 25
90.479 - case 114: stack.push(arg2); // 44
90.480 - case 115: stack.push(arg3); // 29
90.481 - case 116: arg3++; // 132 3 1
90.482 - case 119: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.483 - case 120: stack.push(arg1); // 43
90.484 - case 121: stack.push(arg4); // 21 4
90.485 - case 123: arg4++; // 132 4 1
90.486 - case 126: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.charAtCI(self, v0)); } // 185 1 189
90.487 - case 129: // 2
90.488 - case 130: // 0
90.489 - case 131: if (stack.pop() == stack.pop()) { gt = 106; continue; } // 159 255 231
90.490 - case 134: stack.push(0); // 3
90.491 - case 135: return stack.pop(); // 172
90.492 - case 136: stack.push(1); // 4
90.493 - case 137: return stack.pop(); // 172
90.494 - }
90.495 -}
90.496 -function java_lang_String_equalsIgnoreCaseZLjava_lang_String(arg0,arg1) {
90.497 - var arg2;
90.498 -;
90.499 - var stack = new Array(6);
90.500 - var gt = 0;
90.501 - for(;;) switch(gt) {
90.502 - case 0: stack.push(arg0); // 42
90.503 - case 1: stack.push(arg1); // 43
90.504 - case 2: // 166
90.505 - case 3: // 0
90.506 - case 4: stack.push(4); // 7
90.507 - case 5: stack.push(1); // 4
90.508 - case 6: gt = 44; continue; // 167 0 38
90.509 - case 9: stack.push(arg1); // 43
90.510 - case 10: if (!stack.pop()) { gt = 43; continue; } // 198 0 33
90.511 - case 13: stack.push(arg1); // 43
90.512 - case 14: stack.push(stack.pop().count); // 180 1 97
90.513 - case 17: stack.push(arg0); // 42
90.514 - case 18: stack.push(stack.pop().count); // 180 1 97
90.515 - case 21: if (stack.pop() != stack.pop()) { gt = 43; continue; } // 160 0 22
90.516 - case 24: stack.push(arg0); // 42
90.517 - case 25: stack.push(1); // 4
90.518 - case 26: stack.push(0); // 3
90.519 - case 27: stack.push(arg1); // 43
90.520 - case 28: stack.push(0); // 3
90.521 - case 29: stack.push(arg0); // 42
90.522 - case 30: stack.push(stack.pop().count); // 180 1 97
90.523 - case 33: { var v4 = stack.pop(); var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.regionMatchesZZILjava_lang_StringII(self, v0, v1, v2, v3, v4)); } // 182 1 153
90.524 - case 36: if (stack.pop() == 0) { gt = 43; continue; } // 153 0 7
90.525 - case 39: stack.push(1); // 4
90.526 - case 40: gt = 44; continue; // 167 0 4
90.527 - case 43: stack.push(0); // 3
90.528 - case 44: return stack.pop(); // 172
90.529 - }
90.530 -}
90.531 -function java_lang_String_compareToILjava_lang_String(arg0,arg1) {
90.532 - var arg2;
90.533 - var arg3;
90.534 - var arg4;
90.535 - var arg5;
90.536 - var arg6;
90.537 - var arg7;
90.538 - var arg8;
90.539 - var arg9;
90.540 - var arg10;
90.541 - var arg11;
90.542 - var arg12;
90.543 - var arg13;
90.544 -;
90.545 - var stack = new Array(2);
90.546 - var gt = 0;
90.547 - for(;;) switch(gt) {
90.548 - case 0: stack.push(arg0); // 42
90.549 - case 1: stack.push(stack.pop().count); // 180 1 97
90.550 - case 4: arg2 = stack.pop(); // 61
90.551 - case 5: stack.push(arg1); // 43
90.552 - case 6: stack.push(stack.pop().count); // 180 1 97
90.553 - case 9: arg3 = stack.pop(); // 62
90.554 - case 10: stack.push(arg2); // 28
90.555 - case 11: stack.push(arg3); // 29
90.556 - case 12: { var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_Math_minIII(v0, v1)); } // 184 1 127
90.557 - case 15: arg4 = stack.pop() // 54 4
90.558 - case 17: stack.push(arg0); // 42
90.559 - case 18: stack.push(stack.pop().value); // 180 1 100
90.560 - case 21: arg5 = stack.pop() // 58 5
90.561 - case 23: stack.push(arg1); // 43
90.562 - case 24: stack.push(stack.pop().value); // 180 1 100
90.563 - case 27: arg6 = stack.pop() // 58 6
90.564 - case 29: stack.push(arg0); // 42
90.565 - case 30: stack.push(stack.pop().offset); // 180 1 99
90.566 - case 33: arg7 = stack.pop() // 54 7
90.567 - case 35: stack.push(arg1); // 43
90.568 - case 36: stack.push(stack.pop().offset); // 180 1 99
90.569 - case 39: arg8 = stack.pop() // 54 8
90.570 - case 41: stack.push(arg7); // 21 7
90.571 - case 43: stack.push(arg8); // 21 8
90.572 - case 45: if (stack.pop() != stack.pop()) { gt = 102; continue; } // 160 0 57
90.573 - case 48: stack.push(arg7); // 21 7
90.574 - case 50: arg9 = stack.pop() // 54 9
90.575 - case 52: stack.push(arg4); // 21 4
90.576 - case 54: stack.push(arg7); // 21 7
90.577 - case 56: stack.push(stack.pop() + stack.pop()); // 96
90.578 - case 57: arg10 = stack.pop() // 54 10
90.579 - case 59: stack.push(arg9); // 21 9
90.580 - case 61: stack.push(arg10); // 21 10
90.581 - case 63: if (stack.pop() <= stack.pop()) { gt = 99; continue; } // 162 0 36
90.582 - case 66: stack.push(arg5); // 25 5
90.583 - case 68: stack.push(arg9); // 21 9
90.584 - case 70: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.585 - case 71: arg11 = stack.pop() // 54 11
90.586 - case 73: stack.push(arg6); // 25 6
90.587 - case 75: stack.push(arg9); // 21 9
90.588 - case 77: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.589 - case 78: arg12 = stack.pop() // 54 12
90.590 - case 80: stack.push(arg11); // 21 11
90.591 - case 82: stack.push(arg12); // 21 12
90.592 - case 84: if (stack.pop() == stack.pop()) { gt = 93; continue; } // 159 0 9
90.593 - case 87: stack.push(arg11); // 21 11
90.594 - case 89: stack.push(arg12); // 21 12
90.595 - case 91: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.596 - case 92: return stack.pop(); // 172
90.597 - case 93: arg9++; // 132 9 1
90.598 - case 96: gt = 59; continue; // 167 255 219
90.599 - case 99: gt = 146; continue; // 167 0 47
90.600 - case 102: stack.push(arg4); // 21 4
90.601 - case 104: arg4 += 255; // 132 4 255
90.602 - case 107: if (stack.pop() == 0) { gt = 146; continue; } // 153 0 39
90.603 - case 110: stack.push(arg5); // 25 5
90.604 - case 112: stack.push(arg7); // 21 7
90.605 - case 114: arg7++; // 132 7 1
90.606 - case 117: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.607 - case 118: arg9 = stack.pop() // 54 9
90.608 - case 120: stack.push(arg6); // 25 6
90.609 - case 122: stack.push(arg8); // 21 8
90.610 - case 124: arg8++; // 132 8 1
90.611 - case 127: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.612 - case 128: arg10 = stack.pop() // 54 10
90.613 - case 130: stack.push(arg9); // 21 9
90.614 - case 132: stack.push(arg10); // 21 10
90.615 - case 134: if (stack.pop() == stack.pop()) { gt = 143; continue; } // 159 0 9
90.616 - case 137: stack.push(arg9); // 21 9
90.617 - case 139: stack.push(arg10); // 21 10
90.618 - case 141: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.619 - case 142: return stack.pop(); // 172
90.620 - case 143: gt = 102; continue; // 167 255 215
90.621 - case 146: stack.push(arg2); // 28
90.622 - case 147: stack.push(arg3); // 29
90.623 - case 148: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.624 - case 149: return stack.pop(); // 172
90.625 - }
90.626 -}
90.627 -function java_lang_String_compareToIgnoreCaseILjava_lang_String(arg0,arg1) {
90.628 - var arg2;
90.629 -;
90.630 - var stack = new Array(3);
90.631 - var gt = 0;
90.632 - for(;;) switch(gt) {
90.633 - case 0: stack.push(java_lang_String_CASE_INSENSITIVE_ORDER); // 178 1 102
90.634 - case 3: stack.push(arg0); // 42
90.635 - case 4: stack.push(arg1); // 43
90.636 - case 5: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.compareILjava_lang_ObjectLjava_lang_Object(self, v0, v1)); } // 185 1 190
90.637 - case 8: stack.push(0); // 3
90.638 - case 9: // 0
90.639 - case 10: return stack.pop(); // 172
90.640 - }
90.641 -}
90.642 -function java_lang_String_regionMatchesZILjava_lang_StringII(arg0,arg1,arg2,arg3,arg4) {
90.643 - var arg5;
90.644 - var arg6;
90.645 - var arg7;
90.646 - var arg8;
90.647 - var arg9;
90.648 -;
90.649 - var stack = new Array(6);
90.650 - var gt = 0;
90.651 - for(;;) switch(gt) {
90.652 - case 0: stack.push(arg0); // 42
90.653 - case 1: stack.push(stack.pop().value); // 180 1 100
90.654 - case 4: arg5 = stack.pop() // 58 5
90.655 - case 6: stack.push(arg0); // 42
90.656 - case 7: stack.push(stack.pop().offset); // 180 1 99
90.657 - case 10: stack.push(arg1); // 27
90.658 - case 11: stack.push(stack.pop() + stack.pop()); // 96
90.659 - case 12: arg6 = stack.pop() // 54 6
90.660 - case 14: stack.push(arg2); // 44
90.661 - case 15: stack.push(stack.pop().value); // 180 1 100
90.662 - case 18: arg7 = stack.pop() // 58 7
90.663 - case 20: stack.push(arg2); // 44
90.664 - case 21: stack.push(stack.pop().offset); // 180 1 99
90.665 - case 24: stack.push(arg3); // 29
90.666 - case 25: stack.push(stack.pop() + stack.pop()); // 96
90.667 - case 26: arg8 = stack.pop() // 54 8
90.668 - case 28: stack.push(arg3); // 29
90.669 - case 29: if (stack.pop() < 0) { gt = 66; continue; } // 155 0 37
90.670 - case 32: stack.push(arg1); // 27
90.671 - case 33: if (stack.pop() < 0) { gt = 66; continue; } // 155 0 33
90.672 - case 36: stack.push(arg1); // 27
90.673 - case 37: // number conversion // 133
90.674 - case 38: stack.push(arg0); // 42
90.675 - case 39: stack.push(stack.pop().count); // 180 1 97
90.676 - case 42: // number conversion // 133
90.677 - case 43: stack.push(arg4); // 21 4
90.678 - case 45: // number conversion // 133
90.679 - case 46: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 101
90.680 - case 47: { var delta = stack.pop() - stack.pop(); stack.push(delta < 0 ?-1 : (delta == 0 ? 0 : 1)); } // 148
90.681 - case 48: if (stack.pop() > 0) { gt = 66; continue; } // 157 0 18
90.682 - case 51: stack.push(arg3); // 29
90.683 - case 52: // number conversion // 133
90.684 - case 53: stack.push(arg2); // 44
90.685 - case 54: stack.push(stack.pop().count); // 180 1 97
90.686 - case 57: // number conversion // 133
90.687 - case 58: stack.push(arg4); // 21 4
90.688 - case 60: // number conversion // 133
90.689 - case 61: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 101
90.690 - case 62: { var delta = stack.pop() - stack.pop(); stack.push(delta < 0 ?-1 : (delta == 0 ? 0 : 1)); } // 148
90.691 - case 63: if (stack.pop() <= 0) { gt = 68; continue; } // 158 0 5
90.692 - case 66: stack.push(0); // 3
90.693 - case 67: return stack.pop(); // 172
90.694 - case 68: stack.push(arg4); // 21 4
90.695 - case 70: arg4 += 255; // 132 4 255
90.696 - case 73: if (stack.pop() <= 0) { gt = 97; continue; } // 158 0 24
90.697 - case 76: stack.push(arg5); // 25 5
90.698 - case 78: stack.push(arg6); // 21 6
90.699 - case 80: arg6++; // 132 6 1
90.700 - case 83: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.701 - case 84: stack.push(arg7); // 25 7
90.702 - case 86: stack.push(arg8); // 21 8
90.703 - case 88: arg8++; // 132 8 1
90.704 - case 91: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.705 - case 92: if (stack.pop() == stack.pop()) { gt = 68; continue; } // 159 255 232
90.706 - case 95: stack.push(0); // 3
90.707 - case 96: return stack.pop(); // 172
90.708 - case 97: stack.push(1); // 4
90.709 - case 98: return stack.pop(); // 172
90.710 - }
90.711 -}
90.712 -function java_lang_String_regionMatchesZZILjava_lang_StringII(arg0,arg1,arg2,arg3,arg4,arg5) {
90.713 - var arg6;
90.714 - var arg7;
90.715 - var arg8;
90.716 - var arg9;
90.717 - var arg10;
90.718 - var arg11;
90.719 - var arg12;
90.720 - var arg13;
90.721 - var arg14;
90.722 -;
90.723 - var stack = new Array(6);
90.724 - var gt = 0;
90.725 - for(;;) switch(gt) {
90.726 - case 0: stack.push(arg0); // 42
90.727 - case 1: stack.push(stack.pop().value); // 180 1 100
90.728 - case 4: arg6 = stack.pop() // 58 6
90.729 - case 6: stack.push(arg0); // 42
90.730 - case 7: stack.push(stack.pop().offset); // 180 1 99
90.731 - case 10: stack.push(arg2); // 28
90.732 - case 11: stack.push(stack.pop() + stack.pop()); // 96
90.733 - case 12: arg7 = stack.pop() // 54 7
90.734 - case 14: stack.push(arg3); // 45
90.735 - case 15: stack.push(stack.pop().value); // 180 1 100
90.736 - case 18: arg8 = stack.pop() // 58 8
90.737 - case 20: stack.push(arg3); // 45
90.738 - case 21: stack.push(stack.pop().offset); // 180 1 99
90.739 - case 24: stack.push(arg4); // 21 4
90.740 - case 26: stack.push(stack.pop() + stack.pop()); // 96
90.741 - case 27: arg9 = stack.pop() // 54 9
90.742 - case 29: stack.push(arg4); // 21 4
90.743 - case 31: if (stack.pop() < 0) { gt = 69; continue; } // 155 0 38
90.744 - case 34: stack.push(arg2); // 28
90.745 - case 35: if (stack.pop() < 0) { gt = 69; continue; } // 155 0 34
90.746 - case 38: stack.push(arg2); // 28
90.747 - case 39: // number conversion // 133
90.748 - case 40: stack.push(arg0); // 42
90.749 - case 41: stack.push(stack.pop().count); // 180 1 97
90.750 - case 44: // number conversion // 133
90.751 - case 45: stack.push(arg5); // 21 5
90.752 - case 47: // number conversion // 133
90.753 - case 48: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 101
90.754 - case 49: { var delta = stack.pop() - stack.pop(); stack.push(delta < 0 ?-1 : (delta == 0 ? 0 : 1)); } // 148
90.755 - case 50: if (stack.pop() > 0) { gt = 69; continue; } // 157 0 19
90.756 - case 53: stack.push(arg4); // 21 4
90.757 - case 55: // number conversion // 133
90.758 - case 56: stack.push(arg3); // 45
90.759 - case 57: stack.push(stack.pop().count); // 180 1 97
90.760 - case 60: // number conversion // 133
90.761 - case 61: stack.push(arg5); // 21 5
90.762 - case 63: // number conversion // 133
90.763 - case 64: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 101
90.764 - case 65: { var delta = stack.pop() - stack.pop(); stack.push(delta < 0 ?-1 : (delta == 0 ? 0 : 1)); } // 148
90.765 - case 66: if (stack.pop() <= 0) { gt = 71; continue; } // 158 0 5
90.766 - case 69: stack.push(0); // 3
90.767 - case 70: return stack.pop(); // 172
90.768 - case 71: stack.push(arg5); // 21 5
90.769 - case 73: arg5 += 255; // 132 5 255
90.770 - case 76: if (stack.pop() <= 0) { gt = 155; continue; } // 158 0 79
90.771 - case 79: stack.push(arg6); // 25 6
90.772 - case 81: stack.push(arg7); // 21 7
90.773 - case 83: arg7++; // 132 7 1
90.774 - case 86: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.775 - case 87: arg10 = stack.pop() // 54 10
90.776 - case 89: stack.push(arg8); // 25 8
90.777 - case 91: stack.push(arg9); // 21 9
90.778 - case 93: arg9++; // 132 9 1
90.779 - case 96: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.780 - case 97: arg11 = stack.pop() // 54 11
90.781 - case 99: stack.push(arg10); // 21 10
90.782 - case 101: stack.push(arg11); // 21 11
90.783 - case 103: if (stack.pop() != stack.pop()) { gt = 109; continue; } // 160 0 6
90.784 - case 106: gt = 71; continue; // 167 255 221
90.785 - case 109: stack.push(arg1); // 27
90.786 - case 110: if (stack.pop() == 0) { gt = 153; continue; } // 153 0 43
90.787 - case 113: stack.push(arg10); // 21 10
90.788 - case 115: { var v0 = stack.pop(); stack.push(java_lang_Character_toUpperCaseCC(v0)); } // 184 1 105
90.789 - case 118: arg12 = stack.pop() // 54 12
90.790 - case 120: stack.push(arg11); // 21 11
90.791 - case 122: { var v0 = stack.pop(); stack.push(java_lang_Character_toUpperCaseCC(v0)); } // 184 1 105
90.792 - case 125: arg13 = stack.pop() // 54 13
90.793 - case 127: stack.push(arg12); // 21 12
90.794 - case 129: stack.push(arg13); // 21 13
90.795 - case 131: if (stack.pop() != stack.pop()) { gt = 137; continue; } // 160 0 6
90.796 - case 134: gt = 71; continue; // 167 255 193
90.797 - case 137: stack.push(arg12); // 21 12
90.798 - case 139: { var v0 = stack.pop(); stack.push(java_lang_Character_toLowerCaseCC(v0)); } // 184 1 104
90.799 - case 142: stack.push(arg13); // 21 13
90.800 - case 144: { var v0 = stack.pop(); stack.push(java_lang_Character_toLowerCaseCC(v0)); } // 184 1 104
90.801 - case 147: if (stack.pop() != stack.pop()) { gt = 153; continue; } // 160 0 6
90.802 - case 150: gt = 71; continue; // 167 255 177
90.803 - case 153: stack.push(0); // 3
90.804 - case 154: return stack.pop(); // 172
90.805 - case 155: stack.push(1); // 4
90.806 - case 156: return stack.pop(); // 172
90.807 - }
90.808 -}
90.809 -function java_lang_String_startsWithZLjava_lang_StringI(arg0,arg1,arg2) {
90.810 - var arg3;
90.811 - var arg4;
90.812 - var arg5;
90.813 - var arg6;
90.814 - var arg7;
90.815 - var arg8;
90.816 -;
90.817 - var stack = new Array(3);
90.818 - var gt = 0;
90.819 - for(;;) switch(gt) {
90.820 - case 0: stack.push(arg0); // 42
90.821 - case 1: stack.push(stack.pop().value); // 180 1 100
90.822 - case 4: arg3 = stack.pop(); // 78
90.823 - case 5: stack.push(arg0); // 42
90.824 - case 6: stack.push(stack.pop().offset); // 180 1 99
90.825 - case 9: stack.push(arg2); // 28
90.826 - case 10: stack.push(stack.pop() + stack.pop()); // 96
90.827 - case 11: arg4 = stack.pop() // 54 4
90.828 - case 13: stack.push(arg1); // 43
90.829 - case 14: stack.push(stack.pop().value); // 180 1 100
90.830 - case 17: arg5 = stack.pop() // 58 5
90.831 - case 19: stack.push(arg1); // 43
90.832 - case 20: stack.push(stack.pop().offset); // 180 1 99
90.833 - case 23: arg6 = stack.pop() // 54 6
90.834 - case 25: stack.push(arg1); // 43
90.835 - case 26: stack.push(stack.pop().count); // 180 1 97
90.836 - case 29: arg7 = stack.pop() // 54 7
90.837 - case 31: stack.push(arg2); // 28
90.838 - case 32: if (stack.pop() < 0) { gt = 46; continue; } // 155 0 14
90.839 - case 35: stack.push(arg2); // 28
90.840 - case 36: stack.push(arg0); // 42
90.841 - case 37: stack.push(stack.pop().count); // 180 1 97
90.842 - case 40: stack.push(arg7); // 21 7
90.843 - case 42: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.844 - case 43: if (stack.pop() >= stack.pop()) { gt = 48; continue; } // 164 0 5
90.845 - case 46: stack.push(0); // 3
90.846 - case 47: return stack.pop(); // 172
90.847 - case 48: arg7 += 255; // 132 7 255
90.848 - case 51: stack.push(arg7); // 21 7
90.849 - case 53: if (stack.pop() < 0) { gt = 76; continue; } // 155 0 23
90.850 - case 56: stack.push(arg3); // 45
90.851 - case 57: stack.push(arg4); // 21 4
90.852 - case 59: arg4++; // 132 4 1
90.853 - case 62: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.854 - case 63: stack.push(arg5); // 25 5
90.855 - case 65: stack.push(arg6); // 21 6
90.856 - case 67: arg6++; // 132 6 1
90.857 - case 70: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.858 - case 71: if (stack.pop() == stack.pop()) { gt = 48; continue; } // 159 255 233
90.859 - case 74: stack.push(0); // 3
90.860 - case 75: return stack.pop(); // 172
90.861 - case 76: stack.push(1); // 4
90.862 - case 77: return stack.pop(); // 172
90.863 - }
90.864 -}
90.865 -function java_lang_String_startsWithZLjava_lang_String(arg0,arg1) {
90.866 - var arg2;
90.867 -;
90.868 - var stack = new Array(3);
90.869 - var gt = 0;
90.870 - for(;;) switch(gt) {
90.871 - case 0: stack.push(arg0); // 42
90.872 - case 1: stack.push(arg1); // 43
90.873 - case 2: stack.push(0); // 3
90.874 - case 3: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.startsWithZLjava_lang_StringI(self, v0, v1)); } // 182 1 152
90.875 - case 6: return stack.pop(); // 172
90.876 - }
90.877 -}
90.878 -function java_lang_String_endsWithZLjava_lang_String(arg0,arg1) {
90.879 - var arg2;
90.880 -;
90.881 - var stack = new Array(4);
90.882 - var gt = 0;
90.883 - for(;;) switch(gt) {
90.884 - case 0: stack.push(arg0); // 42
90.885 - case 1: stack.push(arg1); // 43
90.886 - case 2: stack.push(arg0); // 42
90.887 - case 3: stack.push(stack.pop().count); // 180 1 97
90.888 - case 6: stack.push(arg1); // 43
90.889 - case 7: stack.push(stack.pop().count); // 180 1 97
90.890 - case 10: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.891 - case 11: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.startsWithZLjava_lang_StringI(self, v0, v1)); } // 182 1 152
90.892 - case 14: return stack.pop(); // 172
90.893 - }
90.894 -}
90.895 -function java_lang_String_hashCodeI(arg0) {
90.896 - var arg1;
90.897 - var arg2;
90.898 - var arg3;
90.899 - var arg4;
90.900 - var arg5;
90.901 - var arg6;
90.902 -;
90.903 - var stack = new Array(3);
90.904 - var gt = 0;
90.905 - for(;;) switch(gt) {
90.906 - case 0: stack.push(arg0); // 42
90.907 - case 1: stack.push(stack.pop().hash); // 180 1 98
90.908 - case 4: arg1 = stack.pop(); // 60
90.909 - case 5: stack.push(arg0); // 42
90.910 - case 6: stack.push(stack.pop().count); // 180 1 97
90.911 - case 9: arg2 = stack.pop(); // 61
90.912 - case 10: stack.push(arg1); // 27
90.913 - case 11: if (stack.pop() != 0) { gt = 62; continue; } // 154 0 51
90.914 - case 14: stack.push(arg2); // 28
90.915 - case 15: if (stack.pop() <= 0) { gt = 62; continue; } // 158 0 47
90.916 - case 18: stack.push(arg0); // 42
90.917 - case 19: stack.push(stack.pop().offset); // 180 1 99
90.918 - case 22: arg3 = stack.pop(); // 62
90.919 - case 23: stack.push(arg0); // 42
90.920 - case 24: stack.push(stack.pop().value); // 180 1 100
90.921 - case 27: arg4 = stack.pop() // 58 4
90.922 - case 29: stack.push(0); // 3
90.923 - case 30: arg5 = stack.pop() // 54 5
90.924 - case 32: stack.push(arg5); // 21 5
90.925 - case 34: stack.push(arg2); // 28
90.926 - case 35: if (stack.pop() <= stack.pop()) { gt = 57; continue; } // 162 0 22
90.927 - case 38: stack.push(31); // 16 31
90.928 - case 40: stack.push(arg1); // 27
90.929 - case 41: stack.push(stack.pop() * stack.pop()); // 104
90.930 - case 42: stack.push(arg4); // 25 4
90.931 - case 44: stack.push(arg3); // 29
90.932 - case 45: arg3++; // 132 3 1
90.933 - case 48: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.934 - case 49: stack.push(stack.pop() + stack.pop()); // 96
90.935 - case 50: arg1 = stack.pop(); // 60
90.936 - case 51: arg5++; // 132 5 1
90.937 - case 54: gt = 32; continue; // 167 255 234
90.938 - case 57: stack.push(arg0); // 42
90.939 - case 58: stack.push(arg1); // 27
90.940 - case 59: { var v = stack.pop(); stack.pop().hash = v; } // 181 1 98
90.941 - case 62: stack.push(arg1); // 27
90.942 - case 63: return stack.pop(); // 172
90.943 - }
90.944 -}
90.945 -function java_lang_String_indexOfII(arg0,arg1) {
90.946 - var arg2;
90.947 -;
90.948 - var stack = new Array(3);
90.949 - var gt = 0;
90.950 - for(;;) switch(gt) {
90.951 - case 0: stack.push(arg0); // 42
90.952 - case 1: stack.push(arg1); // 27
90.953 - case 2: stack.push(0); // 3
90.954 - case 3: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.indexOfIII(self, v0, v1)); } // 182 1 135
90.955 - case 6: return stack.pop(); // 172
90.956 - }
90.957 -}
90.958 -function java_lang_String_indexOfIII(arg0,arg1,arg2) {
90.959 - var arg3;
90.960 - var arg4;
90.961 - var arg5;
90.962 - var arg6;
90.963 - var arg7;
90.964 -;
90.965 - var stack = new Array(3);
90.966 - var gt = 0;
90.967 - for(;;) switch(gt) {
90.968 - case 0: stack.push(arg0); // 42
90.969 - case 1: stack.push(stack.pop().offset); // 180 1 99
90.970 - case 4: stack.push(arg0); // 42
90.971 - case 5: stack.push(stack.pop().count); // 180 1 97
90.972 - case 8: stack.push(stack.pop() + stack.pop()); // 96
90.973 - case 9: arg3 = stack.pop(); // 62
90.974 - case 10: stack.push(arg0); // 42
90.975 - case 11: stack.push(stack.pop().value); // 180 1 100
90.976 - case 14: arg4 = stack.pop() // 58 4
90.977 - case 16: stack.push(arg2); // 28
90.978 - case 17: if (stack.pop() >= 0) { gt = 25; continue; } // 156 0 8
90.979 - case 20: stack.push(0); // 3
90.980 - case 21: arg2 = stack.pop(); // 61
90.981 - case 22: gt = 35; continue; // 167 0 13
90.982 - case 25: stack.push(arg2); // 28
90.983 - case 26: stack.push(arg0); // 42
90.984 - case 27: stack.push(stack.pop().count); // 180 1 97
90.985 - case 30: if (stack.pop() > stack.pop()) { gt = 35; continue; } // 161 0 5
90.986 - case 33: // 2
90.987 - case 34: return stack.pop(); // 172
90.988 - case 35: stack.push(arg0); // 42
90.989 - case 36: stack.push(stack.pop().offset); // 180 1 99
90.990 - case 39: stack.push(arg2); // 28
90.991 - case 40: stack.push(stack.pop() + stack.pop()); // 96
90.992 - case 41: arg5 = stack.pop() // 54 5
90.993 - case 43: stack.push(arg1); // 27
90.994 - case 44: stack.push(65536); // 18 3
90.995 - case 46: if (stack.pop() <= stack.pop()) { gt = 80; continue; } // 162 0 34
90.996 - case 49: stack.push(arg5); // 21 5
90.997 - case 51: stack.push(arg3); // 29
90.998 - case 52: if (stack.pop() <= stack.pop()) { gt = 78; continue; } // 162 0 26
90.999 - case 55: stack.push(arg4); // 25 4
90.1000 - case 57: stack.push(arg5); // 21 5
90.1001 - case 59: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.1002 - case 60: stack.push(arg1); // 27
90.1003 - case 61: if (stack.pop() != stack.pop()) { gt = 72; continue; } // 160 0 11
90.1004 - case 64: stack.push(arg5); // 21 5
90.1005 - case 66: stack.push(arg0); // 42
90.1006 - case 67: stack.push(stack.pop().offset); // 180 1 99
90.1007 - case 70: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.1008 - case 71: return stack.pop(); // 172
90.1009 - case 72: arg5++; // 132 5 1
90.1010 - case 75: gt = 49; continue; // 167 255 230
90.1011 - case 78: // 2
90.1012 - case 79: return stack.pop(); // 172
90.1013 - case 80: stack.push(arg1); // 27
90.1014 - case 81: stack.push(1114111); // 18 4
90.1015 - case 83: if (stack.pop() < stack.pop()) { gt = 149; continue; } // 163 0 66
90.1016 - case 86: stack.push(arg1); // 27
90.1017 - case 87: { var v0 = stack.pop(); stack.push(java_lang_Character_toCharsACI(v0)); } // 184 1 109
90.1018 - case 90: arg6 = stack.pop() // 58 6
90.1019 - case 92: stack.push(arg5); // 21 5
90.1020 - case 94: stack.push(arg3); // 29
90.1021 - case 95: if (stack.pop() <= stack.pop()) { gt = 149; continue; } // 162 0 54
90.1022 - case 98: stack.push(arg4); // 25 4
90.1023 - case 100: stack.push(arg5); // 21 5
90.1024 - case 102: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.1025 - case 103: stack.push(arg6); // 25 6
90.1026 - case 105: stack.push(0); // 3
90.1027 - case 106: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.1028 - case 107: if (stack.pop() != stack.pop()) { gt = 143; continue; } // 160 0 36
90.1029 - case 110: stack.push(arg5); // 21 5
90.1030 - case 112: stack.push(1); // 4
90.1031 - case 113: stack.push(stack.pop() + stack.pop()); // 96
90.1032 - case 114: stack.push(arg3); // 29
90.1033 - case 115: if (stack.pop() != stack.pop()) { gt = 121; continue; } // 160 0 6
90.1034 - case 118: gt = 149; continue; // 167 0 31
90.1035 - case 121: stack.push(arg4); // 25 4
90.1036 - case 123: stack.push(arg5); // 21 5
90.1037 - case 125: stack.push(1); // 4
90.1038 - case 126: stack.push(stack.pop() + stack.pop()); // 96
90.1039 - case 127: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.1040 - case 128: stack.push(arg6); // 25 6
90.1041 - case 130: stack.push(1); // 4
90.1042 - case 131: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.1043 - case 132: if (stack.pop() != stack.pop()) { gt = 143; continue; } // 160 0 11
90.1044 - case 135: stack.push(arg5); // 21 5
90.1045 - case 137: stack.push(arg0); // 42
90.1046 - case 138: stack.push(stack.pop().offset); // 180 1 99
90.1047 - case 141: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.1048 - case 142: return stack.pop(); // 172
90.1049 - case 143: arg5++; // 132 5 1
90.1050 - case 146: gt = 92; continue; // 167 255 202
90.1051 - case 149: // 2
90.1052 - case 150: return stack.pop(); // 172
90.1053 - }
90.1054 -}
90.1055 -function java_lang_String_lastIndexOfII(arg0,arg1) {
90.1056 - var arg2;
90.1057 -;
90.1058 - var stack = new Array(4);
90.1059 - var gt = 0;
90.1060 - for(;;) switch(gt) {
90.1061 - case 0: stack.push(arg0); // 42
90.1062 - case 1: stack.push(arg1); // 27
90.1063 - case 2: stack.push(arg0); // 42
90.1064 - case 3: stack.push(stack.pop().count); // 180 1 97
90.1065 - case 6: stack.push(1); // 4
90.1066 - case 7: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.1067 - case 8: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.lastIndexOfIII(self, v0, v1)); } // 182 1 136
90.1068 - case 11: return stack.pop(); // 172
90.1069 - }
90.1070 -}
90.1071 -function java_lang_String_lastIndexOfIII(arg0,arg1,arg2) {
90.1072 - var arg3;
90.1073 - var arg4;
90.1074 - var arg5;
90.1075 - var arg6;
90.1076 - var arg7;
90.1077 - var arg8;
90.1078 -;
90.1079 - var stack = new Array(3);
90.1080 - var gt = 0;
90.1081 - for(;;) switch(gt) {
90.1082 - case 0: stack.push(arg0); // 42
90.1083 - case 1: stack.push(stack.pop().offset); // 180 1 99
90.1084 - case 4: arg3 = stack.pop(); // 62
90.1085 - case 5: stack.push(arg0); // 42
90.1086 - case 6: stack.push(stack.pop().value); // 180 1 100
90.1087 - case 9: arg4 = stack.pop() // 58 4
90.1088 - case 11: stack.push(arg0); // 42
90.1089 - case 12: stack.push(stack.pop().offset); // 180 1 99
90.1090 - case 15: stack.push(arg2); // 28
90.1091 - case 16: stack.push(arg0); // 42
90.1092 - case 17: stack.push(stack.pop().count); // 180 1 97
90.1093 - case 20: if (stack.pop() > stack.pop()) { gt = 32; continue; } // 161 0 12
90.1094 - case 23: stack.push(arg0); // 42
90.1095 - case 24: stack.push(stack.pop().count); // 180 1 97
90.1096 - case 27: stack.push(1); // 4
90.1097 - case 28: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.1098 - case 29: gt = 33; continue; // 167 0 4
90.1099 - case 32: stack.push(arg2); // 28
90.1100 - case 33: stack.push(stack.pop() + stack.pop()); // 96
90.1101 - case 34: arg5 = stack.pop() // 54 5
90.1102 - case 36: stack.push(arg1); // 27
90.1103 - case 37: stack.push(65536); // 18 3
90.1104 - case 39: if (stack.pop() <= stack.pop()) { gt = 73; continue; } // 162 0 34
90.1105 - case 42: stack.push(arg5); // 21 5
90.1106 - case 44: stack.push(arg3); // 29
90.1107 - case 45: if (stack.pop() > stack.pop()) { gt = 71; continue; } // 161 0 26
90.1108 - case 48: stack.push(arg4); // 25 4
90.1109 - case 50: stack.push(arg5); // 21 5
90.1110 - case 52: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.1111 - case 53: stack.push(arg1); // 27
90.1112 - case 54: if (stack.pop() != stack.pop()) { gt = 65; continue; } // 160 0 11
90.1113 - case 57: stack.push(arg5); // 21 5
90.1114 - case 59: stack.push(arg0); // 42
90.1115 - case 60: stack.push(stack.pop().offset); // 180 1 99
90.1116 - case 63: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.1117 - case 64: return stack.pop(); // 172
90.1118 - case 65: arg5 += 255; // 132 5 255
90.1119 - case 68: gt = 42; continue; // 167 255 230
90.1120 - case 71: // 2
90.1121 - case 72: return stack.pop(); // 172
90.1122 - case 73: stack.push(arg0); // 42
90.1123 - case 74: stack.push(stack.pop().offset); // 180 1 99
90.1124 - case 77: stack.push(arg0); // 42
90.1125 - case 78: stack.push(stack.pop().count); // 180 1 97
90.1126 - case 81: stack.push(stack.pop() + stack.pop()); // 96
90.1127 - case 82: arg6 = stack.pop() // 54 6
90.1128 - case 84: stack.push(arg1); // 27
90.1129 - case 85: stack.push(1114111); // 18 4
90.1130 - case 87: if (stack.pop() < stack.pop()) { gt = 154; continue; } // 163 0 67
90.1131 - case 90: stack.push(arg1); // 27
90.1132 - case 91: { var v0 = stack.pop(); stack.push(java_lang_Character_toCharsACI(v0)); } // 184 1 109
90.1133 - case 94: arg7 = stack.pop() // 58 7
90.1134 - case 96: stack.push(arg5); // 21 5
90.1135 - case 98: stack.push(arg3); // 29
90.1136 - case 99: if (stack.pop() > stack.pop()) { gt = 154; continue; } // 161 0 55
90.1137 - case 102: stack.push(arg4); // 25 4
90.1138 - case 104: stack.push(arg5); // 21 5
90.1139 - case 106: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.1140 - case 107: stack.push(arg7); // 25 7
90.1141 - case 109: stack.push(0); // 3
90.1142 - case 110: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.1143 - case 111: if (stack.pop() != stack.pop()) { gt = 148; continue; } // 160 0 37
90.1144 - case 114: stack.push(arg5); // 21 5
90.1145 - case 116: stack.push(1); // 4
90.1146 - case 117: stack.push(stack.pop() + stack.pop()); // 96
90.1147 - case 118: stack.push(arg6); // 21 6
90.1148 - case 120: if (stack.pop() != stack.pop()) { gt = 126; continue; } // 160 0 6
90.1149 - case 123: gt = 154; continue; // 167 0 31
90.1150 - case 126: stack.push(arg4); // 25 4
90.1151 - case 128: stack.push(arg5); // 21 5
90.1152 - case 130: stack.push(1); // 4
90.1153 - case 131: stack.push(stack.pop() + stack.pop()); // 96
90.1154 - case 132: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.1155 - case 133: stack.push(arg7); // 25 7
90.1156 - case 135: stack.push(1); // 4
90.1157 - case 136: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.1158 - case 137: if (stack.pop() != stack.pop()) { gt = 148; continue; } // 160 0 11
90.1159 - case 140: stack.push(arg5); // 21 5
90.1160 - case 142: stack.push(arg0); // 42
90.1161 - case 143: stack.push(stack.pop().offset); // 180 1 99
90.1162 - case 146: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.1163 - case 147: return stack.pop(); // 172
90.1164 - case 148: arg5 += 255; // 132 5 255
90.1165 - case 151: gt = 96; continue; // 167 255 201
90.1166 - case 154: // 2
90.1167 - case 155: return stack.pop(); // 172
90.1168 - }
90.1169 -}
90.1170 -function java_lang_String_indexOfILjava_lang_String(arg0,arg1) {
90.1171 - var arg2;
90.1172 -;
90.1173 - var stack = new Array(3);
90.1174 - var gt = 0;
90.1175 - for(;;) switch(gt) {
90.1176 - case 0: stack.push(arg0); // 42
90.1177 - case 1: stack.push(arg1); // 43
90.1178 - case 2: stack.push(0); // 3
90.1179 - case 3: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.indexOfILjava_lang_StringI(self, v0, v1)); } // 182 1 150
90.1180 - case 6: return stack.pop(); // 172
90.1181 - }
90.1182 -}
90.1183 -function java_lang_String_indexOfILjava_lang_StringI(arg0,arg1,arg2) {
90.1184 - var arg3;
90.1185 -;
90.1186 - var stack = new Array(7);
90.1187 - var gt = 0;
90.1188 - for(;;) switch(gt) {
90.1189 - case 0: stack.push(arg0); // 42
90.1190 - case 1: stack.push(stack.pop().value); // 180 1 100
90.1191 - case 4: stack.push(arg0); // 42
90.1192 - case 5: stack.push(stack.pop().offset); // 180 1 99
90.1193 - case 8: stack.push(arg0); // 42
90.1194 - case 9: stack.push(stack.pop().count); // 180 1 97
90.1195 - case 12: stack.push(arg1); // 43
90.1196 - case 13: stack.push(stack.pop().value); // 180 1 100
90.1197 - case 16: stack.push(arg1); // 43
90.1198 - case 17: stack.push(stack.pop().offset); // 180 1 99
90.1199 - case 20: stack.push(arg1); // 43
90.1200 - case 21: stack.push(stack.pop().count); // 180 1 97
90.1201 - case 24: stack.push(arg2); // 28
90.1202 - case 25: { var v6 = stack.pop(); var v5 = stack.pop(); var v4 = stack.pop(); var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_String_indexOfAIACAIAIACAIAIAI(v0, v1, v2, v3, v4, v5, v6)); } // 184 1 144
90.1203 - case 28: return stack.pop(); // 172
90.1204 - }
90.1205 -}
90.1206 -function java_lang_String_indexOfIACIIACIII(arg0,arg1,arg2,arg3,arg4,arg5,arg6) {
90.1207 - var arg7;
90.1208 - var arg8;
90.1209 - var arg9;
90.1210 - var arg10;
90.1211 - var arg11;
90.1212 - var arg12;
90.1213 - var stack = new Array();
90.1214 - var gt = 0;
90.1215 - for(;;) switch(gt) {
90.1216 - case 0: stack.push(arg6); // 21 6
90.1217 - case 2: stack.push(arg2); // 28
90.1218 - case 3: if (stack.pop() > stack.pop()) { gt = 17; continue; } // 161 0 14
90.1219 - case 6: stack.push(arg5); // 21 5
90.1220 - case 8: if (stack.pop() != 0) { gt = 15; continue; } // 154 0 7
90.1221 - case 11: stack.push(arg2); // 28
90.1222 - case 12: gt = 16; continue; // 167 0 4
90.1223 - case 15: // 2
90.1224 - case 16: return stack.pop(); // 172
90.1225 - case 17: stack.push(arg6); // 21 6
90.1226 - case 19: if (stack.pop() >= 0) { gt = 25; continue; } // 156 0 6
90.1227 - case 22: stack.push(0); // 3
90.1228 - case 23: arg6 = stack.pop() // 54 6
90.1229 - case 25: stack.push(arg5); // 21 5
90.1230 - case 27: if (stack.pop() != 0) { gt = 33; continue; } // 154 0 6
90.1231 - case 30: stack.push(arg6); // 21 6
90.1232 - case 32: return stack.pop(); // 172
90.1233 - case 33: stack.push(arg3); // 45
90.1234 - case 34: stack.push(arg4); // 21 4
90.1235 - case 36: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.1236 - case 37: arg7 = stack.pop() // 54 7
90.1237 - case 39: stack.push(arg1); // 27
90.1238 - case 40: stack.push(arg2); // 28
90.1239 - case 41: stack.push(arg5); // 21 5
90.1240 - case 43: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.1241 - case 44: stack.push(stack.pop() + stack.pop()); // 96
90.1242 - case 45: arg8 = stack.pop() // 54 8
90.1243 - case 47: stack.push(arg1); // 27
90.1244 - case 48: stack.push(arg6); // 21 6
90.1245 - case 50: stack.push(stack.pop() + stack.pop()); // 96
90.1246 - case 51: arg9 = stack.pop() // 54 9
90.1247 - case 53: stack.push(arg9); // 21 9
90.1248 - case 55: stack.push(arg8); // 21 8
90.1249 - case 57: if (stack.pop() < stack.pop()) { gt = 164; continue; } // 163 0 107
90.1250 - case 60: stack.push(arg0); // 42
90.1251 - case 61: stack.push(arg9); // 21 9
90.1252 - case 63: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.1253 - case 64: stack.push(arg7); // 21 7
90.1254 - case 66: if (stack.pop() == stack.pop()) { gt = 91; continue; } // 159 0 25
90.1255 - case 69: arg9++; // 132 9 1
90.1256 - case 72: stack.push(arg9); // 21 9
90.1257 - case 74: stack.push(arg8); // 21 8
90.1258 - case 76: if (stack.pop() < stack.pop()) { gt = 91; continue; } // 163 0 15
90.1259 - case 79: stack.push(arg0); // 42
90.1260 - case 80: stack.push(arg9); // 21 9
90.1261 - case 82: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.1262 - case 83: stack.push(arg7); // 21 7
90.1263 - case 85: if (stack.pop() == stack.pop()) { gt = 91; continue; } // 159 0 6
90.1264 - case 88: gt = 69; continue; // 167 255 237
90.1265 - case 91: stack.push(arg9); // 21 9
90.1266 - case 93: stack.push(arg8); // 21 8
90.1267 - case 95: if (stack.pop() < stack.pop()) { gt = 158; continue; } // 163 0 63
90.1268 - case 98: stack.push(arg9); // 21 9
90.1269 - case 100: stack.push(1); // 4
90.1270 - case 101: stack.push(stack.pop() + stack.pop()); // 96
90.1271 - case 102: arg10 = stack.pop() // 54 10
90.1272 - case 104: stack.push(arg10); // 21 10
90.1273 - case 106: stack.push(arg5); // 21 5
90.1274 - case 108: stack.push(stack.pop() + stack.pop()); // 96
90.1275 - case 109: stack.push(1); // 4
90.1276 - case 110: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.1277 - case 111: arg11 = stack.pop() // 54 11
90.1278 - case 113: stack.push(arg4); // 21 4
90.1279 - case 115: stack.push(1); // 4
90.1280 - case 116: stack.push(stack.pop() + stack.pop()); // 96
90.1281 - case 117: arg12 = stack.pop() // 54 12
90.1282 - case 119: stack.push(arg10); // 21 10
90.1283 - case 121: stack.push(arg11); // 21 11
90.1284 - case 123: if (stack.pop() <= stack.pop()) { gt = 146; continue; } // 162 0 23
90.1285 - case 126: stack.push(arg0); // 42
90.1286 - case 127: stack.push(arg10); // 21 10
90.1287 - case 129: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.1288 - case 130: stack.push(arg3); // 45
90.1289 - case 131: stack.push(arg12); // 21 12
90.1290 - case 133: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.1291 - case 134: if (stack.pop() != stack.pop()) { gt = 146; continue; } // 160 0 12
90.1292 - case 137: arg10++; // 132 10 1
90.1293 - case 140: arg12++; // 132 12 1
90.1294 - case 143: gt = 119; continue; // 167 255 232
90.1295 - case 146: stack.push(arg10); // 21 10
90.1296 - case 148: stack.push(arg11); // 21 11
90.1297 - case 150: if (stack.pop() != stack.pop()) { gt = 158; continue; } // 160 0 8
90.1298 - case 153: stack.push(arg9); // 21 9
90.1299 - case 155: stack.push(arg1); // 27
90.1300 - case 156: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.1301 - case 157: return stack.pop(); // 172
90.1302 - case 158: arg9++; // 132 9 1
90.1303 - case 161: gt = 53; continue; // 167 255 148
90.1304 - case 164: // 2
90.1305 - case 165: return stack.pop(); // 172
90.1306 - }
90.1307 -}
90.1308 -function java_lang_String_lastIndexOfILjava_lang_String(arg0,arg1) {
90.1309 - var arg2;
90.1310 -;
90.1311 - var stack = new Array(3);
90.1312 - var gt = 0;
90.1313 - for(;;) switch(gt) {
90.1314 - case 0: stack.push(arg0); // 42
90.1315 - case 1: stack.push(arg1); // 43
90.1316 - case 2: stack.push(arg0); // 42
90.1317 - case 3: stack.push(stack.pop().count); // 180 1 97
90.1318 - case 6: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.lastIndexOfILjava_lang_StringI(self, v0, v1)); } // 182 1 151
90.1319 - case 9: return stack.pop(); // 172
90.1320 - }
90.1321 -}
90.1322 -function java_lang_String_lastIndexOfILjava_lang_StringI(arg0,arg1,arg2) {
90.1323 - var arg3;
90.1324 -;
90.1325 - var stack = new Array(7);
90.1326 - var gt = 0;
90.1327 - for(;;) switch(gt) {
90.1328 - case 0: stack.push(arg0); // 42
90.1329 - case 1: stack.push(stack.pop().value); // 180 1 100
90.1330 - case 4: stack.push(arg0); // 42
90.1331 - case 5: stack.push(stack.pop().offset); // 180 1 99
90.1332 - case 8: stack.push(arg0); // 42
90.1333 - case 9: stack.push(stack.pop().count); // 180 1 97
90.1334 - case 12: stack.push(arg1); // 43
90.1335 - case 13: stack.push(stack.pop().value); // 180 1 100
90.1336 - case 16: stack.push(arg1); // 43
90.1337 - case 17: stack.push(stack.pop().offset); // 180 1 99
90.1338 - case 20: stack.push(arg1); // 43
90.1339 - case 21: stack.push(stack.pop().count); // 180 1 97
90.1340 - case 24: stack.push(arg2); // 28
90.1341 - case 25: { var v6 = stack.pop(); var v5 = stack.pop(); var v4 = stack.pop(); var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_String_lastIndexOfAIACAIAIACAIAIAI(v0, v1, v2, v3, v4, v5, v6)); } // 184 1 145
90.1342 - case 28: return stack.pop(); // 172
90.1343 - }
90.1344 -}
90.1345 -function java_lang_String_lastIndexOfIACIIACIII(arg0,arg1,arg2,arg3,arg4,arg5,arg6) {
90.1346 - var arg7;
90.1347 - var arg8;
90.1348 - var arg9;
90.1349 - var arg10;
90.1350 - var arg11;
90.1351 - var arg12;
90.1352 - var arg13;
90.1353 - var arg14;
90.1354 - var stack = new Array();
90.1355 - var gt = 0;
90.1356 - for(;;) switch(gt) {
90.1357 - case 0: stack.push(arg2); // 28
90.1358 - case 1: stack.push(arg5); // 21 5
90.1359 - case 3: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.1360 - case 4: arg7 = stack.pop() // 54 7
90.1361 - case 6: stack.push(arg6); // 21 6
90.1362 - case 8: if (stack.pop() >= 0) { gt = 13; continue; } // 156 0 5
90.1363 - case 11: // 2
90.1364 - case 12: return stack.pop(); // 172
90.1365 - case 13: stack.push(arg6); // 21 6
90.1366 - case 15: stack.push(arg7); // 21 7
90.1367 - case 17: if (stack.pop() >= stack.pop()) { gt = 24; continue; } // 164 0 7
90.1368 - case 20: stack.push(arg7); // 21 7
90.1369 - case 22: arg6 = stack.pop() // 54 6
90.1370 - case 24: stack.push(arg5); // 21 5
90.1371 - case 26: if (stack.pop() != 0) { gt = 32; continue; } // 154 0 6
90.1372 - case 29: stack.push(arg6); // 21 6
90.1373 - case 31: return stack.pop(); // 172
90.1374 - case 32: stack.push(arg4); // 21 4
90.1375 - case 34: stack.push(arg5); // 21 5
90.1376 - case 36: stack.push(stack.pop() + stack.pop()); // 96
90.1377 - case 37: stack.push(1); // 4
90.1378 - case 38: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.1379 - case 39: arg8 = stack.pop() // 54 8
90.1380 - case 41: stack.push(arg3); // 45
90.1381 - case 42: stack.push(arg8); // 21 8
90.1382 - case 44: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.1383 - case 45: arg9 = stack.pop() // 54 9
90.1384 - case 47: stack.push(arg1); // 27
90.1385 - case 48: stack.push(arg5); // 21 5
90.1386 - case 50: stack.push(stack.pop() + stack.pop()); // 96
90.1387 - case 51: stack.push(1); // 4
90.1388 - case 52: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.1389 - case 53: arg10 = stack.pop() // 54 10
90.1390 - case 55: stack.push(arg10); // 21 10
90.1391 - case 57: stack.push(arg6); // 21 6
90.1392 - case 59: stack.push(stack.pop() + stack.pop()); // 96
90.1393 - case 60: arg11 = stack.pop() // 54 11
90.1394 - case 62: stack.push(arg11); // 21 11
90.1395 - case 64: stack.push(arg10); // 21 10
90.1396 - case 66: if (stack.pop() > stack.pop()) { gt = 84; continue; } // 161 0 18
90.1397 - case 69: stack.push(arg0); // 42
90.1398 - case 70: stack.push(arg11); // 21 11
90.1399 - case 72: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.1400 - case 73: stack.push(arg9); // 21 9
90.1401 - case 75: if (stack.pop() == stack.pop()) { gt = 84; continue; } // 159 0 9
90.1402 - case 78: arg11 += 255; // 132 11 255
90.1403 - case 81: gt = 62; continue; // 167 255 237
90.1404 - case 84: stack.push(arg11); // 21 11
90.1405 - case 86: stack.push(arg10); // 21 10
90.1406 - case 88: if (stack.pop() <= stack.pop()) { gt = 93; continue; } // 162 0 5
90.1407 - case 91: // 2
90.1408 - case 92: return stack.pop(); // 172
90.1409 - case 93: stack.push(arg11); // 21 11
90.1410 - case 95: stack.push(1); // 4
90.1411 - case 96: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.1412 - case 97: arg12 = stack.pop() // 54 12
90.1413 - case 99: stack.push(arg12); // 21 12
90.1414 - case 101: stack.push(arg5); // 21 5
90.1415 - case 103: stack.push(1); // 4
90.1416 - case 104: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.1417 - case 105: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.1418 - case 106: arg13 = stack.pop() // 54 13
90.1419 - case 108: stack.push(arg8); // 21 8
90.1420 - case 110: stack.push(1); // 4
90.1421 - case 111: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.1422 - case 112: arg14 = stack.pop() // 54 14
90.1423 - case 114: stack.push(arg12); // 21 12
90.1424 - case 116: stack.push(arg13); // 21 13
90.1425 - case 118: if (stack.pop() >= stack.pop()) { gt = 144; continue; } // 164 0 26
90.1426 - case 121: stack.push(arg0); // 42
90.1427 - case 122: stack.push(arg12); // 21 12
90.1428 - case 124: arg12 += 255; // 132 12 255
90.1429 - case 127: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.1430 - case 128: stack.push(arg3); // 45
90.1431 - case 129: stack.push(arg14); // 21 14
90.1432 - case 131: arg14 += 255; // 132 14 255
90.1433 - case 134: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.1434 - case 135: if (stack.pop() == stack.pop()) { gt = 114; continue; } // 159 255 235
90.1435 - case 138: arg11 += 255; // 132 11 255
90.1436 - case 141: gt = 62; continue; // 167 255 177
90.1437 - case 144: stack.push(arg13); // 21 13
90.1438 - case 146: stack.push(arg1); // 27
90.1439 - case 147: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.1440 - case 148: stack.push(1); // 4
90.1441 - case 149: stack.push(stack.pop() + stack.pop()); // 96
90.1442 - case 150: return stack.pop(); // 172
90.1443 - }
90.1444 -}
90.1445 -function java_lang_String_substringLjava_lang_StringI(arg0,arg1) {
90.1446 - var arg2;
90.1447 -;
90.1448 - var stack = new Array(3);
90.1449 - var gt = 0;
90.1450 - for(;;) switch(gt) {
90.1451 - case 0: stack.push(arg0); // 42
90.1452 - case 1: stack.push(arg1); // 27
90.1453 - case 2: stack.push(arg0); // 42
90.1454 - case 3: stack.push(stack.pop().count); // 180 1 97
90.1455 - case 6: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.substringLjava_lang_StringII(self, v0, v1)); } // 182 1 147
90.1456 - case 9: return stack.pop(); // 176
90.1457 - }
90.1458 -}
90.1459 -function java_lang_String_substringLjava_lang_StringII(arg0,arg1,arg2) {
90.1460 - var arg3;
90.1461 -;
90.1462 - var stack = new Array(5);
90.1463 - var gt = 0;
90.1464 - for(;;) switch(gt) {
90.1465 - case 0: stack.push(arg1); // 27
90.1466 - case 1: if (stack.pop() >= 0) { gt = 13; continue; } // 156 0 12
90.1467 - case 4: stack.push(new java_lang_StringIndexOutOfBoundsException); // 187 0 206
90.1468 - case 7: stack.push(stack[stack.length - 1]); // 89
90.1469 - case 8: stack.push(arg1); // 27
90.1470 - case 9: { var v0 = stack.pop(); java_lang_StringIndexOutOfBoundsException_consVI(stack.pop(), v0); } // 183 1 169
90.1471 - case 12: // 191
90.1472 - case 13: stack.push(arg2); // 28
90.1473 - case 14: stack.push(arg0); // 42
90.1474 - case 15: stack.push(stack.pop().count); // 180 1 97
90.1475 - case 18: if (stack.pop() >= stack.pop()) { gt = 30; continue; } // 164 0 12
90.1476 - case 21: stack.push(new java_lang_StringIndexOutOfBoundsException); // 187 0 206
90.1477 - case 24: stack.push(stack[stack.length - 1]); // 89
90.1478 - case 25: stack.push(arg2); // 28
90.1479 - case 26: { var v0 = stack.pop(); java_lang_StringIndexOutOfBoundsException_consVI(stack.pop(), v0); } // 183 1 169
90.1480 - case 29: // 191
90.1481 - case 30: stack.push(arg1); // 27
90.1482 - case 31: stack.push(arg2); // 28
90.1483 - case 32: if (stack.pop() >= stack.pop()) { gt = 46; continue; } // 164 0 14
90.1484 - case 35: stack.push(new java_lang_StringIndexOutOfBoundsException); // 187 0 206
90.1485 - case 38: stack.push(stack[stack.length - 1]); // 89
90.1486 - case 39: stack.push(arg2); // 28
90.1487 - case 40: stack.push(arg1); // 27
90.1488 - case 41: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.1489 - case 42: { var v0 = stack.pop(); java_lang_StringIndexOutOfBoundsException_consVI(stack.pop(), v0); } // 183 1 169
90.1490 - case 45: // 191
90.1491 - case 46: stack.push(arg1); // 27
90.1492 - case 47: if (stack.pop() != 0) { gt = 62; continue; } // 154 0 15
90.1493 - case 50: stack.push(arg2); // 28
90.1494 - case 51: stack.push(arg0); // 42
90.1495 - case 52: stack.push(stack.pop().count); // 180 1 97
90.1496 - case 55: if (stack.pop() != stack.pop()) { gt = 62; continue; } // 160 0 7
90.1497 - case 58: stack.push(arg0); // 42
90.1498 - case 59: gt = 82; continue; // 167 0 23
90.1499 - case 62: stack.push(new java_lang_String); // 187 0 200
90.1500 - case 65: stack.push(stack[stack.length - 1]); // 89
90.1501 - case 66: stack.push(arg0); // 42
90.1502 - case 67: stack.push(stack.pop().offset); // 180 1 99
90.1503 - case 70: stack.push(arg1); // 27
90.1504 - case 71: stack.push(stack.pop() + stack.pop()); // 96
90.1505 - case 72: stack.push(arg2); // 28
90.1506 - case 73: stack.push(arg1); // 27
90.1507 - case 74: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.1508 - case 75: stack.push(arg0); // 42
90.1509 - case 76: stack.push(stack.pop().value); // 180 1 100
90.1510 - case 79: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_String_consVIIAC(stack.pop(), v0, v1, v2); } // 183 1 137
90.1511 - case 82: return stack.pop(); // 176
90.1512 - }
90.1513 -}
90.1514 -function java_lang_String_subSequenceLjava_lang_CharSequenceII(arg0,arg1,arg2) {
90.1515 - var arg3;
90.1516 -;
90.1517 - var stack = new Array(3);
90.1518 - var gt = 0;
90.1519 - for(;;) switch(gt) {
90.1520 - case 0: stack.push(arg0); // 42
90.1521 - case 1: stack.push(arg1); // 27
90.1522 - case 2: stack.push(arg2); // 28
90.1523 - case 3: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.substringLjava_lang_StringII(self, v0, v1)); } // 182 1 147
90.1524 - case 6: return stack.pop(); // 176
90.1525 - }
90.1526 -}
90.1527 -function java_lang_String_concatLjava_lang_StringLjava_lang_String(arg0,arg1) {
90.1528 - var arg2;
90.1529 - var arg3;
90.1530 - var arg4;
90.1531 -;
90.1532 - var stack = new Array(5);
90.1533 - var gt = 0;
90.1534 - for(;;) switch(gt) {
90.1535 - case 0: stack.push(arg1); // 43
90.1536 - case 1: { var self = stack.pop(); stack.push(self.lengthI(self)); } // 182 1 133
90.1537 - case 4: arg2 = stack.pop(); // 61
90.1538 - case 5: stack.push(arg2); // 28
90.1539 - case 6: if (stack.pop() != 0) { gt = 11; continue; } // 154 0 5
90.1540 - case 9: stack.push(arg0); // 42
90.1541 - case 10: return stack.pop(); // 176
90.1542 - case 11: stack.push(arg0); // 42
90.1543 - case 12: stack.push(stack.pop().count); // 180 1 97
90.1544 - case 15: stack.push(arg2); // 28
90.1545 - case 16: stack.push(stack.pop() + stack.pop()); // 96
90.1546 - case 17: stack.push(new Array(stack.pop())); // 188 5
90.1547 - case 19: arg3 = stack.pop(); // 78
90.1548 - case 20: stack.push(arg0); // 42
90.1549 - case 21: stack.push(0); // 3
90.1550 - case 22: stack.push(arg0); // 42
90.1551 - case 23: stack.push(stack.pop().count); // 180 1 97
90.1552 - case 26: stack.push(arg3); // 45
90.1553 - case 27: stack.push(0); // 3
90.1554 - case 28: { var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); self.getCharsVIIACAI(self, v0, v1, v2, v3); } // 182 1 138
90.1555 - case 31: stack.push(arg1); // 43
90.1556 - case 32: stack.push(0); // 3
90.1557 - case 33: stack.push(arg2); // 28
90.1558 - case 34: stack.push(arg3); // 45
90.1559 - case 35: stack.push(arg0); // 42
90.1560 - case 36: stack.push(stack.pop().count); // 180 1 97
90.1561 - case 39: { var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); self.getCharsVIIACAI(self, v0, v1, v2, v3); } // 182 1 138
90.1562 - case 42: stack.push(new java_lang_String); // 187 0 200
90.1563 - case 45: stack.push(stack[stack.length - 1]); // 89
90.1564 - case 46: stack.push(0); // 3
90.1565 - case 47: stack.push(arg0); // 42
90.1566 - case 48: stack.push(stack.pop().count); // 180 1 97
90.1567 - case 51: stack.push(arg2); // 28
90.1568 - case 52: stack.push(stack.pop() + stack.pop()); // 96
90.1569 - case 53: stack.push(arg3); // 45
90.1570 - case 54: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_String_consVIIAC(stack.pop(), v0, v1, v2); } // 183 1 137
90.1571 - case 57: return stack.pop(); // 176
90.1572 - }
90.1573 -}
90.1574 -function java_lang_String_replaceLjava_lang_StringCC(arg0,arg1,arg2) {
90.1575 - var arg3;
90.1576 - var arg4;
90.1577 - var arg5;
90.1578 - var arg6;
90.1579 - var arg7;
90.1580 - var arg8;
90.1581 - var arg9;
90.1582 -;
90.1583 - var stack = new Array(5);
90.1584 - var gt = 0;
90.1585 - for(;;) switch(gt) {
90.1586 - case 0: stack.push(arg1); // 27
90.1587 - case 1: stack.push(arg2); // 28
90.1588 - case 2: if (stack.pop() == stack.pop()) { gt = 140; continue; } // 159 0 138
90.1589 - case 5: stack.push(arg0); // 42
90.1590 - case 6: stack.push(stack.pop().count); // 180 1 97
90.1591 - case 9: arg3 = stack.pop(); // 62
90.1592 - case 10: // 2
90.1593 - case 11: arg4 = stack.pop() // 54 4
90.1594 - case 13: stack.push(arg0); // 42
90.1595 - case 14: stack.push(stack.pop().value); // 180 1 100
90.1596 - case 17: arg5 = stack.pop() // 58 5
90.1597 - case 19: stack.push(arg0); // 42
90.1598 - case 20: stack.push(stack.pop().offset); // 180 1 99
90.1599 - case 23: arg6 = stack.pop() // 54 6
90.1600 - case 25: arg4++; // 132 4 1
90.1601 - case 28: stack.push(arg4); // 21 4
90.1602 - case 30: stack.push(arg3); // 29
90.1603 - case 31: if (stack.pop() <= stack.pop()) { gt = 49; continue; } // 162 0 18
90.1604 - case 34: stack.push(arg5); // 25 5
90.1605 - case 36: stack.push(arg6); // 21 6
90.1606 - case 38: stack.push(arg4); // 21 4
90.1607 - case 40: stack.push(stack.pop() + stack.pop()); // 96
90.1608 - case 41: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.1609 - case 42: stack.push(arg1); // 27
90.1610 - case 43: if (stack.pop() != stack.pop()) { gt = 25; continue; } // 160 255 238
90.1611 - case 46: gt = 49; continue; // 167 0 3
90.1612 - case 49: stack.push(arg4); // 21 4
90.1613 - case 51: stack.push(arg3); // 29
90.1614 - case 52: if (stack.pop() <= stack.pop()) { gt = 140; continue; } // 162 0 88
90.1615 - case 55: stack.push(arg3); // 29
90.1616 - case 56: stack.push(new Array(stack.pop())); // 188 5
90.1617 - case 58: arg7 = stack.pop() // 58 7
90.1618 - case 60: stack.push(0); // 3
90.1619 - case 61: arg8 = stack.pop() // 54 8
90.1620 - case 63: stack.push(arg8); // 21 8
90.1621 - case 65: stack.push(arg4); // 21 4
90.1622 - case 67: if (stack.pop() <= stack.pop()) { gt = 89; continue; } // 162 0 22
90.1623 - case 70: stack.push(arg7); // 25 7
90.1624 - case 72: stack.push(arg8); // 21 8
90.1625 - case 74: stack.push(arg5); // 25 5
90.1626 - case 76: stack.push(arg6); // 21 6
90.1627 - case 78: stack.push(arg8); // 21 8
90.1628 - case 80: stack.push(stack.pop() + stack.pop()); // 96
90.1629 - case 81: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.1630 - case 82: { var value = stack.pop(); var indx = stack.pop(); stack.pop()[indx] = value; } // 85
90.1631 - case 83: arg8++; // 132 8 1
90.1632 - case 86: gt = 63; continue; // 167 255 233
90.1633 - case 89: stack.push(arg4); // 21 4
90.1634 - case 91: stack.push(arg3); // 29
90.1635 - case 92: if (stack.pop() <= stack.pop()) { gt = 128; continue; } // 162 0 36
90.1636 - case 95: stack.push(arg5); // 25 5
90.1637 - case 97: stack.push(arg6); // 21 6
90.1638 - case 99: stack.push(arg4); // 21 4
90.1639 - case 101: stack.push(stack.pop() + stack.pop()); // 96
90.1640 - case 102: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.1641 - case 103: arg8 = stack.pop() // 54 8
90.1642 - case 105: stack.push(arg7); // 25 7
90.1643 - case 107: stack.push(arg4); // 21 4
90.1644 - case 109: stack.push(arg8); // 21 8
90.1645 - case 111: stack.push(arg1); // 27
90.1646 - case 112: if (stack.pop() != stack.pop()) { gt = 119; continue; } // 160 0 7
90.1647 - case 115: stack.push(arg2); // 28
90.1648 - case 116: gt = 121; continue; // 167 0 5
90.1649 - case 119: stack.push(arg8); // 21 8
90.1650 - case 121: { var value = stack.pop(); var indx = stack.pop(); stack.pop()[indx] = value; } // 85
90.1651 - case 122: arg4++; // 132 4 1
90.1652 - case 125: gt = 89; continue; // 167 255 220
90.1653 - case 128: stack.push(new java_lang_String); // 187 0 200
90.1654 - case 131: stack.push(stack[stack.length - 1]); // 89
90.1655 - case 132: stack.push(0); // 3
90.1656 - case 133: stack.push(arg3); // 29
90.1657 - case 134: stack.push(arg7); // 25 7
90.1658 - case 136: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_String_consVIIAC(stack.pop(), v0, v1, v2); } // 183 1 137
90.1659 - case 139: return stack.pop(); // 176
90.1660 - case 140: stack.push(arg0); // 42
90.1661 - case 141: return stack.pop(); // 176
90.1662 - }
90.1663 -}
90.1664 -function java_lang_String_matchesZLjava_lang_String(arg0,arg1) {
90.1665 - var arg2;
90.1666 -;
90.1667 - var stack = new Array(2);
90.1668 - var gt = 0;
90.1669 - for(;;) switch(gt) {
90.1670 - case 0: stack.push(arg1); // 43
90.1671 - case 1: stack.push(arg0); // 42
90.1672 - case 2: { var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_util_regex_Pattern_matchesZLjava_lang_StringLjava_lang_CharSequence(v0, v1)); } // 184 1 183
90.1673 - case 5: return stack.pop(); // 172
90.1674 - }
90.1675 -}
90.1676 -function java_lang_String_containsZLjava_lang_CharSequence(arg0,arg1) {
90.1677 - var arg2;
90.1678 -;
90.1679 - var stack = new Array(2);
90.1680 - var gt = 0;
90.1681 - for(;;) switch(gt) {
90.1682 - case 0: stack.push(arg0); // 42
90.1683 - case 1: stack.push(arg1); // 43
90.1684 - case 2: { var self = stack.pop(); stack.push(self.toStringLjava_lang_String(self)); } // 182 1 132
90.1685 - case 5: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.indexOfILjava_lang_String(self, v0)); } // 182 1 149
90.1686 - case 8: // 2
90.1687 - case 9: if (stack.pop() >= stack.pop()) { gt = 16; continue; } // 164 0 7
90.1688 - case 12: stack.push(1); // 4
90.1689 - case 13: gt = 17; continue; // 167 0 4
90.1690 - case 16: stack.push(0); // 3
90.1691 - case 17: return stack.pop(); // 172
90.1692 - }
90.1693 -}
90.1694 -function java_lang_String_replaceFirstLjava_lang_StringLjava_lang_StringLjava_lang_String(arg0,arg1,arg2) {
90.1695 - var arg3;
90.1696 -;
90.1697 - var stack = new Array(2);
90.1698 - var gt = 0;
90.1699 - for(;;) switch(gt) {
90.1700 - case 0: stack.push(arg1); // 43
90.1701 - case 1: { var v0 = stack.pop(); stack.push(java_util_regex_Pattern_compileLjava_util_regex_PatternLjava_lang_String(v0)); } // 184 1 186
90.1702 - case 4: stack.push(arg0); // 42
90.1703 - case 5: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.matcherLjava_util_regex_MatcherLjava_lang_CharSequence(self, v0)); } // 182 1 185
90.1704 - case 8: stack.push(arg2); // 44
90.1705 - case 9: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.replaceFirstLjava_lang_StringLjava_lang_String(self, v0)); } // 182 1 182
90.1706 - case 12: return stack.pop(); // 176
90.1707 - }
90.1708 -}
90.1709 -function java_lang_String_replaceAllLjava_lang_StringLjava_lang_StringLjava_lang_String(arg0,arg1,arg2) {
90.1710 - var arg3;
90.1711 -;
90.1712 - var stack = new Array(2);
90.1713 - var gt = 0;
90.1714 - for(;;) switch(gt) {
90.1715 - case 0: stack.push(arg1); // 43
90.1716 - case 1: { var v0 = stack.pop(); stack.push(java_util_regex_Pattern_compileLjava_util_regex_PatternLjava_lang_String(v0)); } // 184 1 186
90.1717 - case 4: stack.push(arg0); // 42
90.1718 - case 5: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.matcherLjava_util_regex_MatcherLjava_lang_CharSequence(self, v0)); } // 182 1 185
90.1719 - case 8: stack.push(arg2); // 44
90.1720 - case 9: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.replaceAllLjava_lang_StringLjava_lang_String(self, v0)); } // 182 1 181
90.1721 - case 12: return stack.pop(); // 176
90.1722 - }
90.1723 -}
90.1724 -function java_lang_String_replaceLjava_lang_StringLjava_lang_CharSequenceLjava_lang_CharSequence(arg0,arg1,arg2) {
90.1725 - var arg3;
90.1726 -;
90.1727 - var stack = new Array(2);
90.1728 - var gt = 0;
90.1729 - for(;;) switch(gt) {
90.1730 - case 0: stack.push(arg1); // 43
90.1731 - case 1: { var self = stack.pop(); stack.push(self.toStringLjava_lang_String(self)); } // 182 1 132
90.1732 - case 4: stack.push(16); // 16 16
90.1733 - case 6: { var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_util_regex_Pattern_compileLjava_util_regex_PatternLjava_lang_StringI(v0, v1)); } // 184 1 187
90.1734 - case 9: stack.push(arg0); // 42
90.1735 - case 10: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.matcherLjava_util_regex_MatcherLjava_lang_CharSequence(self, v0)); } // 182 1 185
90.1736 - case 13: stack.push(arg2); // 44
90.1737 - case 14: { var self = stack.pop(); stack.push(self.toStringLjava_lang_String(self)); } // 182 1 132
90.1738 - case 17: { var v0 = stack.pop(); stack.push(java_util_regex_Matcher_quoteReplacementLjava_lang_StringLjava_lang_String(v0)); } // 184 1 180
90.1739 - case 20: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.replaceAllLjava_lang_StringLjava_lang_String(self, v0)); } // 182 1 181
90.1740 - case 23: return stack.pop(); // 176
90.1741 - }
90.1742 -}
90.1743 -function java_lang_String_splitALjava_lang_StringLjava_lang_StringI(arg0,arg1,arg2) {
90.1744 - var arg3;
90.1745 -;
90.1746 - var stack = new Array(3);
90.1747 - var gt = 0;
90.1748 - for(;;) switch(gt) {
90.1749 - case 0: stack.push(arg1); // 43
90.1750 - case 1: { var v0 = stack.pop(); stack.push(java_util_regex_Pattern_compileLjava_util_regex_PatternLjava_lang_String(v0)); } // 184 1 186
90.1751 - case 4: stack.push(arg0); // 42
90.1752 - case 5: stack.push(arg2); // 28
90.1753 - case 6: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.splitALjava_lang_StringLjava_lang_CharSequenceI(self, v0, v1)); } // 182 1 184
90.1754 - case 9: return stack.pop(); // 176
90.1755 - }
90.1756 -}
90.1757 -function java_lang_String_splitALjava_lang_StringLjava_lang_String(arg0,arg1) {
90.1758 - var arg2;
90.1759 -;
90.1760 - var stack = new Array(3);
90.1761 - var gt = 0;
90.1762 - for(;;) switch(gt) {
90.1763 - case 0: stack.push(arg0); // 42
90.1764 - case 1: stack.push(arg1); // 43
90.1765 - case 2: stack.push(0); // 3
90.1766 - case 3: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.splitALjava_lang_StringLjava_lang_StringI(self, v0, v1)); } // 182 1 157
90.1767 - case 6: return stack.pop(); // 176
90.1768 - }
90.1769 -}
90.1770 -function java_lang_String_toLowerCaseLjava_lang_StringLjava_util_Locale(arg0,arg1) {
90.1771 - var arg2;
90.1772 - var arg3;
90.1773 - var arg4;
90.1774 - var arg5;
90.1775 - var arg6;
90.1776 - var arg7;
90.1777 - var arg8;
90.1778 - var arg9;
90.1779 - var arg10;
90.1780 - var arg11;
90.1781 - var arg12;
90.1782 - var arg13;
90.1783 - var arg14;
90.1784 -;
90.1785 - var stack = new Array(6);
90.1786 - var gt = 0;
90.1787 - for(;;) switch(gt) {
90.1788 - case 0: stack.push(arg1); // 43
90.1789 - case 1: if (stack.pop()) { gt = 12; continue; } // 199 0 11
90.1790 - case 4: stack.push(new java_lang_NullPointerException); // 187 0 198
90.1791 - case 7: stack.push(stack[stack.length - 1]); // 89
90.1792 - case 8: { java_lang_NullPointerException_consV(stack.pop()); } // 183 1 128
90.1793 - case 11: // 191
90.1794 - case 12: stack.push(0); // 3
90.1795 - case 13: arg2 = stack.pop(); // 61
90.1796 - case 14: stack.push(arg2); // 28
90.1797 - case 15: stack.push(arg0); // 42
90.1798 - case 16: stack.push(stack.pop().count); // 180 1 97
90.1799 - case 19: if (stack.pop() <= stack.pop()) { gt = 94; continue; } // 162 0 75
90.1800 - case 22: stack.push(arg0); // 42
90.1801 - case 23: stack.push(stack.pop().value); // 180 1 100
90.1802 - case 26: stack.push(arg0); // 42
90.1803 - case 27: stack.push(stack.pop().offset); // 180 1 99
90.1804 - case 30: stack.push(arg2); // 28
90.1805 - case 31: stack.push(stack.pop() + stack.pop()); // 96
90.1806 - case 32: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.1807 - case 33: arg3 = stack.pop(); // 62
90.1808 - case 34: stack.push(arg3); // 29
90.1809 - case 35: stack.push(55296); // 18 1
90.1810 - case 37: if (stack.pop() > stack.pop()) { gt = 77; continue; } // 161 0 40
90.1811 - case 40: stack.push(arg3); // 29
90.1812 - case 41: stack.push(56319); // 18 2
90.1813 - case 43: if (stack.pop() < stack.pop()) { gt = 77; continue; } // 163 0 34
90.1814 - case 46: stack.push(arg0); // 42
90.1815 - case 47: stack.push(arg2); // 28
90.1816 - case 48: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.codePointAtII(self, v0)); } // 182 1 134
90.1817 - case 51: arg4 = stack.pop() // 54 4
90.1818 - case 53: stack.push(arg4); // 21 4
90.1819 - case 55: stack.push(arg4); // 21 4
90.1820 - case 57: { var v0 = stack.pop(); stack.push(java_lang_Character_toLowerCaseII(v0)); } // 184 1 107
90.1821 - case 60: if (stack.pop() == stack.pop()) { gt = 66; continue; } // 159 0 6
90.1822 - case 63: gt = 96; continue; // 167 0 33
90.1823 - case 66: stack.push(arg2); // 28
90.1824 - case 67: stack.push(arg4); // 21 4
90.1825 - case 69: { var v0 = stack.pop(); stack.push(java_lang_Character_charCountII(v0)); } // 184 1 106
90.1826 - case 72: stack.push(stack.pop() + stack.pop()); // 96
90.1827 - case 73: arg2 = stack.pop(); // 61
90.1828 - case 74: gt = 91; continue; // 167 0 17
90.1829 - case 77: stack.push(arg3); // 29
90.1830 - case 78: stack.push(arg3); // 29
90.1831 - case 79: { var v0 = stack.pop(); stack.push(java_lang_Character_toLowerCaseCC(v0)); } // 184 1 104
90.1832 - case 82: if (stack.pop() == stack.pop()) { gt = 88; continue; } // 159 0 6
90.1833 - case 85: gt = 96; continue; // 167 0 11
90.1834 - case 88: arg2++; // 132 2 1
90.1835 - case 91: gt = 14; continue; // 167 255 179
90.1836 - case 94: stack.push(arg0); // 42
90.1837 - case 95: return stack.pop(); // 176
90.1838 - case 96: stack.push(arg0); // 42
90.1839 - case 97: stack.push(stack.pop().count); // 180 1 97
90.1840 - case 100: stack.push(new Array(stack.pop())); // 188 5
90.1841 - case 102: arg3 = stack.pop(); // 78
90.1842 - case 103: stack.push(0); // 3
90.1843 - case 104: arg4 = stack.pop() // 54 4
90.1844 - case 106: stack.push(arg0); // 42
90.1845 - case 107: stack.push(stack.pop().value); // 180 1 100
90.1846 - case 110: stack.push(arg0); // 42
90.1847 - case 111: stack.push(stack.pop().offset); // 180 1 99
90.1848 - case 114: stack.push(arg3); // 45
90.1849 - case 115: stack.push(0); // 3
90.1850 - case 116: stack.push(arg2); // 28
90.1851 - case 117: { var v4 = stack.pop(); var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_System_arraycopyVLjava_lang_ObjectILjava_lang_ObjectII(v0, v1, v2, v3, v4); } // 184 1 171
90.1852 - case 120: stack.push(arg1); // 43
90.1853 - case 121: { var self = stack.pop(); stack.push(self.getLanguageLjava_lang_String(self)); } // 182 1 178
90.1854 - case 124: arg5 = stack.pop() // 58 5
90.1855 - case 126: stack.push(arg5); // 25 5
90.1856 - case 128: stack.push("tr"); // 18 11
90.1857 - case 130: // 165
90.1858 - case 131: // 0
90.1859 - case 132: stack.push(6405); // 17 25 5
90.1860 - case 135: stack.push("az"); // 18 5
90.1861 - case 137: // 165
90.1862 - case 138: // 0
90.1863 - case 139: stack.push(1); // 10
90.1864 - case 140: stack.push(arg5); // 25 5
90.1865 - case 142: stack.push("lt"); // 18 9
90.1866 - case 144: // 166
90.1867 - case 145: // 0
90.1868 - case 146: stack.push(4); // 7
90.1869 - case 147: stack.push(1); // 4
90.1870 - case 148: gt = 152; continue; // 167 0 4
90.1871 - case 151: stack.push(0); // 3
90.1872 - case 152: arg6 = stack.pop() // 54 6
90.1873 - case 154: stack.push(arg2); // 28
90.1874 - case 155: arg11 = stack.pop() // 54 11
90.1875 - case 157: stack.push(arg11); // 21 11
90.1876 - case 159: stack.push(arg0); // 42
90.1877 - case 160: stack.push(stack.pop().count); // 180 1 97
90.1878 - case 163: if (stack.pop() <= stack.pop()) { gt = 419; continue; } // 162 1 0
90.1879 - case 166: stack.push(arg0); // 42
90.1880 - case 167: stack.push(stack.pop().value); // 180 1 100
90.1881 - case 170: stack.push(arg0); // 42
90.1882 - case 171: stack.push(stack.pop().offset); // 180 1 99
90.1883 - case 174: stack.push(arg11); // 21 11
90.1884 - case 176: stack.push(stack.pop() + stack.pop()); // 96
90.1885 - case 177: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.1886 - case 178: arg9 = stack.pop() // 54 9
90.1887 - case 180: stack.push(arg9); // 21 9
90.1888 - case 182: // number conversion // 146
90.1889 - case 183: stack.push(55296); // 18 1
90.1890 - case 185: if (stack.pop() > stack.pop()) { gt = 214; continue; } // 161 0 29
90.1891 - case 188: stack.push(arg9); // 21 9
90.1892 - case 190: // number conversion // 146
90.1893 - case 191: stack.push(56319); // 18 2
90.1894 - case 193: if (stack.pop() < stack.pop()) { gt = 214; continue; } // 163 0 21
90.1895 - case 196: stack.push(arg0); // 42
90.1896 - case 197: stack.push(arg11); // 21 11
90.1897 - case 199: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.codePointAtII(self, v0)); } // 182 1 134
90.1898 - case 202: arg9 = stack.pop() // 54 9
90.1899 - case 204: stack.push(arg9); // 21 9
90.1900 - case 206: { var v0 = stack.pop(); stack.push(java_lang_Character_charCountII(v0)); } // 184 1 106
90.1901 - case 209: arg10 = stack.pop() // 54 10
90.1902 - case 211: gt = 217; continue; // 167 0 6
90.1903 - case 214: stack.push(1); // 4
90.1904 - case 215: arg10 = stack.pop() // 54 10
90.1905 - case 217: stack.push(arg6); // 21 6
90.1906 - case 219: if (stack.pop() != 0) { gt = 230; continue; } // 154 0 11
90.1907 - case 222: stack.push(arg9); // 21 9
90.1908 - case 224: stack.push(931); // 17 3 163
90.1909 - case 227: if (stack.pop() != stack.pop()) { gt = 242; continue; } // 160 0 15
90.1910 - case 230: stack.push(arg0); // 42
90.1911 - case 231: stack.push(arg11); // 21 11
90.1912 - case 233: stack.push(arg1); // 43
90.1913 - case 234: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_ConditionalSpecialCasing_toLowerCaseExILjava_lang_StringILjava_util_Locale(v0, v1, v2)); } // 184 1 117
90.1914 - case 237: arg8 = stack.pop() // 54 8
90.1915 - case 239: gt = 249; continue; // 167 0 10
90.1916 - case 242: stack.push(arg9); // 21 9
90.1917 - case 244: { var v0 = stack.pop(); stack.push(java_lang_Character_toLowerCaseII(v0)); } // 184 1 107
90.1918 - case 247: arg8 = stack.pop() // 54 8
90.1919 - case 249: stack.push(arg8); // 21 8
90.1920 - case 251: // 2
90.1921 - case 252: if (stack.pop() == stack.pop()) { gt = 262; continue; } // 159 0 10
90.1922 - case 255: stack.push(arg8); // 21 8
90.1923 - case 257: stack.push(65536); // 18 3
90.1924 - case 259: if (stack.pop() > stack.pop()) { gt = 399; continue; } // 161 0 140
90.1925 - case 262: stack.push(arg8); // 21 8
90.1926 - case 264: // 2
90.1927 - case 265: if (stack.pop() != stack.pop()) { gt = 280; continue; } // 160 0 15
90.1928 - case 268: stack.push(arg0); // 42
90.1929 - case 269: stack.push(arg11); // 21 11
90.1930 - case 271: stack.push(arg1); // 43
90.1931 - case 272: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_ConditionalSpecialCasing_toLowerCaseCharArrayACLjava_lang_StringILjava_util_Locale(v0, v1, v2)); } // 184 1 119
90.1932 - case 275: arg7 = stack.pop() // 58 7
90.1933 - case 277: gt = 315; continue; // 167 0 38
90.1934 - case 280: stack.push(arg10); // 21 10
90.1935 - case 282: stack.push(2); // 5
90.1936 - case 283: if (stack.pop() != stack.pop()) { gt = 308; continue; } // 160 0 25
90.1937 - case 286: stack.push(arg4); // 21 4
90.1938 - case 288: stack.push(arg8); // 21 8
90.1939 - case 290: stack.push(arg3); // 45
90.1940 - case 291: stack.push(arg11); // 21 11
90.1941 - case 293: stack.push(arg4); // 21 4
90.1942 - case 295: stack.push(stack.pop() + stack.pop()); // 96
90.1943 - case 296: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_Character_toCharsAIIACAI(v0, v1, v2)); } // 184 1 111
90.1944 - case 299: stack.push(arg10); // 21 10
90.1945 - case 301: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.1946 - case 302: stack.push(stack.pop() + stack.pop()); // 96
90.1947 - case 303: arg4 = stack.pop() // 54 4
90.1948 - case 305: gt = 409; continue; // 167 0 104
90.1949 - case 308: stack.push(arg8); // 21 8
90.1950 - case 310: { var v0 = stack.pop(); stack.push(java_lang_Character_toCharsACI(v0)); } // 184 1 109
90.1951 - case 313: arg7 = stack.pop() // 58 7
90.1952 - case 315: stack.push(arg7); // 25 7
90.1953 - case 317: stack.push(stack.pop().length); // 190
90.1954 - case 318: arg12 = stack.pop() // 54 12
90.1955 - case 320: stack.push(arg12); // 21 12
90.1956 - case 322: stack.push(arg10); // 21 10
90.1957 - case 324: if (stack.pop() >= stack.pop()) { gt = 355; continue; } // 164 0 31
90.1958 - case 327: stack.push(arg3); // 45
90.1959 - case 328: stack.push(stack.pop().length); // 190
90.1960 - case 329: stack.push(arg12); // 21 12
90.1961 - case 331: stack.push(stack.pop() + stack.pop()); // 96
90.1962 - case 332: stack.push(arg10); // 21 10
90.1963 - case 334: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.1964 - case 335: stack.push(new Array(stack.pop())); // 188 5
90.1965 - case 337: arg13 = stack.pop() // 58 13
90.1966 - case 339: stack.push(arg3); // 45
90.1967 - case 340: stack.push(0); // 3
90.1968 - case 341: stack.push(arg13); // 25 13
90.1969 - case 343: stack.push(0); // 3
90.1970 - case 344: stack.push(arg11); // 21 11
90.1971 - case 346: stack.push(arg4); // 21 4
90.1972 - case 348: stack.push(stack.pop() + stack.pop()); // 96
90.1973 - case 349: { var v4 = stack.pop(); var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_System_arraycopyVLjava_lang_ObjectILjava_lang_ObjectII(v0, v1, v2, v3, v4); } // 184 1 171
90.1974 - case 352: stack.push(arg13); // 25 13
90.1975 - case 354: arg3 = stack.pop(); // 78
90.1976 - case 355: stack.push(0); // 3
90.1977 - case 356: arg13 = stack.pop() // 54 13
90.1978 - case 358: stack.push(arg13); // 21 13
90.1979 - case 360: stack.push(arg12); // 21 12
90.1980 - case 362: if (stack.pop() <= stack.pop()) { gt = 386; continue; } // 162 0 24
90.1981 - case 365: stack.push(arg3); // 45
90.1982 - case 366: stack.push(arg11); // 21 11
90.1983 - case 368: stack.push(arg4); // 21 4
90.1984 - case 370: stack.push(stack.pop() + stack.pop()); // 96
90.1985 - case 371: stack.push(arg13); // 21 13
90.1986 - case 373: stack.push(stack.pop() + stack.pop()); // 96
90.1987 - case 374: stack.push(arg7); // 25 7
90.1988 - case 376: stack.push(arg13); // 21 13
90.1989 - case 378: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.1990 - case 379: { var value = stack.pop(); var indx = stack.pop(); stack.pop()[indx] = value; } // 85
90.1991 - case 380: arg13++; // 132 13 1
90.1992 - case 383: gt = 358; continue; // 167 255 231
90.1993 - case 386: stack.push(arg4); // 21 4
90.1994 - case 388: stack.push(arg12); // 21 12
90.1995 - case 390: stack.push(arg10); // 21 10
90.1996 - case 392: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.1997 - case 393: stack.push(stack.pop() + stack.pop()); // 96
90.1998 - case 394: arg4 = stack.pop() // 54 4
90.1999 - case 396: gt = 409; continue; // 167 0 13
90.2000 - case 399: stack.push(arg3); // 45
90.2001 - case 400: stack.push(arg11); // 21 11
90.2002 - case 402: stack.push(arg4); // 21 4
90.2003 - case 404: stack.push(stack.pop() + stack.pop()); // 96
90.2004 - case 405: stack.push(arg8); // 21 8
90.2005 - case 407: // number conversion // 146
90.2006 - case 408: { var value = stack.pop(); var indx = stack.pop(); stack.pop()[indx] = value; } // 85
90.2007 - case 409: stack.push(arg11); // 21 11
90.2008 - case 411: stack.push(arg10); // 21 10
90.2009 - case 413: stack.push(stack.pop() + stack.pop()); // 96
90.2010 - case 414: arg11 = stack.pop() // 54 11
90.2011 - case 416: gt = 157; continue; // 167 254 253
90.2012 - case 419: stack.push(new java_lang_String); // 187 0 200
90.2013 - case 422: stack.push(stack[stack.length - 1]); // 89
90.2014 - case 423: stack.push(0); // 3
90.2015 - case 424: stack.push(arg0); // 42
90.2016 - case 425: stack.push(stack.pop().count); // 180 1 97
90.2017 - case 428: stack.push(arg4); // 21 4
90.2018 - case 430: stack.push(stack.pop() + stack.pop()); // 96
90.2019 - case 431: stack.push(arg3); // 45
90.2020 - case 432: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_String_consVIIAC(stack.pop(), v0, v1, v2); } // 183 1 137
90.2021 - case 435: return stack.pop(); // 176
90.2022 - }
90.2023 -}
90.2024 -function java_lang_String_toLowerCaseLjava_lang_String(arg0) {
90.2025 - var arg1;
90.2026 -;
90.2027 - var stack = new Array(2);
90.2028 - var gt = 0;
90.2029 - for(;;) switch(gt) {
90.2030 - case 0: stack.push(arg0); // 42
90.2031 - case 1: { stack.push(java_util_Locale_getDefaultLjava_util_Locale()); } // 184 1 179
90.2032 - case 4: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.toLowerCaseLjava_lang_StringLjava_util_Locale(self, v0)); } // 182 1 158
90.2033 - case 7: return stack.pop(); // 176
90.2034 - }
90.2035 -}
90.2036 -function java_lang_String_toUpperCaseLjava_lang_StringLjava_util_Locale(arg0,arg1) {
90.2037 - var arg2;
90.2038 - var arg3;
90.2039 - var arg4;
90.2040 - var arg5;
90.2041 - var arg6;
90.2042 - var arg7;
90.2043 - var arg8;
90.2044 - var arg9;
90.2045 - var arg10;
90.2046 - var arg11;
90.2047 - var arg12;
90.2048 - var arg13;
90.2049 - var arg14;
90.2050 -;
90.2051 - var stack = new Array(6);
90.2052 - var gt = 0;
90.2053 - for(;;) switch(gt) {
90.2054 - case 0: stack.push(arg1); // 43
90.2055 - case 1: if (stack.pop()) { gt = 12; continue; } // 199 0 11
90.2056 - case 4: stack.push(new java_lang_NullPointerException); // 187 0 198
90.2057 - case 7: stack.push(stack[stack.length - 1]); // 89
90.2058 - case 8: { java_lang_NullPointerException_consV(stack.pop()); } // 183 1 128
90.2059 - case 11: // 191
90.2060 - case 12: stack.push(0); // 3
90.2061 - case 13: arg2 = stack.pop(); // 61
90.2062 - case 14: stack.push(arg2); // 28
90.2063 - case 15: stack.push(arg0); // 42
90.2064 - case 16: stack.push(stack.pop().count); // 180 1 97
90.2065 - case 19: if (stack.pop() <= stack.pop()) { gt = 93; continue; } // 162 0 74
90.2066 - case 22: stack.push(arg0); // 42
90.2067 - case 23: stack.push(stack.pop().value); // 180 1 100
90.2068 - case 26: stack.push(arg0); // 42
90.2069 - case 27: stack.push(stack.pop().offset); // 180 1 99
90.2070 - case 30: stack.push(arg2); // 28
90.2071 - case 31: stack.push(stack.pop() + stack.pop()); // 96
90.2072 - case 32: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.2073 - case 33: arg3 = stack.pop(); // 62
90.2074 - case 34: stack.push(arg3); // 29
90.2075 - case 35: stack.push(55296); // 18 1
90.2076 - case 37: if (stack.pop() > stack.pop()) { gt = 61; continue; } // 161 0 24
90.2077 - case 40: stack.push(arg3); // 29
90.2078 - case 41: stack.push(56319); // 18 2
90.2079 - case 43: if (stack.pop() < stack.pop()) { gt = 61; continue; } // 163 0 18
90.2080 - case 46: stack.push(arg0); // 42
90.2081 - case 47: stack.push(arg2); // 28
90.2082 - case 48: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.codePointAtII(self, v0)); } // 182 1 134
90.2083 - case 51: arg3 = stack.pop(); // 62
90.2084 - case 52: stack.push(arg3); // 29
90.2085 - case 53: { var v0 = stack.pop(); stack.push(java_lang_Character_charCountII(v0)); } // 184 1 106
90.2086 - case 56: arg4 = stack.pop() // 54 4
90.2087 - case 58: gt = 64; continue; // 167 0 6
90.2088 - case 61: stack.push(1); // 4
90.2089 - case 62: arg4 = stack.pop() // 54 4
90.2090 - case 64: stack.push(arg3); // 29
90.2091 - case 65: { var v0 = stack.pop(); stack.push(java_lang_Character_toUpperCaseExII(v0)); } // 184 1 108
90.2092 - case 68: arg5 = stack.pop() // 54 5
90.2093 - case 70: stack.push(arg5); // 21 5
90.2094 - case 72: // 2
90.2095 - case 73: if (stack.pop() == stack.pop()) { gt = 95; continue; } // 159 0 22
90.2096 - case 76: stack.push(arg3); // 29
90.2097 - case 77: stack.push(arg5); // 21 5
90.2098 - case 79: if (stack.pop() == stack.pop()) { gt = 85; continue; } // 159 0 6
90.2099 - case 82: gt = 95; continue; // 167 0 13
90.2100 - case 85: stack.push(arg2); // 28
90.2101 - case 86: stack.push(arg4); // 21 4
90.2102 - case 88: stack.push(stack.pop() + stack.pop()); // 96
90.2103 - case 89: arg2 = stack.pop(); // 61
90.2104 - case 90: gt = 14; continue; // 167 255 180
90.2105 - case 93: stack.push(arg0); // 42
90.2106 - case 94: return stack.pop(); // 176
90.2107 - case 95: stack.push(arg0); // 42
90.2108 - case 96: stack.push(stack.pop().count); // 180 1 97
90.2109 - case 99: stack.push(new Array(stack.pop())); // 188 5
90.2110 - case 101: arg3 = stack.pop(); // 78
90.2111 - case 102: stack.push(0); // 3
90.2112 - case 103: arg4 = stack.pop() // 54 4
90.2113 - case 105: stack.push(arg0); // 42
90.2114 - case 106: stack.push(stack.pop().value); // 180 1 100
90.2115 - case 109: stack.push(arg0); // 42
90.2116 - case 110: stack.push(stack.pop().offset); // 180 1 99
90.2117 - case 113: stack.push(arg3); // 45
90.2118 - case 114: stack.push(0); // 3
90.2119 - case 115: stack.push(arg2); // 28
90.2120 - case 116: { var v4 = stack.pop(); var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_System_arraycopyVLjava_lang_ObjectILjava_lang_ObjectII(v0, v1, v2, v3, v4); } // 184 1 171
90.2121 - case 119: stack.push(arg1); // 43
90.2122 - case 120: { var self = stack.pop(); stack.push(self.getLanguageLjava_lang_String(self)); } // 182 1 178
90.2123 - case 123: arg5 = stack.pop() // 58 5
90.2124 - case 125: stack.push(arg5); // 25 5
90.2125 - case 127: stack.push("tr"); // 18 11
90.2126 - case 129: // 165
90.2127 - case 130: // 0
90.2128 - case 131: stack.push(6405); // 17 25 5
90.2129 - case 134: stack.push("az"); // 18 5
90.2130 - case 136: // 165
90.2131 - case 137: // 0
90.2132 - case 138: stack.push(1); // 10
90.2133 - case 139: stack.push(arg5); // 25 5
90.2134 - case 141: stack.push("lt"); // 18 9
90.2135 - case 143: // 166
90.2136 - case 144: // 0
90.2137 - case 145: stack.push(4); // 7
90.2138 - case 146: stack.push(1); // 4
90.2139 - case 147: gt = 151; continue; // 167 0 4
90.2140 - case 150: stack.push(0); // 3
90.2141 - case 151: arg6 = stack.pop() // 54 6
90.2142 - case 153: stack.push(arg2); // 28
90.2143 - case 154: arg11 = stack.pop() // 54 11
90.2144 - case 156: stack.push(arg11); // 21 11
90.2145 - case 158: stack.push(arg0); // 42
90.2146 - case 159: stack.push(stack.pop().count); // 180 1 97
90.2147 - case 162: if (stack.pop() <= stack.pop()) { gt = 425; continue; } // 162 1 7
90.2148 - case 165: stack.push(arg0); // 42
90.2149 - case 166: stack.push(stack.pop().value); // 180 1 100
90.2150 - case 169: stack.push(arg0); // 42
90.2151 - case 170: stack.push(stack.pop().offset); // 180 1 99
90.2152 - case 173: stack.push(arg11); // 21 11
90.2153 - case 175: stack.push(stack.pop() + stack.pop()); // 96
90.2154 - case 176: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.2155 - case 177: arg9 = stack.pop() // 54 9
90.2156 - case 179: stack.push(arg9); // 21 9
90.2157 - case 181: // number conversion // 146
90.2158 - case 182: stack.push(55296); // 18 1
90.2159 - case 184: if (stack.pop() > stack.pop()) { gt = 213; continue; } // 161 0 29
90.2160 - case 187: stack.push(arg9); // 21 9
90.2161 - case 189: // number conversion // 146
90.2162 - case 190: stack.push(56319); // 18 2
90.2163 - case 192: if (stack.pop() < stack.pop()) { gt = 213; continue; } // 163 0 21
90.2164 - case 195: stack.push(arg0); // 42
90.2165 - case 196: stack.push(arg11); // 21 11
90.2166 - case 198: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.codePointAtII(self, v0)); } // 182 1 134
90.2167 - case 201: arg9 = stack.pop() // 54 9
90.2168 - case 203: stack.push(arg9); // 21 9
90.2169 - case 205: { var v0 = stack.pop(); stack.push(java_lang_Character_charCountII(v0)); } // 184 1 106
90.2170 - case 208: arg10 = stack.pop() // 54 10
90.2171 - case 210: gt = 216; continue; // 167 0 6
90.2172 - case 213: stack.push(1); // 4
90.2173 - case 214: arg10 = stack.pop() // 54 10
90.2174 - case 216: stack.push(arg6); // 21 6
90.2175 - case 218: if (stack.pop() == 0) { gt = 233; continue; } // 153 0 15
90.2176 - case 221: stack.push(arg0); // 42
90.2177 - case 222: stack.push(arg11); // 21 11
90.2178 - case 224: stack.push(arg1); // 43
90.2179 - case 225: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_ConditionalSpecialCasing_toUpperCaseExILjava_lang_StringILjava_util_Locale(v0, v1, v2)); } // 184 1 118
90.2180 - case 228: arg8 = stack.pop() // 54 8
90.2181 - case 230: gt = 240; continue; // 167 0 10
90.2182 - case 233: stack.push(arg9); // 21 9
90.2183 - case 235: { var v0 = stack.pop(); stack.push(java_lang_Character_toUpperCaseExII(v0)); } // 184 1 108
90.2184 - case 238: arg8 = stack.pop() // 54 8
90.2185 - case 240: stack.push(arg8); // 21 8
90.2186 - case 242: // 2
90.2187 - case 243: if (stack.pop() == stack.pop()) { gt = 253; continue; } // 159 0 10
90.2188 - case 246: stack.push(arg8); // 21 8
90.2189 - case 248: stack.push(65536); // 18 3
90.2190 - case 250: if (stack.pop() > stack.pop()) { gt = 405; continue; } // 161 0 155
90.2191 - case 253: stack.push(arg8); // 21 8
90.2192 - case 255: // 2
90.2193 - case 256: if (stack.pop() != stack.pop()) { gt = 286; continue; } // 160 0 30
90.2194 - case 259: stack.push(arg6); // 21 6
90.2195 - case 261: if (stack.pop() == 0) { gt = 276; continue; } // 153 0 15
90.2196 - case 264: stack.push(arg0); // 42
90.2197 - case 265: stack.push(arg11); // 21 11
90.2198 - case 267: stack.push(arg1); // 43
90.2199 - case 268: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_ConditionalSpecialCasing_toUpperCaseCharArrayACLjava_lang_StringILjava_util_Locale(v0, v1, v2)); } // 184 1 120
90.2200 - case 271: arg7 = stack.pop() // 58 7
90.2201 - case 273: gt = 321; continue; // 167 0 48
90.2202 - case 276: stack.push(arg9); // 21 9
90.2203 - case 278: { var v0 = stack.pop(); stack.push(java_lang_Character_toUpperCaseCharArrayACI(v0)); } // 184 1 110
90.2204 - case 281: arg7 = stack.pop() // 58 7
90.2205 - case 283: gt = 321; continue; // 167 0 38
90.2206 - case 286: stack.push(arg10); // 21 10
90.2207 - case 288: stack.push(2); // 5
90.2208 - case 289: if (stack.pop() != stack.pop()) { gt = 314; continue; } // 160 0 25
90.2209 - case 292: stack.push(arg4); // 21 4
90.2210 - case 294: stack.push(arg8); // 21 8
90.2211 - case 296: stack.push(arg3); // 45
90.2212 - case 297: stack.push(arg11); // 21 11
90.2213 - case 299: stack.push(arg4); // 21 4
90.2214 - case 301: stack.push(stack.pop() + stack.pop()); // 96
90.2215 - case 302: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_Character_toCharsAIIACAI(v0, v1, v2)); } // 184 1 111
90.2216 - case 305: stack.push(arg10); // 21 10
90.2217 - case 307: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.2218 - case 308: stack.push(stack.pop() + stack.pop()); // 96
90.2219 - case 309: arg4 = stack.pop() // 54 4
90.2220 - case 311: gt = 415; continue; // 167 0 104
90.2221 - case 314: stack.push(arg8); // 21 8
90.2222 - case 316: { var v0 = stack.pop(); stack.push(java_lang_Character_toCharsACI(v0)); } // 184 1 109
90.2223 - case 319: arg7 = stack.pop() // 58 7
90.2224 - case 321: stack.push(arg7); // 25 7
90.2225 - case 323: stack.push(stack.pop().length); // 190
90.2226 - case 324: arg12 = stack.pop() // 54 12
90.2227 - case 326: stack.push(arg12); // 21 12
90.2228 - case 328: stack.push(arg10); // 21 10
90.2229 - case 330: if (stack.pop() >= stack.pop()) { gt = 361; continue; } // 164 0 31
90.2230 - case 333: stack.push(arg3); // 45
90.2231 - case 334: stack.push(stack.pop().length); // 190
90.2232 - case 335: stack.push(arg12); // 21 12
90.2233 - case 337: stack.push(stack.pop() + stack.pop()); // 96
90.2234 - case 338: stack.push(arg10); // 21 10
90.2235 - case 340: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.2236 - case 341: stack.push(new Array(stack.pop())); // 188 5
90.2237 - case 343: arg13 = stack.pop() // 58 13
90.2238 - case 345: stack.push(arg3); // 45
90.2239 - case 346: stack.push(0); // 3
90.2240 - case 347: stack.push(arg13); // 25 13
90.2241 - case 349: stack.push(0); // 3
90.2242 - case 350: stack.push(arg11); // 21 11
90.2243 - case 352: stack.push(arg4); // 21 4
90.2244 - case 354: stack.push(stack.pop() + stack.pop()); // 96
90.2245 - case 355: { var v4 = stack.pop(); var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_System_arraycopyVLjava_lang_ObjectILjava_lang_ObjectII(v0, v1, v2, v3, v4); } // 184 1 171
90.2246 - case 358: stack.push(arg13); // 25 13
90.2247 - case 360: arg3 = stack.pop(); // 78
90.2248 - case 361: stack.push(0); // 3
90.2249 - case 362: arg13 = stack.pop() // 54 13
90.2250 - case 364: stack.push(arg13); // 21 13
90.2251 - case 366: stack.push(arg12); // 21 12
90.2252 - case 368: if (stack.pop() <= stack.pop()) { gt = 392; continue; } // 162 0 24
90.2253 - case 371: stack.push(arg3); // 45
90.2254 - case 372: stack.push(arg11); // 21 11
90.2255 - case 374: stack.push(arg4); // 21 4
90.2256 - case 376: stack.push(stack.pop() + stack.pop()); // 96
90.2257 - case 377: stack.push(arg13); // 21 13
90.2258 - case 379: stack.push(stack.pop() + stack.pop()); // 96
90.2259 - case 380: stack.push(arg7); // 25 7
90.2260 - case 382: stack.push(arg13); // 21 13
90.2261 - case 384: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.2262 - case 385: { var value = stack.pop(); var indx = stack.pop(); stack.pop()[indx] = value; } // 85
90.2263 - case 386: arg13++; // 132 13 1
90.2264 - case 389: gt = 364; continue; // 167 255 231
90.2265 - case 392: stack.push(arg4); // 21 4
90.2266 - case 394: stack.push(arg12); // 21 12
90.2267 - case 396: stack.push(arg10); // 21 10
90.2268 - case 398: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.2269 - case 399: stack.push(stack.pop() + stack.pop()); // 96
90.2270 - case 400: arg4 = stack.pop() // 54 4
90.2271 - case 402: gt = 415; continue; // 167 0 13
90.2272 - case 405: stack.push(arg3); // 45
90.2273 - case 406: stack.push(arg11); // 21 11
90.2274 - case 408: stack.push(arg4); // 21 4
90.2275 - case 410: stack.push(stack.pop() + stack.pop()); // 96
90.2276 - case 411: stack.push(arg8); // 21 8
90.2277 - case 413: // number conversion // 146
90.2278 - case 414: { var value = stack.pop(); var indx = stack.pop(); stack.pop()[indx] = value; } // 85
90.2279 - case 415: stack.push(arg11); // 21 11
90.2280 - case 417: stack.push(arg10); // 21 10
90.2281 - case 419: stack.push(stack.pop() + stack.pop()); // 96
90.2282 - case 420: arg11 = stack.pop() // 54 11
90.2283 - case 422: gt = 156; continue; // 167 254 246
90.2284 - case 425: stack.push(new java_lang_String); // 187 0 200
90.2285 - case 428: stack.push(stack[stack.length - 1]); // 89
90.2286 - case 429: stack.push(0); // 3
90.2287 - case 430: stack.push(arg0); // 42
90.2288 - case 431: stack.push(stack.pop().count); // 180 1 97
90.2289 - case 434: stack.push(arg4); // 21 4
90.2290 - case 436: stack.push(stack.pop() + stack.pop()); // 96
90.2291 - case 437: stack.push(arg3); // 45
90.2292 - case 438: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_String_consVIIAC(stack.pop(), v0, v1, v2); } // 183 1 137
90.2293 - case 441: return stack.pop(); // 176
90.2294 - }
90.2295 -}
90.2296 -function java_lang_String_toUpperCaseLjava_lang_String(arg0) {
90.2297 - var arg1;
90.2298 -;
90.2299 - var stack = new Array(2);
90.2300 - var gt = 0;
90.2301 - for(;;) switch(gt) {
90.2302 - case 0: stack.push(arg0); // 42
90.2303 - case 1: { stack.push(java_util_Locale_getDefaultLjava_util_Locale()); } // 184 1 179
90.2304 - case 4: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.toUpperCaseLjava_lang_StringLjava_util_Locale(self, v0)); } // 182 1 159
90.2305 - case 7: return stack.pop(); // 176
90.2306 - }
90.2307 -}
90.2308 -function java_lang_String_trimLjava_lang_String(arg0) {
90.2309 - var arg1;
90.2310 - var arg2;
90.2311 - var arg3;
90.2312 - var arg4;
90.2313 - var arg5;
90.2314 -;
90.2315 - var stack = new Array(3);
90.2316 - var gt = 0;
90.2317 - for(;;) switch(gt) {
90.2318 - case 0: stack.push(arg0); // 42
90.2319 - case 1: stack.push(stack.pop().count); // 180 1 97
90.2320 - case 4: arg1 = stack.pop(); // 60
90.2321 - case 5: stack.push(0); // 3
90.2322 - case 6: arg2 = stack.pop(); // 61
90.2323 - case 7: stack.push(arg0); // 42
90.2324 - case 8: stack.push(stack.pop().offset); // 180 1 99
90.2325 - case 11: arg3 = stack.pop(); // 62
90.2326 - case 12: stack.push(arg0); // 42
90.2327 - case 13: stack.push(stack.pop().value); // 180 1 100
90.2328 - case 16: arg4 = stack.pop() // 58 4
90.2329 - case 18: stack.push(arg2); // 28
90.2330 - case 19: stack.push(arg1); // 27
90.2331 - case 20: if (stack.pop() <= stack.pop()) { gt = 40; continue; } // 162 0 20
90.2332 - case 23: stack.push(arg4); // 25 4
90.2333 - case 25: stack.push(arg3); // 29
90.2334 - case 26: stack.push(arg2); // 28
90.2335 - case 27: stack.push(stack.pop() + stack.pop()); // 96
90.2336 - case 28: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.2337 - case 29: stack.push(32); // 16 32
90.2338 - case 31: if (stack.pop() < stack.pop()) { gt = 40; continue; } // 163 0 9
90.2339 - case 34: arg2++; // 132 2 1
90.2340 - case 37: gt = 18; continue; // 167 255 237
90.2341 - case 40: stack.push(arg2); // 28
90.2342 - case 41: stack.push(arg1); // 27
90.2343 - case 42: if (stack.pop() <= stack.pop()) { gt = 64; continue; } // 162 0 22
90.2344 - case 45: stack.push(arg4); // 25 4
90.2345 - case 47: stack.push(arg3); // 29
90.2346 - case 48: stack.push(arg1); // 27
90.2347 - case 49: stack.push(stack.pop() + stack.pop()); // 96
90.2348 - case 50: stack.push(1); // 4
90.2349 - case 51: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
90.2350 - case 52: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
90.2351 - case 53: stack.push(32); // 16 32
90.2352 - case 55: if (stack.pop() < stack.pop()) { gt = 64; continue; } // 163 0 9
90.2353 - case 58: arg1 += 255; // 132 1 255
90.2354 - case 61: gt = 40; continue; // 167 255 235
90.2355 - case 64: stack.push(arg2); // 28
90.2356 - case 65: if (stack.pop() > 0) { gt = 76; continue; } // 157 0 11
90.2357 - case 68: stack.push(arg1); // 27
90.2358 - case 69: stack.push(arg0); // 42
90.2359 - case 70: stack.push(stack.pop().count); // 180 1 97
90.2360 - case 73: if (stack.pop() <= stack.pop()) { gt = 85; continue; } // 162 0 12
90.2361 - case 76: stack.push(arg0); // 42
90.2362 - case 77: stack.push(arg2); // 28
90.2363 - case 78: stack.push(arg1); // 27
90.2364 - case 79: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.substringLjava_lang_StringII(self, v0, v1)); } // 182 1 147
90.2365 - case 82: gt = 86; continue; // 167 0 4
90.2366 - case 85: stack.push(arg0); // 42
90.2367 - case 86: return stack.pop(); // 176
90.2368 - }
90.2369 -}
90.2370 -*/
90.2371 -function java_lang_String_toStringLjava_lang_String(arg0) {
90.2372 - return arg0.toString();
90.2373 -}
90.2374 -/*
90.2375 -function java_lang_String_toCharArrayAC(arg0) {
90.2376 - var arg1;
90.2377 - var arg2;
90.2378 -;
90.2379 - var stack = new Array(5);
90.2380 - var gt = 0;
90.2381 - for(;;) switch(gt) {
90.2382 - case 0: stack.push(arg0); // 42
90.2383 - case 1: stack.push(stack.pop().count); // 180 1 97
90.2384 - case 4: stack.push(new Array(stack.pop())); // 188 5
90.2385 - case 6: arg1 = stack.pop(); // 76
90.2386 - case 7: stack.push(arg0); // 42
90.2387 - case 8: stack.push(0); // 3
90.2388 - case 9: stack.push(arg0); // 42
90.2389 - case 10: stack.push(stack.pop().count); // 180 1 97
90.2390 - case 13: stack.push(arg1); // 43
90.2391 - case 14: stack.push(0); // 3
90.2392 - case 15: { var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); self.getCharsVIIACAI(self, v0, v1, v2, v3); } // 182 1 138
90.2393 - case 18: stack.push(arg1); // 43
90.2394 - case 19: return stack.pop(); // 176
90.2395 - }
90.2396 -}
90.2397 -function java_lang_String_formatLjava_lang_StringLjava_lang_StringLjava_lang_Object(arg0,arg1) {
90.2398 - var stack = new Array();
90.2399 - var gt = 0;
90.2400 - for(;;) switch(gt) {
90.2401 - case 0: stack.push(new java_util_Formatter); // 187 0 211
90.2402 - case 3: stack.push(stack[stack.length - 1]); // 89
90.2403 - case 4: { java_util_Formatter_consV(stack.pop()); } // 183 1 174
90.2404 - case 7: stack.push(arg0); // 42
90.2405 - case 8: stack.push(arg1); // 43
90.2406 - case 9: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.formatALjava_util_FormatterLjava_lang_StringALjava_lang_Object(self, v0, v1)); } // 182 1 177
90.2407 - case 12: { var self = stack.pop(); stack.push(self.toStringLjava_lang_String(self)); } // 182 1 175
90.2408 - case 15: return stack.pop(); // 176
90.2409 - }
90.2410 -}
90.2411 -function java_lang_String_formatLjava_lang_StringLjava_util_LocaleLjava_lang_StringLjava_lang_Object(arg0,arg1,arg2) {
90.2412 - var stack = new Array();
90.2413 - var gt = 0;
90.2414 - for(;;) switch(gt) {
90.2415 - case 0: stack.push(new java_util_Formatter); // 187 0 211
90.2416 - case 3: stack.push(stack[stack.length - 1]); // 89
90.2417 - case 4: stack.push(arg0); // 42
90.2418 - case 5: { var v0 = stack.pop(); java_util_Formatter_consVLjava_util_Locale(stack.pop(), v0); } // 183 1 176
90.2419 - case 8: stack.push(arg1); // 43
90.2420 - case 9: stack.push(arg2); // 44
90.2421 - case 10: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.formatALjava_util_FormatterLjava_lang_StringALjava_lang_Object(self, v0, v1)); } // 182 1 177
90.2422 - case 13: { var self = stack.pop(); stack.push(self.toStringLjava_lang_String(self)); } // 182 1 175
90.2423 - case 16: return stack.pop(); // 176
90.2424 - }
90.2425 -}
90.2426 -function java_lang_String_valueOfLjava_lang_StringLjava_lang_Object(arg0) {
90.2427 - var stack = new Array();
90.2428 - var gt = 0;
90.2429 - for(;;) switch(gt) {
90.2430 - case 0: stack.push(arg0); // 42
90.2431 - case 1: if (stack.pop()) { gt = 9; continue; } // 199 0 8
90.2432 - case 4: stack.push("null"); // 18 10
90.2433 - case 6: gt = 13; continue; // 167 0 7
90.2434 - case 9: stack.push(arg0); // 42
90.2435 - case 10: { var self = stack.pop(); stack.push(self.toStringLjava_lang_String(self)); } // 182 1 132
90.2436 - case 13: return stack.pop(); // 176
90.2437 - }
90.2438 -}
90.2439 -function java_lang_String_valueOfLjava_lang_StringAC(arg0) {
90.2440 - var stack = new Array();
90.2441 - var gt = 0;
90.2442 - for(;;) switch(gt) {
90.2443 - case 0: stack.push(new java_lang_String); // 187 0 200
90.2444 - case 3: stack.push(stack[stack.length - 1]); // 89
90.2445 - case 4: stack.push(arg0); // 42
90.2446 - case 5: { var v0 = stack.pop(); java_lang_String_consVAC(stack.pop(), v0); } // 183 1 142
90.2447 - case 8: return stack.pop(); // 176
90.2448 - }
90.2449 -}
90.2450 -function java_lang_String_valueOfLjava_lang_StringACII(arg0,arg1,arg2) {
90.2451 - var stack = new Array();
90.2452 - var gt = 0;
90.2453 - for(;;) switch(gt) {
90.2454 - case 0: stack.push(new java_lang_String); // 187 0 200
90.2455 - case 3: stack.push(stack[stack.length - 1]); // 89
90.2456 - case 4: stack.push(arg0); // 42
90.2457 - case 5: stack.push(arg1); // 27
90.2458 - case 6: stack.push(arg2); // 28
90.2459 - case 7: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_String_consVACAIAI(stack.pop(), v0, v1, v2); } // 183 1 143
90.2460 - case 10: return stack.pop(); // 176
90.2461 - }
90.2462 -}
90.2463 -function java_lang_String_copyValueOfLjava_lang_StringACII(arg0,arg1,arg2) {
90.2464 - var stack = new Array();
90.2465 - var gt = 0;
90.2466 - for(;;) switch(gt) {
90.2467 - case 0: stack.push(new java_lang_String); // 187 0 200
90.2468 - case 3: stack.push(stack[stack.length - 1]); // 89
90.2469 - case 4: stack.push(arg0); // 42
90.2470 - case 5: stack.push(arg1); // 27
90.2471 - case 6: stack.push(arg2); // 28
90.2472 - case 7: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_String_consVACAIAI(stack.pop(), v0, v1, v2); } // 183 1 143
90.2473 - case 10: return stack.pop(); // 176
90.2474 - }
90.2475 -}
90.2476 -function java_lang_String_copyValueOfLjava_lang_StringAC(arg0) {
90.2477 - var stack = new Array();
90.2478 - var gt = 0;
90.2479 - for(;;) switch(gt) {
90.2480 - case 0: stack.push(arg0); // 42
90.2481 - case 1: stack.push(0); // 3
90.2482 - case 2: stack.push(arg0); // 42
90.2483 - case 3: stack.push(stack.pop().length); // 190
90.2484 - case 4: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_String_copyValueOfALjava_lang_StringACAIAI(v0, v1, v2)); } // 184 1 155
90.2485 - case 7: return stack.pop(); // 176
90.2486 - }
90.2487 -}
90.2488 -function java_lang_String_valueOfLjava_lang_StringZ(arg0) {
90.2489 - var stack = new Array();
90.2490 - var gt = 0;
90.2491 - for(;;) switch(gt) {
90.2492 - case 0: stack.push(arg0); // 26
90.2493 - case 1: if (stack.pop() == 0) { gt = 9; continue; } // 153 0 8
90.2494 - case 4: stack.push("true"); // 18 12
90.2495 - case 6: gt = 11; continue; // 167 0 5
90.2496 - case 9: stack.push("false"); // 18 8
90.2497 - case 11: return stack.pop(); // 176
90.2498 - }
90.2499 -}
90.2500 -function java_lang_String_valueOfLjava_lang_StringC(arg0) {
90.2501 - var arg1;
90.2502 - var stack = new Array();
90.2503 - var gt = 0;
90.2504 - for(;;) switch(gt) {
90.2505 - case 0: stack.push(1); // 4
90.2506 - case 1: stack.push(new Array(stack.pop())); // 188 5
90.2507 - case 3: stack.push(stack[stack.length - 1]); // 89
90.2508 - case 4: stack.push(0); // 3
90.2509 - case 5: stack.push(arg0); // 26
90.2510 - case 6: { var value = stack.pop(); var indx = stack.pop(); stack.pop()[indx] = value; } // 85
90.2511 - case 7: arg1 = stack.pop(); // 76
90.2512 - case 8: stack.push(new java_lang_String); // 187 0 200
90.2513 - case 11: stack.push(stack[stack.length - 1]); // 89
90.2514 - case 12: stack.push(0); // 3
90.2515 - case 13: stack.push(1); // 4
90.2516 - case 14: stack.push(arg1); // 43
90.2517 - case 15: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_String_consVIIAC(stack.pop(), v0, v1, v2); } // 183 1 137
90.2518 - case 18: return stack.pop(); // 176
90.2519 - }
90.2520 -}
90.2521 -function java_lang_String_valueOfLjava_lang_StringI(arg0) {
90.2522 - var stack = new Array();
90.2523 - var gt = 0;
90.2524 - for(;;) switch(gt) {
90.2525 - case 0: stack.push(arg0); // 26
90.2526 - case 1: stack.push(10); // 16 10
90.2527 - case 3: { var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_Integer_toStringLjava_lang_StringII(v0, v1)); } // 184 1 125
90.2528 - case 6: return stack.pop(); // 176
90.2529 - }
90.2530 -}
90.2531 -function java_lang_String_valueOfLjava_lang_StringJ(arg0) {
90.2532 - var arg1;
90.2533 - var stack = new Array();
90.2534 - var gt = 0;
90.2535 - for(;;) switch(gt) {
90.2536 - case 0: stack.push(arg0); // 30
90.2537 - case 1: stack.push(10); // 16 10
90.2538 - case 3: { var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_Long_toStringLjava_lang_StringJI(v0, v1)); } // 184 1 126
90.2539 - case 6: return stack.pop(); // 176
90.2540 - }
90.2541 -}
90.2542 -function java_lang_String_valueOfLjava_lang_StringF(arg0) {
90.2543 - var stack = new Array();
90.2544 - var gt = 0;
90.2545 - for(;;) switch(gt) {
90.2546 - case 0: stack.push(arg0); // 34
90.2547 - case 1: { var v0 = stack.pop(); stack.push(java_lang_Float_toStringLjava_lang_StringF(v0)); } // 184 1 122
90.2548 - case 4: return stack.pop(); // 176
90.2549 - }
90.2550 -}
90.2551 -function java_lang_String_valueOfLjava_lang_StringD(arg0) {
90.2552 - var arg1;
90.2553 - var stack = new Array();
90.2554 - var gt = 0;
90.2555 - for(;;) switch(gt) {
90.2556 - case 0: stack.push(arg0); // 38
90.2557 - case 1: { var v0 = stack.pop(); stack.push(java_lang_Double_toStringLjava_lang_StringD(v0)); } // 184 1 121
90.2558 - case 4: return stack.pop(); // 176
90.2559 - }
90.2560 -}
90.2561 -function java_lang_String_internLjava_lang_String(arg0) {
90.2562 - // no code found for null
90.2563 -}
90.2564 -function java_lang_String_compareToILjava_lang_Object(arg0,arg1) {
90.2565 - var arg2;
90.2566 -;
90.2567 - var stack = new Array(2);
90.2568 - var gt = 0;
90.2569 - for(;;) switch(gt) {
90.2570 - case 0: stack.push(arg0); // 42
90.2571 - case 1: stack.push(arg1); // 43
90.2572 - case 2: if(stack[stack.length - 1].$instOf_java_lang_String != 1) throw {}; // 192 0 200
90.2573 - case 5: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.compareToILjava_lang_String(self, v0)); } // 182 1 148
90.2574 - case 8: return stack.pop(); // 172
90.2575 - }
90.2576 -}
90.2577 -function java_lang_String_classV() {
90.2578 - var stack = new Array();
90.2579 - var gt = 0;
90.2580 - for(;;) switch(gt) {
90.2581 - case 0: stack.push(0); // 3
90.2582 - case 1: stack.push(new Array(stack.pop())); // 189 0 183
90.2583 - case 4: java_lang_String_serialPersistentFields = stack.pop(); // 179 1 101
90.2584 - case 7: stack.push(new java_lang_String$CaseInsensitiveComparator); // 187 0 202
90.2585 - case 10: stack.push(stack[stack.length - 1]); // 89
90.2586 - case 11: // 1
90.2587 - case 12: { var v0 = stack.pop(); java_lang_String$CaseInsensitiveComparator_consVLjava_lang_String$1(stack.pop(), v0); } // 183 1 160
90.2588 - case 15: java_lang_String_CASE_INSENSITIVE_ORDER = stack.pop(); // 179 1 102
90.2589 - case 18: return; // 177
90.2590 - }
90.2591 -}
90.2592 -*/
90.2593 -var java_lang_String_serialVersionUID = 0;
90.2594 -var java_lang_String_serialPersistentFields = 0;
90.2595 -var java_lang_String_CASE_INSENSITIVE_ORDER = 0;
90.2596 -function java_lang_String() {
90.2597 - /** the real value of this 'string' we delegate to */
90.2598 - this.r = '';
90.2599 -
90.2600 - var self = this;
90.2601 - /*
90.2602 - this.value = 0;
90.2603 - this.offset = 0;
90.2604 - this.count = 0;
90.2605 - this.hash = 0;
90.2606 - */
90.2607 - this.toString = function() { return self.r; };
90.2608 -}
90.2609 -java_lang_String.prototype = new String;
90.2610 -//java_lang_String_classV();
90.2611 -
90.2612 -/* new method for JavaScript String */
90.2613 -String.prototype.charAtCI = java_lang_String_charAtCI;
90.2614 -String.prototype.lengthI = java_lang_String_lengthI;
90.2615 -String.prototype.isEmptyZ = java_lang_String_isEmptyZ;
90.2616 -String.prototype.getCharsVIIACI = java_lang_String_getCharsVIIACAI;
90.2617 -String.prototype.toStringLjava_lang_String = java_lang_String_toStringLjava_lang_String;
90.2618 -String.prototype.$instOf_java_lang_String = true;
90.2619 -String.prototype.$instOf_java_io_Serializable = true;
90.2620 -String.prototype.$instOf_java_lang_Comparable = true;
90.2621 -String.prototype.$instOf_java_lang_CharSequence = true;
90.2622 -
90.2623 -/*
90.2624 - this.lengthI = java_lang_String_lengthI;
90.2625 - this.isEmptyZ = java_lang_String_isEmptyZ;
90.2626 - this.charAtCI = java_lang_String_charAtCI;
90.2627 - this.codePointAtII = java_lang_String_codePointAtII;
90.2628 - this.codePointBeforeII = java_lang_String_codePointBeforeII;
90.2629 - this.codePointCountIII = java_lang_String_codePointCountIII;
90.2630 - this.offsetByCodePointsIII = java_lang_String_offsetByCodePointsIII;
90.2631 - this.getCharsVACI = java_lang_String_getCharsVACI;
90.2632 - this.getCharsVIIACI = java_lang_String_getCharsVIIACI;
90.2633 - this.getBytesVIIABI = java_lang_String_getBytesVIIABI;
90.2634 - this.getBytesABLjava_lang_String = java_lang_String_getBytesABLjava_lang_String;
90.2635 - this.getBytesABLjava_nio_charset_Charset = java_lang_String_getBytesABLjava_nio_charset_Charset;
90.2636 - this.getBytesAB = java_lang_String_getBytesAB;
90.2637 - this.equalsZLjava_lang_Object = java_lang_String_equalsZLjava_lang_Object;
90.2638 - this.contentEqualsZLjava_lang_StringBuffer = java_lang_String_contentEqualsZLjava_lang_StringBuffer;
90.2639 - this.contentEqualsZLjava_lang_CharSequence = java_lang_String_contentEqualsZLjava_lang_CharSequence;
90.2640 - this.equalsIgnoreCaseZLjava_lang_String = java_lang_String_equalsIgnoreCaseZLjava_lang_String;
90.2641 - this.compareToILjava_lang_String = java_lang_String_compareToILjava_lang_String;
90.2642 - this.compareToIgnoreCaseILjava_lang_String = java_lang_String_compareToIgnoreCaseILjava_lang_String;
90.2643 - this.regionMatchesZILjava_lang_StringII = java_lang_String_regionMatchesZILjava_lang_StringII;
90.2644 - this.regionMatchesZZILjava_lang_StringII = java_lang_String_regionMatchesZZILjava_lang_StringII;
90.2645 - this.startsWithZLjava_lang_StringI = java_lang_String_startsWithZLjava_lang_StringI;
90.2646 - this.startsWithZLjava_lang_String = java_lang_String_startsWithZLjava_lang_String;
90.2647 - this.endsWithZLjava_lang_String = java_lang_String_endsWithZLjava_lang_String;
90.2648 - this.hashCodeI = java_lang_String_hashCodeI;
90.2649 - this.indexOfII = java_lang_String_indexOfII;
90.2650 - this.indexOfIII = java_lang_String_indexOfIII;
90.2651 - this.lastIndexOfII = java_lang_String_lastIndexOfII;
90.2652 - this.lastIndexOfIII = java_lang_String_lastIndexOfIII;
90.2653 - this.indexOfILjava_lang_String = java_lang_String_indexOfILjava_lang_String;
90.2654 - this.indexOfILjava_lang_StringI = java_lang_String_indexOfILjava_lang_StringI;
90.2655 - this.lastIndexOfILjava_lang_String = java_lang_String_lastIndexOfILjava_lang_String;
90.2656 - this.lastIndexOfILjava_lang_StringI = java_lang_String_lastIndexOfILjava_lang_StringI;
90.2657 - this.substringLjava_lang_StringI = java_lang_String_substringLjava_lang_StringI;
90.2658 - this.substringLjava_lang_StringII = java_lang_String_substringLjava_lang_StringII;
90.2659 - this.subSequenceLjava_lang_CharSequenceII = java_lang_String_subSequenceLjava_lang_CharSequenceII;
90.2660 - this.concatLjava_lang_StringLjava_lang_String = java_lang_String_concatLjava_lang_StringLjava_lang_String;
90.2661 - this.replaceLjava_lang_StringCC = java_lang_String_replaceLjava_lang_StringCC;
90.2662 - this.matchesZLjava_lang_String = java_lang_String_matchesZLjava_lang_String;
90.2663 - this.containsZLjava_lang_CharSequence = java_lang_String_containsZLjava_lang_CharSequence;
90.2664 - this.replaceFirstLjava_lang_StringLjava_lang_StringLjava_lang_String = java_lang_String_replaceFirstLjava_lang_StringLjava_lang_StringLjava_lang_String;
90.2665 - this.replaceAllLjava_lang_StringLjava_lang_StringLjava_lang_String = java_lang_String_replaceAllLjava_lang_StringLjava_lang_StringLjava_lang_String;
90.2666 - this.replaceLjava_lang_StringLjava_lang_CharSequenceLjava_lang_CharSequence = java_lang_String_replaceLjava_lang_StringLjava_lang_CharSequenceLjava_lang_CharSequence;
90.2667 - this.splitALjava_lang_StringLjava_lang_StringI = java_lang_String_splitALjava_lang_StringLjava_lang_StringI;
90.2668 - this.splitALjava_lang_StringLjava_lang_String = java_lang_String_splitALjava_lang_StringLjava_lang_String;
90.2669 - this.toLowerCaseLjava_lang_StringLjava_util_Locale = java_lang_String_toLowerCaseLjava_lang_StringLjava_util_Locale;
90.2670 - this.toLowerCaseLjava_lang_String = java_lang_String_toLowerCaseLjava_lang_String;
90.2671 - this.toUpperCaseLjava_lang_StringLjava_util_Locale = java_lang_String_toUpperCaseLjava_lang_StringLjava_util_Locale;
90.2672 - this.toUpperCaseLjava_lang_String = java_lang_String_toUpperCaseLjava_lang_String;
90.2673 - this.trimLjava_lang_String = java_lang_String_trimLjava_lang_String;
90.2674 - this.toStringLjava_lang_String = java_lang_String_toStringLjava_lang_String;
90.2675 - this.toCharArrayAC = java_lang_String_toCharArrayAC;
90.2676 - this.internLjava_lang_String = java_lang_String_internLjava_lang_String;
90.2677 - this.compareToILjava_lang_Object = java_lang_String_compareToILjava_lang_Object;
90.2678 - */
90.2679 -
90.2680 -
90.2681 -
90.2682 + return ret;
90.2683 +};
91.1 --- a/htmlpage/pom.xml Thu Oct 11 06:15:22 2012 -0700
91.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
91.3 @@ -1,66 +0,0 @@
91.4 -<?xml version="1.0"?>
91.5 -<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
91.6 - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
91.7 - <modelVersion>4.0.0</modelVersion>
91.8 - <parent>
91.9 - <groupId>org.apidesign</groupId>
91.10 - <artifactId>bck2brwsr</artifactId>
91.11 - <version>1.0-SNAPSHOT</version>
91.12 - </parent>
91.13 - <groupId>org.apidesign</groupId>
91.14 - <artifactId>htmlpage</artifactId>
91.15 - <version>1.0-SNAPSHOT</version>
91.16 - <name>htmlpage</name>
91.17 - <url>http://maven.apache.org</url>
91.18 - <properties>
91.19 - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
91.20 - </properties>
91.21 - <dependencies>
91.22 - <dependency>
91.23 - <groupId>org.testng</groupId>
91.24 - <artifactId>testng</artifactId>
91.25 - <scope>test</scope>
91.26 - <exclusions>
91.27 - <exclusion>
91.28 - <artifactId>junit</artifactId>
91.29 - <groupId>junit</groupId>
91.30 - </exclusion>
91.31 - </exclusions>
91.32 - </dependency>
91.33 - <dependency>
91.34 - <groupId>org.netbeans.api</groupId>
91.35 - <artifactId>org-openide-util-lookup</artifactId>
91.36 - </dependency>
91.37 - <dependency>
91.38 - <groupId>org.apidesign.bck2brwsr</groupId>
91.39 - <artifactId>core</artifactId>
91.40 - <version>1.0-SNAPSHOT</version>
91.41 - <type>jar</type>
91.42 - </dependency>
91.43 - <dependency>
91.44 - <groupId>org.apidesign.bck2brwsr</groupId>
91.45 - <artifactId>emul</artifactId>
91.46 - <version>1.0-SNAPSHOT</version>
91.47 - <type>jar</type>
91.48 - </dependency>
91.49 - <dependency>
91.50 - <groupId>org.apidesign.bck2brwsr</groupId>
91.51 - <artifactId>vm4brwsr</artifactId>
91.52 - <version>0.1-SNAPSHOT</version>
91.53 - <type>jar</type>
91.54 - <scope>test</scope>
91.55 - </dependency>
91.56 - </dependencies>
91.57 - <build>
91.58 - <plugins>
91.59 - <plugin>
91.60 - <groupId>com.mycila.maven-license-plugin</groupId>
91.61 - <artifactId>maven-license-plugin</artifactId>
91.62 - <version>1.9.0</version>
91.63 - <configuration>
91.64 - <header>../vm/src/header.txt</header>
91.65 - </configuration>
91.66 - </plugin>
91.67 - </plugins>
91.68 - </build>
91.69 -</project>
92.1 --- a/htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/PageProcessor.java Thu Oct 11 06:15:22 2012 -0700
92.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
92.3 @@ -1,165 +0,0 @@
92.4 -/**
92.5 - * Java 4 Browser Bytecode Translator
92.6 - * Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
92.7 - *
92.8 - * This program is free software: you can redistribute it and/or modify
92.9 - * it under the terms of the GNU General Public License as published by
92.10 - * the Free Software Foundation, version 2 of the License.
92.11 - *
92.12 - * This program is distributed in the hope that it will be useful,
92.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
92.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
92.15 - * GNU General Public License for more details.
92.16 - *
92.17 - * You should have received a copy of the GNU General Public License
92.18 - * along with this program. Look for COPYING file in the top folder.
92.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
92.20 - */
92.21 -package org.apidesign.bck2brwsr.htmlpage;
92.22 -
92.23 -import java.io.IOException;
92.24 -import java.io.InputStream;
92.25 -import java.io.OutputStreamWriter;
92.26 -import java.io.Writer;
92.27 -import java.util.Locale;
92.28 -import java.util.Set;
92.29 -import javax.annotation.processing.AbstractProcessor;
92.30 -import javax.annotation.processing.Processor;
92.31 -import javax.annotation.processing.RoundEnvironment;
92.32 -import javax.annotation.processing.SupportedAnnotationTypes;
92.33 -import javax.lang.model.element.Element;
92.34 -import javax.lang.model.element.ElementKind;
92.35 -import javax.lang.model.element.ExecutableElement;
92.36 -import javax.lang.model.element.Modifier;
92.37 -import javax.lang.model.element.PackageElement;
92.38 -import javax.lang.model.element.TypeElement;
92.39 -import javax.tools.Diagnostic;
92.40 -import javax.tools.FileObject;
92.41 -import javax.tools.StandardLocation;
92.42 -import org.apidesign.bck2brwsr.htmlpage.api.OnClick;
92.43 -import org.apidesign.bck2brwsr.htmlpage.api.Page;
92.44 -import org.openide.util.lookup.ServiceProvider;
92.45 -
92.46 -/** Annotation processor to process an XHTML page and generate appropriate
92.47 - * "id" file.
92.48 - *
92.49 - * @author Jaroslav Tulach <jtulach@netbeans.org>
92.50 - */
92.51 -@ServiceProvider(service=Processor.class)
92.52 -@SupportedAnnotationTypes({
92.53 - "org.apidesign.bck2brwsr.htmlpage.api.Page",
92.54 - "org.apidesign.bck2brwsr.htmlpage.api.OnClick"
92.55 -})
92.56 -public final class PageProcessor extends AbstractProcessor {
92.57 - @Override
92.58 - public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
92.59 - for (Element e : roundEnv.getElementsAnnotatedWith(Page.class)) {
92.60 - Page p = e.getAnnotation(Page.class);
92.61 - PackageElement pe = (PackageElement)e.getEnclosingElement();
92.62 - String pkg = pe.getQualifiedName().toString();
92.63 -
92.64 - ProcessPage pp;
92.65 - try {
92.66 - InputStream is = openStream(pkg, p.xhtml());
92.67 - pp = ProcessPage.readPage(is);
92.68 - is.close();
92.69 - } catch (IOException iOException) {
92.70 - processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Can't read " + p.xhtml(), e);
92.71 - return false;
92.72 - }
92.73 - Writer w;
92.74 - try {
92.75 - FileObject java = processingEnv.getFiler().createSourceFile(pkg + '.' + p.name(), e);
92.76 - w = new OutputStreamWriter(java.openOutputStream());
92.77 - try {
92.78 - w.append("package " + pkg + ";\n");
92.79 - w.append("import org.apidesign.bck2brwsr.htmlpage.api.*;\n");
92.80 - w.append("class ").append(p.name()).append(" {\n");
92.81 - for (String id : pp.ids()) {
92.82 - String tag = pp.tagNameForId(id);
92.83 - String type = type(tag);
92.84 - w.append(" ").append("public static final ").
92.85 - append(type).append(' ').append(cnstnt(id)).append(" = new ").
92.86 - append(type).append("(\"").append(id).append("\");\n");
92.87 - }
92.88 - w.append(" static {\n");
92.89 - if (!initializeOnClick(pe, w, pp)) {
92.90 - return false;
92.91 - }
92.92 - w.append(" }\n");
92.93 - w.append("}\n");
92.94 - } finally {
92.95 - w.close();
92.96 - }
92.97 - } catch (IOException ex) {
92.98 - processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Can't create " + p.name() + ".java", e);
92.99 - return false;
92.100 - }
92.101 - }
92.102 - return true;
92.103 - }
92.104 -
92.105 - private InputStream openStream(String pkg, String name) throws IOException {
92.106 - FileObject fo = processingEnv.getFiler().getResource(
92.107 - StandardLocation.SOURCE_PATH, pkg, name);
92.108 - try {
92.109 - return fo.openInputStream();
92.110 - } catch (IOException ex) {
92.111 - return processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, pkg, name).openInputStream();
92.112 - }
92.113 - }
92.114 -
92.115 - private static String type(String tag) {
92.116 - if (tag.equals("title")) {
92.117 - return "Title";
92.118 - }
92.119 - if (tag.equals("button")) {
92.120 - return "Button";
92.121 - }
92.122 - if (tag.equals("input")) {
92.123 - return "Input";
92.124 - }
92.125 - return "Element";
92.126 - }
92.127 -
92.128 - private static String cnstnt(String id) {
92.129 - return id.toUpperCase(Locale.ENGLISH).replace('.', '_');
92.130 - }
92.131 -
92.132 - private boolean initializeOnClick(PackageElement pe, Writer w, ProcessPage pp) throws IOException {
92.133 - for (Element clazz : pe.getEnclosedElements()) {
92.134 - if (clazz.getKind() != ElementKind.CLASS) {
92.135 - continue;
92.136 - }
92.137 - TypeElement type = (TypeElement)clazz;
92.138 - for (Element method : clazz.getEnclosedElements()) {
92.139 - OnClick oc = method.getAnnotation(OnClick.class);
92.140 - if (oc != null) {
92.141 - if (pp.tagNameForId(oc.id()) == null) {
92.142 - processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "id = " + oc.id() + " does not exist in the HTML page. Found only " + pp.ids(), method);
92.143 - return false;
92.144 - }
92.145 - ExecutableElement ee = (ExecutableElement)method;
92.146 - if (!ee.getParameters().isEmpty()) {
92.147 - processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@OnClose method can't take arguments", ee);
92.148 - return false;
92.149 - }
92.150 - if (!ee.getModifiers().contains(Modifier.STATIC)) {
92.151 - processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@OnClose method has to be static", ee);
92.152 - return false;
92.153 - }
92.154 - if (ee.getModifiers().contains(Modifier.PRIVATE)) {
92.155 - processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@OnClose method can't be private", ee);
92.156 - return false;
92.157 - }
92.158 - w.append(" ").append(cnstnt(oc.id())).
92.159 - append(".addOnClick(new Runnable() { public void run() {\n");
92.160 - w.append(" ").append(type.getSimpleName().toString()).
92.161 - append('.').append(ee.getSimpleName()).append("();\n");
92.162 - w.append(" }});\n");
92.163 - }
92.164 - }
92.165 - }
92.166 - return true;
92.167 - }
92.168 -}
93.1 --- a/htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/ProcessPage.java Thu Oct 11 06:15:22 2012 -0700
93.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
93.3 @@ -1,78 +0,0 @@
93.4 -/**
93.5 - * Java 4 Browser Bytecode Translator
93.6 - * Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
93.7 - *
93.8 - * This program is free software: you can redistribute it and/or modify
93.9 - * it under the terms of the GNU General Public License as published by
93.10 - * the Free Software Foundation, version 2 of the License.
93.11 - *
93.12 - * This program is distributed in the hope that it will be useful,
93.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
93.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
93.15 - * GNU General Public License for more details.
93.16 - *
93.17 - * You should have received a copy of the GNU General Public License
93.18 - * along with this program. Look for COPYING file in the top folder.
93.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
93.20 - */
93.21 -package org.apidesign.bck2brwsr.htmlpage;
93.22 -
93.23 -import java.io.IOException;
93.24 -import java.io.InputStream;
93.25 -import java.util.Collections;
93.26 -import java.util.Map;
93.27 -import java.util.Set;
93.28 -import java.util.TreeMap;
93.29 -import javax.xml.parsers.DocumentBuilder;
93.30 -import javax.xml.parsers.DocumentBuilderFactory;
93.31 -import org.w3c.dom.Document;
93.32 -import org.w3c.dom.Element;
93.33 -import org.w3c.dom.Node;
93.34 -import org.w3c.dom.NodeList;
93.35 -
93.36 -class ProcessPage {
93.37 - private final Map<String,String> ids2Elems = new TreeMap<String, String>();
93.38 -
93.39 - public Set<String> ids() {
93.40 - return Collections.unmodifiableSet(ids2Elems.keySet());
93.41 - }
93.42 -
93.43 - public String tagNameForId(String id) {
93.44 - return ids2Elems.get(id);
93.45 - }
93.46 -
93.47 - public static ProcessPage readPage(InputStream is) throws IOException {
93.48 - DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
93.49 - f.setValidating(false);
93.50 - f.setIgnoringComments(true);
93.51 -
93.52 - Document doc = null;
93.53 - try {
93.54 - DocumentBuilder b = f.newDocumentBuilder();
93.55 - doc = b.parse(is);
93.56 - } catch (IOException ex) {
93.57 - throw ex;
93.58 - } catch (Exception e) {
93.59 - throw new IOException(e);
93.60 - }
93.61 - Element root = doc.getDocumentElement();
93.62 -
93.63 - ProcessPage pp = new ProcessPage();
93.64 - pp.seekForIds(root);
93.65 - return pp;
93.66 - }
93.67 -
93.68 - private void seekForIds(Element e) {
93.69 - String val = e.getAttribute("id");
93.70 - if (val != null && !val.isEmpty()) {
93.71 - String prev = ids2Elems.put(val, e.getTagName());
93.72 - }
93.73 - NodeList arr = e.getChildNodes();
93.74 - for (int i = 0; i < arr.getLength(); i++) {
93.75 - final Node n = arr.item(i);
93.76 - if (n instanceof Element) {
93.77 - seekForIds((Element)n);
93.78 - }
93.79 - }
93.80 - }
93.81 -}
94.1 --- a/htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Button.java Thu Oct 11 06:15:22 2012 -0700
94.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
94.3 @@ -1,36 +0,0 @@
94.4 -/**
94.5 - * Java 4 Browser Bytecode Translator
94.6 - * Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
94.7 - *
94.8 - * This program is free software: you can redistribute it and/or modify
94.9 - * it under the terms of the GNU General Public License as published by
94.10 - * the Free Software Foundation, version 2 of the License.
94.11 - *
94.12 - * This program is distributed in the hope that it will be useful,
94.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
94.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
94.15 - * GNU General Public License for more details.
94.16 - *
94.17 - * You should have received a copy of the GNU General Public License
94.18 - * along with this program. Look for COPYING file in the top folder.
94.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
94.20 - */
94.21 -package org.apidesign.bck2brwsr.htmlpage.api;
94.22 -
94.23 -/**
94.24 - *
94.25 - * @author Jaroslav Tulach <jtulach@netbeans.org>
94.26 - */
94.27 -public final class Button extends Element {
94.28 - public Button(String id) {
94.29 - super(id);
94.30 - }
94.31 -
94.32 - @Override
94.33 - void dontSubclass() {
94.34 - }
94.35 -
94.36 - public void setDisabled(boolean state) {
94.37 - setAttribute(this, "disabled", state);
94.38 - }
94.39 -}
95.1 --- a/htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java Thu Oct 11 06:15:22 2012 -0700
95.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
95.3 @@ -1,65 +0,0 @@
95.4 -/**
95.5 - * Java 4 Browser Bytecode Translator
95.6 - * Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
95.7 - *
95.8 - * This program is free software: you can redistribute it and/or modify
95.9 - * it under the terms of the GNU General Public License as published by
95.10 - * the Free Software Foundation, version 2 of the License.
95.11 - *
95.12 - * This program is distributed in the hope that it will be useful,
95.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
95.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
95.15 - * GNU General Public License for more details.
95.16 - *
95.17 - * You should have received a copy of the GNU General Public License
95.18 - * along with this program. Look for COPYING file in the top folder.
95.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
95.20 - */
95.21 -package org.apidesign.bck2brwsr.htmlpage.api;
95.22 -
95.23 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
95.24 -
95.25 -/** Represents a generic HTML element.
95.26 - *
95.27 - * @author Jaroslav Tulach <jtulach@netbeans.org>
95.28 - */
95.29 -public abstract class Element {
95.30 - private final String id;
95.31 -
95.32 - public Element(String id) {
95.33 - this.id = id;
95.34 - }
95.35 -
95.36 - abstract void dontSubclass();
95.37 -
95.38 - @JavaScriptBody(
95.39 - args={"el", "property", "value"},
95.40 - body="var e = window.document.getElementById(el.id);\n"
95.41 - + "e[property] = value;\n"
95.42 - )
95.43 - static void setAttribute(Element el, String property, Object value) {
95.44 - throw new UnsupportedOperationException("Needs JavaScript!");
95.45 - }
95.46 -
95.47 - @JavaScriptBody(
95.48 - args={"el", "property"},
95.49 - body="var e = window.document.getElementById(el.id);\n"
95.50 - + "return e[property];\n"
95.51 - )
95.52 - static Object getAttribute(Element el, String property) {
95.53 - throw new UnsupportedOperationException("Needs JavaScript!");
95.54 - }
95.55 -
95.56 - /** Executes given runnable when user performs a "click" on the given
95.57 - * element.
95.58 - * @param r the runnable to execute, never null
95.59 - */
95.60 - @JavaScriptBody(
95.61 - args={"el", "r"},
95.62 - body="var e = window.document.getElementById(el.id);\n"
95.63 - + "e.onclick = function() { r.runV(); };\n"
95.64 - )
95.65 - public final void addOnClick(Runnable r) {
95.66 - throw new UnsupportedOperationException("Needs JavaScript!");
95.67 - }
95.68 -}
96.1 --- a/htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Input.java Thu Oct 11 06:15:22 2012 -0700
96.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
96.3 @@ -1,40 +0,0 @@
96.4 -/**
96.5 - * Java 4 Browser Bytecode Translator
96.6 - * Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
96.7 - *
96.8 - * This program is free software: you can redistribute it and/or modify
96.9 - * it under the terms of the GNU General Public License as published by
96.10 - * the Free Software Foundation, version 2 of the License.
96.11 - *
96.12 - * This program is distributed in the hope that it will be useful,
96.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
96.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
96.15 - * GNU General Public License for more details.
96.16 - *
96.17 - * You should have received a copy of the GNU General Public License
96.18 - * along with this program. Look for COPYING file in the top folder.
96.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
96.20 - */
96.21 -package org.apidesign.bck2brwsr.htmlpage.api;
96.22 -
96.23 -/**
96.24 - *
96.25 - * @author Jaroslav Tulach <jtulach@netbeans.org>
96.26 - */
96.27 -public final class Input extends Element {
96.28 - public Input(String id) {
96.29 - super(id);
96.30 - }
96.31 -
96.32 - @Override
96.33 - void dontSubclass() {
96.34 - }
96.35 -
96.36 - public void setAutocomplete(boolean state) {
96.37 - Element.setAttribute(this, "autocomplete", state);
96.38 - }
96.39 -
96.40 - public final String getValue() {
96.41 - return (String)Element.getAttribute(this, "value");
96.42 - }
96.43 -}
97.1 --- a/htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/OnClick.java Thu Oct 11 06:15:22 2012 -0700
97.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
97.3 @@ -1,21 +0,0 @@
97.4 -/*
97.5 - * To change this template, choose Tools | Templates
97.6 - * and open the template in the editor.
97.7 - */
97.8 -package org.apidesign.bck2brwsr.htmlpage.api;
97.9 -
97.10 -import java.lang.annotation.ElementType;
97.11 -import java.lang.annotation.Retention;
97.12 -import java.lang.annotation.RetentionPolicy;
97.13 -import java.lang.annotation.Target;
97.14 -
97.15 -/** Adds an onClick handler to an element identified by given <em>id</em>.
97.16 - * Apply on a <code>public static void</code> method with no arguments.
97.17 - *
97.18 - * @author Jaroslav Tulach <jtulach@netbeans.org>
97.19 - */
97.20 -@Retention(RetentionPolicy.SOURCE)
97.21 -@Target(ElementType.METHOD)
97.22 -public @interface OnClick {
97.23 - String id();
97.24 -}
98.1 --- a/htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Page.java Thu Oct 11 06:15:22 2012 -0700
98.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
98.3 @@ -1,43 +0,0 @@
98.4 -/**
98.5 - * Java 4 Browser Bytecode Translator
98.6 - * Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
98.7 - *
98.8 - * This program is free software: you can redistribute it and/or modify
98.9 - * it under the terms of the GNU General Public License as published by
98.10 - * the Free Software Foundation, version 2 of the License.
98.11 - *
98.12 - * This program is distributed in the hope that it will be useful,
98.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
98.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
98.15 - * GNU General Public License for more details.
98.16 - *
98.17 - * You should have received a copy of the GNU General Public License
98.18 - * along with this program. Look for COPYING file in the top folder.
98.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
98.20 - */
98.21 -/*
98.22 - * To change this template, choose Tools | Templates
98.23 - * and open the template in the editor.
98.24 - */
98.25 -package org.apidesign.bck2brwsr.htmlpage.api;
98.26 -
98.27 -import java.lang.annotation.ElementType;
98.28 -import java.lang.annotation.Retention;
98.29 -import java.lang.annotation.RetentionPolicy;
98.30 -import java.lang.annotation.Target;
98.31 -
98.32 -/** Converts an XHTML page into a Java class that contains
98.33 - * references to all IDs.
98.34 - *
98.35 - * @author Jaroslav Tulach <jtulach@netbeans.org>
98.36 - */
98.37 -@Retention(RetentionPolicy.SOURCE)
98.38 -@Target(ElementType.TYPE)
98.39 -public @interface Page {
98.40 - /** Path to the XHTML page to read in */
98.41 - String xhtml();
98.42 - /** Name of a Java class to generate. It will contain constants for all
98.43 - * found elements with IDs.
98.44 - */
98.45 - String name();
98.46 -}
99.1 --- a/htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Title.java Thu Oct 11 06:15:22 2012 -0700
99.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
99.3 @@ -1,36 +0,0 @@
99.4 -/**
99.5 - * Java 4 Browser Bytecode Translator
99.6 - * Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
99.7 - *
99.8 - * This program is free software: you can redistribute it and/or modify
99.9 - * it under the terms of the GNU General Public License as published by
99.10 - * the Free Software Foundation, version 2 of the License.
99.11 - *
99.12 - * This program is distributed in the hope that it will be useful,
99.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
99.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
99.15 - * GNU General Public License for more details.
99.16 - *
99.17 - * You should have received a copy of the GNU General Public License
99.18 - * along with this program. Look for COPYING file in the top folder.
99.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
99.20 - */
99.21 -package org.apidesign.bck2brwsr.htmlpage.api;
99.22 -
99.23 -/**
99.24 - *
99.25 - * @author Jaroslav Tulach <jtulach@netbeans.org>
99.26 - */
99.27 -public class Title extends Element {
99.28 - public Title(String id) {
99.29 - super(id);
99.30 - }
99.31 -
99.32 - @Override
99.33 - void dontSubclass() {
99.34 - }
99.35 -
99.36 - public final void setText(String text) {
99.37 - Element.setAttribute(this, "innerHTML", text);
99.38 - }
99.39 -}
100.1 --- a/htmlpage/src/test/java/org/apidesign/bck2brwsr/htmlpage/PageController.java Thu Oct 11 06:15:22 2012 -0700
100.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
100.3 @@ -1,32 +0,0 @@
100.4 -package org.apidesign.bck2brwsr.htmlpage;
100.5 -
100.6 -import org.apidesign.bck2brwsr.htmlpage.api.OnClick;
100.7 -import org.apidesign.bck2brwsr.htmlpage.api.Page;
100.8 -
100.9 -/** Trivial demo for the bck2brwsr project. First of all start
100.10 - * with <a href="TestPage.html">your XHTML page</a>. Include there
100.11 - * a script that will <em>boot Java</em> in your browser.
100.12 - * <p>
100.13 - * Then use <code>@Page</code> annotation to
100.14 - * generate a Java representation of elements with IDs in that page.
100.15 - * Depending on the type of the elements, they will have different
100.16 - * methods (e.g. <code>PG_TITLE</code> has <code>setText</code>, etc.).
100.17 - * Use <code>@OnClick</code> annotation to associate behavior
100.18 - * with existing elements. Use the generated elements
100.19 - * (<code>PG_TITLE</code>, <code>PG_TEXT</code>) to modify the page.
100.20 - * <p>
100.21 - * Everything is type-safe. As soon as somebody modifies the page and
100.22 - * removes the IDs or re-assigns them to wrong elements. Java compiler
100.23 - * will emit an error.
100.24 - * <p>
100.25 - * Welcome to the type-safe HTML5 world!
100.26 - *
100.27 - * @author Jaroslav Tulach <jtulach@netbeans.org>
100.28 - */
100.29 -@Page(xhtml="TestPage.html", name="TestPage")
100.30 -public class PageController {
100.31 - @OnClick(id="pg.button")
100.32 - static void updateTitle() {
100.33 - TestPage.PG_TITLE.setText(TestPage.PG_TEXT.getValue());
100.34 - }
100.35 -}
101.1 --- a/htmlpage/src/test/java/org/apidesign/bck2brwsr/htmlpage/ProcessPageTest.java Thu Oct 11 06:15:22 2012 -0700
101.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
101.3 @@ -1,109 +0,0 @@
101.4 -/**
101.5 - * Java 4 Browser Bytecode Translator
101.6 - * Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
101.7 - *
101.8 - * This program is free software: you can redistribute it and/or modify
101.9 - * it under the terms of the GNU General Public License as published by
101.10 - * the Free Software Foundation, version 2 of the License.
101.11 - *
101.12 - * This program is distributed in the hope that it will be useful,
101.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
101.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
101.15 - * GNU General Public License for more details.
101.16 - *
101.17 - * You should have received a copy of the GNU General Public License
101.18 - * along with this program. Look for COPYING file in the top folder.
101.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
101.20 - */
101.21 -package org.apidesign.bck2brwsr.htmlpage;
101.22 -
101.23 -import java.io.IOException;
101.24 -import java.io.InputStream;
101.25 -import java.lang.reflect.Method;
101.26 -import java.util.Set;
101.27 -import javax.script.Invocable;
101.28 -import javax.script.ScriptEngine;
101.29 -import javax.script.ScriptEngineManager;
101.30 -import javax.script.ScriptException;
101.31 -import org.testng.annotations.Test;
101.32 -import static org.testng.Assert.*;
101.33 -
101.34 -public class ProcessPageTest {
101.35 -
101.36 -
101.37 - @Test public void findsThreeIds() throws IOException {
101.38 - InputStream is = ProcessPageTest.class.getResourceAsStream("TestPage.html");
101.39 - assertNotNull(is, "Sample HTML page found");
101.40 - ProcessPage res = ProcessPage.readPage(is);
101.41 - final Set<String> ids = res.ids();
101.42 - assertEquals(ids.size(), 3, "Three ids found: " + ids);
101.43 -
101.44 - assertEquals(res.tagNameForId("pg.title"), "title");
101.45 - assertEquals(res.tagNameForId("pg.button"), "button");
101.46 - assertEquals(res.tagNameForId("pg.text"), "input");
101.47 - }
101.48 -
101.49 - @Test public void testCompileAndRunPageController() throws Exception {
101.50 - StringBuilder sb = new StringBuilder();
101.51 - sb.append(
101.52 - "var window = new Object();\n"
101.53 - + "var doc = new Object();\n"
101.54 - + "doc.button = new Object();\n"
101.55 - + "doc.title = new Object();\n"
101.56 - + "doc.title.innerHTML = 'nothing';\n"
101.57 - + "doc.text = new Object();\n"
101.58 - + "doc.text.value = 'something';\n"
101.59 - + "doc.getElementById = function(id) {\n"
101.60 - + " switch(id) {\n"
101.61 - + " case 'pg.button': return doc.button;\n"
101.62 - + " case 'pg.title': return doc.title;\n"
101.63 - + " case 'pg.text': return doc.text;\n"
101.64 - + " }\n"
101.65 - + " throw id;\n"
101.66 - + " }\n"
101.67 - + "\n"
101.68 - + "function clickAndCheck() {\n"
101.69 - + " doc.button.onclick();\n"
101.70 - + " return doc.title.innerHTML.toString();\n"
101.71 - + "};\n"
101.72 - + "\n"
101.73 - + "window.document = doc;\n"
101.74 - );
101.75 - Invocable i = compileClass(sb, "org/apidesign/bck2brwsr/htmlpage/PageController");
101.76 -
101.77 - Object ret = null;
101.78 - try {
101.79 - ret = i.invokeFunction("clickAndCheck");
101.80 - } catch (ScriptException ex) {
101.81 - fail("Execution failed in " + sb, ex);
101.82 - } catch (NoSuchMethodException ex) {
101.83 - fail("Cannot find method in " + sb, ex);
101.84 - }
101.85 - assertEquals(ret, "something", "We expect that the JavaCode performs all the wiring");
101.86 - }
101.87 -
101.88 - static Invocable compileClass(StringBuilder sb, String... names) throws ScriptException, IOException {
101.89 - if (sb == null) {
101.90 - sb = new StringBuilder();
101.91 - }
101.92 - try {
101.93 - Method m;
101.94 - Class<?> genJS = Class.forName("org.apidesign.vm4brwsr.GenJS");
101.95 - m = genJS.getDeclaredMethod("compile", Appendable.class, String[].class);
101.96 - m.setAccessible(true);
101.97 - m.invoke(null, sb, names);
101.98 - } catch (Exception exception) {
101.99 - throw new IOException(exception);
101.100 - }
101.101 - ScriptEngineManager sem = new ScriptEngineManager();
101.102 - ScriptEngine js = sem.getEngineByExtension("js");
101.103 - try {
101.104 - Object res = js.eval(sb.toString());
101.105 - assertTrue(js instanceof Invocable, "It is invocable object: " + res);
101.106 - return (Invocable) js;
101.107 - } catch (ScriptException ex) {
101.108 - fail("Could not compile:\n" + sb, ex);
101.109 - return null;
101.110 - }
101.111 - }
101.112 -}
102.1 --- a/htmlpage/src/test/resources/org/apidesign/bck2brwsr/htmlpage/TestPage.html Thu Oct 11 06:15:22 2012 -0700
102.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
102.3 @@ -1,30 +0,0 @@
102.4 -<?xml version="1.0" encoding="UTF-8"?>
102.5 -<!--
102.6 -
102.7 - Java 4 Browser Bytecode Translator
102.8 - Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
102.9 -
102.10 - This program is free software: you can redistribute it and/or modify
102.11 - it under the terms of the GNU General Public License as published by
102.12 - the Free Software Foundation, version 2 of the License.
102.13 -
102.14 - This program is distributed in the hope that it will be useful,
102.15 - but WITHOUT ANY WARRANTY; without even the implied warranty of
102.16 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
102.17 - GNU General Public License for more details.
102.18 -
102.19 - You should have received a copy of the GNU General Public License
102.20 - along with this program. Look for COPYING file in the top folder.
102.21 - If not, see http://opensource.org/licenses/GPL-2.0.
102.22 -
102.23 --->
102.24 -<!DOCTYPE html>
102.25 -<html xmlns="http://www.w3.org/1999/xhtml">
102.26 - <head>
102.27 - <title id="pg.title">Default Title</title>
102.28 - </head>
102.29 - <body>
102.30 - New title: <input id="pg.text"/>
102.31 - <button id="pg.button">Change title!</button>
102.32 - </body>
102.33 -</html>
103.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
103.2 +++ b/javap/pom.xml Wed Jan 23 20:16:48 2013 +0100
103.3 @@ -0,0 +1,41 @@
103.4 +<?xml version="1.0"?>
103.5 +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
103.6 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
103.7 + <modelVersion>4.0.0</modelVersion>
103.8 + <parent>
103.9 + <groupId>org.apidesign</groupId>
103.10 + <artifactId>bck2brwsr</artifactId>
103.11 + <version>0.3-SNAPSHOT</version>
103.12 + </parent>
103.13 + <groupId>org.apidesign.bck2brwsr</groupId>
103.14 + <artifactId>javap</artifactId>
103.15 + <version>0.3-SNAPSHOT</version>
103.16 + <name>javap</name>
103.17 + <url>http://maven.apache.org</url>
103.18 + <properties>
103.19 + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
103.20 + </properties>
103.21 + <build>
103.22 + <plugins>
103.23 + <plugin>
103.24 + <groupId>org.apache.maven.plugins</groupId>
103.25 + <artifactId>maven-compiler-plugin</artifactId>
103.26 + <version>2.5.1</version>
103.27 + <configuration>
103.28 + <compilerArguments>
103.29 + <!--<bootclasspath>non-existing</bootclasspath>-->
103.30 + </compilerArguments>
103.31 + <source>1.6</source>
103.32 + <target>1.6</target>
103.33 + </configuration>
103.34 + </plugin>
103.35 + </plugins>
103.36 + </build>
103.37 + <dependencies>
103.38 + <dependency>
103.39 + <groupId>org.apidesign.bck2brwsr</groupId>
103.40 + <artifactId>emul</artifactId>
103.41 + <version>0.3-SNAPSHOT</version>
103.42 + </dependency>
103.43 + </dependencies>
103.44 +</project>
104.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
104.2 +++ b/javap/src/main/java/org/apidesign/javap/AnnotationParser.java Wed Jan 23 20:16:48 2013 +0100
104.3 @@ -0,0 +1,124 @@
104.4 +/*
104.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
104.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
104.7 + *
104.8 + * This code is free software; you can redistribute it and/or modify it
104.9 + * under the terms of the GNU General Public License version 2 only, as
104.10 + * published by the Free Software Foundation. Oracle designates this
104.11 + * particular file as subject to the "Classpath" exception as provided
104.12 + * by Oracle in the LICENSE file that accompanied this code.
104.13 + *
104.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
104.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
104.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
104.17 + * version 2 for more details (a copy is included in the LICENSE file that
104.18 + * accompanied this code).
104.19 + *
104.20 + * You should have received a copy of the GNU General Public License version
104.21 + * 2 along with this work; if not, write to the Free Software Foundation,
104.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
104.23 + *
104.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
104.25 + * or visit www.oracle.com if you need additional information or have any
104.26 + * questions.
104.27 + */
104.28 +package org.apidesign.javap;
104.29 +
104.30 +import java.io.ByteArrayInputStream;
104.31 +import java.io.DataInputStream;
104.32 +import java.io.IOException;
104.33 +
104.34 +/** An abstract parser for annotation definitions. Analyses the bytes and
104.35 + * performs some callbacks to the overriden parser methods.
104.36 + *
104.37 + * @author Jaroslav Tulach <jtulach@netbeans.org>
104.38 + */
104.39 +public class AnnotationParser {
104.40 + private final boolean textual;
104.41 +
104.42 + protected AnnotationParser(boolean textual) {
104.43 + this.textual = textual;
104.44 + }
104.45 +
104.46 + protected void visitAnnotationStart(String type) throws IOException {
104.47 + }
104.48 +
104.49 + protected void visitAnnotationEnd(String type) throws IOException {
104.50 + }
104.51 +
104.52 + protected void visitAttr(
104.53 + String annoType, String attr, String attrType, String value
104.54 + ) throws IOException {
104.55 + }
104.56 +
104.57 + /** Initialize the parsing with constant pool from <code>cd</code>.
104.58 + *
104.59 + * @param attr the attribute defining annotations
104.60 + * @param cd constant pool
104.61 + * @throws IOException in case I/O fails
104.62 + */
104.63 + public final void parse(byte[] attr, ClassData cd) throws IOException {
104.64 + ByteArrayInputStream is = new ByteArrayInputStream(attr);
104.65 + DataInputStream dis = new DataInputStream(is);
104.66 + try {
104.67 + read(dis, cd);
104.68 + } finally {
104.69 + is.close();
104.70 + }
104.71 + }
104.72 +
104.73 + private void read(DataInputStream dis, ClassData cd) throws IOException {
104.74 + int cnt = dis.readUnsignedShort();
104.75 + for (int i = 0; i < cnt; i++) {
104.76 + readAnno(dis, cd);
104.77 + }
104.78 + }
104.79 +
104.80 + private void readAnno(DataInputStream dis, ClassData cd) throws IOException {
104.81 + int type = dis.readUnsignedShort();
104.82 + String typeName = cd.StringValue(type);
104.83 + visitAnnotationStart(typeName);
104.84 + int cnt = dis.readUnsignedShort();
104.85 + for (int i = 0; i < cnt; i++) {
104.86 + String attrName = cd.StringValue(dis.readUnsignedShort());
104.87 + readValue(dis, cd, typeName, attrName);
104.88 + }
104.89 + visitAnnotationEnd(typeName);
104.90 + if (cnt == 0) {
104.91 + visitAttr(typeName, null, null, null);
104.92 + }
104.93 + }
104.94 +
104.95 + private void readValue(DataInputStream dis, ClassData cd, String typeName, String attrName)
104.96 + throws IOException {
104.97 + char type = (char)dis.readByte();
104.98 + if (type == '@') {
104.99 + readAnno(dis, cd);
104.100 + } else if ("CFJZsSIDB".indexOf(type) >= 0) { // NOI18N
104.101 + int primitive = dis.readUnsignedShort();
104.102 + String val = cd.stringValue(primitive, textual);
104.103 + String attrType;
104.104 + if (type == 's') {
104.105 + attrType = "Ljava_lang_String_2";
104.106 + if (textual) {
104.107 + val = '"' + val + '"';
104.108 + }
104.109 + } else {
104.110 + attrType = "" + type;
104.111 + }
104.112 + visitAttr(typeName, attrName, attrType, val);
104.113 + } else if (type == 'c') {
104.114 + int cls = dis.readUnsignedShort();
104.115 + } else if (type == '[') {
104.116 + int cnt = dis.readUnsignedShort();
104.117 + for (int i = 0; i < cnt; i++) {
104.118 + readValue(dis, cd, typeName, attrName);
104.119 + }
104.120 + } else if (type == 'e') {
104.121 + int enumT = dis.readUnsignedShort();
104.122 + int enumN = dis.readUnsignedShort();
104.123 + } else {
104.124 + throw new IOException("Unknown type " + type);
104.125 + }
104.126 + }
104.127 +}
105.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
105.2 +++ b/javap/src/main/java/org/apidesign/javap/AttrData.java Wed Jan 23 20:16:48 2013 +0100
105.3 @@ -0,0 +1,77 @@
105.4 +/*
105.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
105.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
105.7 + *
105.8 + * This code is free software; you can redistribute it and/or modify it
105.9 + * under the terms of the GNU General Public License version 2 only, as
105.10 + * published by the Free Software Foundation. Oracle designates this
105.11 + * particular file as subject to the "Classpath" exception as provided
105.12 + * by Oracle in the LICENSE file that accompanied this code.
105.13 + *
105.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
105.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
105.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
105.17 + * version 2 for more details (a copy is included in the LICENSE file that
105.18 + * accompanied this code).
105.19 + *
105.20 + * You should have received a copy of the GNU General Public License version
105.21 + * 2 along with this work; if not, write to the Free Software Foundation,
105.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
105.23 + *
105.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
105.25 + * or visit www.oracle.com if you need additional information or have any
105.26 + * questions.
105.27 + */
105.28 +
105.29 +
105.30 +
105.31 +package org.apidesign.javap;
105.32 +
105.33 +import java.io.*;
105.34 +
105.35 +/**
105.36 + * Reads and stores attribute information.
105.37 + *
105.38 + * @author Sucheta Dambalkar (Adopted code from jdis)
105.39 + */
105.40 +class AttrData {
105.41 + ClassData cls;
105.42 + int name_cpx;
105.43 + int datalen;
105.44 + byte data[];
105.45 +
105.46 + public AttrData (ClassData cls) {
105.47 + this.cls=cls;
105.48 + }
105.49 +
105.50 + /**
105.51 + * Reads unknown attribute.
105.52 + */
105.53 + public void read(int name_cpx, DataInputStream in) throws IOException {
105.54 + this.name_cpx=name_cpx;
105.55 + datalen=in.readInt();
105.56 + data=new byte[datalen];
105.57 + in.readFully(data);
105.58 + }
105.59 +
105.60 + /**
105.61 + * Reads just the name of known attribute.
105.62 + */
105.63 + public void read(int name_cpx){
105.64 + this.name_cpx=name_cpx;
105.65 + }
105.66 +
105.67 + /**
105.68 + * Returns attribute name.
105.69 + */
105.70 + public String getAttrName(){
105.71 + return cls.getString(name_cpx);
105.72 + }
105.73 +
105.74 + /**
105.75 + * Returns attribute data.
105.76 + */
105.77 + public byte[] getData(){
105.78 + return data;
105.79 + }
105.80 +}
106.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
106.2 +++ b/javap/src/main/java/org/apidesign/javap/CPX.java Wed Jan 23 20:16:48 2013 +0100
106.3 @@ -0,0 +1,40 @@
106.4 +/*
106.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
106.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
106.7 + *
106.8 + * This code is free software; you can redistribute it and/or modify it
106.9 + * under the terms of the GNU General Public License version 2 only, as
106.10 + * published by the Free Software Foundation. Oracle designates this
106.11 + * particular file as subject to the "Classpath" exception as provided
106.12 + * by Oracle in the LICENSE file that accompanied this code.
106.13 + *
106.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
106.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
106.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
106.17 + * version 2 for more details (a copy is included in the LICENSE file that
106.18 + * accompanied this code).
106.19 + *
106.20 + * You should have received a copy of the GNU General Public License version
106.21 + * 2 along with this work; if not, write to the Free Software Foundation,
106.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
106.23 + *
106.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
106.25 + * or visit www.oracle.com if you need additional information or have any
106.26 + * questions.
106.27 + */
106.28 +
106.29 +
106.30 +package org.apidesign.javap;
106.31 +
106.32 +/**
106.33 + * Stores constant pool entry information with one field.
106.34 + *
106.35 + * @author Sucheta Dambalkar (Adopted code from jdis)
106.36 + */
106.37 +class CPX {
106.38 + int cpx;
106.39 +
106.40 + CPX (int cpx) {
106.41 + this.cpx=cpx;
106.42 + }
106.43 +}
107.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
107.2 +++ b/javap/src/main/java/org/apidesign/javap/CPX2.java Wed Jan 23 20:16:48 2013 +0100
107.3 @@ -0,0 +1,41 @@
107.4 +/*
107.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
107.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
107.7 + *
107.8 + * This code is free software; you can redistribute it and/or modify it
107.9 + * under the terms of the GNU General Public License version 2 only, as
107.10 + * published by the Free Software Foundation. Oracle designates this
107.11 + * particular file as subject to the "Classpath" exception as provided
107.12 + * by Oracle in the LICENSE file that accompanied this code.
107.13 + *
107.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
107.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
107.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
107.17 + * version 2 for more details (a copy is included in the LICENSE file that
107.18 + * accompanied this code).
107.19 + *
107.20 + * You should have received a copy of the GNU General Public License version
107.21 + * 2 along with this work; if not, write to the Free Software Foundation,
107.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
107.23 + *
107.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
107.25 + * or visit www.oracle.com if you need additional information or have any
107.26 + * questions.
107.27 + */
107.28 +
107.29 +
107.30 +package org.apidesign.javap;
107.31 +
107.32 +/**
107.33 + * Stores constant pool entry information with two fields.
107.34 + *
107.35 + * @author Sucheta Dambalkar (Adopted code from jdis)
107.36 + */
107.37 +class CPX2 {
107.38 + int cpx1,cpx2;
107.39 +
107.40 + CPX2 (int cpx1, int cpx2) {
107.41 + this.cpx1=cpx1;
107.42 + this.cpx2=cpx2;
107.43 + }
107.44 +}
108.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
108.2 +++ b/javap/src/main/java/org/apidesign/javap/ClassData.java Wed Jan 23 20:16:48 2013 +0100
108.3 @@ -0,0 +1,713 @@
108.4 +/*
108.5 + * Copyright (c) 2002, 2004, Oracle and/or its affiliates. All rights reserved.
108.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
108.7 + *
108.8 + * This code is free software; you can redistribute it and/or modify it
108.9 + * under the terms of the GNU General Public License version 2 only, as
108.10 + * published by the Free Software Foundation. Oracle designates this
108.11 + * particular file as subject to the "Classpath" exception as provided
108.12 + * by Oracle in the LICENSE file that accompanied this code.
108.13 + *
108.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
108.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
108.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
108.17 + * version 2 for more details (a copy is included in the LICENSE file that
108.18 + * accompanied this code).
108.19 + *
108.20 + * You should have received a copy of the GNU General Public License version
108.21 + * 2 along with this work; if not, write to the Free Software Foundation,
108.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
108.23 + *
108.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
108.25 + * or visit www.oracle.com if you need additional information or have any
108.26 + * questions.
108.27 + */
108.28 +
108.29 +
108.30 +package org.apidesign.javap;
108.31 +
108.32 +import java.io.*;
108.33 +
108.34 +/**
108.35 + * Central data repository of the Java Disassembler.
108.36 + * Stores all the information in java class file.
108.37 + *
108.38 + * @author Sucheta Dambalkar (Adopted code from jdis)
108.39 + */
108.40 +public final class ClassData implements RuntimeConstants {
108.41 +
108.42 + private int magic;
108.43 + private int minor_version;
108.44 + private int major_version;
108.45 + private int cpool_count;
108.46 + private Object cpool[];
108.47 + private int access;
108.48 + private int this_class = 0;;
108.49 + private int super_class;
108.50 + private int interfaces_count;
108.51 + private int[] interfaces = new int[0];;
108.52 + private int fields_count;
108.53 + private FieldData[] fields;
108.54 + private int methods_count;
108.55 + private MethodData[] methods;
108.56 + private InnerClassData[] innerClasses;
108.57 + private int attributes_count;
108.58 + private AttrData[] attrs;
108.59 + private String classname;
108.60 + private String superclassname;
108.61 + private int source_cpx=0;
108.62 + private byte tags[];
108.63 + private Hashtable indexHashAscii = new Hashtable();
108.64 + private String pkgPrefix="";
108.65 + private int pkgPrefixLen=0;
108.66 +
108.67 + /**
108.68 + * Read classfile to disassemble.
108.69 + */
108.70 + public ClassData(InputStream infile) throws IOException {
108.71 + this.read(new DataInputStream(infile));
108.72 + }
108.73 +
108.74 + /**
108.75 + * Reads and stores class file information.
108.76 + */
108.77 + public void read(DataInputStream in) throws IOException {
108.78 + // Read the header
108.79 + magic = in.readInt();
108.80 + if (magic != JAVA_MAGIC) {
108.81 + throw new ClassFormatError("wrong magic: " +
108.82 + toHex(magic) + ", expected " +
108.83 + toHex(JAVA_MAGIC));
108.84 + }
108.85 + minor_version = in.readShort();
108.86 + major_version = in.readShort();
108.87 + if (major_version != JAVA_VERSION) {
108.88 + }
108.89 +
108.90 + // Read the constant pool
108.91 + readCP(in);
108.92 + access = in.readUnsignedShort();
108.93 + this_class = in.readUnsignedShort();
108.94 + super_class = in.readUnsignedShort();
108.95 +
108.96 + //Read interfaces.
108.97 + interfaces_count = in.readUnsignedShort();
108.98 + if(interfaces_count > 0){
108.99 + interfaces = new int[interfaces_count];
108.100 + }
108.101 + for (int i = 0; i < interfaces_count; i++) {
108.102 + interfaces[i]=in.readShort();
108.103 + }
108.104 +
108.105 + // Read the fields
108.106 + readFields(in);
108.107 +
108.108 + // Read the methods
108.109 + readMethods(in);
108.110 +
108.111 + // Read the attributes
108.112 + attributes_count = in.readUnsignedShort();
108.113 + attrs=new AttrData[attributes_count];
108.114 + for (int k = 0; k < attributes_count; k++) {
108.115 + int name_cpx=in.readUnsignedShort();
108.116 + if (getTag(name_cpx)==CONSTANT_UTF8
108.117 + && getString(name_cpx).equals("SourceFile")
108.118 + ){ if (in.readInt()!=2)
108.119 + throw new ClassFormatError("invalid attr length");
108.120 + source_cpx=in.readUnsignedShort();
108.121 + AttrData attr=new AttrData(this);
108.122 + attr.read(name_cpx);
108.123 + attrs[k]=attr;
108.124 +
108.125 + } else if (getTag(name_cpx)==CONSTANT_UTF8
108.126 + && getString(name_cpx).equals("InnerClasses")
108.127 + ){ int length=in.readInt();
108.128 + int num=in.readUnsignedShort();
108.129 + if (2+num*8 != length)
108.130 + throw new ClassFormatError("invalid attr length");
108.131 + innerClasses=new InnerClassData[num];
108.132 + for (int j = 0; j < num; j++) {
108.133 + InnerClassData innerClass=new InnerClassData(this);
108.134 + innerClass.read(in);
108.135 + innerClasses[j]=innerClass;
108.136 + }
108.137 + AttrData attr=new AttrData(this);
108.138 + attr.read(name_cpx);
108.139 + attrs[k]=attr;
108.140 + } else {
108.141 + AttrData attr=new AttrData(this);
108.142 + attr.read(name_cpx, in);
108.143 + attrs[k]=attr;
108.144 + }
108.145 + }
108.146 + in.close();
108.147 + } // end ClassData.read()
108.148 +
108.149 + /**
108.150 + * Reads and stores constant pool info.
108.151 + */
108.152 + void readCP(DataInputStream in) throws IOException {
108.153 + cpool_count = in.readUnsignedShort();
108.154 + tags = new byte[cpool_count];
108.155 + cpool = new Object[cpool_count];
108.156 + for (int i = 1; i < cpool_count; i++) {
108.157 + byte tag = in.readByte();
108.158 +
108.159 + switch(tags[i] = tag) {
108.160 + case CONSTANT_UTF8:
108.161 + String str=in.readUTF();
108.162 + indexHashAscii.put(cpool[i] = str, new Integer(i));
108.163 + break;
108.164 + case CONSTANT_INTEGER:
108.165 + cpool[i] = new Integer(in.readInt());
108.166 + break;
108.167 + case CONSTANT_FLOAT:
108.168 + cpool[i] = new Float(in.readFloat());
108.169 + break;
108.170 + case CONSTANT_LONG:
108.171 + cpool[i++] = new Long(in.readLong());
108.172 + break;
108.173 + case CONSTANT_DOUBLE:
108.174 + cpool[i++] = new Double(in.readDouble());
108.175 + break;
108.176 + case CONSTANT_CLASS:
108.177 + case CONSTANT_STRING:
108.178 + cpool[i] = new CPX(in.readUnsignedShort());
108.179 + break;
108.180 +
108.181 + case CONSTANT_FIELD:
108.182 + case CONSTANT_METHOD:
108.183 + case CONSTANT_INTERFACEMETHOD:
108.184 + case CONSTANT_NAMEANDTYPE:
108.185 + cpool[i] = new CPX2(in.readUnsignedShort(), in.readUnsignedShort());
108.186 + break;
108.187 +
108.188 + case 0:
108.189 + default:
108.190 + throw new ClassFormatError("invalid constant type: " + (int)tags[i]);
108.191 + }
108.192 + }
108.193 + }
108.194 +
108.195 + /**
108.196 + * Reads and strores field info.
108.197 + */
108.198 + protected void readFields(DataInputStream in) throws IOException {
108.199 + int fields_count = in.readUnsignedShort();
108.200 + fields=new FieldData[fields_count];
108.201 + for (int k = 0; k < fields_count; k++) {
108.202 + FieldData field=new FieldData(this);
108.203 + field.read(in);
108.204 + fields[k]=field;
108.205 + }
108.206 + }
108.207 +
108.208 + /**
108.209 + * Reads and strores Method info.
108.210 + */
108.211 + protected void readMethods(DataInputStream in) throws IOException {
108.212 + int methods_count = in.readUnsignedShort();
108.213 + methods=new MethodData[methods_count];
108.214 + for (int k = 0; k < methods_count ; k++) {
108.215 + MethodData method=new MethodData(this);
108.216 + method.read(in);
108.217 + methods[k]=method;
108.218 + }
108.219 + }
108.220 +
108.221 + /**
108.222 + * get a string
108.223 + */
108.224 + public String getString(int n) {
108.225 + if (n == 0) {
108.226 + return null;
108.227 + } else {
108.228 + return (String)cpool[n];
108.229 + }
108.230 + }
108.231 +
108.232 + /**
108.233 + * get the type of constant given an index
108.234 + */
108.235 + public byte getTag(int n) {
108.236 + try{
108.237 + return tags[n];
108.238 + } catch (ArrayIndexOutOfBoundsException e) {
108.239 + return (byte)100;
108.240 + }
108.241 + }
108.242 +
108.243 + static final String hexString="0123456789ABCDEF";
108.244 +
108.245 + public static char hexTable[]=hexString.toCharArray();
108.246 +
108.247 + static String toHex(long val, int width) {
108.248 + StringBuffer s = new StringBuffer();
108.249 + for (int i=width-1; i>=0; i--)
108.250 + s.append(hexTable[((int)(val>>(4*i)))&0xF]);
108.251 + return "0x"+s.toString();
108.252 + }
108.253 +
108.254 + static String toHex(long val) {
108.255 + int width;
108.256 + for (width=16; width>0; width--) {
108.257 + if ((val>>(width-1)*4)!=0) break;
108.258 + }
108.259 + return toHex(val, width);
108.260 + }
108.261 +
108.262 + static String toHex(int val) {
108.263 + int width;
108.264 + for (width=8; width>0; width--) {
108.265 + if ((val>>(width-1)*4)!=0) break;
108.266 + }
108.267 + return toHex(val, width);
108.268 + }
108.269 +
108.270 + /**
108.271 + * Returns the name of this class.
108.272 + */
108.273 + public String getClassName() {
108.274 + String res=null;
108.275 + if (this_class==0) {
108.276 + return res;
108.277 + }
108.278 + int tcpx;
108.279 + try {
108.280 + if (tags[this_class]!=CONSTANT_CLASS) {
108.281 + return res; //"<CP["+cpx+"] is not a Class> ";
108.282 + }
108.283 + tcpx=((CPX)cpool[this_class]).cpx;
108.284 + } catch (ArrayIndexOutOfBoundsException e) {
108.285 + return res; // "#"+cpx+"// invalid constant pool index";
108.286 + } catch (Throwable e) {
108.287 + return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
108.288 + }
108.289 +
108.290 + try {
108.291 + return (String)(cpool[tcpx]);
108.292 + } catch (ArrayIndexOutOfBoundsException e) {
108.293 + return res; // "class #"+scpx+"// invalid constant pool index";
108.294 + } catch (ClassCastException e) {
108.295 + return res; // "class #"+scpx+"// invalid constant pool reference";
108.296 + } catch (Throwable e) {
108.297 + return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
108.298 + }
108.299 +
108.300 + }
108.301 +
108.302 + /**
108.303 + * Returns the name of class at perticular index.
108.304 + */
108.305 + public String getClassName(int cpx) {
108.306 + String res="#"+cpx;
108.307 + if (cpx==0) {
108.308 + return res;
108.309 + }
108.310 + int scpx;
108.311 + try {
108.312 + if (tags[cpx]!=CONSTANT_CLASS) {
108.313 + return res; //"<CP["+cpx+"] is not a Class> ";
108.314 + }
108.315 + scpx=((CPX)cpool[cpx]).cpx;
108.316 + } catch (ArrayIndexOutOfBoundsException e) {
108.317 + return res; // "#"+cpx+"// invalid constant pool index";
108.318 + } catch (Throwable e) {
108.319 + return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
108.320 + }
108.321 + res="#"+scpx;
108.322 + try {
108.323 + return (String)(cpool[scpx]);
108.324 + } catch (ArrayIndexOutOfBoundsException e) {
108.325 + return res; // "class #"+scpx+"// invalid constant pool index";
108.326 + } catch (ClassCastException e) {
108.327 + return res; // "class #"+scpx+"// invalid constant pool reference";
108.328 + } catch (Throwable e) {
108.329 + return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
108.330 + }
108.331 + }
108.332 +
108.333 + public int getAccessFlags() {
108.334 + return access;
108.335 + }
108.336 +
108.337 + /**
108.338 + * Returns true if it is a class
108.339 + */
108.340 + public boolean isClass() {
108.341 + if((access & ACC_INTERFACE) == 0) return true;
108.342 + return false;
108.343 + }
108.344 +
108.345 + /**
108.346 + * Returns true if it is a interface.
108.347 + */
108.348 + public boolean isInterface(){
108.349 + if((access & ACC_INTERFACE) != 0) return true;
108.350 + return false;
108.351 + }
108.352 +
108.353 + /**
108.354 + * Returns true if this member is public, false otherwise.
108.355 + */
108.356 + public boolean isPublic(){
108.357 + return (access & ACC_PUBLIC) != 0;
108.358 + }
108.359 +
108.360 + /**
108.361 + * Returns the access of this class or interface.
108.362 + */
108.363 + public String[] getAccess(){
108.364 + Vector v = new Vector();
108.365 + if ((access & ACC_PUBLIC) !=0) v.addElement("public");
108.366 + if ((access & ACC_FINAL) !=0) v.addElement("final");
108.367 + if ((access & ACC_ABSTRACT) !=0) v.addElement("abstract");
108.368 + String[] accflags = new String[v.size()];
108.369 + v.copyInto(accflags);
108.370 + return accflags;
108.371 + }
108.372 +
108.373 + /**
108.374 + * Returns list of innerclasses.
108.375 + */
108.376 + public InnerClassData[] getInnerClasses(){
108.377 + return innerClasses;
108.378 + }
108.379 +
108.380 + /**
108.381 + * Returns list of attributes.
108.382 + */
108.383 + final AttrData[] getAttributes(){
108.384 + return attrs;
108.385 + }
108.386 +
108.387 + public byte[] findAnnotationData(boolean classRetention) {
108.388 + String n = classRetention ?
108.389 + "RuntimeInvisibleAnnotations" : // NOI18N
108.390 + "RuntimeVisibleAnnotations"; // NOI18N
108.391 + return findAttr(n, attrs);
108.392 + }
108.393 +
108.394 + /**
108.395 + * Returns true if superbit is set.
108.396 + */
108.397 + public boolean isSuperSet(){
108.398 + if ((access & ACC_SUPER) !=0) return true;
108.399 + return false;
108.400 + }
108.401 +
108.402 + /**
108.403 + * Returns super class name.
108.404 + */
108.405 + public String getSuperClassName(){
108.406 + String res=null;
108.407 + if (super_class==0) {
108.408 + return res;
108.409 + }
108.410 + int scpx;
108.411 + try {
108.412 + if (tags[super_class]!=CONSTANT_CLASS) {
108.413 + return res; //"<CP["+cpx+"] is not a Class> ";
108.414 + }
108.415 + scpx=((CPX)cpool[super_class]).cpx;
108.416 + } catch (ArrayIndexOutOfBoundsException e) {
108.417 + return res; // "#"+cpx+"// invalid constant pool index";
108.418 + } catch (Throwable e) {
108.419 + return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
108.420 + }
108.421 +
108.422 + try {
108.423 + return (String)(cpool[scpx]);
108.424 + } catch (ArrayIndexOutOfBoundsException e) {
108.425 + return res; // "class #"+scpx+"// invalid constant pool index";
108.426 + } catch (ClassCastException e) {
108.427 + return res; // "class #"+scpx+"// invalid constant pool reference";
108.428 + } catch (Throwable e) {
108.429 + return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
108.430 + }
108.431 + }
108.432 +
108.433 + /**
108.434 + * Returns list of super interfaces.
108.435 + */
108.436 + public String[] getSuperInterfaces(){
108.437 + String interfacenames[] = new String[interfaces.length];
108.438 + int interfacecpx = -1;
108.439 + for(int i = 0; i < interfaces.length; i++){
108.440 + interfacecpx=((CPX)cpool[interfaces[i]]).cpx;
108.441 + interfacenames[i] = (String)(cpool[interfacecpx]);
108.442 + }
108.443 + return interfacenames;
108.444 + }
108.445 +
108.446 + /**
108.447 + * Returns string at prticular constant pool index.
108.448 + */
108.449 + public String getStringValue(int cpoolx) {
108.450 + try {
108.451 + return ((String)cpool[cpoolx]);
108.452 + } catch (ArrayIndexOutOfBoundsException e) {
108.453 + return "//invalid constant pool index:"+cpoolx;
108.454 + } catch (ClassCastException e) {
108.455 + return "//invalid constant pool ref:"+cpoolx;
108.456 + }
108.457 + }
108.458 +
108.459 + /**
108.460 + * Returns list of field info.
108.461 + */
108.462 + public FieldData[] getFields(){
108.463 + return fields;
108.464 + }
108.465 +
108.466 + /**
108.467 + * Returns list of method info.
108.468 + */
108.469 + public MethodData[] getMethods(){
108.470 + return methods;
108.471 + }
108.472 +
108.473 + /**
108.474 + * Returns constant pool entry at that index.
108.475 + */
108.476 + public CPX2 getCpoolEntry(int cpx){
108.477 + return ((CPX2)(cpool[cpx]));
108.478 + }
108.479 +
108.480 + public Object getCpoolEntryobj(int cpx){
108.481 + return (cpool[cpx]);
108.482 + }
108.483 +
108.484 + /**
108.485 + * Returns index of this class.
108.486 + */
108.487 + public int getthis_cpx(){
108.488 + return this_class;
108.489 + }
108.490 +
108.491 + /**
108.492 + * Returns string at that index.
108.493 + */
108.494 + public String StringValue(int cpx) {
108.495 + return stringValue(cpx, false);
108.496 + }
108.497 + public String stringValue(int cpx, boolean textual) {
108.498 + return stringValue(cpx, textual, null);
108.499 + }
108.500 + public String stringValue(int cpx, String[] classRefs) {
108.501 + return stringValue(cpx, true, classRefs);
108.502 + }
108.503 + private String stringValue(int cpx, boolean textual, String[] refs) {
108.504 + if (cpx==0) return "#0";
108.505 + int tag;
108.506 + Object x;
108.507 + String suffix="";
108.508 + try {
108.509 + tag=tags[cpx];
108.510 + x=cpool[cpx];
108.511 + } catch (IndexOutOfBoundsException e) {
108.512 + return "<Incorrect CP index:"+cpx+">";
108.513 + }
108.514 +
108.515 + if (x==null) return "<NULL>";
108.516 + switch (tag) {
108.517 + case CONSTANT_UTF8: {
108.518 + if (!textual) {
108.519 + return (String)x;
108.520 + }
108.521 + StringBuilder sb=new StringBuilder();
108.522 + String s=(String)x;
108.523 + for (int k=0; k<s.length(); k++) {
108.524 + char c=s.charAt(k);
108.525 + switch (c) {
108.526 + case '\\': sb.append('\\').append('\\'); break;
108.527 + case '\t': sb.append('\\').append('t'); break;
108.528 + case '\n': sb.append('\\').append('n'); break;
108.529 + case '\r': sb.append('\\').append('r'); break;
108.530 + case '\"': sb.append('\\').append('\"'); break;
108.531 + default: sb.append(c);
108.532 + }
108.533 + }
108.534 + return sb.toString();
108.535 + }
108.536 + case CONSTANT_DOUBLE: {
108.537 + Double d=(Double)x;
108.538 + String sd=d.toString();
108.539 + if (textual) {
108.540 + return sd;
108.541 + }
108.542 + return sd+"d";
108.543 + }
108.544 + case CONSTANT_FLOAT: {
108.545 + Float f=(Float)x;
108.546 + String sf=(f).toString();
108.547 + if (textual) {
108.548 + return sf;
108.549 + }
108.550 + return sf+"f";
108.551 + }
108.552 + case CONSTANT_LONG: {
108.553 + Long ln = (Long)x;
108.554 + if (textual) {
108.555 + return ln.toString();
108.556 + }
108.557 + return ln.toString()+'l';
108.558 + }
108.559 + case CONSTANT_INTEGER: {
108.560 + Integer in = (Integer)x;
108.561 + return in.toString();
108.562 + }
108.563 + case CONSTANT_CLASS:
108.564 + String jn = getClassName(cpx);
108.565 + if (textual) {
108.566 + if (refs != null) {
108.567 + refs[0] = jn;
108.568 + }
108.569 + return jn;
108.570 + }
108.571 + return javaName(jn);
108.572 + case CONSTANT_STRING:
108.573 + String sv = stringValue(((CPX)x).cpx, textual);
108.574 + if (textual) {
108.575 + return '"' + sv + '"';
108.576 + } else {
108.577 + return sv;
108.578 + }
108.579 + case CONSTANT_FIELD:
108.580 + case CONSTANT_METHOD:
108.581 + case CONSTANT_INTERFACEMETHOD:
108.582 + //return getShortClassName(((CPX2)x).cpx1)+"."+StringValue(((CPX2)x).cpx2);
108.583 + return javaName(getClassName(((CPX2)x).cpx1))+"."+StringValue(((CPX2)x).cpx2);
108.584 +
108.585 + case CONSTANT_NAMEANDTYPE:
108.586 + return getName(((CPX2)x).cpx1)+":"+StringValue(((CPX2)x).cpx2);
108.587 + default:
108.588 + return "UnknownTag"; //TBD
108.589 + }
108.590 + }
108.591 +
108.592 + /**
108.593 + * Returns resolved java type name.
108.594 + */
108.595 + public String javaName(String name) {
108.596 + if( name==null) return "null";
108.597 + int len=name.length();
108.598 + if (len==0) return "\"\"";
108.599 + int cc='/';
108.600 + fullname: { // xxx/yyy/zzz
108.601 + int cp;
108.602 + for (int k=0; k<len; k += Character.charCount(cp)) {
108.603 + cp=name.codePointAt(k);
108.604 + if (cc=='/') {
108.605 + if (!isJavaIdentifierStart(cp)) break fullname;
108.606 + } else if (cp!='/') {
108.607 + if (!isJavaIdentifierPart(cp)) break fullname;
108.608 + }
108.609 + cc=cp;
108.610 + }
108.611 + return name;
108.612 + }
108.613 + return "\""+name+"\"";
108.614 + }
108.615 +
108.616 + public String getName(int cpx) {
108.617 + String res;
108.618 + try {
108.619 + return javaName((String)cpool[cpx]); //.replace('/','.');
108.620 + } catch (ArrayIndexOutOfBoundsException e) {
108.621 + return "<invalid constant pool index:"+cpx+">";
108.622 + } catch (ClassCastException e) {
108.623 + return "<invalid constant pool ref:"+cpx+">";
108.624 + }
108.625 + }
108.626 +
108.627 + /**
108.628 + * Returns unqualified class name.
108.629 + */
108.630 + public String getShortClassName(int cpx) {
108.631 + String classname=javaName(getClassName(cpx));
108.632 + pkgPrefixLen=classname.lastIndexOf("/")+1;
108.633 + if (pkgPrefixLen!=0) {
108.634 + pkgPrefix=classname.substring(0,pkgPrefixLen);
108.635 + if (classname.startsWith(pkgPrefix)) {
108.636 + return classname.substring(pkgPrefixLen);
108.637 + }
108.638 + }
108.639 + return classname;
108.640 + }
108.641 +
108.642 + /**
108.643 + * Returns source file name.
108.644 + */
108.645 + public String getSourceName(){
108.646 + return getName(source_cpx);
108.647 + }
108.648 +
108.649 + /**
108.650 + * Returns package name.
108.651 + */
108.652 + public String getPkgName(){
108.653 + String classname=getClassName(this_class);
108.654 + pkgPrefixLen=classname.lastIndexOf("/")+1;
108.655 + if (pkgPrefixLen!=0) {
108.656 + pkgPrefix=classname.substring(0,pkgPrefixLen);
108.657 + return("package "+pkgPrefix.substring(0,pkgPrefixLen-1)+";\n");
108.658 + }else return null;
108.659 + }
108.660 +
108.661 + /**
108.662 + * Returns total constant pool entry count.
108.663 + */
108.664 + public int getCpoolCount(){
108.665 + return cpool_count;
108.666 + }
108.667 +
108.668 + /**
108.669 + * Returns minor version of class file.
108.670 + */
108.671 + public int getMinor_version(){
108.672 + return minor_version;
108.673 + }
108.674 +
108.675 + /**
108.676 + * Returns major version of class file.
108.677 + */
108.678 + public int getMajor_version(){
108.679 + return major_version;
108.680 + }
108.681 +
108.682 + private boolean isJavaIdentifierStart(int cp) {
108.683 + return ('a' <= cp && cp <= 'z') || ('A' <= cp && cp <= 'Z');
108.684 + }
108.685 +
108.686 + private boolean isJavaIdentifierPart(int cp) {
108.687 + return isJavaIdentifierStart(cp) || ('0' <= cp && cp <= '9');
108.688 + }
108.689 +
108.690 + public String[] getNameAndType(int indx) {
108.691 + return getNameAndType(indx, 0, new String[2]);
108.692 + }
108.693 +
108.694 + private String[] getNameAndType(int indx, int at, String[] arr) {
108.695 + CPX2 c2 = getCpoolEntry(indx);
108.696 + arr[at] = StringValue(c2.cpx1);
108.697 + arr[at + 1] = StringValue(c2.cpx2);
108.698 + return arr;
108.699 + }
108.700 +
108.701 + public String[] getFieldInfoName(int indx) {
108.702 + CPX2 c2 = getCpoolEntry(indx);
108.703 + String[] arr = new String[3];
108.704 + arr[0] = getClassName(c2.cpx1);
108.705 + return getNameAndType(c2.cpx2, 1, arr);
108.706 + }
108.707 +
108.708 + static byte[] findAttr(String n, AttrData[] attrs) {
108.709 + for (AttrData ad : attrs) {
108.710 + if (n.equals(ad.getAttrName())) {
108.711 + return ad.getData();
108.712 + }
108.713 + }
108.714 + return null;
108.715 + }
108.716 +}
109.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
109.2 +++ b/javap/src/main/java/org/apidesign/javap/Constants.java Wed Jan 23 20:16:48 2013 +0100
109.3 @@ -0,0 +1,372 @@
109.4 +/*
109.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
109.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
109.7 + *
109.8 + * This code is free software; you can redistribute it and/or modify it
109.9 + * under the terms of the GNU General Public License version 2 only, as
109.10 + * published by the Free Software Foundation. Oracle designates this
109.11 + * particular file as subject to the "Classpath" exception as provided
109.12 + * by Oracle in the LICENSE file that accompanied this code.
109.13 + *
109.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
109.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
109.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
109.17 + * version 2 for more details (a copy is included in the LICENSE file that
109.18 + * accompanied this code).
109.19 + *
109.20 + * You should have received a copy of the GNU General Public License version
109.21 + * 2 along with this work; if not, write to the Free Software Foundation,
109.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
109.23 + *
109.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
109.25 + * or visit www.oracle.com if you need additional information or have any
109.26 + * questions.
109.27 + */
109.28 +
109.29 +
109.30 +
109.31 +package org.apidesign.javap;
109.32 +
109.33 +/**
109.34 + * This interface defines constant that are used
109.35 + * throughout the compiler. It inherits from RuntimeConstants,
109.36 + * which is an autogenerated class that contains contstants
109.37 + * defined in the interpreter.
109.38 + */
109.39 +
109.40 +public
109.41 +interface Constants extends RuntimeConstants {
109.42 +
109.43 + /**
109.44 + * End of input
109.45 + */
109.46 + public static final int EOF = -1;
109.47 +
109.48 + /*
109.49 + * Flags
109.50 + */
109.51 + public static final int F_VERBOSE = 1 << 0;
109.52 + public static final int F_DUMP = 1 << 1;
109.53 + public static final int F_WARNINGS = 1 << 2;
109.54 + public static final int F_DEBUG = 1 << 3;
109.55 + public static final int F_OPTIMIZE = 1 << 4;
109.56 + public static final int F_DEPENDENCIES = 1 << 5;
109.57 +
109.58 + /*
109.59 + * Type codes
109.60 + */
109.61 + public static final int TC_BOOLEAN = 0;
109.62 + public static final int TC_BYTE = 1;
109.63 + public static final int TC_CHAR = 2;
109.64 + public static final int TC_SHORT = 3;
109.65 + public static final int TC_INT = 4;
109.66 + public static final int TC_LONG = 5;
109.67 + public static final int TC_FLOAT = 6;
109.68 + public static final int TC_DOUBLE = 7;
109.69 + public static final int TC_NULL = 8;
109.70 + public static final int TC_ARRAY = 9;
109.71 + public static final int TC_CLASS = 10;
109.72 + public static final int TC_VOID = 11;
109.73 + public static final int TC_METHOD = 12;
109.74 + public static final int TC_ERROR = 13;
109.75 +
109.76 + /*
109.77 + * Type Masks
109.78 + */
109.79 + public static final int TM_NULL = 1 << TC_NULL;
109.80 + public static final int TM_VOID = 1 << TC_VOID;
109.81 + public static final int TM_BOOLEAN = 1 << TC_BOOLEAN;
109.82 + public static final int TM_BYTE = 1 << TC_BYTE;
109.83 + public static final int TM_CHAR = 1 << TC_CHAR;
109.84 + public static final int TM_SHORT = 1 << TC_SHORT;
109.85 + public static final int TM_INT = 1 << TC_INT;
109.86 + public static final int TM_LONG = 1 << TC_LONG;
109.87 + public static final int TM_FLOAT = 1 << TC_FLOAT;
109.88 + public static final int TM_DOUBLE = 1 << TC_DOUBLE;
109.89 + public static final int TM_ARRAY = 1 << TC_ARRAY;
109.90 + public static final int TM_CLASS = 1 << TC_CLASS;
109.91 + public static final int TM_METHOD = 1 << TC_METHOD;
109.92 + public static final int TM_ERROR = 1 << TC_ERROR;
109.93 +
109.94 + public static final int TM_INT32 = TM_BYTE | TM_SHORT | TM_CHAR | TM_INT;
109.95 + public static final int TM_NUM32 = TM_INT32 | TM_FLOAT;
109.96 + public static final int TM_NUM64 = TM_LONG | TM_DOUBLE;
109.97 + public static final int TM_INTEGER = TM_INT32 | TM_LONG;
109.98 + public static final int TM_REAL = TM_FLOAT | TM_DOUBLE;
109.99 + public static final int TM_NUMBER = TM_INTEGER | TM_REAL;
109.100 + public static final int TM_REFERENCE = TM_ARRAY | TM_CLASS | TM_NULL;
109.101 +
109.102 + /*
109.103 + * Class status
109.104 + */
109.105 + public static final int CS_UNDEFINED = 0;
109.106 + public static final int CS_UNDECIDED = 1;
109.107 + public static final int CS_BINARY = 2;
109.108 + public static final int CS_SOURCE = 3;
109.109 + public static final int CS_PARSED = 4;
109.110 + public static final int CS_COMPILED = 5;
109.111 + public static final int CS_NOTFOUND = 6;
109.112 +
109.113 + /*
109.114 + * Attributes
109.115 + */
109.116 + public static final int ATT_ALL = -1;
109.117 + public static final int ATT_CODE = 1;
109.118 +
109.119 + /*
109.120 + * Number of bits used in file offsets
109.121 + */
109.122 + public static final int OFFSETBITS = 19;
109.123 + public static final int MAXFILESIZE = (1 << OFFSETBITS) - 1;
109.124 + public static final int MAXLINENUMBER = (1 << (32 - OFFSETBITS)) - 1;
109.125 +
109.126 + /*
109.127 + * Operators
109.128 + */
109.129 + public final int COMMA = 0;
109.130 + public final int ASSIGN = 1;
109.131 +
109.132 + public final int ASGMUL = 2;
109.133 + public final int ASGDIV = 3;
109.134 + public final int ASGREM = 4;
109.135 + public final int ASGADD = 5;
109.136 + public final int ASGSUB = 6;
109.137 + public final int ASGLSHIFT = 7;
109.138 + public final int ASGRSHIFT = 8;
109.139 + public final int ASGURSHIFT = 9;
109.140 + public final int ASGBITAND = 10;
109.141 + public final int ASGBITOR = 11;
109.142 + public final int ASGBITXOR = 12;
109.143 +
109.144 + public final int COND = 13;
109.145 + public final int OR = 14;
109.146 + public final int AND = 15;
109.147 + public final int BITOR = 16;
109.148 + public final int BITXOR = 17;
109.149 + public final int BITAND = 18;
109.150 + public final int NE = 19;
109.151 + public final int EQ = 20;
109.152 + public final int GE = 21;
109.153 + public final int GT = 22;
109.154 + public final int LE = 23;
109.155 + public final int LT = 24;
109.156 + public final int INSTANCEOF = 25;
109.157 + public final int LSHIFT = 26;
109.158 + public final int RSHIFT = 27;
109.159 + public final int URSHIFT = 28;
109.160 + public final int ADD = 29;
109.161 + public final int SUB = 30;
109.162 + public final int DIV = 31;
109.163 + public final int REM = 32;
109.164 + public final int MUL = 33;
109.165 + public final int CAST = 34; // (x)y
109.166 + public final int POS = 35; // +x
109.167 + public final int NEG = 36; // -x
109.168 + public final int NOT = 37;
109.169 + public final int BITNOT = 38;
109.170 + public final int PREINC = 39; // ++x
109.171 + public final int PREDEC = 40; // --x
109.172 + public final int NEWARRAY = 41;
109.173 + public final int NEWINSTANCE = 42;
109.174 + public final int NEWFROMNAME = 43;
109.175 + public final int POSTINC = 44; // x++
109.176 + public final int POSTDEC = 45; // x--
109.177 + public final int FIELD = 46;
109.178 + public final int METHOD = 47; // x(y)
109.179 + public final int ARRAYACCESS = 48; // x[y]
109.180 + public final int NEW = 49;
109.181 + public final int INC = 50;
109.182 + public final int DEC = 51;
109.183 +
109.184 + public final int CONVERT = 55; // implicit conversion
109.185 + public final int EXPR = 56; // (x)
109.186 + public final int ARRAY = 57; // {x, y, ...}
109.187 + public final int GOTO = 58;
109.188 +
109.189 + /*
109.190 + * Value tokens
109.191 + */
109.192 + public final int IDENT = 60;
109.193 + public final int BOOLEANVAL = 61;
109.194 + public final int BYTEVAL = 62;
109.195 + public final int CHARVAL = 63;
109.196 + public final int SHORTVAL = 64;
109.197 + public final int INTVAL = 65;
109.198 + public final int LONGVAL = 66;
109.199 + public final int FLOATVAL = 67;
109.200 + public final int DOUBLEVAL = 68;
109.201 + public final int STRINGVAL = 69;
109.202 +
109.203 + /*
109.204 + * Type keywords
109.205 + */
109.206 + public final int BYTE = 70;
109.207 + public final int CHAR = 71;
109.208 + public final int SHORT = 72;
109.209 + public final int INT = 73;
109.210 + public final int LONG = 74;
109.211 + public final int FLOAT = 75;
109.212 + public final int DOUBLE = 76;
109.213 + public final int VOID = 77;
109.214 + public final int BOOLEAN = 78;
109.215 +
109.216 + /*
109.217 + * Expression keywords
109.218 + */
109.219 + public final int TRUE = 80;
109.220 + public final int FALSE = 81;
109.221 + public final int THIS = 82;
109.222 + public final int SUPER = 83;
109.223 + public final int NULL = 84;
109.224 +
109.225 + /*
109.226 + * Statement keywords
109.227 + */
109.228 + public final int IF = 90;
109.229 + public final int ELSE = 91;
109.230 + public final int FOR = 92;
109.231 + public final int WHILE = 93;
109.232 + public final int DO = 94;
109.233 + public final int SWITCH = 95;
109.234 + public final int CASE = 96;
109.235 + public final int DEFAULT = 97;
109.236 + public final int BREAK = 98;
109.237 + public final int CONTINUE = 99;
109.238 + public final int RETURN = 100;
109.239 + public final int TRY = 101;
109.240 + public final int CATCH = 102;
109.241 + public final int FINALLY = 103;
109.242 + public final int THROW = 104;
109.243 + public final int STAT = 105;
109.244 + public final int EXPRESSION = 106;
109.245 + public final int DECLARATION = 107;
109.246 + public final int VARDECLARATION = 108;
109.247 +
109.248 + /*
109.249 + * Declaration keywords
109.250 + */
109.251 + public final int IMPORT = 110;
109.252 + public final int CLASS = 111;
109.253 + public final int EXTENDS = 112;
109.254 + public final int IMPLEMENTS = 113;
109.255 + public final int INTERFACE = 114;
109.256 + public final int PACKAGE = 115;
109.257 +
109.258 + /*
109.259 + * Modifier keywords
109.260 + */
109.261 + public final int PRIVATE = 120;
109.262 + public final int PUBLIC = 121;
109.263 + public final int PROTECTED = 122;
109.264 + public final int CONST = 123;
109.265 + public final int STATIC = 124;
109.266 + public final int TRANSIENT = 125;
109.267 + public final int SYNCHRONIZED = 126;
109.268 + public final int NATIVE = 127;
109.269 + public final int FINAL = 128;
109.270 + public final int VOLATILE = 129;
109.271 + public final int ABSTRACT = 130;
109.272 + public final int STRICT = 165;
109.273 +
109.274 + /*
109.275 + * Punctuation
109.276 + */
109.277 + public final int SEMICOLON = 135;
109.278 + public final int COLON = 136;
109.279 + public final int QUESTIONMARK = 137;
109.280 + public final int LBRACE = 138;
109.281 + public final int RBRACE = 139;
109.282 + public final int LPAREN = 140;
109.283 + public final int RPAREN = 141;
109.284 + public final int LSQBRACKET = 142;
109.285 + public final int RSQBRACKET = 143;
109.286 + public final int THROWS = 144;
109.287 +
109.288 + /*
109.289 + * Special tokens
109.290 + */
109.291 + public final int ERROR = 145; // an error
109.292 + public final int COMMENT = 146; // not used anymore.
109.293 + public final int TYPE = 147;
109.294 + public final int LENGTH = 148;
109.295 + public final int INLINERETURN = 149;
109.296 + public final int INLINEMETHOD = 150;
109.297 + public final int INLINENEWINSTANCE = 151;
109.298 +
109.299 + /*
109.300 + * Added for jasm
109.301 + */
109.302 + public final int METHODREF = 152;
109.303 + public final int FIELDREF = 153;
109.304 + public final int STACK = 154;
109.305 + public final int LOCAL = 155;
109.306 + public final int CPINDEX = 156;
109.307 + public final int CPNAME = 157;
109.308 + public final int SIGN = 158;
109.309 + public final int BITS = 159;
109.310 + public final int INF = 160;
109.311 + public final int NAN = 161;
109.312 + public final int INNERCLASS = 162;
109.313 + public final int OF = 163;
109.314 + public final int SYNTHETIC = 164;
109.315 +// last used=165;
109.316 +
109.317 + /*
109.318 + * Operator precedence
109.319 + */
109.320 + public static final int opPrecedence[] = {
109.321 + 10, 11, 11, 11, 11, 11, 11, 11, 11, 11,
109.322 + 11, 11, 11, 12, 13, 14, 15, 16, 17, 18,
109.323 + 18, 19, 19, 19, 19, 19, 20, 20, 20, 21,
109.324 + 21, 22, 22, 22, 23, 24, 24, 24, 24, 24,
109.325 + 24, 25, 25, 26, 26, 26, 26, 26, 26
109.326 + };
109.327 +
109.328 + /*
109.329 + * Operator names
109.330 + */
109.331 + public static final String opNames[] = {
109.332 + ",", "=", "*=", "/=", "%=",
109.333 + "+=", "-=", "<<=", ">>=", "<<<=",
109.334 + "&=", "|=", "^=", "?:", "||",
109.335 + "&&", "|", "^", "&", "!=",
109.336 + "==", ">=", ">", "<=", "<",
109.337 + "instanceof", "<<", ">>", "<<<", "+",
109.338 + "-", "/", "%", "*", "cast",
109.339 + "+", "-", "!", "~", "++",
109.340 + "--", "new", "new", "new", "++",
109.341 + "--", "field", "method", "[]", "new",
109.342 + "++", "--", null, null, null,
109.343 +
109.344 + "convert", "expr", "array", "goto", null,
109.345 +
109.346 + "Identifier", "Boolean", "Byte", "Char", "Short",
109.347 + "Integer", "Long", "Float", "Double", "String",
109.348 +
109.349 + "byte", "char", "short", "int", "long",
109.350 + "float", "double", "void", "boolean", null,
109.351 +
109.352 + "true", "false", "this", "super", "null",
109.353 + null, null, null, null, null,
109.354 +
109.355 + "if", "else", "for", "while", "do",
109.356 + "switch", "case", "default", "break", "continue",
109.357 + "return", "try", "catch", "finally", "throw",
109.358 + "stat", "expression", "declaration", "declaration", null,
109.359 +
109.360 + "import", "class", "extends", "implements", "interface",
109.361 + "package", null, null, null, null,
109.362 +
109.363 + "private", "public", "protected", "const", "static",
109.364 + "transient", "synchronized", "native", "final", "volatile",
109.365 + "abstract", null, null, null, null,
109.366 +
109.367 + ";", ":", "?", "{", "}",
109.368 + "(", ")", "[", "]", "throws",
109.369 + "error", "comment", "type", "length", "inline-return",
109.370 + "inline-method", "inline-new",
109.371 + "method", "field", "stack", "locals", "CPINDEX", "CPName", "SIGN",
109.372 + "bits", "INF", "NaN", "InnerClass", "of", "synthetic"
109.373 + };
109.374 +
109.375 +}
110.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
110.2 +++ b/javap/src/main/java/org/apidesign/javap/FieldData.java Wed Jan 23 20:16:48 2013 +0100
110.3 @@ -0,0 +1,168 @@
110.4 +/*
110.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
110.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
110.7 + *
110.8 + * This code is free software; you can redistribute it and/or modify it
110.9 + * under the terms of the GNU General Public License version 2 only, as
110.10 + * published by the Free Software Foundation. Oracle designates this
110.11 + * particular file as subject to the "Classpath" exception as provided
110.12 + * by Oracle in the LICENSE file that accompanied this code.
110.13 + *
110.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
110.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
110.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
110.17 + * version 2 for more details (a copy is included in the LICENSE file that
110.18 + * accompanied this code).
110.19 + *
110.20 + * You should have received a copy of the GNU General Public License version
110.21 + * 2 along with this work; if not, write to the Free Software Foundation,
110.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
110.23 + *
110.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
110.25 + * or visit www.oracle.com if you need additional information or have any
110.26 + * questions.
110.27 + */
110.28 +
110.29 +
110.30 +package org.apidesign.javap;
110.31 +
110.32 +import java.io.*;
110.33 +
110.34 +/**
110.35 + * Strores field data informastion.
110.36 + *
110.37 + * @author Sucheta Dambalkar (Adopted code from jdis)
110.38 + */
110.39 +
110.40 +public class FieldData implements RuntimeConstants {
110.41 +
110.42 + ClassData cls;
110.43 + int access;
110.44 + int name_index;
110.45 + int descriptor_index;
110.46 + int attributes_count;
110.47 + int value_cpx=0;
110.48 + boolean isSynthetic=false;
110.49 + boolean isDeprecated=false;
110.50 + Vector attrs;
110.51 +
110.52 + public FieldData(ClassData cls){
110.53 + this.cls=cls;
110.54 + }
110.55 +
110.56 + /**
110.57 + * Read and store field info.
110.58 + */
110.59 + public void read(DataInputStream in) throws IOException {
110.60 + access = in.readUnsignedShort();
110.61 + name_index = in.readUnsignedShort();
110.62 + descriptor_index = in.readUnsignedShort();
110.63 + // Read the attributes
110.64 + int attributes_count = in.readUnsignedShort();
110.65 + attrs=new Vector(attributes_count);
110.66 + for (int i = 0; i < attributes_count; i++) {
110.67 + int attr_name_index=in.readUnsignedShort();
110.68 + if (cls.getTag(attr_name_index)!=CONSTANT_UTF8) continue;
110.69 + String attr_name=cls.getString(attr_name_index);
110.70 + if (attr_name.equals("ConstantValue")){
110.71 + if (in.readInt()!=2)
110.72 + throw new ClassFormatError("invalid ConstantValue attr length");
110.73 + value_cpx=in.readUnsignedShort();
110.74 + AttrData attr=new AttrData(cls);
110.75 + attr.read(attr_name_index);
110.76 + attrs.addElement(attr);
110.77 + } else if (attr_name.equals("Synthetic")){
110.78 + if (in.readInt()!=0)
110.79 + throw new ClassFormatError("invalid Synthetic attr length");
110.80 + isSynthetic=true;
110.81 + AttrData attr=new AttrData(cls);
110.82 + attr.read(attr_name_index);
110.83 + attrs.addElement(attr);
110.84 + } else if (attr_name.equals("Deprecated")){
110.85 + if (in.readInt()!=0)
110.86 + throw new ClassFormatError("invalid Synthetic attr length");
110.87 + isDeprecated = true;
110.88 + AttrData attr=new AttrData(cls);
110.89 + attr.read(attr_name_index);
110.90 + attrs.addElement(attr);
110.91 + } else {
110.92 + AttrData attr=new AttrData(cls);
110.93 + attr.read(attr_name_index, in);
110.94 + attrs.addElement(attr);
110.95 + }
110.96 + }
110.97 +
110.98 + } // end read
110.99 +
110.100 + public boolean isStatic() {
110.101 + return (access & ACC_STATIC) != 0;
110.102 + }
110.103 +
110.104 + /**
110.105 + * Returns access of a field.
110.106 + */
110.107 + public String[] getAccess(){
110.108 + Vector v = new Vector();
110.109 + if ((access & ACC_PUBLIC) !=0) v.addElement("public");
110.110 + if ((access & ACC_PRIVATE) !=0) v.addElement("private");
110.111 + if ((access & ACC_PROTECTED) !=0) v.addElement("protected");
110.112 + if ((access & ACC_STATIC) !=0) v.addElement("static");
110.113 + if ((access & ACC_FINAL) !=0) v.addElement("final");
110.114 + if ((access & ACC_VOLATILE) !=0) v.addElement("volatile");
110.115 + if ((access & ACC_TRANSIENT) !=0) v.addElement("transient");
110.116 + String[] accflags = new String[v.size()];
110.117 + v.copyInto(accflags);
110.118 + return accflags;
110.119 + }
110.120 +
110.121 + /**
110.122 + * Returns name of a field.
110.123 + */
110.124 + public String getName(){
110.125 + return cls.getStringValue(name_index);
110.126 + }
110.127 +
110.128 + /**
110.129 + * Returns internal signature of a field
110.130 + */
110.131 + public String getInternalSig(){
110.132 + return cls.getStringValue(descriptor_index);
110.133 + }
110.134 +
110.135 + /**
110.136 + * Returns true if field is synthetic.
110.137 + */
110.138 + public boolean isSynthetic(){
110.139 + return isSynthetic;
110.140 + }
110.141 +
110.142 + /**
110.143 + * Returns true if field is deprecated.
110.144 + */
110.145 + public boolean isDeprecated(){
110.146 + return isDeprecated;
110.147 + }
110.148 +
110.149 + /**
110.150 + * Returns index of constant value in cpool.
110.151 + */
110.152 + public int getConstantValueIndex(){
110.153 + return (value_cpx);
110.154 + }
110.155 +
110.156 + /**
110.157 + * Returns list of attributes of field.
110.158 + */
110.159 + public Vector getAttributes(){
110.160 + return attrs;
110.161 + }
110.162 +
110.163 + public byte[] findAnnotationData(boolean classRetention) {
110.164 + String n = classRetention ?
110.165 + "RuntimeInvisibleAnnotations" : // NOI18N
110.166 + "RuntimeVisibleAnnotations"; // NOI18N
110.167 + AttrData[] arr = new AttrData[attrs.size()];
110.168 + attrs.copyInto(arr);
110.169 + return ClassData.findAttr(n, arr);
110.170 + }
110.171 +}
111.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
111.2 +++ b/javap/src/main/java/org/apidesign/javap/Hashtable.java Wed Jan 23 20:16:48 2013 +0100
111.3 @@ -0,0 +1,94 @@
111.4 +/**
111.5 + * Back 2 Browser Bytecode Translator
111.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
111.7 + *
111.8 + * This program is free software: you can redistribute it and/or modify
111.9 + * it under the terms of the GNU General Public License as published by
111.10 + * the Free Software Foundation, version 2 of the License.
111.11 + *
111.12 + * This program is distributed in the hope that it will be useful,
111.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
111.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
111.15 + * GNU General Public License for more details.
111.16 + *
111.17 + * You should have received a copy of the GNU General Public License
111.18 + * along with this program. Look for COPYING file in the top folder.
111.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
111.20 + */
111.21 +package org.apidesign.javap;
111.22 +
111.23 +/** A JavaScript optimized replacement for Hashtable.
111.24 + *
111.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
111.26 + */
111.27 +final class Hashtable {
111.28 + private Object[] keys;
111.29 + private Object[] values;
111.30 +
111.31 + Hashtable(int i) {
111.32 + this();
111.33 + }
111.34 +
111.35 + Hashtable(int i, double d) {
111.36 + this();
111.37 + }
111.38 +
111.39 + Hashtable() {
111.40 + }
111.41 +
111.42 + synchronized void put(Object key, Object val) {
111.43 + int[] where = { -1, -1 };
111.44 + Object found = get(key, where);
111.45 + if (where[0] != -1) {
111.46 + // key exists
111.47 + values[where[0]] = val;
111.48 + } else {
111.49 + if (where[1] != -1) {
111.50 + // null found
111.51 + keys[where[1]] = key;
111.52 + values[where[1]] = val;
111.53 + } else {
111.54 + if (keys == null) {
111.55 + keys = new Object[11];
111.56 + values = new Object[11];
111.57 + keys[0] = key;
111.58 + values[0] = val;
111.59 + } else {
111.60 + Object[] newKeys = new Object[keys.length * 2];
111.61 + Object[] newValues = new Object[values.length * 2];
111.62 + for (int i = 0; i < keys.length; i++) {
111.63 + newKeys[i] = keys[i];
111.64 + newValues[i] = values[i];
111.65 + }
111.66 + newKeys[keys.length] = key;
111.67 + newValues[keys.length] = val;
111.68 + keys = newKeys;
111.69 + values = newValues;
111.70 + }
111.71 + }
111.72 + }
111.73 + }
111.74 +
111.75 + Object get(Object key) {
111.76 + return get(key, null);
111.77 + }
111.78 + private synchronized Object get(Object key, int[] foundAndNull) {
111.79 + if (keys == null) {
111.80 + return null;
111.81 + }
111.82 + for (int i = 0; i < keys.length; i++) {
111.83 + if (keys[i] == null) {
111.84 + if (foundAndNull != null) {
111.85 + foundAndNull[1] = i;
111.86 + }
111.87 + } else if (keys[i].equals(key)) {
111.88 + if (foundAndNull != null) {
111.89 + foundAndNull[0] = i;
111.90 + }
111.91 + return values[i];
111.92 + }
111.93 + }
111.94 + return null;
111.95 + }
111.96 +
111.97 +}
112.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
112.2 +++ b/javap/src/main/java/org/apidesign/javap/InnerClassData.java Wed Jan 23 20:16:48 2013 +0100
112.3 @@ -0,0 +1,75 @@
112.4 +/*
112.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
112.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
112.7 + *
112.8 + * This code is free software; you can redistribute it and/or modify it
112.9 + * under the terms of the GNU General Public License version 2 only, as
112.10 + * published by the Free Software Foundation. Oracle designates this
112.11 + * particular file as subject to the "Classpath" exception as provided
112.12 + * by Oracle in the LICENSE file that accompanied this code.
112.13 + *
112.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
112.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
112.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
112.17 + * version 2 for more details (a copy is included in the LICENSE file that
112.18 + * accompanied this code).
112.19 + *
112.20 + * You should have received a copy of the GNU General Public License version
112.21 + * 2 along with this work; if not, write to the Free Software Foundation,
112.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
112.23 + *
112.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
112.25 + * or visit www.oracle.com if you need additional information or have any
112.26 + * questions.
112.27 + */
112.28 +
112.29 +
112.30 +package org.apidesign.javap;
112.31 +
112.32 +import java.io.*;
112.33 +import java.util.*;
112.34 +
112.35 +/**
112.36 + * Strores InnerClass data informastion.
112.37 + *
112.38 + * @author Sucheta Dambalkar (Adopted code from jdis)
112.39 + */
112.40 +class InnerClassData implements RuntimeConstants {
112.41 + ClassData cls;
112.42 +
112.43 +
112.44 + int inner_class_info_index
112.45 + ,outer_class_info_index
112.46 + ,inner_name_index
112.47 + ,access
112.48 + ;
112.49 +
112.50 + public InnerClassData(ClassData cls) {
112.51 + this.cls=cls;
112.52 +
112.53 + }
112.54 +
112.55 + /**
112.56 + * Read Innerclass attribute data.
112.57 + */
112.58 + public void read(DataInputStream in) throws IOException {
112.59 + inner_class_info_index = in.readUnsignedShort();
112.60 + outer_class_info_index = in.readUnsignedShort();
112.61 + inner_name_index = in.readUnsignedShort();
112.62 + access = in.readUnsignedShort();
112.63 + } // end read
112.64 +
112.65 + /**
112.66 + * Returns the access of this class or interface.
112.67 + */
112.68 + public String[] getAccess(){
112.69 + Vector v = new Vector();
112.70 + if ((access & ACC_PUBLIC) !=0) v.addElement("public");
112.71 + if ((access & ACC_FINAL) !=0) v.addElement("final");
112.72 + if ((access & ACC_ABSTRACT) !=0) v.addElement("abstract");
112.73 + String[] accflags = new String[v.size()];
112.74 + v.copyInto(accflags);
112.75 + return accflags;
112.76 + }
112.77 +
112.78 +} // end InnerClassData
113.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
113.2 +++ b/javap/src/main/java/org/apidesign/javap/LineNumData.java Wed Jan 23 20:16:48 2013 +0100
113.3 @@ -0,0 +1,50 @@
113.4 +/*
113.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
113.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
113.7 + *
113.8 + * This code is free software; you can redistribute it and/or modify it
113.9 + * under the terms of the GNU General Public License version 2 only, as
113.10 + * published by the Free Software Foundation. Oracle designates this
113.11 + * particular file as subject to the "Classpath" exception as provided
113.12 + * by Oracle in the LICENSE file that accompanied this code.
113.13 + *
113.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
113.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
113.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
113.17 + * version 2 for more details (a copy is included in the LICENSE file that
113.18 + * accompanied this code).
113.19 + *
113.20 + * You should have received a copy of the GNU General Public License version
113.21 + * 2 along with this work; if not, write to the Free Software Foundation,
113.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
113.23 + *
113.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
113.25 + * or visit www.oracle.com if you need additional information or have any
113.26 + * questions.
113.27 + */
113.28 +
113.29 +
113.30 +package org.apidesign.javap;
113.31 +
113.32 +import java.util.*;
113.33 +import java.io.*;
113.34 +
113.35 +/**
113.36 + * Strores LineNumberTable data information.
113.37 + *
113.38 + * @author Sucheta Dambalkar (Adopted code from jdis)
113.39 + */
113.40 +class LineNumData {
113.41 + short start_pc, line_number;
113.42 +
113.43 + public LineNumData() {}
113.44 +
113.45 + /**
113.46 + * Read LineNumberTable attribute.
113.47 + */
113.48 + public LineNumData(DataInputStream in) throws IOException {
113.49 + start_pc = in.readShort();
113.50 + line_number=in.readShort();
113.51 +
113.52 + }
113.53 +}
114.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
114.2 +++ b/javap/src/main/java/org/apidesign/javap/LocVarData.java Wed Jan 23 20:16:48 2013 +0100
114.3 @@ -0,0 +1,54 @@
114.4 +/*
114.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
114.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
114.7 + *
114.8 + * This code is free software; you can redistribute it and/or modify it
114.9 + * under the terms of the GNU General Public License version 2 only, as
114.10 + * published by the Free Software Foundation. Oracle designates this
114.11 + * particular file as subject to the "Classpath" exception as provided
114.12 + * by Oracle in the LICENSE file that accompanied this code.
114.13 + *
114.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
114.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
114.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
114.17 + * version 2 for more details (a copy is included in the LICENSE file that
114.18 + * accompanied this code).
114.19 + *
114.20 + * You should have received a copy of the GNU General Public License version
114.21 + * 2 along with this work; if not, write to the Free Software Foundation,
114.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
114.23 + *
114.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
114.25 + * or visit www.oracle.com if you need additional information or have any
114.26 + * questions.
114.27 + */
114.28 +
114.29 +
114.30 +package org.apidesign.javap;
114.31 +
114.32 +import java.util.*;
114.33 +import java.io.*;
114.34 +
114.35 +/**
114.36 + * Strores LocalVariableTable data information.
114.37 + *
114.38 + * @author Sucheta Dambalkar (Adopted code from jdis)
114.39 + */
114.40 +class LocVarData {
114.41 + short start_pc, length, name_cpx, sig_cpx, slot;
114.42 +
114.43 + public LocVarData() {
114.44 + }
114.45 +
114.46 + /**
114.47 + * Read LocalVariableTable attribute.
114.48 + */
114.49 + public LocVarData(DataInputStream in) throws IOException {
114.50 + start_pc = in.readShort();
114.51 + length=in.readShort();
114.52 + name_cpx=in.readShort();
114.53 + sig_cpx=in.readShort();
114.54 + slot=in.readShort();
114.55 +
114.56 + }
114.57 +}
115.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
115.2 +++ b/javap/src/main/java/org/apidesign/javap/MethodData.java Wed Jan 23 20:16:48 2013 +0100
115.3 @@ -0,0 +1,394 @@
115.4 +/*
115.5 + * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved.
115.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
115.7 + *
115.8 + * This code is free software; you can redistribute it and/or modify it
115.9 + * under the terms of the GNU General Public License version 2 only, as
115.10 + * published by the Free Software Foundation. Oracle designates this
115.11 + * particular file as subject to the "Classpath" exception as provided
115.12 + * by Oracle in the LICENSE file that accompanied this code.
115.13 + *
115.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
115.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
115.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
115.17 + * version 2 for more details (a copy is included in the LICENSE file that
115.18 + * accompanied this code).
115.19 + *
115.20 + * You should have received a copy of the GNU General Public License version
115.21 + * 2 along with this work; if not, write to the Free Software Foundation,
115.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
115.23 + *
115.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
115.25 + * or visit www.oracle.com if you need additional information or have any
115.26 + * questions.
115.27 + */
115.28 +
115.29 +package org.apidesign.javap;
115.30 +
115.31 +
115.32 +import java.io.DataInputStream;
115.33 +import java.io.IOException;
115.34 +import static org.apidesign.javap.RuntimeConstants.*;
115.35 +
115.36 +/**
115.37 + * Strores method data informastion.
115.38 + *
115.39 + * @author Sucheta Dambalkar (Adopted code from jdis)
115.40 + */
115.41 +public class MethodData {
115.42 +
115.43 + ClassData cls;
115.44 + int access;
115.45 + int name_index;
115.46 + int descriptor_index;
115.47 + int attributes_count;
115.48 + byte[] code;
115.49 + Vector exception_table = new Vector(0);
115.50 + Vector lin_num_tb = new Vector(0);
115.51 + Vector loc_var_tb = new Vector(0);
115.52 + StackMapTableData[] stackMapTable;
115.53 + StackMapData[] stackMap;
115.54 + int[] exc_index_table=null;
115.55 + Vector attrs=new Vector(0);
115.56 + Vector code_attrs=new Vector(0);
115.57 + int max_stack, max_locals;
115.58 + boolean isSynthetic=false;
115.59 + boolean isDeprecated=false;
115.60 +
115.61 + public MethodData(ClassData cls){
115.62 + this.cls=cls;
115.63 + }
115.64 +
115.65 + /**
115.66 + * Read method info.
115.67 + */
115.68 + public void read(DataInputStream in) throws IOException {
115.69 + access = in.readUnsignedShort();
115.70 + name_index=in.readUnsignedShort();
115.71 + descriptor_index =in.readUnsignedShort();
115.72 + int attributes_count = in.readUnsignedShort();
115.73 + for (int i = 0; i < attributes_count; i++) {
115.74 + int attr_name_index=in.readUnsignedShort();
115.75 +
115.76 + readAttr: {
115.77 + if (cls.getTag(attr_name_index)==CONSTANT_UTF8) {
115.78 + String attr_name=cls.getString(attr_name_index);
115.79 + if ( attr_name.equals("Code")){
115.80 + readCode (in);
115.81 + AttrData attr=new AttrData(cls);
115.82 + attr.read(attr_name_index);
115.83 + attrs.addElement(attr);
115.84 + break readAttr;
115.85 + } else if ( attr_name.equals("Exceptions")){
115.86 + readExceptions(in);
115.87 + AttrData attr=new AttrData(cls);
115.88 + attr.read(attr_name_index);
115.89 + attrs.addElement(attr);
115.90 + break readAttr;
115.91 + } else if (attr_name.equals("Synthetic")){
115.92 + if (in.readInt()!=0)
115.93 + throw new ClassFormatError("invalid Synthetic attr length");
115.94 + isSynthetic=true;
115.95 + AttrData attr=new AttrData(cls);
115.96 + attr.read(attr_name_index);
115.97 + attrs.addElement(attr);
115.98 + break readAttr;
115.99 + } else if (attr_name.equals("Deprecated")){
115.100 + if (in.readInt()!=0)
115.101 + throw new ClassFormatError("invalid Synthetic attr length");
115.102 + isDeprecated = true;
115.103 + AttrData attr=new AttrData(cls);
115.104 + attr.read(attr_name_index);
115.105 + attrs.addElement(attr);
115.106 + break readAttr;
115.107 + }
115.108 + }
115.109 + AttrData attr=new AttrData(cls);
115.110 + attr.read(attr_name_index, in);
115.111 + attrs.addElement(attr);
115.112 + }
115.113 + }
115.114 + }
115.115 +
115.116 + /**
115.117 + * Read code attribute info.
115.118 + */
115.119 + public void readCode(DataInputStream in) throws IOException {
115.120 +
115.121 + int attr_length = in.readInt();
115.122 + max_stack=in.readUnsignedShort();
115.123 + max_locals=in.readUnsignedShort();
115.124 + int codelen=in.readInt();
115.125 +
115.126 + code=new byte[codelen];
115.127 + int totalread = 0;
115.128 + while(totalread < codelen){
115.129 + totalread += in.read(code, totalread, codelen-totalread);
115.130 + }
115.131 + // in.read(code, 0, codelen);
115.132 + int clen = 0;
115.133 + readExceptionTable(in);
115.134 + int code_attributes_count = in.readUnsignedShort();
115.135 +
115.136 + for (int k = 0 ; k < code_attributes_count ; k++) {
115.137 + int table_name_index=in.readUnsignedShort();
115.138 + int table_name_tag=cls.getTag(table_name_index);
115.139 + AttrData attr=new AttrData(cls);
115.140 + if (table_name_tag==CONSTANT_UTF8) {
115.141 + String table_name_tstr=cls.getString(table_name_index);
115.142 + if (table_name_tstr.equals("LineNumberTable")) {
115.143 + readLineNumTable(in);
115.144 + attr.read(table_name_index);
115.145 + } else if (table_name_tstr.equals("LocalVariableTable")) {
115.146 + readLocVarTable(in);
115.147 + attr.read(table_name_index);
115.148 + } else if (table_name_tstr.equals("StackMapTable")) {
115.149 + readStackMapTable(in);
115.150 + attr.read(table_name_index);
115.151 + } else if (table_name_tstr.equals("StackMap")) {
115.152 + readStackMap(in);
115.153 + attr.read(table_name_index);
115.154 + } else {
115.155 + attr.read(table_name_index, in);
115.156 + }
115.157 + code_attrs.addElement(attr);
115.158 + continue;
115.159 + }
115.160 +
115.161 + attr.read(table_name_index, in);
115.162 + code_attrs.addElement(attr);
115.163 + }
115.164 + }
115.165 +
115.166 + /**
115.167 + * Read exception table info.
115.168 + */
115.169 + void readExceptionTable (DataInputStream in) throws IOException {
115.170 + int exception_table_len=in.readUnsignedShort();
115.171 + exception_table=new Vector(exception_table_len);
115.172 + for (int l = 0; l < exception_table_len; l++) {
115.173 + exception_table.addElement(new TrapData(in, l));
115.174 + }
115.175 + }
115.176 +
115.177 + /**
115.178 + * Read LineNumberTable attribute info.
115.179 + */
115.180 + void readLineNumTable (DataInputStream in) throws IOException {
115.181 + int attr_len = in.readInt(); // attr_length
115.182 + int lin_num_tb_len = in.readUnsignedShort();
115.183 + lin_num_tb=new Vector(lin_num_tb_len);
115.184 + for (int l = 0; l < lin_num_tb_len; l++) {
115.185 + lin_num_tb.addElement(new LineNumData(in));
115.186 + }
115.187 + }
115.188 +
115.189 + /**
115.190 + * Read LocalVariableTable attribute info.
115.191 + */
115.192 + void readLocVarTable (DataInputStream in) throws IOException {
115.193 + int attr_len=in.readInt(); // attr_length
115.194 + int loc_var_tb_len = in.readUnsignedShort();
115.195 + loc_var_tb = new Vector(loc_var_tb_len);
115.196 + for (int l = 0; l < loc_var_tb_len; l++) {
115.197 + loc_var_tb.addElement(new LocVarData(in));
115.198 + }
115.199 + }
115.200 +
115.201 + /**
115.202 + * Read Exception attribute info.
115.203 + */
115.204 + public void readExceptions(DataInputStream in) throws IOException {
115.205 + int attr_len=in.readInt(); // attr_length in prog
115.206 + int num_exceptions = in.readUnsignedShort();
115.207 + exc_index_table=new int[num_exceptions];
115.208 + for (int l = 0; l < num_exceptions; l++) {
115.209 + int exc=in.readShort();
115.210 + exc_index_table[l]=exc;
115.211 + }
115.212 + }
115.213 +
115.214 + /**
115.215 + * Read StackMapTable attribute info.
115.216 + */
115.217 + void readStackMapTable(DataInputStream in) throws IOException {
115.218 + int attr_len = in.readInt(); //attr_length
115.219 + int stack_map_tb_len = in.readUnsignedShort();
115.220 + stackMapTable = new StackMapTableData[stack_map_tb_len];
115.221 + for (int i=0; i<stack_map_tb_len; i++) {
115.222 + stackMapTable[i] = StackMapTableData.getInstance(in, this);
115.223 + }
115.224 + }
115.225 +
115.226 + /**
115.227 + * Read StackMap attribute info.
115.228 + */
115.229 + void readStackMap(DataInputStream in) throws IOException {
115.230 + int attr_len = in.readInt(); //attr_length
115.231 + int stack_map_len = in.readUnsignedShort();
115.232 + stackMap = new StackMapData[stack_map_len];
115.233 + for (int i = 0; i<stack_map_len; i++) {
115.234 + stackMap[i] = new StackMapData(in, this);
115.235 + }
115.236 + }
115.237 +
115.238 + /**
115.239 + * Return access of the method.
115.240 + */
115.241 + public int getAccess(){
115.242 + return access;
115.243 + }
115.244 +
115.245 + /**
115.246 + * Return name of the method.
115.247 + */
115.248 + public String getName(){
115.249 + return cls.getStringValue(name_index);
115.250 + }
115.251 +
115.252 + /**
115.253 + * Return internal siganature of the method.
115.254 + */
115.255 + public String getInternalSig(){
115.256 + return cls.getStringValue(descriptor_index);
115.257 + }
115.258 +
115.259 + /**
115.260 + * Return code attribute data of a method.
115.261 + */
115.262 + public byte[] getCode(){
115.263 + return code;
115.264 + }
115.265 +
115.266 + /**
115.267 + * Return LineNumberTable size.
115.268 + */
115.269 + public int getnumlines(){
115.270 + return lin_num_tb.size();
115.271 + }
115.272 +
115.273 + /**
115.274 + * Return LineNumberTable
115.275 + */
115.276 + public Vector getlin_num_tb(){
115.277 + return lin_num_tb;
115.278 + }
115.279 +
115.280 + /**
115.281 + * Return LocalVariableTable size.
115.282 + */
115.283 + public int getloc_var_tbsize(){
115.284 + return loc_var_tb.size();
115.285 + }
115.286 +
115.287 +
115.288 + /**
115.289 + * Return LocalVariableTable.
115.290 + */
115.291 + public Vector getloc_var_tb(){
115.292 + return loc_var_tb;
115.293 + }
115.294 +
115.295 + /**
115.296 + * Return StackMap.
115.297 + */
115.298 + public StackMapData[] getStackMap() {
115.299 + return stackMap;
115.300 + }
115.301 +
115.302 + /**
115.303 + * Return StackMapTable.
115.304 + */
115.305 + public StackMapTableData[] getStackMapTable() {
115.306 + return stackMapTable;
115.307 + }
115.308 +
115.309 + public StackMapIterator createStackMapIterator() {
115.310 + return new StackMapIterator(this);
115.311 + }
115.312 +
115.313 + /**
115.314 + * Return true if method is static
115.315 + */
115.316 + public boolean isStatic(){
115.317 + if ((access & ACC_STATIC) !=0) return true;
115.318 + return false;
115.319 + }
115.320 +
115.321 +
115.322 + /**
115.323 + * Return max depth of operand stack.
115.324 + */
115.325 + public int getMaxStack(){
115.326 + return max_stack;
115.327 + }
115.328 +
115.329 +
115.330 + /**
115.331 + * Return number of local variables.
115.332 + */
115.333 + public int getMaxLocals(){
115.334 + return max_locals;
115.335 + }
115.336 +
115.337 +
115.338 + /**
115.339 + * Return exception index table in Exception attribute.
115.340 + */
115.341 + public int []get_exc_index_table(){
115.342 + return exc_index_table;
115.343 + }
115.344 +
115.345 +
115.346 + /**
115.347 + * Return exception table in code attributre.
115.348 + */
115.349 + public TrapDataIterator getTrapDataIterator(){
115.350 + return new TrapDataIterator(exception_table);
115.351 + }
115.352 +
115.353 +
115.354 + /**
115.355 + * Return method attributes.
115.356 + */
115.357 + public Vector getAttributes(){
115.358 + return attrs;
115.359 + }
115.360 +
115.361 +
115.362 + /**
115.363 + * Return code attributes.
115.364 + */
115.365 + public Vector getCodeAttributes(){
115.366 + return code_attrs;
115.367 + }
115.368 +
115.369 +
115.370 + /**
115.371 + * Return true if method id synthetic.
115.372 + */
115.373 + public boolean isSynthetic(){
115.374 + return isSynthetic;
115.375 + }
115.376 +
115.377 +
115.378 + /**
115.379 + * Return true if method is deprecated.
115.380 + */
115.381 + public boolean isDeprecated(){
115.382 + return isDeprecated;
115.383 + }
115.384 +
115.385 + public byte[] findAnnotationData(boolean classRetention) {
115.386 + String n = classRetention ?
115.387 + "RuntimeInvisibleAnnotations" : // NOI18N
115.388 + "RuntimeVisibleAnnotations"; // NOI18N
115.389 + AttrData[] arr = new AttrData[attrs.size()];
115.390 + attrs.copyInto(arr);
115.391 + return ClassData.findAttr(n, arr);
115.392 + }
115.393 +
115.394 + public boolean isConstructor() {
115.395 + return "<init>".equals(getName());
115.396 + }
115.397 +}
116.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
116.2 +++ b/javap/src/main/java/org/apidesign/javap/RuntimeConstants.java Wed Jan 23 20:16:48 2013 +0100
116.3 @@ -0,0 +1,787 @@
116.4 +/*
116.5 + * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved.
116.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
116.7 + *
116.8 + * This code is free software; you can redistribute it and/or modify it
116.9 + * under the terms of the GNU General Public License version 2 only, as
116.10 + * published by the Free Software Foundation. Oracle designates this
116.11 + * particular file as subject to the "Classpath" exception as provided
116.12 + * by Oracle in the LICENSE file that accompanied this code.
116.13 + *
116.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
116.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
116.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
116.17 + * version 2 for more details (a copy is included in the LICENSE file that
116.18 + * accompanied this code).
116.19 + *
116.20 + * You should have received a copy of the GNU General Public License version
116.21 + * 2 along with this work; if not, write to the Free Software Foundation,
116.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
116.23 + *
116.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
116.25 + * or visit www.oracle.com if you need additional information or have any
116.26 + * questions.
116.27 + */
116.28 +
116.29 +
116.30 +package org.apidesign.javap;
116.31 +
116.32 +public interface RuntimeConstants {
116.33 +
116.34 + /* Signature Characters */
116.35 + public static final char SIGC_VOID = 'V';
116.36 + public static final String SIG_VOID = "V";
116.37 + public static final char SIGC_BOOLEAN = 'Z';
116.38 + public static final String SIG_BOOLEAN = "Z";
116.39 + public static final char SIGC_BYTE = 'B';
116.40 + public static final String SIG_BYTE = "B";
116.41 + public static final char SIGC_CHAR = 'C';
116.42 + public static final String SIG_CHAR = "C";
116.43 + public static final char SIGC_SHORT = 'S';
116.44 + public static final String SIG_SHORT = "S";
116.45 + public static final char SIGC_INT = 'I';
116.46 + public static final String SIG_INT = "I";
116.47 + public static final char SIGC_LONG = 'J';
116.48 + public static final String SIG_LONG = "J";
116.49 + public static final char SIGC_FLOAT = 'F';
116.50 + public static final String SIG_FLOAT = "F";
116.51 + public static final char SIGC_DOUBLE = 'D';
116.52 + public static final String SIG_DOUBLE = "D";
116.53 + public static final char SIGC_ARRAY = '[';
116.54 + public static final String SIG_ARRAY = "[";
116.55 + public static final char SIGC_CLASS = 'L';
116.56 + public static final String SIG_CLASS = "L";
116.57 + public static final char SIGC_METHOD = '(';
116.58 + public static final String SIG_METHOD = "(";
116.59 + public static final char SIGC_ENDCLASS = ';';
116.60 + public static final String SIG_ENDCLASS = ";";
116.61 + public static final char SIGC_ENDMETHOD = ')';
116.62 + public static final String SIG_ENDMETHOD = ")";
116.63 + public static final char SIGC_PACKAGE = '/';
116.64 + public static final String SIG_PACKAGE = "/";
116.65 +
116.66 + /* Class File Constants */
116.67 + public static final int JAVA_MAGIC = 0xcafebabe;
116.68 + public static final int JAVA_VERSION = 45;
116.69 + public static final int JAVA_MINOR_VERSION = 3;
116.70 +
116.71 + /* Constant table */
116.72 + public static final int CONSTANT_UTF8 = 1;
116.73 + public static final int CONSTANT_UNICODE = 2;
116.74 + public static final int CONSTANT_INTEGER = 3;
116.75 + public static final int CONSTANT_FLOAT = 4;
116.76 + public static final int CONSTANT_LONG = 5;
116.77 + public static final int CONSTANT_DOUBLE = 6;
116.78 + public static final int CONSTANT_CLASS = 7;
116.79 + public static final int CONSTANT_STRING = 8;
116.80 + public static final int CONSTANT_FIELD = 9;
116.81 + public static final int CONSTANT_METHOD = 10;
116.82 + public static final int CONSTANT_INTERFACEMETHOD = 11;
116.83 + public static final int CONSTANT_NAMEANDTYPE = 12;
116.84 +
116.85 + /* Access Flags */
116.86 + public static final int ACC_PUBLIC = 0x00000001;
116.87 + public static final int ACC_PRIVATE = 0x00000002;
116.88 + public static final int ACC_PROTECTED = 0x00000004;
116.89 + public static final int ACC_STATIC = 0x00000008;
116.90 + public static final int ACC_FINAL = 0x00000010;
116.91 + public static final int ACC_SYNCHRONIZED = 0x00000020;
116.92 + public static final int ACC_SUPER = 0x00000020;
116.93 + public static final int ACC_VOLATILE = 0x00000040;
116.94 + public static final int ACC_TRANSIENT = 0x00000080;
116.95 + public static final int ACC_NATIVE = 0x00000100;
116.96 + public static final int ACC_INTERFACE = 0x00000200;
116.97 + public static final int ACC_ABSTRACT = 0x00000400;
116.98 + public static final int ACC_STRICT = 0x00000800;
116.99 + public static final int ACC_EXPLICIT = 0x00001000;
116.100 + public static final int ACC_SYNTHETIC = 0x00010000; // actually, this is an attribute
116.101 +
116.102 + /* Type codes */
116.103 + public static final int T_CLASS = 0x00000002;
116.104 + public static final int T_BOOLEAN = 0x00000004;
116.105 + public static final int T_CHAR = 0x00000005;
116.106 + public static final int T_FLOAT = 0x00000006;
116.107 + public static final int T_DOUBLE = 0x00000007;
116.108 + public static final int T_BYTE = 0x00000008;
116.109 + public static final int T_SHORT = 0x00000009;
116.110 + public static final int T_INT = 0x0000000a;
116.111 + public static final int T_LONG = 0x0000000b;
116.112 +
116.113 + /* Type codes for StackMap attribute */
116.114 + public static final int ITEM_Bogus =0; // an unknown or uninitialized value
116.115 + public static final int ITEM_Integer =1; // a 32-bit integer
116.116 + public static final int ITEM_Float =2; // not used
116.117 + public static final int ITEM_Double =3; // not used
116.118 + public static final int ITEM_Long =4; // a 64-bit integer
116.119 + public static final int ITEM_Null =5; // the type of null
116.120 + public static final int ITEM_InitObject =6; // "this" in constructor
116.121 + public static final int ITEM_Object =7; // followed by 2-byte index of class name
116.122 + public static final int ITEM_NewObject =8; // followed by 2-byte ref to "new"
116.123 +
116.124 + /* Constants used in StackMapTable attribute */
116.125 + public static final int SAME_FRAME_BOUND = 64;
116.126 + public static final int SAME_LOCALS_1_STACK_ITEM_BOUND = 128;
116.127 + public static final int SAME_LOCALS_1_STACK_ITEM_EXTENDED = 247;
116.128 + public static final int SAME_FRAME_EXTENDED = 251;
116.129 + public static final int FULL_FRAME = 255;
116.130 +
116.131 + /* Opcodes */
116.132 + public static final int opc_dead = -2;
116.133 + public static final int opc_label = -1;
116.134 + public static final int opc_nop = 0;
116.135 + public static final int opc_aconst_null = 1;
116.136 + public static final int opc_iconst_m1 = 2;
116.137 + public static final int opc_iconst_0 = 3;
116.138 + public static final int opc_iconst_1 = 4;
116.139 + public static final int opc_iconst_2 = 5;
116.140 + public static final int opc_iconst_3 = 6;
116.141 + public static final int opc_iconst_4 = 7;
116.142 + public static final int opc_iconst_5 = 8;
116.143 + public static final int opc_lconst_0 = 9;
116.144 + public static final int opc_lconst_1 = 10;
116.145 + public static final int opc_fconst_0 = 11;
116.146 + public static final int opc_fconst_1 = 12;
116.147 + public static final int opc_fconst_2 = 13;
116.148 + public static final int opc_dconst_0 = 14;
116.149 + public static final int opc_dconst_1 = 15;
116.150 + public static final int opc_bipush = 16;
116.151 + public static final int opc_sipush = 17;
116.152 + public static final int opc_ldc = 18;
116.153 + public static final int opc_ldc_w = 19;
116.154 + public static final int opc_ldc2_w = 20;
116.155 + public static final int opc_iload = 21;
116.156 + public static final int opc_lload = 22;
116.157 + public static final int opc_fload = 23;
116.158 + public static final int opc_dload = 24;
116.159 + public static final int opc_aload = 25;
116.160 + public static final int opc_iload_0 = 26;
116.161 + public static final int opc_iload_1 = 27;
116.162 + public static final int opc_iload_2 = 28;
116.163 + public static final int opc_iload_3 = 29;
116.164 + public static final int opc_lload_0 = 30;
116.165 + public static final int opc_lload_1 = 31;
116.166 + public static final int opc_lload_2 = 32;
116.167 + public static final int opc_lload_3 = 33;
116.168 + public static final int opc_fload_0 = 34;
116.169 + public static final int opc_fload_1 = 35;
116.170 + public static final int opc_fload_2 = 36;
116.171 + public static final int opc_fload_3 = 37;
116.172 + public static final int opc_dload_0 = 38;
116.173 + public static final int opc_dload_1 = 39;
116.174 + public static final int opc_dload_2 = 40;
116.175 + public static final int opc_dload_3 = 41;
116.176 + public static final int opc_aload_0 = 42;
116.177 + public static final int opc_aload_1 = 43;
116.178 + public static final int opc_aload_2 = 44;
116.179 + public static final int opc_aload_3 = 45;
116.180 + public static final int opc_iaload = 46;
116.181 + public static final int opc_laload = 47;
116.182 + public static final int opc_faload = 48;
116.183 + public static final int opc_daload = 49;
116.184 + public static final int opc_aaload = 50;
116.185 + public static final int opc_baload = 51;
116.186 + public static final int opc_caload = 52;
116.187 + public static final int opc_saload = 53;
116.188 + public static final int opc_istore = 54;
116.189 + public static final int opc_lstore = 55;
116.190 + public static final int opc_fstore = 56;
116.191 + public static final int opc_dstore = 57;
116.192 + public static final int opc_astore = 58;
116.193 + public static final int opc_istore_0 = 59;
116.194 + public static final int opc_istore_1 = 60;
116.195 + public static final int opc_istore_2 = 61;
116.196 + public static final int opc_istore_3 = 62;
116.197 + public static final int opc_lstore_0 = 63;
116.198 + public static final int opc_lstore_1 = 64;
116.199 + public static final int opc_lstore_2 = 65;
116.200 + public static final int opc_lstore_3 = 66;
116.201 + public static final int opc_fstore_0 = 67;
116.202 + public static final int opc_fstore_1 = 68;
116.203 + public static final int opc_fstore_2 = 69;
116.204 + public static final int opc_fstore_3 = 70;
116.205 + public static final int opc_dstore_0 = 71;
116.206 + public static final int opc_dstore_1 = 72;
116.207 + public static final int opc_dstore_2 = 73;
116.208 + public static final int opc_dstore_3 = 74;
116.209 + public static final int opc_astore_0 = 75;
116.210 + public static final int opc_astore_1 = 76;
116.211 + public static final int opc_astore_2 = 77;
116.212 + public static final int opc_astore_3 = 78;
116.213 + public static final int opc_iastore = 79;
116.214 + public static final int opc_lastore = 80;
116.215 + public static final int opc_fastore = 81;
116.216 + public static final int opc_dastore = 82;
116.217 + public static final int opc_aastore = 83;
116.218 + public static final int opc_bastore = 84;
116.219 + public static final int opc_castore = 85;
116.220 + public static final int opc_sastore = 86;
116.221 + public static final int opc_pop = 87;
116.222 + public static final int opc_pop2 = 88;
116.223 + public static final int opc_dup = 89;
116.224 + public static final int opc_dup_x1 = 90;
116.225 + public static final int opc_dup_x2 = 91;
116.226 + public static final int opc_dup2 = 92;
116.227 + public static final int opc_dup2_x1 = 93;
116.228 + public static final int opc_dup2_x2 = 94;
116.229 + public static final int opc_swap = 95;
116.230 + public static final int opc_iadd = 96;
116.231 + public static final int opc_ladd = 97;
116.232 + public static final int opc_fadd = 98;
116.233 + public static final int opc_dadd = 99;
116.234 + public static final int opc_isub = 100;
116.235 + public static final int opc_lsub = 101;
116.236 + public static final int opc_fsub = 102;
116.237 + public static final int opc_dsub = 103;
116.238 + public static final int opc_imul = 104;
116.239 + public static final int opc_lmul = 105;
116.240 + public static final int opc_fmul = 106;
116.241 + public static final int opc_dmul = 107;
116.242 + public static final int opc_idiv = 108;
116.243 + public static final int opc_ldiv = 109;
116.244 + public static final int opc_fdiv = 110;
116.245 + public static final int opc_ddiv = 111;
116.246 + public static final int opc_irem = 112;
116.247 + public static final int opc_lrem = 113;
116.248 + public static final int opc_frem = 114;
116.249 + public static final int opc_drem = 115;
116.250 + public static final int opc_ineg = 116;
116.251 + public static final int opc_lneg = 117;
116.252 + public static final int opc_fneg = 118;
116.253 + public static final int opc_dneg = 119;
116.254 + public static final int opc_ishl = 120;
116.255 + public static final int opc_lshl = 121;
116.256 + public static final int opc_ishr = 122;
116.257 + public static final int opc_lshr = 123;
116.258 + public static final int opc_iushr = 124;
116.259 + public static final int opc_lushr = 125;
116.260 + public static final int opc_iand = 126;
116.261 + public static final int opc_land = 127;
116.262 + public static final int opc_ior = 128;
116.263 + public static final int opc_lor = 129;
116.264 + public static final int opc_ixor = 130;
116.265 + public static final int opc_lxor = 131;
116.266 + public static final int opc_iinc = 132;
116.267 + public static final int opc_i2l = 133;
116.268 + public static final int opc_i2f = 134;
116.269 + public static final int opc_i2d = 135;
116.270 + public static final int opc_l2i = 136;
116.271 + public static final int opc_l2f = 137;
116.272 + public static final int opc_l2d = 138;
116.273 + public static final int opc_f2i = 139;
116.274 + public static final int opc_f2l = 140;
116.275 + public static final int opc_f2d = 141;
116.276 + public static final int opc_d2i = 142;
116.277 + public static final int opc_d2l = 143;
116.278 + public static final int opc_d2f = 144;
116.279 + public static final int opc_i2b = 145;
116.280 + public static final int opc_int2byte = 145;
116.281 + public static final int opc_i2c = 146;
116.282 + public static final int opc_int2char = 146;
116.283 + public static final int opc_i2s = 147;
116.284 + public static final int opc_int2short = 147;
116.285 + public static final int opc_lcmp = 148;
116.286 + public static final int opc_fcmpl = 149;
116.287 + public static final int opc_fcmpg = 150;
116.288 + public static final int opc_dcmpl = 151;
116.289 + public static final int opc_dcmpg = 152;
116.290 + public static final int opc_ifeq = 153;
116.291 + public static final int opc_ifne = 154;
116.292 + public static final int opc_iflt = 155;
116.293 + public static final int opc_ifge = 156;
116.294 + public static final int opc_ifgt = 157;
116.295 + public static final int opc_ifle = 158;
116.296 + public static final int opc_if_icmpeq = 159;
116.297 + public static final int opc_if_icmpne = 160;
116.298 + public static final int opc_if_icmplt = 161;
116.299 + public static final int opc_if_icmpge = 162;
116.300 + public static final int opc_if_icmpgt = 163;
116.301 + public static final int opc_if_icmple = 164;
116.302 + public static final int opc_if_acmpeq = 165;
116.303 + public static final int opc_if_acmpne = 166;
116.304 + public static final int opc_goto = 167;
116.305 + public static final int opc_jsr = 168;
116.306 + public static final int opc_ret = 169;
116.307 + public static final int opc_tableswitch = 170;
116.308 + public static final int opc_lookupswitch = 171;
116.309 + public static final int opc_ireturn = 172;
116.310 + public static final int opc_lreturn = 173;
116.311 + public static final int opc_freturn = 174;
116.312 + public static final int opc_dreturn = 175;
116.313 + public static final int opc_areturn = 176;
116.314 + public static final int opc_return = 177;
116.315 + public static final int opc_getstatic = 178;
116.316 + public static final int opc_putstatic = 179;
116.317 + public static final int opc_getfield = 180;
116.318 + public static final int opc_putfield = 181;
116.319 + public static final int opc_invokevirtual = 182;
116.320 + public static final int opc_invokenonvirtual = 183;
116.321 + public static final int opc_invokespecial = 183;
116.322 + public static final int opc_invokestatic = 184;
116.323 + public static final int opc_invokeinterface = 185;
116.324 +// public static final int opc_xxxunusedxxx = 186;
116.325 + public static final int opc_new = 187;
116.326 + public static final int opc_newarray = 188;
116.327 + public static final int opc_anewarray = 189;
116.328 + public static final int opc_arraylength = 190;
116.329 + public static final int opc_athrow = 191;
116.330 + public static final int opc_checkcast = 192;
116.331 + public static final int opc_instanceof = 193;
116.332 + public static final int opc_monitorenter = 194;
116.333 + public static final int opc_monitorexit = 195;
116.334 + public static final int opc_wide = 196;
116.335 + public static final int opc_multianewarray = 197;
116.336 + public static final int opc_ifnull = 198;
116.337 + public static final int opc_ifnonnull = 199;
116.338 + public static final int opc_goto_w = 200;
116.339 + public static final int opc_jsr_w = 201;
116.340 + /* Pseudo-instructions */
116.341 + public static final int opc_bytecode = 203;
116.342 + public static final int opc_try = 204;
116.343 + public static final int opc_endtry = 205;
116.344 + public static final int opc_catch = 206;
116.345 + public static final int opc_var = 207;
116.346 + public static final int opc_endvar = 208;
116.347 + public static final int opc_localsmap = 209;
116.348 + public static final int opc_stackmap = 210;
116.349 + /* PicoJava prefixes */
116.350 + public static final int opc_nonpriv = 254;
116.351 + public static final int opc_priv = 255;
116.352 +
116.353 + /* Wide instructions */
116.354 + public static final int opc_iload_w = (opc_wide<<8)|opc_iload;
116.355 + public static final int opc_lload_w = (opc_wide<<8)|opc_lload;
116.356 + public static final int opc_fload_w = (opc_wide<<8)|opc_fload;
116.357 + public static final int opc_dload_w = (opc_wide<<8)|opc_dload;
116.358 + public static final int opc_aload_w = (opc_wide<<8)|opc_aload;
116.359 + public static final int opc_istore_w = (opc_wide<<8)|opc_istore;
116.360 + public static final int opc_lstore_w = (opc_wide<<8)|opc_lstore;
116.361 + public static final int opc_fstore_w = (opc_wide<<8)|opc_fstore;
116.362 + public static final int opc_dstore_w = (opc_wide<<8)|opc_dstore;
116.363 + public static final int opc_astore_w = (opc_wide<<8)|opc_astore;
116.364 + public static final int opc_ret_w = (opc_wide<<8)|opc_ret;
116.365 + public static final int opc_iinc_w = (opc_wide<<8)|opc_iinc;
116.366 +
116.367 + /* Opcode Names */
116.368 + public static final String opcNamesTab[] = {
116.369 + "nop",
116.370 + "aconst_null",
116.371 + "iconst_m1",
116.372 + "iconst_0",
116.373 + "iconst_1",
116.374 + "iconst_2",
116.375 + "iconst_3",
116.376 + "iconst_4",
116.377 + "iconst_5",
116.378 + "lconst_0",
116.379 + "lconst_1",
116.380 + "fconst_0",
116.381 + "fconst_1",
116.382 + "fconst_2",
116.383 + "dconst_0",
116.384 + "dconst_1",
116.385 + "bipush",
116.386 + "sipush",
116.387 + "ldc",
116.388 + "ldc_w",
116.389 + "ldc2_w",
116.390 + "iload",
116.391 + "lload",
116.392 + "fload",
116.393 + "dload",
116.394 + "aload",
116.395 + "iload_0",
116.396 + "iload_1",
116.397 + "iload_2",
116.398 + "iload_3",
116.399 + "lload_0",
116.400 + "lload_1",
116.401 + "lload_2",
116.402 + "lload_3",
116.403 + "fload_0",
116.404 + "fload_1",
116.405 + "fload_2",
116.406 + "fload_3",
116.407 + "dload_0",
116.408 + "dload_1",
116.409 + "dload_2",
116.410 + "dload_3",
116.411 + "aload_0",
116.412 + "aload_1",
116.413 + "aload_2",
116.414 + "aload_3",
116.415 + "iaload",
116.416 + "laload",
116.417 + "faload",
116.418 + "daload",
116.419 + "aaload",
116.420 + "baload",
116.421 + "caload",
116.422 + "saload",
116.423 + "istore",
116.424 + "lstore",
116.425 + "fstore",
116.426 + "dstore",
116.427 + "astore",
116.428 + "istore_0",
116.429 + "istore_1",
116.430 + "istore_2",
116.431 + "istore_3",
116.432 + "lstore_0",
116.433 + "lstore_1",
116.434 + "lstore_2",
116.435 + "lstore_3",
116.436 + "fstore_0",
116.437 + "fstore_1",
116.438 + "fstore_2",
116.439 + "fstore_3",
116.440 + "dstore_0",
116.441 + "dstore_1",
116.442 + "dstore_2",
116.443 + "dstore_3",
116.444 + "astore_0",
116.445 + "astore_1",
116.446 + "astore_2",
116.447 + "astore_3",
116.448 + "iastore",
116.449 + "lastore",
116.450 + "fastore",
116.451 + "dastore",
116.452 + "aastore",
116.453 + "bastore",
116.454 + "castore",
116.455 + "sastore",
116.456 + "pop",
116.457 + "pop2",
116.458 + "dup",
116.459 + "dup_x1",
116.460 + "dup_x2",
116.461 + "dup2",
116.462 + "dup2_x1",
116.463 + "dup2_x2",
116.464 + "swap",
116.465 + "iadd",
116.466 + "ladd",
116.467 + "fadd",
116.468 + "dadd",
116.469 + "isub",
116.470 + "lsub",
116.471 + "fsub",
116.472 + "dsub",
116.473 + "imul",
116.474 + "lmul",
116.475 + "fmul",
116.476 + "dmul",
116.477 + "idiv",
116.478 + "ldiv",
116.479 + "fdiv",
116.480 + "ddiv",
116.481 + "irem",
116.482 + "lrem",
116.483 + "frem",
116.484 + "drem",
116.485 + "ineg",
116.486 + "lneg",
116.487 + "fneg",
116.488 + "dneg",
116.489 + "ishl",
116.490 + "lshl",
116.491 + "ishr",
116.492 + "lshr",
116.493 + "iushr",
116.494 + "lushr",
116.495 + "iand",
116.496 + "land",
116.497 + "ior",
116.498 + "lor",
116.499 + "ixor",
116.500 + "lxor",
116.501 + "iinc",
116.502 + "i2l",
116.503 + "i2f",
116.504 + "i2d",
116.505 + "l2i",
116.506 + "l2f",
116.507 + "l2d",
116.508 + "f2i",
116.509 + "f2l",
116.510 + "f2d",
116.511 + "d2i",
116.512 + "d2l",
116.513 + "d2f",
116.514 + "i2b",
116.515 + "i2c",
116.516 + "i2s",
116.517 + "lcmp",
116.518 + "fcmpl",
116.519 + "fcmpg",
116.520 + "dcmpl",
116.521 + "dcmpg",
116.522 + "ifeq",
116.523 + "ifne",
116.524 + "iflt",
116.525 + "ifge",
116.526 + "ifgt",
116.527 + "ifle",
116.528 + "if_icmpeq",
116.529 + "if_icmpne",
116.530 + "if_icmplt",
116.531 + "if_icmpge",
116.532 + "if_icmpgt",
116.533 + "if_icmple",
116.534 + "if_acmpeq",
116.535 + "if_acmpne",
116.536 + "goto",
116.537 + "jsr",
116.538 + "ret",
116.539 + "tableswitch",
116.540 + "lookupswitch",
116.541 + "ireturn",
116.542 + "lreturn",
116.543 + "freturn",
116.544 + "dreturn",
116.545 + "areturn",
116.546 + "return",
116.547 + "getstatic",
116.548 + "putstatic",
116.549 + "getfield",
116.550 + "putfield",
116.551 + "invokevirtual",
116.552 + "invokespecial", // was "invokenonvirtual",
116.553 + "invokestatic",
116.554 + "invokeinterface",
116.555 + "bytecode 186", //"xxxunusedxxx",
116.556 + "new",
116.557 + "newarray",
116.558 + "anewarray",
116.559 + "arraylength",
116.560 + "athrow",
116.561 + "checkcast",
116.562 + "instanceof",
116.563 + "monitorenter",
116.564 + "monitorexit",
116.565 + null, // "wide",
116.566 + "multianewarray",
116.567 + "ifnull",
116.568 + "ifnonnull",
116.569 + "goto_w",
116.570 + "jsr_w",
116.571 + "bytecode 202", // "breakpoint",
116.572 + "bytecode",
116.573 + "try",
116.574 + "endtry",
116.575 + "catch",
116.576 + "var",
116.577 + "endvar",
116.578 + "locals_map",
116.579 + "stack_map"
116.580 + };
116.581 +
116.582 + /* Opcode Lengths */
116.583 + public static final int opcLengthsTab[] = {
116.584 + 1,
116.585 + 1,
116.586 + 1,
116.587 + 1,
116.588 + 1,
116.589 + 1,
116.590 + 1,
116.591 + 1,
116.592 + 1,
116.593 + 1,
116.594 + 1,
116.595 + 1,
116.596 + 1,
116.597 + 1,
116.598 + 1,
116.599 + 1,
116.600 + 2,
116.601 + 3,
116.602 + 2,
116.603 + 3,
116.604 + 3,
116.605 + 2,
116.606 + 2,
116.607 + 2,
116.608 + 2,
116.609 + 2,
116.610 + 1,
116.611 + 1,
116.612 + 1,
116.613 + 1,
116.614 + 1,
116.615 + 1,
116.616 + 1,
116.617 + 1,
116.618 + 1,
116.619 + 1,
116.620 + 1,
116.621 + 1,
116.622 + 1,
116.623 + 1,
116.624 + 1,
116.625 + 1,
116.626 + 1,
116.627 + 1,
116.628 + 1,
116.629 + 1,
116.630 + 1,
116.631 + 1,
116.632 + 1,
116.633 + 1,
116.634 + 1,
116.635 + 1,
116.636 + 1,
116.637 + 1,
116.638 + 2,
116.639 + 2,
116.640 + 2,
116.641 + 2,
116.642 + 2,
116.643 + 1,
116.644 + 1,
116.645 + 1,
116.646 + 1,
116.647 + 1,
116.648 + 1,
116.649 + 1,
116.650 + 1,
116.651 + 1,
116.652 + 1,
116.653 + 1,
116.654 + 1,
116.655 + 1,
116.656 + 1,
116.657 + 1,
116.658 + 1,
116.659 + 1,
116.660 + 1,
116.661 + 1,
116.662 + 1,
116.663 + 1,
116.664 + 1,
116.665 + 1,
116.666 + 1,
116.667 + 1,
116.668 + 1,
116.669 + 1,
116.670 + 1,
116.671 + 1,
116.672 + 1,
116.673 + 1,
116.674 + 1,
116.675 + 1,
116.676 + 1,
116.677 + 1,
116.678 + 1,
116.679 + 1,
116.680 + 1,
116.681 + 1,
116.682 + 1,
116.683 + 1,
116.684 + 1,
116.685 + 1,
116.686 + 1,
116.687 + 1,
116.688 + 1,
116.689 + 1,
116.690 + 1,
116.691 + 1,
116.692 + 1,
116.693 + 1,
116.694 + 1,
116.695 + 1,
116.696 + 1,
116.697 + 1,
116.698 + 1,
116.699 + 1,
116.700 + 1,
116.701 + 1,
116.702 + 1,
116.703 + 1,
116.704 + 1,
116.705 + 1,
116.706 + 1,
116.707 + 1,
116.708 + 1,
116.709 + 1,
116.710 + 1,
116.711 + 1,
116.712 + 1,
116.713 + 1,
116.714 + 1,
116.715 + 1,
116.716 + 3,
116.717 + 1,
116.718 + 1,
116.719 + 1,
116.720 + 1,
116.721 + 1,
116.722 + 1,
116.723 + 1,
116.724 + 1,
116.725 + 1,
116.726 + 1,
116.727 + 1,
116.728 + 1,
116.729 + 1,
116.730 + 1,
116.731 + 1,
116.732 + 1,
116.733 + 1,
116.734 + 1,
116.735 + 1,
116.736 + 1,
116.737 + 3,
116.738 + 3,
116.739 + 3,
116.740 + 3,
116.741 + 3,
116.742 + 3,
116.743 + 3,
116.744 + 3,
116.745 + 3,
116.746 + 3,
116.747 + 3,
116.748 + 3,
116.749 + 3,
116.750 + 3,
116.751 + 3,
116.752 + 3,
116.753 + 2,
116.754 + 99,
116.755 + 99,
116.756 + 1,
116.757 + 1,
116.758 + 1,
116.759 + 1,
116.760 + 1,
116.761 + 1,
116.762 + 3,
116.763 + 3,
116.764 + 3,
116.765 + 3,
116.766 + 3,
116.767 + 3,
116.768 + 3,
116.769 + 5,
116.770 + 0,
116.771 + 3,
116.772 + 2,
116.773 + 3,
116.774 + 1,
116.775 + 1,
116.776 + 3,
116.777 + 3,
116.778 + 1,
116.779 + 1,
116.780 + 0, // wide
116.781 + 4,
116.782 + 3,
116.783 + 3,
116.784 + 5,
116.785 + 5,
116.786 + 1,
116.787 + 1, 0, 0, 0, 0, 0 // pseudo
116.788 + };
116.789 +
116.790 +}
117.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
117.2 +++ b/javap/src/main/java/org/apidesign/javap/StackMapData.java Wed Jan 23 20:16:48 2013 +0100
117.3 @@ -0,0 +1,71 @@
117.4 +/*
117.5 + * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
117.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
117.7 + *
117.8 + * This code is free software; you can redistribute it and/or modify it
117.9 + * under the terms of the GNU General Public License version 2 only, as
117.10 + * published by the Free Software Foundation. Oracle designates this
117.11 + * particular file as subject to the "Classpath" exception as provided
117.12 + * by Oracle in the LICENSE file that accompanied this code.
117.13 + *
117.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
117.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
117.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
117.17 + * version 2 for more details (a copy is included in the LICENSE file that
117.18 + * accompanied this code).
117.19 + *
117.20 + * You should have received a copy of the GNU General Public License version
117.21 + * 2 along with this work; if not, write to the Free Software Foundation,
117.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
117.23 + *
117.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
117.25 + * or visit www.oracle.com if you need additional information or have any
117.26 + * questions.
117.27 + */
117.28 +
117.29 +
117.30 +package org.apidesign.javap;
117.31 +
117.32 +import java.util.*;
117.33 +import java.io.*;
117.34 +
117.35 +import static org.apidesign.javap.RuntimeConstants.*;
117.36 +
117.37 +/* represents one entry of StackMap attribute
117.38 + */
117.39 +class StackMapData {
117.40 + final int offset;
117.41 + final int[] locals;
117.42 + final int[] stack;
117.43 +
117.44 + StackMapData(int offset, int[] locals, int[] stack) {
117.45 + this.offset = offset;
117.46 + this.locals = locals;
117.47 + this.stack = stack;
117.48 + }
117.49 +
117.50 + StackMapData(DataInputStream in, MethodData method) throws IOException {
117.51 + offset = in.readUnsignedShort();
117.52 + int local_size = in.readUnsignedShort();
117.53 + locals = readTypeArray(in, local_size, method);
117.54 + int stack_size = in.readUnsignedShort();
117.55 + stack = readTypeArray(in, stack_size, method);
117.56 + }
117.57 +
117.58 + static final int[] readTypeArray(DataInputStream in, int length, MethodData method) throws IOException {
117.59 + int[] types = new int[length];
117.60 + for (int i=0; i<length; i++) {
117.61 + types[i] = readType(in, method);
117.62 + }
117.63 + return types;
117.64 + }
117.65 +
117.66 + static final int readType(DataInputStream in, MethodData method) throws IOException {
117.67 + int type = in.readUnsignedByte();
117.68 + if (type == ITEM_Object || type == ITEM_NewObject) {
117.69 + type = type | (in.readUnsignedShort()<<8);
117.70 + }
117.71 + return type;
117.72 + }
117.73 +
117.74 +}
118.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
118.2 +++ b/javap/src/main/java/org/apidesign/javap/StackMapIterator.java Wed Jan 23 20:16:48 2013 +0100
118.3 @@ -0,0 +1,179 @@
118.4 +/*
118.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
118.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
118.7 + *
118.8 + * This code is free software; you can redistribute it and/or modify it
118.9 + * under the terms of the GNU General Public License version 2 only, as
118.10 + * published by the Free Software Foundation. Oracle designates this
118.11 + * particular file as subject to the "Classpath" exception as provided
118.12 + * by Oracle in the LICENSE file that accompanied this code.
118.13 + *
118.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
118.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
118.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
118.17 + * version 2 for more details (a copy is included in the LICENSE file that
118.18 + * accompanied this code).
118.19 + *
118.20 + * You should have received a copy of the GNU General Public License version
118.21 + * 2 along with this work; if not, write to the Free Software Foundation,
118.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
118.23 + *
118.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
118.25 + * or visit www.oracle.com if you need additional information or have any
118.26 + * questions.
118.27 + */
118.28 +
118.29 +package org.apidesign.javap;
118.30 +
118.31 +import static org.apidesign.javap.RuntimeConstants.ITEM_Integer;
118.32 +import static org.apidesign.javap.RuntimeConstants.ITEM_Float;
118.33 +import static org.apidesign.javap.RuntimeConstants.ITEM_Double;
118.34 +import static org.apidesign.javap.RuntimeConstants.ITEM_Long;
118.35 +import static org.apidesign.javap.RuntimeConstants.ITEM_Object;
118.36 +
118.37 +public final class StackMapIterator {
118.38 + private final StackMapTableData[] stackMapTable;
118.39 + private final TypeArray argTypes;
118.40 + private final TypeArray localTypes;
118.41 + private final TypeArray stackTypes;
118.42 +
118.43 + private int nextFrameIndex;
118.44 + private int lastFrameByteCodeOffset;
118.45 +
118.46 + private int byteCodeOffset;
118.47 +
118.48 + StackMapIterator(final MethodData methodData) {
118.49 + this(methodData.getStackMapTable(),
118.50 + methodData.getInternalSig(),
118.51 + methodData.isStatic());
118.52 + }
118.53 +
118.54 + StackMapIterator(final StackMapTableData[] stackMapTable,
118.55 + final String methodSignature,
118.56 + final boolean isStaticMethod) {
118.57 + this.stackMapTable = (stackMapTable != null)
118.58 + ? stackMapTable
118.59 + : new StackMapTableData[0];
118.60 +
118.61 + argTypes = getArgTypes(methodSignature, isStaticMethod);
118.62 + localTypes = new TypeArray();
118.63 + stackTypes = new TypeArray();
118.64 +
118.65 + localTypes.addAll(argTypes);
118.66 +
118.67 + lastFrameByteCodeOffset = -1;
118.68 + advanceBy(0);
118.69 + }
118.70 +
118.71 + public String getFrameAsString() {
118.72 + return (nextFrameIndex == 0)
118.73 + ? StackMapTableData.toString("INITIAL", 0, null, null)
118.74 + : stackMapTable[nextFrameIndex - 1].toString();
118.75 + }
118.76 +
118.77 + public int getFrameIndex() {
118.78 + return nextFrameIndex;
118.79 + }
118.80 +
118.81 + public TypeArray getFrameStack() {
118.82 + return stackTypes;
118.83 + }
118.84 +
118.85 + public TypeArray getFrameLocals() {
118.86 + return localTypes;
118.87 + }
118.88 +
118.89 + public TypeArray getArguments() {
118.90 + return argTypes;
118.91 + }
118.92 +
118.93 + public void advanceBy(final int numByteCodes) {
118.94 + if (numByteCodes < 0) {
118.95 + throw new IllegalStateException("Forward only iterator");
118.96 + }
118.97 +
118.98 + byteCodeOffset += numByteCodes;
118.99 + while ((nextFrameIndex < stackMapTable.length)
118.100 + && ((byteCodeOffset - lastFrameByteCodeOffset)
118.101 + >= (stackMapTable[nextFrameIndex].offsetDelta
118.102 + + 1))) {
118.103 + final StackMapTableData nextFrame = stackMapTable[nextFrameIndex];
118.104 +
118.105 + lastFrameByteCodeOffset += nextFrame.offsetDelta + 1;
118.106 + nextFrame.applyTo(localTypes, stackTypes);
118.107 +
118.108 + ++nextFrameIndex;
118.109 + }
118.110 + }
118.111 +
118.112 + public void advanceTo(final int nextByteCodeOffset) {
118.113 + advanceBy(nextByteCodeOffset - byteCodeOffset);
118.114 + }
118.115 +
118.116 + private static TypeArray getArgTypes(final String methodSignature,
118.117 + final boolean isStaticMethod) {
118.118 + final TypeArray argTypes = new TypeArray();
118.119 +
118.120 + if (!isStaticMethod) {
118.121 + argTypes.add(ITEM_Object);
118.122 + }
118.123 +
118.124 + if (methodSignature.charAt(0) != '(') {
118.125 + throw new IllegalArgumentException("Invalid method signature");
118.126 + }
118.127 +
118.128 + final int length = methodSignature.length();
118.129 + boolean skipType = false;
118.130 + int argType;
118.131 + for (int i = 1; i < length; ++i) {
118.132 + switch (methodSignature.charAt(i)) {
118.133 + case 'B':
118.134 + case 'C':
118.135 + case 'S':
118.136 + case 'Z':
118.137 + case 'I':
118.138 + argType = ITEM_Integer;
118.139 + break;
118.140 + case 'J':
118.141 + argType = ITEM_Long;
118.142 + break;
118.143 + case 'F':
118.144 + argType = ITEM_Float;
118.145 + break;
118.146 + case 'D':
118.147 + argType = ITEM_Double;
118.148 + break;
118.149 + case 'L': {
118.150 + i = methodSignature.indexOf(';', i + 1);
118.151 + if (i == -1) {
118.152 + throw new IllegalArgumentException(
118.153 + "Invalid method signature");
118.154 + }
118.155 + argType = ITEM_Object;
118.156 + break;
118.157 + }
118.158 + case ')':
118.159 + // not interested in the return value type
118.160 + return argTypes;
118.161 + case '[':
118.162 + if (!skipType) {
118.163 + argTypes.add(ITEM_Object);
118.164 + skipType = true;
118.165 + }
118.166 + continue;
118.167 +
118.168 + default:
118.169 + throw new IllegalArgumentException(
118.170 + "Invalid method signature");
118.171 + }
118.172 +
118.173 + if (!skipType) {
118.174 + argTypes.add(argType);
118.175 + } else {
118.176 + skipType = false;
118.177 + }
118.178 + }
118.179 +
118.180 + return argTypes;
118.181 + }
118.182 +}
119.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
119.2 +++ b/javap/src/main/java/org/apidesign/javap/StackMapTableData.java Wed Jan 23 20:16:48 2013 +0100
119.3 @@ -0,0 +1,223 @@
119.4 +/*
119.5 + * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
119.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
119.7 + *
119.8 + * This code is free software; you can redistribute it and/or modify it
119.9 + * under the terms of the GNU General Public License version 2 only, as
119.10 + * published by the Free Software Foundation. Oracle designates this
119.11 + * particular file as subject to the "Classpath" exception as provided
119.12 + * by Oracle in the LICENSE file that accompanied this code.
119.13 + *
119.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
119.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
119.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
119.17 + * version 2 for more details (a copy is included in the LICENSE file that
119.18 + * accompanied this code).
119.19 + *
119.20 + * You should have received a copy of the GNU General Public License version
119.21 + * 2 along with this work; if not, write to the Free Software Foundation,
119.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
119.23 + *
119.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
119.25 + * or visit www.oracle.com if you need additional information or have any
119.26 + * questions.
119.27 + */
119.28 +
119.29 +
119.30 +package org.apidesign.javap;
119.31 +
119.32 +import java.io.*;
119.33 +
119.34 +import static org.apidesign.javap.RuntimeConstants.*;
119.35 +
119.36 +/* represents one entry of StackMapTable attribute
119.37 + */
119.38 +abstract class StackMapTableData {
119.39 + final int frameType;
119.40 + int offsetDelta;
119.41 +
119.42 + StackMapTableData(int frameType) {
119.43 + this.frameType = frameType;
119.44 + }
119.45 +
119.46 + abstract void applyTo(TypeArray localTypes, TypeArray stackTypes);
119.47 +
119.48 + protected static String toString(
119.49 + final String frameType,
119.50 + final int offset,
119.51 + final int[] localTypes,
119.52 + final int[] stackTypes) {
119.53 + final StringBuilder sb = new StringBuilder(frameType);
119.54 +
119.55 + sb.append("(off: +").append(offset);
119.56 + if (localTypes != null) {
119.57 + sb.append(", locals: ");
119.58 + appendTypes(sb, localTypes);
119.59 + }
119.60 + if (stackTypes != null) {
119.61 + sb.append(", stack: ");
119.62 + appendTypes(sb, stackTypes);
119.63 + }
119.64 + sb.append(')');
119.65 +
119.66 + return sb.toString();
119.67 + }
119.68 +
119.69 + private static void appendTypes(final StringBuilder sb, final int[] types) {
119.70 + sb.append('[');
119.71 + if (types.length > 0) {
119.72 + sb.append(TypeArray.typeString(types[0]));
119.73 + for (int i = 1; i < types.length; ++i) {
119.74 + sb.append(", ");
119.75 + sb.append(TypeArray.typeString(types[i]));
119.76 + }
119.77 + }
119.78 + sb.append(']');
119.79 + }
119.80 +
119.81 + static class SameFrame extends StackMapTableData {
119.82 + SameFrame(int frameType, int offsetDelta) {
119.83 + super(frameType);
119.84 + this.offsetDelta = offsetDelta;
119.85 + }
119.86 +
119.87 + @Override
119.88 + void applyTo(TypeArray localTypes, TypeArray stackTypes) {
119.89 + stackTypes.clear();
119.90 + }
119.91 +
119.92 + @Override
119.93 + public String toString() {
119.94 + return toString("SAME" + ((frameType == SAME_FRAME_EXTENDED)
119.95 + ? "_FRAME_EXTENDED" : ""),
119.96 + offsetDelta,
119.97 + null, null);
119.98 + }
119.99 + }
119.100 +
119.101 + static class SameLocals1StackItem extends StackMapTableData {
119.102 + final int[] stack;
119.103 + SameLocals1StackItem(int frameType, int offsetDelta, int[] stack) {
119.104 + super(frameType);
119.105 + this.offsetDelta = offsetDelta;
119.106 + this.stack = stack;
119.107 + }
119.108 +
119.109 + @Override
119.110 + void applyTo(TypeArray localTypes, TypeArray stackTypes) {
119.111 + stackTypes.setAll(stack);
119.112 + }
119.113 +
119.114 + @Override
119.115 + public String toString() {
119.116 + return toString(
119.117 + "SAME_LOCALS_1_STACK_ITEM"
119.118 + + ((frameType == SAME_LOCALS_1_STACK_ITEM_EXTENDED)
119.119 + ? "_EXTENDED" : ""),
119.120 + offsetDelta,
119.121 + null, stack);
119.122 + }
119.123 + }
119.124 +
119.125 + static class ChopFrame extends StackMapTableData {
119.126 + ChopFrame(int frameType, int offsetDelta) {
119.127 + super(frameType);
119.128 + this.offsetDelta = offsetDelta;
119.129 + }
119.130 +
119.131 + @Override
119.132 + void applyTo(TypeArray localTypes, TypeArray stackTypes) {
119.133 + localTypes.setSize(localTypes.getSize()
119.134 + - (SAME_FRAME_EXTENDED - frameType));
119.135 + stackTypes.clear();
119.136 + }
119.137 +
119.138 + @Override
119.139 + public String toString() {
119.140 + return toString("CHOP", offsetDelta, null, null);
119.141 + }
119.142 + }
119.143 +
119.144 + static class AppendFrame extends StackMapTableData {
119.145 + final int[] locals;
119.146 + AppendFrame(int frameType, int offsetDelta, int[] locals) {
119.147 + super(frameType);
119.148 + this.offsetDelta = offsetDelta;
119.149 + this.locals = locals;
119.150 + }
119.151 +
119.152 + @Override
119.153 + void applyTo(TypeArray localTypes, TypeArray stackTypes) {
119.154 + localTypes.addAll(locals);
119.155 + stackTypes.clear();
119.156 + }
119.157 +
119.158 + @Override
119.159 + public String toString() {
119.160 + return toString("APPEND", offsetDelta, locals, null);
119.161 + }
119.162 + }
119.163 +
119.164 + static class FullFrame extends StackMapTableData {
119.165 + final int[] locals;
119.166 + final int[] stack;
119.167 + FullFrame(int offsetDelta, int[] locals, int[] stack) {
119.168 + super(FULL_FRAME);
119.169 + this.offsetDelta = offsetDelta;
119.170 + this.locals = locals;
119.171 + this.stack = stack;
119.172 + }
119.173 +
119.174 + @Override
119.175 + void applyTo(TypeArray localTypes, TypeArray stackTypes) {
119.176 + localTypes.setAll(locals);
119.177 + stackTypes.setAll(stack);
119.178 + }
119.179 +
119.180 + @Override
119.181 + public String toString() {
119.182 + return toString("FULL", offsetDelta, locals, stack);
119.183 + }
119.184 + }
119.185 +
119.186 + static StackMapTableData getInstance(DataInputStream in, MethodData method)
119.187 + throws IOException {
119.188 + int frameType = in.readUnsignedByte();
119.189 +
119.190 + if (frameType < SAME_FRAME_BOUND) {
119.191 + // same_frame
119.192 + return new SameFrame(frameType, frameType);
119.193 + } else if (SAME_FRAME_BOUND <= frameType && frameType < SAME_LOCALS_1_STACK_ITEM_BOUND) {
119.194 + // same_locals_1_stack_item_frame
119.195 + // read additional single stack element
119.196 + return new SameLocals1StackItem(frameType,
119.197 + (frameType - SAME_FRAME_BOUND),
119.198 + StackMapData.readTypeArray(in, 1, method));
119.199 + } else if (frameType == SAME_LOCALS_1_STACK_ITEM_EXTENDED) {
119.200 + // same_locals_1_stack_item_extended
119.201 + return new SameLocals1StackItem(frameType,
119.202 + in.readUnsignedShort(),
119.203 + StackMapData.readTypeArray(in, 1, method));
119.204 + } else if (SAME_LOCALS_1_STACK_ITEM_EXTENDED < frameType && frameType < SAME_FRAME_EXTENDED) {
119.205 + // chop_frame or same_frame_extended
119.206 + return new ChopFrame(frameType, in.readUnsignedShort());
119.207 + } else if (frameType == SAME_FRAME_EXTENDED) {
119.208 + // chop_frame or same_frame_extended
119.209 + return new SameFrame(frameType, in.readUnsignedShort());
119.210 + } else if (SAME_FRAME_EXTENDED < frameType && frameType < FULL_FRAME) {
119.211 + // append_frame
119.212 + return new AppendFrame(frameType, in.readUnsignedShort(),
119.213 + StackMapData.readTypeArray(in, frameType - SAME_FRAME_EXTENDED, method));
119.214 + } else if (frameType == FULL_FRAME) {
119.215 + // full_frame
119.216 + int offsetDelta = in.readUnsignedShort();
119.217 + int locals_size = in.readUnsignedShort();
119.218 + int[] locals = StackMapData.readTypeArray(in, locals_size, method);
119.219 + int stack_size = in.readUnsignedShort();
119.220 + int[] stack = StackMapData.readTypeArray(in, stack_size, method);
119.221 + return new FullFrame(offsetDelta, locals, stack);
119.222 + } else {
119.223 + throw new ClassFormatError("unrecognized frame_type in StackMapTable");
119.224 + }
119.225 + }
119.226 +}
120.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
120.2 +++ b/javap/src/main/java/org/apidesign/javap/TrapData.java Wed Jan 23 20:16:48 2013 +0100
120.3 @@ -0,0 +1,62 @@
120.4 +/*
120.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
120.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
120.7 + *
120.8 + * This code is free software; you can redistribute it and/or modify it
120.9 + * under the terms of the GNU General Public License version 2 only, as
120.10 + * published by the Free Software Foundation. Oracle designates this
120.11 + * particular file as subject to the "Classpath" exception as provided
120.12 + * by Oracle in the LICENSE file that accompanied this code.
120.13 + *
120.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
120.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
120.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
120.17 + * version 2 for more details (a copy is included in the LICENSE file that
120.18 + * accompanied this code).
120.19 + *
120.20 + * You should have received a copy of the GNU General Public License version
120.21 + * 2 along with this work; if not, write to the Free Software Foundation,
120.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
120.23 + *
120.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
120.25 + * or visit www.oracle.com if you need additional information or have any
120.26 + * questions.
120.27 + */
120.28 +
120.29 +
120.30 +package org.apidesign.javap;
120.31 +
120.32 +import java.io.*;
120.33 +
120.34 +/**
120.35 + * Stores exception table data in code attribute.
120.36 + *
120.37 + * @author Sucheta Dambalkar (Adopted code from jdis)
120.38 + */
120.39 +public final class TrapData {
120.40 + public final short start_pc;
120.41 + public final short end_pc;
120.42 + public final short handler_pc;
120.43 + public final short catch_cpx;
120.44 + final int num;
120.45 +
120.46 +
120.47 + /**
120.48 + * Read and store exception table data in code attribute.
120.49 + */
120.50 + TrapData(DataInputStream in, int num) throws IOException {
120.51 + this.num=num;
120.52 + start_pc = in.readShort();
120.53 + end_pc=in.readShort();
120.54 + handler_pc=in.readShort();
120.55 + catch_cpx=in.readShort();
120.56 + }
120.57 +
120.58 + /**
120.59 + * returns recommended identifier
120.60 + */
120.61 + public String ident() {
120.62 + return "t"+num;
120.63 + }
120.64 +
120.65 +}
121.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
121.2 +++ b/javap/src/main/java/org/apidesign/javap/TrapDataIterator.java Wed Jan 23 20:16:48 2013 +0100
121.3 @@ -0,0 +1,114 @@
121.4 +/**
121.5 + * Back 2 Browser Bytecode Translator
121.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
121.7 + *
121.8 + * This program is free software: you can redistribute it and/or modify
121.9 + * it under the terms of the GNU General Public License as published by
121.10 + * the Free Software Foundation, version 2 of the License.
121.11 + *
121.12 + * This program is distributed in the hope that it will be useful,
121.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
121.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
121.15 + * GNU General Public License for more details.
121.16 + *
121.17 + * You should have received a copy of the GNU General Public License
121.18 + * along with this program. Look for COPYING file in the top folder.
121.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
121.20 + */
121.21 +package org.apidesign.javap;
121.22 +
121.23 +/**
121.24 + *
121.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
121.26 + */
121.27 +public final class TrapDataIterator {
121.28 + private final Hashtable exStart = new Hashtable();
121.29 + private final Hashtable exStop = new Hashtable();
121.30 + private TrapData[] current = new TrapData[10];
121.31 + private int currentCount;
121.32 +
121.33 + TrapDataIterator(Vector exceptionTable) {
121.34 + for (int i=0 ; i < exceptionTable.size(); i++) {
121.35 + final TrapData td = (TrapData)exceptionTable.elementAt(i);
121.36 + put(exStart, td.start_pc, td);
121.37 + put(exStop, td.end_pc, td);
121.38 + }
121.39 + }
121.40 +
121.41 + private static void put(Hashtable h, short key, TrapData td) {
121.42 + Short s = Short.valueOf((short)key);
121.43 + Vector v = (Vector) h.get(s);
121.44 + if (v == null) {
121.45 + v = new Vector(1);
121.46 + h.put(s, v);
121.47 + }
121.48 + v.add(td);
121.49 + }
121.50 +
121.51 + private boolean processAll(Hashtable h, Short key, boolean add) {
121.52 + boolean change = false;
121.53 + Vector v = (Vector)h.get(key);
121.54 + if (v != null) {
121.55 + int s = v.size();
121.56 + for (int i = 0; i < s; i++) {
121.57 + TrapData td = (TrapData)v.elementAt(i);
121.58 + if (add) {
121.59 + add(td);
121.60 + change = true;
121.61 + } else {
121.62 + remove(td);
121.63 + change = true;
121.64 + }
121.65 + }
121.66 + }
121.67 + return change;
121.68 + }
121.69 +
121.70 + public boolean advanceTo(int i) {
121.71 + Short s = Short.valueOf((short)i);
121.72 + boolean ch1 = processAll(exStart, s, true);
121.73 + boolean ch2 = processAll(exStop, s, false);
121.74 + return ch1 || ch2;
121.75 + }
121.76 +
121.77 + public boolean useTry() {
121.78 + return currentCount > 0;
121.79 + }
121.80 +
121.81 + public TrapData[] current() {
121.82 + TrapData[] copy = new TrapData[currentCount];
121.83 + for (int i = 0; i < currentCount; i++) {
121.84 + copy[i] = current[i];
121.85 + }
121.86 + return copy;
121.87 + }
121.88 +
121.89 + private void add(TrapData e) {
121.90 + if (currentCount == current.length) {
121.91 + TrapData[] data = new TrapData[currentCount * 2];
121.92 + for (int i = 0; i < currentCount; i++) {
121.93 + data[i] = current[i];
121.94 + }
121.95 + current = data;
121.96 + }
121.97 + current[currentCount++] = e;
121.98 + }
121.99 +
121.100 + private void remove(TrapData e) {
121.101 + if (currentCount == 0) {
121.102 + return;
121.103 + }
121.104 + int from = 0;
121.105 + while (from < currentCount) {
121.106 + if (e == current[from++]) {
121.107 + break;
121.108 + }
121.109 + }
121.110 + while (from < currentCount) {
121.111 + current[from - 1] = current[from];
121.112 + current[from] = null;
121.113 + from++;
121.114 + }
121.115 + currentCount--;
121.116 + }
121.117 +}
122.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
122.2 +++ b/javap/src/main/java/org/apidesign/javap/TypeArray.java Wed Jan 23 20:16:48 2013 +0100
122.3 @@ -0,0 +1,186 @@
122.4 +/*
122.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
122.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
122.7 + *
122.8 + * This code is free software; you can redistribute it and/or modify it
122.9 + * under the terms of the GNU General Public License version 2 only, as
122.10 + * published by the Free Software Foundation. Oracle designates this
122.11 + * particular file as subject to the "Classpath" exception as provided
122.12 + * by Oracle in the LICENSE file that accompanied this code.
122.13 + *
122.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
122.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
122.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
122.17 + * version 2 for more details (a copy is included in the LICENSE file that
122.18 + * accompanied this code).
122.19 + *
122.20 + * You should have received a copy of the GNU General Public License version
122.21 + * 2 along with this work; if not, write to the Free Software Foundation,
122.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
122.23 + *
122.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
122.25 + * or visit www.oracle.com if you need additional information or have any
122.26 + * questions.
122.27 + */
122.28 +
122.29 +package org.apidesign.javap;
122.30 +
122.31 +import static org.apidesign.javap.RuntimeConstants.ITEM_Bogus;
122.32 +import static org.apidesign.javap.RuntimeConstants.ITEM_Integer;
122.33 +import static org.apidesign.javap.RuntimeConstants.ITEM_Float;
122.34 +import static org.apidesign.javap.RuntimeConstants.ITEM_Double;
122.35 +import static org.apidesign.javap.RuntimeConstants.ITEM_Long;
122.36 +import static org.apidesign.javap.RuntimeConstants.ITEM_Null;
122.37 +import static org.apidesign.javap.RuntimeConstants.ITEM_InitObject;
122.38 +import static org.apidesign.javap.RuntimeConstants.ITEM_Object;
122.39 +import static org.apidesign.javap.RuntimeConstants.ITEM_NewObject;
122.40 +
122.41 +public final class TypeArray {
122.42 + private static final int CAPACITY_INCREMENT = 16;
122.43 +
122.44 + private int[] types;
122.45 + private int size;
122.46 +
122.47 + public TypeArray() {
122.48 + }
122.49 +
122.50 + public TypeArray(final TypeArray initialTypes) {
122.51 + setAll(initialTypes);
122.52 + }
122.53 +
122.54 + public void add(final int newType) {
122.55 + ensureCapacity(size + 1);
122.56 + types[size++] = newType;
122.57 + }
122.58 +
122.59 + public void addAll(final TypeArray newTypes) {
122.60 + addAll(newTypes.types, 0, newTypes.size);
122.61 + }
122.62 +
122.63 + public void addAll(final int[] newTypes) {
122.64 + addAll(newTypes, 0, newTypes.length);
122.65 + }
122.66 +
122.67 + public void addAll(final int[] newTypes,
122.68 + final int offset,
122.69 + final int count) {
122.70 + if (count > 0) {
122.71 + ensureCapacity(size + count);
122.72 + arraycopy(newTypes, offset, types, size, count);
122.73 + size += count;
122.74 + }
122.75 + }
122.76 +
122.77 + public void set(final int index, final int newType) {
122.78 + types[index] = newType;
122.79 + }
122.80 +
122.81 + public void setAll(final TypeArray newTypes) {
122.82 + setAll(newTypes.types, 0, newTypes.size);
122.83 + }
122.84 +
122.85 + public void setAll(final int[] newTypes) {
122.86 + setAll(newTypes, 0, newTypes.length);
122.87 + }
122.88 +
122.89 + public void setAll(final int[] newTypes,
122.90 + final int offset,
122.91 + final int count) {
122.92 + if (count > 0) {
122.93 + ensureCapacity(count);
122.94 + arraycopy(newTypes, offset, types, 0, count);
122.95 + size = count;
122.96 + } else {
122.97 + clear();
122.98 + }
122.99 + }
122.100 +
122.101 + public void setSize(final int newSize) {
122.102 + if (size != newSize) {
122.103 + ensureCapacity(newSize);
122.104 +
122.105 + for (int i = size; i < newSize; ++i) {
122.106 + types[i] = 0;
122.107 + }
122.108 + size = newSize;
122.109 + }
122.110 + }
122.111 +
122.112 + public void clear() {
122.113 + size = 0;
122.114 + }
122.115 +
122.116 + public int getSize() {
122.117 + return size;
122.118 + }
122.119 +
122.120 + public int get(final int index) {
122.121 + return types[index];
122.122 + }
122.123 +
122.124 + public static String typeString(final int type) {
122.125 + switch (type & 0xff) {
122.126 + case ITEM_Bogus:
122.127 + return "_top_";
122.128 + case ITEM_Integer:
122.129 + return "_int_";
122.130 + case ITEM_Float:
122.131 + return "_float_";
122.132 + case ITEM_Double:
122.133 + return "_double_";
122.134 + case ITEM_Long:
122.135 + return "_long_";
122.136 + case ITEM_Null:
122.137 + return "_null_";
122.138 + case ITEM_InitObject: // UninitializedThis
122.139 + return "_init_";
122.140 + case ITEM_Object:
122.141 + return "_object_";
122.142 + case ITEM_NewObject: // Uninitialized
122.143 + return "_new_";
122.144 + default:
122.145 + throw new IllegalArgumentException("Unknown type");
122.146 + }
122.147 + }
122.148 +
122.149 + @Override
122.150 + public String toString() {
122.151 + final StringBuilder sb = new StringBuilder("[");
122.152 + if (size > 0) {
122.153 + sb.append(typeString(types[0]));
122.154 + for (int i = 1; i < size; ++i) {
122.155 + sb.append(", ");
122.156 + sb.append(typeString(types[i]));
122.157 + }
122.158 + }
122.159 +
122.160 + return sb.append(']').toString();
122.161 + }
122.162 +
122.163 + private void ensureCapacity(final int minCapacity) {
122.164 + if ((minCapacity == 0)
122.165 + || (types != null) && (minCapacity <= types.length)) {
122.166 + return;
122.167 + }
122.168 +
122.169 + final int newCapacity =
122.170 + ((minCapacity + CAPACITY_INCREMENT - 1) / CAPACITY_INCREMENT)
122.171 + * CAPACITY_INCREMENT;
122.172 + final int[] newTypes = new int[newCapacity];
122.173 +
122.174 + if (size > 0) {
122.175 + arraycopy(types, 0, newTypes, 0, size);
122.176 + }
122.177 +
122.178 + types = newTypes;
122.179 + }
122.180 +
122.181 + // no System.arraycopy
122.182 + private void arraycopy(final int[] src, final int srcPos,
122.183 + final int[] dest, final int destPos,
122.184 + final int length) {
122.185 + for (int i = 0; i < length; ++i) {
122.186 + dest[destPos + i] = src[srcPos + i];
122.187 + }
122.188 + }
122.189 +}
123.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
123.2 +++ b/javap/src/main/java/org/apidesign/javap/Vector.java Wed Jan 23 20:16:48 2013 +0100
123.3 @@ -0,0 +1,89 @@
123.4 +/**
123.5 + * Back 2 Browser Bytecode Translator
123.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
123.7 + *
123.8 + * This program is free software: you can redistribute it and/or modify
123.9 + * it under the terms of the GNU General Public License as published by
123.10 + * the Free Software Foundation, version 2 of the License.
123.11 + *
123.12 + * This program is distributed in the hope that it will be useful,
123.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
123.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
123.15 + * GNU General Public License for more details.
123.16 + *
123.17 + * You should have received a copy of the GNU General Public License
123.18 + * along with this program. Look for COPYING file in the top folder.
123.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
123.20 + */
123.21 +package org.apidesign.javap;
123.22 +
123.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
123.24 +import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
123.25 +
123.26 +/** A JavaScript ready replacement for java.util.Vector
123.27 + *
123.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
123.29 + */
123.30 +@JavaScriptPrototype(prototype = "new Array" )
123.31 +final class Vector {
123.32 + private Object[] arr;
123.33 +
123.34 + Vector() {
123.35 + }
123.36 +
123.37 + Vector(int i) {
123.38 + }
123.39 +
123.40 + void add(Object objectType) {
123.41 + addElement(objectType);
123.42 + }
123.43 + @JavaScriptBody(args = { "obj" }, body =
123.44 + "this.push(obj);"
123.45 + )
123.46 + void addElement(Object obj) {
123.47 + final int s = size();
123.48 + setSize(s + 1);
123.49 + setElementAt(obj, s);
123.50 + }
123.51 +
123.52 + @JavaScriptBody(args = { }, body =
123.53 + "return this.length;"
123.54 + )
123.55 + int size() {
123.56 + return arr == null ? 0 : arr.length;
123.57 + }
123.58 +
123.59 + @JavaScriptBody(args = { "newArr" }, body =
123.60 + "for (var i = 0; i < this.length; i++) {\n"
123.61 + + " newArr[i] = this[i];\n"
123.62 + + "}\n")
123.63 + void copyInto(Object[] newArr) {
123.64 + if (arr == null) {
123.65 + return;
123.66 + }
123.67 + int min = Math.min(newArr.length, arr.length);
123.68 + for (int i = 0; i < min; i++) {
123.69 + newArr[i] = arr[i];
123.70 + }
123.71 + }
123.72 +
123.73 + @JavaScriptBody(args = { "index" }, body =
123.74 + "return this[index];"
123.75 + )
123.76 + Object elementAt(int index) {
123.77 + return arr[index];
123.78 + }
123.79 +
123.80 + private void setSize(int len) {
123.81 + Object[] newArr = new Object[len];
123.82 + copyInto(newArr);
123.83 + arr = newArr;
123.84 + }
123.85 +
123.86 + @JavaScriptBody(args = { "val", "index" }, body =
123.87 + "this[index] = val;"
123.88 + )
123.89 + void setElementAt(Object val, int index) {
123.90 + arr[index] = val;
123.91 + }
123.92 +}
124.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
124.2 +++ b/javaquery/api/pom.xml Wed Jan 23 20:16:48 2013 +0100
124.3 @@ -0,0 +1,74 @@
124.4 +<?xml version="1.0"?>
124.5 +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
124.6 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
124.7 + <modelVersion>4.0.0</modelVersion>
124.8 + <parent>
124.9 + <groupId>org.apidesign.bck2brwsr</groupId>
124.10 + <artifactId>javaquery</artifactId>
124.11 + <version>0.3-SNAPSHOT</version>
124.12 + </parent>
124.13 + <groupId>org.apidesign.bck2brwsr</groupId>
124.14 + <artifactId>javaquery.api</artifactId>
124.15 + <version>0.3-SNAPSHOT</version>
124.16 + <name>JavaQuery API</name>
124.17 + <url>http://maven.apache.org</url>
124.18 + <build>
124.19 + <plugins>
124.20 + <plugin>
124.21 + <groupId>org.apache.maven.plugins</groupId>
124.22 + <artifactId>maven-compiler-plugin</artifactId>
124.23 + <version>2.3.2</version>
124.24 + <configuration>
124.25 + <source>1.6</source>
124.26 + <target>1.6</target>
124.27 + </configuration>
124.28 + </plugin>
124.29 + </plugins>
124.30 + </build>
124.31 + <properties>
124.32 + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
124.33 + </properties>
124.34 + <dependencies>
124.35 + <dependency>
124.36 + <groupId>org.testng</groupId>
124.37 + <artifactId>testng</artifactId>
124.38 + <scope>test</scope>
124.39 + <exclusions>
124.40 + <exclusion>
124.41 + <artifactId>junit</artifactId>
124.42 + <groupId>junit</groupId>
124.43 + </exclusion>
124.44 + </exclusions>
124.45 + </dependency>
124.46 + <dependency>
124.47 + <groupId>org.netbeans.api</groupId>
124.48 + <artifactId>org-openide-util-lookup</artifactId>
124.49 + </dependency>
124.50 + <dependency>
124.51 + <groupId>org.apidesign.bck2brwsr</groupId>
124.52 + <artifactId>core</artifactId>
124.53 + <version>0.3-SNAPSHOT</version>
124.54 + <type>jar</type>
124.55 + </dependency>
124.56 + <dependency>
124.57 + <groupId>org.apidesign.bck2brwsr</groupId>
124.58 + <artifactId>emul</artifactId>
124.59 + <version>0.3-SNAPSHOT</version>
124.60 + <type>jar</type>
124.61 + <scope>runtime</scope>
124.62 + </dependency>
124.63 + <dependency>
124.64 + <groupId>org.apidesign.bck2brwsr</groupId>
124.65 + <artifactId>vm4brwsr</artifactId>
124.66 + <version>0.3-SNAPSHOT</version>
124.67 + <type>jar</type>
124.68 + <scope>test</scope>
124.69 + </dependency>
124.70 + <dependency>
124.71 + <groupId>${project.groupId}</groupId>
124.72 + <artifactId>vmtest</artifactId>
124.73 + <version>${project.version}</version>
124.74 + <scope>test</scope>
124.75 + </dependency>
124.76 + </dependencies>
124.77 +</project>
125.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
125.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/Knockout.java Wed Jan 23 20:16:48 2013 +0100
125.3 @@ -0,0 +1,93 @@
125.4 +/**
125.5 + * Back 2 Browser Bytecode Translator
125.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
125.7 + *
125.8 + * This program is free software: you can redistribute it and/or modify
125.9 + * it under the terms of the GNU General Public License as published by
125.10 + * the Free Software Foundation, version 2 of the License.
125.11 + *
125.12 + * This program is distributed in the hope that it will be useful,
125.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
125.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
125.15 + * GNU General Public License for more details.
125.16 + *
125.17 + * You should have received a copy of the GNU General Public License
125.18 + * along with this program. Look for COPYING file in the top folder.
125.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
125.20 + */
125.21 +package org.apidesign.bck2brwsr.htmlpage;
125.22 +
125.23 +import java.lang.reflect.Method;
125.24 +import org.apidesign.bck2brwsr.core.ExtraJavaScript;
125.25 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
125.26 +
125.27 +/** Provides binding between models and
125.28 + *
125.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
125.30 + */
125.31 +@ExtraJavaScript(resource = "/org/apidesign/bck2brwsr/htmlpage/knockout-2.2.1.js")
125.32 +public class Knockout {
125.33 + /** used by tests */
125.34 + static Knockout next;
125.35 +
125.36 + Knockout() {
125.37 + }
125.38 +
125.39 + public static <M> Knockout applyBindings(
125.40 + Class<M> modelClass, M model, String[] propsGettersAndSetters
125.41 + ) {
125.42 + Knockout bindings = next;
125.43 + next = null;
125.44 + if (bindings == null) {
125.45 + bindings = new Knockout();
125.46 + }
125.47 + for (int i = 0; i < propsGettersAndSetters.length; i += 4) {
125.48 + try {
125.49 + Method getter = modelClass.getMethod(propsGettersAndSetters[i + 3]);
125.50 + bind(bindings, model, propsGettersAndSetters[i],
125.51 + propsGettersAndSetters[i + 1],
125.52 + propsGettersAndSetters[i + 2],
125.53 + getter.getReturnType().isPrimitive()
125.54 + );
125.55 + } catch (NoSuchMethodException ex) {
125.56 + throw new IllegalStateException(ex.getMessage());
125.57 + }
125.58 + }
125.59 + applyBindings(bindings);
125.60 + return bindings;
125.61 + }
125.62 +
125.63 + @JavaScriptBody(args = { "prop" }, body =
125.64 + "this[prop].valueHasMutated();"
125.65 + )
125.66 + public void valueHasMutated(String prop) {
125.67 + }
125.68 +
125.69 +
125.70 + @JavaScriptBody(args = { "id", "ev" }, body = "ko.utils.triggerEvent(window.document.getElementById(id), ev.substring(2));")
125.71 + public static void triggerEvent(String id, String ev) {
125.72 + }
125.73 +
125.74 + @JavaScriptBody(args = { "bindings", "model", "prop", "getter", "setter", "primitive" }, body =
125.75 + "var bnd = {\n"
125.76 + + " read: function() {\n"
125.77 + + " var v = model[getter]();\n"
125.78 + + " return v;\n"
125.79 + + " },\n"
125.80 + + " owner: bindings\n"
125.81 + + "};\n"
125.82 + + "if (setter != null) {\n"
125.83 + + " bnd.write = function(val) {\n"
125.84 + + " model[setter](primitive ? new Number(val) : val);\n"
125.85 + + " };\n"
125.86 + + "}\n"
125.87 + + "bindings[prop] = ko.computed(bnd);"
125.88 + )
125.89 + private static void bind(
125.90 + Object bindings, Object model, String prop, String getter, String setter, boolean primitive
125.91 + ) {
125.92 + }
125.93 +
125.94 + @JavaScriptBody(args = { "bindings" }, body = "ko.applyBindings(bindings);")
125.95 + private static void applyBindings(Object bindings) {}
125.96 +}
126.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
126.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/PageProcessor.java Wed Jan 23 20:16:48 2013 +0100
126.3 @@ -0,0 +1,435 @@
126.4 +/**
126.5 + * Back 2 Browser Bytecode Translator
126.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
126.7 + *
126.8 + * This program is free software: you can redistribute it and/or modify
126.9 + * it under the terms of the GNU General Public License as published by
126.10 + * the Free Software Foundation, version 2 of the License.
126.11 + *
126.12 + * This program is distributed in the hope that it will be useful,
126.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
126.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
126.15 + * GNU General Public License for more details.
126.16 + *
126.17 + * You should have received a copy of the GNU General Public License
126.18 + * along with this program. Look for COPYING file in the top folder.
126.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
126.20 + */
126.21 +package org.apidesign.bck2brwsr.htmlpage;
126.22 +
126.23 +import java.io.IOException;
126.24 +import java.io.InputStream;
126.25 +import java.io.OutputStreamWriter;
126.26 +import java.io.Writer;
126.27 +import java.util.ArrayList;
126.28 +import java.util.Collection;
126.29 +import java.util.Collections;
126.30 +import java.util.HashMap;
126.31 +import java.util.LinkedHashSet;
126.32 +import java.util.List;
126.33 +import java.util.Locale;
126.34 +import java.util.Map;
126.35 +import java.util.Set;
126.36 +import javax.annotation.processing.AbstractProcessor;
126.37 +import javax.annotation.processing.Completion;
126.38 +import javax.annotation.processing.Completions;
126.39 +import javax.annotation.processing.Processor;
126.40 +import javax.annotation.processing.RoundEnvironment;
126.41 +import javax.annotation.processing.SupportedAnnotationTypes;
126.42 +import javax.lang.model.element.AnnotationMirror;
126.43 +import javax.lang.model.element.Element;
126.44 +import javax.lang.model.element.ElementKind;
126.45 +import javax.lang.model.element.ExecutableElement;
126.46 +import javax.lang.model.element.Modifier;
126.47 +import javax.lang.model.element.PackageElement;
126.48 +import javax.lang.model.element.TypeElement;
126.49 +import javax.lang.model.element.VariableElement;
126.50 +import javax.lang.model.type.MirroredTypeException;
126.51 +import javax.lang.model.type.TypeMirror;
126.52 +import javax.tools.Diagnostic;
126.53 +import javax.tools.FileObject;
126.54 +import javax.tools.StandardLocation;
126.55 +import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
126.56 +import org.apidesign.bck2brwsr.htmlpage.api.On;
126.57 +import org.apidesign.bck2brwsr.htmlpage.api.Page;
126.58 +import org.apidesign.bck2brwsr.htmlpage.api.Property;
126.59 +import org.openide.util.lookup.ServiceProvider;
126.60 +
126.61 +/** Annotation processor to process an XHTML page and generate appropriate
126.62 + * "id" file.
126.63 + *
126.64 + * @author Jaroslav Tulach <jtulach@netbeans.org>
126.65 + */
126.66 +@ServiceProvider(service=Processor.class)
126.67 +@SupportedAnnotationTypes({
126.68 + "org.apidesign.bck2brwsr.htmlpage.api.Page",
126.69 + "org.apidesign.bck2brwsr.htmlpage.api.On"
126.70 +})
126.71 +public final class PageProcessor extends AbstractProcessor {
126.72 + @Override
126.73 + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
126.74 + for (Element e : roundEnv.getElementsAnnotatedWith(Page.class)) {
126.75 + Page p = e.getAnnotation(Page.class);
126.76 + if (p == null) {
126.77 + continue;
126.78 + }
126.79 + PackageElement pe = (PackageElement)e.getEnclosingElement();
126.80 + String pkg = pe.getQualifiedName().toString();
126.81 +
126.82 + ProcessPage pp;
126.83 + try {
126.84 + InputStream is = openStream(pkg, p.xhtml());
126.85 + pp = ProcessPage.readPage(is);
126.86 + is.close();
126.87 + } catch (IOException iOException) {
126.88 + processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Can't read " + p.xhtml(), e);
126.89 + return false;
126.90 + }
126.91 + Writer w;
126.92 + String className = p.className();
126.93 + if (className.isEmpty()) {
126.94 + int indx = p.xhtml().indexOf('.');
126.95 + className = p.xhtml().substring(0, indx);
126.96 + }
126.97 + try {
126.98 + FileObject java = processingEnv.getFiler().createSourceFile(pkg + '.' + className, e);
126.99 + w = new OutputStreamWriter(java.openOutputStream());
126.100 + try {
126.101 + w.append("package " + pkg + ";\n");
126.102 + w.append("import org.apidesign.bck2brwsr.htmlpage.api.*;\n");
126.103 + w.append("final class ").append(className).append(" {\n");
126.104 + w.append(" private boolean locked;\n");
126.105 + if (!initializeOnClick(className, (TypeElement) e, w, pp)) {
126.106 + return false;
126.107 + }
126.108 + for (String id : pp.ids()) {
126.109 + String tag = pp.tagNameForId(id);
126.110 + String type = type(tag);
126.111 + w.append(" ").append("public final ").
126.112 + append(type).append(' ').append(cnstnt(id)).append(" = new ").
126.113 + append(type).append("(\"").append(id).append("\");\n");
126.114 + }
126.115 + List<String> propsGetSet = new ArrayList<String>();
126.116 + Map<String,Collection<String>> propsDeps = new HashMap<String, Collection<String>>();
126.117 + generateComputedProperties(w, e.getEnclosedElements(), propsGetSet, propsDeps);
126.118 + generateProperties(w, p.properties(), propsGetSet, propsDeps);
126.119 + w.append(" private org.apidesign.bck2brwsr.htmlpage.Knockout ko;\n");
126.120 + if (!propsGetSet.isEmpty()) {
126.121 + w.write("public " + className + " applyBindings() {\n");
126.122 + w.write(" ko = org.apidesign.bck2brwsr.htmlpage.Knockout.applyBindings(");
126.123 + w.write(className + ".class, this, ");
126.124 + w.write("new String[] {\n");
126.125 + String sep = "";
126.126 + for (String n : propsGetSet) {
126.127 + w.write(sep);
126.128 + if (n == null) {
126.129 + w.write(" null");
126.130 + } else {
126.131 + w.write(" \"" + n + "\"");
126.132 + }
126.133 + sep = ",\n";
126.134 + }
126.135 + w.write("\n });\n return this;\n}\n");
126.136 +
126.137 + w.write("public void triggerEvent(Element e, OnEvent ev) {\n");
126.138 + w.write(" org.apidesign.bck2brwsr.htmlpage.Knockout.triggerEvent(e.getId(), ev.getElementPropertyName());\n");
126.139 + w.write("}\n");
126.140 + }
126.141 + w.append("}\n");
126.142 + } finally {
126.143 + w.close();
126.144 + }
126.145 + } catch (IOException ex) {
126.146 + processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Can't create " + className + ".java", e);
126.147 + return false;
126.148 + }
126.149 + }
126.150 + return true;
126.151 + }
126.152 +
126.153 + private InputStream openStream(String pkg, String name) throws IOException {
126.154 + try {
126.155 + FileObject fo = processingEnv.getFiler().getResource(
126.156 + StandardLocation.SOURCE_PATH, pkg, name);
126.157 + return fo.openInputStream();
126.158 + } catch (IOException ex) {
126.159 + return processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, pkg, name).openInputStream();
126.160 + }
126.161 + }
126.162 +
126.163 + private static String type(String tag) {
126.164 + if (tag.equals("title")) {
126.165 + return "Title";
126.166 + }
126.167 + if (tag.equals("button")) {
126.168 + return "Button";
126.169 + }
126.170 + if (tag.equals("input")) {
126.171 + return "Input";
126.172 + }
126.173 + if (tag.equals("canvas")) {
126.174 + return "Canvas";
126.175 + }
126.176 + if (tag.equals("img")) {
126.177 + return "Image";
126.178 + }
126.179 + return "Element";
126.180 + }
126.181 +
126.182 + private static String cnstnt(String id) {
126.183 + return id.toUpperCase(Locale.ENGLISH).replace('.', '_').replace('-', '_');
126.184 + }
126.185 +
126.186 + private boolean initializeOnClick(
126.187 + String className, TypeElement type, Writer w, ProcessPage pp
126.188 + ) throws IOException {
126.189 + TypeMirror stringType = processingEnv.getElementUtils().getTypeElement("java.lang.String").asType();
126.190 + { //for (Element clazz : pe.getEnclosedElements()) {
126.191 + // if (clazz.getKind() != ElementKind.CLASS) {
126.192 + // continue;
126.193 + // }
126.194 + w.append(" public ").append(className).append("() {\n");
126.195 + StringBuilder dispatch = new StringBuilder();
126.196 + int dispatchCnt = 0;
126.197 + for (Element method : type.getEnclosedElements()) {
126.198 + On oc = method.getAnnotation(On.class);
126.199 + if (oc != null) {
126.200 + for (String id : oc.id()) {
126.201 + if (pp.tagNameForId(id) == null) {
126.202 + processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "id = " + id + " does not exist in the HTML page. Found only " + pp.ids(), method);
126.203 + return false;
126.204 + }
126.205 + ExecutableElement ee = (ExecutableElement)method;
126.206 + StringBuilder params = new StringBuilder();
126.207 + {
126.208 + boolean first = true;
126.209 + for (VariableElement ve : ee.getParameters()) {
126.210 + if (!first) {
126.211 + params.append(", ");
126.212 + }
126.213 + first = false;
126.214 + if (ve.asType() == stringType) {
126.215 + params.append('"').append(id).append('"');
126.216 + continue;
126.217 + }
126.218 + String rn = ve.asType().toString();
126.219 + int last = rn.lastIndexOf('.');
126.220 + if (last >= 0) {
126.221 + rn = rn.substring(last + 1);
126.222 + }
126.223 + if (rn.equals(className)) {
126.224 + params.append(className).append(".this");
126.225 + continue;
126.226 + }
126.227 + processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR,
126.228 + "@On method can only accept String or " + className + " arguments",
126.229 + ee
126.230 + );
126.231 + return false;
126.232 + }
126.233 + }
126.234 + if (!ee.getModifiers().contains(Modifier.STATIC)) {
126.235 + processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@On method has to be static", ee);
126.236 + return false;
126.237 + }
126.238 + if (ee.getModifiers().contains(Modifier.PRIVATE)) {
126.239 + processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@On method can't be private", ee);
126.240 + return false;
126.241 + }
126.242 + w.append(" OnEvent." + oc.event()).append(".of(").append(cnstnt(id)).
126.243 + append(").perform(new OnDispatch(" + dispatchCnt + "));\n");
126.244 +
126.245 + dispatch.
126.246 + append(" case ").append(dispatchCnt).append(": ").
126.247 + append(type.getSimpleName().toString()).
126.248 + append('.').append(ee.getSimpleName()).append("(").
126.249 + append(params).
126.250 + append("); break;\n");
126.251 +
126.252 + dispatchCnt++;
126.253 + }
126.254 + }
126.255 + }
126.256 + w.append(" }\n");
126.257 + if (dispatchCnt > 0) {
126.258 + w.append("class OnDispatch implements Runnable {\n");
126.259 + w.append(" private final int dispatch;\n");
126.260 + w.append(" OnDispatch(int d) { dispatch = d; }\n");
126.261 + w.append(" public void run() {\n");
126.262 + w.append(" switch (dispatch) {\n");
126.263 + w.append(dispatch);
126.264 + w.append(" }\n");
126.265 + w.append(" }\n");
126.266 + w.append("}\n");
126.267 + }
126.268 +
126.269 +
126.270 + }
126.271 + return true;
126.272 + }
126.273 +
126.274 + @Override
126.275 + public Iterable<? extends Completion> getCompletions(
126.276 + Element element, AnnotationMirror annotation,
126.277 + ExecutableElement member, String userText
126.278 + ) {
126.279 + if (!userText.startsWith("\"")) {
126.280 + return Collections.emptyList();
126.281 + }
126.282 +
126.283 + Element cls = findClass(element);
126.284 + Page p = cls.getAnnotation(Page.class);
126.285 + PackageElement pe = (PackageElement) cls.getEnclosingElement();
126.286 + String pkg = pe.getQualifiedName().toString();
126.287 + ProcessPage pp;
126.288 + try {
126.289 + InputStream is = openStream(pkg, p.xhtml());
126.290 + pp = ProcessPage.readPage(is);
126.291 + is.close();
126.292 + } catch (IOException iOException) {
126.293 + return Collections.emptyList();
126.294 + }
126.295 +
126.296 + List<Completion> cc = new ArrayList<Completion>();
126.297 + userText = userText.substring(1);
126.298 + for (String id : pp.ids()) {
126.299 + if (id.startsWith(userText)) {
126.300 + cc.add(Completions.of("\"" + id + "\"", id));
126.301 + }
126.302 + }
126.303 + return cc;
126.304 + }
126.305 +
126.306 + private static Element findClass(Element e) {
126.307 + if (e == null) {
126.308 + return null;
126.309 + }
126.310 + Page p = e.getAnnotation(Page.class);
126.311 + if (p != null) {
126.312 + return e;
126.313 + }
126.314 + return e.getEnclosingElement();
126.315 + }
126.316 +
126.317 + private static void generateProperties(
126.318 + Writer w, Property[] properties, Collection<String> props,
126.319 + Map<String,Collection<String>> deps
126.320 + ) throws IOException {
126.321 + for (Property p : properties) {
126.322 + final String tn = typeName(p);
126.323 + String[] gs = toGetSet(p.name(), tn);
126.324 +
126.325 + w.write("private " + tn + " prop_" + p.name() + ";\n");
126.326 + w.write("public " + tn + " " + gs[0] + "() {\n");
126.327 + w.write(" if (locked) throw new IllegalStateException();\n");
126.328 + w.write(" return prop_" + p.name() + ";\n");
126.329 + w.write("}\n");
126.330 + w.write("public void " + gs[1] + "(" + tn + " v) {\n");
126.331 + w.write(" if (locked) throw new IllegalStateException();\n");
126.332 + w.write(" prop_" + p.name() + " = v;\n");
126.333 + w.write(" if (ko != null) {\n");
126.334 + w.write(" ko.valueHasMutated(\"" + p.name() + "\");\n");
126.335 + final Collection<String> dependants = deps.get(p.name());
126.336 + if (dependants != null) {
126.337 + for (String depProp : dependants) {
126.338 + w.write(" ko.valueHasMutated(\"" + depProp + "\");\n");
126.339 + }
126.340 + }
126.341 + w.write(" }\n");
126.342 + w.write("}\n");
126.343 +
126.344 + props.add(p.name());
126.345 + props.add(gs[2]);
126.346 + props.add(gs[3]);
126.347 + props.add(gs[0]);
126.348 + }
126.349 + }
126.350 +
126.351 + private boolean generateComputedProperties(
126.352 + Writer w, Collection<? extends Element> arr, Collection<String> props,
126.353 + Map<String,Collection<String>> deps
126.354 + ) throws IOException {
126.355 + for (Element e : arr) {
126.356 + if (e.getKind() != ElementKind.METHOD) {
126.357 + continue;
126.358 + }
126.359 + if (e.getAnnotation(ComputedProperty.class) == null) {
126.360 + continue;
126.361 + }
126.362 + ExecutableElement ee = (ExecutableElement)e;
126.363 + final String tn = ee.getReturnType().toString();
126.364 + final String sn = ee.getSimpleName().toString();
126.365 + String[] gs = toGetSet(sn, tn);
126.366 +
126.367 + w.write("public " + tn + " " + gs[0] + "() {\n");
126.368 + w.write(" if (locked) throw new IllegalStateException();\n");
126.369 + int arg = 0;
126.370 + for (VariableElement pe : ee.getParameters()) {
126.371 + final String dn = pe.getSimpleName().toString();
126.372 + final String dt = pe.asType().toString();
126.373 + String[] call = toGetSet(dn, dt);
126.374 + w.write(" " + dt + " arg" + (++arg) + " = ");
126.375 + w.write(call[0] + "();\n");
126.376 +
126.377 + Collection<String> depends = deps.get(dn);
126.378 + if (depends == null) {
126.379 + depends = new LinkedHashSet<String>();
126.380 + deps.put(dn, depends);
126.381 + }
126.382 + depends.add(sn);
126.383 + }
126.384 + w.write(" try {\n");
126.385 + w.write(" locked = true;\n");
126.386 + w.write(" return " + e.getEnclosingElement().getSimpleName() + '.' + e.getSimpleName() + "(");
126.387 + String sep = "";
126.388 + for (int i = 1; i <= arg; i++) {
126.389 + w.write(sep);
126.390 + w.write("arg" + i);
126.391 + sep = ", ";
126.392 + }
126.393 + w.write(");\n");
126.394 + w.write(" } finally {\n");
126.395 + w.write(" locked = false;\n");
126.396 + w.write(" }\n");
126.397 + w.write("}\n");
126.398 +
126.399 + props.add(e.getSimpleName().toString());
126.400 + props.add(gs[2]);
126.401 + props.add(null);
126.402 + props.add(gs[0]);
126.403 + }
126.404 +
126.405 + return true;
126.406 + }
126.407 +
126.408 + private static String[] toGetSet(String name, String type) {
126.409 + String n = Character.toUpperCase(name.charAt(0)) + name.substring(1);
126.410 + String bck2brwsrType = "L" + type.replace('.', '_') + "_2";
126.411 + if ("int".equals(type)) {
126.412 + bck2brwsrType = "I";
126.413 + }
126.414 + if ("double".equals(type)) {
126.415 + bck2brwsrType = "D";
126.416 + }
126.417 + String pref = "get";
126.418 + if ("boolean".equals(type)) {
126.419 + pref = "is";
126.420 + bck2brwsrType = "Z";
126.421 + }
126.422 + final String nu = n.replace('.', '_');
126.423 + return new String[]{
126.424 + pref + n,
126.425 + "set" + n,
126.426 + pref + nu + "__" + bck2brwsrType,
126.427 + "set" + nu + "__V" + bck2brwsrType
126.428 + };
126.429 + }
126.430 +
126.431 + private static String typeName(Property p) {
126.432 + try {
126.433 + return p.type().getName();
126.434 + } catch (MirroredTypeException ex) {
126.435 + return ex.getTypeMirror().toString();
126.436 + }
126.437 + }
126.438 +}
127.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
127.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/ProcessPage.java Wed Jan 23 20:16:48 2013 +0100
127.3 @@ -0,0 +1,78 @@
127.4 +/**
127.5 + * Back 2 Browser Bytecode Translator
127.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
127.7 + *
127.8 + * This program is free software: you can redistribute it and/or modify
127.9 + * it under the terms of the GNU General Public License as published by
127.10 + * the Free Software Foundation, version 2 of the License.
127.11 + *
127.12 + * This program is distributed in the hope that it will be useful,
127.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
127.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
127.15 + * GNU General Public License for more details.
127.16 + *
127.17 + * You should have received a copy of the GNU General Public License
127.18 + * along with this program. Look for COPYING file in the top folder.
127.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
127.20 + */
127.21 +package org.apidesign.bck2brwsr.htmlpage;
127.22 +
127.23 +import java.io.IOException;
127.24 +import java.io.InputStream;
127.25 +import java.util.Collections;
127.26 +import java.util.Map;
127.27 +import java.util.Set;
127.28 +import java.util.TreeMap;
127.29 +import javax.xml.parsers.DocumentBuilder;
127.30 +import javax.xml.parsers.DocumentBuilderFactory;
127.31 +import org.w3c.dom.Document;
127.32 +import org.w3c.dom.Element;
127.33 +import org.w3c.dom.Node;
127.34 +import org.w3c.dom.NodeList;
127.35 +
127.36 +class ProcessPage {
127.37 + private final Map<String,String> ids2Elems = new TreeMap<String, String>();
127.38 +
127.39 + public Set<String> ids() {
127.40 + return Collections.unmodifiableSet(ids2Elems.keySet());
127.41 + }
127.42 +
127.43 + public String tagNameForId(String id) {
127.44 + return ids2Elems.get(id);
127.45 + }
127.46 +
127.47 + public static ProcessPage readPage(InputStream is) throws IOException {
127.48 + DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
127.49 + f.setValidating(false);
127.50 + f.setIgnoringComments(true);
127.51 +
127.52 + Document doc = null;
127.53 + try {
127.54 + DocumentBuilder b = f.newDocumentBuilder();
127.55 + doc = b.parse(is);
127.56 + } catch (IOException ex) {
127.57 + throw ex;
127.58 + } catch (Exception e) {
127.59 + throw new IOException(e);
127.60 + }
127.61 + Element root = doc.getDocumentElement();
127.62 +
127.63 + ProcessPage pp = new ProcessPage();
127.64 + pp.seekForIds(root);
127.65 + return pp;
127.66 + }
127.67 +
127.68 + private void seekForIds(Element e) {
127.69 + String val = e.getAttribute("id");
127.70 + if (val != null && !val.isEmpty()) {
127.71 + String prev = ids2Elems.put(val, e.getTagName());
127.72 + }
127.73 + NodeList arr = e.getChildNodes();
127.74 + for (int i = 0; i < arr.getLength(); i++) {
127.75 + final Node n = arr.item(i);
127.76 + if (n instanceof Element) {
127.77 + seekForIds((Element)n);
127.78 + }
127.79 + }
127.80 + }
127.81 +}
128.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
128.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Button.java Wed Jan 23 20:16:48 2013 +0100
128.3 @@ -0,0 +1,36 @@
128.4 +/**
128.5 + * Back 2 Browser Bytecode Translator
128.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
128.7 + *
128.8 + * This program is free software: you can redistribute it and/or modify
128.9 + * it under the terms of the GNU General Public License as published by
128.10 + * the Free Software Foundation, version 2 of the License.
128.11 + *
128.12 + * This program is distributed in the hope that it will be useful,
128.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
128.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
128.15 + * GNU General Public License for more details.
128.16 + *
128.17 + * You should have received a copy of the GNU General Public License
128.18 + * along with this program. Look for COPYING file in the top folder.
128.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
128.20 + */
128.21 +package org.apidesign.bck2brwsr.htmlpage.api;
128.22 +
128.23 +/**
128.24 + *
128.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
128.26 + */
128.27 +public final class Button extends Element {
128.28 + public Button(String id) {
128.29 + super(id);
128.30 + }
128.31 +
128.32 + @Override
128.33 + void dontSubclass() {
128.34 + }
128.35 +
128.36 + public void setDisabled(boolean state) {
128.37 + setAttribute(this, "disabled", state);
128.38 + }
128.39 +}
129.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
129.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Canvas.java Wed Jan 23 20:16:48 2013 +0100
129.3 @@ -0,0 +1,61 @@
129.4 +/**
129.5 + * Back 2 Browser Bytecode Translator
129.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
129.7 + *
129.8 + * This program is free software: you can redistribute it and/or modify
129.9 + * it under the terms of the GNU General Public License as published by
129.10 + * the Free Software Foundation, version 2 of the License.
129.11 + *
129.12 + * This program is distributed in the hope that it will be useful,
129.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
129.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
129.15 + * GNU General Public License for more details.
129.16 + *
129.17 + * You should have received a copy of the GNU General Public License
129.18 + * along with this program. Look for COPYING file in the top folder.
129.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
129.20 + */
129.21 +package org.apidesign.bck2brwsr.htmlpage.api;
129.22 +
129.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
129.24 +
129.25 +/**
129.26 + *
129.27 + * @author Anton Epple <toni.epple@eppleton.de>
129.28 + */
129.29 +public class Canvas extends Element {
129.30 +
129.31 + public Canvas(String id) {
129.32 + super(id);
129.33 + }
129.34 +
129.35 + public void setHeight(int height) {
129.36 + setAttribute(this, "height", height);
129.37 + }
129.38 +
129.39 + public int getHeight() {
129.40 + return (Integer) getAttribute(this, "height");
129.41 + }
129.42 +
129.43 + public void setWidth(int width) {
129.44 + setAttribute(this, "width", width);
129.45 + }
129.46 +
129.47 + public int getWidth() {
129.48 + return (Integer) getAttribute(this, "width");
129.49 + }
129.50 +
129.51 + @JavaScriptBody(
129.52 + args = {"el"},
129.53 + body = "var e = window.document.getElementById(el.fld_id);\n"
129.54 + + "return e.getContext('2d');\n")
129.55 + private native static Object getContextImpl(Canvas el);
129.56 +
129.57 + public GraphicsContext getContext() {
129.58 + return new GraphicsContext(getContextImpl(this));
129.59 + }
129.60 +
129.61 + @Override
129.62 + void dontSubclass() {
129.63 + }
129.64 +}
130.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
130.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/ComputedProperty.java Wed Jan 23 20:16:48 2013 +0100
130.3 @@ -0,0 +1,38 @@
130.4 +/**
130.5 + * Back 2 Browser Bytecode Translator
130.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
130.7 + *
130.8 + * This program is free software: you can redistribute it and/or modify
130.9 + * it under the terms of the GNU General Public License as published by
130.10 + * the Free Software Foundation, version 2 of the License.
130.11 + *
130.12 + * This program is distributed in the hope that it will be useful,
130.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
130.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
130.15 + * GNU General Public License for more details.
130.16 + *
130.17 + * You should have received a copy of the GNU General Public License
130.18 + * along with this program. Look for COPYING file in the top folder.
130.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
130.20 + */
130.21 +package org.apidesign.bck2brwsr.htmlpage.api;
130.22 +
130.23 +import java.lang.annotation.ElementType;
130.24 +import java.lang.annotation.Retention;
130.25 +import java.lang.annotation.RetentionPolicy;
130.26 +import java.lang.annotation.Target;
130.27 +
130.28 +/** Can be used in classes annotated with {@link Page} annotation to
130.29 + * define a derived property. Value of derived property is based on values
130.30 + * of {@link Property} as enumerated by {@link Page#properties()}.
130.31 + * <p>
130.32 + * The name of the derived property is the name of the method. The arguments
130.33 + * of the method define the property names (from {@link Page#properties()} list)
130.34 + * the value of property depends on.
130.35 + *
130.36 + * @author Jaroslav Tulach <jtulach@netbeans.org>
130.37 + */
130.38 +@Retention(RetentionPolicy.SOURCE)
130.39 +@Target(ElementType.METHOD)
130.40 +public @interface ComputedProperty {
130.41 +}
131.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
131.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java Wed Jan 23 20:16:48 2013 +0100
131.3 @@ -0,0 +1,95 @@
131.4 +/**
131.5 + * Back 2 Browser Bytecode Translator
131.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
131.7 + *
131.8 + * This program is free software: you can redistribute it and/or modify
131.9 + * it under the terms of the GNU General Public License as published by
131.10 + * the Free Software Foundation, version 2 of the License.
131.11 + *
131.12 + * This program is distributed in the hope that it will be useful,
131.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
131.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
131.15 + * GNU General Public License for more details.
131.16 + *
131.17 + * You should have received a copy of the GNU General Public License
131.18 + * along with this program. Look for COPYING file in the top folder.
131.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
131.20 + */
131.21 +package org.apidesign.bck2brwsr.htmlpage.api;
131.22 +
131.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
131.24 +
131.25 +/** Represents a generic HTML element.
131.26 + *
131.27 + * @author Jaroslav Tulach <jtulach@netbeans.org>
131.28 + */
131.29 +public abstract class Element {
131.30 + private final String id;
131.31 +
131.32 + public Element(String id) {
131.33 + this.id = id;
131.34 + }
131.35 +
131.36 + /** Id of the element in the document.
131.37 + * @return the id for this element
131.38 + */
131.39 + public String getId() {
131.40 + return id;
131.41 + }
131.42 +
131.43 + abstract void dontSubclass();
131.44 +
131.45 + @JavaScriptBody(
131.46 + args={"el", "property", "value"},
131.47 + body="var e = window.document.getElementById(el.fld_id);\n"
131.48 + + "e[property] = value;\n"
131.49 + )
131.50 + static native void setAttribute(Element el, String property, Object value);
131.51 +
131.52 + @JavaScriptBody(
131.53 + args={"el", "property"},
131.54 + body="var e = window.document.getElementById(el.fld_id);\n"
131.55 + + "return e[property];\n"
131.56 + )
131.57 + static native Object getAttribute(Element el, String property);
131.58 +
131.59 + @JavaScriptBody(
131.60 + args={"el"},
131.61 + body="return window.document.getElementById(el.fld_id);"
131.62 + )
131.63 + static native Object getElementById(Element el);
131.64 +
131.65 + /** Executes given runnable when user performs a "click" on the given
131.66 + * element.
131.67 + * @param r the runnable to execute, never null
131.68 + */
131.69 + @JavaScriptBody(
131.70 + args={ "ev", "r" },
131.71 + body="var e = window.document.getElementById(this.fld_id);\n"
131.72 + + "e[ev.fld_id] = function() { r.run__V(); };\n"
131.73 + )
131.74 + final void on(OnEvent ev, Runnable r) {
131.75 + }
131.76 +
131.77 + /** Shows alert message dialog in a browser.
131.78 + * @param msg the message to show
131.79 + */
131.80 + @JavaScriptBody(args = "msg", body = "alert(msg);")
131.81 + public static native void alert(String msg);
131.82 +
131.83 + /** Generic way to query any attribute of this element.
131.84 + * @param property name of the attribute
131.85 + */
131.86 + public final Object getAttribute(String property) {
131.87 + return getAttribute(this, property);
131.88 + }
131.89 +
131.90 + /** Generic way to change an attribute of this element.
131.91 + *
131.92 + * @param property name of the attribute
131.93 + * @param value value to associate with the attribute
131.94 + */
131.95 + public final void setAttribute(String property, Object value) {
131.96 + setAttribute(this, property, value);
131.97 + }
131.98 +}
132.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
132.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/GraphicsContext.java Wed Jan 23 20:16:48 2013 +0100
132.3 @@ -0,0 +1,335 @@
132.4 +/**
132.5 + * Back 2 Browser Bytecode Translator
132.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
132.7 + *
132.8 + * This program is free software: you can redistribute it and/or modify
132.9 + * it under the terms of the GNU General Public License as published by
132.10 + * the Free Software Foundation, version 2 of the License.
132.11 + *
132.12 + * This program is distributed in the hope that it will be useful,
132.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
132.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
132.15 + * GNU General Public License for more details.
132.16 + *
132.17 + * You should have received a copy of the GNU General Public License
132.18 + * along with this program. Look for COPYING file in the top folder.
132.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
132.20 + */
132.21 +package org.apidesign.bck2brwsr.htmlpage.api;
132.22 +
132.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
132.24 +
132.25 +/**
132.26 + *
132.27 + * @author Anton Epple <toni.epple@eppleton.de>
132.28 + */
132.29 +public class GraphicsContext {
132.30 +
132.31 + Object context;
132.32 +
132.33 + GraphicsContext(Object contextImpl) {
132.34 + this.context = contextImpl;
132.35 + }
132.36 +
132.37 + @JavaScriptBody(args = {"centerx", "centery", "radius", "startangle", "endangle", "ccw"},
132.38 + body = "this.fld_context.arc(centerx,centery, radius, startangle, endangle,ccw);")
132.39 + public native void arc(double centerX,
132.40 + double centerY,
132.41 + double startAngle,
132.42 + double radius,
132.43 + double endAngle,
132.44 + boolean ccw);
132.45 +
132.46 + @JavaScriptBody(args = {"x1", "y1", "x2", "y2", "r"},
132.47 + body = "this.fld_context.arcTo(x1,y1,x2,y2,r);")
132.48 + public native void arcTo(double x1,
132.49 + double y1,
132.50 + double x2,
132.51 + double y2,
132.52 + double r);
132.53 +
132.54 + @JavaScriptBody(args = {"x", "y"},
132.55 + body = "return this.fld_context.isPointInPath(x,y);")
132.56 + public native boolean isPointInPath(double x, double y);
132.57 +
132.58 + @JavaScriptBody(args = {}, body = "this.fld_context.fill();")
132.59 + public native void fill();
132.60 +
132.61 + @JavaScriptBody(args = {}, body = "this.fld_context.stroke();")
132.62 + public native void stroke();
132.63 +
132.64 + @JavaScriptBody(args = {}, body = "this.fld_context.beginPath();")
132.65 + public native void beginPath();
132.66 +
132.67 + @JavaScriptBody(args = {}, body = "this.fld_context.closePath();")
132.68 + public native void closePath();
132.69 +
132.70 + @JavaScriptBody(args = {}, body = "this.fld_context.clip();")
132.71 + public native void clip();
132.72 +
132.73 + @JavaScriptBody(args = {"x", "y"}, body = "this.fld_context.moveTo(x,y);")
132.74 + public native void moveTo(double x, double y);
132.75 +
132.76 + @JavaScriptBody(args = {"x", "y"}, body = "this.fld_context.lineTo(x,y);")
132.77 + public native void lineTo(double x, double y);
132.78 +
132.79 + @JavaScriptBody(args = {"cpx", "cpy", "x", "y"}, body = "this.fld_context.quadraticCurveTo(cpx,cpy,x,y);")
132.80 + public native void quadraticCurveTo(double cpx, double cpy, double x, double y);
132.81 +
132.82 + @JavaScriptBody(args = {"cp1x", "cp1y", "cp2x", "cp2y", "x", "y"},
132.83 + body = "this.fld_context.bezierCurveTo(cp1x,cp1y,cp2x,cp2y,x,y);")
132.84 + public native void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y);
132.85 +
132.86 + @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this.fld_context.fillRect(x,y,width,height);")
132.87 + public native void fillRect(double x, double y, double width, double height);
132.88 +
132.89 + @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this.fld_context.strokeRect(x,y,width,height);")
132.90 + public native void strokeRect(double x, double y, double width, double height);
132.91 +
132.92 + @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this.fld_context.clearRect(x,y,width,height);")
132.93 + public native void clearRect(double x, double y, double width, double height);
132.94 +
132.95 + @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this.fld_context.rectect(x,y,width,height);")
132.96 + public native void rect(double x, double y, double width, double height);
132.97 +
132.98 + @JavaScriptBody(args = {}, body = "this.fld_context.save();")
132.99 + public native void save();
132.100 +
132.101 + @JavaScriptBody(args = {}, body = "this.fld_context.restore();")
132.102 + public native void restore();
132.103 +
132.104 + @JavaScriptBody(args = {"angle"}, body = "this.fld_context.rotate(angle);")
132.105 + public native void rotate(double angle);
132.106 +
132.107 + @JavaScriptBody(args = {"a", "b", "c", "d", "e", "f"}, body = "this.fld_context.transform(a,b,c,d,e,f);")
132.108 + public native void transform(double a, double b, double c, double d, double e, double f);
132.109 +
132.110 + @JavaScriptBody(args = {"a", "b", "c", "d", "e", "f"}, body = "this.fld_context.setTransform(a,b,c,d,e,f);")
132.111 + public native void setTransform(double a, double b, double c, double d, double e, double f);
132.112 +
132.113 + @JavaScriptBody(args = {"x", "y"}, body = "this.fld_context.translate(x,y);")
132.114 + public native void translate(double x, double y);
132.115 +
132.116 + @JavaScriptBody(args = {"x", "y"}, body = "this.fld_context.scale(x,y);")
132.117 + public native void scale(double x, double y);
132.118 +
132.119 + public void drawImage(Image image, double x, double y) {
132.120 + drawImageImpl(context, Element.getElementById(image), x, y);
132.121 + }
132.122 +
132.123 + public void drawImage(Image image, double x, double y, double width, double height) {
132.124 + drawImageImpl(context, Element.getElementById(image), x, y, width, height);
132.125 + }
132.126 +
132.127 + public void drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height) {
132.128 + drawImageImpl(context, Element.getElementById(image), sx, sy, sWidth, sHeight, x, y, width, height);
132.129 + }
132.130 +
132.131 + @JavaScriptBody(args = {"ctx", "img", "x", "y", "width", "height"}, body = "ctx.drawImage(img,x,y,width,height);")
132.132 + private native static void drawImageImpl(Object ctx, Object img, double x, double y, double width, double height);
132.133 +
132.134 + @JavaScriptBody(args = {"ctx", "img", "sx", "sy", "swidth", "sheight", "x", "y", "width", "height"}, body = "ctx.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);")
132.135 + private native static void drawImageImpl(Object ctx, Object img, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height);
132.136 +
132.137 + @JavaScriptBody(args = {"ctx", "img", "x", "y"}, body = "ctx.drawImage(img,x,y);")
132.138 + private native static void drawImageImpl(Object ctx, Object img, double x, double y);
132.139 +
132.140 + @JavaScriptBody(args = {"style"}, body = "this.fld_context.fillStyle=style;")
132.141 + public native void setFillStyle(String style);
132.142 +
132.143 + @JavaScriptBody(args = {}, body = "return this.fld_context.fillStyle;")
132.144 + public native String getFillStyle();
132.145 +
132.146 + public void setFillStyle(LinearGradient style) {
132.147 + setFillStyleImpl(context, style.object());
132.148 + }
132.149 +
132.150 + public void setFillStyle(RadialGradient style) {
132.151 + setFillStyleImpl(context, style.object());
132.152 + }
132.153 +
132.154 + public void setFillStyle(Pattern style) {
132.155 + setFillStyleImpl(context, style.object());
132.156 + }
132.157 +
132.158 + @JavaScriptBody(args = {"context","obj"}, body = "context.fillStyle=obj;")
132.159 + private native void setFillStyleImpl(Object context, Object obj);
132.160 +
132.161 + @JavaScriptBody(args = {"style"}, body = "this.fld_context.strokeStyle=style;")
132.162 + public native void setStrokeStyle(String style);
132.163 +
132.164 + public void setStrokeStyle(LinearGradient style) {
132.165 + setStrokeStyleImpl(context, style.object());
132.166 + }
132.167 +
132.168 + public void setStrokeStyle(RadialGradient style) {
132.169 + setStrokeStyleImpl(context, style.object());
132.170 + }
132.171 +
132.172 + @JavaScriptBody(args = {"style"}, body = "this.fld_context.fillStyle=style;")
132.173 + public void setStrokeStyle(Pattern style) {
132.174 + setStrokeStyleImpl(context, style.object());
132.175 + }
132.176 +
132.177 + @JavaScriptBody(args = {"context","obj"}, body = "context.strokeStyle=obj;")
132.178 + private native void setStrokeStyleImpl(Object context, Object obj);
132.179 +
132.180 + @JavaScriptBody(args = {"color"}, body = "this.fld_context.shadowColor=color;")
132.181 + public native void setShadowColor(String color);
132.182 +
132.183 + @JavaScriptBody(args = {"blur"}, body = "this.fld_context.shadowBlur=blur;")
132.184 + public native void setShadowBlur(double blur);
132.185 +
132.186 + @JavaScriptBody(args = {"x"}, body = "this.fld_context.shadowOffsetX=x;")
132.187 + public native void setShadowOffsetX(double x);
132.188 +
132.189 + @JavaScriptBody(args = {"y"}, body = "this.fld_context.shadowOffsetY=y;")
132.190 + public native void setShadowOffsetY(double y);
132.191 +
132.192 + @JavaScriptBody(args = {}, body = "return this.fld_context.strokeStyle;")
132.193 + public native String getStrokeStyle();
132.194 +
132.195 + @JavaScriptBody(args = {}, body = "return this.fld_context.shadowColor;")
132.196 + public native String getShadowColor();
132.197 +
132.198 + @JavaScriptBody(args = {}, body = "return this.fld_context.shadowBlur;")
132.199 + public native double getShadowBlur();
132.200 +
132.201 + @JavaScriptBody(args = {}, body = "return this.fld_context.shadowOffsetX;")
132.202 + public native double getShadowOffsetX();
132.203 +
132.204 + @JavaScriptBody(args = {}, body = "return this.fld_context.shadowOffsetY;")
132.205 + public native double getShadowOffsetY();
132.206 +
132.207 + @JavaScriptBody(args = {}, body = "return this.fld_context.lineCap;")
132.208 + public native String getLineCap();
132.209 +
132.210 + @JavaScriptBody(args = {"style"}, body = "this.fld_context.lineCap=style;")
132.211 + public native void setLineCap(String style);
132.212 +
132.213 + @JavaScriptBody(args = {}, body = "return this.fld_context.lineJoin;")
132.214 + public native String getLineJoin();
132.215 +
132.216 + @JavaScriptBody(args = {"style"}, body = "this.fld_context.lineJoin=style;")
132.217 + public native void setLineJoin(String style) ;
132.218 +
132.219 + @JavaScriptBody(args = {}, body = "return this.fld_context.lineWidth;")
132.220 + public native double getLineWidth();
132.221 +
132.222 + @JavaScriptBody(args = {"width"}, body = "this.fld_context.lineJoin=width;")
132.223 + public native void setLineWidth(double width);
132.224 +
132.225 + @JavaScriptBody(args = {}, body = "return this.fld_context.miterLimit;")
132.226 + public native double getMiterLimit();
132.227 +
132.228 + @JavaScriptBody(args = {"limit"}, body = "this.fld_context.miterLimit=limit;")
132.229 + public native void setMiterLimit(double limit);
132.230 +
132.231 + @JavaScriptBody(args = {}, body = "return this.fld_context.font;")
132.232 + public native String getFont();
132.233 +
132.234 + @JavaScriptBody(args = {"font"}, body = "this.fld_context.font=font;")
132.235 + public native void setFont(String font);
132.236 +
132.237 + @JavaScriptBody(args = {}, body = "return this.fld_context.textAlign;")
132.238 + public native String getTextAlign();
132.239 +
132.240 + @JavaScriptBody(args = {"textalign"}, body = "this.fld_context.textAlign=textalign;")
132.241 + public native void setTextAlign(String textAlign);
132.242 +
132.243 + @JavaScriptBody(args = {}, body = "return this.fld_context.textBaseline;")
132.244 + public native String getTextBaseline();
132.245 +
132.246 + @JavaScriptBody(args = {"textbaseline"}, body = "this.fld_context.textBaseline=textbaseline;")
132.247 + public native void setTextBaseline(String textbaseline);
132.248 +
132.249 + @JavaScriptBody(args = {"text", "x", "y"}, body = "this.fld_context.fillText(text,x,y);")
132.250 + public native void fillText(String text, double x, double y);
132.251 +
132.252 + @JavaScriptBody(args = {"text", "x", "y", "maxwidth"}, body = "this.fld_context.fillText(text,x,y,maxwidth);")
132.253 + public void fillText(String text, double x, double y, double maxWidth) {
132.254 + }
132.255 +
132.256 + public TextMetrics measureText(String text) {
132.257 + return new TextMetrics(measureTextImpl(text));
132.258 + }
132.259 +
132.260 + @JavaScriptBody(args = {"text"},
132.261 + body = "return this.fld_context.measureText(text);")
132.262 + private native Object measureTextImpl(String text);
132.263 +
132.264 + @JavaScriptBody(args = {"text", "x", "y"}, body = "this.fld_context.strokeText(text,x,y);")
132.265 + public native void strokeText(String text, double x, double y);
132.266 +
132.267 + @JavaScriptBody(args = {"text", "x", "y", "maxWidth"}, body = "this.fld_context.strokeText(text,x,y,maxWidth);")
132.268 + public native void strokeText(String text, double x, double y, double maxWidth) ;
132.269 +
132.270 + public ImageData createImageData(double x, double y) {
132.271 + return new ImageData(createImageDataImpl(x, y));
132.272 + }
132.273 +
132.274 + @JavaScriptBody(args = {"x", "y"},
132.275 + body = "return this.fld_context.createImageData(x,y);")
132.276 + private native Object createImageDataImpl(double x, double y);
132.277 +
132.278 + public ImageData createImageData(ImageData imageData) {
132.279 + return new ImageData(createImageDataImpl(imageData.getWidth(), imageData.getHeight()));
132.280 + }
132.281 +
132.282 + public ImageData getImageData(double x, double y, double width, double height) {
132.283 + return new ImageData(getImageDataImpl(x, y, width, height));
132.284 + }
132.285 +
132.286 + @JavaScriptBody(args = {"x", "y", "width", "height"},
132.287 + body = "return this.fld_context.getImageData(x,y,width,height);")
132.288 + private native Object getImageDataImpl(double x, double y, double width, double height);
132.289 +
132.290 + public void putImageData(ImageData imageData, double x, double y) {
132.291 + putImageDataImpl(imageData.object(), x, y);
132.292 + }
132.293 +
132.294 + @JavaScriptBody(args = {"imageData", "x", "y"},
132.295 + body = "this.fld_context.putImageData(imageData,x,y);")
132.296 + private native void putImageDataImpl(Object imageData, double x, double y);
132.297 +
132.298 + public void putImageData(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight) {
132.299 + putImageDataImpl(imageData.object(), x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
132.300 + }
132.301 +
132.302 + @JavaScriptBody(args = {"imageData", "x", "y", "dirtyx", "dirtyy", "dirtywidth", "dirtyheight"},
132.303 + body = "this.fld_context.putImageData(imageData,x,y, dirtyx, dirtyy, dirtywidth,dirtyheight);")
132.304 + private native void putImageDataImpl(Object imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight);
132.305 +
132.306 + @JavaScriptBody(args = {"alpha"}, body = "this.fld_context.globalAlpha=alpha;")
132.307 + public native void setGlobalAlpha(double alpha) ;
132.308 +
132.309 + @JavaScriptBody(args = {}, body = "return this.fld_context.globalAlpha;")
132.310 + public native double getGlobalAlpha();
132.311 +
132.312 + @JavaScriptBody(args = {"operation"}, body = "this.fld_context.globalCompositeOperation=operation;")
132.313 + public native void setGlobalCompositeOperation(double alpha);
132.314 +
132.315 + @JavaScriptBody(args = {}, body = "return this.fld_context.globalCompositeOperation;")
132.316 + public native double getGlobalCompositeOperation();
132.317 +
132.318 + public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) {
132.319 + return new LinearGradient(createLinearGradientImpl(context, x0, y0, x1, y1));
132.320 + }
132.321 +
132.322 + @JavaScriptBody(args = {"context", "x0", "y0", "x1", "y1"}, body = "return context.createLinearGradient(x0,y0,x1,y1);")
132.323 + private native Object createLinearGradientImpl(Object context, double x0, double y0, double x1, double y1);
132.324 +
132.325 + public Pattern createPattern(Image image, String repeat) {
132.326 + return new Pattern(createPatternImpl(context, image, repeat));
132.327 + }
132.328 +
132.329 + @JavaScriptBody(args = {"context", "image", "repeat"}, body = "return context.createPattern(image, repeat);")
132.330 + private static native Object createPatternImpl(Object context, Image image, String repeat);
132.331 +
132.332 + public RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
132.333 + return new RadialGradient(createRadialGradientImpl(context, x0, y0, r0, x1, y1, r1));
132.334 + }
132.335 +
132.336 + @JavaScriptBody(args = {"context", "x0", "y0", "r0", "x1", "y1", "r1"}, body = "return context.createRadialGradient(x0,y0,r0,x1,y1,r1);")
132.337 + private static native Object createRadialGradientImpl(Object context, double x0, double y0, double r0, double x1, double y1, double r1);
132.338 +}
133.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
133.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Image.java Wed Jan 23 20:16:48 2013 +0100
133.3 @@ -0,0 +1,36 @@
133.4 +/**
133.5 + * Back 2 Browser Bytecode Translator
133.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
133.7 + *
133.8 + * This program is free software: you can redistribute it and/or modify
133.9 + * it under the terms of the GNU General Public License as published by
133.10 + * the Free Software Foundation, version 2 of the License.
133.11 + *
133.12 + * This program is distributed in the hope that it will be useful,
133.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
133.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
133.15 + * GNU General Public License for more details.
133.16 + *
133.17 + * You should have received a copy of the GNU General Public License
133.18 + * along with this program. Look for COPYING file in the top folder.
133.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
133.20 + */
133.21 +package org.apidesign.bck2brwsr.htmlpage.api;
133.22 +
133.23 +/**
133.24 + *
133.25 + * @author Anton Epple <toni.epple@eppleton.de>
133.26 + */
133.27 +public class Image extends Element{
133.28 +
133.29 + public Image(String id) {
133.30 + super(id);
133.31 + }
133.32 +
133.33 +
133.34 +
133.35 + @Override
133.36 + void dontSubclass() {
133.37 + }
133.38 +
133.39 +}
134.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
134.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/ImageData.java Wed Jan 23 20:16:48 2013 +0100
134.3 @@ -0,0 +1,89 @@
134.4 +/**
134.5 + * Back 2 Browser Bytecode Translator
134.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
134.7 + *
134.8 + * This program is free software: you can redistribute it and/or modify
134.9 + * it under the terms of the GNU General Public License as published by
134.10 + * the Free Software Foundation, version 2 of the License.
134.11 + *
134.12 + * This program is distributed in the hope that it will be useful,
134.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
134.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
134.15 + * GNU General Public License for more details.
134.16 + *
134.17 + * You should have received a copy of the GNU General Public License
134.18 + * along with this program. Look for COPYING file in the top folder.
134.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
134.20 + */
134.21 +/*
134.22 + * To change this template, choose Tools | Templates
134.23 + * and open the template in the editor.
134.24 + */
134.25 +package org.apidesign.bck2brwsr.htmlpage.api;
134.26 +
134.27 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
134.28 +
134.29 +/**
134.30 + *
134.31 + * @author Anton Epple <toni.epple@eppleton.de>
134.32 + */
134.33 +public class ImageData {
134.34 +
134.35 + private Object imageData;
134.36 + private Data data;
134.37 +
134.38 + public ImageData(Object imageData) {
134.39 + this.imageData = imageData;
134.40 + }
134.41 +
134.42 + public Data getData(){
134.43 + if (data == null){
134.44 + data = new Data(getDataImpl(imageData));
134.45 + }
134.46 + return data;
134.47 + }
134.48 +
134.49 + @JavaScriptBody(args = {"imageData"}, body = "return imageData.data")
134.50 + public native Object getDataImpl(Object imageData);
134.51 +
134.52 + public double getWidth() {
134.53 + return getWidthImpl(imageData);
134.54 + }
134.55 +
134.56 + @JavaScriptBody(args = {"imageData"}, body = "return imagedata.width;")
134.57 + private static native double getWidthImpl(Object imageData);
134.58 +
134.59 + public double getHeight() {
134.60 + return getHeightImpl(imageData);
134.61 + }
134.62 +
134.63 + @JavaScriptBody(args = {"imageData"}, body = "return imagedata.height;")
134.64 + private static native double getHeightImpl(Object imageData);
134.65 +
134.66 + Object object() {
134.67 + return imageData;
134.68 + }
134.69 +
134.70 + public static class Data {
134.71 +
134.72 + Object data;
134.73 +
134.74 + public Data(Object data) {
134.75 + this.data = data;
134.76 + }
134.77 +
134.78 + public int get(int index) {
134.79 + return getImpl(data, index);
134.80 + }
134.81 +
134.82 + public void set(int index, int value) {
134.83 + setImpl(data, index, value);
134.84 + }
134.85 +
134.86 + @JavaScriptBody(args = {"data", "index", "value"}, body = "data[index]=value;")
134.87 + private static native void setImpl(Object data, int index, int value);
134.88 +
134.89 + @JavaScriptBody(args = {"imagedata", "index"}, body = "return data[index];")
134.90 + private static native int getImpl(Object data, int index);
134.91 + }
134.92 +}
135.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
135.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Input.java Wed Jan 23 20:16:48 2013 +0100
135.3 @@ -0,0 +1,44 @@
135.4 +/**
135.5 + * Back 2 Browser Bytecode Translator
135.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
135.7 + *
135.8 + * This program is free software: you can redistribute it and/or modify
135.9 + * it under the terms of the GNU General Public License as published by
135.10 + * the Free Software Foundation, version 2 of the License.
135.11 + *
135.12 + * This program is distributed in the hope that it will be useful,
135.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
135.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
135.15 + * GNU General Public License for more details.
135.16 + *
135.17 + * You should have received a copy of the GNU General Public License
135.18 + * along with this program. Look for COPYING file in the top folder.
135.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
135.20 + */
135.21 +package org.apidesign.bck2brwsr.htmlpage.api;
135.22 +
135.23 +/**
135.24 + *
135.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
135.26 + */
135.27 +public final class Input extends Element {
135.28 + public Input(String id) {
135.29 + super(id);
135.30 + }
135.31 +
135.32 + @Override
135.33 + void dontSubclass() {
135.34 + }
135.35 +
135.36 + public void setAutocomplete(boolean state) {
135.37 + setAttribute(this, "autocomplete", state);
135.38 + }
135.39 +
135.40 + public final String getValue() {
135.41 + return (String)getAttribute(this, "value");
135.42 + }
135.43 +
135.44 + public final void setValue(String txt) {
135.45 + setAttribute(this, "value", txt);
135.46 + }
135.47 +}
136.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
136.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/LinearGradient.java Wed Jan 23 20:16:48 2013 +0100
136.3 @@ -0,0 +1,45 @@
136.4 +/**
136.5 + * Back 2 Browser Bytecode Translator
136.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
136.7 + *
136.8 + * This program is free software: you can redistribute it and/or modify
136.9 + * it under the terms of the GNU General Public License as published by
136.10 + * the Free Software Foundation, version 2 of the License.
136.11 + *
136.12 + * This program is distributed in the hope that it will be useful,
136.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
136.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
136.15 + * GNU General Public License for more details.
136.16 + *
136.17 + * You should have received a copy of the GNU General Public License
136.18 + * along with this program. Look for COPYING file in the top folder.
136.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
136.20 + */
136.21 +package org.apidesign.bck2brwsr.htmlpage.api;
136.22 +
136.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
136.24 +
136.25 +/**
136.26 + *
136.27 + * @author Anton Epple <toni.epple@eppleton.de>
136.28 + */
136.29 +public class LinearGradient {
136.30 +
136.31 + private final Object gradient;
136.32 +
136.33 + LinearGradient(Object linearGradient) {
136.34 + this.gradient = linearGradient;
136.35 + }
136.36 +
136.37 + Object object() {
136.38 + return gradient;
136.39 + }
136.40 +
136.41 + public void addColorStop(double position, String color) {
136.42 + addColorStopImpl(gradient, position, color);
136.43 + }
136.44 +
136.45 + @JavaScriptBody(args = {"gradient", "position", "color"}, body =
136.46 + "gradient.addColorStop(position,color)")
136.47 + private static native void addColorStopImpl(Object gradient, double position, String color);
136.48 +}
137.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
137.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/On.java Wed Jan 23 20:16:48 2013 +0100
137.3 @@ -0,0 +1,35 @@
137.4 +/**
137.5 + * Back 2 Browser Bytecode Translator
137.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
137.7 + *
137.8 + * This program is free software: you can redistribute it and/or modify
137.9 + * it under the terms of the GNU General Public License as published by
137.10 + * the Free Software Foundation, version 2 of the License.
137.11 + *
137.12 + * This program is distributed in the hope that it will be useful,
137.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
137.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
137.15 + * GNU General Public License for more details.
137.16 + *
137.17 + * You should have received a copy of the GNU General Public License
137.18 + * along with this program. Look for COPYING file in the top folder.
137.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
137.20 + */
137.21 +package org.apidesign.bck2brwsr.htmlpage.api;
137.22 +
137.23 +import java.lang.annotation.ElementType;
137.24 +import java.lang.annotation.Retention;
137.25 +import java.lang.annotation.RetentionPolicy;
137.26 +import java.lang.annotation.Target;
137.27 +
137.28 +/** Adds an onClick handler to an element identified by given <em>id</em>.
137.29 + * Apply on a <code>public static void</code> method with no arguments.
137.30 + *
137.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
137.32 + */
137.33 +@Retention(RetentionPolicy.SOURCE)
137.34 +@Target(ElementType.METHOD)
137.35 +public @interface On {
137.36 + OnEvent event();
137.37 + String[] id();
137.38 +}
138.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
138.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/OnController.java Wed Jan 23 20:16:48 2013 +0100
138.3 @@ -0,0 +1,43 @@
138.4 +/**
138.5 + * Back 2 Browser Bytecode Translator
138.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
138.7 + *
138.8 + * This program is free software: you can redistribute it and/or modify
138.9 + * it under the terms of the GNU General Public License as published by
138.10 + * the Free Software Foundation, version 2 of the License.
138.11 + *
138.12 + * This program is distributed in the hope that it will be useful,
138.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
138.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
138.15 + * GNU General Public License for more details.
138.16 + *
138.17 + * You should have received a copy of the GNU General Public License
138.18 + * along with this program. Look for COPYING file in the top folder.
138.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
138.20 + */
138.21 +package org.apidesign.bck2brwsr.htmlpage.api;
138.22 +
138.23 +/** Controller created via {@link OnEvent#of(org.apidesign.bck2brwsr.htmlpage.api.Element[])}.
138.24 + *
138.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
138.26 + */
138.27 +public final class OnController {
138.28 + private final Element[] arr;
138.29 + private final OnEvent event;
138.30 +
138.31 + OnController(OnEvent event, Element[] arr) {
138.32 + this.event = event;
138.33 + this.arr = arr;
138.34 + }
138.35 +
138.36 + /** Registers a runnable to be performed on associated {@link OnEvent}
138.37 + * and {@link Element}.
138.38 + *
138.39 + * @see OnEvent#of
138.40 + */
138.41 + public void perform(Runnable r) {
138.42 + for (Element e : arr) {
138.43 + e.on(event, r);
138.44 + }
138.45 + }
138.46 +}
139.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
139.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/OnEvent.java Wed Jan 23 20:16:48 2013 +0100
139.3 @@ -0,0 +1,103 @@
139.4 +/**
139.5 + * Back 2 Browser Bytecode Translator
139.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
139.7 + *
139.8 + * This program is free software: you can redistribute it and/or modify
139.9 + * it under the terms of the GNU General Public License as published by
139.10 + * the Free Software Foundation, version 2 of the License.
139.11 + *
139.12 + * This program is distributed in the hope that it will be useful,
139.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
139.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
139.15 + * GNU General Public License for more details.
139.16 + *
139.17 + * You should have received a copy of the GNU General Public License
139.18 + * along with this program. Look for COPYING file in the top folder.
139.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
139.20 + */
139.21 +package org.apidesign.bck2brwsr.htmlpage.api;
139.22 +
139.23 +/** Type of events to use in connection with {@link On} annotation.
139.24 + *
139.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
139.26 + */
139.27 +public enum OnEvent {
139.28 + ABORT("onabort"),
139.29 + BLUR("onblur"),
139.30 + CAN_PLAY("oncanplay"),
139.31 + CAN_PLAY_THROUGH("oncanplaythrough"),
139.32 + CHANGE("onchange"),
139.33 + CLICK("onclick"),
139.34 + CONTEXT_MENU("oncontextmenu"),
139.35 + DBL_CLICK("ondblclick"),
139.36 + DRAG("ondrag"),
139.37 + DRAG_END("ondragend"),
139.38 + DRAG_ENTER("ondragenter"),
139.39 + DRAG_LEAVE("ondragleave"),
139.40 + DRAG_OVER("ondragover"),
139.41 + DRAG_START("ondragstart"),
139.42 + DROP("ondrop"),
139.43 + DURATION_CHANGE("ondurationchange"),
139.44 + EMPTIED("onemptied"),
139.45 + ENDED("onended"),
139.46 + ERROR("onerror"),
139.47 + FOCUS("onfocus"),
139.48 + FORM_CHANGE("onformchange"),
139.49 + FORM_INPUT("onforminput"),
139.50 + INPUT("oninput"),
139.51 + INVALID("oninvalid"),
139.52 + KEY_DOWN("onkeydown"),
139.53 + KEY_PRESS("onkeypress"),
139.54 + KEY_UP("onkeyup"),
139.55 + LOAD("onload"),
139.56 + LOADED_DATA("onloadeddata"),
139.57 + LOADED_META_DATA("onloadedmetadata"),
139.58 + LOAD_START("onloadstart"),
139.59 + MOUSE_DOWN("onmousedown"),
139.60 + MOUSE_MOVE("onmousemove"),
139.61 + MOUSE_OUT("onmouseout"),
139.62 + MOUSE_OVER("onmouseover"),
139.63 + MOUSE_UP("onmouseup"),
139.64 + MOUSE_WHEEL("onmousewheel"),
139.65 + PAUSE("onpause"),
139.66 + PLAY("onplay"),
139.67 + PLAYING("onplaying"),
139.68 + PROGRESS("onprogress"),
139.69 + RATE_CHANGE("onratechange"),
139.70 + READY_STATE_CHANGE("onreadystatechange"),
139.71 + SCROLL("onscroll"),
139.72 + SEEKED("onseeked"),
139.73 + SEEKING("onseeking"),
139.74 + SELECT("onselect"),
139.75 + SHOW("onshow"),
139.76 + STALLED("onstalled"),
139.77 + SUBMIT("onsubmit"),
139.78 + SUSPEND("onsuspend"),
139.79 + TIME_UPDATE("ontimeupdate"),
139.80 + VOLUME_CHANGE("onvolumechange"),
139.81 + WAITING("onwaiting");
139.82 +
139.83 + final String id;
139.84 +
139.85 + private OnEvent(String id) {
139.86 + this.id = id;
139.87 + }
139.88 +
139.89 + /** The name of property this event is referenced by from an {@link Element}.
139.90 + * For {@link OnEvent#CHANGE}, it is <code>onchange</code>.
139.91 + */
139.92 + public String getElementPropertyName() {
139.93 + return id;
139.94 + }
139.95 +
139.96 + /** What should happen when this even happen on one
139.97 + * of associated elements. Continue by calling {@link OnController#perform(java.lang.Runnable)}
139.98 + * method.
139.99 + *
139.100 + * @param elmnts one or more elements
139.101 + * @return controller with <code>perform</code> method.
139.102 + */
139.103 + public OnController of(Element... elmnts) {
139.104 + return new OnController(this, elmnts);
139.105 + }
139.106 +}
140.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
140.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Page.java Wed Jan 23 20:16:48 2013 +0100
140.3 @@ -0,0 +1,42 @@
140.4 +/**
140.5 + * Back 2 Browser Bytecode Translator
140.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
140.7 + *
140.8 + * This program is free software: you can redistribute it and/or modify
140.9 + * it under the terms of the GNU General Public License as published by
140.10 + * the Free Software Foundation, version 2 of the License.
140.11 + *
140.12 + * This program is distributed in the hope that it will be useful,
140.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
140.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
140.15 + * GNU General Public License for more details.
140.16 + *
140.17 + * You should have received a copy of the GNU General Public License
140.18 + * along with this program. Look for COPYING file in the top folder.
140.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
140.20 + */
140.21 +package org.apidesign.bck2brwsr.htmlpage.api;
140.22 +
140.23 +import java.lang.annotation.ElementType;
140.24 +import java.lang.annotation.Retention;
140.25 +import java.lang.annotation.RetentionPolicy;
140.26 +import java.lang.annotation.Target;
140.27 +
140.28 +/** Converts an XHTML page into a Java class that contains
140.29 + * references to all IDs.
140.30 + *
140.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
140.32 + */
140.33 +@Retention(RetentionPolicy.SOURCE)
140.34 +@Target(ElementType.TYPE)
140.35 +public @interface Page {
140.36 + /** Path to the XHTML page to read in */
140.37 + String xhtml();
140.38 + /** Name of a Java class to generate. It will contain constants for all
140.39 + * found elements with IDs.
140.40 + */
140.41 + String className() default "";
140.42 + /** List of properties generated into the page.
140.43 + */
140.44 + Property[] properties() default {};
140.45 +}
141.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
141.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Paint.java Wed Jan 23 20:16:48 2013 +0100
141.3 @@ -0,0 +1,30 @@
141.4 +/**
141.5 + * Back 2 Browser Bytecode Translator
141.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
141.7 + *
141.8 + * This program is free software: you can redistribute it and/or modify
141.9 + * it under the terms of the GNU General Public License as published by
141.10 + * the Free Software Foundation, version 2 of the License.
141.11 + *
141.12 + * This program is distributed in the hope that it will be useful,
141.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
141.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
141.15 + * GNU General Public License for more details.
141.16 + *
141.17 + * You should have received a copy of the GNU General Public License
141.18 + * along with this program. Look for COPYING file in the top folder.
141.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
141.20 + */
141.21 +package org.apidesign.bck2brwsr.htmlpage.api;
141.22 +
141.23 +/**
141.24 + *
141.25 + * @author Anton Epple <toni.epple@eppleton.de>
141.26 + */
141.27 +public class Paint {
141.28 +
141.29 +
141.30 + String asString(){
141.31 + return "";
141.32 + }
141.33 +}
142.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
142.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Pattern.java Wed Jan 23 20:16:48 2013 +0100
142.3 @@ -0,0 +1,35 @@
142.4 +/**
142.5 + * Back 2 Browser Bytecode Translator
142.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
142.7 + *
142.8 + * This program is free software: you can redistribute it and/or modify
142.9 + * it under the terms of the GNU General Public License as published by
142.10 + * the Free Software Foundation, version 2 of the License.
142.11 + *
142.12 + * This program is distributed in the hope that it will be useful,
142.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
142.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
142.15 + * GNU General Public License for more details.
142.16 + *
142.17 + * You should have received a copy of the GNU General Public License
142.18 + * along with this program. Look for COPYING file in the top folder.
142.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
142.20 + */
142.21 +package org.apidesign.bck2brwsr.htmlpage.api;
142.22 +
142.23 +/**
142.24 + *
142.25 + * @author Anton Epple <toni.epple@eppleton.de>
142.26 + */
142.27 +public class Pattern {
142.28 +
142.29 + private Object pattern;
142.30 +
142.31 + public Pattern(Object pattern) {
142.32 + this.pattern = pattern;
142.33 + }
142.34 +
142.35 + Object object() {
142.36 + return pattern;
142.37 + }
142.38 +}
143.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
143.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Property.java Wed Jan 23 20:16:48 2013 +0100
143.3 @@ -0,0 +1,34 @@
143.4 +/**
143.5 + * Back 2 Browser Bytecode Translator
143.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
143.7 + *
143.8 + * This program is free software: you can redistribute it and/or modify
143.9 + * it under the terms of the GNU General Public License as published by
143.10 + * the Free Software Foundation, version 2 of the License.
143.11 + *
143.12 + * This program is distributed in the hope that it will be useful,
143.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
143.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
143.15 + * GNU General Public License for more details.
143.16 + *
143.17 + * You should have received a copy of the GNU General Public License
143.18 + * along with this program. Look for COPYING file in the top folder.
143.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
143.20 + */
143.21 +package org.apidesign.bck2brwsr.htmlpage.api;
143.22 +
143.23 +import java.lang.annotation.Retention;
143.24 +import java.lang.annotation.RetentionPolicy;
143.25 +import java.lang.annotation.Target;
143.26 +
143.27 +/** Represents a property in a generated model of an HTML
143.28 + * {@link Page}.
143.29 + *
143.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
143.31 + */
143.32 +@Retention(RetentionPolicy.SOURCE)
143.33 +@Target({})
143.34 +public @interface Property {
143.35 + String name();
143.36 + Class<?> type();
143.37 +}
144.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
144.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/RadialGradient.java Wed Jan 23 20:16:48 2013 +0100
144.3 @@ -0,0 +1,45 @@
144.4 +/**
144.5 + * Back 2 Browser Bytecode Translator
144.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
144.7 + *
144.8 + * This program is free software: you can redistribute it and/or modify
144.9 + * it under the terms of the GNU General Public License as published by
144.10 + * the Free Software Foundation, version 2 of the License.
144.11 + *
144.12 + * This program is distributed in the hope that it will be useful,
144.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
144.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
144.15 + * GNU General Public License for more details.
144.16 + *
144.17 + * You should have received a copy of the GNU General Public License
144.18 + * along with this program. Look for COPYING file in the top folder.
144.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
144.20 + */
144.21 +package org.apidesign.bck2brwsr.htmlpage.api;
144.22 +
144.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
144.24 +
144.25 +/**
144.26 + *
144.27 + * @author Anton Epple <toni.epple@eppleton.de>
144.28 + */
144.29 +public class RadialGradient {
144.30 +
144.31 + private Object gradient;
144.32 +
144.33 + public RadialGradient(Object radialGradient) {
144.34 + this.gradient = radialGradient;
144.35 + }
144.36 +
144.37 + public void addColorStop(double position, String color) {
144.38 + addColorStopImpl(gradient, position, color);
144.39 + }
144.40 +
144.41 + @JavaScriptBody(args = {"gradient", "position", "color"}, body =
144.42 + "gradient.addColorStop(position,color)")
144.43 + private static native void addColorStopImpl(Object gradient, double position, String color);
144.44 +
144.45 + Object object() {
144.46 + return gradient;
144.47 + }
144.48 +}
145.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
145.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/TextMetrics.java Wed Jan 23 20:16:48 2013 +0100
145.3 @@ -0,0 +1,48 @@
145.4 +/**
145.5 + * Back 2 Browser Bytecode Translator
145.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
145.7 + *
145.8 + * This program is free software: you can redistribute it and/or modify
145.9 + * it under the terms of the GNU General Public License as published by
145.10 + * the Free Software Foundation, version 2 of the License.
145.11 + *
145.12 + * This program is distributed in the hope that it will be useful,
145.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
145.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
145.15 + * GNU General Public License for more details.
145.16 + *
145.17 + * You should have received a copy of the GNU General Public License
145.18 + * along with this program. Look for COPYING file in the top folder.
145.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
145.20 + */
145.21 +package org.apidesign.bck2brwsr.htmlpage.api;
145.22 +
145.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
145.24 +
145.25 +/**
145.26 + *
145.27 + * @author Anton Epple <toni.epple@eppleton.de>
145.28 + */
145.29 +public class TextMetrics {
145.30 +
145.31 + private Object textMetrics;
145.32 +
145.33 + TextMetrics(Object measureTextImpl) {
145.34 + this.textMetrics = measureTextImpl;
145.35 + }
145.36 +
145.37 + @JavaScriptBody(args = {"textMetrics"}, body = "return textMetrics.width;")
145.38 + private native double getWidth(Object textMetrics);
145.39 +
145.40 + @JavaScriptBody(args = {"textMetrics"}, body = "return textMetrics.height;")
145.41 + private native double getHeight(Object textMetrics);
145.42 +
145.43 + public double getWidth() {
145.44 + return getWidth(textMetrics);
145.45 + }
145.46 +
145.47 + public double getHeight() {
145.48 + return getHeight(textMetrics);
145.49 +
145.50 + }
145.51 +}
146.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
146.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Timer.java Wed Jan 23 20:16:48 2013 +0100
146.3 @@ -0,0 +1,59 @@
146.4 +/**
146.5 + * Back 2 Browser Bytecode Translator
146.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
146.7 + *
146.8 + * This program is free software: you can redistribute it and/or modify
146.9 + * it under the terms of the GNU General Public License as published by
146.10 + * the Free Software Foundation, version 2 of the License.
146.11 + *
146.12 + * This program is distributed in the hope that it will be useful,
146.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
146.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
146.15 + * GNU General Public License for more details.
146.16 + *
146.17 + * You should have received a copy of the GNU General Public License
146.18 + * along with this program. Look for COPYING file in the top folder.
146.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
146.20 + */
146.21 +package org.apidesign.bck2brwsr.htmlpage.api;
146.22 +
146.23 +import java.io.Closeable;
146.24 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
146.25 +
146.26 +/**
146.27 + *
146.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
146.29 + */
146.30 +public class Timer implements Closeable {
146.31 + private final Object t;
146.32 +
146.33 + private Timer(Object t) {
146.34 + this.t = t;
146.35 + }
146.36 +
146.37 + /** Creates a timer that invokes provided runnable on a fixed interval
146.38 + *
146.39 + * @param r the runnable to execute
146.40 + * @param time milliseconds to invoke the timer periodically
146.41 + */
146.42 + public static Timer create(Runnable r, int time) {
146.43 + return new Timer(interval(r, time));
146.44 + }
146.45 +
146.46 + @JavaScriptBody(args = { "r", "time" }, body =
146.47 + "return window.setInterval(function() { r.run__V(); }, time);"
146.48 + )
146.49 + private static native Object interval(Runnable r, int time);
146.50 +
146.51 + @JavaScriptBody(args = { "self" }, body =
146.52 + "window.clearInterval(self);"
146.53 + )
146.54 + private static native void close(Object self);
146.55 +
146.56 + /** Cancels this timer.
146.57 + */
146.58 + @Override
146.59 + public void close() {
146.60 + close(t);
146.61 + }
146.62 +}
147.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
147.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Title.java Wed Jan 23 20:16:48 2013 +0100
147.3 @@ -0,0 +1,36 @@
147.4 +/**
147.5 + * Back 2 Browser Bytecode Translator
147.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
147.7 + *
147.8 + * This program is free software: you can redistribute it and/or modify
147.9 + * it under the terms of the GNU General Public License as published by
147.10 + * the Free Software Foundation, version 2 of the License.
147.11 + *
147.12 + * This program is distributed in the hope that it will be useful,
147.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
147.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
147.15 + * GNU General Public License for more details.
147.16 + *
147.17 + * You should have received a copy of the GNU General Public License
147.18 + * along with this program. Look for COPYING file in the top folder.
147.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
147.20 + */
147.21 +package org.apidesign.bck2brwsr.htmlpage.api;
147.22 +
147.23 +/**
147.24 + *
147.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
147.26 + */
147.27 +public class Title extends Element {
147.28 + public Title(String id) {
147.29 + super(id);
147.30 + }
147.31 +
147.32 + @Override
147.33 + void dontSubclass() {
147.34 + }
147.35 +
147.36 + public final void setText(String text) {
147.37 + setAttribute(this, "innerHTML", text);
147.38 + }
147.39 +}
148.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
148.2 +++ b/javaquery/api/src/main/resources/org/apidesign/bck2brwsr/htmlpage/knockout-2.2.1.js Wed Jan 23 20:16:48 2013 +0100
148.3 @@ -0,0 +1,3587 @@
148.4 +// Knockout JavaScript library v2.2.1
148.5 +// (c) Steven Sanderson - http://knockoutjs.com/
148.6 +// License: MIT (http://www.opensource.org/licenses/mit-license.php)
148.7 +
148.8 +(function(){
148.9 +var DEBUG=true;
148.10 +(function(window,document,navigator,jQuery,undefined){
148.11 +!function(factory) {
148.12 + // Support three module loading scenarios
148.13 + if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') {
148.14 + // [1] CommonJS/Node.js
148.15 + var target = module['exports'] || exports; // module.exports is for Node.js
148.16 + factory(target);
148.17 + } else if (typeof define === 'function' && define['amd']) {
148.18 + // [2] AMD anonymous module
148.19 + define(['exports'], factory);
148.20 + } else {
148.21 + // [3] No module loader (plain <script> tag) - put directly in global namespace
148.22 + factory(window['ko'] = {});
148.23 + }
148.24 +}(function(koExports){
148.25 +// Internally, all KO objects are attached to koExports (even the non-exported ones whose names will be minified by the closure compiler).
148.26 +// In the future, the following "ko" variable may be made distinct from "koExports" so that private objects are not externally reachable.
148.27 +var ko = typeof koExports !== 'undefined' ? koExports : {};
148.28 +// Google Closure Compiler helpers (used only to make the minified file smaller)
148.29 +ko.exportSymbol = function(koPath, object) {
148.30 + var tokens = koPath.split(".");
148.31 +
148.32 + // In the future, "ko" may become distinct from "koExports" (so that non-exported objects are not reachable)
148.33 + // At that point, "target" would be set to: (typeof koExports !== "undefined" ? koExports : ko)
148.34 + var target = ko;
148.35 +
148.36 + for (var i = 0; i < tokens.length - 1; i++)
148.37 + target = target[tokens[i]];
148.38 + target[tokens[tokens.length - 1]] = object;
148.39 +};
148.40 +ko.exportProperty = function(owner, publicName, object) {
148.41 + owner[publicName] = object;
148.42 +};
148.43 +ko.version = "2.2.1";
148.44 +
148.45 +ko.exportSymbol('version', ko.version);
148.46 +ko.utils = new (function () {
148.47 + var stringTrimRegex = /^(\s|\u00A0)+|(\s|\u00A0)+$/g;
148.48 +
148.49 + // Represent the known event types in a compact way, then at runtime transform it into a hash with event name as key (for fast lookup)
148.50 + var knownEvents = {}, knownEventTypesByEventName = {};
148.51 + var keyEventTypeName = /Firefox\/2/i.test(navigator.userAgent) ? 'KeyboardEvent' : 'UIEvents';
148.52 + knownEvents[keyEventTypeName] = ['keyup', 'keydown', 'keypress'];
148.53 + knownEvents['MouseEvents'] = ['click', 'dblclick', 'mousedown', 'mouseup', 'mousemove', 'mouseover', 'mouseout', 'mouseenter', 'mouseleave'];
148.54 + for (var eventType in knownEvents) {
148.55 + var knownEventsForType = knownEvents[eventType];
148.56 + if (knownEventsForType.length) {
148.57 + for (var i = 0, j = knownEventsForType.length; i < j; i++)
148.58 + knownEventTypesByEventName[knownEventsForType[i]] = eventType;
148.59 + }
148.60 + }
148.61 + var eventsThatMustBeRegisteredUsingAttachEvent = { 'propertychange': true }; // Workaround for an IE9 issue - https://github.com/SteveSanderson/knockout/issues/406
148.62 +
148.63 + // Detect IE versions for bug workarounds (uses IE conditionals, not UA string, for robustness)
148.64 + // Note that, since IE 10 does not support conditional comments, the following logic only detects IE < 10.
148.65 + // Currently this is by design, since IE 10+ behaves correctly when treated as a standard browser.
148.66 + // If there is a future need to detect specific versions of IE10+, we will amend this.
148.67 + var ieVersion = (function() {
148.68 + var version = 3, div = document.createElement('div'), iElems = div.getElementsByTagName('i');
148.69 +
148.70 + // Keep constructing conditional HTML blocks until we hit one that resolves to an empty fragment
148.71 + while (
148.72 + div.innerHTML = '<!--[if gt IE ' + (++version) + ']><i></i><![endif]-->',
148.73 + iElems[0]
148.74 + );
148.75 + return version > 4 ? version : undefined;
148.76 + }());
148.77 + var isIe6 = ieVersion === 6,
148.78 + isIe7 = ieVersion === 7;
148.79 +
148.80 + function isClickOnCheckableElement(element, eventType) {
148.81 + if ((ko.utils.tagNameLower(element) !== "input") || !element.type) return false;
148.82 + if (eventType.toLowerCase() != "click") return false;
148.83 + var inputType = element.type;
148.84 + return (inputType == "checkbox") || (inputType == "radio");
148.85 + }
148.86 +
148.87 + return {
148.88 + fieldsIncludedWithJsonPost: ['authenticity_token', /^__RequestVerificationToken(_.*)?$/],
148.89 +
148.90 + arrayForEach: function (array, action) {
148.91 + for (var i = 0, j = array.length; i < j; i++)
148.92 + action(array[i]);
148.93 + },
148.94 +
148.95 + arrayIndexOf: function (array, item) {
148.96 + if (typeof Array.prototype.indexOf == "function")
148.97 + return Array.prototype.indexOf.call(array, item);
148.98 + for (var i = 0, j = array.length; i < j; i++)
148.99 + if (array[i] === item)
148.100 + return i;
148.101 + return -1;
148.102 + },
148.103 +
148.104 + arrayFirst: function (array, predicate, predicateOwner) {
148.105 + for (var i = 0, j = array.length; i < j; i++)
148.106 + if (predicate.call(predicateOwner, array[i]))
148.107 + return array[i];
148.108 + return null;
148.109 + },
148.110 +
148.111 + arrayRemoveItem: function (array, itemToRemove) {
148.112 + var index = ko.utils.arrayIndexOf(array, itemToRemove);
148.113 + if (index >= 0)
148.114 + array.splice(index, 1);
148.115 + },
148.116 +
148.117 + arrayGetDistinctValues: function (array) {
148.118 + array = array || [];
148.119 + var result = [];
148.120 + for (var i = 0, j = array.length; i < j; i++) {
148.121 + if (ko.utils.arrayIndexOf(result, array[i]) < 0)
148.122 + result.push(array[i]);
148.123 + }
148.124 + return result;
148.125 + },
148.126 +
148.127 + arrayMap: function (array, mapping) {
148.128 + array = array || [];
148.129 + var result = [];
148.130 + for (var i = 0, j = array.length; i < j; i++)
148.131 + result.push(mapping(array[i]));
148.132 + return result;
148.133 + },
148.134 +
148.135 + arrayFilter: function (array, predicate) {
148.136 + array = array || [];
148.137 + var result = [];
148.138 + for (var i = 0, j = array.length; i < j; i++)
148.139 + if (predicate(array[i]))
148.140 + result.push(array[i]);
148.141 + return result;
148.142 + },
148.143 +
148.144 + arrayPushAll: function (array, valuesToPush) {
148.145 + if (valuesToPush instanceof Array)
148.146 + array.push.apply(array, valuesToPush);
148.147 + else
148.148 + for (var i = 0, j = valuesToPush.length; i < j; i++)
148.149 + array.push(valuesToPush[i]);
148.150 + return array;
148.151 + },
148.152 +
148.153 + extend: function (target, source) {
148.154 + if (source) {
148.155 + for(var prop in source) {
148.156 + if(source.hasOwnProperty(prop)) {
148.157 + target[prop] = source[prop];
148.158 + }
148.159 + }
148.160 + }
148.161 + return target;
148.162 + },
148.163 +
148.164 + emptyDomNode: function (domNode) {
148.165 + while (domNode.firstChild) {
148.166 + ko.removeNode(domNode.firstChild);
148.167 + }
148.168 + },
148.169 +
148.170 + moveCleanedNodesToContainerElement: function(nodes) {
148.171 + // Ensure it's a real array, as we're about to reparent the nodes and
148.172 + // we don't want the underlying collection to change while we're doing that.
148.173 + var nodesArray = ko.utils.makeArray(nodes);
148.174 +
148.175 + var container = document.createElement('div');
148.176 + for (var i = 0, j = nodesArray.length; i < j; i++) {
148.177 + container.appendChild(ko.cleanNode(nodesArray[i]));
148.178 + }
148.179 + return container;
148.180 + },
148.181 +
148.182 + cloneNodes: function (nodesArray, shouldCleanNodes) {
148.183 + for (var i = 0, j = nodesArray.length, newNodesArray = []; i < j; i++) {
148.184 + var clonedNode = nodesArray[i].cloneNode(true);
148.185 + newNodesArray.push(shouldCleanNodes ? ko.cleanNode(clonedNode) : clonedNode);
148.186 + }
148.187 + return newNodesArray;
148.188 + },
148.189 +
148.190 + setDomNodeChildren: function (domNode, childNodes) {
148.191 + ko.utils.emptyDomNode(domNode);
148.192 + if (childNodes) {
148.193 + for (var i = 0, j = childNodes.length; i < j; i++)
148.194 + domNode.appendChild(childNodes[i]);
148.195 + }
148.196 + },
148.197 +
148.198 + replaceDomNodes: function (nodeToReplaceOrNodeArray, newNodesArray) {
148.199 + var nodesToReplaceArray = nodeToReplaceOrNodeArray.nodeType ? [nodeToReplaceOrNodeArray] : nodeToReplaceOrNodeArray;
148.200 + if (nodesToReplaceArray.length > 0) {
148.201 + var insertionPoint = nodesToReplaceArray[0];
148.202 + var parent = insertionPoint.parentNode;
148.203 + for (var i = 0, j = newNodesArray.length; i < j; i++)
148.204 + parent.insertBefore(newNodesArray[i], insertionPoint);
148.205 + for (var i = 0, j = nodesToReplaceArray.length; i < j; i++) {
148.206 + ko.removeNode(nodesToReplaceArray[i]);
148.207 + }
148.208 + }
148.209 + },
148.210 +
148.211 + setOptionNodeSelectionState: function (optionNode, isSelected) {
148.212 + // IE6 sometimes throws "unknown error" if you try to write to .selected directly, whereas Firefox struggles with setAttribute. Pick one based on browser.
148.213 + if (ieVersion < 7)
148.214 + optionNode.setAttribute("selected", isSelected);
148.215 + else
148.216 + optionNode.selected = isSelected;
148.217 + },
148.218 +
148.219 + stringTrim: function (string) {
148.220 + return (string || "").replace(stringTrimRegex, "");
148.221 + },
148.222 +
148.223 + stringTokenize: function (string, delimiter) {
148.224 + var result = [];
148.225 + var tokens = (string || "").split(delimiter);
148.226 + for (var i = 0, j = tokens.length; i < j; i++) {
148.227 + var trimmed = ko.utils.stringTrim(tokens[i]);
148.228 + if (trimmed !== "")
148.229 + result.push(trimmed);
148.230 + }
148.231 + return result;
148.232 + },
148.233 +
148.234 + stringStartsWith: function (string, startsWith) {
148.235 + string = string || "";
148.236 + if (startsWith.length > string.length)
148.237 + return false;
148.238 + return string.substring(0, startsWith.length) === startsWith;
148.239 + },
148.240 +
148.241 + domNodeIsContainedBy: function (node, containedByNode) {
148.242 + if (containedByNode.compareDocumentPosition)
148.243 + return (containedByNode.compareDocumentPosition(node) & 16) == 16;
148.244 + while (node != null) {
148.245 + if (node == containedByNode)
148.246 + return true;
148.247 + node = node.parentNode;
148.248 + }
148.249 + return false;
148.250 + },
148.251 +
148.252 + domNodeIsAttachedToDocument: function (node) {
148.253 + return ko.utils.domNodeIsContainedBy(node, node.ownerDocument);
148.254 + },
148.255 +
148.256 + tagNameLower: function(element) {
148.257 + // For HTML elements, tagName will always be upper case; for XHTML elements, it'll be lower case.
148.258 + // Possible future optimization: If we know it's an element from an XHTML document (not HTML),
148.259 + // we don't need to do the .toLowerCase() as it will always be lower case anyway.
148.260 + return element && element.tagName && element.tagName.toLowerCase();
148.261 + },
148.262 +
148.263 + registerEventHandler: function (element, eventType, handler) {
148.264 + var mustUseAttachEvent = ieVersion && eventsThatMustBeRegisteredUsingAttachEvent[eventType];
148.265 + if (!mustUseAttachEvent && typeof jQuery != "undefined") {
148.266 + if (isClickOnCheckableElement(element, eventType)) {
148.267 + // For click events on checkboxes, jQuery interferes with the event handling in an awkward way:
148.268 + // it toggles the element checked state *after* the click event handlers run, whereas native
148.269 + // click events toggle the checked state *before* the event handler.
148.270 + // Fix this by intecepting the handler and applying the correct checkedness before it runs.
148.271 + var originalHandler = handler;
148.272 + handler = function(event, eventData) {
148.273 + var jQuerySuppliedCheckedState = this.checked;
148.274 + if (eventData)
148.275 + this.checked = eventData.checkedStateBeforeEvent !== true;
148.276 + originalHandler.call(this, event);
148.277 + this.checked = jQuerySuppliedCheckedState; // Restore the state jQuery applied
148.278 + };
148.279 + }
148.280 + jQuery(element)['bind'](eventType, handler);
148.281 + } else if (!mustUseAttachEvent && typeof element.addEventListener == "function")
148.282 + element.addEventListener(eventType, handler, false);
148.283 + else if (typeof element.attachEvent != "undefined")
148.284 + element.attachEvent("on" + eventType, function (event) {
148.285 + handler.call(element, event);
148.286 + });
148.287 + else
148.288 + throw new Error("Browser doesn't support addEventListener or attachEvent");
148.289 + },
148.290 +
148.291 + triggerEvent: function (element, eventType) {
148.292 + if (!(element && element.nodeType))
148.293 + throw new Error("element must be a DOM node when calling triggerEvent");
148.294 +
148.295 + if (typeof jQuery != "undefined") {
148.296 + var eventData = [];
148.297 + if (isClickOnCheckableElement(element, eventType)) {
148.298 + // Work around the jQuery "click events on checkboxes" issue described above by storing the original checked state before triggering the handler
148.299 + eventData.push({ checkedStateBeforeEvent: element.checked });
148.300 + }
148.301 + jQuery(element)['trigger'](eventType, eventData);
148.302 + } else if (typeof document.createEvent == "function") {
148.303 + if (typeof element.dispatchEvent == "function") {
148.304 + var eventCategory = knownEventTypesByEventName[eventType] || "HTMLEvents";
148.305 + var event = document.createEvent(eventCategory);
148.306 + event.initEvent(eventType, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, element);
148.307 + element.dispatchEvent(event);
148.308 + }
148.309 + else
148.310 + throw new Error("The supplied element doesn't support dispatchEvent");
148.311 + } else if (typeof element.fireEvent != "undefined") {
148.312 + // Unlike other browsers, IE doesn't change the checked state of checkboxes/radiobuttons when you trigger their "click" event
148.313 + // so to make it consistent, we'll do it manually here
148.314 + if (isClickOnCheckableElement(element, eventType))
148.315 + element.checked = element.checked !== true;
148.316 + element.fireEvent("on" + eventType);
148.317 + }
148.318 + else
148.319 + throw new Error("Browser doesn't support triggering events");
148.320 + },
148.321 +
148.322 + unwrapObservable: function (value) {
148.323 + return ko.isObservable(value) ? value() : value;
148.324 + },
148.325 +
148.326 + peekObservable: function (value) {
148.327 + return ko.isObservable(value) ? value.peek() : value;
148.328 + },
148.329 +
148.330 + toggleDomNodeCssClass: function (node, classNames, shouldHaveClass) {
148.331 + if (classNames) {
148.332 + var cssClassNameRegex = /[\w-]+/g,
148.333 + currentClassNames = node.className.match(cssClassNameRegex) || [];
148.334 + ko.utils.arrayForEach(classNames.match(cssClassNameRegex), function(className) {
148.335 + var indexOfClass = ko.utils.arrayIndexOf(currentClassNames, className);
148.336 + if (indexOfClass >= 0) {
148.337 + if (!shouldHaveClass)
148.338 + currentClassNames.splice(indexOfClass, 1);
148.339 + } else {
148.340 + if (shouldHaveClass)
148.341 + currentClassNames.push(className);
148.342 + }
148.343 + });
148.344 + node.className = currentClassNames.join(" ");
148.345 + }
148.346 + },
148.347 +
148.348 + setTextContent: function(element, textContent) {
148.349 + var value = ko.utils.unwrapObservable(textContent);
148.350 + if ((value === null) || (value === undefined))
148.351 + value = "";
148.352 +
148.353 + if (element.nodeType === 3) {
148.354 + element.data = value;
148.355 + } else {
148.356 + // We need there to be exactly one child: a text node.
148.357 + // If there are no children, more than one, or if it's not a text node,
148.358 + // we'll clear everything and create a single text node.
148.359 + var innerTextNode = ko.virtualElements.firstChild(element);
148.360 + if (!innerTextNode || innerTextNode.nodeType != 3 || ko.virtualElements.nextSibling(innerTextNode)) {
148.361 + ko.virtualElements.setDomNodeChildren(element, [document.createTextNode(value)]);
148.362 + } else {
148.363 + innerTextNode.data = value;
148.364 + }
148.365 +
148.366 + ko.utils.forceRefresh(element);
148.367 + }
148.368 + },
148.369 +
148.370 + setElementName: function(element, name) {
148.371 + element.name = name;
148.372 +
148.373 + // Workaround IE 6/7 issue
148.374 + // - https://github.com/SteveSanderson/knockout/issues/197
148.375 + // - http://www.matts411.com/post/setting_the_name_attribute_in_ie_dom/
148.376 + if (ieVersion <= 7) {
148.377 + try {
148.378 + element.mergeAttributes(document.createElement("<input name='" + element.name + "'/>"), false);
148.379 + }
148.380 + catch(e) {} // For IE9 with doc mode "IE9 Standards" and browser mode "IE9 Compatibility View"
148.381 + }
148.382 + },
148.383 +
148.384 + forceRefresh: function(node) {
148.385 + // Workaround for an IE9 rendering bug - https://github.com/SteveSanderson/knockout/issues/209
148.386 + if (ieVersion >= 9) {
148.387 + // For text nodes and comment nodes (most likely virtual elements), we will have to refresh the container
148.388 + var elem = node.nodeType == 1 ? node : node.parentNode;
148.389 + if (elem.style)
148.390 + elem.style.zoom = elem.style.zoom;
148.391 + }
148.392 + },
148.393 +
148.394 + ensureSelectElementIsRenderedCorrectly: function(selectElement) {
148.395 + // Workaround for IE9 rendering bug - it doesn't reliably display all the text in dynamically-added select boxes unless you force it to re-render by updating the width.
148.396 + // (See https://github.com/SteveSanderson/knockout/issues/312, http://stackoverflow.com/questions/5908494/select-only-shows-first-char-of-selected-option)
148.397 + if (ieVersion >= 9) {
148.398 + var originalWidth = selectElement.style.width;
148.399 + selectElement.style.width = 0;
148.400 + selectElement.style.width = originalWidth;
148.401 + }
148.402 + },
148.403 +
148.404 + range: function (min, max) {
148.405 + min = ko.utils.unwrapObservable(min);
148.406 + max = ko.utils.unwrapObservable(max);
148.407 + var result = [];
148.408 + for (var i = min; i <= max; i++)
148.409 + result.push(i);
148.410 + return result;
148.411 + },
148.412 +
148.413 + makeArray: function(arrayLikeObject) {
148.414 + var result = [];
148.415 + for (var i = 0, j = arrayLikeObject.length; i < j; i++) {
148.416 + result.push(arrayLikeObject[i]);
148.417 + };
148.418 + return result;
148.419 + },
148.420 +
148.421 + isIe6 : isIe6,
148.422 + isIe7 : isIe7,
148.423 + ieVersion : ieVersion,
148.424 +
148.425 + getFormFields: function(form, fieldName) {
148.426 + var fields = ko.utils.makeArray(form.getElementsByTagName("input")).concat(ko.utils.makeArray(form.getElementsByTagName("textarea")));
148.427 + var isMatchingField = (typeof fieldName == 'string')
148.428 + ? function(field) { return field.name === fieldName }
148.429 + : function(field) { return fieldName.test(field.name) }; // Treat fieldName as regex or object containing predicate
148.430 + var matches = [];
148.431 + for (var i = fields.length - 1; i >= 0; i--) {
148.432 + if (isMatchingField(fields[i]))
148.433 + matches.push(fields[i]);
148.434 + };
148.435 + return matches;
148.436 + },
148.437 +
148.438 + parseJson: function (jsonString) {
148.439 + if (typeof jsonString == "string") {
148.440 + jsonString = ko.utils.stringTrim(jsonString);
148.441 + if (jsonString) {
148.442 + if (window.JSON && window.JSON.parse) // Use native parsing where available
148.443 + return window.JSON.parse(jsonString);
148.444 + return (new Function("return " + jsonString))(); // Fallback on less safe parsing for older browsers
148.445 + }
148.446 + }
148.447 + return null;
148.448 + },
148.449 +
148.450 + stringifyJson: function (data, replacer, space) { // replacer and space are optional
148.451 + if ((typeof JSON == "undefined") || (typeof JSON.stringify == "undefined"))
148.452 + throw new Error("Cannot find JSON.stringify(). Some browsers (e.g., IE < 8) don't support it natively, but you can overcome this by adding a script reference to json2.js, downloadable from http://www.json.org/json2.js");
148.453 + return JSON.stringify(ko.utils.unwrapObservable(data), replacer, space);
148.454 + },
148.455 +
148.456 + postJson: function (urlOrForm, data, options) {
148.457 + options = options || {};
148.458 + var params = options['params'] || {};
148.459 + var includeFields = options['includeFields'] || this.fieldsIncludedWithJsonPost;
148.460 + var url = urlOrForm;
148.461 +
148.462 + // If we were given a form, use its 'action' URL and pick out any requested field values
148.463 + if((typeof urlOrForm == 'object') && (ko.utils.tagNameLower(urlOrForm) === "form")) {
148.464 + var originalForm = urlOrForm;
148.465 + url = originalForm.action;
148.466 + for (var i = includeFields.length - 1; i >= 0; i--) {
148.467 + var fields = ko.utils.getFormFields(originalForm, includeFields[i]);
148.468 + for (var j = fields.length - 1; j >= 0; j--)
148.469 + params[fields[j].name] = fields[j].value;
148.470 + }
148.471 + }
148.472 +
148.473 + data = ko.utils.unwrapObservable(data);
148.474 + var form = document.createElement("form");
148.475 + form.style.display = "none";
148.476 + form.action = url;
148.477 + form.method = "post";
148.478 + for (var key in data) {
148.479 + var input = document.createElement("input");
148.480 + input.name = key;
148.481 + input.value = ko.utils.stringifyJson(ko.utils.unwrapObservable(data[key]));
148.482 + form.appendChild(input);
148.483 + }
148.484 + for (var key in params) {
148.485 + var input = document.createElement("input");
148.486 + input.name = key;
148.487 + input.value = params[key];
148.488 + form.appendChild(input);
148.489 + }
148.490 + document.body.appendChild(form);
148.491 + options['submitter'] ? options['submitter'](form) : form.submit();
148.492 + setTimeout(function () { form.parentNode.removeChild(form); }, 0);
148.493 + }
148.494 + }
148.495 +})();
148.496 +
148.497 +ko.exportSymbol('utils', ko.utils);
148.498 +ko.exportSymbol('utils.arrayForEach', ko.utils.arrayForEach);
148.499 +ko.exportSymbol('utils.arrayFirst', ko.utils.arrayFirst);
148.500 +ko.exportSymbol('utils.arrayFilter', ko.utils.arrayFilter);
148.501 +ko.exportSymbol('utils.arrayGetDistinctValues', ko.utils.arrayGetDistinctValues);
148.502 +ko.exportSymbol('utils.arrayIndexOf', ko.utils.arrayIndexOf);
148.503 +ko.exportSymbol('utils.arrayMap', ko.utils.arrayMap);
148.504 +ko.exportSymbol('utils.arrayPushAll', ko.utils.arrayPushAll);
148.505 +ko.exportSymbol('utils.arrayRemoveItem', ko.utils.arrayRemoveItem);
148.506 +ko.exportSymbol('utils.extend', ko.utils.extend);
148.507 +ko.exportSymbol('utils.fieldsIncludedWithJsonPost', ko.utils.fieldsIncludedWithJsonPost);
148.508 +ko.exportSymbol('utils.getFormFields', ko.utils.getFormFields);
148.509 +ko.exportSymbol('utils.peekObservable', ko.utils.peekObservable);
148.510 +ko.exportSymbol('utils.postJson', ko.utils.postJson);
148.511 +ko.exportSymbol('utils.parseJson', ko.utils.parseJson);
148.512 +ko.exportSymbol('utils.registerEventHandler', ko.utils.registerEventHandler);
148.513 +ko.exportSymbol('utils.stringifyJson', ko.utils.stringifyJson);
148.514 +ko.exportSymbol('utils.range', ko.utils.range);
148.515 +ko.exportSymbol('utils.toggleDomNodeCssClass', ko.utils.toggleDomNodeCssClass);
148.516 +ko.exportSymbol('utils.triggerEvent', ko.utils.triggerEvent);
148.517 +ko.exportSymbol('utils.unwrapObservable', ko.utils.unwrapObservable);
148.518 +
148.519 +if (!Function.prototype['bind']) {
148.520 + // Function.prototype.bind is a standard part of ECMAScript 5th Edition (December 2009, http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf)
148.521 + // In case the browser doesn't implement it natively, provide a JavaScript implementation. This implementation is based on the one in prototype.js
148.522 + Function.prototype['bind'] = function (object) {
148.523 + var originalFunction = this, args = Array.prototype.slice.call(arguments), object = args.shift();
148.524 + return function () {
148.525 + return originalFunction.apply(object, args.concat(Array.prototype.slice.call(arguments)));
148.526 + };
148.527 + };
148.528 +}
148.529 +
148.530 +ko.utils.domData = new (function () {
148.531 + var uniqueId = 0;
148.532 + var dataStoreKeyExpandoPropertyName = "__ko__" + (new Date).getTime();
148.533 + var dataStore = {};
148.534 + return {
148.535 + get: function (node, key) {
148.536 + var allDataForNode = ko.utils.domData.getAll(node, false);
148.537 + return allDataForNode === undefined ? undefined : allDataForNode[key];
148.538 + },
148.539 + set: function (node, key, value) {
148.540 + if (value === undefined) {
148.541 + // Make sure we don't actually create a new domData key if we are actually deleting a value
148.542 + if (ko.utils.domData.getAll(node, false) === undefined)
148.543 + return;
148.544 + }
148.545 + var allDataForNode = ko.utils.domData.getAll(node, true);
148.546 + allDataForNode[key] = value;
148.547 + },
148.548 + getAll: function (node, createIfNotFound) {
148.549 + var dataStoreKey = node[dataStoreKeyExpandoPropertyName];
148.550 + var hasExistingDataStore = dataStoreKey && (dataStoreKey !== "null") && dataStore[dataStoreKey];
148.551 + if (!hasExistingDataStore) {
148.552 + if (!createIfNotFound)
148.553 + return undefined;
148.554 + dataStoreKey = node[dataStoreKeyExpandoPropertyName] = "ko" + uniqueId++;
148.555 + dataStore[dataStoreKey] = {};
148.556 + }
148.557 + return dataStore[dataStoreKey];
148.558 + },
148.559 + clear: function (node) {
148.560 + var dataStoreKey = node[dataStoreKeyExpandoPropertyName];
148.561 + if (dataStoreKey) {
148.562 + delete dataStore[dataStoreKey];
148.563 + node[dataStoreKeyExpandoPropertyName] = null;
148.564 + return true; // Exposing "did clean" flag purely so specs can infer whether things have been cleaned up as intended
148.565 + }
148.566 + return false;
148.567 + }
148.568 + }
148.569 +})();
148.570 +
148.571 +ko.exportSymbol('utils.domData', ko.utils.domData);
148.572 +ko.exportSymbol('utils.domData.clear', ko.utils.domData.clear); // Exporting only so specs can clear up after themselves fully
148.573 +
148.574 +ko.utils.domNodeDisposal = new (function () {
148.575 + var domDataKey = "__ko_domNodeDisposal__" + (new Date).getTime();
148.576 + var cleanableNodeTypes = { 1: true, 8: true, 9: true }; // Element, Comment, Document
148.577 + var cleanableNodeTypesWithDescendants = { 1: true, 9: true }; // Element, Document
148.578 +
148.579 + function getDisposeCallbacksCollection(node, createIfNotFound) {
148.580 + var allDisposeCallbacks = ko.utils.domData.get(node, domDataKey);
148.581 + if ((allDisposeCallbacks === undefined) && createIfNotFound) {
148.582 + allDisposeCallbacks = [];
148.583 + ko.utils.domData.set(node, domDataKey, allDisposeCallbacks);
148.584 + }
148.585 + return allDisposeCallbacks;
148.586 + }
148.587 + function destroyCallbacksCollection(node) {
148.588 + ko.utils.domData.set(node, domDataKey, undefined);
148.589 + }
148.590 +
148.591 + function cleanSingleNode(node) {
148.592 + // Run all the dispose callbacks
148.593 + var callbacks = getDisposeCallbacksCollection(node, false);
148.594 + if (callbacks) {
148.595 + callbacks = callbacks.slice(0); // Clone, as the array may be modified during iteration (typically, callbacks will remove themselves)
148.596 + for (var i = 0; i < callbacks.length; i++)
148.597 + callbacks[i](node);
148.598 + }
148.599 +
148.600 + // Also erase the DOM data
148.601 + ko.utils.domData.clear(node);
148.602 +
148.603 + // Special support for jQuery here because it's so commonly used.
148.604 + // Many jQuery plugins (including jquery.tmpl) store data using jQuery's equivalent of domData
148.605 + // so notify it to tear down any resources associated with the node & descendants here.
148.606 + if ((typeof jQuery == "function") && (typeof jQuery['cleanData'] == "function"))
148.607 + jQuery['cleanData']([node]);
148.608 +
148.609 + // Also clear any immediate-child comment nodes, as these wouldn't have been found by
148.610 + // node.getElementsByTagName("*") in cleanNode() (comment nodes aren't elements)
148.611 + if (cleanableNodeTypesWithDescendants[node.nodeType])
148.612 + cleanImmediateCommentTypeChildren(node);
148.613 + }
148.614 +
148.615 + function cleanImmediateCommentTypeChildren(nodeWithChildren) {
148.616 + var child, nextChild = nodeWithChildren.firstChild;
148.617 + while (child = nextChild) {
148.618 + nextChild = child.nextSibling;
148.619 + if (child.nodeType === 8)
148.620 + cleanSingleNode(child);
148.621 + }
148.622 + }
148.623 +
148.624 + return {
148.625 + addDisposeCallback : function(node, callback) {
148.626 + if (typeof callback != "function")
148.627 + throw new Error("Callback must be a function");
148.628 + getDisposeCallbacksCollection(node, true).push(callback);
148.629 + },
148.630 +
148.631 + removeDisposeCallback : function(node, callback) {
148.632 + var callbacksCollection = getDisposeCallbacksCollection(node, false);
148.633 + if (callbacksCollection) {
148.634 + ko.utils.arrayRemoveItem(callbacksCollection, callback);
148.635 + if (callbacksCollection.length == 0)
148.636 + destroyCallbacksCollection(node);
148.637 + }
148.638 + },
148.639 +
148.640 + cleanNode : function(node) {
148.641 + // First clean this node, where applicable
148.642 + if (cleanableNodeTypes[node.nodeType]) {
148.643 + cleanSingleNode(node);
148.644 +
148.645 + // ... then its descendants, where applicable
148.646 + if (cleanableNodeTypesWithDescendants[node.nodeType]) {
148.647 + // Clone the descendants list in case it changes during iteration
148.648 + var descendants = [];
148.649 + ko.utils.arrayPushAll(descendants, node.getElementsByTagName("*"));
148.650 + for (var i = 0, j = descendants.length; i < j; i++)
148.651 + cleanSingleNode(descendants[i]);
148.652 + }
148.653 + }
148.654 + return node;
148.655 + },
148.656 +
148.657 + removeNode : function(node) {
148.658 + ko.cleanNode(node);
148.659 + if (node.parentNode)
148.660 + node.parentNode.removeChild(node);
148.661 + }
148.662 + }
148.663 +})();
148.664 +ko.cleanNode = ko.utils.domNodeDisposal.cleanNode; // Shorthand name for convenience
148.665 +ko.removeNode = ko.utils.domNodeDisposal.removeNode; // Shorthand name for convenience
148.666 +ko.exportSymbol('cleanNode', ko.cleanNode);
148.667 +ko.exportSymbol('removeNode', ko.removeNode);
148.668 +ko.exportSymbol('utils.domNodeDisposal', ko.utils.domNodeDisposal);
148.669 +ko.exportSymbol('utils.domNodeDisposal.addDisposeCallback', ko.utils.domNodeDisposal.addDisposeCallback);
148.670 +ko.exportSymbol('utils.domNodeDisposal.removeDisposeCallback', ko.utils.domNodeDisposal.removeDisposeCallback);
148.671 +(function () {
148.672 + var leadingCommentRegex = /^(\s*)<!--(.*?)-->/;
148.673 +
148.674 + function simpleHtmlParse(html) {
148.675 + // Based on jQuery's "clean" function, but only accounting for table-related elements.
148.676 + // If you have referenced jQuery, this won't be used anyway - KO will use jQuery's "clean" function directly
148.677 +
148.678 + // Note that there's still an issue in IE < 9 whereby it will discard comment nodes that are the first child of
148.679 + // a descendant node. For example: "<div><!-- mycomment -->abc</div>" will get parsed as "<div>abc</div>"
148.680 + // This won't affect anyone who has referenced jQuery, and there's always the workaround of inserting a dummy node
148.681 + // (possibly a text node) in front of the comment. So, KO does not attempt to workaround this IE issue automatically at present.
148.682 +
148.683 + // Trim whitespace, otherwise indexOf won't work as expected
148.684 + var tags = ko.utils.stringTrim(html).toLowerCase(), div = document.createElement("div");
148.685 +
148.686 + // Finds the first match from the left column, and returns the corresponding "wrap" data from the right column
148.687 + var wrap = tags.match(/^<(thead|tbody|tfoot)/) && [1, "<table>", "</table>"] ||
148.688 + !tags.indexOf("<tr") && [2, "<table><tbody>", "</tbody></table>"] ||
148.689 + (!tags.indexOf("<td") || !tags.indexOf("<th")) && [3, "<table><tbody><tr>", "</tr></tbody></table>"] ||
148.690 + /* anything else */ [0, "", ""];
148.691 +
148.692 + // Go to html and back, then peel off extra wrappers
148.693 + // Note that we always prefix with some dummy text, because otherwise, IE<9 will strip out leading comment nodes in descendants. Total madness.
148.694 + var markup = "ignored<div>" + wrap[1] + html + wrap[2] + "</div>";
148.695 + if (typeof window['innerShiv'] == "function") {
148.696 + div.appendChild(window['innerShiv'](markup));
148.697 + } else {
148.698 + div.innerHTML = markup;
148.699 + }
148.700 +
148.701 + // Move to the right depth
148.702 + while (wrap[0]--)
148.703 + div = div.lastChild;
148.704 +
148.705 + return ko.utils.makeArray(div.lastChild.childNodes);
148.706 + }
148.707 +
148.708 + function jQueryHtmlParse(html) {
148.709 + // jQuery's "parseHTML" function was introduced in jQuery 1.8.0 and is a documented public API.
148.710 + if (jQuery['parseHTML']) {
148.711 + return jQuery['parseHTML'](html);
148.712 + } else {
148.713 + // For jQuery < 1.8.0, we fall back on the undocumented internal "clean" function.
148.714 + var elems = jQuery['clean']([html]);
148.715 +
148.716 + // As of jQuery 1.7.1, jQuery parses the HTML by appending it to some dummy parent nodes held in an in-memory document fragment.
148.717 + // Unfortunately, it never clears the dummy parent nodes from the document fragment, so it leaks memory over time.
148.718 + // Fix this by finding the top-most dummy parent element, and detaching it from its owner fragment.
148.719 + if (elems && elems[0]) {
148.720 + // Find the top-most parent element that's a direct child of a document fragment
148.721 + var elem = elems[0];
148.722 + while (elem.parentNode && elem.parentNode.nodeType !== 11 /* i.e., DocumentFragment */)
148.723 + elem = elem.parentNode;
148.724 + // ... then detach it
148.725 + if (elem.parentNode)
148.726 + elem.parentNode.removeChild(elem);
148.727 + }
148.728 +
148.729 + return elems;
148.730 + }
148.731 + }
148.732 +
148.733 + ko.utils.parseHtmlFragment = function(html) {
148.734 + return typeof jQuery != 'undefined' ? jQueryHtmlParse(html) // As below, benefit from jQuery's optimisations where possible
148.735 + : simpleHtmlParse(html); // ... otherwise, this simple logic will do in most common cases.
148.736 + };
148.737 +
148.738 + ko.utils.setHtml = function(node, html) {
148.739 + ko.utils.emptyDomNode(node);
148.740 +
148.741 + // There's no legitimate reason to display a stringified observable without unwrapping it, so we'll unwrap it
148.742 + html = ko.utils.unwrapObservable(html);
148.743 +
148.744 + if ((html !== null) && (html !== undefined)) {
148.745 + if (typeof html != 'string')
148.746 + html = html.toString();
148.747 +
148.748 + // jQuery contains a lot of sophisticated code to parse arbitrary HTML fragments,
148.749 + // for example <tr> elements which are not normally allowed to exist on their own.
148.750 + // If you've referenced jQuery we'll use that rather than duplicating its code.
148.751 + if (typeof jQuery != 'undefined') {
148.752 + jQuery(node)['html'](html);
148.753 + } else {
148.754 + // ... otherwise, use KO's own parsing logic.
148.755 + var parsedNodes = ko.utils.parseHtmlFragment(html);
148.756 + for (var i = 0; i < parsedNodes.length; i++)
148.757 + node.appendChild(parsedNodes[i]);
148.758 + }
148.759 + }
148.760 + };
148.761 +})();
148.762 +
148.763 +ko.exportSymbol('utils.parseHtmlFragment', ko.utils.parseHtmlFragment);
148.764 +ko.exportSymbol('utils.setHtml', ko.utils.setHtml);
148.765 +
148.766 +ko.memoization = (function () {
148.767 + var memos = {};
148.768 +
148.769 + function randomMax8HexChars() {
148.770 + return (((1 + Math.random()) * 0x100000000) | 0).toString(16).substring(1);
148.771 + }
148.772 + function generateRandomId() {
148.773 + return randomMax8HexChars() + randomMax8HexChars();
148.774 + }
148.775 + function findMemoNodes(rootNode, appendToArray) {
148.776 + if (!rootNode)
148.777 + return;
148.778 + if (rootNode.nodeType == 8) {
148.779 + var memoId = ko.memoization.parseMemoText(rootNode.nodeValue);
148.780 + if (memoId != null)
148.781 + appendToArray.push({ domNode: rootNode, memoId: memoId });
148.782 + } else if (rootNode.nodeType == 1) {
148.783 + for (var i = 0, childNodes = rootNode.childNodes, j = childNodes.length; i < j; i++)
148.784 + findMemoNodes(childNodes[i], appendToArray);
148.785 + }
148.786 + }
148.787 +
148.788 + return {
148.789 + memoize: function (callback) {
148.790 + if (typeof callback != "function")
148.791 + throw new Error("You can only pass a function to ko.memoization.memoize()");
148.792 + var memoId = generateRandomId();
148.793 + memos[memoId] = callback;
148.794 + return "<!--[ko_memo:" + memoId + "]-->";
148.795 + },
148.796 +
148.797 + unmemoize: function (memoId, callbackParams) {
148.798 + var callback = memos[memoId];
148.799 + if (callback === undefined)
148.800 + throw new Error("Couldn't find any memo with ID " + memoId + ". Perhaps it's already been unmemoized.");
148.801 + try {
148.802 + callback.apply(null, callbackParams || []);
148.803 + return true;
148.804 + }
148.805 + finally { delete memos[memoId]; }
148.806 + },
148.807 +
148.808 + unmemoizeDomNodeAndDescendants: function (domNode, extraCallbackParamsArray) {
148.809 + var memos = [];
148.810 + findMemoNodes(domNode, memos);
148.811 + for (var i = 0, j = memos.length; i < j; i++) {
148.812 + var node = memos[i].domNode;
148.813 + var combinedParams = [node];
148.814 + if (extraCallbackParamsArray)
148.815 + ko.utils.arrayPushAll(combinedParams, extraCallbackParamsArray);
148.816 + ko.memoization.unmemoize(memos[i].memoId, combinedParams);
148.817 + node.nodeValue = ""; // Neuter this node so we don't try to unmemoize it again
148.818 + if (node.parentNode)
148.819 + node.parentNode.removeChild(node); // If possible, erase it totally (not always possible - someone else might just hold a reference to it then call unmemoizeDomNodeAndDescendants again)
148.820 + }
148.821 + },
148.822 +
148.823 + parseMemoText: function (memoText) {
148.824 + var match = memoText.match(/^\[ko_memo\:(.*?)\]$/);
148.825 + return match ? match[1] : null;
148.826 + }
148.827 + };
148.828 +})();
148.829 +
148.830 +ko.exportSymbol('memoization', ko.memoization);
148.831 +ko.exportSymbol('memoization.memoize', ko.memoization.memoize);
148.832 +ko.exportSymbol('memoization.unmemoize', ko.memoization.unmemoize);
148.833 +ko.exportSymbol('memoization.parseMemoText', ko.memoization.parseMemoText);
148.834 +ko.exportSymbol('memoization.unmemoizeDomNodeAndDescendants', ko.memoization.unmemoizeDomNodeAndDescendants);
148.835 +ko.extenders = {
148.836 + 'throttle': function(target, timeout) {
148.837 + // Throttling means two things:
148.838 +
148.839 + // (1) For dependent observables, we throttle *evaluations* so that, no matter how fast its dependencies
148.840 + // notify updates, the target doesn't re-evaluate (and hence doesn't notify) faster than a certain rate
148.841 + target['throttleEvaluation'] = timeout;
148.842 +
148.843 + // (2) For writable targets (observables, or writable dependent observables), we throttle *writes*
148.844 + // so the target cannot change value synchronously or faster than a certain rate
148.845 + var writeTimeoutInstance = null;
148.846 + return ko.dependentObservable({
148.847 + 'read': target,
148.848 + 'write': function(value) {
148.849 + clearTimeout(writeTimeoutInstance);
148.850 + writeTimeoutInstance = setTimeout(function() {
148.851 + target(value);
148.852 + }, timeout);
148.853 + }
148.854 + });
148.855 + },
148.856 +
148.857 + 'notify': function(target, notifyWhen) {
148.858 + target["equalityComparer"] = notifyWhen == "always"
148.859 + ? function() { return false } // Treat all values as not equal
148.860 + : ko.observable["fn"]["equalityComparer"];
148.861 + return target;
148.862 + }
148.863 +};
148.864 +
148.865 +function applyExtenders(requestedExtenders) {
148.866 + var target = this;
148.867 + if (requestedExtenders) {
148.868 + for (var key in requestedExtenders) {
148.869 + var extenderHandler = ko.extenders[key];
148.870 + if (typeof extenderHandler == 'function') {
148.871 + target = extenderHandler(target, requestedExtenders[key]);
148.872 + }
148.873 + }
148.874 + }
148.875 + return target;
148.876 +}
148.877 +
148.878 +ko.exportSymbol('extenders', ko.extenders);
148.879 +
148.880 +ko.subscription = function (target, callback, disposeCallback) {
148.881 + this.target = target;
148.882 + this.callback = callback;
148.883 + this.disposeCallback = disposeCallback;
148.884 + ko.exportProperty(this, 'dispose', this.dispose);
148.885 +};
148.886 +ko.subscription.prototype.dispose = function () {
148.887 + this.isDisposed = true;
148.888 + this.disposeCallback();
148.889 +};
148.890 +
148.891 +ko.subscribable = function () {
148.892 + this._subscriptions = {};
148.893 +
148.894 + ko.utils.extend(this, ko.subscribable['fn']);
148.895 + ko.exportProperty(this, 'subscribe', this.subscribe);
148.896 + ko.exportProperty(this, 'extend', this.extend);
148.897 + ko.exportProperty(this, 'getSubscriptionsCount', this.getSubscriptionsCount);
148.898 +}
148.899 +
148.900 +var defaultEvent = "change";
148.901 +
148.902 +ko.subscribable['fn'] = {
148.903 + subscribe: function (callback, callbackTarget, event) {
148.904 + event = event || defaultEvent;
148.905 + var boundCallback = callbackTarget ? callback.bind(callbackTarget) : callback;
148.906 +
148.907 + var subscription = new ko.subscription(this, boundCallback, function () {
148.908 + ko.utils.arrayRemoveItem(this._subscriptions[event], subscription);
148.909 + }.bind(this));
148.910 +
148.911 + if (!this._subscriptions[event])
148.912 + this._subscriptions[event] = [];
148.913 + this._subscriptions[event].push(subscription);
148.914 + return subscription;
148.915 + },
148.916 +
148.917 + "notifySubscribers": function (valueToNotify, event) {
148.918 + event = event || defaultEvent;
148.919 + if (this._subscriptions[event]) {
148.920 + ko.dependencyDetection.ignore(function() {
148.921 + ko.utils.arrayForEach(this._subscriptions[event].slice(0), function (subscription) {
148.922 + // In case a subscription was disposed during the arrayForEach cycle, check
148.923 + // for isDisposed on each subscription before invoking its callback
148.924 + if (subscription && (subscription.isDisposed !== true))
148.925 + subscription.callback(valueToNotify);
148.926 + });
148.927 + }, this);
148.928 + }
148.929 + },
148.930 +
148.931 + getSubscriptionsCount: function () {
148.932 + var total = 0;
148.933 + for (var eventName in this._subscriptions) {
148.934 + if (this._subscriptions.hasOwnProperty(eventName))
148.935 + total += this._subscriptions[eventName].length;
148.936 + }
148.937 + return total;
148.938 + },
148.939 +
148.940 + extend: applyExtenders
148.941 +};
148.942 +
148.943 +
148.944 +ko.isSubscribable = function (instance) {
148.945 + return typeof instance.subscribe == "function" && typeof instance["notifySubscribers"] == "function";
148.946 +};
148.947 +
148.948 +ko.exportSymbol('subscribable', ko.subscribable);
148.949 +ko.exportSymbol('isSubscribable', ko.isSubscribable);
148.950 +
148.951 +ko.dependencyDetection = (function () {
148.952 + var _frames = [];
148.953 +
148.954 + return {
148.955 + begin: function (callback) {
148.956 + _frames.push({ callback: callback, distinctDependencies:[] });
148.957 + },
148.958 +
148.959 + end: function () {
148.960 + _frames.pop();
148.961 + },
148.962 +
148.963 + registerDependency: function (subscribable) {
148.964 + if (!ko.isSubscribable(subscribable))
148.965 + throw new Error("Only subscribable things can act as dependencies");
148.966 + if (_frames.length > 0) {
148.967 + var topFrame = _frames[_frames.length - 1];
148.968 + if (!topFrame || ko.utils.arrayIndexOf(topFrame.distinctDependencies, subscribable) >= 0)
148.969 + return;
148.970 + topFrame.distinctDependencies.push(subscribable);
148.971 + topFrame.callback(subscribable);
148.972 + }
148.973 + },
148.974 +
148.975 + ignore: function(callback, callbackTarget, callbackArgs) {
148.976 + try {
148.977 + _frames.push(null);
148.978 + return callback.apply(callbackTarget, callbackArgs || []);
148.979 + } finally {
148.980 + _frames.pop();
148.981 + }
148.982 + }
148.983 + };
148.984 +})();
148.985 +var primitiveTypes = { 'undefined':true, 'boolean':true, 'number':true, 'string':true };
148.986 +
148.987 +ko.observable = function (initialValue) {
148.988 + var _latestValue = initialValue;
148.989 +
148.990 + function observable() {
148.991 + if (arguments.length > 0) {
148.992 + // Write
148.993 +
148.994 + // Ignore writes if the value hasn't changed
148.995 + if ((!observable['equalityComparer']) || !observable['equalityComparer'](_latestValue, arguments[0])) {
148.996 + observable.valueWillMutate();
148.997 + _latestValue = arguments[0];
148.998 + if (DEBUG) observable._latestValue = _latestValue;
148.999 + observable.valueHasMutated();
148.1000 + }
148.1001 + return this; // Permits chained assignments
148.1002 + }
148.1003 + else {
148.1004 + // Read
148.1005 + ko.dependencyDetection.registerDependency(observable); // The caller only needs to be notified of changes if they did a "read" operation
148.1006 + return _latestValue;
148.1007 + }
148.1008 + }
148.1009 + if (DEBUG) observable._latestValue = _latestValue;
148.1010 + ko.subscribable.call(observable);
148.1011 + observable.peek = function() { return _latestValue };
148.1012 + observable.valueHasMutated = function () { observable["notifySubscribers"](_latestValue); }
148.1013 + observable.valueWillMutate = function () { observable["notifySubscribers"](_latestValue, "beforeChange"); }
148.1014 + ko.utils.extend(observable, ko.observable['fn']);
148.1015 +
148.1016 + ko.exportProperty(observable, 'peek', observable.peek);
148.1017 + ko.exportProperty(observable, "valueHasMutated", observable.valueHasMutated);
148.1018 + ko.exportProperty(observable, "valueWillMutate", observable.valueWillMutate);
148.1019 +
148.1020 + return observable;
148.1021 +}
148.1022 +
148.1023 +ko.observable['fn'] = {
148.1024 + "equalityComparer": function valuesArePrimitiveAndEqual(a, b) {
148.1025 + var oldValueIsPrimitive = (a === null) || (typeof(a) in primitiveTypes);
148.1026 + return oldValueIsPrimitive ? (a === b) : false;
148.1027 + }
148.1028 +};
148.1029 +
148.1030 +var protoProperty = ko.observable.protoProperty = "__ko_proto__";
148.1031 +ko.observable['fn'][protoProperty] = ko.observable;
148.1032 +
148.1033 +ko.hasPrototype = function(instance, prototype) {
148.1034 + if ((instance === null) || (instance === undefined) || (instance[protoProperty] === undefined)) return false;
148.1035 + if (instance[protoProperty] === prototype) return true;
148.1036 + return ko.hasPrototype(instance[protoProperty], prototype); // Walk the prototype chain
148.1037 +};
148.1038 +
148.1039 +ko.isObservable = function (instance) {
148.1040 + return ko.hasPrototype(instance, ko.observable);
148.1041 +}
148.1042 +ko.isWriteableObservable = function (instance) {
148.1043 + // Observable
148.1044 + if ((typeof instance == "function") && instance[protoProperty] === ko.observable)
148.1045 + return true;
148.1046 + // Writeable dependent observable
148.1047 + if ((typeof instance == "function") && (instance[protoProperty] === ko.dependentObservable) && (instance.hasWriteFunction))
148.1048 + return true;
148.1049 + // Anything else
148.1050 + return false;
148.1051 +}
148.1052 +
148.1053 +
148.1054 +ko.exportSymbol('observable', ko.observable);
148.1055 +ko.exportSymbol('isObservable', ko.isObservable);
148.1056 +ko.exportSymbol('isWriteableObservable', ko.isWriteableObservable);
148.1057 +ko.observableArray = function (initialValues) {
148.1058 + if (arguments.length == 0) {
148.1059 + // Zero-parameter constructor initializes to empty array
148.1060 + initialValues = [];
148.1061 + }
148.1062 + if ((initialValues !== null) && (initialValues !== undefined) && !('length' in initialValues))
148.1063 + throw new Error("The argument passed when initializing an observable array must be an array, or null, or undefined.");
148.1064 +
148.1065 + var result = ko.observable(initialValues);
148.1066 + ko.utils.extend(result, ko.observableArray['fn']);
148.1067 + return result;
148.1068 +}
148.1069 +
148.1070 +ko.observableArray['fn'] = {
148.1071 + 'remove': function (valueOrPredicate) {
148.1072 + var underlyingArray = this.peek();
148.1073 + var removedValues = [];
148.1074 + var predicate = typeof valueOrPredicate == "function" ? valueOrPredicate : function (value) { return value === valueOrPredicate; };
148.1075 + for (var i = 0; i < underlyingArray.length; i++) {
148.1076 + var value = underlyingArray[i];
148.1077 + if (predicate(value)) {
148.1078 + if (removedValues.length === 0) {
148.1079 + this.valueWillMutate();
148.1080 + }
148.1081 + removedValues.push(value);
148.1082 + underlyingArray.splice(i, 1);
148.1083 + i--;
148.1084 + }
148.1085 + }
148.1086 + if (removedValues.length) {
148.1087 + this.valueHasMutated();
148.1088 + }
148.1089 + return removedValues;
148.1090 + },
148.1091 +
148.1092 + 'removeAll': function (arrayOfValues) {
148.1093 + // If you passed zero args, we remove everything
148.1094 + if (arrayOfValues === undefined) {
148.1095 + var underlyingArray = this.peek();
148.1096 + var allValues = underlyingArray.slice(0);
148.1097 + this.valueWillMutate();
148.1098 + underlyingArray.splice(0, underlyingArray.length);
148.1099 + this.valueHasMutated();
148.1100 + return allValues;
148.1101 + }
148.1102 + // If you passed an arg, we interpret it as an array of entries to remove
148.1103 + if (!arrayOfValues)
148.1104 + return [];
148.1105 + return this['remove'](function (value) {
148.1106 + return ko.utils.arrayIndexOf(arrayOfValues, value) >= 0;
148.1107 + });
148.1108 + },
148.1109 +
148.1110 + 'destroy': function (valueOrPredicate) {
148.1111 + var underlyingArray = this.peek();
148.1112 + var predicate = typeof valueOrPredicate == "function" ? valueOrPredicate : function (value) { return value === valueOrPredicate; };
148.1113 + this.valueWillMutate();
148.1114 + for (var i = underlyingArray.length - 1; i >= 0; i--) {
148.1115 + var value = underlyingArray[i];
148.1116 + if (predicate(value))
148.1117 + underlyingArray[i]["_destroy"] = true;
148.1118 + }
148.1119 + this.valueHasMutated();
148.1120 + },
148.1121 +
148.1122 + 'destroyAll': function (arrayOfValues) {
148.1123 + // If you passed zero args, we destroy everything
148.1124 + if (arrayOfValues === undefined)
148.1125 + return this['destroy'](function() { return true });
148.1126 +
148.1127 + // If you passed an arg, we interpret it as an array of entries to destroy
148.1128 + if (!arrayOfValues)
148.1129 + return [];
148.1130 + return this['destroy'](function (value) {
148.1131 + return ko.utils.arrayIndexOf(arrayOfValues, value) >= 0;
148.1132 + });
148.1133 + },
148.1134 +
148.1135 + 'indexOf': function (item) {
148.1136 + var underlyingArray = this();
148.1137 + return ko.utils.arrayIndexOf(underlyingArray, item);
148.1138 + },
148.1139 +
148.1140 + 'replace': function(oldItem, newItem) {
148.1141 + var index = this['indexOf'](oldItem);
148.1142 + if (index >= 0) {
148.1143 + this.valueWillMutate();
148.1144 + this.peek()[index] = newItem;
148.1145 + this.valueHasMutated();
148.1146 + }
148.1147 + }
148.1148 +}
148.1149 +
148.1150 +// Populate ko.observableArray.fn with read/write functions from native arrays
148.1151 +// Important: Do not add any additional functions here that may reasonably be used to *read* data from the array
148.1152 +// because we'll eval them without causing subscriptions, so ko.computed output could end up getting stale
148.1153 +ko.utils.arrayForEach(["pop", "push", "reverse", "shift", "sort", "splice", "unshift"], function (methodName) {
148.1154 + ko.observableArray['fn'][methodName] = function () {
148.1155 + // Use "peek" to avoid creating a subscription in any computed that we're executing in the context of
148.1156 + // (for consistency with mutating regular observables)
148.1157 + var underlyingArray = this.peek();
148.1158 + this.valueWillMutate();
148.1159 + var methodCallResult = underlyingArray[methodName].apply(underlyingArray, arguments);
148.1160 + this.valueHasMutated();
148.1161 + return methodCallResult;
148.1162 + };
148.1163 +});
148.1164 +
148.1165 +// Populate ko.observableArray.fn with read-only functions from native arrays
148.1166 +ko.utils.arrayForEach(["slice"], function (methodName) {
148.1167 + ko.observableArray['fn'][methodName] = function () {
148.1168 + var underlyingArray = this();
148.1169 + return underlyingArray[methodName].apply(underlyingArray, arguments);
148.1170 + };
148.1171 +});
148.1172 +
148.1173 +ko.exportSymbol('observableArray', ko.observableArray);
148.1174 +ko.dependentObservable = function (evaluatorFunctionOrOptions, evaluatorFunctionTarget, options) {
148.1175 + var _latestValue,
148.1176 + _hasBeenEvaluated = false,
148.1177 + _isBeingEvaluated = false,
148.1178 + readFunction = evaluatorFunctionOrOptions;
148.1179 +
148.1180 + if (readFunction && typeof readFunction == "object") {
148.1181 + // Single-parameter syntax - everything is on this "options" param
148.1182 + options = readFunction;
148.1183 + readFunction = options["read"];
148.1184 + } else {
148.1185 + // Multi-parameter syntax - construct the options according to the params passed
148.1186 + options = options || {};
148.1187 + if (!readFunction)
148.1188 + readFunction = options["read"];
148.1189 + }
148.1190 + if (typeof readFunction != "function")
148.1191 + throw new Error("Pass a function that returns the value of the ko.computed");
148.1192 +
148.1193 + function addSubscriptionToDependency(subscribable) {
148.1194 + _subscriptionsToDependencies.push(subscribable.subscribe(evaluatePossiblyAsync));
148.1195 + }
148.1196 +
148.1197 + function disposeAllSubscriptionsToDependencies() {
148.1198 + ko.utils.arrayForEach(_subscriptionsToDependencies, function (subscription) {
148.1199 + subscription.dispose();
148.1200 + });
148.1201 + _subscriptionsToDependencies = [];
148.1202 + }
148.1203 +
148.1204 + function evaluatePossiblyAsync() {
148.1205 + var throttleEvaluationTimeout = dependentObservable['throttleEvaluation'];
148.1206 + if (throttleEvaluationTimeout && throttleEvaluationTimeout >= 0) {
148.1207 + clearTimeout(evaluationTimeoutInstance);
148.1208 + evaluationTimeoutInstance = setTimeout(evaluateImmediate, throttleEvaluationTimeout);
148.1209 + } else
148.1210 + evaluateImmediate();
148.1211 + }
148.1212 +
148.1213 + function evaluateImmediate() {
148.1214 + if (_isBeingEvaluated) {
148.1215 + // If the evaluation of a ko.computed causes side effects, it's possible that it will trigger its own re-evaluation.
148.1216 + // This is not desirable (it's hard for a developer to realise a chain of dependencies might cause this, and they almost
148.1217 + // certainly didn't intend infinite re-evaluations). So, for predictability, we simply prevent ko.computeds from causing
148.1218 + // their own re-evaluation. Further discussion at https://github.com/SteveSanderson/knockout/pull/387
148.1219 + return;
148.1220 + }
148.1221 +
148.1222 + // Don't dispose on first evaluation, because the "disposeWhen" callback might
148.1223 + // e.g., dispose when the associated DOM element isn't in the doc, and it's not
148.1224 + // going to be in the doc until *after* the first evaluation
148.1225 + if (_hasBeenEvaluated && disposeWhen()) {
148.1226 + dispose();
148.1227 + return;
148.1228 + }
148.1229 +
148.1230 + _isBeingEvaluated = true;
148.1231 + try {
148.1232 + // Initially, we assume that none of the subscriptions are still being used (i.e., all are candidates for disposal).
148.1233 + // Then, during evaluation, we cross off any that are in fact still being used.
148.1234 + var disposalCandidates = ko.utils.arrayMap(_subscriptionsToDependencies, function(item) {return item.target;});
148.1235 +
148.1236 + ko.dependencyDetection.begin(function(subscribable) {
148.1237 + var inOld;
148.1238 + if ((inOld = ko.utils.arrayIndexOf(disposalCandidates, subscribable)) >= 0)
148.1239 + disposalCandidates[inOld] = undefined; // Don't want to dispose this subscription, as it's still being used
148.1240 + else
148.1241 + addSubscriptionToDependency(subscribable); // Brand new subscription - add it
148.1242 + });
148.1243 +
148.1244 + var newValue = readFunction.call(evaluatorFunctionTarget);
148.1245 +
148.1246 + // For each subscription no longer being used, remove it from the active subscriptions list and dispose it
148.1247 + for (var i = disposalCandidates.length - 1; i >= 0; i--) {
148.1248 + if (disposalCandidates[i])
148.1249 + _subscriptionsToDependencies.splice(i, 1)[0].dispose();
148.1250 + }
148.1251 + _hasBeenEvaluated = true;
148.1252 +
148.1253 + dependentObservable["notifySubscribers"](_latestValue, "beforeChange");
148.1254 + _latestValue = newValue;
148.1255 + if (DEBUG) dependentObservable._latestValue = _latestValue;
148.1256 + } finally {
148.1257 + ko.dependencyDetection.end();
148.1258 + }
148.1259 +
148.1260 + dependentObservable["notifySubscribers"](_latestValue);
148.1261 + _isBeingEvaluated = false;
148.1262 + if (!_subscriptionsToDependencies.length)
148.1263 + dispose();
148.1264 + }
148.1265 +
148.1266 + function dependentObservable() {
148.1267 + if (arguments.length > 0) {
148.1268 + if (typeof writeFunction === "function") {
148.1269 + // Writing a value
148.1270 + writeFunction.apply(evaluatorFunctionTarget, arguments);
148.1271 + } else {
148.1272 + throw new Error("Cannot write a value to a ko.computed unless you specify a 'write' option. If you wish to read the current value, don't pass any parameters.");
148.1273 + }
148.1274 + return this; // Permits chained assignments
148.1275 + } else {
148.1276 + // Reading the value
148.1277 + if (!_hasBeenEvaluated)
148.1278 + evaluateImmediate();
148.1279 + ko.dependencyDetection.registerDependency(dependentObservable);
148.1280 + return _latestValue;
148.1281 + }
148.1282 + }
148.1283 +
148.1284 + function peek() {
148.1285 + if (!_hasBeenEvaluated)
148.1286 + evaluateImmediate();
148.1287 + return _latestValue;
148.1288 + }
148.1289 +
148.1290 + function isActive() {
148.1291 + return !_hasBeenEvaluated || _subscriptionsToDependencies.length > 0;
148.1292 + }
148.1293 +
148.1294 + // By here, "options" is always non-null
148.1295 + var writeFunction = options["write"],
148.1296 + disposeWhenNodeIsRemoved = options["disposeWhenNodeIsRemoved"] || options.disposeWhenNodeIsRemoved || null,
148.1297 + disposeWhen = options["disposeWhen"] || options.disposeWhen || function() { return false; },
148.1298 + dispose = disposeAllSubscriptionsToDependencies,
148.1299 + _subscriptionsToDependencies = [],
148.1300 + evaluationTimeoutInstance = null;
148.1301 +
148.1302 + if (!evaluatorFunctionTarget)
148.1303 + evaluatorFunctionTarget = options["owner"];
148.1304 +
148.1305 + dependentObservable.peek = peek;
148.1306 + dependentObservable.getDependenciesCount = function () { return _subscriptionsToDependencies.length; };
148.1307 + dependentObservable.hasWriteFunction = typeof options["write"] === "function";
148.1308 + dependentObservable.dispose = function () { dispose(); };
148.1309 + dependentObservable.isActive = isActive;
148.1310 + dependentObservable.valueHasMutated = function() {
148.1311 + _hasBeenEvaluated = false;
148.1312 + evaluateImmediate();
148.1313 + };
148.1314 +
148.1315 + ko.subscribable.call(dependentObservable);
148.1316 + ko.utils.extend(dependentObservable, ko.dependentObservable['fn']);
148.1317 +
148.1318 + ko.exportProperty(dependentObservable, 'peek', dependentObservable.peek);
148.1319 + ko.exportProperty(dependentObservable, 'dispose', dependentObservable.dispose);
148.1320 + ko.exportProperty(dependentObservable, 'isActive', dependentObservable.isActive);
148.1321 + ko.exportProperty(dependentObservable, 'getDependenciesCount', dependentObservable.getDependenciesCount);
148.1322 +
148.1323 + // Evaluate, unless deferEvaluation is true
148.1324 + if (options['deferEvaluation'] !== true)
148.1325 + evaluateImmediate();
148.1326 +
148.1327 + // Build "disposeWhenNodeIsRemoved" and "disposeWhenNodeIsRemovedCallback" option values.
148.1328 + // But skip if isActive is false (there will never be any dependencies to dispose).
148.1329 + // (Note: "disposeWhenNodeIsRemoved" option both proactively disposes as soon as the node is removed using ko.removeNode(),
148.1330 + // plus adds a "disposeWhen" callback that, on each evaluation, disposes if the node was removed by some other means.)
148.1331 + if (disposeWhenNodeIsRemoved && isActive()) {
148.1332 + dispose = function() {
148.1333 + ko.utils.domNodeDisposal.removeDisposeCallback(disposeWhenNodeIsRemoved, arguments.callee);
148.1334 + disposeAllSubscriptionsToDependencies();
148.1335 + };
148.1336 + ko.utils.domNodeDisposal.addDisposeCallback(disposeWhenNodeIsRemoved, dispose);
148.1337 + var existingDisposeWhenFunction = disposeWhen;
148.1338 + disposeWhen = function () {
148.1339 + return !ko.utils.domNodeIsAttachedToDocument(disposeWhenNodeIsRemoved) || existingDisposeWhenFunction();
148.1340 + }
148.1341 + }
148.1342 +
148.1343 + return dependentObservable;
148.1344 +};
148.1345 +
148.1346 +ko.isComputed = function(instance) {
148.1347 + return ko.hasPrototype(instance, ko.dependentObservable);
148.1348 +};
148.1349 +
148.1350 +var protoProp = ko.observable.protoProperty; // == "__ko_proto__"
148.1351 +ko.dependentObservable[protoProp] = ko.observable;
148.1352 +
148.1353 +ko.dependentObservable['fn'] = {};
148.1354 +ko.dependentObservable['fn'][protoProp] = ko.dependentObservable;
148.1355 +
148.1356 +ko.exportSymbol('dependentObservable', ko.dependentObservable);
148.1357 +ko.exportSymbol('computed', ko.dependentObservable); // Make "ko.computed" an alias for "ko.dependentObservable"
148.1358 +ko.exportSymbol('isComputed', ko.isComputed);
148.1359 +
148.1360 +(function() {
148.1361 + var maxNestedObservableDepth = 10; // Escape the (unlikely) pathalogical case where an observable's current value is itself (or similar reference cycle)
148.1362 +
148.1363 + ko.toJS = function(rootObject) {
148.1364 + if (arguments.length == 0)
148.1365 + throw new Error("When calling ko.toJS, pass the object you want to convert.");
148.1366 +
148.1367 + // We just unwrap everything at every level in the object graph
148.1368 + return mapJsObjectGraph(rootObject, function(valueToMap) {
148.1369 + // Loop because an observable's value might in turn be another observable wrapper
148.1370 + for (var i = 0; ko.isObservable(valueToMap) && (i < maxNestedObservableDepth); i++)
148.1371 + valueToMap = valueToMap();
148.1372 + return valueToMap;
148.1373 + });
148.1374 + };
148.1375 +
148.1376 + ko.toJSON = function(rootObject, replacer, space) { // replacer and space are optional
148.1377 + var plainJavaScriptObject = ko.toJS(rootObject);
148.1378 + return ko.utils.stringifyJson(plainJavaScriptObject, replacer, space);
148.1379 + };
148.1380 +
148.1381 + function mapJsObjectGraph(rootObject, mapInputCallback, visitedObjects) {
148.1382 + visitedObjects = visitedObjects || new objectLookup();
148.1383 +
148.1384 + rootObject = mapInputCallback(rootObject);
148.1385 + var canHaveProperties = (typeof rootObject == "object") && (rootObject !== null) && (rootObject !== undefined) && (!(rootObject instanceof Date));
148.1386 + if (!canHaveProperties)
148.1387 + return rootObject;
148.1388 +
148.1389 + var outputProperties = rootObject instanceof Array ? [] : {};
148.1390 + visitedObjects.save(rootObject, outputProperties);
148.1391 +
148.1392 + visitPropertiesOrArrayEntries(rootObject, function(indexer) {
148.1393 + var propertyValue = mapInputCallback(rootObject[indexer]);
148.1394 +
148.1395 + switch (typeof propertyValue) {
148.1396 + case "boolean":
148.1397 + case "number":
148.1398 + case "string":
148.1399 + case "function":
148.1400 + outputProperties[indexer] = propertyValue;
148.1401 + break;
148.1402 + case "object":
148.1403 + case "undefined":
148.1404 + var previouslyMappedValue = visitedObjects.get(propertyValue);
148.1405 + outputProperties[indexer] = (previouslyMappedValue !== undefined)
148.1406 + ? previouslyMappedValue
148.1407 + : mapJsObjectGraph(propertyValue, mapInputCallback, visitedObjects);
148.1408 + break;
148.1409 + }
148.1410 + });
148.1411 +
148.1412 + return outputProperties;
148.1413 + }
148.1414 +
148.1415 + function visitPropertiesOrArrayEntries(rootObject, visitorCallback) {
148.1416 + if (rootObject instanceof Array) {
148.1417 + for (var i = 0; i < rootObject.length; i++)
148.1418 + visitorCallback(i);
148.1419 +
148.1420 + // For arrays, also respect toJSON property for custom mappings (fixes #278)
148.1421 + if (typeof rootObject['toJSON'] == 'function')
148.1422 + visitorCallback('toJSON');
148.1423 + } else {
148.1424 + for (var propertyName in rootObject)
148.1425 + visitorCallback(propertyName);
148.1426 + }
148.1427 + };
148.1428 +
148.1429 + function objectLookup() {
148.1430 + var keys = [];
148.1431 + var values = [];
148.1432 + this.save = function(key, value) {
148.1433 + var existingIndex = ko.utils.arrayIndexOf(keys, key);
148.1434 + if (existingIndex >= 0)
148.1435 + values[existingIndex] = value;
148.1436 + else {
148.1437 + keys.push(key);
148.1438 + values.push(value);
148.1439 + }
148.1440 + };
148.1441 + this.get = function(key) {
148.1442 + var existingIndex = ko.utils.arrayIndexOf(keys, key);
148.1443 + return (existingIndex >= 0) ? values[existingIndex] : undefined;
148.1444 + };
148.1445 + };
148.1446 +})();
148.1447 +
148.1448 +ko.exportSymbol('toJS', ko.toJS);
148.1449 +ko.exportSymbol('toJSON', ko.toJSON);
148.1450 +(function () {
148.1451 + var hasDomDataExpandoProperty = '__ko__hasDomDataOptionValue__';
148.1452 +
148.1453 + // Normally, SELECT elements and their OPTIONs can only take value of type 'string' (because the values
148.1454 + // are stored on DOM attributes). ko.selectExtensions provides a way for SELECTs/OPTIONs to have values
148.1455 + // that are arbitrary objects. This is very convenient when implementing things like cascading dropdowns.
148.1456 + ko.selectExtensions = {
148.1457 + readValue : function(element) {
148.1458 + switch (ko.utils.tagNameLower(element)) {
148.1459 + case 'option':
148.1460 + if (element[hasDomDataExpandoProperty] === true)
148.1461 + return ko.utils.domData.get(element, ko.bindingHandlers.options.optionValueDomDataKey);
148.1462 + return ko.utils.ieVersion <= 7
148.1463 + ? (element.getAttributeNode('value').specified ? element.value : element.text)
148.1464 + : element.value;
148.1465 + case 'select':
148.1466 + return element.selectedIndex >= 0 ? ko.selectExtensions.readValue(element.options[element.selectedIndex]) : undefined;
148.1467 + default:
148.1468 + return element.value;
148.1469 + }
148.1470 + },
148.1471 +
148.1472 + writeValue: function(element, value) {
148.1473 + switch (ko.utils.tagNameLower(element)) {
148.1474 + case 'option':
148.1475 + switch(typeof value) {
148.1476 + case "string":
148.1477 + ko.utils.domData.set(element, ko.bindingHandlers.options.optionValueDomDataKey, undefined);
148.1478 + if (hasDomDataExpandoProperty in element) { // IE <= 8 throws errors if you delete non-existent properties from a DOM node
148.1479 + delete element[hasDomDataExpandoProperty];
148.1480 + }
148.1481 + element.value = value;
148.1482 + break;
148.1483 + default:
148.1484 + // Store arbitrary object using DomData
148.1485 + ko.utils.domData.set(element, ko.bindingHandlers.options.optionValueDomDataKey, value);
148.1486 + element[hasDomDataExpandoProperty] = true;
148.1487 +
148.1488 + // Special treatment of numbers is just for backward compatibility. KO 1.2.1 wrote numerical values to element.value.
148.1489 + element.value = typeof value === "number" ? value : "";
148.1490 + break;
148.1491 + }
148.1492 + break;
148.1493 + case 'select':
148.1494 + for (var i = element.options.length - 1; i >= 0; i--) {
148.1495 + if (ko.selectExtensions.readValue(element.options[i]) == value) {
148.1496 + element.selectedIndex = i;
148.1497 + break;
148.1498 + }
148.1499 + }
148.1500 + break;
148.1501 + default:
148.1502 + if ((value === null) || (value === undefined))
148.1503 + value = "";
148.1504 + element.value = value;
148.1505 + break;
148.1506 + }
148.1507 + }
148.1508 + };
148.1509 +})();
148.1510 +
148.1511 +ko.exportSymbol('selectExtensions', ko.selectExtensions);
148.1512 +ko.exportSymbol('selectExtensions.readValue', ko.selectExtensions.readValue);
148.1513 +ko.exportSymbol('selectExtensions.writeValue', ko.selectExtensions.writeValue);
148.1514 +ko.expressionRewriting = (function () {
148.1515 + var restoreCapturedTokensRegex = /\@ko_token_(\d+)\@/g;
148.1516 + var javaScriptReservedWords = ["true", "false"];
148.1517 +
148.1518 + // Matches something that can be assigned to--either an isolated identifier or something ending with a property accessor
148.1519 + // This is designed to be simple and avoid false negatives, but could produce false positives (e.g., a+b.c).
148.1520 + var javaScriptAssignmentTarget = /^(?:[$_a-z][$\w]*|(.+)(\.\s*[$_a-z][$\w]*|\[.+\]))$/i;
148.1521 +
148.1522 + function restoreTokens(string, tokens) {
148.1523 + var prevValue = null;
148.1524 + while (string != prevValue) { // Keep restoring tokens until it no longer makes a difference (they may be nested)
148.1525 + prevValue = string;
148.1526 + string = string.replace(restoreCapturedTokensRegex, function (match, tokenIndex) {
148.1527 + return tokens[tokenIndex];
148.1528 + });
148.1529 + }
148.1530 + return string;
148.1531 + }
148.1532 +
148.1533 + function getWriteableValue(expression) {
148.1534 + if (ko.utils.arrayIndexOf(javaScriptReservedWords, ko.utils.stringTrim(expression).toLowerCase()) >= 0)
148.1535 + return false;
148.1536 + var match = expression.match(javaScriptAssignmentTarget);
148.1537 + return match === null ? false : match[1] ? ('Object(' + match[1] + ')' + match[2]) : expression;
148.1538 + }
148.1539 +
148.1540 + function ensureQuoted(key) {
148.1541 + var trimmedKey = ko.utils.stringTrim(key);
148.1542 + switch (trimmedKey.length && trimmedKey.charAt(0)) {
148.1543 + case "'":
148.1544 + case '"':
148.1545 + return key;
148.1546 + default:
148.1547 + return "'" + trimmedKey + "'";
148.1548 + }
148.1549 + }
148.1550 +
148.1551 + return {
148.1552 + bindingRewriteValidators: [],
148.1553 +
148.1554 + parseObjectLiteral: function(objectLiteralString) {
148.1555 + // A full tokeniser+lexer would add too much weight to this library, so here's a simple parser
148.1556 + // that is sufficient just to split an object literal string into a set of top-level key-value pairs
148.1557 +
148.1558 + var str = ko.utils.stringTrim(objectLiteralString);
148.1559 + if (str.length < 3)
148.1560 + return [];
148.1561 + if (str.charAt(0) === "{")// Ignore any braces surrounding the whole object literal
148.1562 + str = str.substring(1, str.length - 1);
148.1563 +
148.1564 + // Pull out any string literals and regex literals
148.1565 + var tokens = [];
148.1566 + var tokenStart = null, tokenEndChar;
148.1567 + for (var position = 0; position < str.length; position++) {
148.1568 + var c = str.charAt(position);
148.1569 + if (tokenStart === null) {
148.1570 + switch (c) {
148.1571 + case '"':
148.1572 + case "'":
148.1573 + case "/":
148.1574 + tokenStart = position;
148.1575 + tokenEndChar = c;
148.1576 + break;
148.1577 + }
148.1578 + } else if ((c == tokenEndChar) && (str.charAt(position - 1) !== "\\")) {
148.1579 + var token = str.substring(tokenStart, position + 1);
148.1580 + tokens.push(token);
148.1581 + var replacement = "@ko_token_" + (tokens.length - 1) + "@";
148.1582 + str = str.substring(0, tokenStart) + replacement + str.substring(position + 1);
148.1583 + position -= (token.length - replacement.length);
148.1584 + tokenStart = null;
148.1585 + }
148.1586 + }
148.1587 +
148.1588 + // Next pull out balanced paren, brace, and bracket blocks
148.1589 + tokenStart = null;
148.1590 + tokenEndChar = null;
148.1591 + var tokenDepth = 0, tokenStartChar = null;
148.1592 + for (var position = 0; position < str.length; position++) {
148.1593 + var c = str.charAt(position);
148.1594 + if (tokenStart === null) {
148.1595 + switch (c) {
148.1596 + case "{": tokenStart = position; tokenStartChar = c;
148.1597 + tokenEndChar = "}";
148.1598 + break;
148.1599 + case "(": tokenStart = position; tokenStartChar = c;
148.1600 + tokenEndChar = ")";
148.1601 + break;
148.1602 + case "[": tokenStart = position; tokenStartChar = c;
148.1603 + tokenEndChar = "]";
148.1604 + break;
148.1605 + }
148.1606 + }
148.1607 +
148.1608 + if (c === tokenStartChar)
148.1609 + tokenDepth++;
148.1610 + else if (c === tokenEndChar) {
148.1611 + tokenDepth--;
148.1612 + if (tokenDepth === 0) {
148.1613 + var token = str.substring(tokenStart, position + 1);
148.1614 + tokens.push(token);
148.1615 + var replacement = "@ko_token_" + (tokens.length - 1) + "@";
148.1616 + str = str.substring(0, tokenStart) + replacement + str.substring(position + 1);
148.1617 + position -= (token.length - replacement.length);
148.1618 + tokenStart = null;
148.1619 + }
148.1620 + }
148.1621 + }
148.1622 +
148.1623 + // Now we can safely split on commas to get the key/value pairs
148.1624 + var result = [];
148.1625 + var keyValuePairs = str.split(",");
148.1626 + for (var i = 0, j = keyValuePairs.length; i < j; i++) {
148.1627 + var pair = keyValuePairs[i];
148.1628 + var colonPos = pair.indexOf(":");
148.1629 + if ((colonPos > 0) && (colonPos < pair.length - 1)) {
148.1630 + var key = pair.substring(0, colonPos);
148.1631 + var value = pair.substring(colonPos + 1);
148.1632 + result.push({ 'key': restoreTokens(key, tokens), 'value': restoreTokens(value, tokens) });
148.1633 + } else {
148.1634 + result.push({ 'unknown': restoreTokens(pair, tokens) });
148.1635 + }
148.1636 + }
148.1637 + return result;
148.1638 + },
148.1639 +
148.1640 + preProcessBindings: function (objectLiteralStringOrKeyValueArray) {
148.1641 + var keyValueArray = typeof objectLiteralStringOrKeyValueArray === "string"
148.1642 + ? ko.expressionRewriting.parseObjectLiteral(objectLiteralStringOrKeyValueArray)
148.1643 + : objectLiteralStringOrKeyValueArray;
148.1644 + var resultStrings = [], propertyAccessorResultStrings = [];
148.1645 +
148.1646 + var keyValueEntry;
148.1647 + for (var i = 0; keyValueEntry = keyValueArray[i]; i++) {
148.1648 + if (resultStrings.length > 0)
148.1649 + resultStrings.push(",");
148.1650 +
148.1651 + if (keyValueEntry['key']) {
148.1652 + var quotedKey = ensureQuoted(keyValueEntry['key']), val = keyValueEntry['value'];
148.1653 + resultStrings.push(quotedKey);
148.1654 + resultStrings.push(":");
148.1655 + resultStrings.push(val);
148.1656 +
148.1657 + if (val = getWriteableValue(ko.utils.stringTrim(val))) {
148.1658 + if (propertyAccessorResultStrings.length > 0)
148.1659 + propertyAccessorResultStrings.push(", ");
148.1660 + propertyAccessorResultStrings.push(quotedKey + " : function(__ko_value) { " + val + " = __ko_value; }");
148.1661 + }
148.1662 + } else if (keyValueEntry['unknown']) {
148.1663 + resultStrings.push(keyValueEntry['unknown']);
148.1664 + }
148.1665 + }
148.1666 +
148.1667 + var combinedResult = resultStrings.join("");
148.1668 + if (propertyAccessorResultStrings.length > 0) {
148.1669 + var allPropertyAccessors = propertyAccessorResultStrings.join("");
148.1670 + combinedResult = combinedResult + ", '_ko_property_writers' : { " + allPropertyAccessors + " } ";
148.1671 + }
148.1672 +
148.1673 + return combinedResult;
148.1674 + },
148.1675 +
148.1676 + keyValueArrayContainsKey: function(keyValueArray, key) {
148.1677 + for (var i = 0; i < keyValueArray.length; i++)
148.1678 + if (ko.utils.stringTrim(keyValueArray[i]['key']) == key)
148.1679 + return true;
148.1680 + return false;
148.1681 + },
148.1682 +
148.1683 + // Internal, private KO utility for updating model properties from within bindings
148.1684 + // property: If the property being updated is (or might be) an observable, pass it here
148.1685 + // If it turns out to be a writable observable, it will be written to directly
148.1686 + // allBindingsAccessor: All bindings in the current execution context.
148.1687 + // This will be searched for a '_ko_property_writers' property in case you're writing to a non-observable
148.1688 + // key: The key identifying the property to be written. Example: for { hasFocus: myValue }, write to 'myValue' by specifying the key 'hasFocus'
148.1689 + // value: The value to be written
148.1690 + // checkIfDifferent: If true, and if the property being written is a writable observable, the value will only be written if
148.1691 + // it is !== existing value on that writable observable
148.1692 + writeValueToProperty: function(property, allBindingsAccessor, key, value, checkIfDifferent) {
148.1693 + if (!property || !ko.isWriteableObservable(property)) {
148.1694 + var propWriters = allBindingsAccessor()['_ko_property_writers'];
148.1695 + if (propWriters && propWriters[key])
148.1696 + propWriters[key](value);
148.1697 + } else if (!checkIfDifferent || property.peek() !== value) {
148.1698 + property(value);
148.1699 + }
148.1700 + }
148.1701 + };
148.1702 +})();
148.1703 +
148.1704 +ko.exportSymbol('expressionRewriting', ko.expressionRewriting);
148.1705 +ko.exportSymbol('expressionRewriting.bindingRewriteValidators', ko.expressionRewriting.bindingRewriteValidators);
148.1706 +ko.exportSymbol('expressionRewriting.parseObjectLiteral', ko.expressionRewriting.parseObjectLiteral);
148.1707 +ko.exportSymbol('expressionRewriting.preProcessBindings', ko.expressionRewriting.preProcessBindings);
148.1708 +
148.1709 +// For backward compatibility, define the following aliases. (Previously, these function names were misleading because
148.1710 +// they referred to JSON specifically, even though they actually work with arbitrary JavaScript object literal expressions.)
148.1711 +ko.exportSymbol('jsonExpressionRewriting', ko.expressionRewriting);
148.1712 +ko.exportSymbol('jsonExpressionRewriting.insertPropertyAccessorsIntoJson', ko.expressionRewriting.preProcessBindings);(function() {
148.1713 + // "Virtual elements" is an abstraction on top of the usual DOM API which understands the notion that comment nodes
148.1714 + // may be used to represent hierarchy (in addition to the DOM's natural hierarchy).
148.1715 + // If you call the DOM-manipulating functions on ko.virtualElements, you will be able to read and write the state
148.1716 + // of that virtual hierarchy
148.1717 + //
148.1718 + // The point of all this is to support containerless templates (e.g., <!-- ko foreach:someCollection -->blah<!-- /ko -->)
148.1719 + // without having to scatter special cases all over the binding and templating code.
148.1720 +
148.1721 + // IE 9 cannot reliably read the "nodeValue" property of a comment node (see https://github.com/SteveSanderson/knockout/issues/186)
148.1722 + // but it does give them a nonstandard alternative property called "text" that it can read reliably. Other browsers don't have that property.
148.1723 + // So, use node.text where available, and node.nodeValue elsewhere
148.1724 + var commentNodesHaveTextProperty = document.createComment("test").text === "<!--test-->";
148.1725 +
148.1726 + var startCommentRegex = commentNodesHaveTextProperty ? /^<!--\s*ko(?:\s+(.+\s*\:[\s\S]*))?\s*-->$/ : /^\s*ko(?:\s+(.+\s*\:[\s\S]*))?\s*$/;
148.1727 + var endCommentRegex = commentNodesHaveTextProperty ? /^<!--\s*\/ko\s*-->$/ : /^\s*\/ko\s*$/;
148.1728 + var htmlTagsWithOptionallyClosingChildren = { 'ul': true, 'ol': true };
148.1729 +
148.1730 + function isStartComment(node) {
148.1731 + return (node.nodeType == 8) && (commentNodesHaveTextProperty ? node.text : node.nodeValue).match(startCommentRegex);
148.1732 + }
148.1733 +
148.1734 + function isEndComment(node) {
148.1735 + return (node.nodeType == 8) && (commentNodesHaveTextProperty ? node.text : node.nodeValue).match(endCommentRegex);
148.1736 + }
148.1737 +
148.1738 + function getVirtualChildren(startComment, allowUnbalanced) {
148.1739 + var currentNode = startComment;
148.1740 + var depth = 1;
148.1741 + var children = [];
148.1742 + while (currentNode = currentNode.nextSibling) {
148.1743 + if (isEndComment(currentNode)) {
148.1744 + depth--;
148.1745 + if (depth === 0)
148.1746 + return children;
148.1747 + }
148.1748 +
148.1749 + children.push(currentNode);
148.1750 +
148.1751 + if (isStartComment(currentNode))
148.1752 + depth++;
148.1753 + }
148.1754 + if (!allowUnbalanced)
148.1755 + throw new Error("Cannot find closing comment tag to match: " + startComment.nodeValue);
148.1756 + return null;
148.1757 + }
148.1758 +
148.1759 + function getMatchingEndComment(startComment, allowUnbalanced) {
148.1760 + var allVirtualChildren = getVirtualChildren(startComment, allowUnbalanced);
148.1761 + if (allVirtualChildren) {
148.1762 + if (allVirtualChildren.length > 0)
148.1763 + return allVirtualChildren[allVirtualChildren.length - 1].nextSibling;
148.1764 + return startComment.nextSibling;
148.1765 + } else
148.1766 + return null; // Must have no matching end comment, and allowUnbalanced is true
148.1767 + }
148.1768 +
148.1769 + function getUnbalancedChildTags(node) {
148.1770 + // e.g., from <div>OK</div><!-- ko blah --><span>Another</span>, returns: <!-- ko blah --><span>Another</span>
148.1771 + // from <div>OK</div><!-- /ko --><!-- /ko -->, returns: <!-- /ko --><!-- /ko -->
148.1772 + var childNode = node.firstChild, captureRemaining = null;
148.1773 + if (childNode) {
148.1774 + do {
148.1775 + if (captureRemaining) // We already hit an unbalanced node and are now just scooping up all subsequent nodes
148.1776 + captureRemaining.push(childNode);
148.1777 + else if (isStartComment(childNode)) {
148.1778 + var matchingEndComment = getMatchingEndComment(childNode, /* allowUnbalanced: */ true);
148.1779 + if (matchingEndComment) // It's a balanced tag, so skip immediately to the end of this virtual set
148.1780 + childNode = matchingEndComment;
148.1781 + else
148.1782 + captureRemaining = [childNode]; // It's unbalanced, so start capturing from this point
148.1783 + } else if (isEndComment(childNode)) {
148.1784 + captureRemaining = [childNode]; // It's unbalanced (if it wasn't, we'd have skipped over it already), so start capturing
148.1785 + }
148.1786 + } while (childNode = childNode.nextSibling);
148.1787 + }
148.1788 + return captureRemaining;
148.1789 + }
148.1790 +
148.1791 + ko.virtualElements = {
148.1792 + allowedBindings: {},
148.1793 +
148.1794 + childNodes: function(node) {
148.1795 + return isStartComment(node) ? getVirtualChildren(node) : node.childNodes;
148.1796 + },
148.1797 +
148.1798 + emptyNode: function(node) {
148.1799 + if (!isStartComment(node))
148.1800 + ko.utils.emptyDomNode(node);
148.1801 + else {
148.1802 + var virtualChildren = ko.virtualElements.childNodes(node);
148.1803 + for (var i = 0, j = virtualChildren.length; i < j; i++)
148.1804 + ko.removeNode(virtualChildren[i]);
148.1805 + }
148.1806 + },
148.1807 +
148.1808 + setDomNodeChildren: function(node, childNodes) {
148.1809 + if (!isStartComment(node))
148.1810 + ko.utils.setDomNodeChildren(node, childNodes);
148.1811 + else {
148.1812 + ko.virtualElements.emptyNode(node);
148.1813 + var endCommentNode = node.nextSibling; // Must be the next sibling, as we just emptied the children
148.1814 + for (var i = 0, j = childNodes.length; i < j; i++)
148.1815 + endCommentNode.parentNode.insertBefore(childNodes[i], endCommentNode);
148.1816 + }
148.1817 + },
148.1818 +
148.1819 + prepend: function(containerNode, nodeToPrepend) {
148.1820 + if (!isStartComment(containerNode)) {
148.1821 + if (containerNode.firstChild)
148.1822 + containerNode.insertBefore(nodeToPrepend, containerNode.firstChild);
148.1823 + else
148.1824 + containerNode.appendChild(nodeToPrepend);
148.1825 + } else {
148.1826 + // Start comments must always have a parent and at least one following sibling (the end comment)
148.1827 + containerNode.parentNode.insertBefore(nodeToPrepend, containerNode.nextSibling);
148.1828 + }
148.1829 + },
148.1830 +
148.1831 + insertAfter: function(containerNode, nodeToInsert, insertAfterNode) {
148.1832 + if (!insertAfterNode) {
148.1833 + ko.virtualElements.prepend(containerNode, nodeToInsert);
148.1834 + } else if (!isStartComment(containerNode)) {
148.1835 + // Insert after insertion point
148.1836 + if (insertAfterNode.nextSibling)
148.1837 + containerNode.insertBefore(nodeToInsert, insertAfterNode.nextSibling);
148.1838 + else
148.1839 + containerNode.appendChild(nodeToInsert);
148.1840 + } else {
148.1841 + // Children of start comments must always have a parent and at least one following sibling (the end comment)
148.1842 + containerNode.parentNode.insertBefore(nodeToInsert, insertAfterNode.nextSibling);
148.1843 + }
148.1844 + },
148.1845 +
148.1846 + firstChild: function(node) {
148.1847 + if (!isStartComment(node))
148.1848 + return node.firstChild;
148.1849 + if (!node.nextSibling || isEndComment(node.nextSibling))
148.1850 + return null;
148.1851 + return node.nextSibling;
148.1852 + },
148.1853 +
148.1854 + nextSibling: function(node) {
148.1855 + if (isStartComment(node))
148.1856 + node = getMatchingEndComment(node);
148.1857 + if (node.nextSibling && isEndComment(node.nextSibling))
148.1858 + return null;
148.1859 + return node.nextSibling;
148.1860 + },
148.1861 +
148.1862 + virtualNodeBindingValue: function(node) {
148.1863 + var regexMatch = isStartComment(node);
148.1864 + return regexMatch ? regexMatch[1] : null;
148.1865 + },
148.1866 +
148.1867 + normaliseVirtualElementDomStructure: function(elementVerified) {
148.1868 + // Workaround for https://github.com/SteveSanderson/knockout/issues/155
148.1869 + // (IE <= 8 or IE 9 quirks mode parses your HTML weirdly, treating closing </li> tags as if they don't exist, thereby moving comment nodes
148.1870 + // that are direct descendants of <ul> into the preceding <li>)
148.1871 + if (!htmlTagsWithOptionallyClosingChildren[ko.utils.tagNameLower(elementVerified)])
148.1872 + return;
148.1873 +
148.1874 + // Scan immediate children to see if they contain unbalanced comment tags. If they do, those comment tags
148.1875 + // must be intended to appear *after* that child, so move them there.
148.1876 + var childNode = elementVerified.firstChild;
148.1877 + if (childNode) {
148.1878 + do {
148.1879 + if (childNode.nodeType === 1) {
148.1880 + var unbalancedTags = getUnbalancedChildTags(childNode);
148.1881 + if (unbalancedTags) {
148.1882 + // Fix up the DOM by moving the unbalanced tags to where they most likely were intended to be placed - *after* the child
148.1883 + var nodeToInsertBefore = childNode.nextSibling;
148.1884 + for (var i = 0; i < unbalancedTags.length; i++) {
148.1885 + if (nodeToInsertBefore)
148.1886 + elementVerified.insertBefore(unbalancedTags[i], nodeToInsertBefore);
148.1887 + else
148.1888 + elementVerified.appendChild(unbalancedTags[i]);
148.1889 + }
148.1890 + }
148.1891 + }
148.1892 + } while (childNode = childNode.nextSibling);
148.1893 + }
148.1894 + }
148.1895 + };
148.1896 +})();
148.1897 +ko.exportSymbol('virtualElements', ko.virtualElements);
148.1898 +ko.exportSymbol('virtualElements.allowedBindings', ko.virtualElements.allowedBindings);
148.1899 +ko.exportSymbol('virtualElements.emptyNode', ko.virtualElements.emptyNode);
148.1900 +//ko.exportSymbol('virtualElements.firstChild', ko.virtualElements.firstChild); // firstChild is not minified
148.1901 +ko.exportSymbol('virtualElements.insertAfter', ko.virtualElements.insertAfter);
148.1902 +//ko.exportSymbol('virtualElements.nextSibling', ko.virtualElements.nextSibling); // nextSibling is not minified
148.1903 +ko.exportSymbol('virtualElements.prepend', ko.virtualElements.prepend);
148.1904 +ko.exportSymbol('virtualElements.setDomNodeChildren', ko.virtualElements.setDomNodeChildren);
148.1905 +(function() {
148.1906 + var defaultBindingAttributeName = "data-bind";
148.1907 +
148.1908 + ko.bindingProvider = function() {
148.1909 + this.bindingCache = {};
148.1910 + };
148.1911 +
148.1912 + ko.utils.extend(ko.bindingProvider.prototype, {
148.1913 + 'nodeHasBindings': function(node) {
148.1914 + switch (node.nodeType) {
148.1915 + case 1: return node.getAttribute(defaultBindingAttributeName) != null; // Element
148.1916 + case 8: return ko.virtualElements.virtualNodeBindingValue(node) != null; // Comment node
148.1917 + default: return false;
148.1918 + }
148.1919 + },
148.1920 +
148.1921 + 'getBindings': function(node, bindingContext) {
148.1922 + var bindingsString = this['getBindingsString'](node, bindingContext);
148.1923 + return bindingsString ? this['parseBindingsString'](bindingsString, bindingContext, node) : null;
148.1924 + },
148.1925 +
148.1926 + // The following function is only used internally by this default provider.
148.1927 + // It's not part of the interface definition for a general binding provider.
148.1928 + 'getBindingsString': function(node, bindingContext) {
148.1929 + switch (node.nodeType) {
148.1930 + case 1: return node.getAttribute(defaultBindingAttributeName); // Element
148.1931 + case 8: return ko.virtualElements.virtualNodeBindingValue(node); // Comment node
148.1932 + default: return null;
148.1933 + }
148.1934 + },
148.1935 +
148.1936 + // The following function is only used internally by this default provider.
148.1937 + // It's not part of the interface definition for a general binding provider.
148.1938 + 'parseBindingsString': function(bindingsString, bindingContext, node) {
148.1939 + try {
148.1940 + var bindingFunction = createBindingsStringEvaluatorViaCache(bindingsString, this.bindingCache);
148.1941 + return bindingFunction(bindingContext, node);
148.1942 + } catch (ex) {
148.1943 + throw new Error("Unable to parse bindings.\nMessage: " + ex + ";\nBindings value: " + bindingsString);
148.1944 + }
148.1945 + }
148.1946 + });
148.1947 +
148.1948 + ko.bindingProvider['instance'] = new ko.bindingProvider();
148.1949 +
148.1950 + function createBindingsStringEvaluatorViaCache(bindingsString, cache) {
148.1951 + var cacheKey = bindingsString;
148.1952 + return cache[cacheKey]
148.1953 + || (cache[cacheKey] = createBindingsStringEvaluator(bindingsString));
148.1954 + }
148.1955 +
148.1956 + function createBindingsStringEvaluator(bindingsString) {
148.1957 + // Build the source for a function that evaluates "expression"
148.1958 + // For each scope variable, add an extra level of "with" nesting
148.1959 + // Example result: with(sc1) { with(sc0) { return (expression) } }
148.1960 + var rewrittenBindings = ko.expressionRewriting.preProcessBindings(bindingsString),
148.1961 + functionBody = "with($context){with($data||{}){return{" + rewrittenBindings + "}}}";
148.1962 + return new Function("$context", "$element", functionBody);
148.1963 + }
148.1964 +})();
148.1965 +
148.1966 +ko.exportSymbol('bindingProvider', ko.bindingProvider);
148.1967 +(function () {
148.1968 + ko.bindingHandlers = {};
148.1969 +
148.1970 + ko.bindingContext = function(dataItem, parentBindingContext, dataItemAlias) {
148.1971 + if (parentBindingContext) {
148.1972 + ko.utils.extend(this, parentBindingContext); // Inherit $root and any custom properties
148.1973 + this['$parentContext'] = parentBindingContext;
148.1974 + this['$parent'] = parentBindingContext['$data'];
148.1975 + this['$parents'] = (parentBindingContext['$parents'] || []).slice(0);
148.1976 + this['$parents'].unshift(this['$parent']);
148.1977 + } else {
148.1978 + this['$parents'] = [];
148.1979 + this['$root'] = dataItem;
148.1980 + // Export 'ko' in the binding context so it will be available in bindings and templates
148.1981 + // even if 'ko' isn't exported as a global, such as when using an AMD loader.
148.1982 + // See https://github.com/SteveSanderson/knockout/issues/490
148.1983 + this['ko'] = ko;
148.1984 + }
148.1985 + this['$data'] = dataItem;
148.1986 + if (dataItemAlias)
148.1987 + this[dataItemAlias] = dataItem;
148.1988 + }
148.1989 + ko.bindingContext.prototype['createChildContext'] = function (dataItem, dataItemAlias) {
148.1990 + return new ko.bindingContext(dataItem, this, dataItemAlias);
148.1991 + };
148.1992 + ko.bindingContext.prototype['extend'] = function(properties) {
148.1993 + var clone = ko.utils.extend(new ko.bindingContext(), this);
148.1994 + return ko.utils.extend(clone, properties);
148.1995 + };
148.1996 +
148.1997 + function validateThatBindingIsAllowedForVirtualElements(bindingName) {
148.1998 + var validator = ko.virtualElements.allowedBindings[bindingName];
148.1999 + if (!validator)
148.2000 + throw new Error("The binding '" + bindingName + "' cannot be used with virtual elements")
148.2001 + }
148.2002 +
148.2003 + function applyBindingsToDescendantsInternal (viewModel, elementOrVirtualElement, bindingContextsMayDifferFromDomParentElement) {
148.2004 + var currentChild, nextInQueue = ko.virtualElements.firstChild(elementOrVirtualElement);
148.2005 + while (currentChild = nextInQueue) {
148.2006 + // Keep a record of the next child *before* applying bindings, in case the binding removes the current child from its position
148.2007 + nextInQueue = ko.virtualElements.nextSibling(currentChild);
148.2008 + applyBindingsToNodeAndDescendantsInternal(viewModel, currentChild, bindingContextsMayDifferFromDomParentElement);
148.2009 + }
148.2010 + }
148.2011 +
148.2012 + function applyBindingsToNodeAndDescendantsInternal (viewModel, nodeVerified, bindingContextMayDifferFromDomParentElement) {
148.2013 + var shouldBindDescendants = true;
148.2014 +
148.2015 + // Perf optimisation: Apply bindings only if...
148.2016 + // (1) We need to store the binding context on this node (because it may differ from the DOM parent node's binding context)
148.2017 + // Note that we can't store binding contexts on non-elements (e.g., text nodes), as IE doesn't allow expando properties for those
148.2018 + // (2) It might have bindings (e.g., it has a data-bind attribute, or it's a marker for a containerless template)
148.2019 + var isElement = (nodeVerified.nodeType === 1);
148.2020 + if (isElement) // Workaround IE <= 8 HTML parsing weirdness
148.2021 + ko.virtualElements.normaliseVirtualElementDomStructure(nodeVerified);
148.2022 +
148.2023 + var shouldApplyBindings = (isElement && bindingContextMayDifferFromDomParentElement) // Case (1)
148.2024 + || ko.bindingProvider['instance']['nodeHasBindings'](nodeVerified); // Case (2)
148.2025 + if (shouldApplyBindings)
148.2026 + shouldBindDescendants = applyBindingsToNodeInternal(nodeVerified, null, viewModel, bindingContextMayDifferFromDomParentElement).shouldBindDescendants;
148.2027 +
148.2028 + if (shouldBindDescendants) {
148.2029 + // We're recursing automatically into (real or virtual) child nodes without changing binding contexts. So,
148.2030 + // * For children of a *real* element, the binding context is certainly the same as on their DOM .parentNode,
148.2031 + // hence bindingContextsMayDifferFromDomParentElement is false
148.2032 + // * For children of a *virtual* element, we can't be sure. Evaluating .parentNode on those children may
148.2033 + // skip over any number of intermediate virtual elements, any of which might define a custom binding context,
148.2034 + // hence bindingContextsMayDifferFromDomParentElement is true
148.2035 + applyBindingsToDescendantsInternal(viewModel, nodeVerified, /* bindingContextsMayDifferFromDomParentElement: */ !isElement);
148.2036 + }
148.2037 + }
148.2038 +
148.2039 + function applyBindingsToNodeInternal (node, bindings, viewModelOrBindingContext, bindingContextMayDifferFromDomParentElement) {
148.2040 + // Need to be sure that inits are only run once, and updates never run until all the inits have been run
148.2041 + var initPhase = 0; // 0 = before all inits, 1 = during inits, 2 = after all inits
148.2042 +
148.2043 + // Each time the dependentObservable is evaluated (after data changes),
148.2044 + // the binding attribute is reparsed so that it can pick out the correct
148.2045 + // model properties in the context of the changed data.
148.2046 + // DOM event callbacks need to be able to access this changed data,
148.2047 + // so we need a single parsedBindings variable (shared by all callbacks
148.2048 + // associated with this node's bindings) that all the closures can access.
148.2049 + var parsedBindings;
148.2050 + function makeValueAccessor(bindingKey) {
148.2051 + return function () { return parsedBindings[bindingKey] }
148.2052 + }
148.2053 + function parsedBindingsAccessor() {
148.2054 + return parsedBindings;
148.2055 + }
148.2056 +
148.2057 + var bindingHandlerThatControlsDescendantBindings;
148.2058 + ko.dependentObservable(
148.2059 + function () {
148.2060 + // Ensure we have a nonnull binding context to work with
148.2061 + var bindingContextInstance = viewModelOrBindingContext && (viewModelOrBindingContext instanceof ko.bindingContext)
148.2062 + ? viewModelOrBindingContext
148.2063 + : new ko.bindingContext(ko.utils.unwrapObservable(viewModelOrBindingContext));
148.2064 + var viewModel = bindingContextInstance['$data'];
148.2065 +
148.2066 + // Optimization: Don't store the binding context on this node if it's definitely the same as on node.parentNode, because
148.2067 + // we can easily recover it just by scanning up the node's ancestors in the DOM
148.2068 + // (note: here, parent node means "real DOM parent" not "virtual parent", as there's no O(1) way to find the virtual parent)
148.2069 + if (bindingContextMayDifferFromDomParentElement)
148.2070 + ko.storedBindingContextForNode(node, bindingContextInstance);
148.2071 +
148.2072 + // Use evaluatedBindings if given, otherwise fall back on asking the bindings provider to give us some bindings
148.2073 + var evaluatedBindings = (typeof bindings == "function") ? bindings(bindingContextInstance, node) : bindings;
148.2074 + parsedBindings = evaluatedBindings || ko.bindingProvider['instance']['getBindings'](node, bindingContextInstance);
148.2075 +
148.2076 + if (parsedBindings) {
148.2077 + // First run all the inits, so bindings can register for notification on changes
148.2078 + if (initPhase === 0) {
148.2079 + initPhase = 1;
148.2080 + for (var bindingKey in parsedBindings) {
148.2081 + var binding = ko.bindingHandlers[bindingKey];
148.2082 + if (binding && node.nodeType === 8)
148.2083 + validateThatBindingIsAllowedForVirtualElements(bindingKey);
148.2084 +
148.2085 + if (binding && typeof binding["init"] == "function") {
148.2086 + var handlerInitFn = binding["init"];
148.2087 + var initResult = handlerInitFn(node, makeValueAccessor(bindingKey), parsedBindingsAccessor, viewModel, bindingContextInstance);
148.2088 +
148.2089 + // If this binding handler claims to control descendant bindings, make a note of this
148.2090 + if (initResult && initResult['controlsDescendantBindings']) {
148.2091 + if (bindingHandlerThatControlsDescendantBindings !== undefined)
148.2092 + throw new Error("Multiple bindings (" + bindingHandlerThatControlsDescendantBindings + " and " + bindingKey + ") are trying to control descendant bindings of the same element. You cannot use these bindings together on the same element.");
148.2093 + bindingHandlerThatControlsDescendantBindings = bindingKey;
148.2094 + }
148.2095 + }
148.2096 + }
148.2097 + initPhase = 2;
148.2098 + }
148.2099 +
148.2100 + // ... then run all the updates, which might trigger changes even on the first evaluation
148.2101 + if (initPhase === 2) {
148.2102 + for (var bindingKey in parsedBindings) {
148.2103 + var binding = ko.bindingHandlers[bindingKey];
148.2104 + if (binding && typeof binding["update"] == "function") {
148.2105 + var handlerUpdateFn = binding["update"];
148.2106 + handlerUpdateFn(node, makeValueAccessor(bindingKey), parsedBindingsAccessor, viewModel, bindingContextInstance);
148.2107 + }
148.2108 + }
148.2109 + }
148.2110 + }
148.2111 + },
148.2112 + null,
148.2113 + { disposeWhenNodeIsRemoved : node }
148.2114 + );
148.2115 +
148.2116 + return {
148.2117 + shouldBindDescendants: bindingHandlerThatControlsDescendantBindings === undefined
148.2118 + };
148.2119 + };
148.2120 +
148.2121 + var storedBindingContextDomDataKey = "__ko_bindingContext__";
148.2122 + ko.storedBindingContextForNode = function (node, bindingContext) {
148.2123 + if (arguments.length == 2)
148.2124 + ko.utils.domData.set(node, storedBindingContextDomDataKey, bindingContext);
148.2125 + else
148.2126 + return ko.utils.domData.get(node, storedBindingContextDomDataKey);
148.2127 + }
148.2128 +
148.2129 + ko.applyBindingsToNode = function (node, bindings, viewModel) {
148.2130 + if (node.nodeType === 1) // If it's an element, workaround IE <= 8 HTML parsing weirdness
148.2131 + ko.virtualElements.normaliseVirtualElementDomStructure(node);
148.2132 + return applyBindingsToNodeInternal(node, bindings, viewModel, true);
148.2133 + };
148.2134 +
148.2135 + ko.applyBindingsToDescendants = function(viewModel, rootNode) {
148.2136 + if (rootNode.nodeType === 1 || rootNode.nodeType === 8)
148.2137 + applyBindingsToDescendantsInternal(viewModel, rootNode, true);
148.2138 + };
148.2139 +
148.2140 + ko.applyBindings = function (viewModel, rootNode) {
148.2141 + if (rootNode && (rootNode.nodeType !== 1) && (rootNode.nodeType !== 8))
148.2142 + throw new Error("ko.applyBindings: first parameter should be your view model; second parameter should be a DOM node");
148.2143 + rootNode = rootNode || window.document.body; // Make "rootNode" parameter optional
148.2144 +
148.2145 + applyBindingsToNodeAndDescendantsInternal(viewModel, rootNode, true);
148.2146 + };
148.2147 +
148.2148 + // Retrieving binding context from arbitrary nodes
148.2149 + ko.contextFor = function(node) {
148.2150 + // We can only do something meaningful for elements and comment nodes (in particular, not text nodes, as IE can't store domdata for them)
148.2151 + switch (node.nodeType) {
148.2152 + case 1:
148.2153 + case 8:
148.2154 + var context = ko.storedBindingContextForNode(node);
148.2155 + if (context) return context;
148.2156 + if (node.parentNode) return ko.contextFor(node.parentNode);
148.2157 + break;
148.2158 + }
148.2159 + return undefined;
148.2160 + };
148.2161 + ko.dataFor = function(node) {
148.2162 + var context = ko.contextFor(node);
148.2163 + return context ? context['$data'] : undefined;
148.2164 + };
148.2165 +
148.2166 + ko.exportSymbol('bindingHandlers', ko.bindingHandlers);
148.2167 + ko.exportSymbol('applyBindings', ko.applyBindings);
148.2168 + ko.exportSymbol('applyBindingsToDescendants', ko.applyBindingsToDescendants);
148.2169 + ko.exportSymbol('applyBindingsToNode', ko.applyBindingsToNode);
148.2170 + ko.exportSymbol('contextFor', ko.contextFor);
148.2171 + ko.exportSymbol('dataFor', ko.dataFor);
148.2172 +})();
148.2173 +var attrHtmlToJavascriptMap = { 'class': 'className', 'for': 'htmlFor' };
148.2174 +ko.bindingHandlers['attr'] = {
148.2175 + 'update': function(element, valueAccessor, allBindingsAccessor) {
148.2176 + var value = ko.utils.unwrapObservable(valueAccessor()) || {};
148.2177 + for (var attrName in value) {
148.2178 + if (typeof attrName == "string") {
148.2179 + var attrValue = ko.utils.unwrapObservable(value[attrName]);
148.2180 +
148.2181 + // To cover cases like "attr: { checked:someProp }", we want to remove the attribute entirely
148.2182 + // when someProp is a "no value"-like value (strictly null, false, or undefined)
148.2183 + // (because the absence of the "checked" attr is how to mark an element as not checked, etc.)
148.2184 + var toRemove = (attrValue === false) || (attrValue === null) || (attrValue === undefined);
148.2185 + if (toRemove)
148.2186 + element.removeAttribute(attrName);
148.2187 +
148.2188 + // In IE <= 7 and IE8 Quirks Mode, you have to use the Javascript property name instead of the
148.2189 + // HTML attribute name for certain attributes. IE8 Standards Mode supports the correct behavior,
148.2190 + // but instead of figuring out the mode, we'll just set the attribute through the Javascript
148.2191 + // property for IE <= 8.
148.2192 + if (ko.utils.ieVersion <= 8 && attrName in attrHtmlToJavascriptMap) {
148.2193 + attrName = attrHtmlToJavascriptMap[attrName];
148.2194 + if (toRemove)
148.2195 + element.removeAttribute(attrName);
148.2196 + else
148.2197 + element[attrName] = attrValue;
148.2198 + } else if (!toRemove) {
148.2199 + element.setAttribute(attrName, attrValue.toString());
148.2200 + }
148.2201 +
148.2202 + // Treat "name" specially - although you can think of it as an attribute, it also needs
148.2203 + // special handling on older versions of IE (https://github.com/SteveSanderson/knockout/pull/333)
148.2204 + // Deliberately being case-sensitive here because XHTML would regard "Name" as a different thing
148.2205 + // entirely, and there's no strong reason to allow for such casing in HTML.
148.2206 + if (attrName === "name") {
148.2207 + ko.utils.setElementName(element, toRemove ? "" : attrValue.toString());
148.2208 + }
148.2209 + }
148.2210 + }
148.2211 + }
148.2212 +};
148.2213 +ko.bindingHandlers['checked'] = {
148.2214 + 'init': function (element, valueAccessor, allBindingsAccessor) {
148.2215 + var updateHandler = function() {
148.2216 + var valueToWrite;
148.2217 + if (element.type == "checkbox") {
148.2218 + valueToWrite = element.checked;
148.2219 + } else if ((element.type == "radio") && (element.checked)) {
148.2220 + valueToWrite = element.value;
148.2221 + } else {
148.2222 + return; // "checked" binding only responds to checkboxes and selected radio buttons
148.2223 + }
148.2224 +
148.2225 + var modelValue = valueAccessor(), unwrappedValue = ko.utils.unwrapObservable(modelValue);
148.2226 + if ((element.type == "checkbox") && (unwrappedValue instanceof Array)) {
148.2227 + // For checkboxes bound to an array, we add/remove the checkbox value to that array
148.2228 + // This works for both observable and non-observable arrays
148.2229 + var existingEntryIndex = ko.utils.arrayIndexOf(unwrappedValue, element.value);
148.2230 + if (element.checked && (existingEntryIndex < 0))
148.2231 + modelValue.push(element.value);
148.2232 + else if ((!element.checked) && (existingEntryIndex >= 0))
148.2233 + modelValue.splice(existingEntryIndex, 1);
148.2234 + } else {
148.2235 + ko.expressionRewriting.writeValueToProperty(modelValue, allBindingsAccessor, 'checked', valueToWrite, true);
148.2236 + }
148.2237 + };
148.2238 + ko.utils.registerEventHandler(element, "click", updateHandler);
148.2239 +
148.2240 + // IE 6 won't allow radio buttons to be selected unless they have a name
148.2241 + if ((element.type == "radio") && !element.name)
148.2242 + ko.bindingHandlers['uniqueName']['init'](element, function() { return true });
148.2243 + },
148.2244 + 'update': function (element, valueAccessor) {
148.2245 + var value = ko.utils.unwrapObservable(valueAccessor());
148.2246 +
148.2247 + if (element.type == "checkbox") {
148.2248 + if (value instanceof Array) {
148.2249 + // When bound to an array, the checkbox being checked represents its value being present in that array
148.2250 + element.checked = ko.utils.arrayIndexOf(value, element.value) >= 0;
148.2251 + } else {
148.2252 + // When bound to anything other value (not an array), the checkbox being checked represents the value being trueish
148.2253 + element.checked = value;
148.2254 + }
148.2255 + } else if (element.type == "radio") {
148.2256 + element.checked = (element.value == value);
148.2257 + }
148.2258 + }
148.2259 +};
148.2260 +var classesWrittenByBindingKey = '__ko__cssValue';
148.2261 +ko.bindingHandlers['css'] = {
148.2262 + 'update': function (element, valueAccessor) {
148.2263 + var value = ko.utils.unwrapObservable(valueAccessor());
148.2264 + if (typeof value == "object") {
148.2265 + for (var className in value) {
148.2266 + var shouldHaveClass = ko.utils.unwrapObservable(value[className]);
148.2267 + ko.utils.toggleDomNodeCssClass(element, className, shouldHaveClass);
148.2268 + }
148.2269 + } else {
148.2270 + value = String(value || ''); // Make sure we don't try to store or set a non-string value
148.2271 + ko.utils.toggleDomNodeCssClass(element, element[classesWrittenByBindingKey], false);
148.2272 + element[classesWrittenByBindingKey] = value;
148.2273 + ko.utils.toggleDomNodeCssClass(element, value, true);
148.2274 + }
148.2275 + }
148.2276 +};
148.2277 +ko.bindingHandlers['enable'] = {
148.2278 + 'update': function (element, valueAccessor) {
148.2279 + var value = ko.utils.unwrapObservable(valueAccessor());
148.2280 + if (value && element.disabled)
148.2281 + element.removeAttribute("disabled");
148.2282 + else if ((!value) && (!element.disabled))
148.2283 + element.disabled = true;
148.2284 + }
148.2285 +};
148.2286 +
148.2287 +ko.bindingHandlers['disable'] = {
148.2288 + 'update': function (element, valueAccessor) {
148.2289 + ko.bindingHandlers['enable']['update'](element, function() { return !ko.utils.unwrapObservable(valueAccessor()) });
148.2290 + }
148.2291 +};
148.2292 +// For certain common events (currently just 'click'), allow a simplified data-binding syntax
148.2293 +// e.g. click:handler instead of the usual full-length event:{click:handler}
148.2294 +function makeEventHandlerShortcut(eventName) {
148.2295 + ko.bindingHandlers[eventName] = {
148.2296 + 'init': function(element, valueAccessor, allBindingsAccessor, viewModel) {
148.2297 + var newValueAccessor = function () {
148.2298 + var result = {};
148.2299 + result[eventName] = valueAccessor();
148.2300 + return result;
148.2301 + };
148.2302 + return ko.bindingHandlers['event']['init'].call(this, element, newValueAccessor, allBindingsAccessor, viewModel);
148.2303 + }
148.2304 + }
148.2305 +}
148.2306 +
148.2307 +ko.bindingHandlers['event'] = {
148.2308 + 'init' : function (element, valueAccessor, allBindingsAccessor, viewModel) {
148.2309 + var eventsToHandle = valueAccessor() || {};
148.2310 + for(var eventNameOutsideClosure in eventsToHandle) {
148.2311 + (function() {
148.2312 + var eventName = eventNameOutsideClosure; // Separate variable to be captured by event handler closure
148.2313 + if (typeof eventName == "string") {
148.2314 + ko.utils.registerEventHandler(element, eventName, function (event) {
148.2315 + var handlerReturnValue;
148.2316 + var handlerFunction = valueAccessor()[eventName];
148.2317 + if (!handlerFunction)
148.2318 + return;
148.2319 + var allBindings = allBindingsAccessor();
148.2320 +
148.2321 + try {
148.2322 + // Take all the event args, and prefix with the viewmodel
148.2323 + var argsForHandler = ko.utils.makeArray(arguments);
148.2324 + argsForHandler.unshift(viewModel);
148.2325 + handlerReturnValue = handlerFunction.apply(viewModel, argsForHandler);
148.2326 + } finally {
148.2327 + if (handlerReturnValue !== true) { // Normally we want to prevent default action. Developer can override this be explicitly returning true.
148.2328 + if (event.preventDefault)
148.2329 + event.preventDefault();
148.2330 + else
148.2331 + event.returnValue = false;
148.2332 + }
148.2333 + }
148.2334 +
148.2335 + var bubble = allBindings[eventName + 'Bubble'] !== false;
148.2336 + if (!bubble) {
148.2337 + event.cancelBubble = true;
148.2338 + if (event.stopPropagation)
148.2339 + event.stopPropagation();
148.2340 + }
148.2341 + });
148.2342 + }
148.2343 + })();
148.2344 + }
148.2345 + }
148.2346 +};
148.2347 +// "foreach: someExpression" is equivalent to "template: { foreach: someExpression }"
148.2348 +// "foreach: { data: someExpression, afterAdd: myfn }" is equivalent to "template: { foreach: someExpression, afterAdd: myfn }"
148.2349 +ko.bindingHandlers['foreach'] = {
148.2350 + makeTemplateValueAccessor: function(valueAccessor) {
148.2351 + return function() {
148.2352 + var modelValue = valueAccessor(),
148.2353 + unwrappedValue = ko.utils.peekObservable(modelValue); // Unwrap without setting a dependency here
148.2354 +
148.2355 + // If unwrappedValue is the array, pass in the wrapped value on its own
148.2356 + // The value will be unwrapped and tracked within the template binding
148.2357 + // (See https://github.com/SteveSanderson/knockout/issues/523)
148.2358 + if ((!unwrappedValue) || typeof unwrappedValue.length == "number")
148.2359 + return { 'foreach': modelValue, 'templateEngine': ko.nativeTemplateEngine.instance };
148.2360 +
148.2361 + // If unwrappedValue.data is the array, preserve all relevant options and unwrap again value so we get updates
148.2362 + ko.utils.unwrapObservable(modelValue);
148.2363 + return {
148.2364 + 'foreach': unwrappedValue['data'],
148.2365 + 'as': unwrappedValue['as'],
148.2366 + 'includeDestroyed': unwrappedValue['includeDestroyed'],
148.2367 + 'afterAdd': unwrappedValue['afterAdd'],
148.2368 + 'beforeRemove': unwrappedValue['beforeRemove'],
148.2369 + 'afterRender': unwrappedValue['afterRender'],
148.2370 + 'beforeMove': unwrappedValue['beforeMove'],
148.2371 + 'afterMove': unwrappedValue['afterMove'],
148.2372 + 'templateEngine': ko.nativeTemplateEngine.instance
148.2373 + };
148.2374 + };
148.2375 + },
148.2376 + 'init': function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
148.2377 + return ko.bindingHandlers['template']['init'](element, ko.bindingHandlers['foreach'].makeTemplateValueAccessor(valueAccessor));
148.2378 + },
148.2379 + 'update': function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
148.2380 + return ko.bindingHandlers['template']['update'](element, ko.bindingHandlers['foreach'].makeTemplateValueAccessor(valueAccessor), allBindingsAccessor, viewModel, bindingContext);
148.2381 + }
148.2382 +};
148.2383 +ko.expressionRewriting.bindingRewriteValidators['foreach'] = false; // Can't rewrite control flow bindings
148.2384 +ko.virtualElements.allowedBindings['foreach'] = true;
148.2385 +var hasfocusUpdatingProperty = '__ko_hasfocusUpdating';
148.2386 +ko.bindingHandlers['hasfocus'] = {
148.2387 + 'init': function(element, valueAccessor, allBindingsAccessor) {
148.2388 + var handleElementFocusChange = function(isFocused) {
148.2389 + // Where possible, ignore which event was raised and determine focus state using activeElement,
148.2390 + // as this avoids phantom focus/blur events raised when changing tabs in modern browsers.
148.2391 + // However, not all KO-targeted browsers (Firefox 2) support activeElement. For those browsers,
148.2392 + // prevent a loss of focus when changing tabs/windows by setting a flag that prevents hasfocus
148.2393 + // from calling 'blur()' on the element when it loses focus.
148.2394 + // Discussion at https://github.com/SteveSanderson/knockout/pull/352
148.2395 + element[hasfocusUpdatingProperty] = true;
148.2396 + var ownerDoc = element.ownerDocument;
148.2397 + if ("activeElement" in ownerDoc) {
148.2398 + isFocused = (ownerDoc.activeElement === element);
148.2399 + }
148.2400 + var modelValue = valueAccessor();
148.2401 + ko.expressionRewriting.writeValueToProperty(modelValue, allBindingsAccessor, 'hasfocus', isFocused, true);
148.2402 + element[hasfocusUpdatingProperty] = false;
148.2403 + };
148.2404 + var handleElementFocusIn = handleElementFocusChange.bind(null, true);
148.2405 + var handleElementFocusOut = handleElementFocusChange.bind(null, false);
148.2406 +
148.2407 + ko.utils.registerEventHandler(element, "focus", handleElementFocusIn);
148.2408 + ko.utils.registerEventHandler(element, "focusin", handleElementFocusIn); // For IE
148.2409 + ko.utils.registerEventHandler(element, "blur", handleElementFocusOut);
148.2410 + ko.utils.registerEventHandler(element, "focusout", handleElementFocusOut); // For IE
148.2411 + },
148.2412 + 'update': function(element, valueAccessor) {
148.2413 + var value = ko.utils.unwrapObservable(valueAccessor());
148.2414 + if (!element[hasfocusUpdatingProperty]) {
148.2415 + value ? element.focus() : element.blur();
148.2416 + ko.dependencyDetection.ignore(ko.utils.triggerEvent, null, [element, value ? "focusin" : "focusout"]); // For IE, which doesn't reliably fire "focus" or "blur" events synchronously
148.2417 + }
148.2418 + }
148.2419 +};
148.2420 +ko.bindingHandlers['html'] = {
148.2421 + 'init': function() {
148.2422 + // Prevent binding on the dynamically-injected HTML (as developers are unlikely to expect that, and it has security implications)
148.2423 + return { 'controlsDescendantBindings': true };
148.2424 + },
148.2425 + 'update': function (element, valueAccessor) {
148.2426 + // setHtml will unwrap the value if needed
148.2427 + ko.utils.setHtml(element, valueAccessor());
148.2428 + }
148.2429 +};
148.2430 +var withIfDomDataKey = '__ko_withIfBindingData';
148.2431 +// Makes a binding like with or if
148.2432 +function makeWithIfBinding(bindingKey, isWith, isNot, makeContextCallback) {
148.2433 + ko.bindingHandlers[bindingKey] = {
148.2434 + 'init': function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
148.2435 + ko.utils.domData.set(element, withIfDomDataKey, {});
148.2436 + return { 'controlsDescendantBindings': true };
148.2437 + },
148.2438 + 'update': function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
148.2439 + var withIfData = ko.utils.domData.get(element, withIfDomDataKey),
148.2440 + dataValue = ko.utils.unwrapObservable(valueAccessor()),
148.2441 + shouldDisplay = !isNot !== !dataValue, // equivalent to isNot ? !dataValue : !!dataValue
148.2442 + isFirstRender = !withIfData.savedNodes,
148.2443 + needsRefresh = isFirstRender || isWith || (shouldDisplay !== withIfData.didDisplayOnLastUpdate);
148.2444 +
148.2445 + if (needsRefresh) {
148.2446 + if (isFirstRender) {
148.2447 + withIfData.savedNodes = ko.utils.cloneNodes(ko.virtualElements.childNodes(element), true /* shouldCleanNodes */);
148.2448 + }
148.2449 +
148.2450 + if (shouldDisplay) {
148.2451 + if (!isFirstRender) {
148.2452 + ko.virtualElements.setDomNodeChildren(element, ko.utils.cloneNodes(withIfData.savedNodes));
148.2453 + }
148.2454 + ko.applyBindingsToDescendants(makeContextCallback ? makeContextCallback(bindingContext, dataValue) : bindingContext, element);
148.2455 + } else {
148.2456 + ko.virtualElements.emptyNode(element);
148.2457 + }
148.2458 +
148.2459 + withIfData.didDisplayOnLastUpdate = shouldDisplay;
148.2460 + }
148.2461 + }
148.2462 + };
148.2463 + ko.expressionRewriting.bindingRewriteValidators[bindingKey] = false; // Can't rewrite control flow bindings
148.2464 + ko.virtualElements.allowedBindings[bindingKey] = true;
148.2465 +}
148.2466 +
148.2467 +// Construct the actual binding handlers
148.2468 +makeWithIfBinding('if');
148.2469 +makeWithIfBinding('ifnot', false /* isWith */, true /* isNot */);
148.2470 +makeWithIfBinding('with', true /* isWith */, false /* isNot */,
148.2471 + function(bindingContext, dataValue) {
148.2472 + return bindingContext['createChildContext'](dataValue);
148.2473 + }
148.2474 +);
148.2475 +function ensureDropdownSelectionIsConsistentWithModelValue(element, modelValue, preferModelValue) {
148.2476 + if (preferModelValue) {
148.2477 + if (modelValue !== ko.selectExtensions.readValue(element))
148.2478 + ko.selectExtensions.writeValue(element, modelValue);
148.2479 + }
148.2480 +
148.2481 + // No matter which direction we're syncing in, we want the end result to be equality between dropdown value and model value.
148.2482 + // If they aren't equal, either we prefer the dropdown value, or the model value couldn't be represented, so either way,
148.2483 + // change the model value to match the dropdown.
148.2484 + if (modelValue !== ko.selectExtensions.readValue(element))
148.2485 + ko.dependencyDetection.ignore(ko.utils.triggerEvent, null, [element, "change"]);
148.2486 +};
148.2487 +
148.2488 +ko.bindingHandlers['options'] = {
148.2489 + 'update': function (element, valueAccessor, allBindingsAccessor) {
148.2490 + if (ko.utils.tagNameLower(element) !== "select")
148.2491 + throw new Error("options binding applies only to SELECT elements");
148.2492 +
148.2493 + var selectWasPreviouslyEmpty = element.length == 0;
148.2494 + var previousSelectedValues = ko.utils.arrayMap(ko.utils.arrayFilter(element.childNodes, function (node) {
148.2495 + return node.tagName && (ko.utils.tagNameLower(node) === "option") && node.selected;
148.2496 + }), function (node) {
148.2497 + return ko.selectExtensions.readValue(node) || node.innerText || node.textContent;
148.2498 + });
148.2499 + var previousScrollTop = element.scrollTop;
148.2500 +
148.2501 + var value = ko.utils.unwrapObservable(valueAccessor());
148.2502 + var selectedValue = element.value;
148.2503 +
148.2504 + // Remove all existing <option>s.
148.2505 + // Need to use .remove() rather than .removeChild() for <option>s otherwise IE behaves oddly (https://github.com/SteveSanderson/knockout/issues/134)
148.2506 + while (element.length > 0) {
148.2507 + ko.cleanNode(element.options[0]);
148.2508 + element.remove(0);
148.2509 + }
148.2510 +
148.2511 + if (value) {
148.2512 + var allBindings = allBindingsAccessor(),
148.2513 + includeDestroyed = allBindings['optionsIncludeDestroyed'];
148.2514 +
148.2515 + if (typeof value.length != "number")
148.2516 + value = [value];
148.2517 + if (allBindings['optionsCaption']) {
148.2518 + var option = document.createElement("option");
148.2519 + ko.utils.setHtml(option, allBindings['optionsCaption']);
148.2520 + ko.selectExtensions.writeValue(option, undefined);
148.2521 + element.appendChild(option);
148.2522 + }
148.2523 +
148.2524 + for (var i = 0, j = value.length; i < j; i++) {
148.2525 + // Skip destroyed items
148.2526 + var arrayEntry = value[i];
148.2527 + if (arrayEntry && arrayEntry['_destroy'] && !includeDestroyed)
148.2528 + continue;
148.2529 +
148.2530 + var option = document.createElement("option");
148.2531 +
148.2532 + function applyToObject(object, predicate, defaultValue) {
148.2533 + var predicateType = typeof predicate;
148.2534 + if (predicateType == "function") // Given a function; run it against the data value
148.2535 + return predicate(object);
148.2536 + else if (predicateType == "string") // Given a string; treat it as a property name on the data value
148.2537 + return object[predicate];
148.2538 + else // Given no optionsText arg; use the data value itself
148.2539 + return defaultValue;
148.2540 + }
148.2541 +
148.2542 + // Apply a value to the option element
148.2543 + var optionValue = applyToObject(arrayEntry, allBindings['optionsValue'], arrayEntry);
148.2544 + ko.selectExtensions.writeValue(option, ko.utils.unwrapObservable(optionValue));
148.2545 +
148.2546 + // Apply some text to the option element
148.2547 + var optionText = applyToObject(arrayEntry, allBindings['optionsText'], optionValue);
148.2548 + ko.utils.setTextContent(option, optionText);
148.2549 +
148.2550 + element.appendChild(option);
148.2551 + }
148.2552 +
148.2553 + // IE6 doesn't like us to assign selection to OPTION nodes before they're added to the document.
148.2554 + // That's why we first added them without selection. Now it's time to set the selection.
148.2555 + var newOptions = element.getElementsByTagName("option");
148.2556 + var countSelectionsRetained = 0;
148.2557 + for (var i = 0, j = newOptions.length; i < j; i++) {
148.2558 + if (ko.utils.arrayIndexOf(previousSelectedValues, ko.selectExtensions.readValue(newOptions[i])) >= 0) {
148.2559 + ko.utils.setOptionNodeSelectionState(newOptions[i], true);
148.2560 + countSelectionsRetained++;
148.2561 + }
148.2562 + }
148.2563 +
148.2564 + element.scrollTop = previousScrollTop;
148.2565 +
148.2566 + if (selectWasPreviouslyEmpty && ('value' in allBindings)) {
148.2567 + // Ensure consistency between model value and selected option.
148.2568 + // If the dropdown is being populated for the first time here (or was otherwise previously empty),
148.2569 + // the dropdown selection state is meaningless, so we preserve the model value.
148.2570 + ensureDropdownSelectionIsConsistentWithModelValue(element, ko.utils.peekObservable(allBindings['value']), /* preferModelValue */ true);
148.2571 + }
148.2572 +
148.2573 + // Workaround for IE9 bug
148.2574 + ko.utils.ensureSelectElementIsRenderedCorrectly(element);
148.2575 + }
148.2576 + }
148.2577 +};
148.2578 +ko.bindingHandlers['options'].optionValueDomDataKey = '__ko.optionValueDomData__';
148.2579 +ko.bindingHandlers['selectedOptions'] = {
148.2580 + 'init': function (element, valueAccessor, allBindingsAccessor) {
148.2581 + ko.utils.registerEventHandler(element, "change", function () {
148.2582 + var value = valueAccessor(), valueToWrite = [];
148.2583 + ko.utils.arrayForEach(element.getElementsByTagName("option"), function(node) {
148.2584 + if (node.selected)
148.2585 + valueToWrite.push(ko.selectExtensions.readValue(node));
148.2586 + });
148.2587 + ko.expressionRewriting.writeValueToProperty(value, allBindingsAccessor, 'value', valueToWrite);
148.2588 + });
148.2589 + },
148.2590 + 'update': function (element, valueAccessor) {
148.2591 + if (ko.utils.tagNameLower(element) != "select")
148.2592 + throw new Error("values binding applies only to SELECT elements");
148.2593 +
148.2594 + var newValue = ko.utils.unwrapObservable(valueAccessor());
148.2595 + if (newValue && typeof newValue.length == "number") {
148.2596 + ko.utils.arrayForEach(element.getElementsByTagName("option"), function(node) {
148.2597 + var isSelected = ko.utils.arrayIndexOf(newValue, ko.selectExtensions.readValue(node)) >= 0;
148.2598 + ko.utils.setOptionNodeSelectionState(node, isSelected);
148.2599 + });
148.2600 + }
148.2601 + }
148.2602 +};
148.2603 +ko.bindingHandlers['style'] = {
148.2604 + 'update': function (element, valueAccessor) {
148.2605 + var value = ko.utils.unwrapObservable(valueAccessor() || {});
148.2606 + for (var styleName in value) {
148.2607 + if (typeof styleName == "string") {
148.2608 + var styleValue = ko.utils.unwrapObservable(value[styleName]);
148.2609 + element.style[styleName] = styleValue || ""; // Empty string removes the value, whereas null/undefined have no effect
148.2610 + }
148.2611 + }
148.2612 + }
148.2613 +};
148.2614 +ko.bindingHandlers['submit'] = {
148.2615 + 'init': function (element, valueAccessor, allBindingsAccessor, viewModel) {
148.2616 + if (typeof valueAccessor() != "function")
148.2617 + throw new Error("The value for a submit binding must be a function");
148.2618 + ko.utils.registerEventHandler(element, "submit", function (event) {
148.2619 + var handlerReturnValue;
148.2620 + var value = valueAccessor();
148.2621 + try { handlerReturnValue = value.call(viewModel, element); }
148.2622 + finally {
148.2623 + if (handlerReturnValue !== true) { // Normally we want to prevent default action. Developer can override this be explicitly returning true.
148.2624 + if (event.preventDefault)
148.2625 + event.preventDefault();
148.2626 + else
148.2627 + event.returnValue = false;
148.2628 + }
148.2629 + }
148.2630 + });
148.2631 + }
148.2632 +};
148.2633 +ko.bindingHandlers['text'] = {
148.2634 + 'update': function (element, valueAccessor) {
148.2635 + ko.utils.setTextContent(element, valueAccessor());
148.2636 + }
148.2637 +};
148.2638 +ko.virtualElements.allowedBindings['text'] = true;
148.2639 +ko.bindingHandlers['uniqueName'] = {
148.2640 + 'init': function (element, valueAccessor) {
148.2641 + if (valueAccessor()) {
148.2642 + var name = "ko_unique_" + (++ko.bindingHandlers['uniqueName'].currentIndex);
148.2643 + ko.utils.setElementName(element, name);
148.2644 + }
148.2645 + }
148.2646 +};
148.2647 +ko.bindingHandlers['uniqueName'].currentIndex = 0;
148.2648 +ko.bindingHandlers['value'] = {
148.2649 + 'init': function (element, valueAccessor, allBindingsAccessor) {
148.2650 + // Always catch "change" event; possibly other events too if asked
148.2651 + var eventsToCatch = ["change"];
148.2652 + var requestedEventsToCatch = allBindingsAccessor()["valueUpdate"];
148.2653 + var propertyChangedFired = false;
148.2654 + if (requestedEventsToCatch) {
148.2655 + if (typeof requestedEventsToCatch == "string") // Allow both individual event names, and arrays of event names
148.2656 + requestedEventsToCatch = [requestedEventsToCatch];
148.2657 + ko.utils.arrayPushAll(eventsToCatch, requestedEventsToCatch);
148.2658 + eventsToCatch = ko.utils.arrayGetDistinctValues(eventsToCatch);
148.2659 + }
148.2660 +
148.2661 + var valueUpdateHandler = function() {
148.2662 + propertyChangedFired = false;
148.2663 + var modelValue = valueAccessor();
148.2664 + var elementValue = ko.selectExtensions.readValue(element);
148.2665 + ko.expressionRewriting.writeValueToProperty(modelValue, allBindingsAccessor, 'value', elementValue);
148.2666 + }
148.2667 +
148.2668 + // Workaround for https://github.com/SteveSanderson/knockout/issues/122
148.2669 + // IE doesn't fire "change" events on textboxes if the user selects a value from its autocomplete list
148.2670 + var ieAutoCompleteHackNeeded = ko.utils.ieVersion && element.tagName.toLowerCase() == "input" && element.type == "text"
148.2671 + && element.autocomplete != "off" && (!element.form || element.form.autocomplete != "off");
148.2672 + if (ieAutoCompleteHackNeeded && ko.utils.arrayIndexOf(eventsToCatch, "propertychange") == -1) {
148.2673 + ko.utils.registerEventHandler(element, "propertychange", function () { propertyChangedFired = true });
148.2674 + ko.utils.registerEventHandler(element, "blur", function() {
148.2675 + if (propertyChangedFired) {
148.2676 + valueUpdateHandler();
148.2677 + }
148.2678 + });
148.2679 + }
148.2680 +
148.2681 + ko.utils.arrayForEach(eventsToCatch, function(eventName) {
148.2682 + // The syntax "after<eventname>" means "run the handler asynchronously after the event"
148.2683 + // This is useful, for example, to catch "keydown" events after the browser has updated the control
148.2684 + // (otherwise, ko.selectExtensions.readValue(this) will receive the control's value *before* the key event)
148.2685 + var handler = valueUpdateHandler;
148.2686 + if (ko.utils.stringStartsWith(eventName, "after")) {
148.2687 + handler = function() { setTimeout(valueUpdateHandler, 0) };
148.2688 + eventName = eventName.substring("after".length);
148.2689 + }
148.2690 + ko.utils.registerEventHandler(element, eventName, handler);
148.2691 + });
148.2692 + },
148.2693 + 'update': function (element, valueAccessor) {
148.2694 + var valueIsSelectOption = ko.utils.tagNameLower(element) === "select";
148.2695 + var newValue = ko.utils.unwrapObservable(valueAccessor());
148.2696 + var elementValue = ko.selectExtensions.readValue(element);
148.2697 + var valueHasChanged = (newValue != elementValue);
148.2698 +
148.2699 + // JavaScript's 0 == "" behavious is unfortunate here as it prevents writing 0 to an empty text box (loose equality suggests the values are the same).
148.2700 + // We don't want to do a strict equality comparison as that is more confusing for developers in certain cases, so we specifically special case 0 != "" here.
148.2701 + if ((newValue === 0) && (elementValue !== 0) && (elementValue !== "0"))
148.2702 + valueHasChanged = true;
148.2703 +
148.2704 + if (valueHasChanged) {
148.2705 + var applyValueAction = function () { ko.selectExtensions.writeValue(element, newValue); };
148.2706 + applyValueAction();
148.2707 +
148.2708 + // Workaround for IE6 bug: It won't reliably apply values to SELECT nodes during the same execution thread
148.2709 + // right after you've changed the set of OPTION nodes on it. So for that node type, we'll schedule a second thread
148.2710 + // to apply the value as well.
148.2711 + var alsoApplyAsynchronously = valueIsSelectOption;
148.2712 + if (alsoApplyAsynchronously)
148.2713 + setTimeout(applyValueAction, 0);
148.2714 + }
148.2715 +
148.2716 + // If you try to set a model value that can't be represented in an already-populated dropdown, reject that change,
148.2717 + // because you're not allowed to have a model value that disagrees with a visible UI selection.
148.2718 + if (valueIsSelectOption && (element.length > 0))
148.2719 + ensureDropdownSelectionIsConsistentWithModelValue(element, newValue, /* preferModelValue */ false);
148.2720 + }
148.2721 +};
148.2722 +ko.bindingHandlers['visible'] = {
148.2723 + 'update': function (element, valueAccessor) {
148.2724 + var value = ko.utils.unwrapObservable(valueAccessor());
148.2725 + var isCurrentlyVisible = !(element.style.display == "none");
148.2726 + if (value && !isCurrentlyVisible)
148.2727 + element.style.display = "";
148.2728 + else if ((!value) && isCurrentlyVisible)
148.2729 + element.style.display = "none";
148.2730 + }
148.2731 +};
148.2732 +// 'click' is just a shorthand for the usual full-length event:{click:handler}
148.2733 +makeEventHandlerShortcut('click');
148.2734 +// If you want to make a custom template engine,
148.2735 +//
148.2736 +// [1] Inherit from this class (like ko.nativeTemplateEngine does)
148.2737 +// [2] Override 'renderTemplateSource', supplying a function with this signature:
148.2738 +//
148.2739 +// function (templateSource, bindingContext, options) {
148.2740 +// // - templateSource.text() is the text of the template you should render
148.2741 +// // - bindingContext.$data is the data you should pass into the template
148.2742 +// // - you might also want to make bindingContext.$parent, bindingContext.$parents,
148.2743 +// // and bindingContext.$root available in the template too
148.2744 +// // - options gives you access to any other properties set on "data-bind: { template: options }"
148.2745 +// //
148.2746 +// // Return value: an array of DOM nodes
148.2747 +// }
148.2748 +//
148.2749 +// [3] Override 'createJavaScriptEvaluatorBlock', supplying a function with this signature:
148.2750 +//
148.2751 +// function (script) {
148.2752 +// // Return value: Whatever syntax means "Evaluate the JavaScript statement 'script' and output the result"
148.2753 +// // For example, the jquery.tmpl template engine converts 'someScript' to '${ someScript }'
148.2754 +// }
148.2755 +//
148.2756 +// This is only necessary if you want to allow data-bind attributes to reference arbitrary template variables.
148.2757 +// If you don't want to allow that, you can set the property 'allowTemplateRewriting' to false (like ko.nativeTemplateEngine does)
148.2758 +// and then you don't need to override 'createJavaScriptEvaluatorBlock'.
148.2759 +
148.2760 +ko.templateEngine = function () { };
148.2761 +
148.2762 +ko.templateEngine.prototype['renderTemplateSource'] = function (templateSource, bindingContext, options) {
148.2763 + throw new Error("Override renderTemplateSource");
148.2764 +};
148.2765 +
148.2766 +ko.templateEngine.prototype['createJavaScriptEvaluatorBlock'] = function (script) {
148.2767 + throw new Error("Override createJavaScriptEvaluatorBlock");
148.2768 +};
148.2769 +
148.2770 +ko.templateEngine.prototype['makeTemplateSource'] = function(template, templateDocument) {
148.2771 + // Named template
148.2772 + if (typeof template == "string") {
148.2773 + templateDocument = templateDocument || document;
148.2774 + var elem = templateDocument.getElementById(template);
148.2775 + if (!elem)
148.2776 + throw new Error("Cannot find template with ID " + template);
148.2777 + return new ko.templateSources.domElement(elem);
148.2778 + } else if ((template.nodeType == 1) || (template.nodeType == 8)) {
148.2779 + // Anonymous template
148.2780 + return new ko.templateSources.anonymousTemplate(template);
148.2781 + } else
148.2782 + throw new Error("Unknown template type: " + template);
148.2783 +};
148.2784 +
148.2785 +ko.templateEngine.prototype['renderTemplate'] = function (template, bindingContext, options, templateDocument) {
148.2786 + var templateSource = this['makeTemplateSource'](template, templateDocument);
148.2787 + return this['renderTemplateSource'](templateSource, bindingContext, options);
148.2788 +};
148.2789 +
148.2790 +ko.templateEngine.prototype['isTemplateRewritten'] = function (template, templateDocument) {
148.2791 + // Skip rewriting if requested
148.2792 + if (this['allowTemplateRewriting'] === false)
148.2793 + return true;
148.2794 + return this['makeTemplateSource'](template, templateDocument)['data']("isRewritten");
148.2795 +};
148.2796 +
148.2797 +ko.templateEngine.prototype['rewriteTemplate'] = function (template, rewriterCallback, templateDocument) {
148.2798 + var templateSource = this['makeTemplateSource'](template, templateDocument);
148.2799 + var rewritten = rewriterCallback(templateSource['text']());
148.2800 + templateSource['text'](rewritten);
148.2801 + templateSource['data']("isRewritten", true);
148.2802 +};
148.2803 +
148.2804 +ko.exportSymbol('templateEngine', ko.templateEngine);
148.2805 +
148.2806 +ko.templateRewriting = (function () {
148.2807 + var memoizeDataBindingAttributeSyntaxRegex = /(<[a-z]+\d*(\s+(?!data-bind=)[a-z0-9\-]+(=(\"[^\"]*\"|\'[^\']*\'))?)*\s+)data-bind=(["'])([\s\S]*?)\5/gi;
148.2808 + var memoizeVirtualContainerBindingSyntaxRegex = /<!--\s*ko\b\s*([\s\S]*?)\s*-->/g;
148.2809 +
148.2810 + function validateDataBindValuesForRewriting(keyValueArray) {
148.2811 + var allValidators = ko.expressionRewriting.bindingRewriteValidators;
148.2812 + for (var i = 0; i < keyValueArray.length; i++) {
148.2813 + var key = keyValueArray[i]['key'];
148.2814 + if (allValidators.hasOwnProperty(key)) {
148.2815 + var validator = allValidators[key];
148.2816 +
148.2817 + if (typeof validator === "function") {
148.2818 + var possibleErrorMessage = validator(keyValueArray[i]['value']);
148.2819 + if (possibleErrorMessage)
148.2820 + throw new Error(possibleErrorMessage);
148.2821 + } else if (!validator) {
148.2822 + throw new Error("This template engine does not support the '" + key + "' binding within its templates");
148.2823 + }
148.2824 + }
148.2825 + }
148.2826 + }
148.2827 +
148.2828 + function constructMemoizedTagReplacement(dataBindAttributeValue, tagToRetain, templateEngine) {
148.2829 + var dataBindKeyValueArray = ko.expressionRewriting.parseObjectLiteral(dataBindAttributeValue);
148.2830 + validateDataBindValuesForRewriting(dataBindKeyValueArray);
148.2831 + var rewrittenDataBindAttributeValue = ko.expressionRewriting.preProcessBindings(dataBindKeyValueArray);
148.2832 +
148.2833 + // For no obvious reason, Opera fails to evaluate rewrittenDataBindAttributeValue unless it's wrapped in an additional
148.2834 + // anonymous function, even though Opera's built-in debugger can evaluate it anyway. No other browser requires this
148.2835 + // extra indirection.
148.2836 + var applyBindingsToNextSiblingScript =
148.2837 + "ko.__tr_ambtns(function($context,$element){return(function(){return{ " + rewrittenDataBindAttributeValue + " } })()})";
148.2838 + return templateEngine['createJavaScriptEvaluatorBlock'](applyBindingsToNextSiblingScript) + tagToRetain;
148.2839 + }
148.2840 +
148.2841 + return {
148.2842 + ensureTemplateIsRewritten: function (template, templateEngine, templateDocument) {
148.2843 + if (!templateEngine['isTemplateRewritten'](template, templateDocument))
148.2844 + templateEngine['rewriteTemplate'](template, function (htmlString) {
148.2845 + return ko.templateRewriting.memoizeBindingAttributeSyntax(htmlString, templateEngine);
148.2846 + }, templateDocument);
148.2847 + },
148.2848 +
148.2849 + memoizeBindingAttributeSyntax: function (htmlString, templateEngine) {
148.2850 + return htmlString.replace(memoizeDataBindingAttributeSyntaxRegex, function () {
148.2851 + return constructMemoizedTagReplacement(/* dataBindAttributeValue: */ arguments[6], /* tagToRetain: */ arguments[1], templateEngine);
148.2852 + }).replace(memoizeVirtualContainerBindingSyntaxRegex, function() {
148.2853 + return constructMemoizedTagReplacement(/* dataBindAttributeValue: */ arguments[1], /* tagToRetain: */ "<!-- ko -->", templateEngine);
148.2854 + });
148.2855 + },
148.2856 +
148.2857 + applyMemoizedBindingsToNextSibling: function (bindings) {
148.2858 + return ko.memoization.memoize(function (domNode, bindingContext) {
148.2859 + if (domNode.nextSibling)
148.2860 + ko.applyBindingsToNode(domNode.nextSibling, bindings, bindingContext);
148.2861 + });
148.2862 + }
148.2863 + }
148.2864 +})();
148.2865 +
148.2866 +
148.2867 +// Exported only because it has to be referenced by string lookup from within rewritten template
148.2868 +ko.exportSymbol('__tr_ambtns', ko.templateRewriting.applyMemoizedBindingsToNextSibling);
148.2869 +(function() {
148.2870 + // A template source represents a read/write way of accessing a template. This is to eliminate the need for template loading/saving
148.2871 + // logic to be duplicated in every template engine (and means they can all work with anonymous templates, etc.)
148.2872 + //
148.2873 + // Two are provided by default:
148.2874 + // 1. ko.templateSources.domElement - reads/writes the text content of an arbitrary DOM element
148.2875 + // 2. ko.templateSources.anonymousElement - uses ko.utils.domData to read/write text *associated* with the DOM element, but
148.2876 + // without reading/writing the actual element text content, since it will be overwritten
148.2877 + // with the rendered template output.
148.2878 + // You can implement your own template source if you want to fetch/store templates somewhere other than in DOM elements.
148.2879 + // Template sources need to have the following functions:
148.2880 + // text() - returns the template text from your storage location
148.2881 + // text(value) - writes the supplied template text to your storage location
148.2882 + // data(key) - reads values stored using data(key, value) - see below
148.2883 + // data(key, value) - associates "value" with this template and the key "key". Is used to store information like "isRewritten".
148.2884 + //
148.2885 + // Optionally, template sources can also have the following functions:
148.2886 + // nodes() - returns a DOM element containing the nodes of this template, where available
148.2887 + // nodes(value) - writes the given DOM element to your storage location
148.2888 + // If a DOM element is available for a given template source, template engines are encouraged to use it in preference over text()
148.2889 + // for improved speed. However, all templateSources must supply text() even if they don't supply nodes().
148.2890 + //
148.2891 + // Once you've implemented a templateSource, make your template engine use it by subclassing whatever template engine you were
148.2892 + // using and overriding "makeTemplateSource" to return an instance of your custom template source.
148.2893 +
148.2894 + ko.templateSources = {};
148.2895 +
148.2896 + // ---- ko.templateSources.domElement -----
148.2897 +
148.2898 + ko.templateSources.domElement = function(element) {
148.2899 + this.domElement = element;
148.2900 + }
148.2901 +
148.2902 + ko.templateSources.domElement.prototype['text'] = function(/* valueToWrite */) {
148.2903 + var tagNameLower = ko.utils.tagNameLower(this.domElement),
148.2904 + elemContentsProperty = tagNameLower === "script" ? "text"
148.2905 + : tagNameLower === "textarea" ? "value"
148.2906 + : "innerHTML";
148.2907 +
148.2908 + if (arguments.length == 0) {
148.2909 + return this.domElement[elemContentsProperty];
148.2910 + } else {
148.2911 + var valueToWrite = arguments[0];
148.2912 + if (elemContentsProperty === "innerHTML")
148.2913 + ko.utils.setHtml(this.domElement, valueToWrite);
148.2914 + else
148.2915 + this.domElement[elemContentsProperty] = valueToWrite;
148.2916 + }
148.2917 + };
148.2918 +
148.2919 + ko.templateSources.domElement.prototype['data'] = function(key /*, valueToWrite */) {
148.2920 + if (arguments.length === 1) {
148.2921 + return ko.utils.domData.get(this.domElement, "templateSourceData_" + key);
148.2922 + } else {
148.2923 + ko.utils.domData.set(this.domElement, "templateSourceData_" + key, arguments[1]);
148.2924 + }
148.2925 + };
148.2926 +
148.2927 + // ---- ko.templateSources.anonymousTemplate -----
148.2928 + // Anonymous templates are normally saved/retrieved as DOM nodes through "nodes".
148.2929 + // For compatibility, you can also read "text"; it will be serialized from the nodes on demand.
148.2930 + // Writing to "text" is still supported, but then the template data will not be available as DOM nodes.
148.2931 +
148.2932 + var anonymousTemplatesDomDataKey = "__ko_anon_template__";
148.2933 + ko.templateSources.anonymousTemplate = function(element) {
148.2934 + this.domElement = element;
148.2935 + }
148.2936 + ko.templateSources.anonymousTemplate.prototype = new ko.templateSources.domElement();
148.2937 + ko.templateSources.anonymousTemplate.prototype['text'] = function(/* valueToWrite */) {
148.2938 + if (arguments.length == 0) {
148.2939 + var templateData = ko.utils.domData.get(this.domElement, anonymousTemplatesDomDataKey) || {};
148.2940 + if (templateData.textData === undefined && templateData.containerData)
148.2941 + templateData.textData = templateData.containerData.innerHTML;
148.2942 + return templateData.textData;
148.2943 + } else {
148.2944 + var valueToWrite = arguments[0];
148.2945 + ko.utils.domData.set(this.domElement, anonymousTemplatesDomDataKey, {textData: valueToWrite});
148.2946 + }
148.2947 + };
148.2948 + ko.templateSources.domElement.prototype['nodes'] = function(/* valueToWrite */) {
148.2949 + if (arguments.length == 0) {
148.2950 + var templateData = ko.utils.domData.get(this.domElement, anonymousTemplatesDomDataKey) || {};
148.2951 + return templateData.containerData;
148.2952 + } else {
148.2953 + var valueToWrite = arguments[0];
148.2954 + ko.utils.domData.set(this.domElement, anonymousTemplatesDomDataKey, {containerData: valueToWrite});
148.2955 + }
148.2956 + };
148.2957 +
148.2958 + ko.exportSymbol('templateSources', ko.templateSources);
148.2959 + ko.exportSymbol('templateSources.domElement', ko.templateSources.domElement);
148.2960 + ko.exportSymbol('templateSources.anonymousTemplate', ko.templateSources.anonymousTemplate);
148.2961 +})();
148.2962 +(function () {
148.2963 + var _templateEngine;
148.2964 + ko.setTemplateEngine = function (templateEngine) {
148.2965 + if ((templateEngine != undefined) && !(templateEngine instanceof ko.templateEngine))
148.2966 + throw new Error("templateEngine must inherit from ko.templateEngine");
148.2967 + _templateEngine = templateEngine;
148.2968 + }
148.2969 +
148.2970 + function invokeForEachNodeOrCommentInContinuousRange(firstNode, lastNode, action) {
148.2971 + var node, nextInQueue = firstNode, firstOutOfRangeNode = ko.virtualElements.nextSibling(lastNode);
148.2972 + while (nextInQueue && ((node = nextInQueue) !== firstOutOfRangeNode)) {
148.2973 + nextInQueue = ko.virtualElements.nextSibling(node);
148.2974 + if (node.nodeType === 1 || node.nodeType === 8)
148.2975 + action(node);
148.2976 + }
148.2977 + }
148.2978 +
148.2979 + function activateBindingsOnContinuousNodeArray(continuousNodeArray, bindingContext) {
148.2980 + // To be used on any nodes that have been rendered by a template and have been inserted into some parent element
148.2981 + // Walks through continuousNodeArray (which *must* be continuous, i.e., an uninterrupted sequence of sibling nodes, because
148.2982 + // the algorithm for walking them relies on this), and for each top-level item in the virtual-element sense,
148.2983 + // (1) Does a regular "applyBindings" to associate bindingContext with this node and to activate any non-memoized bindings
148.2984 + // (2) Unmemoizes any memos in the DOM subtree (e.g., to activate bindings that had been memoized during template rewriting)
148.2985 +
148.2986 + if (continuousNodeArray.length) {
148.2987 + var firstNode = continuousNodeArray[0], lastNode = continuousNodeArray[continuousNodeArray.length - 1];
148.2988 +
148.2989 + // Need to applyBindings *before* unmemoziation, because unmemoization might introduce extra nodes (that we don't want to re-bind)
148.2990 + // whereas a regular applyBindings won't introduce new memoized nodes
148.2991 + invokeForEachNodeOrCommentInContinuousRange(firstNode, lastNode, function(node) {
148.2992 + ko.applyBindings(bindingContext, node);
148.2993 + });
148.2994 + invokeForEachNodeOrCommentInContinuousRange(firstNode, lastNode, function(node) {
148.2995 + ko.memoization.unmemoizeDomNodeAndDescendants(node, [bindingContext]);
148.2996 + });
148.2997 + }
148.2998 + }
148.2999 +
148.3000 + function getFirstNodeFromPossibleArray(nodeOrNodeArray) {
148.3001 + return nodeOrNodeArray.nodeType ? nodeOrNodeArray
148.3002 + : nodeOrNodeArray.length > 0 ? nodeOrNodeArray[0]
148.3003 + : null;
148.3004 + }
148.3005 +
148.3006 + function executeTemplate(targetNodeOrNodeArray, renderMode, template, bindingContext, options) {
148.3007 + options = options || {};
148.3008 + var firstTargetNode = targetNodeOrNodeArray && getFirstNodeFromPossibleArray(targetNodeOrNodeArray);
148.3009 + var templateDocument = firstTargetNode && firstTargetNode.ownerDocument;
148.3010 + var templateEngineToUse = (options['templateEngine'] || _templateEngine);
148.3011 + ko.templateRewriting.ensureTemplateIsRewritten(template, templateEngineToUse, templateDocument);
148.3012 + var renderedNodesArray = templateEngineToUse['renderTemplate'](template, bindingContext, options, templateDocument);
148.3013 +
148.3014 + // Loosely check result is an array of DOM nodes
148.3015 + if ((typeof renderedNodesArray.length != "number") || (renderedNodesArray.length > 0 && typeof renderedNodesArray[0].nodeType != "number"))
148.3016 + throw new Error("Template engine must return an array of DOM nodes");
148.3017 +
148.3018 + var haveAddedNodesToParent = false;
148.3019 + switch (renderMode) {
148.3020 + case "replaceChildren":
148.3021 + ko.virtualElements.setDomNodeChildren(targetNodeOrNodeArray, renderedNodesArray);
148.3022 + haveAddedNodesToParent = true;
148.3023 + break;
148.3024 + case "replaceNode":
148.3025 + ko.utils.replaceDomNodes(targetNodeOrNodeArray, renderedNodesArray);
148.3026 + haveAddedNodesToParent = true;
148.3027 + break;
148.3028 + case "ignoreTargetNode": break;
148.3029 + default:
148.3030 + throw new Error("Unknown renderMode: " + renderMode);
148.3031 + }
148.3032 +
148.3033 + if (haveAddedNodesToParent) {
148.3034 + activateBindingsOnContinuousNodeArray(renderedNodesArray, bindingContext);
148.3035 + if (options['afterRender'])
148.3036 + ko.dependencyDetection.ignore(options['afterRender'], null, [renderedNodesArray, bindingContext['$data']]);
148.3037 + }
148.3038 +
148.3039 + return renderedNodesArray;
148.3040 + }
148.3041 +
148.3042 + ko.renderTemplate = function (template, dataOrBindingContext, options, targetNodeOrNodeArray, renderMode) {
148.3043 + options = options || {};
148.3044 + if ((options['templateEngine'] || _templateEngine) == undefined)
148.3045 + throw new Error("Set a template engine before calling renderTemplate");
148.3046 + renderMode = renderMode || "replaceChildren";
148.3047 +
148.3048 + if (targetNodeOrNodeArray) {
148.3049 + var firstTargetNode = getFirstNodeFromPossibleArray(targetNodeOrNodeArray);
148.3050 +
148.3051 + var whenToDispose = function () { return (!firstTargetNode) || !ko.utils.domNodeIsAttachedToDocument(firstTargetNode); }; // Passive disposal (on next evaluation)
148.3052 + var activelyDisposeWhenNodeIsRemoved = (firstTargetNode && renderMode == "replaceNode") ? firstTargetNode.parentNode : firstTargetNode;
148.3053 +
148.3054 + return ko.dependentObservable( // So the DOM is automatically updated when any dependency changes
148.3055 + function () {
148.3056 + // Ensure we've got a proper binding context to work with
148.3057 + var bindingContext = (dataOrBindingContext && (dataOrBindingContext instanceof ko.bindingContext))
148.3058 + ? dataOrBindingContext
148.3059 + : new ko.bindingContext(ko.utils.unwrapObservable(dataOrBindingContext));
148.3060 +
148.3061 + // Support selecting template as a function of the data being rendered
148.3062 + var templateName = typeof(template) == 'function' ? template(bindingContext['$data'], bindingContext) : template;
148.3063 +
148.3064 + var renderedNodesArray = executeTemplate(targetNodeOrNodeArray, renderMode, templateName, bindingContext, options);
148.3065 + if (renderMode == "replaceNode") {
148.3066 + targetNodeOrNodeArray = renderedNodesArray;
148.3067 + firstTargetNode = getFirstNodeFromPossibleArray(targetNodeOrNodeArray);
148.3068 + }
148.3069 + },
148.3070 + null,
148.3071 + { disposeWhen: whenToDispose, disposeWhenNodeIsRemoved: activelyDisposeWhenNodeIsRemoved }
148.3072 + );
148.3073 + } else {
148.3074 + // We don't yet have a DOM node to evaluate, so use a memo and render the template later when there is a DOM node
148.3075 + return ko.memoization.memoize(function (domNode) {
148.3076 + ko.renderTemplate(template, dataOrBindingContext, options, domNode, "replaceNode");
148.3077 + });
148.3078 + }
148.3079 + };
148.3080 +
148.3081 + ko.renderTemplateForEach = function (template, arrayOrObservableArray, options, targetNode, parentBindingContext) {
148.3082 + // Since setDomNodeChildrenFromArrayMapping always calls executeTemplateForArrayItem and then
148.3083 + // activateBindingsCallback for added items, we can store the binding context in the former to use in the latter.
148.3084 + var arrayItemContext;
148.3085 +
148.3086 + // This will be called by setDomNodeChildrenFromArrayMapping to get the nodes to add to targetNode
148.3087 + var executeTemplateForArrayItem = function (arrayValue, index) {
148.3088 + // Support selecting template as a function of the data being rendered
148.3089 + arrayItemContext = parentBindingContext['createChildContext'](ko.utils.unwrapObservable(arrayValue), options['as']);
148.3090 + arrayItemContext['$index'] = index;
148.3091 + var templateName = typeof(template) == 'function' ? template(arrayValue, arrayItemContext) : template;
148.3092 + return executeTemplate(null, "ignoreTargetNode", templateName, arrayItemContext, options);
148.3093 + }
148.3094 +
148.3095 + // This will be called whenever setDomNodeChildrenFromArrayMapping has added nodes to targetNode
148.3096 + var activateBindingsCallback = function(arrayValue, addedNodesArray, index) {
148.3097 + activateBindingsOnContinuousNodeArray(addedNodesArray, arrayItemContext);
148.3098 + if (options['afterRender'])
148.3099 + options['afterRender'](addedNodesArray, arrayValue);
148.3100 + };
148.3101 +
148.3102 + return ko.dependentObservable(function () {
148.3103 + var unwrappedArray = ko.utils.unwrapObservable(arrayOrObservableArray) || [];
148.3104 + if (typeof unwrappedArray.length == "undefined") // Coerce single value into array
148.3105 + unwrappedArray = [unwrappedArray];
148.3106 +
148.3107 + // Filter out any entries marked as destroyed
148.3108 + var filteredArray = ko.utils.arrayFilter(unwrappedArray, function(item) {
148.3109 + return options['includeDestroyed'] || item === undefined || item === null || !ko.utils.unwrapObservable(item['_destroy']);
148.3110 + });
148.3111 +
148.3112 + // Call setDomNodeChildrenFromArrayMapping, ignoring any observables unwrapped within (most likely from a callback function).
148.3113 + // If the array items are observables, though, they will be unwrapped in executeTemplateForArrayItem and managed within setDomNodeChildrenFromArrayMapping.
148.3114 + ko.dependencyDetection.ignore(ko.utils.setDomNodeChildrenFromArrayMapping, null, [targetNode, filteredArray, executeTemplateForArrayItem, options, activateBindingsCallback]);
148.3115 +
148.3116 + }, null, { disposeWhenNodeIsRemoved: targetNode });
148.3117 + };
148.3118 +
148.3119 + var templateComputedDomDataKey = '__ko__templateComputedDomDataKey__';
148.3120 + function disposeOldComputedAndStoreNewOne(element, newComputed) {
148.3121 + var oldComputed = ko.utils.domData.get(element, templateComputedDomDataKey);
148.3122 + if (oldComputed && (typeof(oldComputed.dispose) == 'function'))
148.3123 + oldComputed.dispose();
148.3124 + ko.utils.domData.set(element, templateComputedDomDataKey, (newComputed && newComputed.isActive()) ? newComputed : undefined);
148.3125 + }
148.3126 +
148.3127 + ko.bindingHandlers['template'] = {
148.3128 + 'init': function(element, valueAccessor) {
148.3129 + // Support anonymous templates
148.3130 + var bindingValue = ko.utils.unwrapObservable(valueAccessor());
148.3131 + if ((typeof bindingValue != "string") && (!bindingValue['name']) && (element.nodeType == 1 || element.nodeType == 8)) {
148.3132 + // It's an anonymous template - store the element contents, then clear the element
148.3133 + var templateNodes = element.nodeType == 1 ? element.childNodes : ko.virtualElements.childNodes(element),
148.3134 + container = ko.utils.moveCleanedNodesToContainerElement(templateNodes); // This also removes the nodes from their current parent
148.3135 + new ko.templateSources.anonymousTemplate(element)['nodes'](container);
148.3136 + }
148.3137 + return { 'controlsDescendantBindings': true };
148.3138 + },
148.3139 + 'update': function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
148.3140 + var templateName = ko.utils.unwrapObservable(valueAccessor()),
148.3141 + options = {},
148.3142 + shouldDisplay = true,
148.3143 + dataValue,
148.3144 + templateComputed = null;
148.3145 +
148.3146 + if (typeof templateName != "string") {
148.3147 + options = templateName;
148.3148 + templateName = options['name'];
148.3149 +
148.3150 + // Support "if"/"ifnot" conditions
148.3151 + if ('if' in options)
148.3152 + shouldDisplay = ko.utils.unwrapObservable(options['if']);
148.3153 + if (shouldDisplay && 'ifnot' in options)
148.3154 + shouldDisplay = !ko.utils.unwrapObservable(options['ifnot']);
148.3155 +
148.3156 + dataValue = ko.utils.unwrapObservable(options['data']);
148.3157 + }
148.3158 +
148.3159 + if ('foreach' in options) {
148.3160 + // Render once for each data point (treating data set as empty if shouldDisplay==false)
148.3161 + var dataArray = (shouldDisplay && options['foreach']) || [];
148.3162 + templateComputed = ko.renderTemplateForEach(templateName || element, dataArray, options, element, bindingContext);
148.3163 + } else if (!shouldDisplay) {
148.3164 + ko.virtualElements.emptyNode(element);
148.3165 + } else {
148.3166 + // Render once for this single data point (or use the viewModel if no data was provided)
148.3167 + var innerBindingContext = ('data' in options) ?
148.3168 + bindingContext['createChildContext'](dataValue, options['as']) : // Given an explitit 'data' value, we create a child binding context for it
148.3169 + bindingContext; // Given no explicit 'data' value, we retain the same binding context
148.3170 + templateComputed = ko.renderTemplate(templateName || element, innerBindingContext, options, element);
148.3171 + }
148.3172 +
148.3173 + // It only makes sense to have a single template computed per element (otherwise which one should have its output displayed?)
148.3174 + disposeOldComputedAndStoreNewOne(element, templateComputed);
148.3175 + }
148.3176 + };
148.3177 +
148.3178 + // Anonymous templates can't be rewritten. Give a nice error message if you try to do it.
148.3179 + ko.expressionRewriting.bindingRewriteValidators['template'] = function(bindingValue) {
148.3180 + var parsedBindingValue = ko.expressionRewriting.parseObjectLiteral(bindingValue);
148.3181 +
148.3182 + if ((parsedBindingValue.length == 1) && parsedBindingValue[0]['unknown'])
148.3183 + return null; // It looks like a string literal, not an object literal, so treat it as a named template (which is allowed for rewriting)
148.3184 +
148.3185 + if (ko.expressionRewriting.keyValueArrayContainsKey(parsedBindingValue, "name"))
148.3186 + return null; // Named templates can be rewritten, so return "no error"
148.3187 + return "This template engine does not support anonymous templates nested within its templates";
148.3188 + };
148.3189 +
148.3190 + ko.virtualElements.allowedBindings['template'] = true;
148.3191 +})();
148.3192 +
148.3193 +ko.exportSymbol('setTemplateEngine', ko.setTemplateEngine);
148.3194 +ko.exportSymbol('renderTemplate', ko.renderTemplate);
148.3195 +
148.3196 +ko.utils.compareArrays = (function () {
148.3197 + var statusNotInOld = 'added', statusNotInNew = 'deleted';
148.3198 +
148.3199 + // Simple calculation based on Levenshtein distance.
148.3200 + function compareArrays(oldArray, newArray, dontLimitMoves) {
148.3201 + oldArray = oldArray || [];
148.3202 + newArray = newArray || [];
148.3203 +
148.3204 + if (oldArray.length <= newArray.length)
148.3205 + return compareSmallArrayToBigArray(oldArray, newArray, statusNotInOld, statusNotInNew, dontLimitMoves);
148.3206 + else
148.3207 + return compareSmallArrayToBigArray(newArray, oldArray, statusNotInNew, statusNotInOld, dontLimitMoves);
148.3208 + }
148.3209 +
148.3210 + function compareSmallArrayToBigArray(smlArray, bigArray, statusNotInSml, statusNotInBig, dontLimitMoves) {
148.3211 + var myMin = Math.min,
148.3212 + myMax = Math.max,
148.3213 + editDistanceMatrix = [],
148.3214 + smlIndex, smlIndexMax = smlArray.length,
148.3215 + bigIndex, bigIndexMax = bigArray.length,
148.3216 + compareRange = (bigIndexMax - smlIndexMax) || 1,
148.3217 + maxDistance = smlIndexMax + bigIndexMax + 1,
148.3218 + thisRow, lastRow,
148.3219 + bigIndexMaxForRow, bigIndexMinForRow;
148.3220 +
148.3221 + for (smlIndex = 0; smlIndex <= smlIndexMax; smlIndex++) {
148.3222 + lastRow = thisRow;
148.3223 + editDistanceMatrix.push(thisRow = []);
148.3224 + bigIndexMaxForRow = myMin(bigIndexMax, smlIndex + compareRange);
148.3225 + bigIndexMinForRow = myMax(0, smlIndex - 1);
148.3226 + for (bigIndex = bigIndexMinForRow; bigIndex <= bigIndexMaxForRow; bigIndex++) {
148.3227 + if (!bigIndex)
148.3228 + thisRow[bigIndex] = smlIndex + 1;
148.3229 + else if (!smlIndex) // Top row - transform empty array into new array via additions
148.3230 + thisRow[bigIndex] = bigIndex + 1;
148.3231 + else if (smlArray[smlIndex - 1] === bigArray[bigIndex - 1])
148.3232 + thisRow[bigIndex] = lastRow[bigIndex - 1]; // copy value (no edit)
148.3233 + else {
148.3234 + var northDistance = lastRow[bigIndex] || maxDistance; // not in big (deletion)
148.3235 + var westDistance = thisRow[bigIndex - 1] || maxDistance; // not in small (addition)
148.3236 + thisRow[bigIndex] = myMin(northDistance, westDistance) + 1;
148.3237 + }
148.3238 + }
148.3239 + }
148.3240 +
148.3241 + var editScript = [], meMinusOne, notInSml = [], notInBig = [];
148.3242 + for (smlIndex = smlIndexMax, bigIndex = bigIndexMax; smlIndex || bigIndex;) {
148.3243 + meMinusOne = editDistanceMatrix[smlIndex][bigIndex] - 1;
148.3244 + if (bigIndex && meMinusOne === editDistanceMatrix[smlIndex][bigIndex-1]) {
148.3245 + notInSml.push(editScript[editScript.length] = { // added
148.3246 + 'status': statusNotInSml,
148.3247 + 'value': bigArray[--bigIndex],
148.3248 + 'index': bigIndex });
148.3249 + } else if (smlIndex && meMinusOne === editDistanceMatrix[smlIndex - 1][bigIndex]) {
148.3250 + notInBig.push(editScript[editScript.length] = { // deleted
148.3251 + 'status': statusNotInBig,
148.3252 + 'value': smlArray[--smlIndex],
148.3253 + 'index': smlIndex });
148.3254 + } else {
148.3255 + editScript.push({
148.3256 + 'status': "retained",
148.3257 + 'value': bigArray[--bigIndex] });
148.3258 + --smlIndex;
148.3259 + }
148.3260 + }
148.3261 +
148.3262 + if (notInSml.length && notInBig.length) {
148.3263 + // Set a limit on the number of consecutive non-matching comparisons; having it a multiple of
148.3264 + // smlIndexMax keeps the time complexity of this algorithm linear.
148.3265 + var limitFailedCompares = smlIndexMax * 10, failedCompares,
148.3266 + a, d, notInSmlItem, notInBigItem;
148.3267 + // Go through the items that have been added and deleted and try to find matches between them.
148.3268 + for (failedCompares = a = 0; (dontLimitMoves || failedCompares < limitFailedCompares) && (notInSmlItem = notInSml[a]); a++) {
148.3269 + for (d = 0; notInBigItem = notInBig[d]; d++) {
148.3270 + if (notInSmlItem['value'] === notInBigItem['value']) {
148.3271 + notInSmlItem['moved'] = notInBigItem['index'];
148.3272 + notInBigItem['moved'] = notInSmlItem['index'];
148.3273 + notInBig.splice(d,1); // This item is marked as moved; so remove it from notInBig list
148.3274 + failedCompares = d = 0; // Reset failed compares count because we're checking for consecutive failures
148.3275 + break;
148.3276 + }
148.3277 + }
148.3278 + failedCompares += d;
148.3279 + }
148.3280 + }
148.3281 + return editScript.reverse();
148.3282 + }
148.3283 +
148.3284 + return compareArrays;
148.3285 +})();
148.3286 +
148.3287 +ko.exportSymbol('utils.compareArrays', ko.utils.compareArrays);
148.3288 +
148.3289 +(function () {
148.3290 + // Objective:
148.3291 + // * Given an input array, a container DOM node, and a function from array elements to arrays of DOM nodes,
148.3292 + // map the array elements to arrays of DOM nodes, concatenate together all these arrays, and use them to populate the container DOM node
148.3293 + // * Next time we're given the same combination of things (with the array possibly having mutated), update the container DOM node
148.3294 + // so that its children is again the concatenation of the mappings of the array elements, but don't re-map any array elements that we
148.3295 + // previously mapped - retain those nodes, and just insert/delete other ones
148.3296 +
148.3297 + // "callbackAfterAddingNodes" will be invoked after any "mapping"-generated nodes are inserted into the container node
148.3298 + // You can use this, for example, to activate bindings on those nodes.
148.3299 +
148.3300 + function fixUpNodesToBeMovedOrRemoved(contiguousNodeArray) {
148.3301 + // Before moving, deleting, or replacing a set of nodes that were previously outputted by the "map" function, we have to reconcile
148.3302 + // them against what is in the DOM right now. It may be that some of the nodes have already been removed from the document,
148.3303 + // or that new nodes might have been inserted in the middle, for example by a binding. Also, there may previously have been
148.3304 + // leading comment nodes (created by rewritten string-based templates) that have since been removed during binding.
148.3305 + // So, this function translates the old "map" output array into its best guess of what set of current DOM nodes should be removed.
148.3306 + //
148.3307 + // Rules:
148.3308 + // [A] Any leading nodes that aren't in the document any more should be ignored
148.3309 + // These most likely correspond to memoization nodes that were already removed during binding
148.3310 + // See https://github.com/SteveSanderson/knockout/pull/440
148.3311 + // [B] We want to output a contiguous series of nodes that are still in the document. So, ignore any nodes that
148.3312 + // have already been removed, and include any nodes that have been inserted among the previous collection
148.3313 +
148.3314 + // Rule [A]
148.3315 + while (contiguousNodeArray.length && !ko.utils.domNodeIsAttachedToDocument(contiguousNodeArray[0]))
148.3316 + contiguousNodeArray.splice(0, 1);
148.3317 +
148.3318 + // Rule [B]
148.3319 + if (contiguousNodeArray.length > 1) {
148.3320 + // Build up the actual new contiguous node set
148.3321 + var current = contiguousNodeArray[0], last = contiguousNodeArray[contiguousNodeArray.length - 1], newContiguousSet = [current];
148.3322 + while (current !== last) {
148.3323 + current = current.nextSibling;
148.3324 + if (!current) // Won't happen, except if the developer has manually removed some DOM elements (then we're in an undefined scenario)
148.3325 + return;
148.3326 + newContiguousSet.push(current);
148.3327 + }
148.3328 +
148.3329 + // ... then mutate the input array to match this.
148.3330 + // (The following line replaces the contents of contiguousNodeArray with newContiguousSet)
148.3331 + Array.prototype.splice.apply(contiguousNodeArray, [0, contiguousNodeArray.length].concat(newContiguousSet));
148.3332 + }
148.3333 + return contiguousNodeArray;
148.3334 + }
148.3335 +
148.3336 + function mapNodeAndRefreshWhenChanged(containerNode, mapping, valueToMap, callbackAfterAddingNodes, index) {
148.3337 + // Map this array value inside a dependentObservable so we re-map when any dependency changes
148.3338 + var mappedNodes = [];
148.3339 + var dependentObservable = ko.dependentObservable(function() {
148.3340 + var newMappedNodes = mapping(valueToMap, index) || [];
148.3341 +
148.3342 + // On subsequent evaluations, just replace the previously-inserted DOM nodes
148.3343 + if (mappedNodes.length > 0) {
148.3344 + ko.utils.replaceDomNodes(fixUpNodesToBeMovedOrRemoved(mappedNodes), newMappedNodes);
148.3345 + if (callbackAfterAddingNodes)
148.3346 + ko.dependencyDetection.ignore(callbackAfterAddingNodes, null, [valueToMap, newMappedNodes, index]);
148.3347 + }
148.3348 +
148.3349 + // Replace the contents of the mappedNodes array, thereby updating the record
148.3350 + // of which nodes would be deleted if valueToMap was itself later removed
148.3351 + mappedNodes.splice(0, mappedNodes.length);
148.3352 + ko.utils.arrayPushAll(mappedNodes, newMappedNodes);
148.3353 + }, null, { disposeWhenNodeIsRemoved: containerNode, disposeWhen: function() { return (mappedNodes.length == 0) || !ko.utils.domNodeIsAttachedToDocument(mappedNodes[0]) } });
148.3354 + return { mappedNodes : mappedNodes, dependentObservable : (dependentObservable.isActive() ? dependentObservable : undefined) };
148.3355 + }
148.3356 +
148.3357 + var lastMappingResultDomDataKey = "setDomNodeChildrenFromArrayMapping_lastMappingResult";
148.3358 +
148.3359 + ko.utils.setDomNodeChildrenFromArrayMapping = function (domNode, array, mapping, options, callbackAfterAddingNodes) {
148.3360 + // Compare the provided array against the previous one
148.3361 + array = array || [];
148.3362 + options = options || {};
148.3363 + var isFirstExecution = ko.utils.domData.get(domNode, lastMappingResultDomDataKey) === undefined;
148.3364 + var lastMappingResult = ko.utils.domData.get(domNode, lastMappingResultDomDataKey) || [];
148.3365 + var lastArray = ko.utils.arrayMap(lastMappingResult, function (x) { return x.arrayEntry; });
148.3366 + var editScript = ko.utils.compareArrays(lastArray, array);
148.3367 +
148.3368 + // Build the new mapping result
148.3369 + var newMappingResult = [];
148.3370 + var lastMappingResultIndex = 0;
148.3371 + var newMappingResultIndex = 0;
148.3372 +
148.3373 + var nodesToDelete = [];
148.3374 + var itemsToProcess = [];
148.3375 + var itemsForBeforeRemoveCallbacks = [];
148.3376 + var itemsForMoveCallbacks = [];
148.3377 + var itemsForAfterAddCallbacks = [];
148.3378 + var mapData;
148.3379 +
148.3380 + function itemMovedOrRetained(editScriptIndex, oldPosition) {
148.3381 + mapData = lastMappingResult[oldPosition];
148.3382 + if (newMappingResultIndex !== oldPosition)
148.3383 + itemsForMoveCallbacks[editScriptIndex] = mapData;
148.3384 + // Since updating the index might change the nodes, do so before calling fixUpNodesToBeMovedOrRemoved
148.3385 + mapData.indexObservable(newMappingResultIndex++);
148.3386 + fixUpNodesToBeMovedOrRemoved(mapData.mappedNodes);
148.3387 + newMappingResult.push(mapData);
148.3388 + itemsToProcess.push(mapData);
148.3389 + }
148.3390 +
148.3391 + function callCallback(callback, items) {
148.3392 + if (callback) {
148.3393 + for (var i = 0, n = items.length; i < n; i++) {
148.3394 + if (items[i]) {
148.3395 + ko.utils.arrayForEach(items[i].mappedNodes, function(node) {
148.3396 + callback(node, i, items[i].arrayEntry);
148.3397 + });
148.3398 + }
148.3399 + }
148.3400 + }
148.3401 + }
148.3402 +
148.3403 + for (var i = 0, editScriptItem, movedIndex; editScriptItem = editScript[i]; i++) {
148.3404 + movedIndex = editScriptItem['moved'];
148.3405 + switch (editScriptItem['status']) {
148.3406 + case "deleted":
148.3407 + if (movedIndex === undefined) {
148.3408 + mapData = lastMappingResult[lastMappingResultIndex];
148.3409 +
148.3410 + // Stop tracking changes to the mapping for these nodes
148.3411 + if (mapData.dependentObservable)
148.3412 + mapData.dependentObservable.dispose();
148.3413 +
148.3414 + // Queue these nodes for later removal
148.3415 + nodesToDelete.push.apply(nodesToDelete, fixUpNodesToBeMovedOrRemoved(mapData.mappedNodes));
148.3416 + if (options['beforeRemove']) {
148.3417 + itemsForBeforeRemoveCallbacks[i] = mapData;
148.3418 + itemsToProcess.push(mapData);
148.3419 + }
148.3420 + }
148.3421 + lastMappingResultIndex++;
148.3422 + break;
148.3423 +
148.3424 + case "retained":
148.3425 + itemMovedOrRetained(i, lastMappingResultIndex++);
148.3426 + break;
148.3427 +
148.3428 + case "added":
148.3429 + if (movedIndex !== undefined) {
148.3430 + itemMovedOrRetained(i, movedIndex);
148.3431 + } else {
148.3432 + mapData = { arrayEntry: editScriptItem['value'], indexObservable: ko.observable(newMappingResultIndex++) };
148.3433 + newMappingResult.push(mapData);
148.3434 + itemsToProcess.push(mapData);
148.3435 + if (!isFirstExecution)
148.3436 + itemsForAfterAddCallbacks[i] = mapData;
148.3437 + }
148.3438 + break;
148.3439 + }
148.3440 + }
148.3441 +
148.3442 + // Call beforeMove first before any changes have been made to the DOM
148.3443 + callCallback(options['beforeMove'], itemsForMoveCallbacks);
148.3444 +
148.3445 + // Next remove nodes for deleted items (or just clean if there's a beforeRemove callback)
148.3446 + ko.utils.arrayForEach(nodesToDelete, options['beforeRemove'] ? ko.cleanNode : ko.removeNode);
148.3447 +
148.3448 + // Next add/reorder the remaining items (will include deleted items if there's a beforeRemove callback)
148.3449 + for (var i = 0, nextNode = ko.virtualElements.firstChild(domNode), lastNode, node; mapData = itemsToProcess[i]; i++) {
148.3450 + // Get nodes for newly added items
148.3451 + if (!mapData.mappedNodes)
148.3452 + ko.utils.extend(mapData, mapNodeAndRefreshWhenChanged(domNode, mapping, mapData.arrayEntry, callbackAfterAddingNodes, mapData.indexObservable));
148.3453 +
148.3454 + // Put nodes in the right place if they aren't there already
148.3455 + for (var j = 0; node = mapData.mappedNodes[j]; nextNode = node.nextSibling, lastNode = node, j++) {
148.3456 + if (node !== nextNode)
148.3457 + ko.virtualElements.insertAfter(domNode, node, lastNode);
148.3458 + }
148.3459 +
148.3460 + // Run the callbacks for newly added nodes (for example, to apply bindings, etc.)
148.3461 + if (!mapData.initialized && callbackAfterAddingNodes) {
148.3462 + callbackAfterAddingNodes(mapData.arrayEntry, mapData.mappedNodes, mapData.indexObservable);
148.3463 + mapData.initialized = true;
148.3464 + }
148.3465 + }
148.3466 +
148.3467 + // If there's a beforeRemove callback, call it after reordering.
148.3468 + // Note that we assume that the beforeRemove callback will usually be used to remove the nodes using
148.3469 + // some sort of animation, which is why we first reorder the nodes that will be removed. If the
148.3470 + // callback instead removes the nodes right away, it would be more efficient to skip reordering them.
148.3471 + // Perhaps we'll make that change in the future if this scenario becomes more common.
148.3472 + callCallback(options['beforeRemove'], itemsForBeforeRemoveCallbacks);
148.3473 +
148.3474 + // Finally call afterMove and afterAdd callbacks
148.3475 + callCallback(options['afterMove'], itemsForMoveCallbacks);
148.3476 + callCallback(options['afterAdd'], itemsForAfterAddCallbacks);
148.3477 +
148.3478 + // Store a copy of the array items we just considered so we can difference it next time
148.3479 + ko.utils.domData.set(domNode, lastMappingResultDomDataKey, newMappingResult);
148.3480 + }
148.3481 +})();
148.3482 +
148.3483 +ko.exportSymbol('utils.setDomNodeChildrenFromArrayMapping', ko.utils.setDomNodeChildrenFromArrayMapping);
148.3484 +ko.nativeTemplateEngine = function () {
148.3485 + this['allowTemplateRewriting'] = false;
148.3486 +}
148.3487 +
148.3488 +ko.nativeTemplateEngine.prototype = new ko.templateEngine();
148.3489 +ko.nativeTemplateEngine.prototype['renderTemplateSource'] = function (templateSource, bindingContext, options) {
148.3490 + var useNodesIfAvailable = !(ko.utils.ieVersion < 9), // IE<9 cloneNode doesn't work properly
148.3491 + templateNodesFunc = useNodesIfAvailable ? templateSource['nodes'] : null,
148.3492 + templateNodes = templateNodesFunc ? templateSource['nodes']() : null;
148.3493 +
148.3494 + if (templateNodes) {
148.3495 + return ko.utils.makeArray(templateNodes.cloneNode(true).childNodes);
148.3496 + } else {
148.3497 + var templateText = templateSource['text']();
148.3498 + return ko.utils.parseHtmlFragment(templateText);
148.3499 + }
148.3500 +};
148.3501 +
148.3502 +ko.nativeTemplateEngine.instance = new ko.nativeTemplateEngine();
148.3503 +ko.setTemplateEngine(ko.nativeTemplateEngine.instance);
148.3504 +
148.3505 +ko.exportSymbol('nativeTemplateEngine', ko.nativeTemplateEngine);
148.3506 +(function() {
148.3507 + ko.jqueryTmplTemplateEngine = function () {
148.3508 + // Detect which version of jquery-tmpl you're using. Unfortunately jquery-tmpl
148.3509 + // doesn't expose a version number, so we have to infer it.
148.3510 + // Note that as of Knockout 1.3, we only support jQuery.tmpl 1.0.0pre and later,
148.3511 + // which KO internally refers to as version "2", so older versions are no longer detected.
148.3512 + var jQueryTmplVersion = this.jQueryTmplVersion = (function() {
148.3513 + if ((typeof(jQuery) == "undefined") || !(jQuery['tmpl']))
148.3514 + return 0;
148.3515 + // Since it exposes no official version number, we use our own numbering system. To be updated as jquery-tmpl evolves.
148.3516 + try {
148.3517 + if (jQuery['tmpl']['tag']['tmpl']['open'].toString().indexOf('__') >= 0) {
148.3518 + // Since 1.0.0pre, custom tags should append markup to an array called "__"
148.3519 + return 2; // Final version of jquery.tmpl
148.3520 + }
148.3521 + } catch(ex) { /* Apparently not the version we were looking for */ }
148.3522 +
148.3523 + return 1; // Any older version that we don't support
148.3524 + })();
148.3525 +
148.3526 + function ensureHasReferencedJQueryTemplates() {
148.3527 + if (jQueryTmplVersion < 2)
148.3528 + throw new Error("Your version of jQuery.tmpl is too old. Please upgrade to jQuery.tmpl 1.0.0pre or later.");
148.3529 + }
148.3530 +
148.3531 + function executeTemplate(compiledTemplate, data, jQueryTemplateOptions) {
148.3532 + return jQuery['tmpl'](compiledTemplate, data, jQueryTemplateOptions);
148.3533 + }
148.3534 +
148.3535 + this['renderTemplateSource'] = function(templateSource, bindingContext, options) {
148.3536 + options = options || {};
148.3537 + ensureHasReferencedJQueryTemplates();
148.3538 +
148.3539 + // Ensure we have stored a precompiled version of this template (don't want to reparse on every render)
148.3540 + var precompiled = templateSource['data']('precompiled');
148.3541 + if (!precompiled) {
148.3542 + var templateText = templateSource['text']() || "";
148.3543 + // Wrap in "with($whatever.koBindingContext) { ... }"
148.3544 + templateText = "{{ko_with $item.koBindingContext}}" + templateText + "{{/ko_with}}";
148.3545 +
148.3546 + precompiled = jQuery['template'](null, templateText);
148.3547 + templateSource['data']('precompiled', precompiled);
148.3548 + }
148.3549 +
148.3550 + var data = [bindingContext['$data']]; // Prewrap the data in an array to stop jquery.tmpl from trying to unwrap any arrays
148.3551 + var jQueryTemplateOptions = jQuery['extend']({ 'koBindingContext': bindingContext }, options['templateOptions']);
148.3552 +
148.3553 + var resultNodes = executeTemplate(precompiled, data, jQueryTemplateOptions);
148.3554 + resultNodes['appendTo'](document.createElement("div")); // Using "appendTo" forces jQuery/jQuery.tmpl to perform necessary cleanup work
148.3555 +
148.3556 + jQuery['fragments'] = {}; // Clear jQuery's fragment cache to avoid a memory leak after a large number of template renders
148.3557 + return resultNodes;
148.3558 + };
148.3559 +
148.3560 + this['createJavaScriptEvaluatorBlock'] = function(script) {
148.3561 + return "{{ko_code ((function() { return " + script + " })()) }}";
148.3562 + };
148.3563 +
148.3564 + this['addTemplate'] = function(templateName, templateMarkup) {
148.3565 + document.write("<script type='text/html' id='" + templateName + "'>" + templateMarkup + "</script>");
148.3566 + };
148.3567 +
148.3568 + if (jQueryTmplVersion > 0) {
148.3569 + jQuery['tmpl']['tag']['ko_code'] = {
148.3570 + open: "__.push($1 || '');"
148.3571 + };
148.3572 + jQuery['tmpl']['tag']['ko_with'] = {
148.3573 + open: "with($1) {",
148.3574 + close: "} "
148.3575 + };
148.3576 + }
148.3577 + };
148.3578 +
148.3579 + ko.jqueryTmplTemplateEngine.prototype = new ko.templateEngine();
148.3580 +
148.3581 + // Use this one by default *only if jquery.tmpl is referenced*
148.3582 + var jqueryTmplTemplateEngineInstance = new ko.jqueryTmplTemplateEngine();
148.3583 + if (jqueryTmplTemplateEngineInstance.jQueryTmplVersion > 0)
148.3584 + ko.setTemplateEngine(jqueryTmplTemplateEngineInstance);
148.3585 +
148.3586 + ko.exportSymbol('jqueryTmplTemplateEngine', ko.jqueryTmplTemplateEngine);
148.3587 +})();
148.3588 +});
148.3589 +})(window,document,navigator,window["jQuery"]);
148.3590 +})();
148.3591 \ No newline at end of file
149.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
149.2 +++ b/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/KnockoutTest.java Wed Jan 23 20:16:48 2013 +0100
149.3 @@ -0,0 +1,62 @@
149.4 +/**
149.5 + * Back 2 Browser Bytecode Translator
149.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
149.7 + *
149.8 + * This program is free software: you can redistribute it and/or modify
149.9 + * it under the terms of the GNU General Public License as published by
149.10 + * the Free Software Foundation, version 2 of the License.
149.11 + *
149.12 + * This program is distributed in the hope that it will be useful,
149.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
149.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
149.15 + * GNU General Public License for more details.
149.16 + *
149.17 + * You should have received a copy of the GNU General Public License
149.18 + * along with this program. Look for COPYING file in the top folder.
149.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
149.20 + */
149.21 +package org.apidesign.bck2brwsr.htmlpage;
149.22 +
149.23 +import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
149.24 +import org.apidesign.bck2brwsr.htmlpage.api.OnEvent;
149.25 +import org.apidesign.bck2brwsr.htmlpage.api.Page;
149.26 +import org.apidesign.bck2brwsr.htmlpage.api.Property;
149.27 +import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
149.28 +import org.apidesign.bck2brwsr.vmtest.HtmlFragment;
149.29 +import org.apidesign.bck2brwsr.vmtest.VMTest;
149.30 +import org.testng.annotations.Factory;
149.31 +
149.32 +/**
149.33 + *
149.34 + * @author Jaroslav Tulach <jtulach@netbeans.org>
149.35 + */
149.36 +@Page(xhtml="Knockout.xhtml", className="KnockoutModel", properties={
149.37 + @Property(name="name", type=String.class)
149.38 +})
149.39 +public class KnockoutTest {
149.40 +
149.41 + @HtmlFragment(
149.42 + "<h1 data-bind=\"text: helloMessage\">Loading Bck2Brwsr's Hello World...</h1>\n" +
149.43 + "Your name: <input id='input' data-bind=\"value: name\"></input>\n" +
149.44 + "<button id=\"hello\">Say Hello!</button>\n"
149.45 + )
149.46 + @BrwsrTest public void modifyValueAssertChangeInModel() {
149.47 + KnockoutModel m = new KnockoutModel();
149.48 + m.setName("Kukuc");
149.49 + m.applyBindings();
149.50 + assert "Kukuc".equals(m.INPUT.getValue()) : "Value is really kukuc: " + m.INPUT.getValue();
149.51 + m.INPUT.setValue("Jardo");
149.52 + m.triggerEvent(m.INPUT, OnEvent.CHANGE);
149.53 + assert "Jardo".equals(m.getName()) : "Name property updated: " + m.getName();
149.54 + }
149.55 +
149.56 + @ComputedProperty
149.57 + static String helloMessage(String name) {
149.58 + return "Hello " + name + "!";
149.59 + }
149.60 +
149.61 + @Factory
149.62 + public static Object[] create() {
149.63 + return VMTest.create(KnockoutTest.class);
149.64 + }
149.65 +}
150.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
150.2 +++ b/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/ModelTest.java Wed Jan 23 20:16:48 2013 +0100
150.3 @@ -0,0 +1,119 @@
150.4 +/**
150.5 + * Back 2 Browser Bytecode Translator
150.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
150.7 + *
150.8 + * This program is free software: you can redistribute it and/or modify
150.9 + * it under the terms of the GNU General Public License as published by
150.10 + * the Free Software Foundation, version 2 of the License.
150.11 + *
150.12 + * This program is distributed in the hope that it will be useful,
150.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
150.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
150.15 + * GNU General Public License for more details.
150.16 + *
150.17 + * You should have received a copy of the GNU General Public License
150.18 + * along with this program. Look for COPYING file in the top folder.
150.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
150.20 + */
150.21 +package org.apidesign.bck2brwsr.htmlpage;
150.22 +
150.23 +import java.util.ArrayList;
150.24 +import java.util.List;
150.25 +import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
150.26 +import org.apidesign.bck2brwsr.htmlpage.api.Page;
150.27 +import org.apidesign.bck2brwsr.htmlpage.api.Property;
150.28 +import static org.testng.Assert.*;
150.29 +import org.testng.annotations.BeforeMethod;
150.30 +import org.testng.annotations.Test;
150.31 +
150.32 +/**
150.33 + *
150.34 + * @author Jaroslav Tulach <jtulach@netbeans.org>
150.35 + */
150.36 +@Page(xhtml = "Empty.html", className = "Model", properties = {
150.37 + @Property(name = "value", type = int.class),
150.38 + @Property(name = "unrelated", type = long.class)
150.39 +})
150.40 +public class ModelTest {
150.41 + private Model model;
150.42 + private static Model leakedModel;
150.43 +
150.44 + @BeforeMethod
150.45 + public void createModel() {
150.46 + model = new Model();
150.47 + }
150.48 +
150.49 + @Test public void classGeneratedWithSetterGetter() {
150.50 + model.setValue(10);
150.51 + assertEquals(10, model.getValue(), "Value changed");
150.52 + }
150.53 +
150.54 + @Test public void computedMethod() {
150.55 + model.setValue(4);
150.56 + assertEquals(16, model.getPowerValue());
150.57 + }
150.58 +
150.59 + @Test public void derivedPropertiesAreNotified() {
150.60 + MockKnockout my = new MockKnockout();
150.61 + MockKnockout.next = my;
150.62 +
150.63 + model.applyBindings();
150.64 +
150.65 + model.setValue(33);
150.66 +
150.67 + assertEquals(my.mutated.size(), 2, "Two properties changed: " + my.mutated);
150.68 + assertTrue(my.mutated.contains("powerValue"), "Power value is in there: " + my.mutated);
150.69 + assertTrue(my.mutated.contains("value"), "Simple value is in there: " + my.mutated);
150.70 +
150.71 + my.mutated.clear();
150.72 +
150.73 + model.setUnrelated(44);
150.74 + assertEquals(my.mutated.size(), 1, "One property changed");
150.75 + assertTrue(my.mutated.contains("unrelated"), "Its name is unrelated");
150.76 + }
150.77 +
150.78 + @Test public void computedPropertyCannotWriteToModel() {
150.79 + leakedModel = model;
150.80 + try {
150.81 + String res = model.getNotAllowedWrite();
150.82 + fail("We should not be allowed to write to the model: " + res);
150.83 + } catch (IllegalStateException ex) {
150.84 + // OK, we can't read
150.85 + }
150.86 + }
150.87 +
150.88 + @Test public void computedPropertyCannotReadToModel() {
150.89 + leakedModel = model;
150.90 + try {
150.91 + String res = model.getNotAllowedRead();
150.92 + fail("We should not be allowed to read from the model: " + res);
150.93 + } catch (IllegalStateException ex) {
150.94 + // OK, we can't read
150.95 + }
150.96 + }
150.97 +
150.98 + @ComputedProperty
150.99 + static int powerValue(int value) {
150.100 + return value * value;
150.101 + }
150.102 +
150.103 + @ComputedProperty
150.104 + static String notAllowedRead() {
150.105 + return "Not allowed callback: " + leakedModel.getUnrelated();
150.106 + }
150.107 +
150.108 + @ComputedProperty
150.109 + static String notAllowedWrite() {
150.110 + leakedModel.setUnrelated(11);
150.111 + return "Not allowed callback!";
150.112 + }
150.113 +
150.114 + static class MockKnockout extends Knockout {
150.115 + List<String> mutated = new ArrayList<String>();
150.116 +
150.117 + @Override
150.118 + public void valueHasMutated(String prop) {
150.119 + mutated.add(prop);
150.120 + }
150.121 + }
150.122 +}
151.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
151.2 +++ b/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/PageController.java Wed Jan 23 20:16:48 2013 +0100
151.3 @@ -0,0 +1,63 @@
151.4 +/**
151.5 + * Back 2 Browser Bytecode Translator
151.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
151.7 + *
151.8 + * This program is free software: you can redistribute it and/or modify
151.9 + * it under the terms of the GNU General Public License as published by
151.10 + * the Free Software Foundation, version 2 of the License.
151.11 + *
151.12 + * This program is distributed in the hope that it will be useful,
151.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
151.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
151.15 + * GNU General Public License for more details.
151.16 + *
151.17 + * You should have received a copy of the GNU General Public License
151.18 + * along with this program. Look for COPYING file in the top folder.
151.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
151.20 + */
151.21 +package org.apidesign.bck2brwsr.htmlpage;
151.22 +
151.23 +import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;
151.24 +import org.apidesign.bck2brwsr.htmlpage.api.On;
151.25 +import org.apidesign.bck2brwsr.htmlpage.api.Page;
151.26 +
151.27 +/** Trivial demo for the bck2brwsr project. First of all start
151.28 + * with <a href="TestPage.html">your XHTML page</a>. Include there
151.29 + * a script that will <em>boot Java</em> in your browser.
151.30 + * <p>
151.31 + * Then use <code>@Page</code> annotation to
151.32 + * generate a Java representation of elements with IDs in that page.
151.33 + * Depending on the type of the elements, they will have different
151.34 + * methods (e.g. <code>PG_TITLE</code> has <code>setText</code>, etc.).
151.35 + * Use <code>@OnClick</code> annotation to associate behavior
151.36 + * with existing elements. Use the generated elements
151.37 + * (<code>PG_TITLE</code>, <code>PG_TEXT</code>) to modify the page.
151.38 + * <p>
151.39 + * Everything is type-safe. As soon as somebody modifies the page and
151.40 + * removes the IDs or re-assigns them to wrong elements. Java compiler
151.41 + * will emit an error.
151.42 + * <p>
151.43 + * Welcome to the type-safe HTML5 world!
151.44 + *
151.45 + * @author Jaroslav Tulach <jtulach@netbeans.org>
151.46 + */
151.47 +@Page(xhtml="TestPage.html")
151.48 +public class PageController {
151.49 + private static final TestPage PAGE = new TestPage();
151.50 +
151.51 + @On(event = CLICK, id="pg.button")
151.52 + static void updateTitle(TestPage ref) {
151.53 + if (PAGE != ref) {
151.54 + throw new IllegalStateException("Both references should be the same. " + ref + " != " + PAGE);
151.55 + }
151.56 + ref.PG_TITLE.setText("You want this window to be named " + ref.PG_TEXT.getValue());
151.57 + }
151.58 +
151.59 + @On(event = CLICK, id={ "pg.title", "pg.text" })
151.60 + static void click(String id) {
151.61 + if (!id.equals("pg.title")) {
151.62 + throw new IllegalStateException();
151.63 + }
151.64 + PAGE.PG_TITLE.setText(id);
151.65 + }
151.66 +}
152.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
152.2 +++ b/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/ProcessPageTest.java Wed Jan 23 20:16:48 2013 +0100
152.3 @@ -0,0 +1,142 @@
152.4 +/**
152.5 + * Back 2 Browser Bytecode Translator
152.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
152.7 + *
152.8 + * This program is free software: you can redistribute it and/or modify
152.9 + * it under the terms of the GNU General Public License as published by
152.10 + * the Free Software Foundation, version 2 of the License.
152.11 + *
152.12 + * This program is distributed in the hope that it will be useful,
152.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
152.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
152.15 + * GNU General Public License for more details.
152.16 + *
152.17 + * You should have received a copy of the GNU General Public License
152.18 + * along with this program. Look for COPYING file in the top folder.
152.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
152.20 + */
152.21 +package org.apidesign.bck2brwsr.htmlpage;
152.22 +
152.23 +import java.io.IOException;
152.24 +import java.io.InputStream;
152.25 +import java.util.Set;
152.26 +import javax.script.Invocable;
152.27 +import javax.script.ScriptEngine;
152.28 +import javax.script.ScriptEngineManager;
152.29 +import javax.script.ScriptException;
152.30 +import org.apidesign.vm4brwsr.Bck2Brwsr;
152.31 +import org.testng.annotations.Test;
152.32 +import static org.testng.Assert.*;
152.33 +
152.34 +public class ProcessPageTest {
152.35 +
152.36 +
152.37 + @Test public void findsThreeIds() throws IOException {
152.38 + InputStream is = ProcessPageTest.class.getResourceAsStream("TestPage.html");
152.39 + assertNotNull(is, "Sample HTML page found");
152.40 + ProcessPage res = ProcessPage.readPage(is);
152.41 + final Set<String> ids = res.ids();
152.42 + assertEquals(ids.size(), 3, "Three ids found: " + ids);
152.43 +
152.44 + assertEquals(res.tagNameForId("pg.title"), "title");
152.45 + assertEquals(res.tagNameForId("pg.button"), "button");
152.46 + assertEquals(res.tagNameForId("pg.text"), "input");
152.47 + }
152.48 +
152.49 + @Test public void testCompileAndRunPageController() throws Exception {
152.50 + StringBuilder sb = new StringBuilder();
152.51 + sb.append(
152.52 + "var window = new Object();\n"
152.53 + + "var doc = new Object();\n"
152.54 + + "doc.button = new Object();\n"
152.55 + + "doc.title = new Object();\n"
152.56 + + "doc.title.innerHTML = 'nothing';\n"
152.57 + + "doc.text = new Object();\n"
152.58 + + "doc.text.value = 'something';\n"
152.59 + + "doc.getElementById = function(id) {\n"
152.60 + + " switch(id) {\n"
152.61 + + " case 'pg.button': return doc.button;\n"
152.62 + + " case 'pg.title': return doc.title;\n"
152.63 + + " case 'pg.text': return doc.text;\n"
152.64 + + " }\n"
152.65 + + " throw id;\n"
152.66 + + " }\n"
152.67 + + "\n"
152.68 + + "function clickAndCheck() {\n"
152.69 + + " doc.button.onclick();\n"
152.70 + + " return doc.title.innerHTML.toString();\n"
152.71 + + "};\n"
152.72 + + "\n"
152.73 + + "window.document = doc;\n"
152.74 + );
152.75 + Invocable i = compileClass(sb, "org/apidesign/bck2brwsr/htmlpage/PageController");
152.76 +
152.77 + Object ret = null;
152.78 + try {
152.79 + ret = i.invokeFunction("clickAndCheck");
152.80 + } catch (ScriptException ex) {
152.81 + fail("Execution failed in " + sb, ex);
152.82 + } catch (NoSuchMethodException ex) {
152.83 + fail("Cannot find method in " + sb, ex);
152.84 + }
152.85 + assertEquals(ret, "You want this window to be named something", "We expect that the JavaCode performs all the wiring");
152.86 + }
152.87 +
152.88 + @Test public void clickWithArgumentCalled() throws Exception {
152.89 + StringBuilder sb = new StringBuilder();
152.90 + sb.append(
152.91 + "var window = new Object();\n"
152.92 + + "var doc = new Object();\n"
152.93 + + "doc.button = new Object();\n"
152.94 + + "doc.title = new Object();\n"
152.95 + + "doc.title.innerHTML = 'nothing';\n"
152.96 + + "doc.text = new Object();\n"
152.97 + + "doc.text.value = 'something';\n"
152.98 + + "doc.getElementById = function(id) {\n"
152.99 + + " switch(id) {\n"
152.100 + + " case 'pg.button': return doc.button;\n"
152.101 + + " case 'pg.title': return doc.title;\n"
152.102 + + " case 'pg.text': return doc.text;\n"
152.103 + + " }\n"
152.104 + + " throw id;\n"
152.105 + + " }\n"
152.106 + + "\n"
152.107 + + "function clickAndCheck() {\n"
152.108 + + " doc.title.onclick();\n"
152.109 + + " return doc.title.innerHTML.toString();\n"
152.110 + + "};\n"
152.111 + + "\n"
152.112 + + "window.document = doc;\n"
152.113 + );
152.114 + Invocable i = compileClass(sb,
152.115 + "org/apidesign/bck2brwsr/htmlpage/PageController"
152.116 + );
152.117 +
152.118 + Object ret = null;
152.119 + try {
152.120 + ret = i.invokeFunction("clickAndCheck");
152.121 + } catch (ScriptException ex) {
152.122 + fail("Execution failed in " + sb, ex);
152.123 + } catch (NoSuchMethodException ex) {
152.124 + fail("Cannot find method in " + sb, ex);
152.125 + }
152.126 + assertEquals(ret, "pg.title", "Title has been passed to the method argument");
152.127 + }
152.128 +
152.129 + static Invocable compileClass(StringBuilder sb, String... names) throws ScriptException, IOException {
152.130 + if (sb == null) {
152.131 + sb = new StringBuilder();
152.132 + }
152.133 + Bck2Brwsr.generate(sb, ProcessPageTest.class.getClassLoader(), names);
152.134 + ScriptEngineManager sem = new ScriptEngineManager();
152.135 + ScriptEngine js = sem.getEngineByExtension("js");
152.136 + try {
152.137 + Object res = js.eval(sb.toString());
152.138 + assertTrue(js instanceof Invocable, "It is invocable object: " + res);
152.139 + return (Invocable) js;
152.140 + } catch (ScriptException ex) {
152.141 + fail("Could not compile:\n" + sb, ex);
152.142 + return null;
152.143 + }
152.144 + }
152.145 +}
153.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
153.2 +++ b/javaquery/api/src/test/resources/org/apidesign/bck2brwsr/htmlpage/Empty.html Wed Jan 23 20:16:48 2013 +0100
153.3 @@ -0,0 +1,29 @@
153.4 +<?xml version="1.0" encoding="UTF-8"?>
153.5 +<!--
153.6 +
153.7 + Back 2 Browser Bytecode Translator
153.8 + Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
153.9 +
153.10 + This program is free software: you can redistribute it and/or modify
153.11 + it under the terms of the GNU General Public License as published by
153.12 + the Free Software Foundation, version 2 of the License.
153.13 +
153.14 + This program is distributed in the hope that it will be useful,
153.15 + but WITHOUT ANY WARRANTY; without even the implied warranty of
153.16 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
153.17 + GNU General Public License for more details.
153.18 +
153.19 + You should have received a copy of the GNU General Public License
153.20 + along with this program. Look for COPYING file in the top folder.
153.21 + If not, see http://opensource.org/licenses/GPL-2.0.
153.22 +
153.23 +-->
153.24 +<!DOCTYPE html>
153.25 +<html xmlns="http://www.w3.org/1999/xhtml">
153.26 + <head>
153.27 + <title>Empty</title>
153.28 + </head>
153.29 + <body>
153.30 + Empty page
153.31 + </body>
153.32 +</html>
154.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
154.2 +++ b/javaquery/api/src/test/resources/org/apidesign/bck2brwsr/htmlpage/Knockout.xhtml Wed Jan 23 20:16:48 2013 +0100
154.3 @@ -0,0 +1,25 @@
154.4 +<?xml version="1.0" encoding="UTF-8"?>
154.5 +<!--
154.6 +
154.7 + Back 2 Browser Bytecode Translator
154.8 + Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
154.9 +
154.10 + This program is free software: you can redistribute it and/or modify
154.11 + it under the terms of the GNU General Public License as published by
154.12 + the Free Software Foundation, version 2 of the License.
154.13 +
154.14 + This program is distributed in the hope that it will be useful,
154.15 + but WITHOUT ANY WARRANTY; without even the implied warranty of
154.16 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
154.17 + GNU General Public License for more details.
154.18 +
154.19 + You should have received a copy of the GNU General Public License
154.20 + along with this program. Look for COPYING file in the top folder.
154.21 + If not, see http://opensource.org/licenses/GPL-2.0.
154.22 +
154.23 +-->
154.24 +<p>
154.25 + <h1 data-bind="text: helloMessage">Loading Bck2Brwsr's Hello World...</h1>
154.26 + Your name: <input id="input" data-bind="value: name, valueUpdate: 'afterkeydown'"></input>
154.27 + <button id="hello">Say Hello!</button>
154.28 +</p>
155.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
155.2 +++ b/javaquery/api/src/test/resources/org/apidesign/bck2brwsr/htmlpage/TestPage.html Wed Jan 23 20:16:48 2013 +0100
155.3 @@ -0,0 +1,30 @@
155.4 +<?xml version="1.0" encoding="UTF-8"?>
155.5 +<!--
155.6 +
155.7 + Back 2 Browser Bytecode Translator
155.8 + Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
155.9 +
155.10 + This program is free software: you can redistribute it and/or modify
155.11 + it under the terms of the GNU General Public License as published by
155.12 + the Free Software Foundation, version 2 of the License.
155.13 +
155.14 + This program is distributed in the hope that it will be useful,
155.15 + but WITHOUT ANY WARRANTY; without even the implied warranty of
155.16 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
155.17 + GNU General Public License for more details.
155.18 +
155.19 + You should have received a copy of the GNU General Public License
155.20 + along with this program. Look for COPYING file in the top folder.
155.21 + If not, see http://opensource.org/licenses/GPL-2.0.
155.22 +
155.23 +-->
155.24 +<!DOCTYPE html>
155.25 +<html xmlns="http://www.w3.org/1999/xhtml">
155.26 + <head>
155.27 + <title id="pg.title">Default Title</title>
155.28 + </head>
155.29 + <body>
155.30 + New title: <input id="pg.text"/>
155.31 + <button id="pg.button">Change title!</button>
155.32 + </body>
155.33 +</html>
156.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
156.2 +++ b/javaquery/demo-calculator-dynamic/nbactions.xml Wed Jan 23 20:16:48 2013 +0100
156.3 @@ -0,0 +1,29 @@
156.4 +<?xml version="1.0" encoding="UTF-8"?>
156.5 +<!--
156.6 +
156.7 + Back 2 Browser Bytecode Translator
156.8 + Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
156.9 +
156.10 + This program is free software: you can redistribute it and/or modify
156.11 + it under the terms of the GNU General Public License as published by
156.12 + the Free Software Foundation, version 2 of the License.
156.13 +
156.14 + This program is distributed in the hope that it will be useful,
156.15 + but WITHOUT ANY WARRANTY; without even the implied warranty of
156.16 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
156.17 + GNU General Public License for more details.
156.18 +
156.19 + You should have received a copy of the GNU General Public License
156.20 + along with this program. Look for COPYING file in the top folder.
156.21 + If not, see http://opensource.org/licenses/GPL-2.0.
156.22 +
156.23 +-->
156.24 +<actions>
156.25 + <action>
156.26 + <actionName>run</actionName>
156.27 + <goals>
156.28 + <goal>process-classes</goal>
156.29 + <goal>org.apidesign.bck2brwsr:mojo:0.3-SNAPSHOT:brwsr</goal>
156.30 + </goals>
156.31 + </action>
156.32 + </actions>
157.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
157.2 +++ b/javaquery/demo-calculator-dynamic/pom.xml Wed Jan 23 20:16:48 2013 +0100
157.3 @@ -0,0 +1,64 @@
157.4 +<?xml version="1.0"?>
157.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
157.6 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
157.7 + <modelVersion>4.0.0</modelVersion>
157.8 +
157.9 + <groupId>org.apidesign.bck2brwsr</groupId>
157.10 + <artifactId>demo.calculator</artifactId>
157.11 + <version>0.3-SNAPSHOT</version>
157.12 + <packaging>jar</packaging>
157.13 +
157.14 + <name>JavaQuery Demo - Calculator</name>
157.15 + <url>http://maven.apache.org</url>
157.16 +
157.17 + <properties>
157.18 + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
157.19 + </properties>
157.20 + <build>
157.21 + <plugins>
157.22 + <plugin>
157.23 + <groupId>org.apidesign.bck2brwsr</groupId>
157.24 + <artifactId>mojo</artifactId>
157.25 + <version>0.3-SNAPSHOT</version>
157.26 + <executions>
157.27 + <execution>
157.28 + <goals>
157.29 + <goal>brwsr</goal>
157.30 + </goals>
157.31 + </execution>
157.32 + </executions>
157.33 + <configuration>
157.34 + <startpage>org/apidesign/bck2brwsr/demo/calc/Calculator.xhtml</startpage>
157.35 + </configuration>
157.36 + </plugin>
157.37 + <plugin>
157.38 + <groupId>org.apache.maven.plugins</groupId>
157.39 + <artifactId>maven-compiler-plugin</artifactId>
157.40 + <version>2.3.2</version>
157.41 + <configuration>
157.42 + <source>1.7</source>
157.43 + <target>1.7</target>
157.44 + </configuration>
157.45 + </plugin>
157.46 + </plugins>
157.47 + </build>
157.48 +
157.49 + <dependencies>
157.50 + <dependency>
157.51 + <groupId>org.apidesign.bck2brwsr</groupId>
157.52 + <artifactId>emul</artifactId>
157.53 + <version>0.3-SNAPSHOT</version>
157.54 + </dependency>
157.55 + <dependency>
157.56 + <groupId>org.apidesign.bck2brwsr</groupId>
157.57 + <artifactId>javaquery.api</artifactId>
157.58 + <version>0.3-SNAPSHOT</version>
157.59 + </dependency>
157.60 + <dependency>
157.61 + <groupId>org.testng</groupId>
157.62 + <artifactId>testng</artifactId>
157.63 + <version>6.5.2</version>
157.64 + <scope>test</scope>
157.65 + </dependency>
157.66 + </dependencies>
157.67 +</project>
158.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
158.2 +++ b/javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/demo/calc/Calc.java Wed Jan 23 20:16:48 2013 +0100
158.3 @@ -0,0 +1,112 @@
158.4 +/**
158.5 + * Back 2 Browser Bytecode Translator
158.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
158.7 + *
158.8 + * This program is free software: you can redistribute it and/or modify
158.9 + * it under the terms of the GNU General Public License as published by
158.10 + * the Free Software Foundation, version 2 of the License.
158.11 + *
158.12 + * This program is distributed in the hope that it will be useful,
158.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
158.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
158.15 + * GNU General Public License for more details.
158.16 + *
158.17 + * You should have received a copy of the GNU General Public License
158.18 + * along with this program. Look for COPYING file in the top folder.
158.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
158.20 + */
158.21 +package org.apidesign.bck2brwsr.demo.calc;
158.22 +
158.23 +import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
158.24 +import org.apidesign.bck2brwsr.htmlpage.api.On;
158.25 +import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;
158.26 +import org.apidesign.bck2brwsr.htmlpage.api.Page;
158.27 +import org.apidesign.bck2brwsr.htmlpage.api.Property;
158.28 +
158.29 +/** HTML5 & Java demo showing the power of
158.30 + * <a href="http://wiki.apidesign.org/wiki/AnnotationProcessor">annotation processors</a>
158.31 + * as well as other goodies.
158.32 + *
158.33 + * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
158.34 + */
158.35 +@Page(xhtml="Calculator.xhtml", properties = {
158.36 + @Property(name = "memory", type = double.class),
158.37 + @Property(name = "display", type = double.class),
158.38 + @Property(name = "operation", type = String.class),
158.39 + @Property(name = "hover", type = boolean.class)
158.40 +})
158.41 +public class Calc {
158.42 + static {
158.43 + new Calculator().applyBindings();
158.44 + }
158.45 +
158.46 + @On(event = CLICK, id="clear")
158.47 + static void clear(Calculator c) {
158.48 + c.setMemory(0);
158.49 + c.setOperation(null);
158.50 + c.setDisplay(0);
158.51 + }
158.52 +
158.53 + @On(event = CLICK, id= { "plus", "minus", "mul", "div" })
158.54 + static void applyOp(Calculator c, String op) {
158.55 + c.setMemory(c.getDisplay());
158.56 + c.setOperation(op);
158.57 + c.setDisplay(0);
158.58 + }
158.59 +
158.60 + @On(event = MOUSE_OVER, id= { "result" })
158.61 + static void attemptingIn(Calculator c, String op) {
158.62 + c.setHover(true);
158.63 + }
158.64 + @On(event = MOUSE_OUT, id= { "result" })
158.65 + static void attemptingOut(Calculator c, String op) {
158.66 + c.setHover(false);
158.67 + }
158.68 +
158.69 + @On(event = CLICK, id="result")
158.70 + static void computeTheValue(Calculator c) {
158.71 + c.setDisplay(compute(
158.72 + c.getOperation(),
158.73 + c.getMemory(),
158.74 + c.getDisplay()
158.75 + ));
158.76 + c.setMemory(0);
158.77 + }
158.78 +
158.79 + private static double compute(String op, double memory, double display) {
158.80 + switch (op) {
158.81 + case "plus": return memory + display;
158.82 + case "minus": return memory - display;
158.83 + case "mul": return memory * display;
158.84 + case "div": return memory / display;
158.85 + default: throw new IllegalStateException(op);
158.86 + }
158.87 + }
158.88 +
158.89 + @On(event = CLICK, id={"n0", "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9"})
158.90 + static void addDigit(String digit, Calculator c) {
158.91 + digit = digit.substring(1);
158.92 +
158.93 + double v = c.getDisplay();
158.94 + if (v == 0.0) {
158.95 + c.setDisplay(Integer.parseInt(digit));
158.96 + } else {
158.97 + String txt = Double.toString(v);
158.98 + if (txt.endsWith(".0")) {
158.99 + txt = txt.substring(0, txt.length() - 2);
158.100 + }
158.101 + txt = txt + digit;
158.102 + c.setDisplay(Double.parseDouble(txt));
158.103 + }
158.104 + }
158.105 +
158.106 + @ComputedProperty
158.107 + public static String displayPreview(
158.108 + double display, boolean hover, double memory, String operation
158.109 + ) {
158.110 + if (!hover) {
158.111 + return "Type numbers and perform simple operations! Press '=' to get result.";
158.112 + }
158.113 + return "Attempt to compute " + memory + " " + operation + " " + display + " = " + compute(operation, memory, display);
158.114 + }
158.115 +}
159.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
159.2 +++ b/javaquery/demo-calculator-dynamic/src/main/resources/org/apidesign/bck2brwsr/demo/calc/Calculator.xhtml Wed Jan 23 20:16:48 2013 +0100
159.3 @@ -0,0 +1,159 @@
159.4 +<?xml version="1.0" encoding="UTF-8"?>
159.5 +<!--
159.6 +
159.7 + Back 2 Browser Bytecode Translator
159.8 + Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
159.9 +
159.10 + This program is free software: you can redistribute it and/or modify
159.11 + it under the terms of the GNU General Public License as published by
159.12 + the Free Software Foundation, version 2 of the License.
159.13 +
159.14 + This program is distributed in the hope that it will be useful,
159.15 + but WITHOUT ANY WARRANTY; without even the implied warranty of
159.16 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
159.17 + GNU General Public License for more details.
159.18 +
159.19 + You should have received a copy of the GNU General Public License
159.20 + along with this program. Look for COPYING file in the top folder.
159.21 + If not, see http://opensource.org/licenses/GPL-2.0.
159.22 +
159.23 +-->
159.24 +<!DOCTYPE html>
159.25 +<html xmlns="http://www.w3.org/1999/xhtml">
159.26 + <head>
159.27 + <title>Simple Calculator in HTML5 and Java</title>
159.28 +
159.29 + <style type="text/css">
159.30 + body {color: #ffffff; background-color: #121e31; font-family: Monospaced}
159.31 + pre {color: #ffffff; background-color: #121e31; font-family: Monospaced}
159.32 + table {color: #ffffff; background-color: #121e31; font-family: Monospaced}
159.33 + .string {color: #e2ce00}
159.34 + a {color: #e2ce00}
159.35 + .ST1 {color: #0000cc; font-family: Monospaced; font-weight: bold}
159.36 + .ST0 {color: #0000ff}
159.37 + .comment {color: #428bdd}
159.38 + .keyword-directive {color: #f8bb00}
159.39 + .tag {color: #f8bb00}
159.40 + .ST0 {color: #628fb5; background-color: #1b3450}
159.41 + .sgml-comment {color: #808080}
159.42 + .value {color: #99006b}
159.43 + .argument {color: #007c00}
159.44 + .sgml-declaration {color: #bf9221}
159.45 + </style>
159.46 + </head>
159.47 + <body>
159.48 + <h1>Java and HTML5 - Together at Last!</h1>
159.49 + <table border="0" cellspacing="2">
159.50 + <tbody>
159.51 + <tr>
159.52 + <td colspan="4"><input data-bind="value: display" value="0"
159.53 + style="text-align: right"/>
159.54 + </td>
159.55 + </tr>
159.56 + <tr>
159.57 + <td><button id="n1">1</button></td>
159.58 + <td><button id="n2">2</button></td>
159.59 + <td><button id="n3">3</button></td>
159.60 + <td><button id="plus">+</button></td>
159.61 + </tr>
159.62 + <tr>
159.63 + <td><button id="n4">4</button></td>
159.64 + <td><button id="n5">5</button></td>
159.65 + <td><button id="n6">6</button></td>
159.66 + <td><button id="minus">-</button></td>
159.67 + </tr>
159.68 + <tr>
159.69 + <td><button id="n7">7</button></td>
159.70 + <td><button id="n8">8</button></td>
159.71 + <td><button id="n9">9</button></td>
159.72 + <td><button id="mul">*</button></td>
159.73 + </tr>
159.74 + <tr>
159.75 + <td><button id="clear">C</button></td>
159.76 + <td><button id="n0">0</button></td>
159.77 + <td><button id="result">=</button></td>
159.78 + <td><button id="div">/</button></td>
159.79 + </tr>
159.80 + </tbody>
159.81 + </table>
159.82 + <div data-bind="text: displayPreview"></div>
159.83 +
159.84 + <script src="/bck2brwsr.js"></script>
159.85 + <script src="/vm.js"></script>
159.86 + <script type="text/javascript">
159.87 + vm.loadClass('org.apidesign.bck2brwsr.demo.calc.Calc');
159.88 + </script>
159.89 +
159.90 + <hr/>
159.91 + <pre>
159.92 + <span class="keyword-directive">package</span> org.apidesign.bck2brwsr.mavenhtml;
159.93 +
159.94 + <span class="keyword-directive">import</span> org.apidesign.bck2brwsr.htmlpage.api.OnClick;
159.95 + <span class="keyword-directive">import</span> org.apidesign.bck2brwsr.htmlpage.api.Page;
159.96 +
159.97 + <span class="comment">/**</span> <span class="comment">HTML5</span><span class="comment"> & </span><span class="comment">Java</span> <span class="comment">demo</span> <span class="comment">showing</span> <span class="comment">the</span> <span class="comment">power</span> <span class="comment">of</span> <a href="http://wiki.apidesign.org/wiki/AnnotationProcessor">annotation processors</a>
159.98 + <span class="comment"> * </span><span class="comment">as</span> <span class="comment">well</span> <span class="comment">as</span> <span class="comment">other</span> <span class="comment">goodies</span><span class="comment">, including type-safe association between</span>
159.99 + <span class="comment"> * </span><span class="comment">an XHTML page and Java.</span>
159.100 + <span class="comment"> * </span>
159.101 + <span class="comment"> * </span><span class="ST1">@author</span> <span class="comment">Jaroslav</span> <span class="comment">Tulach</span> <span class="ST0"><jaroslav.tulach@apidesign.org></span>
159.102 + <span class="comment">*/</span>
159.103 + @Page(xhtml=<span class="string">"</span><span class="string">Calculator.xhtml</span><span class="string">"</span>)
159.104 + <span class="keyword-directive">public</span> <span class="keyword-directive">class</span> App {
159.105 + <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">double</span> memory;
159.106 + <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> String operation;
159.107 +
159.108 + @OnClick(id=<span class="string">"</span><span class="string">clear</span><span class="string">"</span>)
159.109 + <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> clear() {
159.110 + memory = <span class="number">0</span>;
159.111 + operation = <span class="keyword-directive">null</span>;
159.112 + Calculator.DISPLAY.setValue(<span class="string">"</span><span class="string">0</span><span class="string">"</span>);
159.113 + }
159.114 +
159.115 + @OnClick(id= { <span class="string">"</span><span class="string">plus</span><span class="string">"</span>, <span class="string">"</span><span class="string">minus</span><span class="string">"</span>, <span class="string">"</span><span class="string">mul</span><span class="string">"</span>, <span class="string">"</span><span class="string">div</span><span class="string">"</span> })
159.116 + <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> applyOp(String op) {
159.117 + memory = getValue();
159.118 + operation = op;
159.119 + Calculator.DISPLAY.setValue(<span class="string">"</span><span class="string">0</span><span class="string">"</span>);
159.120 + }
159.121 +
159.122 + @OnClick(id=<span class="string">"</span><span class="string">result</span><span class="string">"</span>)
159.123 + <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> computeTheValue() {
159.124 + <span class="keyword-directive">switch</span> (operation) {
159.125 + <span class="keyword-directive">case</span> <span class="string">"</span><span class="string">plus</span><span class="string">"</span>: setValue(memory + getValue()); <span class="keyword-directive">break</span>;
159.126 + <span class="keyword-directive">case</span> <span class="string">"</span><span class="string">minus</span><span class="string">"</span>: setValue(memory - getValue()); <span class="keyword-directive">break</span>;
159.127 + <span class="keyword-directive">case</span> <span class="string">"</span><span class="string">mul</span><span class="string">"</span>: setValue(memory * getValue()); <span class="keyword-directive">break</span>;
159.128 + <span class="keyword-directive">case</span> <span class="string">"</span><span class="string">div</span><span class="string">"</span>: setValue(memory / getValue()); <span class="keyword-directive">break</span>;
159.129 + <span class="keyword-directive">default</span>: <span class="keyword-directive">throw</span> <span class="keyword-directive">new</span> IllegalStateException(operation);
159.130 + }
159.131 + }
159.132 +
159.133 + @OnClick(id={<span class="string">"</span><span class="string">n0</span><span class="string">"</span>, <span class="string">"</span><span class="string">n1</span><span class="string">"</span>, <span class="string">"</span><span class="string">n2</span><span class="string">"</span>, <span class="string">"</span><span class="string">n3</span><span class="string">"</span>, <span class="string">"</span><span class="string">n4</span><span class="string">"</span>, <span class="string">"</span><span class="string">n5</span><span class="string">"</span>, <span class="string">"</span><span class="string">n6</span><span class="string">"</span>, <span class="string">"</span><span class="string">n7</span><span class="string">"</span>, <span class="string">"</span><span class="string">n8</span><span class="string">"</span>, <span class="string">"</span><span class="string">n9</span><span class="string">"</span>})
159.134 + <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> addDigit(String digit) {
159.135 + digit = digit.substring(<span class="number">1</span>);
159.136 + String v = Calculator.DISPLAY.getValue();
159.137 + <span class="keyword-directive">if</span> (getValue() == <span class="number">0.0</span>) {
159.138 + Calculator.DISPLAY.setValue(digit);
159.139 + } <span class="keyword-directive">else</span> {
159.140 + Calculator.DISPLAY.setValue(v + digit);
159.141 + }
159.142 + }
159.143 +
159.144 + <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> setValue(<span class="keyword-directive">double</span> v) {
159.145 + StringBuilder sb = <span class="keyword-directive">new</span> StringBuilder();
159.146 + sb.append(v);
159.147 + Calculator.DISPLAY.setValue(sb.toString());
159.148 + }
159.149 +
159.150 + <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">double</span> getValue() {
159.151 + <span class="keyword-directive">try</span> {
159.152 + <span class="keyword-directive">return</span> Double.parseDouble(Calculator.DISPLAY.getValue());
159.153 + } <span class="keyword-directive">catch</span> (NumberFormatException ex) {
159.154 + Calculator.DISPLAY.setValue(<span class="string">"</span><span class="string">err</span><span class="string">"</span>);
159.155 + <span class="keyword-directive">return</span> <span class="number">0.0</span>;
159.156 + }
159.157 + }
159.158 + }
159.159 +
159.160 + </pre>
159.161 + </body>
159.162 +</html>
160.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
160.2 +++ b/javaquery/demo-calculator-dynamic/src/test/java/org/apidesign/bck2brwsr/demo/calc/CalcTest.java Wed Jan 23 20:16:48 2013 +0100
160.3 @@ -0,0 +1,46 @@
160.4 +/**
160.5 + * Back 2 Browser Bytecode Translator
160.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
160.7 + *
160.8 + * This program is free software: you can redistribute it and/or modify
160.9 + * it under the terms of the GNU General Public License as published by
160.10 + * the Free Software Foundation, version 2 of the License.
160.11 + *
160.12 + * This program is distributed in the hope that it will be useful,
160.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
160.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
160.15 + * GNU General Public License for more details.
160.16 + *
160.17 + * You should have received a copy of the GNU General Public License
160.18 + * along with this program. Look for COPYING file in the top folder.
160.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
160.20 + */
160.21 +package org.apidesign.bck2brwsr.demo.calc;
160.22 +
160.23 +import static org.testng.Assert.*;
160.24 +import org.testng.annotations.BeforeMethod;
160.25 +import org.testng.annotations.Test;
160.26 +
160.27 +/** Demonstrating POJO testing of HTML page model.
160.28 + *
160.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
160.30 + */
160.31 +public class CalcTest {
160.32 + private Calculator model;
160.33 +
160.34 +
160.35 + @BeforeMethod
160.36 + public void initModel() {
160.37 + model = new Calculator().applyBindings();
160.38 + }
160.39 +
160.40 + @Test
160.41 + public void testSomeMethod() {
160.42 + model.setDisplay(10);
160.43 + Calc.applyOp(model, "plus");
160.44 + assertEquals(0.0, model.getDisplay(), "Cleared after pressing +");
160.45 + model.setDisplay(5);
160.46 + Calc.computeTheValue(model);
160.47 + assertEquals(15.0, model.getDisplay(), "Shows fifteen");
160.48 + }
160.49 +}
161.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
161.2 +++ b/javaquery/demo-calculator/nbactions.xml Wed Jan 23 20:16:48 2013 +0100
161.3 @@ -0,0 +1,29 @@
161.4 +<?xml version="1.0" encoding="UTF-8"?>
161.5 +<!--
161.6 +
161.7 + Back 2 Browser Bytecode Translator
161.8 + Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
161.9 +
161.10 + This program is free software: you can redistribute it and/or modify
161.11 + it under the terms of the GNU General Public License as published by
161.12 + the Free Software Foundation, version 2 of the License.
161.13 +
161.14 + This program is distributed in the hope that it will be useful,
161.15 + but WITHOUT ANY WARRANTY; without even the implied warranty of
161.16 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
161.17 + GNU General Public License for more details.
161.18 +
161.19 + You should have received a copy of the GNU General Public License
161.20 + along with this program. Look for COPYING file in the top folder.
161.21 + If not, see http://opensource.org/licenses/GPL-2.0.
161.22 +
161.23 +-->
161.24 +<actions>
161.25 + <action>
161.26 + <actionName>run</actionName>
161.27 + <goals>
161.28 + <goal>process-classes</goal>
161.29 + <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
161.30 + </goals>
161.31 + </action>
161.32 + </actions>
162.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
162.2 +++ b/javaquery/demo-calculator/pom.xml Wed Jan 23 20:16:48 2013 +0100
162.3 @@ -0,0 +1,73 @@
162.4 +<?xml version="1.0"?>
162.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
162.6 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
162.7 + <modelVersion>4.0.0</modelVersion>
162.8 +
162.9 + <groupId>org.apidesign.bck2brwsr</groupId>
162.10 + <artifactId>demo.static.calculator</artifactId>
162.11 + <version>0.3-SNAPSHOT</version>
162.12 + <packaging>jar</packaging>
162.13 +
162.14 + <name>JavaQuery Demo - Calculator - Static Compilation</name>
162.15 + <url>http://maven.apache.org</url>
162.16 +
162.17 + <properties>
162.18 + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
162.19 + </properties>
162.20 + <build>
162.21 + <plugins>
162.22 + <plugin>
162.23 + <groupId>org.apidesign.bck2brwsr</groupId>
162.24 + <artifactId>mojo</artifactId>
162.25 + <version>0.3-SNAPSHOT</version>
162.26 + <executions>
162.27 + <execution>
162.28 + <goals>
162.29 + <goal>j2js</goal>
162.30 + </goals>
162.31 + </execution>
162.32 + </executions>
162.33 + </plugin>
162.34 + <plugin>
162.35 + <groupId>org.codehaus.mojo</groupId>
162.36 + <artifactId>exec-maven-plugin</artifactId>
162.37 + <version>1.2.1</version>
162.38 + <executions>
162.39 + <execution>
162.40 + <goals>
162.41 + <goal>exec</goal>
162.42 + </goals>
162.43 + </execution>
162.44 + </executions>
162.45 + <configuration>
162.46 + <executable>xdg-open</executable>
162.47 + <arguments>
162.48 + <argument>${project.build.directory}/classes/org/apidesign/bck2brwsr/demo/calc/staticcompilation/Calculator.xhtml</argument>
162.49 + </arguments>
162.50 + </configuration>
162.51 + </plugin>
162.52 + <plugin>
162.53 + <groupId>org.apache.maven.plugins</groupId>
162.54 + <artifactId>maven-compiler-plugin</artifactId>
162.55 + <version>2.3.2</version>
162.56 + <configuration>
162.57 + <source>1.7</source>
162.58 + <target>1.7</target>
162.59 + </configuration>
162.60 + </plugin>
162.61 + </plugins>
162.62 + </build>
162.63 +
162.64 + <dependencies>
162.65 + <dependency>
162.66 + <groupId>org.apidesign.bck2brwsr</groupId>
162.67 + <artifactId>emul</artifactId>
162.68 + <version>0.3-SNAPSHOT</version>
162.69 + </dependency>
162.70 + <dependency>
162.71 + <groupId>org.apidesign.bck2brwsr</groupId>
162.72 + <artifactId>javaquery.api</artifactId>
162.73 + <version>0.3-SNAPSHOT</version>
162.74 + </dependency>
162.75 + </dependencies>
162.76 +</project>
163.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
163.2 +++ b/javaquery/demo-calculator/src/main/java/org/apidesign/bck2brwsr/demo/calc/staticcompilation/Calc.java Wed Jan 23 20:16:48 2013 +0100
163.3 @@ -0,0 +1,112 @@
163.4 +/**
163.5 + * Back 2 Browser Bytecode Translator
163.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
163.7 + *
163.8 + * This program is free software: you can redistribute it and/or modify
163.9 + * it under the terms of the GNU General Public License as published by
163.10 + * the Free Software Foundation, version 2 of the License.
163.11 + *
163.12 + * This program is distributed in the hope that it will be useful,
163.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
163.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
163.15 + * GNU General Public License for more details.
163.16 + *
163.17 + * You should have received a copy of the GNU General Public License
163.18 + * along with this program. Look for COPYING file in the top folder.
163.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
163.20 + */
163.21 +package org.apidesign.bck2brwsr.demo.calc.staticcompilation;
163.22 +
163.23 +import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
163.24 +import org.apidesign.bck2brwsr.htmlpage.api.On;
163.25 +import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;
163.26 +import org.apidesign.bck2brwsr.htmlpage.api.Page;
163.27 +import org.apidesign.bck2brwsr.htmlpage.api.Property;
163.28 +
163.29 +/** HTML5 & Java demo showing the power of
163.30 + * <a href="http://wiki.apidesign.org/wiki/AnnotationProcessor">annotation processors</a>
163.31 + * as well as other goodies.
163.32 + *
163.33 + * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
163.34 + */
163.35 +@Page(xhtml="Calculator.xhtml", properties = {
163.36 + @Property(name = "memory", type = double.class),
163.37 + @Property(name = "display", type = double.class),
163.38 + @Property(name = "operation", type = String.class),
163.39 + @Property(name = "hover", type = boolean.class)
163.40 +})
163.41 +public class Calc {
163.42 + static {
163.43 + new Calculator().applyBindings();
163.44 + }
163.45 +
163.46 + @On(event = CLICK, id="clear")
163.47 + static void clear(Calculator c) {
163.48 + c.setMemory(0);
163.49 + c.setOperation(null);
163.50 + c.setDisplay(0);
163.51 + }
163.52 +
163.53 + @On(event = CLICK, id= { "plus", "minus", "mul", "div" })
163.54 + static void applyOp(Calculator c, String op) {
163.55 + c.setMemory(c.getDisplay());
163.56 + c.setOperation(op);
163.57 + c.setDisplay(0);
163.58 + }
163.59 +
163.60 + @On(event = MOUSE_OVER, id= { "result" })
163.61 + static void attemptingIn(Calculator c, String op) {
163.62 + c.setHover(true);
163.63 + }
163.64 + @On(event = MOUSE_OUT, id= { "result" })
163.65 + static void attemptingOut(Calculator c, String op) {
163.66 + c.setHover(false);
163.67 + }
163.68 +
163.69 + @On(event = CLICK, id="result")
163.70 + static void computeTheValue(Calculator c) {
163.71 + c.setDisplay(compute(
163.72 + c.getOperation(),
163.73 + c.getMemory(),
163.74 + c.getDisplay()
163.75 + ));
163.76 + c.setMemory(0);
163.77 + }
163.78 +
163.79 + private static double compute(String op, double memory, double display) {
163.80 + switch (op) {
163.81 + case "plus": return memory + display;
163.82 + case "minus": return memory - display;
163.83 + case "mul": return memory * display;
163.84 + case "div": return memory / display;
163.85 + default: throw new IllegalStateException(op);
163.86 + }
163.87 + }
163.88 +
163.89 + @On(event = CLICK, id={"n0", "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9"})
163.90 + static void addDigit(String digit, Calculator c) {
163.91 + digit = digit.substring(1);
163.92 +
163.93 + double v = c.getDisplay();
163.94 + if (v == 0.0) {
163.95 + c.setDisplay(Integer.parseInt(digit));
163.96 + } else {
163.97 + String txt = Double.toString(v);
163.98 + if (txt.endsWith(".0")) {
163.99 + txt = txt.substring(0, txt.length() - 2);
163.100 + }
163.101 + txt = txt + digit;
163.102 + c.setDisplay(Double.parseDouble(txt));
163.103 + }
163.104 + }
163.105 +
163.106 + @ComputedProperty
163.107 + public static String displayPreview(
163.108 + double display, boolean hover, double memory, String operation
163.109 + ) {
163.110 + if (!hover) {
163.111 + return "Type numbers and perform simple operations! Press '=' to get result.";
163.112 + }
163.113 + return "Attempt to compute " + memory + " " + operation + " " + display + " = " + compute(operation, memory, display);
163.114 + }
163.115 +}
164.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
164.2 +++ b/javaquery/demo-calculator/src/main/resources/org/apidesign/bck2brwsr/demo/calc/staticcompilation/Calculator.xhtml Wed Jan 23 20:16:48 2013 +0100
164.3 @@ -0,0 +1,154 @@
164.4 +<?xml version="1.0" encoding="UTF-8"?>
164.5 +<!--
164.6 +
164.7 + Back 2 Browser Bytecode Translator
164.8 + Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
164.9 +
164.10 + This program is free software: you can redistribute it and/or modify
164.11 + it under the terms of the GNU General Public License as published by
164.12 + the Free Software Foundation, version 2 of the License.
164.13 +
164.14 + This program is distributed in the hope that it will be useful,
164.15 + but WITHOUT ANY WARRANTY; without even the implied warranty of
164.16 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
164.17 + GNU General Public License for more details.
164.18 +
164.19 + You should have received a copy of the GNU General Public License
164.20 + along with this program. Look for COPYING file in the top folder.
164.21 + If not, see http://opensource.org/licenses/GPL-2.0.
164.22 +
164.23 +-->
164.24 +<!DOCTYPE html>
164.25 +<html xmlns="http://www.w3.org/1999/xhtml">
164.26 + <head>
164.27 + <title>Simple Calculator in HTML5 and Java</title>
164.28 +
164.29 + <style type="text/css">
164.30 + body {color: #ffffff; background-color: #121e31; font-family: Monospaced}
164.31 + pre {color: #ffffff; background-color: #121e31; font-family: Monospaced}
164.32 + table {color: #ffffff; background-color: #121e31; font-family: Monospaced}
164.33 + .string {color: #e2ce00}
164.34 + a {color: #e2ce00}
164.35 + .ST1 {color: #0000cc; font-family: Monospaced; font-weight: bold}
164.36 + .ST0 {color: #0000ff}
164.37 + .comment {color: #428bdd}
164.38 + .keyword-directive {color: #f8bb00}
164.39 + .tag {color: #f8bb00}
164.40 + .ST0 {color: #628fb5; background-color: #1b3450}
164.41 + .sgml-comment {color: #808080}
164.42 + .value {color: #99006b}
164.43 + .argument {color: #007c00}
164.44 + .sgml-declaration {color: #bf9221}
164.45 + </style>
164.46 + </head>
164.47 + <body>
164.48 + <h1>Java and HTML5 - Together at Last!</h1>
164.49 + <table border="0" cellspacing="2">
164.50 + <tbody>
164.51 + <tr>
164.52 + <td colspan="4"><input data-bind="value: display" value="0"
164.53 + style="text-align: right"/>
164.54 + </td>
164.55 + </tr>
164.56 + <tr>
164.57 + <td><button id="n1">1</button></td>
164.58 + <td><button id="n2">2</button></td>
164.59 + <td><button id="n3">3</button></td>
164.60 + <td><button id="plus">+</button></td>
164.61 + </tr>
164.62 + <tr>
164.63 + <td><button id="n4">4</button></td>
164.64 + <td><button id="n5">5</button></td>
164.65 + <td><button id="n6">6</button></td>
164.66 + <td><button id="minus">-</button></td>
164.67 + </tr>
164.68 + <tr>
164.69 + <td><button id="n7">7</button></td>
164.70 + <td><button id="n8">8</button></td>
164.71 + <td><button id="n9">9</button></td>
164.72 + <td><button id="mul">*</button></td>
164.73 + </tr>
164.74 + <tr>
164.75 + <td><button id="clear">C</button></td>
164.76 + <td><button id="n0">0</button></td>
164.77 + <td><button id="result">=</button></td>
164.78 + <td><button id="div">/</button></td>
164.79 + </tr>
164.80 + </tbody>
164.81 + </table>
164.82 + <div data-bind="text: displayPreview"></div>
164.83 + <script src="bootjava.js"/>
164.84 +
164.85 + <hr/>
164.86 + <pre>
164.87 + <span class="keyword-directive">package</span> org.apidesign.bck2brwsr.mavenhtml;
164.88 +
164.89 + <span class="keyword-directive">import</span> org.apidesign.bck2brwsr.htmlpage.api.OnClick;
164.90 + <span class="keyword-directive">import</span> org.apidesign.bck2brwsr.htmlpage.api.Page;
164.91 +
164.92 + <span class="comment">/**</span> <span class="comment">HTML5</span><span class="comment"> & </span><span class="comment">Java</span> <span class="comment">demo</span> <span class="comment">showing</span> <span class="comment">the</span> <span class="comment">power</span> <span class="comment">of</span> <a href="http://wiki.apidesign.org/wiki/AnnotationProcessor">annotation processors</a>
164.93 + <span class="comment"> * </span><span class="comment">as</span> <span class="comment">well</span> <span class="comment">as</span> <span class="comment">other</span> <span class="comment">goodies</span><span class="comment">, including type-safe association between</span>
164.94 + <span class="comment"> * </span><span class="comment">an XHTML page and Java.</span>
164.95 + <span class="comment"> * </span>
164.96 + <span class="comment"> * </span><span class="ST1">@author</span> <span class="comment">Jaroslav</span> <span class="comment">Tulach</span> <span class="ST0"><jaroslav.tulach@apidesign.org></span>
164.97 + <span class="comment">*/</span>
164.98 + @Page(xhtml=<span class="string">"</span><span class="string">Calculator.xhtml</span><span class="string">"</span>)
164.99 + <span class="keyword-directive">public</span> <span class="keyword-directive">class</span> App {
164.100 + <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">double</span> memory;
164.101 + <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> String operation;
164.102 +
164.103 + @OnClick(id=<span class="string">"</span><span class="string">clear</span><span class="string">"</span>)
164.104 + <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> clear() {
164.105 + memory = <span class="number">0</span>;
164.106 + operation = <span class="keyword-directive">null</span>;
164.107 + Calculator.DISPLAY.setValue(<span class="string">"</span><span class="string">0</span><span class="string">"</span>);
164.108 + }
164.109 +
164.110 + @OnClick(id= { <span class="string">"</span><span class="string">plus</span><span class="string">"</span>, <span class="string">"</span><span class="string">minus</span><span class="string">"</span>, <span class="string">"</span><span class="string">mul</span><span class="string">"</span>, <span class="string">"</span><span class="string">div</span><span class="string">"</span> })
164.111 + <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> applyOp(String op) {
164.112 + memory = getValue();
164.113 + operation = op;
164.114 + Calculator.DISPLAY.setValue(<span class="string">"</span><span class="string">0</span><span class="string">"</span>);
164.115 + }
164.116 +
164.117 + @OnClick(id=<span class="string">"</span><span class="string">result</span><span class="string">"</span>)
164.118 + <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> computeTheValue() {
164.119 + <span class="keyword-directive">switch</span> (operation) {
164.120 + <span class="keyword-directive">case</span> <span class="string">"</span><span class="string">plus</span><span class="string">"</span>: setValue(memory + getValue()); <span class="keyword-directive">break</span>;
164.121 + <span class="keyword-directive">case</span> <span class="string">"</span><span class="string">minus</span><span class="string">"</span>: setValue(memory - getValue()); <span class="keyword-directive">break</span>;
164.122 + <span class="keyword-directive">case</span> <span class="string">"</span><span class="string">mul</span><span class="string">"</span>: setValue(memory * getValue()); <span class="keyword-directive">break</span>;
164.123 + <span class="keyword-directive">case</span> <span class="string">"</span><span class="string">div</span><span class="string">"</span>: setValue(memory / getValue()); <span class="keyword-directive">break</span>;
164.124 + <span class="keyword-directive">default</span>: <span class="keyword-directive">throw</span> <span class="keyword-directive">new</span> IllegalStateException(operation);
164.125 + }
164.126 + }
164.127 +
164.128 + @OnClick(id={<span class="string">"</span><span class="string">n0</span><span class="string">"</span>, <span class="string">"</span><span class="string">n1</span><span class="string">"</span>, <span class="string">"</span><span class="string">n2</span><span class="string">"</span>, <span class="string">"</span><span class="string">n3</span><span class="string">"</span>, <span class="string">"</span><span class="string">n4</span><span class="string">"</span>, <span class="string">"</span><span class="string">n5</span><span class="string">"</span>, <span class="string">"</span><span class="string">n6</span><span class="string">"</span>, <span class="string">"</span><span class="string">n7</span><span class="string">"</span>, <span class="string">"</span><span class="string">n8</span><span class="string">"</span>, <span class="string">"</span><span class="string">n9</span><span class="string">"</span>})
164.129 + <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> addDigit(String digit) {
164.130 + digit = digit.substring(<span class="number">1</span>);
164.131 + String v = Calculator.DISPLAY.getValue();
164.132 + <span class="keyword-directive">if</span> (getValue() == <span class="number">0.0</span>) {
164.133 + Calculator.DISPLAY.setValue(digit);
164.134 + } <span class="keyword-directive">else</span> {
164.135 + Calculator.DISPLAY.setValue(v + digit);
164.136 + }
164.137 + }
164.138 +
164.139 + <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> setValue(<span class="keyword-directive">double</span> v) {
164.140 + StringBuilder sb = <span class="keyword-directive">new</span> StringBuilder();
164.141 + sb.append(v);
164.142 + Calculator.DISPLAY.setValue(sb.toString());
164.143 + }
164.144 +
164.145 + <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">double</span> getValue() {
164.146 + <span class="keyword-directive">try</span> {
164.147 + <span class="keyword-directive">return</span> Double.parseDouble(Calculator.DISPLAY.getValue());
164.148 + } <span class="keyword-directive">catch</span> (NumberFormatException ex) {
164.149 + Calculator.DISPLAY.setValue(<span class="string">"</span><span class="string">err</span><span class="string">"</span>);
164.150 + <span class="keyword-directive">return</span> <span class="number">0.0</span>;
164.151 + }
164.152 + }
164.153 + }
164.154 +
164.155 + </pre>
164.156 + </body>
164.157 +</html>
165.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
165.2 +++ b/javaquery/pom.xml Wed Jan 23 20:16:48 2013 +0100
165.3 @@ -0,0 +1,19 @@
165.4 +<?xml version="1.0" encoding="UTF-8"?>
165.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
165.6 + <modelVersion>4.0.0</modelVersion>
165.7 + <parent>
165.8 + <artifactId>bck2brwsr</artifactId>
165.9 + <groupId>org.apidesign</groupId>
165.10 + <version>0.3-SNAPSHOT</version>
165.11 + </parent>
165.12 + <groupId>org.apidesign.bck2brwsr</groupId>
165.13 + <artifactId>javaquery</artifactId>
165.14 + <version>0.3-SNAPSHOT</version>
165.15 + <packaging>pom</packaging>
165.16 + <name>JavaQuery API and Demo</name>
165.17 + <modules>
165.18 + <module>api</module>
165.19 + <module>demo-calculator</module>
165.20 + <module>demo-calculator-dynamic</module>
165.21 + </modules>
165.22 +</project>
166.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
166.2 +++ b/launcher/pom.xml Wed Jan 23 20:16:48 2013 +0100
166.3 @@ -0,0 +1,49 @@
166.4 +<?xml version="1.0"?>
166.5 +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
166.6 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
166.7 + <modelVersion>4.0.0</modelVersion>
166.8 + <parent>
166.9 + <groupId>org.apidesign</groupId>
166.10 + <artifactId>bck2brwsr</artifactId>
166.11 + <version>0.3-SNAPSHOT</version>
166.12 + </parent>
166.13 + <groupId>org.apidesign.bck2brwsr</groupId>
166.14 + <artifactId>launcher</artifactId>
166.15 + <version>0.3-SNAPSHOT</version>
166.16 + <name>Bck2Brwsr Launcher</name>
166.17 + <url>http://maven.apache.org</url>
166.18 + <build>
166.19 + <plugins>
166.20 + <plugin>
166.21 + <groupId>org.apache.maven.plugins</groupId>
166.22 + <artifactId>maven-compiler-plugin</artifactId>
166.23 + <version>2.3.2</version>
166.24 + <configuration>
166.25 + <source>1.7</source>
166.26 + <target>1.7</target>
166.27 + </configuration>
166.28 + </plugin>
166.29 + </plugins>
166.30 + </build>
166.31 + <properties>
166.32 + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
166.33 + </properties>
166.34 + <dependencies>
166.35 + <dependency>
166.36 + <groupId>junit</groupId>
166.37 + <artifactId>junit</artifactId>
166.38 + <version>3.8.1</version>
166.39 + <scope>test</scope>
166.40 + </dependency>
166.41 + <dependency>
166.42 + <groupId>org.glassfish.grizzly</groupId>
166.43 + <artifactId>grizzly-http-server</artifactId>
166.44 + <version>2.2.19</version>
166.45 + </dependency>
166.46 + <dependency>
166.47 + <groupId>${project.groupId}</groupId>
166.48 + <artifactId>vm4brwsr</artifactId>
166.49 + <version>${project.version}</version>
166.50 + </dependency>
166.51 + </dependencies>
166.52 +</project>
167.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
167.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java Wed Jan 23 20:16:48 2013 +0100
167.3 @@ -0,0 +1,486 @@
167.4 +/**
167.5 + * Back 2 Browser Bytecode Translator
167.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
167.7 + *
167.8 + * This program is free software: you can redistribute it and/or modify
167.9 + * it under the terms of the GNU General Public License as published by
167.10 + * the Free Software Foundation, version 2 of the License.
167.11 + *
167.12 + * This program is distributed in the hope that it will be useful,
167.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
167.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
167.15 + * GNU General Public License for more details.
167.16 + *
167.17 + * You should have received a copy of the GNU General Public License
167.18 + * along with this program. Look for COPYING file in the top folder.
167.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
167.20 + */
167.21 +package org.apidesign.bck2brwsr.launcher;
167.22 +
167.23 +import java.io.Closeable;
167.24 +import java.io.File;
167.25 +import java.io.IOException;
167.26 +import java.io.InputStream;
167.27 +import java.io.InterruptedIOException;
167.28 +import java.io.OutputStream;
167.29 +import java.io.Writer;
167.30 +import java.net.URI;
167.31 +import java.net.URISyntaxException;
167.32 +import java.net.URL;
167.33 +import java.util.ArrayList;
167.34 +import java.util.Arrays;
167.35 +import java.util.Enumeration;
167.36 +import java.util.LinkedHashSet;
167.37 +import java.util.List;
167.38 +import java.util.Set;
167.39 +import java.util.concurrent.BlockingQueue;
167.40 +import java.util.concurrent.CountDownLatch;
167.41 +import java.util.concurrent.LinkedBlockingQueue;
167.42 +import java.util.concurrent.TimeUnit;
167.43 +import java.util.logging.Level;
167.44 +import java.util.logging.Logger;
167.45 +import org.apidesign.vm4brwsr.Bck2Brwsr;
167.46 +import org.glassfish.grizzly.PortRange;
167.47 +import org.glassfish.grizzly.http.server.HttpHandler;
167.48 +import org.glassfish.grizzly.http.server.HttpServer;
167.49 +import org.glassfish.grizzly.http.server.NetworkListener;
167.50 +import org.glassfish.grizzly.http.server.Request;
167.51 +import org.glassfish.grizzly.http.server.Response;
167.52 +import org.glassfish.grizzly.http.server.ServerConfiguration;
167.53 +
167.54 +/**
167.55 + * Lightweight server to launch Bck2Brwsr applications and tests.
167.56 + * Supports execution in native browser as well as Java's internal
167.57 + * execution engine.
167.58 + */
167.59 +final class Bck2BrwsrLauncher extends Launcher implements Closeable {
167.60 + private static final Logger LOG = Logger.getLogger(Bck2BrwsrLauncher.class.getName());
167.61 + private static final MethodInvocation END = new MethodInvocation(null, null, null);
167.62 + private Set<ClassLoader> loaders = new LinkedHashSet<>();
167.63 + private BlockingQueue<MethodInvocation> methods = new LinkedBlockingQueue<>();
167.64 + private long timeOut;
167.65 + private final Res resources = new Res();
167.66 + private final String cmd;
167.67 + private Object[] brwsr;
167.68 + private HttpServer server;
167.69 + private CountDownLatch wait;
167.70 +
167.71 + public Bck2BrwsrLauncher(String cmd) {
167.72 + this.cmd = cmd;
167.73 + }
167.74 +
167.75 + @Override
167.76 + MethodInvocation addMethod(Class<?> clazz, String method, String html) throws IOException {
167.77 + loaders.add(clazz.getClassLoader());
167.78 + MethodInvocation c = new MethodInvocation(clazz.getName(), method, html);
167.79 + methods.add(c);
167.80 + try {
167.81 + c.await(timeOut);
167.82 + } catch (InterruptedException ex) {
167.83 + throw new IOException(ex);
167.84 + }
167.85 + return c;
167.86 + }
167.87 +
167.88 + public void setTimeout(long ms) {
167.89 + timeOut = ms;
167.90 + }
167.91 +
167.92 + public void addClassLoader(ClassLoader url) {
167.93 + this.loaders.add(url);
167.94 + }
167.95 +
167.96 + public void showURL(String startpage) throws IOException {
167.97 + if (!startpage.startsWith("/")) {
167.98 + startpage = "/" + startpage;
167.99 + }
167.100 + HttpServer s = initServer();
167.101 + s.getServerConfiguration().addHttpHandler(new Page(resources, null), "/");
167.102 + try {
167.103 + launchServerAndBrwsr(s, startpage);
167.104 + } catch (URISyntaxException | InterruptedException ex) {
167.105 + throw new IOException(ex);
167.106 + }
167.107 + }
167.108 +
167.109 + @Override
167.110 + public void initialize() throws IOException {
167.111 + try {
167.112 + executeInBrowser();
167.113 + } catch (InterruptedException ex) {
167.114 + final InterruptedIOException iio = new InterruptedIOException(ex.getMessage());
167.115 + iio.initCause(ex);
167.116 + throw iio;
167.117 + } catch (Exception ex) {
167.118 + if (ex instanceof IOException) {
167.119 + throw (IOException)ex;
167.120 + }
167.121 + if (ex instanceof RuntimeException) {
167.122 + throw (RuntimeException)ex;
167.123 + }
167.124 + throw new IOException(ex);
167.125 + }
167.126 + }
167.127 +
167.128 + private HttpServer initServer() {
167.129 + HttpServer s = HttpServer.createSimpleServer(".", new PortRange(8080, 65535));
167.130 +
167.131 + final ServerConfiguration conf = s.getServerConfiguration();
167.132 + conf.addHttpHandler(new Page(resources,
167.133 + "org/apidesign/bck2brwsr/launcher/console.xhtml",
167.134 + "org.apidesign.bck2brwsr.launcher.Console", "welcome", "false"
167.135 + ), "/console");
167.136 + conf.addHttpHandler(new VM(resources), "/bck2brwsr.js");
167.137 + conf.addHttpHandler(new VMInit(), "/vm.js");
167.138 + conf.addHttpHandler(new Classes(resources), "/classes/");
167.139 + return s;
167.140 + }
167.141 +
167.142 + private void executeInBrowser() throws InterruptedException, URISyntaxException, IOException {
167.143 + wait = new CountDownLatch(1);
167.144 + server = initServer();
167.145 + ServerConfiguration conf = server.getServerConfiguration();
167.146 + conf.addHttpHandler(new Page(resources,
167.147 + "org/apidesign/bck2brwsr/launcher/harness.xhtml"
167.148 + ), "/execute");
167.149 + conf.addHttpHandler(new HttpHandler() {
167.150 + int cnt;
167.151 + List<MethodInvocation> cases = new ArrayList<>();
167.152 + @Override
167.153 + public void service(Request request, Response response) throws Exception {
167.154 + String id = request.getParameter("request");
167.155 + String value = request.getParameter("result");
167.156 +
167.157 + if (id != null && value != null) {
167.158 + LOG.log(Level.INFO, "Received result for case {0} = {1}", new Object[]{id, value});
167.159 + value = decodeURL(value);
167.160 + cases.get(Integer.parseInt(id)).result(value, null);
167.161 + }
167.162 +
167.163 + MethodInvocation mi = methods.take();
167.164 + if (mi == END) {
167.165 + response.getWriter().write("");
167.166 + wait.countDown();
167.167 + cnt = 0;
167.168 + LOG.log(Level.INFO, "End of data reached. Exiting.");
167.169 + return;
167.170 + }
167.171 +
167.172 + cases.add(mi);
167.173 + final String cn = mi.className;
167.174 + final String mn = mi.methodName;
167.175 + LOG.log(Level.INFO, "Request for {0} case. Sending {1}.{2}", new Object[]{cnt, cn, mn});
167.176 + response.getWriter().write("{"
167.177 + + "className: '" + cn + "', "
167.178 + + "methodName: '" + mn + "', "
167.179 + + "request: " + cnt
167.180 + );
167.181 + if (mi.html != null) {
167.182 + response.getWriter().write(", html: '");
167.183 + response.getWriter().write(encodeJSON(mi.html));
167.184 + response.getWriter().write("'");
167.185 + }
167.186 + response.getWriter().write("}");
167.187 + cnt++;
167.188 + }
167.189 + }, "/data");
167.190 +
167.191 + this.brwsr = launchServerAndBrwsr(server, "/execute");
167.192 + }
167.193 +
167.194 + private static String encodeJSON(String in) {
167.195 + StringBuilder sb = new StringBuilder();
167.196 + for (int i = 0; i < in.length(); i++) {
167.197 + char ch = in.charAt(i);
167.198 + if (ch < 32 || ch == '\'' || ch == '"') {
167.199 + sb.append("\\u");
167.200 + String hs = "0000" + Integer.toHexString(ch);
167.201 + hs = hs.substring(hs.length() - 4);
167.202 + sb.append(hs);
167.203 + } else {
167.204 + sb.append(ch);
167.205 + }
167.206 + }
167.207 + return sb.toString();
167.208 + }
167.209 +
167.210 + @Override
167.211 + public void shutdown() throws IOException {
167.212 + methods.offer(END);
167.213 + for (;;) {
167.214 + int prev = methods.size();
167.215 + try {
167.216 + if (wait != null && wait.await(timeOut, TimeUnit.MILLISECONDS)) {
167.217 + break;
167.218 + }
167.219 + } catch (InterruptedException ex) {
167.220 + throw new IOException(ex);
167.221 + }
167.222 + if (prev == methods.size()) {
167.223 + LOG.log(
167.224 + Level.WARNING,
167.225 + "Timeout and no test has been executed meanwhile (at {0}). Giving up.",
167.226 + methods.size()
167.227 + );
167.228 + break;
167.229 + }
167.230 + LOG.log(Level.INFO,
167.231 + "Timeout, but tests got from {0} to {1}. Trying again.",
167.232 + new Object[]{prev, methods.size()}
167.233 + );
167.234 + }
167.235 + stopServerAndBrwsr(server, brwsr);
167.236 + }
167.237 +
167.238 + static void copyStream(InputStream is, OutputStream os, String baseURL, String... params) throws IOException {
167.239 + for (;;) {
167.240 + int ch = is.read();
167.241 + if (ch == -1) {
167.242 + break;
167.243 + }
167.244 + if (ch == '$' && params.length > 0) {
167.245 + int cnt = is.read() - '0';
167.246 + if (cnt == 'U' - '0') {
167.247 + os.write(baseURL.getBytes());
167.248 + }
167.249 + if (cnt >= 0 && cnt < params.length) {
167.250 + os.write(params[cnt].getBytes());
167.251 + }
167.252 + } else {
167.253 + os.write(ch);
167.254 + }
167.255 + }
167.256 + }
167.257 +
167.258 + private Object[] launchServerAndBrwsr(HttpServer server, final String page) throws IOException, URISyntaxException, InterruptedException {
167.259 + server.start();
167.260 + NetworkListener listener = server.getListeners().iterator().next();
167.261 + int port = listener.getPort();
167.262 +
167.263 + URI uri = new URI("http://localhost:" + port + page);
167.264 + LOG.log(Level.INFO, "Showing {0}", uri);
167.265 + if (cmd == null) {
167.266 + try {
167.267 + LOG.log(Level.INFO, "Trying Desktop.browse on {0} {2} by {1}", new Object[] {
167.268 + System.getProperty("java.vm.name"),
167.269 + System.getProperty("java.vm.vendor"),
167.270 + System.getProperty("java.vm.version"),
167.271 + });
167.272 + java.awt.Desktop.getDesktop().browse(uri);
167.273 + LOG.log(Level.INFO, "Desktop.browse successfully finished");
167.274 + return null;
167.275 + } catch (UnsupportedOperationException ex) {
167.276 + LOG.log(Level.INFO, "Desktop.browse not supported: {0}", ex.getMessage());
167.277 + LOG.log(Level.FINE, null, ex);
167.278 + }
167.279 + }
167.280 + {
167.281 + String cmdName = cmd == null ? "xdg-open" : cmd;
167.282 + String[] cmdArr = {
167.283 + cmdName, uri.toString()
167.284 + };
167.285 + LOG.log(Level.INFO, "Launching {0}", Arrays.toString(cmdArr));
167.286 + final Process process = Runtime.getRuntime().exec(cmdArr);
167.287 + return new Object[] { process, null };
167.288 + }
167.289 + }
167.290 +
167.291 + private static String decodeURL(String s) {
167.292 + for (;;) {
167.293 + int pos = s.indexOf('%');
167.294 + if (pos == -1) {
167.295 + return s;
167.296 + }
167.297 + int i = Integer.parseInt(s.substring(pos + 1, pos + 2), 16);
167.298 + s = s.substring(0, pos) + (char)i + s.substring(pos + 2);
167.299 + }
167.300 + }
167.301 +
167.302 + private void stopServerAndBrwsr(HttpServer server, Object[] brwsr) throws IOException {
167.303 + if (brwsr == null) {
167.304 + return;
167.305 + }
167.306 + Process process = (Process)brwsr[0];
167.307 +
167.308 + server.stop();
167.309 + InputStream stdout = process.getInputStream();
167.310 + InputStream stderr = process.getErrorStream();
167.311 + drain("StdOut", stdout);
167.312 + drain("StdErr", stderr);
167.313 + process.destroy();
167.314 + int res;
167.315 + try {
167.316 + res = process.waitFor();
167.317 + } catch (InterruptedException ex) {
167.318 + throw new IOException(ex);
167.319 + }
167.320 + LOG.log(Level.INFO, "Exit code: {0}", res);
167.321 +
167.322 + deleteTree((File)brwsr[1]);
167.323 + }
167.324 +
167.325 + private static void drain(String name, InputStream is) throws IOException {
167.326 + int av = is.available();
167.327 + if (av > 0) {
167.328 + StringBuilder sb = new StringBuilder();
167.329 + sb.append("v== ").append(name).append(" ==v\n");
167.330 + while (av-- > 0) {
167.331 + sb.append((char)is.read());
167.332 + }
167.333 + sb.append("\n^== ").append(name).append(" ==^");
167.334 + LOG.log(Level.INFO, sb.toString());
167.335 + }
167.336 + }
167.337 +
167.338 + private void deleteTree(File file) {
167.339 + if (file == null) {
167.340 + return;
167.341 + }
167.342 + File[] arr = file.listFiles();
167.343 + if (arr != null) {
167.344 + for (File s : arr) {
167.345 + deleteTree(s);
167.346 + }
167.347 + }
167.348 + file.delete();
167.349 + }
167.350 +
167.351 + @Override
167.352 + public void close() throws IOException {
167.353 + shutdown();
167.354 + }
167.355 +
167.356 + private class Res implements Bck2Brwsr.Resources {
167.357 + @Override
167.358 + public InputStream get(String resource) throws IOException {
167.359 + for (ClassLoader l : loaders) {
167.360 + URL u = null;
167.361 + Enumeration<URL> en = l.getResources(resource);
167.362 + while (en.hasMoreElements()) {
167.363 + u = en.nextElement();
167.364 + }
167.365 + if (u != null) {
167.366 + return u.openStream();
167.367 + }
167.368 + }
167.369 + throw new IOException("Can't find " + resource);
167.370 + }
167.371 + }
167.372 +
167.373 + private static class Page extends HttpHandler {
167.374 + private final String resource;
167.375 + private final String[] args;
167.376 + private final Res res;
167.377 +
167.378 + public Page(Res res, String resource, String... args) {
167.379 + this.res = res;
167.380 + this.resource = resource;
167.381 + this.args = args.length == 0 ? new String[] { "$0" } : args;
167.382 + }
167.383 +
167.384 + @Override
167.385 + public void service(Request request, Response response) throws Exception {
167.386 + String r = resource;
167.387 + if (r == null) {
167.388 + r = request.getHttpHandlerPath();
167.389 + if (r.startsWith("/")) {
167.390 + r = r.substring(1);
167.391 + }
167.392 + }
167.393 + String[] replace = {};
167.394 + if (r.endsWith(".html")) {
167.395 + response.setContentType("text/html");
167.396 + LOG.info("Content type text/html");
167.397 + replace = args;
167.398 + }
167.399 + if (r.endsWith(".xhtml")) {
167.400 + response.setContentType("application/xhtml+xml");
167.401 + LOG.info("Content type application/xhtml+xml");
167.402 + replace = args;
167.403 + }
167.404 + OutputStream os = response.getOutputStream();
167.405 + try (InputStream is = res.get(r)) {
167.406 + copyStream(is, os, request.getRequestURL().toString(), replace);
167.407 + } catch (IOException ex) {
167.408 + response.setDetailMessage(ex.getLocalizedMessage());
167.409 + response.setError();
167.410 + response.setStatus(404);
167.411 + }
167.412 + }
167.413 + }
167.414 +
167.415 + private static class VM extends HttpHandler {
167.416 + private final Res loader;
167.417 +
167.418 + public VM(Res loader) {
167.419 + this.loader = loader;
167.420 + }
167.421 +
167.422 + @Override
167.423 + public void service(Request request, Response response) throws Exception {
167.424 + response.setCharacterEncoding("UTF-8");
167.425 + response.setContentType("text/javascript");
167.426 + Bck2Brwsr.generate(response.getWriter(), loader);
167.427 + }
167.428 + }
167.429 + private static class VMInit extends HttpHandler {
167.430 + public VMInit() {
167.431 + }
167.432 +
167.433 + @Override
167.434 + public void service(Request request, Response response) throws Exception {
167.435 + response.setCharacterEncoding("UTF-8");
167.436 + response.setContentType("text/javascript");
167.437 + response.getWriter().append(
167.438 + "function ldCls(res) {\n"
167.439 + + " var request = new XMLHttpRequest();\n"
167.440 + + " request.open('GET', '/classes/' + res, false);\n"
167.441 + + " request.send();\n"
167.442 + + " var arr = eval('(' + request.responseText + ')');\n"
167.443 + + " return arr;\n"
167.444 + + "}\n"
167.445 + + "var vm = new bck2brwsr(ldCls);\n");
167.446 + }
167.447 + }
167.448 +
167.449 + private static class Classes extends HttpHandler {
167.450 + private final Res loader;
167.451 +
167.452 + public Classes(Res loader) {
167.453 + this.loader = loader;
167.454 + }
167.455 +
167.456 + @Override
167.457 + public void service(Request request, Response response) throws Exception {
167.458 + String res = request.getHttpHandlerPath();
167.459 + if (res.startsWith("/")) {
167.460 + res = res.substring(1);
167.461 + }
167.462 + try (InputStream is = loader.get(res)) {
167.463 + response.setContentType("text/javascript");
167.464 + Writer w = response.getWriter();
167.465 + w.append("[");
167.466 + for (int i = 0;; i++) {
167.467 + int b = is.read();
167.468 + if (b == -1) {
167.469 + break;
167.470 + }
167.471 + if (i > 0) {
167.472 + w.append(", ");
167.473 + }
167.474 + if (i % 20 == 0) {
167.475 + w.write("\n");
167.476 + }
167.477 + if (b > 127) {
167.478 + b = b - 256;
167.479 + }
167.480 + w.append(Integer.toString(b));
167.481 + }
167.482 + w.append("\n]");
167.483 + } catch (IOException ex) {
167.484 + response.setError();
167.485 + response.setDetailMessage(ex.getMessage());
167.486 + }
167.487 + }
167.488 + }
167.489 +}
168.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
168.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Console.java Wed Jan 23 20:16:48 2013 +0100
168.3 @@ -0,0 +1,253 @@
168.4 +/**
168.5 + * Back 2 Browser Bytecode Translator
168.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
168.7 + *
168.8 + * This program is free software: you can redistribute it and/or modify
168.9 + * it under the terms of the GNU General Public License as published by
168.10 + * the Free Software Foundation, version 2 of the License.
168.11 + *
168.12 + * This program is distributed in the hope that it will be useful,
168.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
168.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
168.15 + * GNU General Public License for more details.
168.16 + *
168.17 + * You should have received a copy of the GNU General Public License
168.18 + * along with this program. Look for COPYING file in the top folder.
168.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
168.20 + */
168.21 +package org.apidesign.bck2brwsr.launcher;
168.22 +
168.23 +import java.io.IOException;
168.24 +import java.io.InputStream;
168.25 +import java.lang.reflect.InvocationTargetException;
168.26 +import java.lang.reflect.Method;
168.27 +import java.lang.reflect.Modifier;
168.28 +import java.net.URL;
168.29 +import java.util.Enumeration;
168.30 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
168.31 +
168.32 +/**
168.33 + *
168.34 + * @author Jaroslav Tulach <jtulach@netbeans.org>
168.35 + */
168.36 +public class Console {
168.37 + static {
168.38 + turnAssetionStatusOn();
168.39 + }
168.40 +
168.41 + @JavaScriptBody(args = {"id", "attr"}, body =
168.42 + "return window.document.getElementById(id)[attr].toString();")
168.43 + private static native Object getAttr(String id, String attr);
168.44 +
168.45 + @JavaScriptBody(args = {"id", "attr", "value"}, body =
168.46 + "window.document.getElementById(id)[attr] = value;")
168.47 + private static native void setAttr(String id, String attr, Object value);
168.48 +
168.49 + @JavaScriptBody(args = {}, body = "return; window.close();")
168.50 + private static native void closeWindow();
168.51 +
168.52 + private static void log(String newText) {
168.53 + String id = "bck2brwsr.result";
168.54 + String attr = "value";
168.55 + setAttr(id, attr, getAttr(id, attr) + "\n" + newText);
168.56 + setAttr(id, "scrollTop", getAttr(id, "scrollHeight"));
168.57 + }
168.58 +
168.59 + public static void execute() throws Exception {
168.60 + String clazz = (String) getAttr("clazz", "value");
168.61 + String method = (String) getAttr("method", "value");
168.62 + Object res = invokeMethod(clazz, method);
168.63 + setAttr("bck2brwsr.result", "value", res);
168.64 + }
168.65 +
168.66 + @JavaScriptBody(args = { "url", "callback", "arr" }, body = ""
168.67 + + "var request = new XMLHttpRequest();\n"
168.68 + + "request.open('GET', url, true);\n"
168.69 + + "request.onreadystatechange = function() {\n"
168.70 + + " if (this.readyState!==4) return;\n"
168.71 + + " arr[0] = this.responseText;\n"
168.72 + + " callback.run__V();\n"
168.73 + + "};"
168.74 + + "request.send();"
168.75 + )
168.76 + private static native void loadText(String url, Runnable callback, String[] arr) throws IOException;
168.77 +
168.78 + public static void harness(String url) throws IOException {
168.79 + log("Connecting to " + url);
168.80 + Request r = new Request(url);
168.81 + }
168.82 +
168.83 + private static class Request implements Runnable {
168.84 + private final String[] arr = { null };
168.85 + private final String url;
168.86 +
168.87 + private Request(String url) throws IOException {
168.88 + this.url = url;
168.89 + loadText(url, this, arr);
168.90 + }
168.91 +
168.92 + @Override
168.93 + public void run() {
168.94 + try {
168.95 + String data = arr[0];
168.96 + log("\nGot \"" + data + "\"");
168.97 +
168.98 + if (data == null) {
168.99 + log("Some error exiting");
168.100 + closeWindow();
168.101 + return;
168.102 + }
168.103 +
168.104 + if (data.isEmpty()) {
168.105 + log("No data, exiting");
168.106 + closeWindow();
168.107 + return;
168.108 + }
168.109 +
168.110 + Case c = Case.parseData(data);
168.111 + if (c.getHtmlFragment() != null) {
168.112 + setAttr("bck2brwsr.fragment", "innerHTML", c.getHtmlFragment());
168.113 + }
168.114 + log("Invoking " + c.getClassName() + '.' + c.getMethodName() + " as request: " + c.getRequestId());
168.115 +
168.116 + Object result = invokeMethod(c.getClassName(), c.getMethodName());
168.117 +
168.118 + setAttr("bck2brwsr.fragment", "innerHTML", "");
168.119 + log("Result: " + result);
168.120 +
168.121 + result = encodeURL("" + result);
168.122 +
168.123 + log("Sending back: " + url + "?request=" + c.getRequestId() + "&result=" + result);
168.124 + String u = url + "?request=" + c.getRequestId() + "&result=" + result;
168.125 +
168.126 + loadText(u, this, arr);
168.127 +
168.128 + } catch (Exception ex) {
168.129 + log(ex.getMessage());
168.130 + }
168.131 + }
168.132 + }
168.133 +
168.134 + private static String encodeURL(String r) {
168.135 + StringBuilder sb = new StringBuilder();
168.136 + for (int i = 0; i < r.length(); i++) {
168.137 + int ch = r.charAt(i);
168.138 + if (ch < 32 || ch == '%' || ch == '+') {
168.139 + sb.append("%").append(("0" + Integer.toHexString(ch)).substring(0, 2));
168.140 + } else {
168.141 + if (ch == 32) {
168.142 + sb.append("+");
168.143 + } else {
168.144 + sb.append((char)ch);
168.145 + }
168.146 + }
168.147 + }
168.148 + return sb.toString();
168.149 + }
168.150 +
168.151 + static String invoke(String clazz, String method) throws ClassNotFoundException, InvocationTargetException, IllegalAccessException, InstantiationException {
168.152 + final Object r = invokeMethod(clazz, method);
168.153 + return r == null ? "null" : r.toString().toString();
168.154 + }
168.155 +
168.156 + /** Helper method that inspects the classpath and loads given resource
168.157 + * (usually a class file). Used while running tests in Rhino.
168.158 + *
168.159 + * @param name resource name to find
168.160 + * @return the array of bytes in the given resource
168.161 + * @throws IOException I/O in case something goes wrong
168.162 + */
168.163 + public static byte[] read(String name) throws IOException {
168.164 + URL u = null;
168.165 + Enumeration<URL> en = Console.class.getClassLoader().getResources(name);
168.166 + while (en.hasMoreElements()) {
168.167 + u = en.nextElement();
168.168 + }
168.169 + if (u == null) {
168.170 + throw new IOException("Can't find " + name);
168.171 + }
168.172 + try (InputStream is = u.openStream()) {
168.173 + byte[] arr;
168.174 + arr = new byte[is.available()];
168.175 + int offset = 0;
168.176 + while (offset < arr.length) {
168.177 + int len = is.read(arr, offset, arr.length - offset);
168.178 + if (len == -1) {
168.179 + throw new IOException("Can't read " + name);
168.180 + }
168.181 + offset += len;
168.182 + }
168.183 + return arr;
168.184 + }
168.185 + }
168.186 +
168.187 + private static Object invokeMethod(String clazz, String method)
168.188 + throws ClassNotFoundException, InvocationTargetException,
168.189 + SecurityException, IllegalAccessException, IllegalArgumentException,
168.190 + InstantiationException {
168.191 + Method found = null;
168.192 + Class<?> c = Class.forName(clazz);
168.193 + for (Method m : c.getMethods()) {
168.194 + if (m.getName().equals(method)) {
168.195 + found = m;
168.196 + }
168.197 + }
168.198 + Object res;
168.199 + if (found != null) {
168.200 + try {
168.201 + if ((found.getModifiers() & Modifier.STATIC) != 0) {
168.202 + res = found.invoke(null);
168.203 + } else {
168.204 + res = found.invoke(c.newInstance());
168.205 + }
168.206 + } catch (Throwable ex) {
168.207 + res = ex.getClass().getName() + ":" + ex.getMessage();
168.208 + }
168.209 + } else {
168.210 + res = "Can't find method " + method + " in " + clazz;
168.211 + }
168.212 + return res;
168.213 + }
168.214 +
168.215 + @JavaScriptBody(args = {}, body = "vm.desiredAssertionStatus = true;")
168.216 + private static void turnAssetionStatusOn() {
168.217 + }
168.218 +
168.219 + private static final class Case {
168.220 + private final Object data;
168.221 +
168.222 + private Case(Object data) {
168.223 + this.data = data;
168.224 + }
168.225 +
168.226 + public static Case parseData(String s) {
168.227 + return new Case(toJSON(s));
168.228 + }
168.229 +
168.230 + public String getMethodName() {
168.231 + return value("methodName", data);
168.232 + }
168.233 +
168.234 + public String getClassName() {
168.235 + return value("className", data);
168.236 + }
168.237 +
168.238 + public String getRequestId() {
168.239 + return value("request", data);
168.240 + }
168.241 +
168.242 + public String getHtmlFragment() {
168.243 + return value("html", data);
168.244 + }
168.245 +
168.246 + @JavaScriptBody(args = "s", body = "return eval('(' + s + ')');")
168.247 + private static native Object toJSON(String s);
168.248 +
168.249 + @JavaScriptBody(args = {"p", "d"}, body =
168.250 + "var v = d[p];\n"
168.251 + + "if (typeof v === 'undefined') return null;\n"
168.252 + + "return v.toString();"
168.253 + )
168.254 + private static native String value(String p, Object d);
168.255 + }
168.256 +}
169.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
169.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/JSLauncher.java Wed Jan 23 20:16:48 2013 +0100
169.3 @@ -0,0 +1,126 @@
169.4 +/**
169.5 + * Back 2 Browser Bytecode Translator
169.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
169.7 + *
169.8 + * This program is free software: you can redistribute it and/or modify
169.9 + * it under the terms of the GNU General Public License as published by
169.10 + * the Free Software Foundation, version 2 of the License.
169.11 + *
169.12 + * This program is distributed in the hope that it will be useful,
169.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
169.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
169.15 + * GNU General Public License for more details.
169.16 + *
169.17 + * You should have received a copy of the GNU General Public License
169.18 + * along with this program. Look for COPYING file in the top folder.
169.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
169.20 + */
169.21 +package org.apidesign.bck2brwsr.launcher;
169.22 +
169.23 +import java.io.IOException;
169.24 +import java.io.InputStream;
169.25 +import java.net.URL;
169.26 +import java.util.Enumeration;
169.27 +import java.util.LinkedHashSet;
169.28 +import java.util.Set;
169.29 +import java.util.logging.Logger;
169.30 +import javax.script.Invocable;
169.31 +import javax.script.ScriptEngine;
169.32 +import javax.script.ScriptEngineManager;
169.33 +import javax.script.ScriptException;
169.34 +import org.apidesign.vm4brwsr.Bck2Brwsr;
169.35 +
169.36 +/**
169.37 + * Tests execution in Java's internal scripting engine.
169.38 + */
169.39 +final class JSLauncher extends Launcher {
169.40 + private static final Logger LOG = Logger.getLogger(JSLauncher.class.getName());
169.41 + private Set<ClassLoader> loaders = new LinkedHashSet<>();
169.42 + private final Res resources = new Res();
169.43 + private Invocable code;
169.44 + private StringBuilder codeSeq;
169.45 + private Object console;
169.46 +
169.47 +
169.48 + @Override MethodInvocation addMethod(Class<?> clazz, String method, String html) {
169.49 + loaders.add(clazz.getClassLoader());
169.50 + MethodInvocation mi = new MethodInvocation(clazz.getName(), method, html);
169.51 + try {
169.52 + mi.result(code.invokeMethod(
169.53 + console,
169.54 + "invoke__Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2",
169.55 + mi.className, mi.methodName).toString(), null);
169.56 + } catch (ScriptException | NoSuchMethodException ex) {
169.57 + mi.result(null, ex);
169.58 + }
169.59 + return mi;
169.60 + }
169.61 +
169.62 + public void addClassLoader(ClassLoader url) {
169.63 + this.loaders.add(url);
169.64 + }
169.65 +
169.66 + @Override
169.67 + public void initialize() throws IOException {
169.68 + try {
169.69 + initRhino();
169.70 + } catch (Exception ex) {
169.71 + if (ex instanceof IOException) {
169.72 + throw (IOException)ex;
169.73 + }
169.74 + if (ex instanceof RuntimeException) {
169.75 + throw (RuntimeException)ex;
169.76 + }
169.77 + throw new IOException(ex);
169.78 + }
169.79 + }
169.80 +
169.81 + private void initRhino() throws IOException, ScriptException, NoSuchMethodException {
169.82 + StringBuilder sb = new StringBuilder();
169.83 + Bck2Brwsr.generate(sb, new Res());
169.84 +
169.85 + ScriptEngineManager sem = new ScriptEngineManager();
169.86 + ScriptEngine mach = sem.getEngineByExtension("js");
169.87 +
169.88 + sb.append(
169.89 + "\nvar vm = new bck2brwsr(org.apidesign.bck2brwsr.launcher.Console.read);"
169.90 + + "\nfunction initVM() { return vm; };"
169.91 + + "\n");
169.92 +
169.93 + Object res = mach.eval(sb.toString());
169.94 + if (!(mach instanceof Invocable)) {
169.95 + throw new IOException("It is invocable object: " + res);
169.96 + }
169.97 + code = (Invocable) mach;
169.98 + codeSeq = sb;
169.99 +
169.100 + Object vm = code.invokeFunction("initVM");
169.101 + console = code.invokeMethod(vm, "loadClass", Console.class.getName());
169.102 + }
169.103 +
169.104 + @Override
169.105 + public void shutdown() throws IOException {
169.106 + }
169.107 +
169.108 + @Override
169.109 + public String toString() {
169.110 + return codeSeq.toString();
169.111 + }
169.112 +
169.113 + private class Res implements Bck2Brwsr.Resources {
169.114 + @Override
169.115 + public InputStream get(String resource) throws IOException {
169.116 + for (ClassLoader l : loaders) {
169.117 + URL u = null;
169.118 + Enumeration<URL> en = l.getResources(resource);
169.119 + while (en.hasMoreElements()) {
169.120 + u = en.nextElement();
169.121 + }
169.122 + if (u != null) {
169.123 + return u.openStream();
169.124 + }
169.125 + }
169.126 + throw new IOException("Can't find " + resource);
169.127 + }
169.128 + }
169.129 +}
170.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
170.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Launcher.java Wed Jan 23 20:16:48 2013 +0100
170.3 @@ -0,0 +1,63 @@
170.4 +/**
170.5 + * Back 2 Browser Bytecode Translator
170.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
170.7 + *
170.8 + * This program is free software: you can redistribute it and/or modify
170.9 + * it under the terms of the GNU General Public License as published by
170.10 + * the Free Software Foundation, version 2 of the License.
170.11 + *
170.12 + * This program is distributed in the hope that it will be useful,
170.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
170.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
170.15 + * GNU General Public License for more details.
170.16 + *
170.17 + * You should have received a copy of the GNU General Public License
170.18 + * along with this program. Look for COPYING file in the top folder.
170.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
170.20 + */
170.21 +package org.apidesign.bck2brwsr.launcher;
170.22 +
170.23 +import java.io.Closeable;
170.24 +import java.io.IOException;
170.25 +import java.net.URLClassLoader;
170.26 +import org.apidesign.vm4brwsr.Bck2Brwsr;
170.27 +
170.28 +/** An abstraction for executing tests in a Bck2Brwsr virtual machine.
170.29 + * Either in JavaScript engine, or in external browser.
170.30 + *
170.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
170.32 + */
170.33 +public abstract class Launcher {
170.34 +
170.35 + Launcher() {
170.36 + }
170.37 +
170.38 + abstract MethodInvocation addMethod(Class<?> clazz, String method, String html) throws IOException;
170.39 +
170.40 + public abstract void initialize() throws IOException;
170.41 + public abstract void shutdown() throws IOException;
170.42 + public MethodInvocation invokeMethod(Class<?> clazz, String method, String html) throws IOException {
170.43 + return addMethod(clazz, method, html);
170.44 + }
170.45 +
170.46 +
170.47 +
170.48 + public static Launcher createJavaScript() {
170.49 + final JSLauncher l = new JSLauncher();
170.50 + l.addClassLoader(Bck2Brwsr.class.getClassLoader());
170.51 + return l;
170.52 + }
170.53 +
170.54 + public static Launcher createBrowser(String cmd) {
170.55 + final Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(cmd);
170.56 + l.addClassLoader(Bck2Brwsr.class.getClassLoader());
170.57 + l.setTimeout(180000);
170.58 + return l;
170.59 + }
170.60 + public static Closeable showURL(URLClassLoader classes, String startpage) throws IOException {
170.61 + Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(null);
170.62 + l.addClassLoader(classes);
170.63 + l.showURL(startpage);
170.64 + return l;
170.65 + }
170.66 +}
171.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
171.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/MethodInvocation.java Wed Jan 23 20:16:48 2013 +0100
171.3 @@ -0,0 +1,59 @@
171.4 +/**
171.5 + * Back 2 Browser Bytecode Translator
171.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
171.7 + *
171.8 + * This program is free software: you can redistribute it and/or modify
171.9 + * it under the terms of the GNU General Public License as published by
171.10 + * the Free Software Foundation, version 2 of the License.
171.11 + *
171.12 + * This program is distributed in the hope that it will be useful,
171.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
171.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
171.15 + * GNU General Public License for more details.
171.16 + *
171.17 + * You should have received a copy of the GNU General Public License
171.18 + * along with this program. Look for COPYING file in the top folder.
171.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
171.20 + */
171.21 +package org.apidesign.bck2brwsr.launcher;
171.22 +
171.23 +import java.util.concurrent.CountDownLatch;
171.24 +import java.util.concurrent.TimeUnit;
171.25 +
171.26 +/**
171.27 + *
171.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
171.29 + */
171.30 +public final class MethodInvocation {
171.31 + final CountDownLatch wait = new CountDownLatch(1);
171.32 + final String className;
171.33 + final String methodName;
171.34 + final String html;
171.35 + private String result;
171.36 + private Throwable exception;
171.37 +
171.38 + MethodInvocation(String className, String methodName, String html) {
171.39 + this.className = className;
171.40 + this.methodName = methodName;
171.41 + this.html = html;
171.42 + }
171.43 +
171.44 + void await(long timeOut) throws InterruptedException {
171.45 + wait.await(timeOut, TimeUnit.MILLISECONDS);
171.46 + }
171.47 +
171.48 + void result(String r, Throwable e) {
171.49 + this.result = r;
171.50 + this.exception = e;
171.51 + wait.countDown();
171.52 + }
171.53 +
171.54 + @Override
171.55 + public String toString() {
171.56 + if (exception != null) {
171.57 + return exception.toString();
171.58 + }
171.59 + return result;
171.60 + }
171.61 +
171.62 +}
172.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
172.2 +++ b/launcher/src/main/resources/org/apidesign/bck2brwsr/launcher/harness.xhtml Wed Jan 23 20:16:48 2013 +0100
172.3 @@ -0,0 +1,41 @@
172.4 +<?xml version="1.0" encoding="UTF-8"?>
172.5 +<!--
172.6 +
172.7 + Back 2 Browser Bytecode Translator
172.8 + Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
172.9 +
172.10 + This program is free software: you can redistribute it and/or modify
172.11 + it under the terms of the GNU General Public License as published by
172.12 + the Free Software Foundation, version 2 of the License.
172.13 +
172.14 + This program is distributed in the hope that it will be useful,
172.15 + but WITHOUT ANY WARRANTY; without even the implied warranty of
172.16 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
172.17 + GNU General Public License for more details.
172.18 +
172.19 + You should have received a copy of the GNU General Public License
172.20 + along with this program. Look for COPYING file in the top folder.
172.21 + If not, see http://opensource.org/licenses/GPL-2.0.
172.22 +
172.23 +-->
172.24 +<!DOCTYPE html>
172.25 +<html xmlns="http://www.w3.org/1999/xhtml">
172.26 + <head>
172.27 + <title>Bck2Brwsr Harness</title>
172.28 + </head>
172.29 + <body>
172.30 + <script src="/bck2brwsr.js"></script>
172.31 + <script src="/vm.js"></script>
172.32 +
172.33 + <h1>Bck2Brwsr Execution Harness</h1>
172.34 +
172.35 + <textarea id="bck2brwsr.result" rows="25" style="width: 100%;" disabled="">
172.36 + </textarea>
172.37 +
172.38 + <div id="bck2brwsr.fragment"/>
172.39 +
172.40 + <script type="text/javascript">
172.41 + vm.loadClass('org.apidesign.bck2brwsr.launcher.Console').harness__VLjava_lang_String_2('$U/../data');
172.42 + </script>
172.43 + </body>
172.44 +</html>
173.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
173.2 +++ b/mojo/pom.xml Wed Jan 23 20:16:48 2013 +0100
173.3 @@ -0,0 +1,86 @@
173.4 +<?xml version="1.0"?>
173.5 +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
173.6 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
173.7 + <modelVersion>4.0.0</modelVersion>
173.8 + <parent>
173.9 + <groupId>org.apidesign</groupId>
173.10 + <artifactId>bck2brwsr</artifactId>
173.11 + <version>0.3-SNAPSHOT</version>
173.12 + </parent>
173.13 + <groupId>org.apidesign.bck2brwsr</groupId>
173.14 + <artifactId>mojo</artifactId>
173.15 + <version>0.3-SNAPSHOT</version>
173.16 + <packaging>maven-plugin</packaging>
173.17 + <name>Bck2Brwsr Maven Project</name>
173.18 + <url>http://maven.apache.org</url>
173.19 + <build>
173.20 + <plugins>
173.21 + <plugin>
173.22 + <groupId>org.apache.maven.plugins</groupId>
173.23 + <artifactId>maven-plugin-plugin</artifactId>
173.24 + <version>3.1</version>
173.25 + <configuration>
173.26 + <extractors>
173.27 + <extractor>java-annotations</extractor>
173.28 + </extractors>
173.29 + <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
173.30 + </configuration>
173.31 + <executions>
173.32 + <execution>
173.33 + <id>mojo-descriptor</id>
173.34 + <phase>process-classes</phase>
173.35 + <goals>
173.36 + <goal>descriptor</goal>
173.37 + </goals>
173.38 + </execution>
173.39 + </executions>
173.40 + </plugin>
173.41 + <plugin>
173.42 + <groupId>org.apache.maven.plugins</groupId>
173.43 + <artifactId>maven-compiler-plugin</artifactId>
173.44 + <version>2.3.2</version>
173.45 + <configuration>
173.46 + <source>1.6</source>
173.47 + <target>1.6</target>
173.48 + </configuration>
173.49 + </plugin>
173.50 + </plugins>
173.51 + </build>
173.52 +
173.53 +<dependencies>
173.54 + <dependency>
173.55 + <groupId>org.apache.maven</groupId>
173.56 + <artifactId>maven-plugin-api</artifactId>
173.57 + <version>3.0.4</version>
173.58 + <type>jar</type>
173.59 + </dependency>
173.60 + <dependency>
173.61 + <groupId>org.apache.maven.plugin-tools</groupId>
173.62 + <artifactId>maven-plugin-annotations</artifactId>
173.63 + <version>3.0</version>
173.64 + <type>jar</type>
173.65 + </dependency>
173.66 + <dependency>
173.67 + <groupId>${project.groupId}</groupId>
173.68 + <artifactId>vm4brwsr</artifactId>
173.69 + <version>0.3-SNAPSHOT</version>
173.70 + <exclusions>
173.71 + <exclusion>
173.72 + <artifactId>emul</artifactId>
173.73 + <groupId>org.apidesign.bck2brwsr</groupId>
173.74 + </exclusion>
173.75 + </exclusions>
173.76 + </dependency>
173.77 + <dependency>
173.78 + <groupId>org.apache.maven</groupId>
173.79 + <artifactId>maven-core</artifactId>
173.80 + <version>3.0.2</version>
173.81 + <type>jar</type>
173.82 + </dependency>
173.83 + <dependency>
173.84 + <groupId>${project.groupId}</groupId>
173.85 + <artifactId>launcher</artifactId>
173.86 + <version>${project.version}</version>
173.87 + </dependency>
173.88 +</dependencies>
173.89 +</project>
174.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
174.2 +++ b/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/Bck2BrswrMojo.java Wed Jan 23 20:16:48 2013 +0100
174.3 @@ -0,0 +1,122 @@
174.4 +/**
174.5 + * Back 2 Browser Bytecode Translator
174.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
174.7 + *
174.8 + * This program is free software: you can redistribute it and/or modify
174.9 + * it under the terms of the GNU General Public License as published by
174.10 + * the Free Software Foundation, version 2 of the License.
174.11 + *
174.12 + * This program is distributed in the hope that it will be useful,
174.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
174.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
174.15 + * GNU General Public License for more details.
174.16 + *
174.17 + * You should have received a copy of the GNU General Public License
174.18 + * along with this program. Look for COPYING file in the top folder.
174.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
174.20 + */
174.21 +package org.apidesign.bck2brwsr.mojo;
174.22 +
174.23 +import org.apache.maven.plugin.AbstractMojo;
174.24 +
174.25 +import java.io.File;
174.26 +import java.io.FileWriter;
174.27 +import java.io.IOException;
174.28 +import java.net.MalformedURLException;
174.29 +import java.net.URL;
174.30 +import java.net.URLClassLoader;
174.31 +import java.util.ArrayList;
174.32 +import java.util.Collection;
174.33 +import java.util.List;
174.34 +import org.apache.maven.artifact.Artifact;
174.35 +import org.apache.maven.plugin.MojoExecutionException;
174.36 +import org.apache.maven.plugins.annotations.LifecyclePhase;
174.37 +import org.apache.maven.plugins.annotations.Mojo;
174.38 +import org.apache.maven.plugins.annotations.Parameter;
174.39 +import org.apache.maven.project.MavenProject;
174.40 +import org.apidesign.vm4brwsr.Bck2Brwsr;
174.41 +
174.42 +/** Compiles classes into JavaScript. */
174.43 +@Mojo(name="j2js", defaultPhase=LifecyclePhase.PROCESS_CLASSES)
174.44 +public class Bck2BrswrMojo extends AbstractMojo {
174.45 + public Bck2BrswrMojo() {
174.46 + }
174.47 + /** Root of the class files */
174.48 + @Parameter(defaultValue="${project.build.directory}/classes")
174.49 + private File classes;
174.50 + /** File to generate. Defaults bootjava.js in the first non-empty
174.51 + package under the classes directory */
174.52 + @Parameter
174.53 + private File javascript;
174.54 +
174.55 + @Parameter(defaultValue="${project}")
174.56 + private MavenProject prj;
174.57 +
174.58 +
174.59 +
174.60 + @Override
174.61 + public void execute() throws MojoExecutionException {
174.62 + if (!classes.isDirectory()) {
174.63 + throw new MojoExecutionException("Can't find " + classes);
174.64 + }
174.65 +
174.66 + if (javascript == null) {
174.67 + javascript = new File(findNonEmptyFolder(classes), "bootjava.js");
174.68 + }
174.69 +
174.70 + List<String> arr = new ArrayList<String>();
174.71 + long newest = collectAllClasses("", classes, arr);
174.72 +
174.73 + if (javascript.lastModified() > newest) {
174.74 + return;
174.75 + }
174.76 +
174.77 + try {
174.78 + URLClassLoader url = buildClassLoader(classes, prj.getDependencyArtifacts());
174.79 + FileWriter w = new FileWriter(javascript);
174.80 + Bck2Brwsr.generate(w, url, arr.toArray(new String[0]));
174.81 + w.close();
174.82 + } catch (IOException ex) {
174.83 + throw new MojoExecutionException("Can't compile", ex);
174.84 + }
174.85 + }
174.86 +
174.87 + private static File findNonEmptyFolder(File dir) throws MojoExecutionException {
174.88 + if (!dir.isDirectory()) {
174.89 + throw new MojoExecutionException("Not a directory " + dir);
174.90 + }
174.91 + File[] arr = dir.listFiles();
174.92 + if (arr.length == 1 && arr[0].isDirectory()) {
174.93 + return findNonEmptyFolder(arr[0]);
174.94 + }
174.95 + return dir;
174.96 + }
174.97 +
174.98 + private static long collectAllClasses(String prefix, File toCheck, List<String> arr) {
174.99 + File[] files = toCheck.listFiles();
174.100 + if (files != null) {
174.101 + long newest = 0L;
174.102 + for (File f : files) {
174.103 + long lastModified = collectAllClasses(prefix + f.getName() + "/", f, arr);
174.104 + if (newest < lastModified) {
174.105 + newest = lastModified;
174.106 + }
174.107 + }
174.108 + return newest;
174.109 + } else if (toCheck.getName().endsWith(".class")) {
174.110 + arr.add(prefix.substring(0, prefix.length() - 7));
174.111 + return toCheck.lastModified();
174.112 + } else {
174.113 + return 0L;
174.114 + }
174.115 + }
174.116 +
174.117 + private static URLClassLoader buildClassLoader(File root, Collection<Artifact> deps) throws MalformedURLException {
174.118 + List<URL> arr = new ArrayList<URL>();
174.119 + arr.add(root.toURI().toURL());
174.120 + for (Artifact a : deps) {
174.121 + arr.add(a.getFile().toURI().toURL());
174.122 + }
174.123 + return new URLClassLoader(arr.toArray(new URL[0]), Bck2BrswrMojo.class.getClassLoader());
174.124 + }
174.125 +}
175.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
175.2 +++ b/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/BrswrMojo.java Wed Jan 23 20:16:48 2013 +0100
175.3 @@ -0,0 +1,92 @@
175.4 +/**
175.5 + * Back 2 Browser Bytecode Translator
175.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
175.7 + *
175.8 + * This program is free software: you can redistribute it and/or modify
175.9 + * it under the terms of the GNU General Public License as published by
175.10 + * the Free Software Foundation, version 2 of the License.
175.11 + *
175.12 + * This program is distributed in the hope that it will be useful,
175.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
175.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
175.15 + * GNU General Public License for more details.
175.16 + *
175.17 + * You should have received a copy of the GNU General Public License
175.18 + * along with this program. Look for COPYING file in the top folder.
175.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
175.20 + */
175.21 +package org.apidesign.bck2brwsr.mojo;
175.22 +
175.23 +import java.io.Closeable;
175.24 +import org.apache.maven.plugin.AbstractMojo;
175.25 +
175.26 +import java.io.File;
175.27 +import java.io.IOException;
175.28 +import java.net.MalformedURLException;
175.29 +import java.net.URL;
175.30 +import java.net.URLClassLoader;
175.31 +import java.util.ArrayList;
175.32 +import java.util.Collection;
175.33 +import java.util.List;
175.34 +import org.apache.maven.artifact.Artifact;
175.35 +import org.apache.maven.plugin.MojoExecutionException;
175.36 +import org.apache.maven.plugins.annotations.LifecyclePhase;
175.37 +import org.apache.maven.plugins.annotations.Mojo;
175.38 +import org.apache.maven.plugins.annotations.Parameter;
175.39 +import org.apache.maven.project.MavenProject;
175.40 +import org.apidesign.bck2brwsr.launcher.Launcher;
175.41 +
175.42 +/** Executes given HTML page in a browser. */
175.43 +@Mojo(name="brwsr", defaultPhase=LifecyclePhase.DEPLOY)
175.44 +public class BrswrMojo extends AbstractMojo {
175.45 + public BrswrMojo() {
175.46 + }
175.47 + /** Resource to show as initial page */
175.48 + @Parameter
175.49 + private String startpage;
175.50 +
175.51 + @Parameter(defaultValue="${project}")
175.52 + private MavenProject prj;
175.53 +
175.54 + /** Root of the class files */
175.55 + @Parameter(defaultValue="${project.build.directory}/classes")
175.56 + private File classes;
175.57 +
175.58 + @Override
175.59 + public void execute() throws MojoExecutionException {
175.60 + if (startpage == null) {
175.61 + throw new MojoExecutionException("You have to provide a start page");
175.62 + }
175.63 +
175.64 + try {
175.65 + URLClassLoader url = buildClassLoader(classes, prj.getDependencyArtifacts());
175.66 +
175.67 + Closeable httpServer;
175.68 + try {
175.69 + httpServer = Launcher.showURL(url, startpage());
175.70 + } catch (Exception ex) {
175.71 + throw new MojoExecutionException("Can't open " + startpage(), ex);
175.72 + }
175.73 + System.in.read();
175.74 + httpServer.close();
175.75 + } catch (IOException ex) {
175.76 + throw new MojoExecutionException("Can't show the browser", ex);
175.77 + }
175.78 + }
175.79 +
175.80 + private String startpage() {
175.81 + return startpage;
175.82 + }
175.83 +
175.84 + private static URLClassLoader buildClassLoader(File root, Collection<Artifact> deps) throws MalformedURLException {
175.85 + List<URL> arr = new ArrayList<URL>();
175.86 + arr.add(root.toURI().toURL());
175.87 + for (Artifact a : deps) {
175.88 + final File f = a.getFile();
175.89 + if (f != null) {
175.90 + arr.add(f.toURI().toURL());
175.91 + }
175.92 + }
175.93 + return new URLClassLoader(arr.toArray(new URL[0]), BrswrMojo.class.getClassLoader());
175.94 + }
175.95 +}
176.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
176.2 +++ b/mojo/src/main/resources/META-INF/maven/archetype-metadata.xml Wed Jan 23 20:16:48 2013 +0100
176.3 @@ -0,0 +1,48 @@
176.4 +<?xml version="1.0" encoding="UTF-8"?>
176.5 +<!--
176.6 +
176.7 + Back 2 Browser Bytecode Translator
176.8 + Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
176.9 +
176.10 + This program is free software: you can redistribute it and/or modify
176.11 + it under the terms of the GNU General Public License as published by
176.12 + the Free Software Foundation, version 2 of the License.
176.13 +
176.14 + This program is distributed in the hope that it will be useful,
176.15 + but WITHOUT ANY WARRANTY; without even the implied warranty of
176.16 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
176.17 + GNU General Public License for more details.
176.18 +
176.19 + You should have received a copy of the GNU General Public License
176.20 + along with this program. Look for COPYING file in the top folder.
176.21 + If not, see http://opensource.org/licenses/GPL-2.0.
176.22 +
176.23 +-->
176.24 +<archetype-descriptor name="bck2brwsr">
176.25 + <fileSets>
176.26 + <fileSet filtered="true" packaged="true">
176.27 + <directory>src/main/java</directory>
176.28 + <includes>
176.29 + <include>**/App.java</include>
176.30 + </includes>
176.31 + </fileSet>
176.32 + <fileSet filtered="true" packaged="true">
176.33 + <directory>src/main/resources</directory>
176.34 + <includes>
176.35 + <include>**/*.xhtml</include>
176.36 + </includes>
176.37 + </fileSet>
176.38 + <fileSet filtered="true" packaged="true">
176.39 + <directory>src/test/java</directory>
176.40 + <includes>
176.41 + <include>**/*Test.java</include>
176.42 + </includes>
176.43 + </fileSet>
176.44 + <fileSet filtered="false" packaged="false">
176.45 + <directory></directory>
176.46 + <includes>
176.47 + <include>nbactions.xml</include>
176.48 + </includes>
176.49 + </fileSet>
176.50 + </fileSets>
176.51 +</archetype-descriptor>
176.52 \ No newline at end of file
177.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
177.2 +++ b/mojo/src/main/resources/archetype-resources/nbactions.xml Wed Jan 23 20:16:48 2013 +0100
177.3 @@ -0,0 +1,10 @@
177.4 +<?xml version="1.0" encoding="UTF-8"?>
177.5 +<actions>
177.6 + <action>
177.7 + <actionName>run</actionName>
177.8 + <goals>
177.9 + <goal>process-classes</goal>
177.10 + <goal>org.apidesign.bck2brwsr:mojo:0.3-SNAPSHOT:brwsr</goal>
177.11 + </goals>
177.12 + </action>
177.13 +</actions>
178.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
178.2 +++ b/mojo/src/main/resources/archetype-resources/pom.xml Wed Jan 23 20:16:48 2013 +0100
178.3 @@ -0,0 +1,69 @@
178.4 +<?xml version="1.0"?>
178.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
178.6 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
178.7 + <modelVersion>4.0.0</modelVersion>
178.8 +
178.9 + <groupId>${groupId}</groupId>
178.10 + <artifactId>${artifactId}</artifactId>
178.11 + <version>${version}</version>
178.12 + <packaging>jar</packaging>
178.13 +
178.14 + <name>${artifactId}</name>
178.15 +
178.16 + <properties>
178.17 + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
178.18 + </properties>
178.19 + <build>
178.20 + <plugins>
178.21 + <plugin>
178.22 + <groupId>org.apidesign.bck2brwsr</groupId>
178.23 + <artifactId>mojo</artifactId>
178.24 + <version>0.3-SNAPSHOT</version>
178.25 + <executions>
178.26 + <execution>
178.27 + <goals>
178.28 + <goal>brwsr</goal>
178.29 + </goals>
178.30 + </execution>
178.31 + </executions>
178.32 + <configuration>
178.33 + <startpage>${package.replace('.','/')}/index.xhtml</startpage>
178.34 + </configuration>
178.35 + </plugin>
178.36 + <plugin>
178.37 + <groupId>org.apache.maven.plugins</groupId>
178.38 + <artifactId>maven-compiler-plugin</artifactId>
178.39 + <version>2.3.2</version>
178.40 + <configuration>
178.41 + <source>1.7</source>
178.42 + <target>1.7</target>
178.43 + </configuration>
178.44 + </plugin>
178.45 + </plugins>
178.46 + </build>
178.47 +
178.48 + <dependencies>
178.49 + <dependency>
178.50 + <groupId>org.apidesign.bck2brwsr</groupId>
178.51 + <artifactId>emul</artifactId>
178.52 + <version>0.3-SNAPSHOT</version>
178.53 + </dependency>
178.54 + <dependency>
178.55 + <groupId>org.apidesign.bck2brwsr</groupId>
178.56 + <artifactId>javaquery.api</artifactId>
178.57 + <version>0.3-SNAPSHOT</version>
178.58 + </dependency>
178.59 + <dependency>
178.60 + <groupId>org.testng</groupId>
178.61 + <artifactId>testng</artifactId>
178.62 + <version>6.5.2</version>
178.63 + <scope>test</scope>
178.64 + </dependency>
178.65 + <dependency>
178.66 + <groupId>${project.groupId}</groupId>
178.67 + <artifactId>vmtest</artifactId>
178.68 + <version>0.3-SNAPSHOT</version>
178.69 + <scope>test</scope>
178.70 + </dependency>
178.71 + </dependencies>
178.72 +</project>
179.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
179.2 +++ b/mojo/src/main/resources/archetype-resources/src/main/java/App.java Wed Jan 23 20:16:48 2013 +0100
179.3 @@ -0,0 +1,34 @@
179.4 +package ${package};
179.5 +
179.6 +import org.apidesign.bck2brwsr.htmlpage.api.*;
179.7 +import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;
179.8 +import org.apidesign.bck2brwsr.htmlpage.api.Page;
179.9 +import org.apidesign.bck2brwsr.htmlpage.api.Property;
179.10 +import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
179.11 +
179.12 +/** Edit the index.xhtml file. Use 'id' to name certain HTML elements.
179.13 + * Use this class to define behavior of the elements.
179.14 + */
179.15 +@Page(xhtml="index.xhtml", className="Index", properties={
179.16 + @Property(name="name", type=String.class)
179.17 +})
179.18 +public class App {
179.19 + static {
179.20 + Index model = new Index();
179.21 + model.setName("World");
179.22 + model.applyBindings();
179.23 + }
179.24 +
179.25 + @On(event = CLICK, id="hello")
179.26 + static void hello(Index m) {
179.27 + GraphicsContext g = m.CANVAS.getContext();
179.28 + g.clearRect(0, 0, 1000, 1000);
179.29 + g.setFont("italic 40px Calibri");
179.30 + g.fillText(m.getHelloMessage(), 10, 40);
179.31 + }
179.32 +
179.33 + @ComputedProperty
179.34 + static String helloMessage(String name) {
179.35 + return "Hello " + name + "!";
179.36 + }
179.37 +}
180.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
180.2 +++ b/mojo/src/main/resources/archetype-resources/src/main/resources/index.xhtml Wed Jan 23 20:16:48 2013 +0100
180.3 @@ -0,0 +1,22 @@
180.4 +<?xml version="1.0" encoding="UTF-8"?>
180.5 +<!DOCTYPE html>
180.6 +<html xmlns="http://www.w3.org/1999/xhtml">
180.7 + <head>
180.8 + <title>Bck2Brwsr's Hello World</title>
180.9 + </head>
180.10 + <body>
180.11 + <h1 data-bind="text: helloMessage">Loading Bck2Brwsr's Hello World...</h1>
180.12 + Your name: <input id='input' data-bind="value: name, valueUpdate: 'afterkeydown'"></input>
180.13 + <button id="hello">Say Hello!</button>
180.14 + <p>
180.15 + <canvas id="canvas" width="300" height="50">
180.16 + </canvas>
180.17 + </p>
180.18 +
180.19 + <script src="/bck2brwsr.js"></script>
180.20 + <script src="/vm.js"></script>
180.21 + <script type="text/javascript">
180.22 + vm.loadClass('${package}.App');
180.23 + </script>
180.24 + </body>
180.25 +</html>
181.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
181.2 +++ b/mojo/src/main/resources/archetype-resources/src/test/java/AppTest.java Wed Jan 23 20:16:48 2013 +0100
181.3 @@ -0,0 +1,26 @@
181.4 +package ${package};
181.5 +
181.6 +import static org.testng.Assert.*;
181.7 +import org.testng.annotations.BeforeMethod;
181.8 +import org.testng.annotations.Test;
181.9 +
181.10 +/** Demonstrating POJO testing of HTML page model. Runs in good old HotSpot
181.11 + * as it does not reference any HTML elements or browser functionality. Just
181.12 + * operates on the page model.
181.13 + *
181.14 + * @author Jaroslav Tulach <jtulach@netbeans.org>
181.15 + */
181.16 +public class AppTest {
181.17 + private Index model;
181.18 +
181.19 +
181.20 + @BeforeMethod
181.21 + public void initModel() {
181.22 + model = new Index().applyBindings();
181.23 + }
181.24 +
181.25 + @Test public void testHelloMessage() {
181.26 + model.setName("Joe");
181.27 + assertEquals(model.getHelloMessage(), "Hello Joe!", "Cleared after pressing +");
181.28 + }
181.29 +}
182.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
182.2 +++ b/mojo/src/main/resources/archetype-resources/src/test/java/InconsistencyTest.java Wed Jan 23 20:16:48 2013 +0100
182.3 @@ -0,0 +1,40 @@
182.4 +package ${package};
182.5 +
182.6 +import org.apidesign.bck2brwsr.vmtest.Compare;
182.7 +import org.apidesign.bck2brwsr.vmtest.VMTest;
182.8 +import org.testng.annotations.Factory;
182.9 +
182.10 +/** Bck2brwsr cares about compatibility with real Java. Whatever API is
182.11 + * supported by bck2brwsr, it needs to behave the same way as when running
182.12 + * in HotSpot VM.
182.13 + * <p>
182.14 + * There can be bugs, however. To help us fix them, we kindly ask you to
182.15 + * write an "inconsistency" test. A test that compares behavior of the API
182.16 + * between real VM and bck2brwsr VM. This class is skeleton of such test.
182.17 + *
182.18 + * @author Jaroslav Tulach <jtulach@netbeans.org>
182.19 + */
182.20 +public class InconsistencyTest {
182.21 + /** A method to demonstrate inconsistency between bck2brwsr and HotSpot.
182.22 + * Make calls to an API that behaves strangely, return some result at
182.23 + * the end. No need to use any <code>assert</code>.
182.24 + *
182.25 + * @return value to compare between HotSpot and bck2brwsr
182.26 + */
182.27 + @Compare
182.28 + public int checkStringHashCode() throws Exception {
182.29 + return "Is string hashCode the same?".hashCode();
182.30 + }
182.31 +
182.32 + /** Factory method that creates a three tests for each method annotated with
182.33 + * {@link org.apidesign.bck2brwsr.vmtest.Compare}. One executes the code in
182.34 + * HotSpot, one in Rhino and the last one compares the results.
182.35 + *
182.36 + * @see org.apidesign.bck2brwsr.vmtest.VMTest
182.37 + */
182.38 + @Factory
182.39 + public static Object[] create() {
182.40 + return VMTest.create(InconsistencyTest.class);
182.41 + }
182.42 +
182.43 +}
183.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
183.2 +++ b/mojo/src/main/resources/archetype-resources/src/test/java/IntegrationTest.java Wed Jan 23 20:16:48 2013 +0100
183.3 @@ -0,0 +1,46 @@
183.4 +package ${package};
183.5 +
183.6 +import org.apidesign.bck2brwsr.htmlpage.api.OnEvent;
183.7 +import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
183.8 +import org.apidesign.bck2brwsr.vmtest.HtmlFragment;
183.9 +import org.apidesign.bck2brwsr.vmtest.VMTest;
183.10 +import org.testng.annotations.Factory;
183.11 +
183.12 +/** Sometimes it is useful to run tests inside of the real browser.
183.13 + * To do that just annotate your method with {@link org.apidesign.bck2brwsr.vmtest.BrwsrTest}
183.14 + * and that is it. If your code references elements on the HTML page,
183.15 + * you can pass in an {@link org.apidesign.bck2brwsr.vmtest.HtmlFragment} which
183.16 + * will be made available on the page before your test starts.
183.17 + *
183.18 + * @author Jaroslav Tulach <jtulach@netbeans.org>
183.19 + */
183.20 +public class IntegrationTest {
183.21 +
183.22 + /** Write to testing code here. Use <code>assert</code> (but not TestNG's
183.23 + * Assert, as TestNG is not compiled with target 1.6 yet).
183.24 + */
183.25 + @HtmlFragment(
183.26 + "<h1 data-bind=\"text: helloMessage\">Loading Bck2Brwsr's Hello World...</h1>\n" +
183.27 + "Your name: <input id='input' data-bind=\"value: name, valueUpdate: 'afterkeydown'\"></input>\n" +
183.28 + "<button id=\"hello\">Say Hello!</button>\n" +
183.29 + "<p>\n" +
183.30 + " <canvas id=\"canvas\" width=\"300\" height=\"50\"></canvas>\n" +
183.31 + "</p>\n"
183.32 + )
183.33 + @BrwsrTest
183.34 + public void modifyValueAssertChangeInModel() {
183.35 + Index m = new Index();
183.36 + m.setName("Joe Hacker");
183.37 + m.applyBindings();
183.38 + assert "Joe Hacker".equals(m.INPUT.getValue()) : "Value is really Joe Hacker: " + m.INPUT.getValue();
183.39 + m.INPUT.setValue("Happy Joe");
183.40 + m.triggerEvent(m.INPUT, OnEvent.CHANGE);
183.41 + assert "Happy Joe".equals(m.getName()) : "Name property updated to Happy Joe: " + m.getName();
183.42 + }
183.43 +
183.44 + @Factory
183.45 + public static Object[] create() {
183.46 + return VMTest.create(IntegrationTest.class);
183.47 + }
183.48 +
183.49 +}
184.1 --- a/pom.xml Thu Oct 11 06:15:22 2012 -0700
184.2 +++ b/pom.xml Wed Jan 23 20:16:48 2013 +0100
184.3 @@ -3,14 +3,20 @@
184.4 <modelVersion>4.0.0</modelVersion>
184.5 <groupId>org.apidesign</groupId>
184.6 <artifactId>bck2brwsr</artifactId>
184.7 - <version>1.0-SNAPSHOT</version>
184.8 + <version>0.3-SNAPSHOT</version>
184.9 <packaging>pom</packaging>
184.10 <name>Back 2 Browser</name>
184.11 <modules>
184.12 - <module>vm</module>
184.13 - <module>htmlpage</module>
184.14 + <module>vm</module>
184.15 <module>emul</module>
184.16 <module>core</module>
184.17 + <module>dew</module>
184.18 + <module>mojo</module>
184.19 + <module>javaquery</module>
184.20 + <module>javap</module>
184.21 + <module>benchmarks</module>
184.22 + <module>launcher</module>
184.23 + <module>vmtest</module>
184.24 </modules>
184.25 <licenses>
184.26 <license>
184.27 @@ -43,6 +49,40 @@
184.28 </releases>
184.29 </pluginRepository>
184.30 </pluginRepositories>
184.31 + <build>
184.32 + <plugins>
184.33 + <plugin>
184.34 + <inherited>false</inherited>
184.35 + <groupId>com.mycila.maven-license-plugin</groupId>
184.36 + <artifactId>maven-license-plugin</artifactId>
184.37 + <version>1.9.0</version>
184.38 + <executions>
184.39 + <execution>
184.40 + <id>blah</id>
184.41 + <goals>
184.42 + <goal>check</goal>
184.43 + </goals>
184.44 + </execution>
184.45 + </executions>
184.46 + <configuration>
184.47 + <aggregate>true</aggregate>
184.48 + <basedir>${basedir}</basedir>
184.49 + <header>COPYING</header>
184.50 + <strictCheck>true</strictCheck>
184.51 + <excludes>
184.52 + <exclude>emul/**</exclude>
184.53 + <exclude>javap/**</exclude>
184.54 + <exclude>*</exclude>
184.55 + <exclude>.*/**</exclude>
184.56 + <exclude>mojo/src/main/resources/archetype-resources/**</exclude>
184.57 + <exclude>dew/src/main/resources/org/apidesign/bck2brwsr/dew/**</exclude>
184.58 + <exclude>vmtest/src/test/resources/**</exclude>
184.59 + <exclude>javaquery/api/src/main/resources/org/apidesign/bck2brwsr/htmlpage/knockout*.js</exclude>
184.60 + </excludes>
184.61 + </configuration>
184.62 + </plugin>
184.63 + </plugins>
184.64 + </build>
184.65 <dependencyManagement>
184.66 <dependencies>
184.67 <dependency>
184.68 @@ -75,4 +115,4 @@
184.69 <properties>
184.70 <license>COPYING</license>
184.71 </properties>
184.72 -</project>
184.73 \ No newline at end of file
184.74 +</project>
185.1 --- a/vm/nb-configuration.xml Thu Oct 11 06:15:22 2012 -0700
185.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
185.3 @@ -1,37 +0,0 @@
185.4 -<?xml version="1.0" encoding="UTF-8"?>
185.5 -<!--
185.6 -
185.7 - Java 4 Browser Bytecode Translator
185.8 - Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
185.9 -
185.10 - This program is free software: you can redistribute it and/or modify
185.11 - it under the terms of the GNU General Public License as published by
185.12 - the Free Software Foundation, version 2 of the License.
185.13 -
185.14 - This program is distributed in the hope that it will be useful,
185.15 - but WITHOUT ANY WARRANTY; without even the implied warranty of
185.16 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
185.17 - GNU General Public License for more details.
185.18 -
185.19 - You should have received a copy of the GNU General Public License
185.20 - along with this program. Look for COPYING file in the top folder.
185.21 - If not, see http://opensource.org/licenses/GPL-2.0.
185.22 -
185.23 --->
185.24 -<project-shared-configuration>
185.25 - <!--
185.26 -This file contains additional configuration written by modules in the NetBeans IDE.
185.27 -The configuration is intended to be shared among all the users of project and
185.28 -therefore it is assumed to be part of version control checkout.
185.29 -Without this configuration present, some functionality in the IDE may be limited or fail altogether.
185.30 --->
185.31 - <properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
185.32 - <!--
185.33 -Properties that influence various parts of the IDE, especially code formatting and the like.
185.34 -You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
185.35 -That way multiple projects can share the same settings (useful for formatting rules for example).
185.36 -Any value defined here will override the pom.xml file value but is only applicable to the current project.
185.37 --->
185.38 - <netbeans.compile.on.save>all</netbeans.compile.on.save>
185.39 - </properties>
185.40 -</project-shared-configuration>
186.1 --- a/vm/pom.xml Thu Oct 11 06:15:22 2012 -0700
186.2 +++ b/vm/pom.xml Wed Jan 23 20:16:48 2013 +0100
186.3 @@ -4,12 +4,12 @@
186.4 <parent>
186.5 <groupId>org.apidesign</groupId>
186.6 <artifactId>bck2brwsr</artifactId>
186.7 - <version>1.0-SNAPSHOT</version>
186.8 + <version>0.3-SNAPSHOT</version>
186.9 </parent>
186.10
186.11 <groupId>org.apidesign.bck2brwsr</groupId>
186.12 <artifactId>vm4brwsr</artifactId>
186.13 - <version>0.1-SNAPSHOT</version>
186.14 + <version>0.3-SNAPSHOT</version>
186.15 <packaging>jar</packaging>
186.16
186.17 <name>Java VM for Browser</name>
186.18 @@ -54,19 +54,20 @@
186.19 <configuration>
186.20 <archive>
186.21 <manifest>
186.22 - <mainClass>org.apidesign.vm4brwsr.GenJS</mainClass>
186.23 + <mainClass>org.apidesign.vm4brwsr.Main</mainClass>
186.24 </manifest>
186.25 </archive>
186.26 </configuration>
186.27 </plugin>
186.28 - <plugin>
186.29 - <groupId>com.mycila.maven-license-plugin</groupId>
186.30 - <artifactId>maven-license-plugin</artifactId>
186.31 - <version>1.9.0</version>
186.32 - <configuration>
186.33 - <header>src/header.txt</header>
186.34 - </configuration>
186.35 - </plugin>
186.36 + <plugin>
186.37 + <groupId>org.apache.maven.plugins</groupId>
186.38 + <artifactId>maven-compiler-plugin</artifactId>
186.39 + <version>2.3.2</version>
186.40 + <configuration>
186.41 + <source>1.7</source>
186.42 + <target>1.7</target>
186.43 + </configuration>
186.44 + </plugin>
186.45 </plugins>
186.46 </build>
186.47 <dependencies>
186.48 @@ -82,21 +83,21 @@
186.49 </exclusions>
186.50 </dependency>
186.51 <dependency>
186.52 - <groupId>org.netbeans.api</groupId>
186.53 - <artifactId>org-netbeans-modules-classfile</artifactId>
186.54 + <groupId>${project.groupId}</groupId>
186.55 + <artifactId>core</artifactId>
186.56 + <version>0.3-SNAPSHOT</version>
186.57 <type>jar</type>
186.58 </dependency>
186.59 <dependency>
186.60 - <groupId>org.apidesign.bck2brwsr</groupId>
186.61 - <artifactId>core</artifactId>
186.62 - <version>1.0-SNAPSHOT</version>
186.63 - <type>jar</type>
186.64 + <groupId>${project.groupId}</groupId>
186.65 + <artifactId>emul</artifactId>
186.66 + <version>0.3-SNAPSHOT</version>
186.67 + <scope>test</scope>
186.68 </dependency>
186.69 <dependency>
186.70 - <groupId>org.apidesign.bck2brwsr</groupId>
186.71 - <artifactId>emul</artifactId>
186.72 - <version>1.0-SNAPSHOT</version>
186.73 - <scope>test</scope>
186.74 + <groupId>${project.groupId}</groupId>
186.75 + <artifactId>javap</artifactId>
186.76 + <version>0.3-SNAPSHOT</version>
186.77 </dependency>
186.78 </dependencies>
186.79 </project>
187.1 --- a/vm/src/header.txt Thu Oct 11 06:15:22 2012 -0700
187.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
187.3 @@ -1,15 +0,0 @@
187.4 -Java 4 Browser Bytecode Translator
187.5 -Copyright (C) 2012-${year} Jaroslav Tulach <jaroslav.tulach@apidesign.org>
187.6 -
187.7 -This program is free software: you can redistribute it and/or modify
187.8 -it under the terms of the GNU General Public License as published by
187.9 -the Free Software Foundation, version 2 of the License.
187.10 -
187.11 -This program is distributed in the hope that it will be useful,
187.12 -but WITHOUT ANY WARRANTY; without even the implied warranty of
187.13 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
187.14 -GNU General Public License for more details.
187.15 -
187.16 -You should have received a copy of the GNU General Public License
187.17 -along with this program. Look for COPYING file in the top folder.
187.18 -If not, see http://opensource.org/licenses/GPL-2.0.
188.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
188.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/Bck2Brwsr.java Wed Jan 23 20:16:48 2013 +0100
188.3 @@ -0,0 +1,106 @@
188.4 +/**
188.5 + * Back 2 Browser Bytecode Translator
188.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
188.7 + *
188.8 + * This program is free software: you can redistribute it and/or modify
188.9 + * it under the terms of the GNU General Public License as published by
188.10 + * the Free Software Foundation, version 2 of the License.
188.11 + *
188.12 + * This program is distributed in the hope that it will be useful,
188.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
188.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
188.15 + * GNU General Public License for more details.
188.16 + *
188.17 + * You should have received a copy of the GNU General Public License
188.18 + * along with this program. Look for COPYING file in the top folder.
188.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
188.20 + */
188.21 +package org.apidesign.vm4brwsr;
188.22 +
188.23 +import java.io.IOException;
188.24 +import java.io.InputStream;
188.25 +import java.net.URL;
188.26 +import java.util.Enumeration;
188.27 +
188.28 +/** Build your own virtual machine! Use methods in this class to generate
188.29 + * a skeleton JVM in JavaScript that contains pre-compiled classes of your
188.30 + * choice. The generated script defines one JavaScript method that can
188.31 + * be used to bootstrap and load the virtual machine: <pre>
188.32 + * var vm = bck2brwsr();
188.33 + * var main = vm.loadClass('org.your.pkg.Main');
188.34 + * main.main__V_3Ljava_lang_String_2(null);
188.35 + * </pre>
188.36 + * In case one wants to initialize the virtual machine with ability to
188.37 + * load classes lazily when needed, one can provide a loader function to
188.38 + * when creating the virtual machine: <pre>
188.39 + * var vm = bck2brwsr(function(resource) {
188.40 + * return null; // byte[] for the resource
188.41 + * });
188.42 + * </pre>
188.43 + * In this scenario, when a request for an unknown class is made, the loader
188.44 + * function is asked for its byte code and the system dynamically transforms
188.45 + * it to JavaScript.
188.46 + *
188.47 + * @author Jaroslav Tulach <jtulach@netbeans.org>
188.48 + */
188.49 +public final class Bck2Brwsr {
188.50 + private Bck2Brwsr() {
188.51 + }
188.52 +
188.53 + /** Generates virtual machine from bytes served by a <code>resources</code>
188.54 + * provider.
188.55 + *
188.56 + * @param out the output to write the generated JavaScript to
188.57 + * @param resources provider of class files to use
188.58 + * @param classes additional classes to include in the generated script
188.59 + * @throws IOException I/O exception can be thrown when something goes wrong
188.60 + */
188.61 + public static void generate(Appendable out, Resources resources, String... classes) throws IOException {
188.62 + StringArray arr = StringArray.asList(classes);
188.63 + arr.add(VM.class.getName().replace('.', '/'));
188.64 + VM.compile(resources, out, arr);
188.65 + }
188.66 +
188.67 + /** Generates virtual machine from bytes served by a class loader.
188.68 + *
188.69 + * @param out the output to write the generated JavaScript to
188.70 + * @param loader class loader to load needed classes from
188.71 + * @param classes additional classes to include in the generated script
188.72 + * @throws IOException I/O exception can be thrown when something goes wrong
188.73 + */
188.74 + public static void generate(Appendable out, final ClassLoader loader, String... classes) throws IOException {
188.75 + class R implements Resources {
188.76 + @Override
188.77 + public InputStream get(String name) throws IOException {
188.78 + Enumeration<URL> en = loader.getResources(name);
188.79 + URL u = null;
188.80 + while (en.hasMoreElements()) {
188.81 + u = en.nextElement();
188.82 + }
188.83 + if (u == null) {
188.84 + throw new IOException("Can't find " + name);
188.85 + }
188.86 + return u.openStream();
188.87 + }
188.88 + }
188.89 + generate(out, new R(), classes);
188.90 + }
188.91 +
188.92 + /** Provider of resources (classes and other files). The
188.93 + * {@link #generate(java.lang.Appendable, org.apidesign.vm4brwsr.Bck2Brwsr.Resources, java.lang.String[])
188.94 + * generator method} will call back here for all classes needed during
188.95 + * translation to JavaScript.
188.96 + */
188.97 + public interface Resources {
188.98 + /** Loads given resource (class or other file like image). The
188.99 + * resource name to load bytes for the {@link String} class
188.100 + * would be <code>"java/lang/String.class"</code>.
188.101 + *
188.102 + * @param resource path to resource to load
188.103 + * @return the input stream for the resource
188.104 + * @throws IOException can be thrown if the loading fails on some error
188.105 + * or the file cannot be found
188.106 + */
188.107 + public InputStream get(String resource) throws IOException;
188.108 + }
188.109 +}
189.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Thu Oct 11 06:15:22 2012 -0700
189.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Wed Jan 23 20:16:48 2013 +0100
189.3 @@ -1,698 +1,1179 @@
189.4 -/*
189.5 -Java 4 Browser Bytecode Translator
189.6 -Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
189.7 -
189.8 -This program is free software: you can redistribute it and/or modify
189.9 -it under the terms of the GNU General Public License as published by
189.10 -the Free Software Foundation, version 2 of the License.
189.11 -
189.12 -This program is distributed in the hope that it will be useful,
189.13 -but WITHOUT ANY WARRANTY; without even the implied warranty of
189.14 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
189.15 -GNU General Public License for more details.
189.16 -
189.17 -You should have received a copy of the GNU General Public License
189.18 -along with this program. Look for COPYING file in the top folder.
189.19 -If not, see http://opensource.org/licenses/GPL-2.0.
189.20 -*/
189.21 +/**
189.22 + * Back 2 Browser Bytecode Translator
189.23 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
189.24 + *
189.25 + * This program is free software: you can redistribute it and/or modify
189.26 + * it under the terms of the GNU General Public License as published by
189.27 + * the Free Software Foundation, version 2 of the License.
189.28 + *
189.29 + * This program is distributed in the hope that it will be useful,
189.30 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
189.31 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
189.32 + * GNU General Public License for more details.
189.33 + *
189.34 + * You should have received a copy of the GNU General Public License
189.35 + * along with this program. Look for COPYING file in the top folder.
189.36 + * If not, see http://opensource.org/licenses/GPL-2.0.
189.37 + */
189.38 package org.apidesign.vm4brwsr;
189.39
189.40 import java.io.IOException;
189.41 import java.io.InputStream;
189.42 -import java.util.ArrayList;
189.43 -import java.util.Collection;
189.44 -import java.util.List;
189.45 -import org.apidesign.bck2brwsr.core.ExtraJavaScript;
189.46 import org.apidesign.bck2brwsr.core.JavaScriptBody;
189.47 -import org.netbeans.modules.classfile.Annotation;
189.48 -import org.netbeans.modules.classfile.AnnotationComponent;
189.49 -import org.netbeans.modules.classfile.ArrayElementValue;
189.50 -import static org.netbeans.modules.classfile.ByteCodes.*;
189.51 -import org.netbeans.modules.classfile.CPClassInfo;
189.52 -import org.netbeans.modules.classfile.CPEntry;
189.53 -import org.netbeans.modules.classfile.CPFieldInfo;
189.54 -import org.netbeans.modules.classfile.CPMethodInfo;
189.55 -import org.netbeans.modules.classfile.CPStringInfo;
189.56 -import org.netbeans.modules.classfile.ClassFile;
189.57 -import org.netbeans.modules.classfile.ClassName;
189.58 -import org.netbeans.modules.classfile.Code;
189.59 -import org.netbeans.modules.classfile.ElementValue;
189.60 -import org.netbeans.modules.classfile.Method;
189.61 -import org.netbeans.modules.classfile.Parameter;
189.62 -import org.netbeans.modules.classfile.PrimitiveElementValue;
189.63 -import org.netbeans.modules.classfile.Variable;
189.64 +import org.apidesign.javap.AnnotationParser;
189.65 +import org.apidesign.javap.ClassData;
189.66 +import org.apidesign.javap.FieldData;
189.67 +import org.apidesign.javap.MethodData;
189.68 +import org.apidesign.javap.StackMapIterator;
189.69 +import static org.apidesign.javap.RuntimeConstants.*;
189.70 +import org.apidesign.javap.TrapData;
189.71 +import org.apidesign.javap.TrapDataIterator;
189.72
189.73 /** Translator of the code inside class files to JavaScript.
189.74 *
189.75 * @author Jaroslav Tulach <jtulach@netbeans.org>
189.76 */
189.77 -public final class ByteCodeToJavaScript {
189.78 - private final ClassFile jc;
189.79 - private final Appendable out;
189.80 - private final Collection<? super String> references;
189.81 +abstract class ByteCodeToJavaScript {
189.82 + private ClassData jc;
189.83 + final Appendable out;
189.84
189.85 - private ByteCodeToJavaScript(
189.86 - ClassFile jc, Appendable out, Collection<? super String> references
189.87 - ) {
189.88 - this.jc = jc;
189.89 + protected ByteCodeToJavaScript(Appendable out) {
189.90 this.out = out;
189.91 - this.references = references;
189.92 + }
189.93 +
189.94 + /* Collects additional required resources.
189.95 + *
189.96 + * @param internalClassName classes that were referenced and should be loaded in order the
189.97 + * generated JavaScript code works properly. The names are in internal
189.98 + * JVM form so String is <code>java/lang/String</code>.
189.99 + */
189.100 + protected abstract boolean requireReference(String internalClassName);
189.101 +
189.102 + /*
189.103 + * @param resourcePath name of resources to read
189.104 + */
189.105 + protected abstract void requireScript(String resourcePath) throws IOException;
189.106 +
189.107 + /** Allows subclasses to redefine what field a function representing a
189.108 + * class gets assigned. By default it returns the suggested name followed
189.109 + * by <code>" = "</code>;
189.110 + *
189.111 + * @param className suggested name of the class
189.112 + */
189.113 + /* protected */ String assignClass(String className) {
189.114 + return className + " = ";
189.115 + }
189.116 + /* protected */ String accessClass(String classOperation) {
189.117 + return classOperation;
189.118 + }
189.119 +
189.120 + /** Prints out a debug message.
189.121 + *
189.122 + * @param msg the message
189.123 + * @return true if the message has been printed
189.124 + * @throws IOException
189.125 + */
189.126 + boolean debug(String msg) throws IOException {
189.127 + out.append(msg);
189.128 + return true;
189.129 }
189.130
189.131 /**
189.132 * Converts a given class file to a JavaScript version.
189.133 *
189.134 * @param classFile input stream with code of the .class file
189.135 - * @param out a {@link StringBuilder} or similar to generate the output to
189.136 - * @param references a write only collection where the system adds list of
189.137 - * other classes that were referenced and should be loaded in order the
189.138 - * generated JavaScript code works properly. The names are in internal
189.139 - * JVM form so String is <code>java/lang/String</code>. Can be <code>null</code>
189.140 - * if one is not interested in knowing references
189.141 - * @param scripts write only collection with names of resources to read
189.142 * @return the initialization code for this class, if any. Otherwise <code>null</code>
189.143 *
189.144 * @throws IOException if something goes wrong during read or write or translating
189.145 */
189.146
189.147 - public static String compile(
189.148 - InputStream classFile, Appendable out,
189.149 - Collection<? super String> references,
189.150 - Collection<? super String> scripts
189.151 - ) throws IOException {
189.152 - ClassFile jc = new ClassFile(classFile, true);
189.153 - final ClassName extraAnn = ClassName.getClassName(ExtraJavaScript.class.getName().replace('.', '/'));
189.154 - Annotation a = jc.getAnnotation(extraAnn);
189.155 - if (a != null) {
189.156 - final ElementValue annVal = a.getComponent("resource").getValue();
189.157 - String res = ((PrimitiveElementValue)annVal).getValue().getValue().toString();
189.158 - scripts.add(res);
189.159 - final AnnotationComponent process = a.getComponent("processByteCode");
189.160 - if (process != null && "const=0".equals(process.getValue().toString())) {
189.161 + public String compile(InputStream classFile) throws IOException {
189.162 + this.jc = new ClassData(classFile);
189.163 + if (jc.getMajor_version() < 50) {
189.164 + throw new IOException("Can't compile " + jc.getClassName() + ". Class file version " + jc.getMajor_version() + "."
189.165 + + jc.getMinor_version() + " - recompile with -target 1.6 (at least)."
189.166 + );
189.167 + }
189.168 + byte[] arrData = jc.findAnnotationData(true);
189.169 + String[] arr = findAnnotation(arrData, jc,
189.170 + "org.apidesign.bck2brwsr.core.ExtraJavaScript",
189.171 + "resource", "processByteCode"
189.172 + );
189.173 + if (arr != null) {
189.174 + requireScript(arr[0]);
189.175 + if ("0".equals(arr[1])) {
189.176 return null;
189.177 }
189.178 }
189.179 -
189.180 - ByteCodeToJavaScript compiler = new ByteCodeToJavaScript(
189.181 - jc, out, references
189.182 + String[] proto = findAnnotation(arrData, jc,
189.183 + "org.apidesign.bck2brwsr.core.JavaScriptPrototype",
189.184 + "container", "prototype"
189.185 );
189.186 - List<String> toInitilize = new ArrayList<String>();
189.187 - for (Method m : jc.getMethods()) {
189.188 - if (m.isStatic()) {
189.189 - compiler.generateStaticMethod(m, toInitilize);
189.190 - } else {
189.191 - compiler.generateInstanceMethod(m);
189.192 + StringArray toInitilize = new StringArray();
189.193 + final String className = className(jc);
189.194 + out.append("\n\n").append(assignClass(className));
189.195 + out.append("function CLS() {");
189.196 + out.append("\n if (!CLS.prototype.$instOf_").append(className).append(") {");
189.197 + for (FieldData v : jc.getFields()) {
189.198 + if (v.isStatic()) {
189.199 + out.append("\n CLS.").append(v.getName()).append(initField(v));
189.200 }
189.201 }
189.202 - for (Variable v : jc.getVariables()) {
189.203 - if (v.isStatic()) {
189.204 - compiler.generateStaticField(v);
189.205 + if (proto == null) {
189.206 + String sc = jc.getSuperClassName(); // with _
189.207 + out.append("\n var pp = ").
189.208 + append(accessClass(sc.replace('/', '_'))).append("(true);");
189.209 + out.append("\n var p = CLS.prototype = pp;");
189.210 + out.append("\n var c = p;");
189.211 + out.append("\n var sprcls = pp.constructor.$class;");
189.212 + } else {
189.213 + out.append("\n var p = CLS.prototype = ").append(proto[1]).append(";");
189.214 + if (proto[0] == null) {
189.215 + proto[0] = "p";
189.216 + }
189.217 + out.append("\n var c = ").append(proto[0]).append(";");
189.218 + out.append("\n var sprcls = null;");
189.219 + }
189.220 + for (MethodData m : jc.getMethods()) {
189.221 + byte[] onlyArr = m.findAnnotationData(true);
189.222 + String[] only = findAnnotation(onlyArr, jc,
189.223 + "org.apidesign.bck2brwsr.core.JavaScriptOnly",
189.224 + "name", "value"
189.225 + );
189.226 + if (only != null) {
189.227 + if (only[0] != null && only[1] != null) {
189.228 + out.append("\n p.").append(only[0]).append(" = ")
189.229 + .append(only[1]).append(";");
189.230 + }
189.231 + continue;
189.232 + }
189.233 + String prefix;
189.234 + String mn;
189.235 + if (m.isStatic()) {
189.236 + prefix = "\n c.";
189.237 + mn = generateStaticMethod(prefix, m, toInitilize);
189.238 + } else {
189.239 + if (m.isConstructor()) {
189.240 + prefix = "\n CLS.";
189.241 + mn = generateInstanceMethod(prefix, m);
189.242 + } else {
189.243 + prefix = "\n c.";
189.244 + mn = generateInstanceMethod(prefix, m);
189.245 + }
189.246 + }
189.247 + byte[] runAnno = m.findAnnotationData(false);
189.248 + if (runAnno != null) {
189.249 + out.append(prefix).append(mn).append(".anno = {");
189.250 + generateAnno(jc, out, runAnno);
189.251 + out.append("\n };");
189.252 + }
189.253 + out.append(prefix).append(mn).append(".access = " + m.getAccess()).append(";");
189.254 + }
189.255 + out.append("\n c.constructor = CLS;");
189.256 + out.append("\n c.$instOf_").append(className).append(" = true;");
189.257 + for (String superInterface : jc.getSuperInterfaces()) {
189.258 + out.append("\n c.$instOf_").append(superInterface.replace('/', '_')).append(" = true;");
189.259 + }
189.260 + out.append("\n CLS.$class = ");
189.261 + out.append(accessClass("java_lang_Class(true);"));
189.262 + out.append("\n CLS.$class.jvmName = '").append(jc.getClassName()).append("';");
189.263 + out.append("\n CLS.$class.superclass = sprcls;");
189.264 + out.append("\n CLS.$class.access = ").append(jc.getAccessFlags()+";");
189.265 + out.append("\n CLS.$class.cnstr = CLS;");
189.266 + byte[] classAnno = jc.findAnnotationData(false);
189.267 + if (classAnno != null) {
189.268 + out.append("\n CLS.$class.anno = {");
189.269 + generateAnno(jc, out, classAnno);
189.270 + out.append("\n };");
189.271 + }
189.272 + out.append("\n }");
189.273 + out.append("\n if (arguments.length === 0) {");
189.274 + out.append("\n if (!(this instanceof CLS)) {");
189.275 + out.append("\n return new CLS();");
189.276 + out.append("\n }");
189.277 + for (FieldData v : jc.getFields()) {
189.278 + byte[] onlyArr = v.findAnnotationData(true);
189.279 + String[] only = findAnnotation(onlyArr, jc,
189.280 + "org.apidesign.bck2brwsr.core.JavaScriptOnly",
189.281 + "name", "value"
189.282 + );
189.283 + if (only != null) {
189.284 + if (only[0] != null && only[1] != null) {
189.285 + out.append("\n p.").append(only[0]).append(" = ")
189.286 + .append(only[1]).append(";");
189.287 + }
189.288 + continue;
189.289 + }
189.290 + if (!v.isStatic()) {
189.291 + out.append("\n this.fld_").
189.292 + append(v.getName()).append(initField(v));
189.293 }
189.294 }
189.295 -
189.296 - final String className = jc.getName().getInternalName().replace('/', '_');
189.297 - out.append("\nfunction ").append(className);
189.298 - out.append("() {");
189.299 - for (Variable v : jc.getVariables()) {
189.300 - if (!v.isStatic()) {
189.301 - out.append("\n this." + v.getName() + " = 0;");
189.302 - }
189.303 - }
189.304 - out.append("\n}\n\nfunction ").append(className).append("_proto() {");
189.305 - out.append("\n if (").append(className).
189.306 - append(".prototype.$instOf_").append(className).append(") {");
189.307 - out.append("\n return ").append(className).append(".prototype;");
189.308 + out.append("\n return this;");
189.309 out.append("\n }");
189.310 - ClassName sc = jc.getSuperClass();
189.311 - if (sc != null) {
189.312 - out.append("\n ").append(sc.getInternalName().replace('/', '_')).append("_proto();");
189.313 - out.append("\n ").append(className)
189.314 - .append(".prototype = new ").append(sc.getInternalName().replace('/', '_')).append(';');
189.315 - }
189.316 - for (Method m : jc.getMethods()) {
189.317 - if (!m.isStatic() && !m.isPrivate() && !m.getName().contains("<init>")) {
189.318 - compiler.generateMethodReference("\n " + className + ".prototype.", m);
189.319 - }
189.320 - }
189.321 - out.append("\n " + className + ".prototype.$instOf_").append(className).append(" = true;");
189.322 - for (ClassName superInterface : jc.getInterfaces()) {
189.323 - out.append("\n " + className + ".prototype.$instOf_").append(superInterface.getInternalName().replace('/', '_')).append(" = true;");
189.324 - }
189.325 - out.append("\n return ").append(className).append(".prototype;");
189.326 - out.append("\n}");
189.327 - out.append("\n").append(className).append("_proto();");
189.328 + out.append("\n return arguments[0] ? new CLS() : CLS.prototype;");
189.329 + out.append("\n};");
189.330 StringBuilder sb = new StringBuilder();
189.331 - for (String init : toInitilize) {
189.332 + for (String init : toInitilize.toArray()) {
189.333 sb.append("\n").append(init).append("();");
189.334 }
189.335 return sb.toString();
189.336 }
189.337 - private void generateStaticMethod(Method m, List<String> toInitilize) throws IOException {
189.338 - if (javaScriptBody(m, true)) {
189.339 + private String generateStaticMethod(String prefix, MethodData m, StringArray toInitilize) throws IOException {
189.340 + String jsb = javaScriptBody(prefix, m, true);
189.341 + if (jsb != null) {
189.342 + return jsb;
189.343 + }
189.344 + final String mn = findMethodName(m, new StringBuilder());
189.345 + if (mn.equals("class__V")) {
189.346 + toInitilize.add(accessClass(className(jc)) + "(false)." + mn);
189.347 + }
189.348 + generateMethod(prefix, mn, m);
189.349 + return mn;
189.350 + }
189.351 +
189.352 + private String generateInstanceMethod(String prefix, MethodData m) throws IOException {
189.353 + String jsb = javaScriptBody(prefix, m, false);
189.354 + if (jsb != null) {
189.355 + return jsb;
189.356 + }
189.357 + final String mn = findMethodName(m, new StringBuilder());
189.358 + generateMethod(prefix, mn, m);
189.359 + return mn;
189.360 + }
189.361 +
189.362 + private void generateMethod(String prefix, String name, MethodData m)
189.363 + throws IOException {
189.364 + final StackMapIterator stackMapIterator = m.createStackMapIterator();
189.365 + TrapDataIterator trap = m.getTrapDataIterator();
189.366 + final LocalsMapper lmapper =
189.367 + new LocalsMapper(stackMapIterator.getArguments());
189.368 +
189.369 + out.append(prefix).append(name).append(" = function(");
189.370 + lmapper.outputArguments(out, m.isStatic());
189.371 + out.append(") {").append("\n");
189.372 +
189.373 + final byte[] byteCodes = m.getCode();
189.374 + if (byteCodes == null) {
189.375 + out.append(" throw 'no code found for ")
189.376 + .append(jc.getClassName()).append('.')
189.377 + .append(m.getName()).append("';\n");
189.378 + out.append("};");
189.379 return;
189.380 }
189.381 - final String mn = findMethodName(m);
189.382 - out.append("\nfunction ").append(
189.383 - jc.getName().getInternalName().replace('/', '_')
189.384 - ).append('_').append(mn);
189.385 - if (mn.equals("classV")) {
189.386 - toInitilize.add(jc.getName().getInternalName().replace('/', '_') + '_' + mn);
189.387 +
189.388 + final StackMapper smapper = new StackMapper();
189.389 +
189.390 + if (!m.isStatic()) {
189.391 + out.append(" var ").append(" lcA0 = this;\n");
189.392 }
189.393 - out.append('(');
189.394 - String space = "";
189.395 - List<Parameter> args = m.getParameters();
189.396 - for (int index = 0, i = 0; i < args.size(); i++) {
189.397 - out.append(space);
189.398 - out.append("arg").append(String.valueOf(index));
189.399 - space = ",";
189.400 - final String desc = findDescriptor(args.get(i).getDescriptor());
189.401 - if ("D".equals(desc) || "J".equals(desc)) {
189.402 - index += 2;
189.403 - } else {
189.404 - index++;
189.405 - }
189.406 - }
189.407 - out.append(") {").append("\n");
189.408 - final Code code = m.getCode();
189.409 - if (code != null) {
189.410 - int len = code.getMaxLocals();
189.411 - for (int index = args.size(), i = args.size(); i < len; i++) {
189.412 - out.append(" var ");
189.413 - out.append("arg").append(String.valueOf(i)).append(";\n");
189.414 - }
189.415 - out.append(" var stack = new Array();\n");
189.416 - produceCode(code.getByteCodes());
189.417 - } else {
189.418 - out.append(" /* no code found for ").append(m.getTypeSignature()).append(" */\n");
189.419 - }
189.420 - out.append("}");
189.421 - }
189.422 -
189.423 - private void generateMethodReference(String prefix, Method m) throws IOException {
189.424 - final String name = findMethodName(m);
189.425 - out.append(prefix).append(name).append(" = ")
189.426 - .append(jc.getName().getInternalName().replace('/', '_'))
189.427 - .append('_').append(name).append(";");
189.428 - }
189.429 -
189.430 - private void generateInstanceMethod(Method m) throws IOException {
189.431 - if (javaScriptBody(m, false)) {
189.432 - return;
189.433 - }
189.434 - out.append("\nfunction ").append(
189.435 - jc.getName().getInternalName().replace('/', '_')
189.436 - ).append('_').append(findMethodName(m));
189.437 - out.append("(arg0");
189.438 - String space = ",";
189.439 - List<Parameter> args = m.getParameters();
189.440 - for (int index = 1, i = 0; i < args.size(); i++) {
189.441 - out.append(space);
189.442 - out.append("arg").append(String.valueOf(index));
189.443 - final String desc = findDescriptor(args.get(i).getDescriptor());
189.444 - if ("D".equals(desc) || "J".equals(desc)) {
189.445 - index += 2;
189.446 - } else {
189.447 - index++;
189.448 - }
189.449 - }
189.450 - out.append(") {").append("\n");
189.451 - final Code code = m.getCode();
189.452 - if (code != null) {
189.453 - int len = code.getMaxLocals();
189.454 - for (int index = args.size(), i = args.size(); i < len; i++) {
189.455 - out.append(" var ");
189.456 - out.append("arg").append(String.valueOf(i + 1)).append(";\n");
189.457 - }
189.458 - out.append(";\n var stack = new Array();\n");
189.459 - produceCode(code.getByteCodes());
189.460 - } else {
189.461 - out.append(" /* no code found for ").append(m.getTypeSignature()).append(" */\n");
189.462 - }
189.463 - out.append("}");
189.464 - }
189.465
189.466 - private void produceCode(byte[] byteCodes) throws IOException {
189.467 + int lastStackFrame = -1;
189.468 + TrapData[] previousTrap = null;
189.469 +
189.470 out.append("\n var gt = 0;\n for(;;) switch(gt) {\n");
189.471 for (int i = 0; i < byteCodes.length; i++) {
189.472 int prev = i;
189.473 - out.append(" case " + i).append(": ");
189.474 - final int c = (byteCodes[i] + 256) % 256;
189.475 + stackMapIterator.advanceTo(i);
189.476 + boolean changeInCatch = trap.advanceTo(i);
189.477 + if (changeInCatch || lastStackFrame != stackMapIterator.getFrameIndex()) {
189.478 + if (previousTrap != null) {
189.479 + generateCatch(previousTrap);
189.480 + previousTrap = null;
189.481 + }
189.482 + }
189.483 + if (lastStackFrame != stackMapIterator.getFrameIndex()) {
189.484 + lastStackFrame = stackMapIterator.getFrameIndex();
189.485 + lmapper.syncWithFrameLocals(stackMapIterator.getFrameLocals());
189.486 + smapper.syncWithFrameStack(stackMapIterator.getFrameStack());
189.487 + out.append(" case " + i).append(": ");
189.488 + changeInCatch = true;
189.489 + } else {
189.490 + debug(" /* " + i + " */ ");
189.491 + }
189.492 + if (changeInCatch && trap.useTry()) {
189.493 + out.append("try {");
189.494 + previousTrap = trap.current();
189.495 + }
189.496 + final int c = readByte(byteCodes, i);
189.497 switch (c) {
189.498 - case bc_aload_0:
189.499 - case bc_iload_0:
189.500 - case bc_lload_0:
189.501 - case bc_fload_0:
189.502 - case bc_dload_0:
189.503 - out.append("stack.push(arg0);");
189.504 + case opc_aload_0:
189.505 + emit(out, "var @1 = @2;", smapper.pushA(), lmapper.getA(0));
189.506 break;
189.507 - case bc_aload_1:
189.508 - case bc_iload_1:
189.509 - case bc_lload_1:
189.510 - case bc_fload_1:
189.511 - case bc_dload_1:
189.512 - out.append("stack.push(arg1);");
189.513 + case opc_iload_0:
189.514 + emit(out, "var @1 = @2;", smapper.pushI(), lmapper.getI(0));
189.515 break;
189.516 - case bc_aload_2:
189.517 - case bc_iload_2:
189.518 - case bc_lload_2:
189.519 - case bc_fload_2:
189.520 - case bc_dload_2:
189.521 - out.append("stack.push(arg2);");
189.522 + case opc_lload_0:
189.523 + emit(out, "var @1 = @2;", smapper.pushL(), lmapper.getL(0));
189.524 break;
189.525 - case bc_aload_3:
189.526 - case bc_iload_3:
189.527 - case bc_lload_3:
189.528 - case bc_fload_3:
189.529 - case bc_dload_3:
189.530 - out.append("stack.push(arg3);");
189.531 + case opc_fload_0:
189.532 + emit(out, "var @1 = @2;", smapper.pushF(), lmapper.getF(0));
189.533 break;
189.534 - case bc_iload:
189.535 - case bc_lload:
189.536 - case bc_fload:
189.537 - case bc_dload:
189.538 - case bc_aload: {
189.539 - final int indx = (byteCodes[++i] + 256) % 256;
189.540 - out.append("stack.push(arg").append(indx + ");");
189.541 + case opc_dload_0:
189.542 + emit(out, "var @1 = @2;", smapper.pushD(), lmapper.getD(0));
189.543 + break;
189.544 + case opc_aload_1:
189.545 + emit(out, "var @1 = @2;", smapper.pushA(), lmapper.getA(1));
189.546 + break;
189.547 + case opc_iload_1:
189.548 + emit(out, "var @1 = @2;", smapper.pushI(), lmapper.getI(1));
189.549 + break;
189.550 + case opc_lload_1:
189.551 + emit(out, "var @1 = @2;", smapper.pushL(), lmapper.getL(1));
189.552 + break;
189.553 + case opc_fload_1:
189.554 + emit(out, "var @1 = @2;", smapper.pushF(), lmapper.getF(1));
189.555 + break;
189.556 + case opc_dload_1:
189.557 + emit(out, "var @1 = @2;", smapper.pushD(), lmapper.getD(1));
189.558 + break;
189.559 + case opc_aload_2:
189.560 + emit(out, "var @1 = @2;", smapper.pushA(), lmapper.getA(2));
189.561 + break;
189.562 + case opc_iload_2:
189.563 + emit(out, "var @1 = @2;", smapper.pushI(), lmapper.getI(2));
189.564 + break;
189.565 + case opc_lload_2:
189.566 + emit(out, "var @1 = @2;", smapper.pushL(), lmapper.getL(2));
189.567 + break;
189.568 + case opc_fload_2:
189.569 + emit(out, "var @1 = @2;", smapper.pushF(), lmapper.getF(2));
189.570 + break;
189.571 + case opc_dload_2:
189.572 + emit(out, "var @1 = @2;", smapper.pushD(), lmapper.getD(2));
189.573 + break;
189.574 + case opc_aload_3:
189.575 + emit(out, "var @1 = @2;", smapper.pushA(), lmapper.getA(3));
189.576 + break;
189.577 + case opc_iload_3:
189.578 + emit(out, "var @1 = @2;", smapper.pushI(), lmapper.getI(3));
189.579 + break;
189.580 + case opc_lload_3:
189.581 + emit(out, "var @1 = @2;", smapper.pushL(), lmapper.getL(3));
189.582 + break;
189.583 + case opc_fload_3:
189.584 + emit(out, "var @1 = @2;", smapper.pushF(), lmapper.getF(3));
189.585 + break;
189.586 + case opc_dload_3:
189.587 + emit(out, "var @1 = @2;", smapper.pushD(), lmapper.getD(3));
189.588 + break;
189.589 + case opc_iload: {
189.590 + final int indx = readByte(byteCodes, ++i);
189.591 + emit(out, "var @1 = @2;",
189.592 + smapper.pushI(), lmapper.getI(indx));
189.593 break;
189.594 }
189.595 - case bc_istore:
189.596 - case bc_lstore:
189.597 - case bc_fstore:
189.598 - case bc_dstore:
189.599 - case bc_astore: {
189.600 - final int indx = (byteCodes[++i] + 256) % 256;
189.601 - out.append("arg" + indx).append(" = stack.pop()");
189.602 + case opc_lload: {
189.603 + final int indx = readByte(byteCodes, ++i);
189.604 + emit(out, "var @1 = @2;",
189.605 + smapper.pushL(), lmapper.getL(indx));
189.606 break;
189.607 }
189.608 - case bc_astore_0:
189.609 - case bc_istore_0:
189.610 - case bc_lstore_0:
189.611 - case bc_fstore_0:
189.612 - case bc_dstore_0:
189.613 - out.append("arg0 = stack.pop();");
189.614 + case opc_fload: {
189.615 + final int indx = readByte(byteCodes, ++i);
189.616 + emit(out, "var @1 = @2;",
189.617 + smapper.pushF(), lmapper.getF(indx));
189.618 break;
189.619 - case bc_astore_1:
189.620 - case bc_istore_1:
189.621 - case bc_lstore_1:
189.622 - case bc_fstore_1:
189.623 - case bc_dstore_1:
189.624 - out.append("arg1 = stack.pop();");
189.625 + }
189.626 + case opc_dload: {
189.627 + final int indx = readByte(byteCodes, ++i);
189.628 + emit(out, "var @1 = @2;",
189.629 + smapper.pushD(), lmapper.getD(indx));
189.630 break;
189.631 - case bc_astore_2:
189.632 - case bc_istore_2:
189.633 - case bc_lstore_2:
189.634 - case bc_fstore_2:
189.635 - case bc_dstore_2:
189.636 - out.append("arg2 = stack.pop();");
189.637 + }
189.638 + case opc_aload: {
189.639 + final int indx = readByte(byteCodes, ++i);
189.640 + emit(out, "var @1 = @2;",
189.641 + smapper.pushA(), lmapper.getA(indx));
189.642 break;
189.643 - case bc_astore_3:
189.644 - case bc_istore_3:
189.645 - case bc_lstore_3:
189.646 - case bc_fstore_3:
189.647 - case bc_dstore_3:
189.648 - out.append("arg3 = stack.pop();");
189.649 + }
189.650 + case opc_istore: {
189.651 + final int indx = readByte(byteCodes, ++i);
189.652 + emit(out, "var @1 = @2;",
189.653 + lmapper.setI(indx), smapper.popI());
189.654 break;
189.655 - case bc_iadd:
189.656 - case bc_ladd:
189.657 - case bc_fadd:
189.658 - case bc_dadd:
189.659 - out.append("stack.push(stack.pop() + stack.pop());");
189.660 + }
189.661 + case opc_lstore: {
189.662 + final int indx = readByte(byteCodes, ++i);
189.663 + emit(out, "var @1 = @2;",
189.664 + lmapper.setL(indx), smapper.popL());
189.665 break;
189.666 - case bc_isub:
189.667 - case bc_lsub:
189.668 - case bc_fsub:
189.669 - case bc_dsub:
189.670 - out.append("{ var tmp = stack.pop(); stack.push(stack.pop() - tmp); }");
189.671 + }
189.672 + case opc_fstore: {
189.673 + final int indx = readByte(byteCodes, ++i);
189.674 + emit(out, "var @1 = @2;",
189.675 + lmapper.setF(indx), smapper.popF());
189.676 break;
189.677 - case bc_imul:
189.678 - case bc_lmul:
189.679 - case bc_fmul:
189.680 - case bc_dmul:
189.681 - out.append("stack.push(stack.pop() * stack.pop());");
189.682 + }
189.683 + case opc_dstore: {
189.684 + final int indx = readByte(byteCodes, ++i);
189.685 + emit(out, "var @1 = @2;",
189.686 + lmapper.setD(indx), smapper.popD());
189.687 break;
189.688 - case bc_idiv:
189.689 - case bc_ldiv:
189.690 - out.append("{ var tmp = stack.pop(); stack.push(Math.floor(stack.pop() / tmp)); }");
189.691 + }
189.692 + case opc_astore: {
189.693 + final int indx = readByte(byteCodes, ++i);
189.694 + emit(out, "var @1 = @2;",
189.695 + lmapper.setA(indx), smapper.popA());
189.696 break;
189.697 - case bc_fdiv:
189.698 - case bc_ddiv:
189.699 - out.append("{ var tmp = stack.pop(); stack.push(stack.pop() / tmp); }");
189.700 + }
189.701 + case opc_astore_0:
189.702 + emit(out, "var @1 = @2;", lmapper.setA(0), smapper.popA());
189.703 break;
189.704 - case bc_iand:
189.705 - case bc_land:
189.706 - out.append("stack.push(stack.pop() & stack.pop());");
189.707 + case opc_istore_0:
189.708 + emit(out, "var @1 = @2;", lmapper.setI(0), smapper.popI());
189.709 break;
189.710 - case bc_ior:
189.711 - case bc_lor:
189.712 - out.append("stack.push(stack.pop() | stack.pop());");
189.713 + case opc_lstore_0:
189.714 + emit(out, "var @1 = @2;", lmapper.setL(0), smapper.popL());
189.715 break;
189.716 - case bc_ixor:
189.717 - case bc_lxor:
189.718 - out.append("stack.push(stack.pop() ^ stack.pop());");
189.719 + case opc_fstore_0:
189.720 + emit(out, "var @1 = @2;", lmapper.setF(0), smapper.popF());
189.721 break;
189.722 - case bc_ineg:
189.723 - case bc_lneg:
189.724 - case bc_fneg:
189.725 - case bc_dneg:
189.726 - out.append("stack.push(- stack.pop());");
189.727 + case opc_dstore_0:
189.728 + emit(out, "var @1 = @2;", lmapper.setD(0), smapper.popD());
189.729 break;
189.730 - case bc_ishl:
189.731 - case bc_lshl:
189.732 - out.append("{ var v = stack.pop(); stack.push(stack.pop() << v); }");
189.733 + case opc_astore_1:
189.734 + emit(out, "var @1 = @2;", lmapper.setA(1), smapper.popA());
189.735 break;
189.736 - case bc_ishr:
189.737 - case bc_lshr:
189.738 - out.append("{ var v = stack.pop(); stack.push(stack.pop() >> v); }");
189.739 + case opc_istore_1:
189.740 + emit(out, "var @1 = @2;", lmapper.setI(1), smapper.popI());
189.741 break;
189.742 - case bc_iushr:
189.743 - case bc_lushr:
189.744 - out.append("{ var v = stack.pop(); stack.push(stack.pop() >>> v); }");
189.745 + case opc_lstore_1:
189.746 + emit(out, "var @1 = @2;", lmapper.setL(1), smapper.popL());
189.747 break;
189.748 - case bc_iinc: {
189.749 - final int varIndx = (byteCodes[++i] + 256) % 256;
189.750 - final int incrBy = (byteCodes[++i] + 256) % 256;
189.751 + case opc_fstore_1:
189.752 + emit(out, "var @1 = @2;", lmapper.setF(1), smapper.popF());
189.753 + break;
189.754 + case opc_dstore_1:
189.755 + emit(out, "var @1 = @2;", lmapper.setD(1), smapper.popD());
189.756 + break;
189.757 + case opc_astore_2:
189.758 + emit(out, "var @1 = @2;", lmapper.setA(2), smapper.popA());
189.759 + break;
189.760 + case opc_istore_2:
189.761 + emit(out, "var @1 = @2;", lmapper.setI(2), smapper.popI());
189.762 + break;
189.763 + case opc_lstore_2:
189.764 + emit(out, "var @1 = @2;", lmapper.setL(2), smapper.popL());
189.765 + break;
189.766 + case opc_fstore_2:
189.767 + emit(out, "var @1 = @2;", lmapper.setF(2), smapper.popF());
189.768 + break;
189.769 + case opc_dstore_2:
189.770 + emit(out, "var @1 = @2;", lmapper.setD(2), smapper.popD());
189.771 + break;
189.772 + case opc_astore_3:
189.773 + emit(out, "var @1 = @2;", lmapper.setA(3), smapper.popA());
189.774 + break;
189.775 + case opc_istore_3:
189.776 + emit(out, "var @1 = @2;", lmapper.setI(3), smapper.popI());
189.777 + break;
189.778 + case opc_lstore_3:
189.779 + emit(out, "var @1 = @2;", lmapper.setL(3), smapper.popL());
189.780 + break;
189.781 + case opc_fstore_3:
189.782 + emit(out, "var @1 = @2;", lmapper.setF(3), smapper.popF());
189.783 + break;
189.784 + case opc_dstore_3:
189.785 + emit(out, "var @1 = @2;", lmapper.setD(3), smapper.popD());
189.786 + break;
189.787 + case opc_iadd:
189.788 + emit(out, "@1 = @1.add32(@2);", smapper.getI(1), smapper.popI());
189.789 + break;
189.790 + case opc_ladd:
189.791 + emit(out, "@1 += @2;", smapper.getL(1), smapper.popL());
189.792 + break;
189.793 + case opc_fadd:
189.794 + emit(out, "@1 += @2;", smapper.getF(1), smapper.popF());
189.795 + break;
189.796 + case opc_dadd:
189.797 + emit(out, "@1 += @2;", smapper.getD(1), smapper.popD());
189.798 + break;
189.799 + case opc_isub:
189.800 + emit(out, "@1 = @1.sub32(@2);", smapper.getI(1), smapper.popI());
189.801 + break;
189.802 + case opc_lsub:
189.803 + emit(out, "@1 -= @2;", smapper.getL(1), smapper.popL());
189.804 + break;
189.805 + case opc_fsub:
189.806 + emit(out, "@1 -= @2;", smapper.getF(1), smapper.popF());
189.807 + break;
189.808 + case opc_dsub:
189.809 + emit(out, "@1 -= @2;", smapper.getD(1), smapper.popD());
189.810 + break;
189.811 + case opc_imul:
189.812 + emit(out, "@1 = @1.mul32(@2);", smapper.getI(1), smapper.popI());
189.813 + break;
189.814 + case opc_lmul:
189.815 + emit(out, "@1 *= @2;", smapper.getL(1), smapper.popL());
189.816 + break;
189.817 + case opc_fmul:
189.818 + emit(out, "@1 *= @2;", smapper.getF(1), smapper.popF());
189.819 + break;
189.820 + case opc_dmul:
189.821 + emit(out, "@1 *= @2;", smapper.getD(1), smapper.popD());
189.822 + break;
189.823 + case opc_idiv:
189.824 + emit(out, "@1 = Math.floor(@1 / @2);",
189.825 + smapper.getI(1), smapper.popI());
189.826 + break;
189.827 + case opc_ldiv:
189.828 + emit(out, "@1 = Math.floor(@1 / @2);",
189.829 + smapper.getL(1), smapper.popL());
189.830 + break;
189.831 + case opc_fdiv:
189.832 + emit(out, "@1 /= @2;", smapper.getF(1), smapper.popF());
189.833 + break;
189.834 + case opc_ddiv:
189.835 + emit(out, "@1 /= @2;", smapper.getD(1), smapper.popD());
189.836 + break;
189.837 + case opc_irem:
189.838 + emit(out, "@1 %= @2;", smapper.getI(1), smapper.popI());
189.839 + break;
189.840 + case opc_lrem:
189.841 + emit(out, "@1 %= @2;", smapper.getL(1), smapper.popL());
189.842 + break;
189.843 + case opc_frem:
189.844 + emit(out, "@1 %= @2;", smapper.getF(1), smapper.popF());
189.845 + break;
189.846 + case opc_drem:
189.847 + emit(out, "@1 %= @2;", smapper.getD(1), smapper.popD());
189.848 + break;
189.849 + case opc_iand:
189.850 + emit(out, "@1 &= @2;", smapper.getI(1), smapper.popI());
189.851 + break;
189.852 + case opc_land:
189.853 + emit(out, "@1 &= @2;", smapper.getL(1), smapper.popL());
189.854 + break;
189.855 + case opc_ior:
189.856 + emit(out, "@1 |= @2;", smapper.getI(1), smapper.popI());
189.857 + break;
189.858 + case opc_lor:
189.859 + emit(out, "@1 |= @2;", smapper.getL(1), smapper.popL());
189.860 + break;
189.861 + case opc_ixor:
189.862 + emit(out, "@1 ^= @2;", smapper.getI(1), smapper.popI());
189.863 + break;
189.864 + case opc_lxor:
189.865 + emit(out, "@1 ^= @2;", smapper.getL(1), smapper.popL());
189.866 + break;
189.867 + case opc_ineg:
189.868 + emit(out, "@1 = -@1;", smapper.getI(0));
189.869 + break;
189.870 + case opc_lneg:
189.871 + emit(out, "@1 = -@1;", smapper.getL(0));
189.872 + break;
189.873 + case opc_fneg:
189.874 + emit(out, "@1 = -@1;", smapper.getF(0));
189.875 + break;
189.876 + case opc_dneg:
189.877 + emit(out, "@1 = -@1;", smapper.getD(0));
189.878 + break;
189.879 + case opc_ishl:
189.880 + emit(out, "@1 <<= @2;", smapper.getI(1), smapper.popI());
189.881 + break;
189.882 + case opc_lshl:
189.883 + emit(out, "@1 <<= @2;", smapper.getL(1), smapper.popI());
189.884 + break;
189.885 + case opc_ishr:
189.886 + emit(out, "@1 >>= @2;", smapper.getI(1), smapper.popI());
189.887 + break;
189.888 + case opc_lshr:
189.889 + emit(out, "@1 >>= @2;", smapper.getL(1), smapper.popI());
189.890 + break;
189.891 + case opc_iushr:
189.892 + emit(out, "@1 >>>= @2;", smapper.getI(1), smapper.popI());
189.893 + break;
189.894 + case opc_lushr:
189.895 + emit(out, "@1 >>>= @2;", smapper.getL(1), smapper.popI());
189.896 + break;
189.897 + case opc_iinc: {
189.898 + final int varIndx = readByte(byteCodes, ++i);
189.899 + final int incrBy = byteCodes[++i];
189.900 if (incrBy == 1) {
189.901 - out.append("arg" + varIndx).append("++;");
189.902 + emit(out, "@1++;", lmapper.getI(varIndx));
189.903 } else {
189.904 - out.append("arg" + varIndx).append(" += " + incrBy).append(";");
189.905 + emit(out, "@1 += @2;",
189.906 + lmapper.getI(varIndx),
189.907 + Integer.toString(incrBy));
189.908 }
189.909 break;
189.910 }
189.911 - case bc_return:
189.912 - out.append("return;");
189.913 + case opc_return:
189.914 + emit(out, "return;");
189.915 break;
189.916 - case bc_ireturn:
189.917 - case bc_lreturn:
189.918 - case bc_freturn:
189.919 - case bc_dreturn:
189.920 - case bc_areturn:
189.921 - out.append("return stack.pop();");
189.922 + case opc_ireturn:
189.923 + emit(out, "return @1;", smapper.popI());
189.924 break;
189.925 - case bc_i2l:
189.926 - case bc_i2f:
189.927 - case bc_i2d:
189.928 - case bc_l2i:
189.929 + case opc_lreturn:
189.930 + emit(out, "return @1;", smapper.popL());
189.931 + break;
189.932 + case opc_freturn:
189.933 + emit(out, "return @1;", smapper.popF());
189.934 + break;
189.935 + case opc_dreturn:
189.936 + emit(out, "return @1;", smapper.popD());
189.937 + break;
189.938 + case opc_areturn:
189.939 + emit(out, "return @1;", smapper.popA());
189.940 + break;
189.941 + case opc_i2l:
189.942 + emit(out, "var @2 = @1;", smapper.popI(), smapper.pushL());
189.943 + break;
189.944 + case opc_i2f:
189.945 + emit(out, "var @2 = @1;", smapper.popI(), smapper.pushF());
189.946 + break;
189.947 + case opc_i2d:
189.948 + emit(out, "var @2 = @1;", smapper.popI(), smapper.pushD());
189.949 + break;
189.950 + case opc_l2i:
189.951 + emit(out, "var @2 = @1;", smapper.popL(), smapper.pushI());
189.952 + break;
189.953 // max int check?
189.954 - case bc_l2f:
189.955 - case bc_l2d:
189.956 - case bc_f2d:
189.957 - case bc_d2f:
189.958 - out.append("/* number conversion */");
189.959 + case opc_l2f:
189.960 + emit(out, "var @2 = @1;", smapper.popL(), smapper.pushF());
189.961 break;
189.962 - case bc_f2i:
189.963 - case bc_f2l:
189.964 - case bc_d2i:
189.965 - case bc_d2l:
189.966 - out.append("stack.push(Math.floor(stack.pop()));");
189.967 + case opc_l2d:
189.968 + emit(out, "var @2 = @1;", smapper.popL(), smapper.pushD());
189.969 break;
189.970 - case bc_i2b:
189.971 - case bc_i2c:
189.972 - case bc_i2s:
189.973 - out.append("/* number conversion */");
189.974 + case opc_f2d:
189.975 + emit(out, "var @2 = @1;", smapper.popF(), smapper.pushD());
189.976 break;
189.977 - case bc_aconst_null:
189.978 - out.append("stack.push(null);");
189.979 + case opc_d2f:
189.980 + emit(out, "var @2 = @1;", smapper.popD(), smapper.pushF());
189.981 break;
189.982 - case bc_iconst_m1:
189.983 - out.append("stack.push(-1);");
189.984 + case opc_f2i:
189.985 + emit(out, "var @2 = Math.floor(@1);",
189.986 + smapper.popF(), smapper.pushI());
189.987 break;
189.988 - case bc_iconst_0:
189.989 - case bc_dconst_0:
189.990 - case bc_lconst_0:
189.991 - case bc_fconst_0:
189.992 - out.append("stack.push(0);");
189.993 + case opc_f2l:
189.994 + emit(out, "var @2 = Math.floor(@1);",
189.995 + smapper.popF(), smapper.pushL());
189.996 break;
189.997 - case bc_iconst_1:
189.998 - case bc_lconst_1:
189.999 - case bc_fconst_1:
189.1000 - case bc_dconst_1:
189.1001 - out.append("stack.push(1);");
189.1002 + case opc_d2i:
189.1003 + emit(out, "var @2 = Math.floor(@1);",
189.1004 + smapper.popD(), smapper.pushI());
189.1005 break;
189.1006 - case bc_iconst_2:
189.1007 - case bc_fconst_2:
189.1008 - out.append("stack.push(2);");
189.1009 + case opc_d2l:
189.1010 + emit(out, "var @2 = Math.floor(@1);",
189.1011 + smapper.popD(), smapper.pushL());
189.1012 break;
189.1013 - case bc_iconst_3:
189.1014 - out.append("stack.push(3);");
189.1015 + case opc_i2b:
189.1016 + emit(out, "var @1 = @1.toInt8();", smapper.getI(0));
189.1017 break;
189.1018 - case bc_iconst_4:
189.1019 - out.append("stack.push(4);");
189.1020 + case opc_i2c:
189.1021 + out.append("{ /* number conversion */ }");
189.1022 break;
189.1023 - case bc_iconst_5:
189.1024 - out.append("stack.push(5);");
189.1025 + case opc_i2s:
189.1026 + emit(out, "var @1 = @1.toInt16();", smapper.getI(0));
189.1027 break;
189.1028 - case bc_ldc: {
189.1029 - int indx = byteCodes[++i];
189.1030 - CPEntry entry = jc.getConstantPool().get(indx);
189.1031 - String v = encodeConstant(entry);
189.1032 - out.append("stack.push(").append(v).append(");");
189.1033 + case opc_aconst_null:
189.1034 + emit(out, "var @1 = null;", smapper.pushA());
189.1035 + break;
189.1036 + case opc_iconst_m1:
189.1037 + emit(out, "var @1 = -1;", smapper.pushI());
189.1038 + break;
189.1039 + case opc_iconst_0:
189.1040 + emit(out, "var @1 = 0;", smapper.pushI());
189.1041 + break;
189.1042 + case opc_dconst_0:
189.1043 + emit(out, "var @1 = 0;", smapper.pushD());
189.1044 + break;
189.1045 + case opc_lconst_0:
189.1046 + emit(out, "var @1 = 0;", smapper.pushL());
189.1047 + break;
189.1048 + case opc_fconst_0:
189.1049 + emit(out, "var @1 = 0;", smapper.pushF());
189.1050 + break;
189.1051 + case opc_iconst_1:
189.1052 + emit(out, "var @1 = 1;", smapper.pushI());
189.1053 + break;
189.1054 + case opc_lconst_1:
189.1055 + emit(out, "var @1 = 1;", smapper.pushL());
189.1056 + break;
189.1057 + case opc_fconst_1:
189.1058 + emit(out, "var @1 = 1;", smapper.pushF());
189.1059 + break;
189.1060 + case opc_dconst_1:
189.1061 + emit(out, "var @1 = 1;", smapper.pushD());
189.1062 + break;
189.1063 + case opc_iconst_2:
189.1064 + emit(out, "var @1 = 2;", smapper.pushI());
189.1065 + break;
189.1066 + case opc_fconst_2:
189.1067 + emit(out, "var @1 = 2;", smapper.pushF());
189.1068 + break;
189.1069 + case opc_iconst_3:
189.1070 + emit(out, "var @1 = 3;", smapper.pushI());
189.1071 + break;
189.1072 + case opc_iconst_4:
189.1073 + emit(out, "var @1 = 4;", smapper.pushI());
189.1074 + break;
189.1075 + case opc_iconst_5:
189.1076 + emit(out, "var @1 = 5;", smapper.pushI());
189.1077 + break;
189.1078 + case opc_ldc: {
189.1079 + int indx = readByte(byteCodes, ++i);
189.1080 + String v = encodeConstant(indx);
189.1081 + int type = VarType.fromConstantType(jc.getTag(indx));
189.1082 + emit(out, "var @1 = @2;", smapper.pushT(type), v);
189.1083 break;
189.1084 }
189.1085 - case bc_ldc_w:
189.1086 - case bc_ldc2_w: {
189.1087 + case opc_ldc_w:
189.1088 + case opc_ldc2_w: {
189.1089 int indx = readIntArg(byteCodes, i);
189.1090 - CPEntry entry = jc.getConstantPool().get(indx);
189.1091 i += 2;
189.1092 - String v = encodeConstant(entry);
189.1093 - out.append("stack.push(").append(v).append(");");
189.1094 + String v = encodeConstant(indx);
189.1095 + int type = VarType.fromConstantType(jc.getTag(indx));
189.1096 + emit(out, "var @1 = @2;", smapper.pushT(type), v);
189.1097 break;
189.1098 }
189.1099 - case bc_lcmp:
189.1100 - case bc_fcmpl:
189.1101 - case bc_fcmpg:
189.1102 - case bc_dcmpl:
189.1103 - case bc_dcmpg: {
189.1104 - out.append("{ var delta = stack.pop() - stack.pop(); stack.push(delta < 0 ?-1 : (delta == 0 ? 0 : 1)); }");
189.1105 + case opc_lcmp:
189.1106 + emit(out, "var @3 = (@2 == @1) ? 0 : ((@2 < @1) ? -1 : 1);",
189.1107 + smapper.popL(), smapper.popL(), smapper.pushI());
189.1108 break;
189.1109 - }
189.1110 - case bc_if_icmpeq: {
189.1111 - i = generateIf(byteCodes, i, "==");
189.1112 + case opc_fcmpl:
189.1113 + case opc_fcmpg:
189.1114 + emit(out, "var @3 = (@2 == @1) ? 0 : ((@2 < @1) ? -1 : 1);",
189.1115 + smapper.popF(), smapper.popF(), smapper.pushI());
189.1116 break;
189.1117 - }
189.1118 - case bc_ifeq: {
189.1119 + case opc_dcmpl:
189.1120 + case opc_dcmpg:
189.1121 + emit(out, "var @3 = (@2 == @1) ? 0 : ((@2 < @1) ? -1 : 1);",
189.1122 + smapper.popD(), smapper.popD(), smapper.pushI());
189.1123 + break;
189.1124 + case opc_if_acmpeq:
189.1125 + i = generateIf(byteCodes, i, smapper.popA(), smapper.popA(),
189.1126 + "===");
189.1127 + break;
189.1128 + case opc_if_acmpne:
189.1129 + i = generateIf(byteCodes, i, smapper.popA(), smapper.popA(),
189.1130 + "!=");
189.1131 + break;
189.1132 + case opc_if_icmpeq:
189.1133 + i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
189.1134 + "==");
189.1135 + break;
189.1136 + case opc_ifeq: {
189.1137 int indx = i + readIntArg(byteCodes, i);
189.1138 - out.append("if (stack.pop() == 0) { gt = " + indx);
189.1139 - out.append("; continue; }");
189.1140 + emit(out, "if (@1 == 0) { gt = @2; continue; }",
189.1141 + smapper.popI(), Integer.toString(indx));
189.1142 i += 2;
189.1143 break;
189.1144 }
189.1145 - case bc_ifne: {
189.1146 + case opc_ifne: {
189.1147 int indx = i + readIntArg(byteCodes, i);
189.1148 - out.append("if (stack.pop() != 0) { gt = " + indx);
189.1149 - out.append("; continue; }");
189.1150 + emit(out, "if (@1 != 0) { gt = @2; continue; }",
189.1151 + smapper.popI(), Integer.toString(indx));
189.1152 i += 2;
189.1153 break;
189.1154 }
189.1155 - case bc_iflt: {
189.1156 + case opc_iflt: {
189.1157 int indx = i + readIntArg(byteCodes, i);
189.1158 - out.append("if (stack.pop() < 0) { gt = " + indx);
189.1159 - out.append("; continue; }");
189.1160 + emit(out, "if (@1 < 0) { gt = @2; continue; }",
189.1161 + smapper.popI(), Integer.toString(indx));
189.1162 i += 2;
189.1163 break;
189.1164 }
189.1165 - case bc_ifle: {
189.1166 + case opc_ifle: {
189.1167 int indx = i + readIntArg(byteCodes, i);
189.1168 - out.append("if (stack.pop() <= 0) { gt = " + indx);
189.1169 - out.append("; continue; }");
189.1170 + emit(out, "if (@1 <= 0) { gt = @2; continue; }",
189.1171 + smapper.popI(), Integer.toString(indx));
189.1172 i += 2;
189.1173 break;
189.1174 }
189.1175 - case bc_ifgt: {
189.1176 + case opc_ifgt: {
189.1177 int indx = i + readIntArg(byteCodes, i);
189.1178 - out.append("if (stack.pop() > 0) { gt = " + indx);
189.1179 - out.append("; continue; }");
189.1180 + emit(out, "if (@1 > 0) { gt = @2; continue; }",
189.1181 + smapper.popI(), Integer.toString(indx));
189.1182 i += 2;
189.1183 break;
189.1184 }
189.1185 - case bc_ifge: {
189.1186 + case opc_ifge: {
189.1187 int indx = i + readIntArg(byteCodes, i);
189.1188 - out.append("if (stack.pop() >= 0) { gt = " + indx);
189.1189 - out.append("; continue; }");
189.1190 + emit(out, "if (@1 >= 0) { gt = @2; continue; }",
189.1191 + smapper.popI(), Integer.toString(indx));
189.1192 i += 2;
189.1193 break;
189.1194 }
189.1195 - case bc_ifnonnull: {
189.1196 + case opc_ifnonnull: {
189.1197 int indx = i + readIntArg(byteCodes, i);
189.1198 - out.append("if (stack.pop()) { gt = " + indx);
189.1199 - out.append("; continue; }");
189.1200 + emit(out, "if (@1 !== null) { gt = @2; continue; }",
189.1201 + smapper.popA(), Integer.toString(indx));
189.1202 i += 2;
189.1203 break;
189.1204 }
189.1205 - case bc_ifnull: {
189.1206 + case opc_ifnull: {
189.1207 int indx = i + readIntArg(byteCodes, i);
189.1208 - out.append("if (!stack.pop()) { gt = " + indx);
189.1209 - out.append("; continue; }");
189.1210 + emit(out, "if (@1 === null) { gt = @2; continue; }",
189.1211 + smapper.popA(), Integer.toString(indx));
189.1212 i += 2;
189.1213 break;
189.1214 }
189.1215 - case bc_if_icmpne:
189.1216 - i = generateIf(byteCodes, i, "!=");
189.1217 + case opc_if_icmpne:
189.1218 + i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
189.1219 + "!=");
189.1220 break;
189.1221 - case bc_if_icmplt:
189.1222 - i = generateIf(byteCodes, i, ">");
189.1223 + case opc_if_icmplt:
189.1224 + i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
189.1225 + "<");
189.1226 break;
189.1227 - case bc_if_icmple:
189.1228 - i = generateIf(byteCodes, i, ">=");
189.1229 + case opc_if_icmple:
189.1230 + i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
189.1231 + "<=");
189.1232 break;
189.1233 - case bc_if_icmpgt:
189.1234 - i = generateIf(byteCodes, i, "<");
189.1235 + case opc_if_icmpgt:
189.1236 + i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
189.1237 + ">");
189.1238 break;
189.1239 - case bc_if_icmpge:
189.1240 - i = generateIf(byteCodes, i, "<=");
189.1241 + case opc_if_icmpge:
189.1242 + i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
189.1243 + ">=");
189.1244 break;
189.1245 - case bc_goto: {
189.1246 + case opc_goto: {
189.1247 int indx = i + readIntArg(byteCodes, i);
189.1248 - out.append("gt = " + indx).append("; continue;");
189.1249 + emit(out, "gt = @1; continue;", Integer.toString(indx));
189.1250 i += 2;
189.1251 break;
189.1252 }
189.1253 - case bc_invokeinterface: {
189.1254 - i = invokeVirtualMethod(byteCodes, i) + 2;
189.1255 + case opc_lookupswitch: {
189.1256 + int table = i / 4 * 4 + 4;
189.1257 + int dflt = i + readInt4(byteCodes, table);
189.1258 + table += 4;
189.1259 + int n = readInt4(byteCodes, table);
189.1260 + table += 4;
189.1261 + out.append("switch (").append(smapper.popI()).append(") {\n");
189.1262 + while (n-- > 0) {
189.1263 + int cnstnt = readInt4(byteCodes, table);
189.1264 + table += 4;
189.1265 + int offset = i + readInt4(byteCodes, table);
189.1266 + table += 4;
189.1267 + out.append(" case " + cnstnt).append(": gt = " + offset).append("; continue;\n");
189.1268 + }
189.1269 + out.append(" default: gt = " + dflt).append("; continue;\n}");
189.1270 + i = table - 1;
189.1271 break;
189.1272 }
189.1273 - case bc_invokevirtual:
189.1274 - i = invokeVirtualMethod(byteCodes, i);
189.1275 + case opc_tableswitch: {
189.1276 + int table = i / 4 * 4 + 4;
189.1277 + int dflt = i + readInt4(byteCodes, table);
189.1278 + table += 4;
189.1279 + int low = readInt4(byteCodes, table);
189.1280 + table += 4;
189.1281 + int high = readInt4(byteCodes, table);
189.1282 + table += 4;
189.1283 + out.append("switch (").append(smapper.popI()).append(") {\n");
189.1284 + while (low <= high) {
189.1285 + int offset = i + readInt4(byteCodes, table);
189.1286 + table += 4;
189.1287 + out.append(" case " + low).append(": gt = " + offset).append("; continue;\n");
189.1288 + low++;
189.1289 + }
189.1290 + out.append(" default: gt = " + dflt).append("; continue;\n}");
189.1291 + i = table - 1;
189.1292 break;
189.1293 - case bc_invokespecial:
189.1294 - i = invokeStaticMethod(byteCodes, i, false);
189.1295 + }
189.1296 + case opc_invokeinterface: {
189.1297 + i = invokeVirtualMethod(byteCodes, i, smapper) + 2;
189.1298 break;
189.1299 - case bc_invokestatic:
189.1300 - i = invokeStaticMethod(byteCodes, i, true);
189.1301 + }
189.1302 + case opc_invokevirtual:
189.1303 + i = invokeVirtualMethod(byteCodes, i, smapper);
189.1304 break;
189.1305 - case bc_new: {
189.1306 + case opc_invokespecial:
189.1307 + i = invokeStaticMethod(byteCodes, i, smapper, false);
189.1308 + break;
189.1309 + case opc_invokestatic:
189.1310 + i = invokeStaticMethod(byteCodes, i, smapper, true);
189.1311 + break;
189.1312 + case opc_new: {
189.1313 int indx = readIntArg(byteCodes, i);
189.1314 - CPClassInfo ci = jc.getConstantPool().getClass(indx);
189.1315 - out.append("stack.push(");
189.1316 - out.append("new ").append(ci.getClassName().getInternalName().replace('/','_'));
189.1317 - out.append(");");
189.1318 - addReference(ci.getClassName().getInternalName());
189.1319 + String ci = jc.getClassName(indx);
189.1320 + emit(out, "var @1 = new @2;",
189.1321 + smapper.pushA(), accessClass(ci.replace('/', '_')));
189.1322 + addReference(ci);
189.1323 i += 2;
189.1324 break;
189.1325 }
189.1326 - case bc_newarray: {
189.1327 - int type = byteCodes[i++];
189.1328 - out.append("stack.push(new Array(stack.pop()));");
189.1329 + case opc_newarray:
189.1330 + int atype = readByte(byteCodes, ++i);
189.1331 + String jvmType;
189.1332 + switch (atype) {
189.1333 + case 4: jvmType = "[Z"; break;
189.1334 + case 5: jvmType = "[C"; break;
189.1335 + case 6: jvmType = "[F"; break;
189.1336 + case 7: jvmType = "[D"; break;
189.1337 + case 8: jvmType = "[B"; break;
189.1338 + case 9: jvmType = "[S"; break;
189.1339 + case 10: jvmType = "[I"; break;
189.1340 + case 11: jvmType = "[J"; break;
189.1341 + default: throw new IllegalStateException("Array type: " + atype);
189.1342 + }
189.1343 + emit(out, "var @2 = Array.prototype.newArray__Ljava_lang_Object_2ZLjava_lang_String_2I(true, '@3', @1);",
189.1344 + smapper.popI(), smapper.pushA(), jvmType);
189.1345 + break;
189.1346 + case opc_anewarray: {
189.1347 + int type = readIntArg(byteCodes, i);
189.1348 + i += 2;
189.1349 + String typeName = jc.getClassName(type);
189.1350 + if (typeName.startsWith("[")) {
189.1351 + typeName = "[" + typeName;
189.1352 + } else {
189.1353 + typeName = "[L" + typeName + ";";
189.1354 + }
189.1355 + emit(out, "var @2 = Array.prototype.newArray__Ljava_lang_Object_2ZLjava_lang_String_2I(false, '@3', @1);",
189.1356 + smapper.popI(), smapper.pushA(), typeName);
189.1357 break;
189.1358 }
189.1359 - case bc_anewarray: {
189.1360 - i += 2; // skip type of array
189.1361 - out.append("stack.push(new Array(stack.pop()));");
189.1362 + case opc_multianewarray: {
189.1363 + int type = readIntArg(byteCodes, i);
189.1364 + i += 2;
189.1365 + String typeName = jc.getClassName(type);
189.1366 + int dim = readByte(byteCodes, ++i);
189.1367 + StringBuilder dims = new StringBuilder();
189.1368 + dims.append('[');
189.1369 + for (int d = 0; d < dim; d++) {
189.1370 + if (d != 0) {
189.1371 + dims.append(",");
189.1372 + }
189.1373 + dims.append(smapper.popI());
189.1374 + }
189.1375 + dims.append(']');
189.1376 + emit(out, "var @2 = Array.prototype.multiNewArray__Ljava_lang_Object_2Ljava_lang_String_2_3II('@3', @1, 0);",
189.1377 + dims.toString(), smapper.pushA(), typeName);
189.1378 break;
189.1379 }
189.1380 - case bc_arraylength:
189.1381 - out.append("stack.push(stack.pop().length);");
189.1382 + case opc_arraylength:
189.1383 + emit(out, "var @2 = @1.length;",
189.1384 + smapper.popA(), smapper.pushI());
189.1385 break;
189.1386 - case bc_iastore:
189.1387 - case bc_lastore:
189.1388 - case bc_fastore:
189.1389 - case bc_dastore:
189.1390 - case bc_aastore:
189.1391 - case bc_bastore:
189.1392 - case bc_castore:
189.1393 - case bc_sastore: {
189.1394 - out.append("{ var value = stack.pop(); var indx = stack.pop(); stack.pop()[indx] = value; }");
189.1395 + case opc_lastore:
189.1396 + emit(out, "@3.at(@2, @1);",
189.1397 + smapper.popL(), smapper.popI(), smapper.popA());
189.1398 + break;
189.1399 + case opc_fastore:
189.1400 + emit(out, "@3.at(@2, @1);",
189.1401 + smapper.popF(), smapper.popI(), smapper.popA());
189.1402 + break;
189.1403 + case opc_dastore:
189.1404 + emit(out, "@3.at(@2, @1);",
189.1405 + smapper.popD(), smapper.popI(), smapper.popA());
189.1406 + break;
189.1407 + case opc_aastore:
189.1408 + emit(out, "@3.at(@2, @1);",
189.1409 + smapper.popA(), smapper.popI(), smapper.popA());
189.1410 + break;
189.1411 + case opc_iastore:
189.1412 + case opc_bastore:
189.1413 + case opc_castore:
189.1414 + case opc_sastore:
189.1415 + emit(out, "@3.at(@2, @1);",
189.1416 + smapper.popI(), smapper.popI(), smapper.popA());
189.1417 + break;
189.1418 + case opc_laload:
189.1419 + emit(out, "var @3 = @2.at(@1);",
189.1420 + smapper.popI(), smapper.popA(), smapper.pushL());
189.1421 + break;
189.1422 + case opc_faload:
189.1423 + emit(out, "var @3 = @2.at(@1);",
189.1424 + smapper.popI(), smapper.popA(), smapper.pushF());
189.1425 + break;
189.1426 + case opc_daload:
189.1427 + emit(out, "var @3 = @2.at(@1);",
189.1428 + smapper.popI(), smapper.popA(), smapper.pushD());
189.1429 + break;
189.1430 + case opc_aaload:
189.1431 + emit(out, "var @3 = @2.at(@1);",
189.1432 + smapper.popI(), smapper.popA(), smapper.pushA());
189.1433 + break;
189.1434 + case opc_iaload:
189.1435 + case opc_baload:
189.1436 + case opc_caload:
189.1437 + case opc_saload:
189.1438 + emit(out, "var @3 = @2.at(@1);",
189.1439 + smapper.popI(), smapper.popA(), smapper.pushI());
189.1440 + break;
189.1441 + case opc_pop:
189.1442 + case opc_pop2:
189.1443 + smapper.pop(1);
189.1444 + debug("/* pop */");
189.1445 + break;
189.1446 + case opc_dup: {
189.1447 + final Variable v = smapper.get(0);
189.1448 + emit(out, "var @1 = @2;", smapper.pushT(v.getType()), v);
189.1449 break;
189.1450 }
189.1451 - case bc_iaload:
189.1452 - case bc_laload:
189.1453 - case bc_faload:
189.1454 - case bc_daload:
189.1455 - case bc_aaload:
189.1456 - case bc_baload:
189.1457 - case bc_caload:
189.1458 - case bc_saload: {
189.1459 - out.append("{ var indx = stack.pop(); stack.push(stack.pop()[indx]); }");
189.1460 + case opc_dup2: {
189.1461 + if (smapper.get(0).isCategory2()) {
189.1462 + final Variable v = smapper.get(0);
189.1463 + emit(out, "var @1 = @2;",
189.1464 + smapper.pushT(v.getType()), v);
189.1465 + } else {
189.1466 + final Variable v1 = smapper.get(0);
189.1467 + final Variable v2 = smapper.get(1);
189.1468 + emit(out, "var @1 = @2, @3 = @4;",
189.1469 + smapper.pushT(v2.getType()), v2,
189.1470 + smapper.pushT(v1.getType()), v1);
189.1471 + }
189.1472 break;
189.1473 }
189.1474 - case bc_pop2:
189.1475 - out.append("stack.pop();");
189.1476 - case bc_pop:
189.1477 - out.append("stack.pop();");
189.1478 + case opc_dup_x1: {
189.1479 + final Variable vi1 = smapper.pop();
189.1480 + final Variable vi2 = smapper.pop();
189.1481 + final Variable vo3 = smapper.pushT(vi1.getType());
189.1482 + final Variable vo2 = smapper.pushT(vi2.getType());
189.1483 + final Variable vo1 = smapper.pushT(vi1.getType());
189.1484 +
189.1485 + emit(out, "var @1 = @2, @3 = @4, @5 = @6;",
189.1486 + vo1, vi1, vo2, vi2, vo3, vo1);
189.1487 break;
189.1488 - case bc_dup:
189.1489 - out.append("stack.push(stack[stack.length - 1]);");
189.1490 + }
189.1491 + case opc_dup_x2: {
189.1492 + if (smapper.get(1).isCategory2()) {
189.1493 + final Variable vi1 = smapper.pop();
189.1494 + final Variable vi2 = smapper.pop();
189.1495 + final Variable vo3 = smapper.pushT(vi1.getType());
189.1496 + final Variable vo2 = smapper.pushT(vi2.getType());
189.1497 + final Variable vo1 = smapper.pushT(vi1.getType());
189.1498 +
189.1499 + emit(out, "var @1 = @2, @3 = @4, @5 = @6;",
189.1500 + vo1, vi1, vo2, vi2, vo3, vo1);
189.1501 + } else {
189.1502 + final Variable vi1 = smapper.pop();
189.1503 + final Variable vi2 = smapper.pop();
189.1504 + final Variable vi3 = smapper.pop();
189.1505 + final Variable vo4 = smapper.pushT(vi1.getType());
189.1506 + final Variable vo3 = smapper.pushT(vi3.getType());
189.1507 + final Variable vo2 = smapper.pushT(vi2.getType());
189.1508 + final Variable vo1 = smapper.pushT(vi1.getType());
189.1509 +
189.1510 + emit(out, "var @1 = @2, @3 = @4, @5 = @6, @7 = @8;",
189.1511 + vo1, vi1, vo2, vi2, vo3, vi3, vo4, vo1);
189.1512 + }
189.1513 break;
189.1514 - case bc_bipush:
189.1515 - out.append("stack.push(" + byteCodes[++i] + ");");
189.1516 + }
189.1517 + case opc_bipush:
189.1518 + emit(out, "var @1 = @2;",
189.1519 + smapper.pushI(), Integer.toString(byteCodes[++i]));
189.1520 break;
189.1521 - case bc_sipush:
189.1522 - out.append("stack.push(" + readIntArg(byteCodes, i) + ");");
189.1523 + case opc_sipush:
189.1524 + emit(out, "var @1 = @2;",
189.1525 + smapper.pushI(),
189.1526 + Integer.toString(readIntArg(byteCodes, i)));
189.1527 i += 2;
189.1528 break;
189.1529 - case bc_getfield: {
189.1530 + case opc_getfield: {
189.1531 int indx = readIntArg(byteCodes, i);
189.1532 - CPFieldInfo fi = (CPFieldInfo) jc.getConstantPool().get(indx);
189.1533 - out.append("stack.push(stack.pop().").append(fi.getFieldName()).append(");");
189.1534 + String[] fi = jc.getFieldInfoName(indx);
189.1535 + final int type = VarType.fromFieldType(fi[2].charAt(0));
189.1536 + emit(out, "var @2 = @1.fld_@3;",
189.1537 + smapper.popA(), smapper.pushT(type), fi[1]);
189.1538 i += 2;
189.1539 break;
189.1540 }
189.1541 - case bc_getstatic: {
189.1542 + case opc_getstatic: {
189.1543 int indx = readIntArg(byteCodes, i);
189.1544 - CPFieldInfo fi = (CPFieldInfo) jc.getConstantPool().get(indx);
189.1545 - final String in = fi.getClassName().getInternalName();
189.1546 - out.append("stack.push(").append(in.replace('/', '_'));
189.1547 - out.append('_').append(fi.getFieldName()).append(");");
189.1548 + String[] fi = jc.getFieldInfoName(indx);
189.1549 + final int type = VarType.fromFieldType(fi[2].charAt(0));
189.1550 + emit(out, "var @1 = @2(false).constructor.@3;",
189.1551 + smapper.pushT(type),
189.1552 + accessClass(fi[0].replace('/', '_')), fi[1]);
189.1553 i += 2;
189.1554 - addReference(in);
189.1555 + addReference(fi[0]);
189.1556 break;
189.1557 }
189.1558 - case bc_putstatic: {
189.1559 + case opc_putfield: {
189.1560 int indx = readIntArg(byteCodes, i);
189.1561 - CPFieldInfo fi = (CPFieldInfo) jc.getConstantPool().get(indx);
189.1562 - final String in = fi.getClassName().getInternalName();
189.1563 - out.append(in.replace('/', '_'));
189.1564 - out.append('_').append(fi.getFieldName()).append(" = stack.pop();");
189.1565 - i += 2;
189.1566 - addReference(in);
189.1567 - break;
189.1568 - }
189.1569 - case bc_putfield: {
189.1570 - int indx = readIntArg(byteCodes, i);
189.1571 - CPFieldInfo fi = (CPFieldInfo) jc.getConstantPool().get(indx);
189.1572 - out.append("{ var v = stack.pop(); stack.pop().")
189.1573 - .append(fi.getFieldName()).append(" = v; }");
189.1574 + String[] fi = jc.getFieldInfoName(indx);
189.1575 + final int type = VarType.fromFieldType(fi[2].charAt(0));
189.1576 + emit(out, "@2.fld_@3 = @1;",
189.1577 + smapper.popT(type), smapper.popA(), fi[1]);
189.1578 i += 2;
189.1579 break;
189.1580 }
189.1581 - case bc_checkcast: {
189.1582 + case opc_putstatic: {
189.1583 int indx = readIntArg(byteCodes, i);
189.1584 - CPClassInfo ci = jc.getConstantPool().getClass(indx);
189.1585 - final String type = ci.getClassName().getType();
189.1586 + String[] fi = jc.getFieldInfoName(indx);
189.1587 + final int type = VarType.fromFieldType(fi[2].charAt(0));
189.1588 + emit(out, "@1(false).constructor.@2 = @3;",
189.1589 + accessClass(fi[0].replace('/', '_')), fi[1],
189.1590 + smapper.popT(type));
189.1591 + i += 2;
189.1592 + addReference(fi[0]);
189.1593 + break;
189.1594 + }
189.1595 + case opc_checkcast: {
189.1596 + int indx = readIntArg(byteCodes, i);
189.1597 + final String type = jc.getClassName(indx);
189.1598 if (!type.startsWith("[")) {
189.1599 // no way to check arrays right now
189.1600 - out.append("if(stack[stack.length - 1].$instOf_")
189.1601 - .append(type.replace('/', '_'))
189.1602 - .append(" != 1) throw {};"); // XXX proper exception
189.1603 + // XXX proper exception
189.1604 + emit(out,
189.1605 + "if (@1 !== null && !@1.$instOf_@2) throw {};",
189.1606 + smapper.getA(0), type.replace('/', '_'));
189.1607 }
189.1608 i += 2;
189.1609 break;
189.1610 }
189.1611 - case bc_instanceof: {
189.1612 + case opc_instanceof: {
189.1613 int indx = readIntArg(byteCodes, i);
189.1614 - CPClassInfo ci = jc.getConstantPool().getClass(indx);
189.1615 - out.append("stack.push(stack.pop().$instOf_")
189.1616 - .append(ci.getClassName().getInternalName().replace('/', '_'))
189.1617 - .append(" ? 1 : 0);");
189.1618 + final String type = jc.getClassName(indx);
189.1619 + emit(out, "var @2 = @1.$instOf_@3 ? 1 : 0;",
189.1620 + smapper.popA(), smapper.pushI(),
189.1621 + type.replace('/', '_'));
189.1622 i += 2;
189.1623 break;
189.1624 }
189.1625 -
189.1626 + case opc_athrow: {
189.1627 + final Variable v = smapper.popA();
189.1628 + smapper.clear();
189.1629 +
189.1630 + emit(out, "{ var @1 = @2; throw @2; }",
189.1631 + smapper.pushA(), v);
189.1632 + break;
189.1633 + }
189.1634 +
189.1635 + case opc_monitorenter: {
189.1636 + out.append("/* monitor enter */");
189.1637 + smapper.popA();
189.1638 + break;
189.1639 + }
189.1640 +
189.1641 + case opc_monitorexit: {
189.1642 + out.append("/* monitor exit */");
189.1643 + smapper.popA();
189.1644 + break;
189.1645 + }
189.1646 +
189.1647 + default: {
189.1648 + emit(out, "throw 'unknown bytecode @1';",
189.1649 + Integer.toString(c));
189.1650 + }
189.1651 }
189.1652 - out.append(" //");
189.1653 - for (int j = prev; j <= i; j++) {
189.1654 - out.append(" ");
189.1655 - final int cc = (byteCodes[j] + 256) % 256;
189.1656 - out.append(Integer.toString(cc));
189.1657 + if (debug(" //")) {
189.1658 + for (int j = prev; j <= i; j++) {
189.1659 + out.append(" ");
189.1660 + final int cc = readByte(byteCodes, j);
189.1661 + out.append(Integer.toString(cc));
189.1662 + }
189.1663 }
189.1664 - out.append("\n");
189.1665 + out.append("\n");
189.1666 + }
189.1667 + if (previousTrap != null) {
189.1668 + generateCatch(previousTrap);
189.1669 }
189.1670 out.append(" }\n");
189.1671 + out.append("};");
189.1672 }
189.1673
189.1674 - private int generateIf(byte[] byteCodes, int i, final String test) throws IOException {
189.1675 + private int generateIf(byte[] byteCodes, int i,
189.1676 + final Variable v2, final Variable v1,
189.1677 + final String test) throws IOException {
189.1678 int indx = i + readIntArg(byteCodes, i);
189.1679 - out.append("if (stack.pop() ").append(test).append(" stack.pop()) { gt = " + indx);
189.1680 - out.append("; continue; }");
189.1681 + out.append("if (").append(v1)
189.1682 + .append(' ').append(test).append(' ')
189.1683 + .append(v2).append(") { gt = " + indx)
189.1684 + .append("; continue; }");
189.1685 return i + 2;
189.1686 }
189.1687
189.1688 @@ -701,12 +1182,22 @@
189.1689 final int indxLo = byteCodes[offsetInstruction + 2];
189.1690 return (indxHi & 0xffffff00) | (indxLo & 0xff);
189.1691 }
189.1692 + private int readInt4(byte[] byteCodes, int offsetInstruction) {
189.1693 + final int d = byteCodes[offsetInstruction + 0] << 24;
189.1694 + final int c = byteCodes[offsetInstruction + 1] << 16;
189.1695 + final int b = byteCodes[offsetInstruction + 2] << 8;
189.1696 + final int a = byteCodes[offsetInstruction + 3];
189.1697 + return (d & 0xff000000) | (c & 0xff0000) | (b & 0xff00) | (a & 0xff);
189.1698 + }
189.1699 + private int readByte(byte[] byteCodes, int offsetInstruction) {
189.1700 + return byteCodes[offsetInstruction] & 0xff;
189.1701 + }
189.1702
189.1703 - private static int countArgs(String descriptor, boolean[] hasReturnType, StringBuilder sig) {
189.1704 - int cnt = 0;
189.1705 + private static void countArgs(String descriptor, char[] returnType, StringBuilder sig, StringBuilder cnt) {
189.1706 int i = 0;
189.1707 Boolean count = null;
189.1708 boolean array = false;
189.1709 + sig.append("__");
189.1710 int firstPos = sig.length();
189.1711 while (i < descriptor.length()) {
189.1712 char ch = descriptor.charAt(i++);
189.1713 @@ -717,9 +1208,6 @@
189.1714 case ')':
189.1715 count = false;
189.1716 continue;
189.1717 - case 'A':
189.1718 - array = true;
189.1719 - break;
189.1720 case 'B':
189.1721 case 'C':
189.1722 case 'D':
189.1723 @@ -729,63 +1217,76 @@
189.1724 case 'S':
189.1725 case 'Z':
189.1726 if (count) {
189.1727 - cnt++;
189.1728 if (array) {
189.1729 - sig.append('A');
189.1730 + sig.append("_3");
189.1731 }
189.1732 sig.append(ch);
189.1733 + if (ch == 'J' || ch == 'D') {
189.1734 + cnt.append('1');
189.1735 + } else {
189.1736 + cnt.append('0');
189.1737 + }
189.1738 } else {
189.1739 - hasReturnType[0] = true;
189.1740 sig.insert(firstPos, ch);
189.1741 if (array) {
189.1742 - sig.insert(firstPos, 'A');
189.1743 + returnType[0] = '[';
189.1744 + sig.insert(firstPos, "_3");
189.1745 + } else {
189.1746 + returnType[0] = ch;
189.1747 }
189.1748 }
189.1749 array = false;
189.1750 continue;
189.1751 case 'V':
189.1752 assert !count;
189.1753 - hasReturnType[0] = false;
189.1754 + returnType[0] = 'V';
189.1755 sig.insert(firstPos, 'V');
189.1756 continue;
189.1757 case 'L':
189.1758 int next = descriptor.indexOf(';', i);
189.1759 + String realSig = mangleSig(descriptor, i - 1, next + 1);
189.1760 if (count) {
189.1761 - cnt++;
189.1762 if (array) {
189.1763 - sig.append('A');
189.1764 + sig.append("_3");
189.1765 }
189.1766 - sig.append(ch);
189.1767 - sig.append(descriptor.substring(i, next).replace('/', '_'));
189.1768 + sig.append(realSig);
189.1769 + cnt.append('0');
189.1770 } else {
189.1771 - sig.insert(firstPos, descriptor.substring(i, next).replace('/', '_'));
189.1772 - sig.insert(firstPos, ch);
189.1773 + sig.insert(firstPos, realSig);
189.1774 if (array) {
189.1775 - sig.insert(firstPos, 'A');
189.1776 + sig.insert(firstPos, "_3");
189.1777 }
189.1778 - hasReturnType[0] = true;
189.1779 + returnType[0] = 'L';
189.1780 }
189.1781 i = next + 1;
189.1782 + array = false;
189.1783 continue;
189.1784 case '[':
189.1785 - //arrays++;
189.1786 + array = true;
189.1787 continue;
189.1788 default:
189.1789 - break; // invalid character
189.1790 + throw new IllegalStateException("Invalid char: " + ch);
189.1791 }
189.1792 }
189.1793 - return cnt;
189.1794 + }
189.1795 +
189.1796 + private static String mangleSig(String txt, int first, int last) {
189.1797 + StringBuilder sb = new StringBuilder();
189.1798 + for (int i = first; i < last; i++) {
189.1799 + final char ch = txt.charAt(i);
189.1800 + switch (ch) {
189.1801 + case '/': sb.append('_'); break;
189.1802 + case '_': sb.append("_1"); break;
189.1803 + case ';': sb.append("_2"); break;
189.1804 + case '[': sb.append("_3"); break;
189.1805 + default: sb.append(ch); break;
189.1806 + }
189.1807 + }
189.1808 + return sb.toString();
189.1809 }
189.1810
189.1811 - private void generateStaticField(Variable v) throws IOException {
189.1812 - out.append("\nvar ")
189.1813 - .append(jc.getName().getInternalName().replace('/', '_'))
189.1814 - .append('_').append(v.getName()).append(" = 0;");
189.1815 - }
189.1816 -
189.1817 - private String findMethodName(Method m) {
189.1818 + private static String findMethodName(MethodData m, StringBuilder cnt) {
189.1819 StringBuilder name = new StringBuilder();
189.1820 - String descr = m.getDescriptor();
189.1821 if ("<init>".equals(m.getName())) { // NOI18N
189.1822 name.append("cons"); // NOI18N
189.1823 } else if ("<clinit>".equals(m.getName())) { // NOI18N
189.1824 @@ -794,97 +1295,106 @@
189.1825 name.append(m.getName());
189.1826 }
189.1827
189.1828 - boolean hasReturn[] = { false };
189.1829 - countArgs(findDescriptor(m.getDescriptor()), hasReturn, name);
189.1830 + countArgs(m.getInternalSig(), new char[1], name, cnt);
189.1831 return name.toString();
189.1832 }
189.1833
189.1834 - private String findMethodName(CPMethodInfo mi, int[] cnt, boolean[] hasReturn) {
189.1835 + static String findMethodName(String[] mi, StringBuilder cnt, char[] returnType) {
189.1836 StringBuilder name = new StringBuilder();
189.1837 - String descr = mi.getDescriptor();
189.1838 - if ("<init>".equals(mi.getName())) { // NOI18N
189.1839 + String descr = mi[2];//mi.getDescriptor();
189.1840 + String nm= mi[1];
189.1841 + if ("<init>".equals(nm)) { // NOI18N
189.1842 name.append("cons"); // NOI18N
189.1843 } else {
189.1844 - name.append(mi.getName());
189.1845 + name.append(nm);
189.1846 }
189.1847 - cnt[0] = countArgs(findDescriptor(mi.getDescriptor()), hasReturn, name);
189.1848 + countArgs(descr, returnType, name, cnt);
189.1849 return name.toString();
189.1850 }
189.1851
189.1852 - private int invokeStaticMethod(byte[] byteCodes, int i, boolean isStatic)
189.1853 + private int invokeStaticMethod(byte[] byteCodes, int i, final StackMapper mapper, boolean isStatic)
189.1854 throws IOException {
189.1855 int methodIndex = readIntArg(byteCodes, i);
189.1856 - CPMethodInfo mi = (CPMethodInfo) jc.getConstantPool().get(methodIndex);
189.1857 - boolean[] hasReturn = { false };
189.1858 - int[] cnt = { 0 };
189.1859 - String mn = findMethodName(mi, cnt, hasReturn);
189.1860 - out.append("{ ");
189.1861 - for (int j = cnt[0] - 1; j >= 0; j--) {
189.1862 - out.append("var v" + j).append(" = stack.pop(); ");
189.1863 + String[] mi = jc.getFieldInfoName(methodIndex);
189.1864 + char[] returnType = { 'V' };
189.1865 + StringBuilder cnt = new StringBuilder();
189.1866 + String mn = findMethodName(mi, cnt, returnType);
189.1867 +
189.1868 + final int numArguments = isStatic ? cnt.length() : cnt.length() + 1;
189.1869 + final Variable[] vars = new Variable[numArguments];
189.1870 +
189.1871 + for (int j = numArguments - 1; j >= 0; --j) {
189.1872 + vars[j] = mapper.pop();
189.1873 }
189.1874 -
189.1875 - if (hasReturn[0]) {
189.1876 - out.append("stack.push(");
189.1877 +
189.1878 + if (returnType[0] != 'V') {
189.1879 + out.append("var ")
189.1880 + .append(mapper.pushT(VarType.fromFieldType(returnType[0])))
189.1881 + .append(" = ");
189.1882 }
189.1883 - final String in = mi.getClassName().getInternalName();
189.1884 - out.append(in.replace('/', '_'));
189.1885 - out.append('_');
189.1886 +
189.1887 + final String in = mi[0];
189.1888 + out.append(accessClass(in.replace('/', '_')));
189.1889 + out.append("(false).");
189.1890 + if (mn.startsWith("cons_")) {
189.1891 + out.append("constructor.");
189.1892 + }
189.1893 out.append(mn);
189.1894 - out.append('(');
189.1895 - String sep = "";
189.1896 - if (!isStatic) {
189.1897 - out.append("stack.pop()");
189.1898 - sep = ", ";
189.1899 + if (isStatic) {
189.1900 + out.append('(');
189.1901 + } else {
189.1902 + out.append(".call(");
189.1903 }
189.1904 - for (int j = 0; j < cnt[0]; j++) {
189.1905 - out.append(sep);
189.1906 - out.append("v" + j);
189.1907 - sep = ", ";
189.1908 + if (numArguments > 0) {
189.1909 + out.append(vars[0]);
189.1910 + for (int j = 1; j < numArguments; ++j) {
189.1911 + out.append(", ");
189.1912 + out.append(vars[j]);
189.1913 + }
189.1914 }
189.1915 - out.append(")");
189.1916 - if (hasReturn[0]) {
189.1917 - out.append(")");
189.1918 - }
189.1919 - out.append("; }");
189.1920 + out.append(");");
189.1921 i += 2;
189.1922 addReference(in);
189.1923 return i;
189.1924 }
189.1925 - private int invokeVirtualMethod(byte[] byteCodes, int i)
189.1926 + private int invokeVirtualMethod(byte[] byteCodes, int i, final StackMapper mapper)
189.1927 throws IOException {
189.1928 int methodIndex = readIntArg(byteCodes, i);
189.1929 - CPMethodInfo mi = (CPMethodInfo) jc.getConstantPool().get(methodIndex);
189.1930 - boolean[] hasReturn = { false };
189.1931 - int[] cnt = { 0 };
189.1932 - String mn = findMethodName(mi, cnt, hasReturn);
189.1933 - out.append("{ ");
189.1934 - for (int j = cnt[0] - 1; j >= 0; j--) {
189.1935 - out.append("var v" + j).append(" = stack.pop(); ");
189.1936 + String[] mi = jc.getFieldInfoName(methodIndex);
189.1937 + char[] returnType = { 'V' };
189.1938 + StringBuilder cnt = new StringBuilder();
189.1939 + String mn = findMethodName(mi, cnt, returnType);
189.1940 +
189.1941 + final int numArguments = cnt.length() + 1;
189.1942 + final Variable[] vars = new Variable[numArguments];
189.1943 +
189.1944 + for (int j = numArguments - 1; j >= 0; --j) {
189.1945 + vars[j] = mapper.pop();
189.1946 }
189.1947 - out.append("var self = stack.pop(); ");
189.1948 - if (hasReturn[0]) {
189.1949 - out.append("stack.push(");
189.1950 +
189.1951 + if (returnType[0] != 'V') {
189.1952 + out.append("var ")
189.1953 + .append(mapper.pushT(VarType.fromFieldType(returnType[0])))
189.1954 + .append(" = ");
189.1955 }
189.1956 - out.append("self.");
189.1957 +
189.1958 + out.append(vars[0]).append('.');
189.1959 out.append(mn);
189.1960 out.append('(');
189.1961 - out.append("self");
189.1962 - for (int j = 0; j < cnt[0]; j++) {
189.1963 - out.append(", ");
189.1964 - out.append("v" + j);
189.1965 + String sep = "";
189.1966 + for (int j = 1; j < numArguments; ++j) {
189.1967 + out.append(sep);
189.1968 + out.append(vars[j]);
189.1969 + sep = ", ";
189.1970 }
189.1971 - out.append(")");
189.1972 - if (hasReturn[0]) {
189.1973 - out.append(")");
189.1974 - }
189.1975 - out.append("; }");
189.1976 + out.append(");");
189.1977 i += 2;
189.1978 return i;
189.1979 }
189.1980 -
189.1981 - private void addReference(String cn) {
189.1982 - if (references != null) {
189.1983 - references.add(cn);
189.1984 +
189.1985 + private void addReference(String cn) throws IOException {
189.1986 + if (requireReference(cn)) {
189.1987 + debug(" /* needs " + cn + " */");
189.1988 }
189.1989 }
189.1990
189.1991 @@ -902,61 +1412,220 @@
189.1992 }
189.1993 }
189.1994
189.1995 - private String encodeConstant(CPEntry entry) {
189.1996 - final String v;
189.1997 - if (entry instanceof CPClassInfo) {
189.1998 - v = "new java_lang_Class";
189.1999 - } else if (entry instanceof CPStringInfo) {
189.2000 - v = "\"" + entry.getValue().toString().replace("\"", "\\\"") + "\"";
189.2001 - } else {
189.2002 - v = entry.getValue().toString();
189.2003 + private String encodeConstant(int entryIndex) throws IOException {
189.2004 + String[] classRef = { null };
189.2005 + String s = jc.stringValue(entryIndex, classRef);
189.2006 + if (classRef[0] != null) {
189.2007 + addReference(classRef[0]);
189.2008 + s = accessClass(s.replace('/', '_')) + "(false).constructor.$class";
189.2009 }
189.2010 - return v;
189.2011 + return s;
189.2012 }
189.2013
189.2014 - private String findDescriptor(String d) {
189.2015 - return d.replace('[', 'A');
189.2016 + private String javaScriptBody(String prefix, MethodData m, boolean isStatic) throws IOException {
189.2017 + byte[] arr = m.findAnnotationData(true);
189.2018 + if (arr == null) {
189.2019 + return null;
189.2020 + }
189.2021 + final String jvmType = "Lorg/apidesign/bck2brwsr/core/JavaScriptBody;";
189.2022 + class P extends AnnotationParser {
189.2023 + public P() {
189.2024 + super(false);
189.2025 + }
189.2026 +
189.2027 + int cnt;
189.2028 + String[] args = new String[30];
189.2029 + String body;
189.2030 +
189.2031 + @Override
189.2032 + protected void visitAttr(String type, String attr, String at, String value) {
189.2033 + if (type.equals(jvmType)) {
189.2034 + if ("body".equals(attr)) {
189.2035 + body = value;
189.2036 + } else if ("args".equals(attr)) {
189.2037 + args[cnt++] = value;
189.2038 + } else {
189.2039 + throw new IllegalArgumentException(attr);
189.2040 + }
189.2041 + }
189.2042 + }
189.2043 + }
189.2044 + P p = new P();
189.2045 + p.parse(arr, jc);
189.2046 + if (p.body == null) {
189.2047 + return null;
189.2048 + }
189.2049 + StringBuilder cnt = new StringBuilder();
189.2050 + final String mn = findMethodName(m, cnt);
189.2051 + out.append(prefix).append(mn);
189.2052 + out.append(" = function(");
189.2053 + String space = "";
189.2054 + int index = 0;
189.2055 + for (int i = 0; i < cnt.length(); i++) {
189.2056 + out.append(space);
189.2057 + space = outputArg(out, p.args, index);
189.2058 + index++;
189.2059 + }
189.2060 + out.append(") {").append("\n");
189.2061 + out.append(p.body);
189.2062 + out.append("\n}\n");
189.2063 + return mn;
189.2064 + }
189.2065 + private static String className(ClassData jc) {
189.2066 + //return jc.getName().getInternalName().replace('/', '_');
189.2067 + return jc.getClassName().replace('/', '_');
189.2068 + }
189.2069 +
189.2070 + private static String[] findAnnotation(
189.2071 + byte[] arr, ClassData cd, final String className,
189.2072 + final String... attrNames
189.2073 + ) throws IOException {
189.2074 + if (arr == null) {
189.2075 + return null;
189.2076 + }
189.2077 + final String[] values = new String[attrNames.length];
189.2078 + final boolean[] found = { false };
189.2079 + final String jvmType = "L" + className.replace('.', '/') + ";";
189.2080 + AnnotationParser ap = new AnnotationParser(false) {
189.2081 + @Override
189.2082 + protected void visitAttr(String type, String attr, String at, String value) {
189.2083 + if (type.equals(jvmType)) {
189.2084 + found[0] = true;
189.2085 + for (int i = 0; i < attrNames.length; i++) {
189.2086 + if (attrNames[i].equals(attr)) {
189.2087 + values[i] = value;
189.2088 + }
189.2089 + }
189.2090 + }
189.2091 + }
189.2092 +
189.2093 + };
189.2094 + ap.parse(arr, cd);
189.2095 + return found[0] ? values : null;
189.2096 }
189.2097
189.2098 - private boolean javaScriptBody(Method m, boolean isStatic) throws IOException {
189.2099 - final ClassName extraAnn = ClassName.getClassName(JavaScriptBody.class.getName().replace('.', '/'));
189.2100 - Annotation a = m.getAnnotation(extraAnn);
189.2101 - if (a != null) {
189.2102 - final ElementValue annVal = a.getComponent("body").getValue();
189.2103 - String body = ((PrimitiveElementValue) annVal).getValue().getValue().toString();
189.2104 + private CharSequence initField(FieldData v) {
189.2105 + final String is = v.getInternalSig();
189.2106 + if (is.length() == 1) {
189.2107 + switch (is.charAt(0)) {
189.2108 + case 'S':
189.2109 + case 'J':
189.2110 + case 'B':
189.2111 + case 'Z':
189.2112 + case 'C':
189.2113 + case 'I': return " = 0;";
189.2114 + case 'F':
189.2115 + case 'D': return " = 0.0;";
189.2116 + default:
189.2117 + throw new IllegalStateException(is);
189.2118 + }
189.2119 + }
189.2120 + return " = null;";
189.2121 + }
189.2122 +
189.2123 + private static void generateAnno(ClassData cd, final Appendable out, byte[] data) throws IOException {
189.2124 + AnnotationParser ap = new AnnotationParser(true) {
189.2125 + int anno;
189.2126 + int cnt;
189.2127
189.2128 - final ArrayElementValue arrVal = (ArrayElementValue) a.getComponent("args").getValue();
189.2129 - final int len = arrVal.getValues().length;
189.2130 - String[] names = new String[len];
189.2131 - for (int i = 0; i < len; i++) {
189.2132 - names[i] = ((PrimitiveElementValue) arrVal.getValues()[i]).getValue().getValue().toString();
189.2133 + @Override
189.2134 + protected void visitAnnotationStart(String type) throws IOException {
189.2135 + if (anno++ > 0) {
189.2136 + out.append(",");
189.2137 + }
189.2138 + out.append('"').append(type).append("\" : {\n");
189.2139 + cnt = 0;
189.2140 }
189.2141 - out.append("\nfunction ").append(
189.2142 - jc.getName().getInternalName().replace('/', '_')).append('_').append(findMethodName(m));
189.2143 - out.append("(");
189.2144 - String space;
189.2145 - int index;
189.2146 - if (!isStatic) {
189.2147 - out.append(names[0]);
189.2148 - space = ",";
189.2149 - index = 1;
189.2150 +
189.2151 + @Override
189.2152 + protected void visitAnnotationEnd(String type) throws IOException {
189.2153 + out.append("\n}\n");
189.2154 + }
189.2155 +
189.2156 + @Override
189.2157 + protected void visitAttr(String type, String attr, String attrType, String value)
189.2158 + throws IOException {
189.2159 + if (attr == null) {
189.2160 + return;
189.2161 + }
189.2162 + if (cnt++ > 0) {
189.2163 + out.append(",\n");
189.2164 + }
189.2165 + out.append(attr).append("__").append(attrType).append(" : ").append(value);
189.2166 + }
189.2167 + };
189.2168 + ap.parse(data, cd);
189.2169 + }
189.2170 +
189.2171 + private static String outputArg(Appendable out, String[] args, int indx) throws IOException {
189.2172 + final String name = args[indx];
189.2173 + if (name == null) {
189.2174 + return "";
189.2175 + }
189.2176 + if (name.contains(",")) {
189.2177 + throw new IOException("Wrong parameter with ',': " + name);
189.2178 + }
189.2179 + out.append(name);
189.2180 + return ",";
189.2181 + }
189.2182 +
189.2183 + private static void emit(final Appendable out,
189.2184 + final String format,
189.2185 + final CharSequence... params) throws IOException {
189.2186 + final int length = format.length();
189.2187 +
189.2188 + int processed = 0;
189.2189 + int paramOffset = format.indexOf('@');
189.2190 + while ((paramOffset != -1) && (paramOffset < (length - 1))) {
189.2191 + final char paramChar = format.charAt(paramOffset + 1);
189.2192 + if ((paramChar >= '1') && (paramChar <= '9')) {
189.2193 + final int paramIndex = paramChar - '0' - 1;
189.2194 +
189.2195 + out.append(format, processed, paramOffset);
189.2196 + out.append(params[paramIndex]);
189.2197 +
189.2198 + ++paramOffset;
189.2199 + processed = paramOffset + 1;
189.2200 + }
189.2201 +
189.2202 + paramOffset = format.indexOf('@', paramOffset + 1);
189.2203 + }
189.2204 +
189.2205 + out.append(format, processed, length);
189.2206 + }
189.2207 +
189.2208 + private void generateCatch(TrapData[] traps) throws IOException {
189.2209 + out.append("} catch (e) {\n");
189.2210 + int finallyPC = -1;
189.2211 + for (TrapData e : traps) {
189.2212 + if (e == null) {
189.2213 + break;
189.2214 + }
189.2215 + if (e.catch_cpx != 0) { //not finally
189.2216 + final String classInternalName = jc.getClassName(e.catch_cpx);
189.2217 + addReference(classInternalName);
189.2218 + if ("java/lang/Throwable".equals(classInternalName)) {
189.2219 + out.append("if (e.$instOf_java_lang_Throwable) {");
189.2220 + out.append(" var stA0 = e;");
189.2221 + out.append("} else {");
189.2222 + out.append(" var stA0 = vm.java_lang_Throwable(true);");
189.2223 + out.append(" vm.java_lang_Throwable.cons__VLjava_lang_String_2.call(stA0, e.toString());");
189.2224 + out.append("}");
189.2225 + out.append("gt=" + e.handler_pc + "; continue;");
189.2226 + } else {
189.2227 + out.append("if (e.$instOf_" + classInternalName.replace('/', '_') + ") {");
189.2228 + out.append("gt=" + e.handler_pc + "; var stA0 = e; continue;");
189.2229 + out.append("}\n");
189.2230 + }
189.2231 } else {
189.2232 - space = "";
189.2233 - index = 0;
189.2234 + finallyPC = e.handler_pc;
189.2235 }
189.2236 - List<Parameter> args = m.getParameters();
189.2237 - for (int i = 0; i < args.size(); i++) {
189.2238 - out.append(space);
189.2239 - out.append(names[index]);
189.2240 - final String desc = findDescriptor(args.get(i).getDescriptor());
189.2241 - index++;
189.2242 - space = ",";
189.2243 - }
189.2244 - out.append(") {").append("\n");
189.2245 - out.append(body);
189.2246 - out.append("\n}\n");
189.2247 - return true;
189.2248 }
189.2249 - return false;
189.2250 + if (finallyPC == -1) {
189.2251 + out.append("throw e;");
189.2252 + } else {
189.2253 + out.append("gt=" + finallyPC + "; var stA0 = e; continue;");
189.2254 + }
189.2255 + out.append("\n}");
189.2256 }
189.2257 }
190.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/GenJS.java Thu Oct 11 06:15:22 2012 -0700
190.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
190.3 @@ -1,179 +0,0 @@
190.4 -package org.apidesign.vm4brwsr;
190.5 -
190.6 -import java.io.BufferedWriter;
190.7 -import java.io.FileWriter;
190.8 -import java.io.IOException;
190.9 -import java.io.InputStream;
190.10 -import java.io.Writer;
190.11 -import java.net.URL;
190.12 -import java.util.Arrays;
190.13 -import java.util.Collections;
190.14 -import java.util.Enumeration;
190.15 -import java.util.HashMap;
190.16 -import java.util.Iterator;
190.17 -import java.util.LinkedList;
190.18 -import java.util.List;
190.19 -import java.util.Map;
190.20 -
190.21 -/** Generator of JavaScript from bytecode of classes on classpath of the VM.
190.22 - *
190.23 - * @author Jaroslav Tulach <jtulach@netbeans.org>
190.24 - */
190.25 -final class GenJS {
190.26 - private GenJS() {}
190.27 -
190.28 - public static void main(String... args) throws IOException {
190.29 - if (args.length < 2) {
190.30 - System.err.println("Usage: java -cp ... -jar ... <file_to_generate_js_code_to> java/lang/Class org/your/App ...");
190.31 - return;
190.32 - }
190.33 -
190.34 - Writer w = new BufferedWriter(new FileWriter(args[0]));
190.35 - List<String> classes = Arrays.asList(args).subList(1, args.length);
190.36 - compile(w, classes);
190.37 - w.close();
190.38 - }
190.39 -
190.40 - static void compile(Appendable out, String... names) throws IOException {
190.41 - compile(out, Arrays.asList(names));
190.42 - }
190.43 - static void compile(Appendable out, List<String> names) throws IOException {
190.44 - for (String baseClass : names) {
190.45 - Map<String,String> processed = new HashMap<String, String>();
190.46 - LinkedList<String> toProcess = new LinkedList<String>();
190.47 - toProcess.add(baseClass);
190.48 - for (;;) {
190.49 - String name = null;
190.50 - Iterator<String> it = toProcess.iterator();
190.51 - while (it.hasNext() && name == null) {
190.52 - String n = it.next();
190.53 - if (processed.get(n) != null) {
190.54 - continue;
190.55 - }
190.56 - name = n;
190.57 - }
190.58 - if (name == null) {
190.59 - break;
190.60 - }
190.61 - if (name.startsWith("java/")
190.62 - && !name.equals("java/lang/Object")
190.63 - && !name.equals("java/lang/Class")
190.64 - && !name.equals("java/lang/Number")
190.65 - && !name.equals("java/lang/Integer")
190.66 - && !name.equals("java/lang/Throwable")
190.67 - && !name.equals("java/lang/Exception")
190.68 - && !name.equals("java/lang/RuntimeException")
190.69 - && !name.equals("java/lang/UnsupportedOperationException")
190.70 - && !name.equals("java/lang/String")
190.71 - && !name.equals("java/lang/String$CaseInsensitiveComparator")
190.72 - && !name.equals("java/lang/StringBuilder")
190.73 - && !name.equals("java/lang/AbstractStringBuilder")
190.74 - ) {
190.75 - processed.put(name, "");
190.76 - continue;
190.77 - }
190.78 - InputStream is = loadClass(name);
190.79 - if (is == null) {
190.80 - throw new IOException("Can't find class " + name);
190.81 - }
190.82 - LinkedList<String> scripts = new LinkedList<String>();
190.83 - try {
190.84 - String initCode = ByteCodeToJavaScript.compile(is, out, toProcess, scripts);
190.85 - processed.put(name, initCode == null ? "" : initCode);
190.86 - } catch (RuntimeException ex) {
190.87 - if (out instanceof CharSequence) {
190.88 - CharSequence seq = (CharSequence)out;
190.89 - int lastBlock = seq.length();
190.90 - while (lastBlock-- >= 0) {
190.91 - if (seq.charAt(lastBlock) == '{') {
190.92 - break;
190.93 - }
190.94 - }
190.95 - throw new IOException("Error while compiling " + name + "\n"
190.96 - + seq.subSequence(lastBlock + 1, seq.length()), ex
190.97 - );
190.98 - } else {
190.99 - throw new IOException("Error while compiling " + name + "\n"
190.100 - + out, ex
190.101 - );
190.102 - }
190.103 - }
190.104 - for (String resource : scripts) {
190.105 - InputStream emul = GenJS.class.getResourceAsStream(resource);
190.106 - if (emul == null) {
190.107 - throw new IOException("Can't find " + resource);
190.108 - }
190.109 - readResource(emul, out);
190.110 - }
190.111 - }
190.112 -
190.113 - Collections.reverse(toProcess);
190.114 -
190.115 - for (String clazz : toProcess) {
190.116 - String initCode = processed.remove(clazz);
190.117 - if (initCode != null) {
190.118 - out.append(initCode).append("\n");
190.119 - }
190.120 - }
190.121 - }
190.122 -
190.123 - }
190.124 - private static void readResource(InputStream emul, Appendable out) throws IOException {
190.125 - try {
190.126 - int state = 0;
190.127 - for (;;) {
190.128 - int ch = emul.read();
190.129 - if (ch == -1) {
190.130 - break;
190.131 - }
190.132 - if (ch < 0 || ch > 255) {
190.133 - throw new IOException("Invalid char in emulation " + ch);
190.134 - }
190.135 - switch (state) {
190.136 - case 0:
190.137 - if (ch == '/') {
190.138 - state = 1;
190.139 - } else {
190.140 - out.append((char)ch);
190.141 - }
190.142 - break;
190.143 - case 1:
190.144 - if (ch == '*') {
190.145 - state = 2;
190.146 - } else {
190.147 - out.append('/').append((char)ch);
190.148 - state = 0;
190.149 - }
190.150 - break;
190.151 - case 2:
190.152 - if (ch == '*') {
190.153 - state = 3;
190.154 - }
190.155 - break;
190.156 - case 3:
190.157 - if (ch == '/') {
190.158 - state = 0;
190.159 - } else {
190.160 - state = 2;
190.161 - }
190.162 - break;
190.163 - }
190.164 - }
190.165 - } finally {
190.166 - emul.close();
190.167 - }
190.168 - }
190.169 -
190.170 - private static InputStream loadClass(String name) throws IOException {
190.171 - Enumeration<URL> en = ClassLoader.getSystemClassLoader().getResources(name + ".class");
190.172 - URL u = null;
190.173 - while (en.hasMoreElements()) {
190.174 - u = en.nextElement();
190.175 - }
190.176 - if (u == null) {
190.177 - throw new IOException("Can't find " + name);
190.178 - }
190.179 - return u.openStream();
190.180 - }
190.181 -
190.182 -}
191.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
191.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/LocalsMapper.java Wed Jan 23 20:16:48 2013 +0100
191.3 @@ -0,0 +1,142 @@
191.4 +/**
191.5 + * Back 2 Browser Bytecode Translator
191.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
191.7 + *
191.8 + * This program is free software: you can redistribute it and/or modify
191.9 + * it under the terms of the GNU General Public License as published by
191.10 + * the Free Software Foundation, version 2 of the License.
191.11 + *
191.12 + * This program is distributed in the hope that it will be useful,
191.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
191.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
191.15 + * GNU General Public License for more details.
191.16 + *
191.17 + * You should have received a copy of the GNU General Public License
191.18 + * along with this program. Look for COPYING file in the top folder.
191.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
191.20 + */
191.21 +package org.apidesign.vm4brwsr;
191.22 +
191.23 +import java.io.IOException;
191.24 +import org.apidesign.javap.RuntimeConstants;
191.25 +import org.apidesign.javap.TypeArray;
191.26 +
191.27 +final class LocalsMapper {
191.28 + private final TypeArray argTypeRecords;
191.29 + private final TypeArray localTypeRecords;
191.30 +
191.31 + public LocalsMapper(final TypeArray stackMapArgs) {
191.32 + final TypeArray initTypeRecords = new TypeArray();
191.33 + updateRecords(initTypeRecords, stackMapArgs);
191.34 +
191.35 + argTypeRecords = initTypeRecords;
191.36 + localTypeRecords = new TypeArray(initTypeRecords);
191.37 + }
191.38 +
191.39 + public void outputArguments(final Appendable out, boolean isStatic) throws IOException {
191.40 + final int argRecordCount = argTypeRecords.getSize();
191.41 + int first = isStatic ? 0 : 1;
191.42 + if (argRecordCount > first) {
191.43 + Variable variable = getVariable(argTypeRecords, first);
191.44 + out.append(variable);
191.45 +
191.46 + int i = first + (variable.isCategory2() ? 2 : 1);
191.47 + while (i < argRecordCount) {
191.48 + variable = getVariable(argTypeRecords, i);
191.49 + out.append(", ");
191.50 + out.append(variable);
191.51 + i += variable.isCategory2() ? 2 : 1;
191.52 + }
191.53 + }
191.54 + }
191.55 +
191.56 + public void syncWithFrameLocals(final TypeArray frameLocals) {
191.57 + updateRecords(localTypeRecords, frameLocals);
191.58 + }
191.59 +
191.60 + public Variable setI(final int index) {
191.61 + return setT(index, VarType.INTEGER);
191.62 + }
191.63 +
191.64 + public Variable setL(final int index) {
191.65 + return setT(index, VarType.LONG);
191.66 + }
191.67 +
191.68 + public Variable setF(final int index) {
191.69 + return setT(index, VarType.FLOAT);
191.70 + }
191.71 +
191.72 + public Variable setD(final int index) {
191.73 + return setT(index, VarType.DOUBLE);
191.74 + }
191.75 +
191.76 + public Variable setA(final int index) {
191.77 + return setT(index, VarType.REFERENCE);
191.78 + }
191.79 +
191.80 + public Variable setT(final int index, final int type) {
191.81 + updateRecord(localTypeRecords, index, type);
191.82 + return Variable.getLocalVariable(type, index);
191.83 + }
191.84 +
191.85 + public Variable getI(final int index) {
191.86 + return getT(index, VarType.INTEGER);
191.87 + }
191.88 +
191.89 + public Variable getL(final int index) {
191.90 + return getT(index, VarType.LONG);
191.91 + }
191.92 +
191.93 + public Variable getF(final int index) {
191.94 + return getT(index, VarType.FLOAT);
191.95 + }
191.96 +
191.97 + public Variable getD(final int index) {
191.98 + return getT(index, VarType.DOUBLE);
191.99 + }
191.100 +
191.101 + public Variable getA(final int index) {
191.102 + return getT(index, VarType.REFERENCE);
191.103 + }
191.104 +
191.105 + public Variable getT(final int index, final int type) {
191.106 + final int oldRecordValue = localTypeRecords.get(index);
191.107 + if ((oldRecordValue & 0xff) != type) {
191.108 + throw new IllegalStateException("Type mismatch");
191.109 + }
191.110 +
191.111 + return Variable.getLocalVariable(type, index);
191.112 + }
191.113 +
191.114 + private static void updateRecords(final TypeArray typeRecords,
191.115 + final TypeArray stackMapTypes) {
191.116 + final int srcSize = stackMapTypes.getSize();
191.117 + for (int i = 0, dstIndex = 0; i < srcSize; ++i) {
191.118 + final int smType = stackMapTypes.get(i);
191.119 + if (smType == RuntimeConstants.ITEM_Bogus) {
191.120 + ++dstIndex;
191.121 + continue;
191.122 + }
191.123 + final int varType = VarType.fromStackMapType(smType);
191.124 + updateRecord(typeRecords, dstIndex, varType);
191.125 + dstIndex += VarType.isCategory2(varType) ? 2 : 1;
191.126 + }
191.127 + }
191.128 +
191.129 + private static void updateRecord(final TypeArray typeRecords,
191.130 + final int index, final int type) {
191.131 + if (typeRecords.getSize() < (index + 1)) {
191.132 + typeRecords.setSize(index + 1);
191.133 + }
191.134 +
191.135 + final int oldRecordValue = typeRecords.get(index);
191.136 + final int usedTypesMask =
191.137 + (oldRecordValue >> 8) | (1 << type);
191.138 + typeRecords.set(index, (usedTypesMask << 8) | type);
191.139 + }
191.140 +
191.141 + private static Variable getVariable(final TypeArray typeRecords,
191.142 + final int index) {
191.143 + return Variable.getLocalVariable(typeRecords.get(index) & 0xff, index);
191.144 + }
191.145 +}
192.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
192.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/Main.java Wed Jan 23 20:16:48 2013 +0100
192.3 @@ -0,0 +1,50 @@
192.4 +/**
192.5 + * Back 2 Browser Bytecode Translator
192.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
192.7 + *
192.8 + * This program is free software: you can redistribute it and/or modify
192.9 + * it under the terms of the GNU General Public License as published by
192.10 + * the Free Software Foundation, version 2 of the License.
192.11 + *
192.12 + * This program is distributed in the hope that it will be useful,
192.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
192.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
192.15 + * GNU General Public License for more details.
192.16 + *
192.17 + * You should have received a copy of the GNU General Public License
192.18 + * along with this program. Look for COPYING file in the top folder.
192.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
192.20 + */
192.21 +package org.apidesign.vm4brwsr;
192.22 +
192.23 +import java.io.BufferedWriter;
192.24 +import java.io.FileWriter;
192.25 +import java.io.IOException;
192.26 +import java.io.Writer;
192.27 +
192.28 +/** Generator of JavaScript from bytecode of classes on classpath of the VM
192.29 + * with a Main method.
192.30 + *
192.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
192.32 + */
192.33 +final class Main {
192.34 + private Main() {}
192.35 +
192.36 + public static void main(String... args) throws IOException {
192.37 + if (args.length < 2) {
192.38 + System.err.println("Bck2Brwsr Translator from Java(tm) to JavaScript, (c) Jaroslav Tulach 2012");
192.39 + System.err.println("Usage: java -cp ... -jar ... <file_to_generate_js_code_to> java/lang/Class org/your/App ...");
192.40 + return;
192.41 + }
192.42 +
192.43 + Writer w = new BufferedWriter(new FileWriter(args[0]));
192.44 + StringArray classes = StringArray.asList(args);
192.45 + classes.delete(0);
192.46 + try {
192.47 + Bck2Brwsr.generate(w, Main.class.getClassLoader(),
192.48 + classes.toArray());
192.49 + } finally {
192.50 + w.close();
192.51 + }
192.52 + }
192.53 +}
193.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
193.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/StackMapper.java Wed Jan 23 20:16:48 2013 +0100
193.3 @@ -0,0 +1,194 @@
193.4 +/**
193.5 + * Back 2 Browser Bytecode Translator
193.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
193.7 + *
193.8 + * This program is free software: you can redistribute it and/or modify
193.9 + * it under the terms of the GNU General Public License as published by
193.10 + * the Free Software Foundation, version 2 of the License.
193.11 + *
193.12 + * This program is distributed in the hope that it will be useful,
193.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
193.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
193.15 + * GNU General Public License for more details.
193.16 + *
193.17 + * You should have received a copy of the GNU General Public License
193.18 + * along with this program. Look for COPYING file in the top folder.
193.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
193.20 + */
193.21 +package org.apidesign.vm4brwsr;
193.22 +
193.23 +import org.apidesign.javap.TypeArray;
193.24 +
193.25 +final class StackMapper {
193.26 + private final TypeArray stackTypeIndexPairs;
193.27 + private int[] typeCounters;
193.28 + private int[] typeMaxCounters;
193.29 +
193.30 + public StackMapper() {
193.31 + stackTypeIndexPairs = new TypeArray();
193.32 + typeCounters = new int[VarType.LAST + 1];
193.33 + typeMaxCounters = new int[VarType.LAST + 1];
193.34 + }
193.35 +
193.36 + public void clear() {
193.37 + for (int type = 0; type <= VarType.LAST; ++type) {
193.38 + typeCounters[type] = 0;
193.39 + }
193.40 + stackTypeIndexPairs.clear();
193.41 + }
193.42 +
193.43 + public void syncWithFrameStack(final TypeArray frameStack) {
193.44 + clear();
193.45 +
193.46 + final int size = frameStack.getSize();
193.47 + for (int i = 0; i < size; ++i) {
193.48 + pushTypeImpl(VarType.fromStackMapType(frameStack.get(i)));
193.49 + }
193.50 + }
193.51 +
193.52 + public Variable pushI() {
193.53 + return pushT(VarType.INTEGER);
193.54 + }
193.55 +
193.56 + public Variable pushL() {
193.57 + return pushT(VarType.LONG);
193.58 + }
193.59 +
193.60 + public Variable pushF() {
193.61 + return pushT(VarType.FLOAT);
193.62 + }
193.63 +
193.64 + public Variable pushD() {
193.65 + return pushT(VarType.DOUBLE);
193.66 + }
193.67 +
193.68 + public Variable pushA() {
193.69 + return pushT(VarType.REFERENCE);
193.70 + }
193.71 +
193.72 + public Variable pushT(final int type) {
193.73 + return getVariable(pushTypeImpl(type));
193.74 + }
193.75 +
193.76 + public Variable popI() {
193.77 + return popT(VarType.INTEGER);
193.78 + }
193.79 +
193.80 + public Variable popL() {
193.81 + return popT(VarType.LONG);
193.82 + }
193.83 +
193.84 + public Variable popF() {
193.85 + return popT(VarType.FLOAT);
193.86 + }
193.87 +
193.88 + public Variable popD() {
193.89 + return popT(VarType.DOUBLE);
193.90 + }
193.91 +
193.92 + public Variable popA() {
193.93 + return popT(VarType.REFERENCE);
193.94 + }
193.95 +
193.96 + public Variable popT(final int type) {
193.97 + final Variable variable = getT(0, type);
193.98 + popImpl(1);
193.99 + return variable;
193.100 + }
193.101 +
193.102 + public Variable pop() {
193.103 + final Variable variable = get(0);
193.104 + popImpl(1);
193.105 + return variable;
193.106 + }
193.107 +
193.108 + public void pop(final int count) {
193.109 + final int stackSize = stackTypeIndexPairs.getSize();
193.110 + if (count > stackSize) {
193.111 + throw new IllegalStateException("Stack underflow");
193.112 + }
193.113 + popImpl(count);
193.114 + }
193.115 +
193.116 + public Variable getI(final int indexFromTop) {
193.117 + return getT(indexFromTop, VarType.INTEGER);
193.118 + }
193.119 +
193.120 + public Variable getL(final int indexFromTop) {
193.121 + return getT(indexFromTop, VarType.LONG);
193.122 + }
193.123 +
193.124 + public Variable getF(final int indexFromTop) {
193.125 + return getT(indexFromTop, VarType.FLOAT);
193.126 + }
193.127 +
193.128 + public Variable getD(final int indexFromTop) {
193.129 + return getT(indexFromTop, VarType.DOUBLE);
193.130 + }
193.131 +
193.132 + public Variable getA(final int indexFromTop) {
193.133 + return getT(indexFromTop, VarType.REFERENCE);
193.134 + }
193.135 +
193.136 + public Variable getT(final int indexFromTop, final int type) {
193.137 + final int stackSize = stackTypeIndexPairs.getSize();
193.138 + if (indexFromTop >= stackSize) {
193.139 + throw new IllegalStateException("Stack underflow");
193.140 + }
193.141 + final int stackValue =
193.142 + stackTypeIndexPairs.get(stackSize - indexFromTop - 1);
193.143 + if ((stackValue & 0xff) != type) {
193.144 + throw new IllegalStateException("Type mismatch");
193.145 + }
193.146 +
193.147 + return getVariable(stackValue);
193.148 + }
193.149 +
193.150 + public Variable get(final int indexFromTop) {
193.151 + final int stackSize = stackTypeIndexPairs.getSize();
193.152 + if (indexFromTop >= stackSize) {
193.153 + throw new IllegalStateException("Stack underflow");
193.154 + }
193.155 + final int stackValue =
193.156 + stackTypeIndexPairs.get(stackSize - indexFromTop - 1);
193.157 +
193.158 + return getVariable(stackValue);
193.159 + }
193.160 +
193.161 + private int pushTypeImpl(final int type) {
193.162 + final int count = typeCounters[type];
193.163 + final int value = (count << 8) | (type & 0xff);
193.164 + incCounter(type);
193.165 + stackTypeIndexPairs.add(value);
193.166 +
193.167 + return value;
193.168 + }
193.169 +
193.170 + private void popImpl(final int count) {
193.171 + final int stackSize = stackTypeIndexPairs.getSize();
193.172 + for (int i = stackSize - count; i < stackSize; ++i) {
193.173 + final int value = stackTypeIndexPairs.get(i);
193.174 + decCounter(value & 0xff);
193.175 + }
193.176 +
193.177 + stackTypeIndexPairs.setSize(stackSize - count);
193.178 + }
193.179 +
193.180 + private void incCounter(final int type) {
193.181 + final int newValue = ++typeCounters[type];
193.182 + if (typeMaxCounters[type] < newValue) {
193.183 + typeMaxCounters[type] = newValue;
193.184 + }
193.185 + }
193.186 +
193.187 + private void decCounter(final int type) {
193.188 + --typeCounters[type];
193.189 + }
193.190 +
193.191 + public Variable getVariable(final int typeAndIndex) {
193.192 + final int type = typeAndIndex & 0xff;
193.193 + final int index = typeAndIndex >> 8;
193.194 +
193.195 + return Variable.getStackVariable(type, index);
193.196 + }
193.197 +}
194.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
194.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/StringArray.java Wed Jan 23 20:16:48 2013 +0100
194.3 @@ -0,0 +1,97 @@
194.4 +/**
194.5 + * Back 2 Browser Bytecode Translator
194.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
194.7 + *
194.8 + * This program is free software: you can redistribute it and/or modify
194.9 + * it under the terms of the GNU General Public License as published by
194.10 + * the Free Software Foundation, version 2 of the License.
194.11 + *
194.12 + * This program is distributed in the hope that it will be useful,
194.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
194.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
194.15 + * GNU General Public License for more details.
194.16 + *
194.17 + * You should have received a copy of the GNU General Public License
194.18 + * along with this program. Look for COPYING file in the top folder.
194.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
194.20 + */
194.21 +package org.apidesign.vm4brwsr;
194.22 +
194.23 +/**
194.24 + *
194.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
194.26 + */
194.27 +class StringArray {
194.28 + private String[] arr;
194.29 +
194.30 + public StringArray() {
194.31 + }
194.32 +
194.33 + private StringArray(String[] arr) {
194.34 + this.arr = arr;
194.35 + }
194.36 +
194.37 + public void add(String s) {
194.38 + if (arr == null) {
194.39 + arr = new String[1];
194.40 + } else {
194.41 + String[] tmp = new String[arr.length + 1];
194.42 + for (int i = 0; i < arr.length; i++) {
194.43 + tmp[i] = arr[i];
194.44 + }
194.45 + arr = tmp;
194.46 + }
194.47 + arr[arr.length - 1] = s;
194.48 + }
194.49 +
194.50 + public String[] toArray() {
194.51 + return arr == null ? new String[0] : arr;
194.52 + }
194.53 +
194.54 + static StringArray asList(String... names) {
194.55 + return new StringArray(names);
194.56 + }
194.57 +
194.58 + void reverse() {
194.59 + for (int i = 0, j = arr.length; i < j; i++) {
194.60 + String s = arr[i];
194.61 + arr[i] = arr[--j];
194.62 + arr[j] = s;
194.63 + }
194.64 + }
194.65 +
194.66 + boolean contains(String n) {
194.67 + if (arr == null) {
194.68 + return false;
194.69 + }
194.70 + for (int i = 0; i < arr.length; i++) {
194.71 + if (n.equals(arr[i])) {
194.72 + return true;
194.73 + }
194.74 + }
194.75 + return false;
194.76 + }
194.77 +
194.78 + void delete(int indx) {
194.79 + if (arr == null || indx < 0 || indx >= arr.length) {
194.80 + return;
194.81 + }
194.82 + String[] tmp = new String[arr.length - 1];
194.83 + for (int i = 0, j = 0; i < arr.length; i++) {
194.84 + if (i != indx) {
194.85 + tmp[j++] = arr[i];
194.86 + }
194.87 + }
194.88 + arr = tmp;
194.89 + }
194.90 +
194.91 + int indexOf(String ic) {
194.92 + for (int i = 0; i < arr.length; i++) {
194.93 + if (ic.equals(arr[i])) {
194.94 + return i;
194.95 + }
194.96 + }
194.97 + return -1;
194.98 + }
194.99 +
194.100 +}
195.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
195.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Wed Jan 23 20:16:48 2013 +0100
195.3 @@ -0,0 +1,220 @@
195.4 +/**
195.5 + * Back 2 Browser Bytecode Translator
195.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
195.7 + *
195.8 + * This program is free software: you can redistribute it and/or modify
195.9 + * it under the terms of the GNU General Public License as published by
195.10 + * the Free Software Foundation, version 2 of the License.
195.11 + *
195.12 + * This program is distributed in the hope that it will be useful,
195.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
195.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
195.15 + * GNU General Public License for more details.
195.16 + *
195.17 + * You should have received a copy of the GNU General Public License
195.18 + * along with this program. Look for COPYING file in the top folder.
195.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
195.20 + */
195.21 +package org.apidesign.vm4brwsr;
195.22 +
195.23 +import java.io.IOException;
195.24 +import java.io.InputStream;
195.25 +
195.26 +/** Generator of JavaScript from bytecode of classes on classpath of the VM.
195.27 + *
195.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
195.29 + */
195.30 +class VM extends ByteCodeToJavaScript {
195.31 + public VM(Appendable out) {
195.32 + super(out);
195.33 + }
195.34 +
195.35 + static {
195.36 + // uses VMLazy to load dynamic classes
195.37 + VMLazy.init();
195.38 + }
195.39 +
195.40 + @Override
195.41 + boolean debug(String msg) throws IOException {
195.42 + return false;
195.43 + }
195.44 +
195.45 + static void compile(Bck2Brwsr.Resources l, Appendable out, StringArray names) throws IOException {
195.46 + new VM(out).doCompile(l, names);
195.47 + }
195.48 + protected void doCompile(Bck2Brwsr.Resources l, StringArray names) throws IOException {
195.49 + out.append("(function VM(global) {");
195.50 + out.append("\n var vm = {};");
195.51 + StringArray processed = new StringArray();
195.52 + StringArray initCode = new StringArray();
195.53 + for (String baseClass : names.toArray()) {
195.54 + references.add(baseClass);
195.55 + for (;;) {
195.56 + String name = null;
195.57 + for (String n : references.toArray()) {
195.58 + if (processed.contains(n)) {
195.59 + continue;
195.60 + }
195.61 + name = n;
195.62 + }
195.63 + if (name == null) {
195.64 + break;
195.65 + }
195.66 + InputStream is = loadClass(l, name);
195.67 + if (is == null) {
195.68 + throw new IOException("Can't find class " + name);
195.69 + }
195.70 + try {
195.71 + String ic = compile(is);
195.72 + processed.add(name);
195.73 + initCode.add(ic == null ? "" : ic);
195.74 + } catch (RuntimeException ex) {
195.75 + if (out instanceof CharSequence) {
195.76 + CharSequence seq = (CharSequence)out;
195.77 + int lastBlock = seq.length();
195.78 + while (lastBlock-- > 0) {
195.79 + if (seq.charAt(lastBlock) == '{') {
195.80 + break;
195.81 + }
195.82 + }
195.83 + throw new IOException("Error while compiling " + name + "\n"
195.84 + + seq.subSequence(lastBlock + 1, seq.length()), ex
195.85 + );
195.86 + } else {
195.87 + throw new IOException("Error while compiling " + name + "\n"
195.88 + + out, ex
195.89 + );
195.90 + }
195.91 + }
195.92 + }
195.93 +
195.94 + for (String resource : scripts.toArray()) {
195.95 + while (resource.startsWith("/")) {
195.96 + resource = resource.substring(1);
195.97 + }
195.98 + InputStream emul = l.get(resource);
195.99 + if (emul == null) {
195.100 + throw new IOException("Can't find " + resource);
195.101 + }
195.102 + readResource(emul, out);
195.103 + }
195.104 + scripts = new StringArray();
195.105 +
195.106 + StringArray toInit = StringArray.asList(references.toArray());
195.107 + toInit.reverse();
195.108 +
195.109 + for (String ic : toInit.toArray()) {
195.110 + int indx = processed.indexOf(ic);
195.111 + if (indx >= 0) {
195.112 + out.append(initCode.toArray()[indx]).append("\n");
195.113 + initCode.toArray()[indx] = "";
195.114 + }
195.115 + }
195.116 + }
195.117 + out.append(
195.118 + " global.bck2brwsr = function() {\n"
195.119 + + " var args = arguments;\n"
195.120 + + " var loader = {};\n"
195.121 + + " loader.vm = vm;\n"
195.122 + + " loader.loadClass = function(name) {\n"
195.123 + + " var attr = name.replace__Ljava_lang_String_2CC('.','_');\n"
195.124 + + " var fn = vm[attr];\n"
195.125 + + " if (fn) return fn(false);\n"
195.126 + + " if (!args[0]) throw 'bck2brwsr initialized without loader function, cannot load ' + name;\n"
195.127 + + " return vm.org_apidesign_vm4brwsr_VMLazy(false).\n"
195.128 + + " load__Ljava_lang_Object_2Ljava_lang_Object_2Ljava_lang_String_2_3Ljava_lang_Object_2(loader, name, args);\n"
195.129 + + " }\n"
195.130 + + " if (args[0]) {\n"
195.131 + + " vm.loadClass = loader.loadClass;\n"
195.132 + + " vm.loadBytes = function(name) {\n"
195.133 + + " if (!args[0]) throw 'bck2brwsr initialized without loader function, cannot load ' + name;\n"
195.134 + + " return args[0](name);\n"
195.135 + + " }\n"
195.136 + + " }\n"
195.137 + + " return loader;\n"
195.138 + + " };\n");
195.139 + out.append("}(this));");
195.140 + }
195.141 + private static void readResource(InputStream emul, Appendable out) throws IOException {
195.142 + try {
195.143 + int state = 0;
195.144 + for (;;) {
195.145 + int ch = emul.read();
195.146 + if (ch == -1) {
195.147 + break;
195.148 + }
195.149 + if (ch < 0 || ch > 255) {
195.150 + throw new IOException("Invalid char in emulation " + ch);
195.151 + }
195.152 + switch (state) {
195.153 + case 0:
195.154 + if (ch == '/') {
195.155 + state = 1;
195.156 + } else {
195.157 + out.append((char)ch);
195.158 + }
195.159 + break;
195.160 + case 1:
195.161 + if (ch == '*') {
195.162 + state = 2;
195.163 + } else {
195.164 + out.append('/').append((char)ch);
195.165 + state = 0;
195.166 + }
195.167 + break;
195.168 + case 2:
195.169 + if (ch == '*') {
195.170 + state = 3;
195.171 + }
195.172 + break;
195.173 + case 3:
195.174 + if (ch == '/') {
195.175 + state = 0;
195.176 + } else {
195.177 + state = 2;
195.178 + }
195.179 + break;
195.180 + }
195.181 + }
195.182 + } finally {
195.183 + emul.close();
195.184 + }
195.185 + }
195.186 +
195.187 + private static InputStream loadClass(Bck2Brwsr.Resources l, String name) throws IOException {
195.188 + return l.get(name + ".class"); // NOI18N
195.189 + }
195.190 +
195.191 + static String toString(String name) throws IOException {
195.192 + StringBuilder sb = new StringBuilder();
195.193 +// compile(sb, name);
195.194 + return sb.toString().toString();
195.195 + }
195.196 +
195.197 + private StringArray scripts = new StringArray();
195.198 + private StringArray references = new StringArray();
195.199 +
195.200 + @Override
195.201 + protected boolean requireReference(String cn) {
195.202 + if (references.contains(cn)) {
195.203 + return false;
195.204 + }
195.205 + references.add(cn);
195.206 + return true;
195.207 + }
195.208 +
195.209 + @Override
195.210 + protected void requireScript(String resourcePath) {
195.211 + scripts.add(resourcePath);
195.212 + }
195.213 +
195.214 + @Override
195.215 + String assignClass(String className) {
195.216 + return "vm." + className + " = ";
195.217 + }
195.218 +
195.219 + @Override
195.220 + String accessClass(String className) {
195.221 + return "vm." + className;
195.222 + }
195.223 +}
196.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
196.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/VMLazy.java Wed Jan 23 20:16:48 2013 +0100
196.3 @@ -0,0 +1,158 @@
196.4 +/**
196.5 + * Back 2 Browser Bytecode Translator
196.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
196.7 + *
196.8 + * This program is free software: you can redistribute it and/or modify
196.9 + * it under the terms of the GNU General Public License as published by
196.10 + * the Free Software Foundation, version 2 of the License.
196.11 + *
196.12 + * This program is distributed in the hope that it will be useful,
196.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
196.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
196.15 + * GNU General Public License for more details.
196.16 + *
196.17 + * You should have received a copy of the GNU General Public License
196.18 + * along with this program. Look for COPYING file in the top folder.
196.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
196.20 + */
196.21 +package org.apidesign.vm4brwsr;
196.22 +
196.23 +import java.io.ByteArrayInputStream;
196.24 +import java.io.IOException;
196.25 +import java.io.InputStream;
196.26 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
196.27 +
196.28 +/**
196.29 + *
196.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
196.31 + */
196.32 +final class VMLazy {
196.33 + private final Object loader;
196.34 + private final Object[] args;
196.35 +
196.36 + private VMLazy(Object loader, Object[] args) {
196.37 + this.loader = loader;
196.38 + this.args = args;
196.39 + }
196.40 +
196.41 + static void init() {
196.42 + }
196.43 +
196.44 + @JavaScriptBody(args={"l", "res", "args" }, body = ""
196.45 + + "\ntry {"
196.46 + + "\n return args[0](res.toString());"
196.47 + + "\n} catch (x) {"
196.48 + + "\n throw Object.getOwnPropertyNames(l.vm).toString() + x.toString();"
196.49 + + "\n}")
196.50 + private static native byte[] read(Object l, String res, Object[] args);
196.51 +
196.52 + static Object load(Object loader, String name, Object[] arguments)
196.53 + throws IOException, ClassNotFoundException {
196.54 + return new VMLazy(loader, arguments).load(name, false);
196.55 + }
196.56 +
196.57 + private Object load(String name, boolean instance)
196.58 + throws IOException, ClassNotFoundException {
196.59 + String res = name.replace('.', '/') + ".class";
196.60 + byte[] arr = read(loader, res, args);
196.61 + if (arr == null) {
196.62 + throw new ClassNotFoundException(name);
196.63 + }
196.64 +// beingDefined(loader, name);
196.65 + StringBuilder out = new StringBuilder();
196.66 + out.append("var loader = arguments[0];\n");
196.67 + out.append("var vm = loader.vm;\n");
196.68 + int prelude = out.length();
196.69 + String initCode = new Gen(this, out).compile(new ByteArrayInputStream(arr));
196.70 + String code = out.toString().toString();
196.71 +// dump("Loading " + name);
196.72 + dump(code);
196.73 + String under = name.replace('.', '_');
196.74 + Object fn = applyCode(loader, under, code, instance);
196.75 +
196.76 + if (!initCode.isEmpty()) {
196.77 + out.setLength(prelude);
196.78 + out.append(initCode);
196.79 + code = out.toString().toString();
196.80 + dump(code);
196.81 + applyCode(loader, null, code, false);
196.82 + }
196.83 +
196.84 + return fn;
196.85 + }
196.86 +
196.87 +// @JavaScriptBody(args = "s", body = "java.lang.System.out.println(s.toString());")
196.88 + static void dump(String s) {
196.89 + }
196.90 +
196.91 +/* possibly not needed:
196.92 + @JavaScriptBody(args = {"loader", "n" }, body =
196.93 + "var cls = n.replace__Ljava_lang_String_2CC(n, '.','_').toString();" +
196.94 + "loader.vm[cls] = true;\n"
196.95 + )
196.96 + private static native void beingDefined(Object loader, String name);
196.97 +*/
196.98 +
196.99 +
196.100 + @JavaScriptBody(args = {"loader", "name", "script", "instance" }, body =
196.101 + "try {\n" +
196.102 + " new Function(script)(loader, name);\n" +
196.103 + "} catch (ex) {\n" +
196.104 + " throw 'Cannot compile ' + ex + ' line: ' + ex.lineNumber + ' script:\\n' + script;\n" +
196.105 + "}\n" +
196.106 + "return name != null ? vm[name](instance) : null;\n"
196.107 + )
196.108 + private static native Object applyCode(Object loader, String name, String script, boolean instance);
196.109 +
196.110 +
196.111 + private static final class Gen extends ByteCodeToJavaScript {
196.112 + private final VMLazy lazy;
196.113 +
196.114 + public Gen(VMLazy vm, Appendable out) {
196.115 + super(out);
196.116 + this.lazy = vm;
196.117 + }
196.118 +
196.119 + @JavaScriptBody(args = {"n"},
196.120 + body =
196.121 + "var cls = n.replace__Ljava_lang_String_2CC('/','_').toString();"
196.122 + + "\nvar dot = n.replace__Ljava_lang_String_2CC('/','.').toString();"
196.123 + + "\nvar lazy = this.fld_lazy;"
196.124 + + "\nvar loader = lazy.fld_loader;"
196.125 + + "\nvar vm = loader.vm;"
196.126 + + "\nif (vm[cls]) return false;"
196.127 + + "\nvm[cls] = function() {"
196.128 + + "\n var instance = arguments.length == 0 || arguments[0] === true;"
196.129 + + "\n return lazy.load__Ljava_lang_Object_2Ljava_lang_String_2Z(dot, instance);"
196.130 + + "\n};"
196.131 + + "\nreturn true;")
196.132 + @Override
196.133 + protected boolean requireReference(String internalClassName) {
196.134 + throw new UnsupportedOperationException();
196.135 + }
196.136 +
196.137 + @Override
196.138 + protected void requireScript(String resourcePath) throws IOException {
196.139 + InputStream is = getClass().getResourceAsStream(resourcePath);
196.140 + StringBuilder sb = new StringBuilder();
196.141 + for (;;) {
196.142 + int ch = is.read();
196.143 + if (ch == -1) {
196.144 + break;
196.145 + }
196.146 + sb.append((char)ch);
196.147 + }
196.148 + applyCode(lazy.loader, null, sb.toString(), false);
196.149 + }
196.150 +
196.151 + @Override
196.152 + String assignClass(String className) {
196.153 + return "vm[arguments[1]]=";
196.154 + }
196.155 +
196.156 + @Override
196.157 + String accessClass(String classOperation) {
196.158 + return "vm." + classOperation;
196.159 + }
196.160 + }
196.161 +}
197.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
197.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/VarType.java Wed Jan 23 20:16:48 2013 +0100
197.3 @@ -0,0 +1,110 @@
197.4 +/**
197.5 + * Back 2 Browser Bytecode Translator
197.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
197.7 + *
197.8 + * This program is free software: you can redistribute it and/or modify
197.9 + * it under the terms of the GNU General Public License as published by
197.10 + * the Free Software Foundation, version 2 of the License.
197.11 + *
197.12 + * This program is distributed in the hope that it will be useful,
197.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
197.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
197.15 + * GNU General Public License for more details.
197.16 + *
197.17 + * You should have received a copy of the GNU General Public License
197.18 + * along with this program. Look for COPYING file in the top folder.
197.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
197.20 + */
197.21 +package org.apidesign.vm4brwsr;
197.22 +
197.23 +import org.apidesign.javap.RuntimeConstants;
197.24 +
197.25 +final class VarType {
197.26 + public static final int INTEGER = 0;
197.27 + public static final int LONG = 1;
197.28 + public static final int FLOAT = 2;
197.29 + public static final int DOUBLE = 3;
197.30 + public static final int REFERENCE = 4;
197.31 +
197.32 + public static final int LAST = REFERENCE;
197.33 +
197.34 + private VarType() {
197.35 + }
197.36 +
197.37 + public static boolean isCategory2(final int varType) {
197.38 + return (varType == LONG) || (varType == DOUBLE);
197.39 + }
197.40 +
197.41 + public static int fromStackMapType(final int smType) {
197.42 + switch (smType & 0xff) {
197.43 + case RuntimeConstants.ITEM_Integer:
197.44 + return VarType.INTEGER;
197.45 + case RuntimeConstants.ITEM_Float:
197.46 + return VarType.FLOAT;
197.47 + case RuntimeConstants.ITEM_Double:
197.48 + return VarType.DOUBLE;
197.49 + case RuntimeConstants.ITEM_Long:
197.50 + return VarType.LONG;
197.51 + case RuntimeConstants.ITEM_Object:
197.52 + return VarType.REFERENCE;
197.53 +
197.54 + case RuntimeConstants.ITEM_Bogus:
197.55 + case RuntimeConstants.ITEM_Null:
197.56 + case RuntimeConstants.ITEM_InitObject:
197.57 + case RuntimeConstants.ITEM_NewObject:
197.58 + /* unclear how to handle for now */
197.59 + default:
197.60 + throw new IllegalStateException("Unhandled stack map type");
197.61 + }
197.62 + }
197.63 +
197.64 + public static int fromConstantType(final byte constantTag) {
197.65 + switch (constantTag) {
197.66 + case RuntimeConstants.CONSTANT_INTEGER:
197.67 + return VarType.INTEGER;
197.68 + case RuntimeConstants.CONSTANT_FLOAT:
197.69 + return VarType.FLOAT;
197.70 + case RuntimeConstants.CONSTANT_LONG:
197.71 + return VarType.LONG;
197.72 + case RuntimeConstants.CONSTANT_DOUBLE:
197.73 + return VarType.DOUBLE;
197.74 +
197.75 + case RuntimeConstants.CONSTANT_CLASS:
197.76 + case RuntimeConstants.CONSTANT_UTF8:
197.77 + case RuntimeConstants.CONSTANT_UNICODE:
197.78 + case RuntimeConstants.CONSTANT_STRING:
197.79 + return VarType.REFERENCE;
197.80 +
197.81 + case RuntimeConstants.CONSTANT_FIELD:
197.82 + case RuntimeConstants.CONSTANT_METHOD:
197.83 + case RuntimeConstants.CONSTANT_INTERFACEMETHOD:
197.84 + case RuntimeConstants.CONSTANT_NAMEANDTYPE:
197.85 + /* unclear how to handle for now */
197.86 + default:
197.87 + throw new IllegalStateException("Unhandled constant tag");
197.88 + }
197.89 + }
197.90 +
197.91 + public static int fromFieldType(final char fieldType) {
197.92 + switch (fieldType) {
197.93 + case 'B':
197.94 + case 'C':
197.95 + case 'S':
197.96 + case 'Z':
197.97 + case 'I':
197.98 + return VarType.INTEGER;
197.99 + case 'J':
197.100 + return VarType.LONG;
197.101 + case 'F':
197.102 + return VarType.FLOAT;
197.103 + case 'D':
197.104 + return VarType.DOUBLE;
197.105 + case 'L':
197.106 + case '[':
197.107 + return VarType.REFERENCE;
197.108 +
197.109 + default:
197.110 + throw new IllegalStateException("Unhandled field type");
197.111 + }
197.112 + }
197.113 +}
198.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
198.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/Variable.java Wed Jan 23 20:16:48 2013 +0100
198.3 @@ -0,0 +1,100 @@
198.4 +/**
198.5 + * Back 2 Browser Bytecode Translator
198.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
198.7 + *
198.8 + * This program is free software: you can redistribute it and/or modify
198.9 + * it under the terms of the GNU General Public License as published by
198.10 + * the Free Software Foundation, version 2 of the License.
198.11 + *
198.12 + * This program is distributed in the hope that it will be useful,
198.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
198.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
198.15 + * GNU General Public License for more details.
198.16 + *
198.17 + * You should have received a copy of the GNU General Public License
198.18 + * along with this program. Look for COPYING file in the top folder.
198.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
198.20 + */
198.21 +package org.apidesign.vm4brwsr;
198.22 +
198.23 +final class Variable implements CharSequence {
198.24 + private static final String STACK_VAR_PREFIX = "st";
198.25 + private static final String LOCAL_VAR_PREFIX = "lc";
198.26 +
198.27 + private final String name;
198.28 + private final int type;
198.29 + private final int index;
198.30 +
198.31 + private static final char[] TYPE_IDS = { 'I', 'L', 'F', 'D', 'A' };
198.32 +
198.33 + private Variable(final String prefix, final int type, final int index) {
198.34 + this.name = prefix + TYPE_IDS[type] + index;
198.35 + this.type = type;
198.36 + this.index = index;
198.37 + }
198.38 +
198.39 + public static Variable getStackVariable(
198.40 + final int type, final int index) {
198.41 + // TODO: precreate frequently used variables
198.42 + return new Variable(STACK_VAR_PREFIX, type, index);
198.43 + }
198.44 +
198.45 + public static Variable getLocalVariable(
198.46 + final int type, final int index) {
198.47 + // TODO: precreate frequently used variables
198.48 + return new Variable(LOCAL_VAR_PREFIX, type, index);
198.49 + }
198.50 +
198.51 + public String getName() {
198.52 + return name;
198.53 + }
198.54 +
198.55 + public int getType() {
198.56 + return type;
198.57 + }
198.58 +
198.59 + public int getIndex() {
198.60 + return index;
198.61 + }
198.62 +
198.63 + public boolean isCategory2() {
198.64 + return VarType.isCategory2(type);
198.65 + }
198.66 +
198.67 + @Override
198.68 + public int length() {
198.69 + return name.length();
198.70 + }
198.71 +
198.72 + @Override
198.73 + public char charAt(final int index) {
198.74 + return name.charAt(index);
198.75 + }
198.76 +
198.77 + @Override
198.78 + public CharSequence subSequence(final int start, final int end) {
198.79 + return name.subSequence(start, end);
198.80 + }
198.81 +
198.82 + @Override
198.83 + public int hashCode() {
198.84 + return name.hashCode();
198.85 + }
198.86 +
198.87 + @Override
198.88 + public boolean equals(final Object other) {
198.89 + if (this == other) {
198.90 + return true;
198.91 + }
198.92 + if (!(other instanceof Variable)) {
198.93 + return false;
198.94 + }
198.95 +
198.96 + return name.equals(((Variable) other).name);
198.97 + }
198.98 +
198.99 + @Override
198.100 + public String toString() {
198.101 + return name;
198.102 + }
198.103 +}
199.1 --- a/vm/src/main/resources/org/apidesign/vm4brwsr/emulation/java_lang_String.js Thu Oct 11 06:15:22 2012 -0700
199.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
199.3 @@ -1,3296 +0,0 @@
199.4 -/* */
199.5 -
199.6 -
199.7 -/*
199.8 -function java_lang_String_consV(arg0) {
199.9 - var arg1;
199.10 -;
199.11 - var stack = new Array(2);
199.12 - var gt = 0;
199.13 - for(;;) switch(gt) {
199.14 - case 0: stack.push(arg0); // 42
199.15 - case 1: { java_lang_Object_consV(stack.pop()); } // 183 1 130
199.16 - case 4: stack.push(arg0); // 42
199.17 - case 5: stack.push(0); // 3
199.18 - case 6: { var v = stack.pop(); stack.pop().offset = v; } // 181 1 99
199.19 - case 9: stack.push(arg0); // 42
199.20 - case 10: stack.push(0); // 3
199.21 - case 11: { var v = stack.pop(); stack.pop().count = v; } // 181 1 97
199.22 - case 14: stack.push(arg0); // 42
199.23 - case 15: stack.push(0); // 3
199.24 - case 16: stack.push(new Array(stack.pop())); // 188 5
199.25 - case 18: { var v = stack.pop(); stack.pop().value = v; } // 181 1 100
199.26 - case 21: return; // 177
199.27 - }
199.28 -}
199.29 -function java_lang_String_consVLjava_lang_String(arg0,arg1) {
199.30 - var arg2;
199.31 - var arg3;
199.32 - var arg4;
199.33 - var arg5;
199.34 - var arg6;
199.35 -;
199.36 - var stack = new Array(4);
199.37 - var gt = 0;
199.38 - for(;;) switch(gt) {
199.39 - case 0: stack.push(arg0); // 42
199.40 - case 1: { java_lang_Object_consV(stack.pop()); } // 183 1 130
199.41 - case 4: stack.push(arg1); // 43
199.42 - case 5: stack.push(stack.pop().count); // 180 1 97
199.43 - case 8: arg2 = stack.pop(); // 61
199.44 - case 9: stack.push(arg1); // 43
199.45 - case 10: stack.push(stack.pop().value); // 180 1 100
199.46 - case 13: arg3 = stack.pop(); // 78
199.47 - case 14: stack.push(arg3); // 45
199.48 - case 15: stack.push(stack.pop().length); // 190
199.49 - case 16: stack.push(arg2); // 28
199.50 - case 17: if (stack.pop() >= stack.pop()) { gt = 41; continue; } // 164 0 24
199.51 - case 20: stack.push(arg1); // 43
199.52 - case 21: stack.push(stack.pop().offset); // 180 1 99
199.53 - case 24: arg5 = stack.pop() // 54 5
199.54 - case 26: stack.push(arg3); // 45
199.55 - case 27: stack.push(arg5); // 21 5
199.56 - case 29: stack.push(arg5); // 21 5
199.57 - case 31: stack.push(arg2); // 28
199.58 - case 32: stack.push(stack.pop() + stack.pop()); // 96
199.59 - case 33: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_util_Arrays_copyOfRangeACACAIAI(v0, v1, v2)); } // 184 1 173
199.60 - case 36: arg4 = stack.pop() // 58 4
199.61 - case 38: gt = 44; continue; // 167 0 6
199.62 - case 41: stack.push(arg3); // 45
199.63 - case 42: arg4 = stack.pop() // 58 4
199.64 - case 44: stack.push(arg0); // 42
199.65 - case 45: stack.push(0); // 3
199.66 - case 46: { var v = stack.pop(); stack.pop().offset = v; } // 181 1 99
199.67 - case 49: stack.push(arg0); // 42
199.68 - case 50: stack.push(arg2); // 28
199.69 - case 51: { var v = stack.pop(); stack.pop().count = v; } // 181 1 97
199.70 - case 54: stack.push(arg0); // 42
199.71 - case 55: stack.push(arg4); // 25 4
199.72 - case 57: { var v = stack.pop(); stack.pop().value = v; } // 181 1 100
199.73 - case 60: return; // 177
199.74 - }
199.75 -}
199.76 -*/
199.77 -function java_lang_String_consVAC(arg0,arg1) {
199.78 - arg0.r = arg1.join("");
199.79 -}
199.80 -/*
199.81 -function java_lang_String_consVACII(arg0,arg1,arg2,arg3) {
199.82 - var arg4;
199.83 -;
199.84 - var stack = new Array(5);
199.85 - var gt = 0;
199.86 - for(;;) switch(gt) {
199.87 - case 0: stack.push(arg0); // 42
199.88 - case 1: { java_lang_Object_consV(stack.pop()); } // 183 1 130
199.89 - case 4: stack.push(arg2); // 28
199.90 - case 5: if (stack.pop() >= 0) { gt = 17; continue; } // 156 0 12
199.91 - case 8: stack.push(new java_lang_StringIndexOutOfBoundsException); // 187 0 206
199.92 - case 11: stack.push(stack[stack.length - 1]); // 89
199.93 - case 12: stack.push(arg2); // 28
199.94 - case 13: { var v0 = stack.pop(); java_lang_StringIndexOutOfBoundsException_consVI(stack.pop(), v0); } // 183 1 169
199.95 - case 16: // 191
199.96 - case 17: stack.push(arg3); // 29
199.97 - case 18: if (stack.pop() >= 0) { gt = 30; continue; } // 156 0 12
199.98 - case 21: stack.push(new java_lang_StringIndexOutOfBoundsException); // 187 0 206
199.99 - case 24: stack.push(stack[stack.length - 1]); // 89
199.100 - case 25: stack.push(arg3); // 29
199.101 - case 26: { var v0 = stack.pop(); java_lang_StringIndexOutOfBoundsException_consVI(stack.pop(), v0); } // 183 1 169
199.102 - case 29: // 191
199.103 - case 30: stack.push(arg2); // 28
199.104 - case 31: stack.push(arg1); // 43
199.105 - case 32: stack.push(stack.pop().length); // 190
199.106 - case 33: stack.push(arg3); // 29
199.107 - case 34: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.108 - case 35: if (stack.pop() >= stack.pop()) { gt = 49; continue; } // 164 0 14
199.109 - case 38: stack.push(new java_lang_StringIndexOutOfBoundsException); // 187 0 206
199.110 - case 41: stack.push(stack[stack.length - 1]); // 89
199.111 - case 42: stack.push(arg2); // 28
199.112 - case 43: stack.push(arg3); // 29
199.113 - case 44: stack.push(stack.pop() + stack.pop()); // 96
199.114 - case 45: { var v0 = stack.pop(); java_lang_StringIndexOutOfBoundsException_consVI(stack.pop(), v0); } // 183 1 169
199.115 - case 48: // 191
199.116 - case 49: stack.push(arg0); // 42
199.117 - case 50: stack.push(0); // 3
199.118 - case 51: { var v = stack.pop(); stack.pop().offset = v; } // 181 1 99
199.119 - case 54: stack.push(arg0); // 42
199.120 - case 55: stack.push(arg3); // 29
199.121 - case 56: { var v = stack.pop(); stack.pop().count = v; } // 181 1 97
199.122 - case 59: stack.push(arg0); // 42
199.123 - case 60: stack.push(arg1); // 43
199.124 - case 61: stack.push(arg2); // 28
199.125 - case 62: stack.push(arg2); // 28
199.126 - case 63: stack.push(arg3); // 29
199.127 - case 64: stack.push(stack.pop() + stack.pop()); // 96
199.128 - case 65: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_util_Arrays_copyOfRangeACACAIAI(v0, v1, v2)); } // 184 1 173
199.129 - case 68: { var v = stack.pop(); stack.pop().value = v; } // 181 1 100
199.130 - case 71: return; // 177
199.131 - }
199.132 -}
199.133 -function java_lang_String_consVAIII(arg0,arg1,arg2,arg3) {
199.134 - var arg4;
199.135 - var arg5;
199.136 - var arg6;
199.137 - var arg7;
199.138 - var arg8;
199.139 - var arg9;
199.140 - var arg10;
199.141 - var arg11;
199.142 - var arg12;
199.143 -;
199.144 - var stack = new Array(4);
199.145 - var gt = 0;
199.146 - for(;;) switch(gt) {
199.147 - case 0: stack.push(arg0); // 42
199.148 - case 1: { java_lang_Object_consV(stack.pop()); } // 183 1 130
199.149 - case 4: stack.push(arg2); // 28
199.150 - case 5: if (stack.pop() >= 0) { gt = 17; continue; } // 156 0 12
199.151 - case 8: stack.push(new java_lang_StringIndexOutOfBoundsException); // 187 0 206
199.152 - case 11: stack.push(stack[stack.length - 1]); // 89
199.153 - case 12: stack.push(arg2); // 28
199.154 - case 13: { var v0 = stack.pop(); java_lang_StringIndexOutOfBoundsException_consVI(stack.pop(), v0); } // 183 1 169
199.155 - case 16: // 191
199.156 - case 17: stack.push(arg3); // 29
199.157 - case 18: if (stack.pop() >= 0) { gt = 30; continue; } // 156 0 12
199.158 - case 21: stack.push(new java_lang_StringIndexOutOfBoundsException); // 187 0 206
199.159 - case 24: stack.push(stack[stack.length - 1]); // 89
199.160 - case 25: stack.push(arg3); // 29
199.161 - case 26: { var v0 = stack.pop(); java_lang_StringIndexOutOfBoundsException_consVI(stack.pop(), v0); } // 183 1 169
199.162 - case 29: // 191
199.163 - case 30: stack.push(arg2); // 28
199.164 - case 31: stack.push(arg1); // 43
199.165 - case 32: stack.push(stack.pop().length); // 190
199.166 - case 33: stack.push(arg3); // 29
199.167 - case 34: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.168 - case 35: if (stack.pop() >= stack.pop()) { gt = 49; continue; } // 164 0 14
199.169 - case 38: stack.push(new java_lang_StringIndexOutOfBoundsException); // 187 0 206
199.170 - case 41: stack.push(stack[stack.length - 1]); // 89
199.171 - case 42: stack.push(arg2); // 28
199.172 - case 43: stack.push(arg3); // 29
199.173 - case 44: stack.push(stack.pop() + stack.pop()); // 96
199.174 - case 45: { var v0 = stack.pop(); java_lang_StringIndexOutOfBoundsException_consVI(stack.pop(), v0); } // 183 1 169
199.175 - case 48: // 191
199.176 - case 49: stack.push(0); // 3
199.177 - case 50: arg4 = stack.pop() // 54 4
199.178 - case 52: stack.push(1); // 4
199.179 - case 53: arg5 = stack.pop() // 54 5
199.180 - case 55: stack.push(arg3); // 29
199.181 - case 56: stack.push(arg5); // 21 5
199.182 - case 58: stack.push(stack.pop() + stack.pop()); // 96
199.183 - case 59: stack.push(new Array(stack.pop())); // 188 5
199.184 - case 61: arg6 = stack.pop() // 58 6
199.185 - case 63: stack.push(arg2); // 28
199.186 - case 64: arg7 = stack.pop() // 54 7
199.187 - case 66: stack.push(0); // 3
199.188 - case 67: arg8 = stack.pop() // 54 8
199.189 - case 69: stack.push(0); // 3
199.190 - case 70: arg9 = stack.pop() // 54 9
199.191 - case 72: stack.push(arg9); // 21 9
199.192 - case 74: stack.push(arg3); // 29
199.193 - case 75: if (stack.pop() <= stack.pop()) { gt = 255; continue; } // 162 0 180
199.194 - case 78: stack.push(arg1); // 43
199.195 - case 79: stack.push(arg7); // 21 7
199.196 - case 81: arg7++; // 132 7 1
199.197 - case 84: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 46
199.198 - case 85: arg10 = stack.pop() // 54 10
199.199 - case 87: stack.push(arg10); // 21 10
199.200 - case 89: if (stack.pop() >= 0) { gt = 100; continue; } // 156 0 11
199.201 - case 92: stack.push(new java_lang_IllegalArgumentException); // 187 0 193
199.202 - case 95: stack.push(stack[stack.length - 1]); // 89
199.203 - case 96: { java_lang_IllegalArgumentException_consV(stack.pop()); } // 183 1 123
199.204 - case 99: // 191
199.205 - case 100: stack.push(arg5); // 21 5
199.206 - case 102: if (stack.pop() > 0) { gt = 195; continue; } // 157 0 93
199.207 - case 105: stack.push(arg8); // 21 8
199.208 - case 107: stack.push(1); // 4
199.209 - case 108: stack.push(stack.pop() + stack.pop()); // 96
199.210 - case 109: stack.push(arg6); // 25 6
199.211 - case 111: stack.push(stack.pop().length); // 190
199.212 - case 112: if (stack.pop() > stack.pop()) { gt = 195; continue; } // 161 0 83
199.213 - case 115: stack.push(arg4); // 21 4
199.214 - case 117: if (stack.pop() != 0) { gt = 153; continue; } // 154 0 36
199.215 - case 120: stack.push(arg5); // 21 5
199.216 - case 122: // 116
199.217 - case 123: stack.push(1); // 4
199.218 - case 124: stack.push(stack.pop() + stack.pop()); // 96
199.219 - case 125: stack.push(arg3); // 29
199.220 - case 126: stack.push(stack.pop() * stack.pop()); // 104
199.221 - case 127: stack.push(10); // 16 10
199.222 - case 129: // 120
199.223 - case 130: stack.push(arg9); // 21 9
199.224 - case 132: { var tmp = stack.pop(); stack.push(Math.floor(stack.pop() / tmp)); } // 108
199.225 - case 133: arg4 = stack.pop() // 54 4
199.226 - case 135: stack.push(arg4); // 21 4
199.227 - case 137: stack.push(10); // 16 10
199.228 - case 139: // 122
199.229 - case 140: arg4 = stack.pop() // 54 4
199.230 - case 142: stack.push(arg4); // 21 4
199.231 - case 144: if (stack.pop() > 0) { gt = 159; continue; } // 157 0 15
199.232 - case 147: stack.push(1); // 4
199.233 - case 148: arg4 = stack.pop() // 54 4
199.234 - case 150: gt = 159; continue; // 167 0 9
199.235 - case 153: stack.push(arg4); // 21 4
199.236 - case 155: stack.push(2); // 5
199.237 - case 156: stack.push(stack.pop() * stack.pop()); // 104
199.238 - case 157: arg4 = stack.pop() // 54 4
199.239 - case 159: stack.push(arg6); // 25 6
199.240 - case 161: stack.push(stack.pop().length); // 190
199.241 - case 162: stack.push(arg4); // 21 4
199.242 - case 164: stack.push(stack.pop() + stack.pop()); // 96
199.243 - case 165: stack.push(arg3); // 29
199.244 - case 166: stack.push(2); // 5
199.245 - case 167: stack.push(stack.pop() * stack.pop()); // 104
199.246 - case 168: { var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_Math_minIII(v0, v1)); } // 184 1 127
199.247 - case 171: arg11 = stack.pop() // 54 11
199.248 - case 173: stack.push(arg11); // 21 11
199.249 - case 175: stack.push(arg6); // 25 6
199.250 - case 177: stack.push(stack.pop().length); // 190
199.251 - case 178: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.252 - case 179: stack.push(arg3); // 29
199.253 - case 180: stack.push(arg9); // 21 9
199.254 - case 182: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.255 - case 183: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.256 - case 184: arg5 = stack.pop() // 54 5
199.257 - case 186: stack.push(arg6); // 25 6
199.258 - case 188: stack.push(arg11); // 21 11
199.259 - case 190: { var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_util_Arrays_copyOfACACAI(v0, v1)); } // 184 1 172
199.260 - case 193: arg6 = stack.pop() // 58 6
199.261 - case 195: stack.push(arg10); // 21 10
199.262 - case 197: stack.push(65536); // 18 3
199.263 - case 199: if (stack.pop() <= stack.pop()) { gt = 216; continue; } // 162 0 17
199.264 - case 202: stack.push(arg6); // 25 6
199.265 - case 204: stack.push(arg8); // 21 8
199.266 - case 206: arg8++; // 132 8 1
199.267 - case 209: stack.push(arg10); // 21 10
199.268 - case 211: // number conversion // 146
199.269 - case 212: { var value = stack.pop(); var indx = stack.pop(); stack.pop()[indx] = value; } // 85
199.270 - case 213: gt = 249; continue; // 167 0 36
199.271 - case 216: stack.push(arg10); // 21 10
199.272 - case 218: stack.push(1114111); // 18 4
199.273 - case 220: if (stack.pop() < stack.pop()) { gt = 241; continue; } // 163 0 21
199.274 - case 223: stack.push(arg10); // 21 10
199.275 - case 225: stack.push(arg6); // 25 6
199.276 - case 227: stack.push(arg8); // 21 8
199.277 - case 229: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_Character_toSurrogatesVIACAI(v0, v1, v2); } // 184 1 112
199.278 - case 232: arg8 += 2; // 132 8 2
199.279 - case 235: arg5 += 255; // 132 5 255
199.280 - case 238: gt = 249; continue; // 167 0 11
199.281 - case 241: stack.push(new java_lang_IllegalArgumentException); // 187 0 193
199.282 - case 244: stack.push(stack[stack.length - 1]); // 89
199.283 - case 245: { java_lang_IllegalArgumentException_consV(stack.pop()); } // 183 1 123
199.284 - case 248: // 191
199.285 - case 249: arg9++; // 132 9 1
199.286 - case 252: gt = 72; continue; // 167 255 76
199.287 - case 255: stack.push(arg0); // 42
199.288 - case 256: stack.push(0); // 3
199.289 - case 257: { var v = stack.pop(); stack.pop().offset = v; } // 181 1 99
199.290 - case 260: stack.push(arg0); // 42
199.291 - case 261: stack.push(arg6); // 25 6
199.292 - case 263: { var v = stack.pop(); stack.pop().value = v; } // 181 1 100
199.293 - case 266: stack.push(arg0); // 42
199.294 - case 267: stack.push(arg8); // 21 8
199.295 - case 269: { var v = stack.pop(); stack.pop().count = v; } // 181 1 97
199.296 - case 272: return; // 177
199.297 - }
199.298 -}
199.299 -function java_lang_String_consVABIII(arg0,arg1,arg2,arg3,arg4) {
199.300 - var arg5;
199.301 - var arg6;
199.302 - var arg7;
199.303 -;
199.304 - var stack = new Array(6);
199.305 - var gt = 0;
199.306 - for(;;) switch(gt) {
199.307 - case 0: stack.push(arg0); // 42
199.308 - case 1: { java_lang_Object_consV(stack.pop()); } // 183 1 130
199.309 - case 4: stack.push(arg1); // 43
199.310 - case 5: stack.push(arg3); // 29
199.311 - case 6: stack.push(arg4); // 21 4
199.312 - case 8: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_String_checkBoundsVABAIAI(v0, v1, v2); } // 184 1 140
199.313 - case 11: stack.push(arg4); // 21 4
199.314 - case 13: stack.push(new Array(stack.pop())); // 188 5
199.315 - case 15: arg5 = stack.pop() // 58 5
199.316 - case 17: stack.push(arg2); // 28
199.317 - case 18: if (stack.pop() != 0) { gt = 55; continue; } // 154 0 37
199.318 - case 21: stack.push(arg4); // 21 4
199.319 - case 23: arg6 = stack.pop() // 54 6
199.320 - case 25: stack.push(arg6); // 21 6
199.321 - case 27: arg6 += 255; // 132 6 255
199.322 - case 30: if (stack.pop() <= 0) { gt = 52; continue; } // 158 0 22
199.323 - case 33: stack.push(arg5); // 25 5
199.324 - case 35: stack.push(arg6); // 21 6
199.325 - case 37: stack.push(arg1); // 43
199.326 - case 38: stack.push(arg6); // 21 6
199.327 - case 40: stack.push(arg3); // 29
199.328 - case 41: stack.push(stack.pop() + stack.pop()); // 96
199.329 - case 42: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 51
199.330 - case 43: stack.push(255); // 17 0 255
199.331 - case 46: stack.push(stack.pop() & stack.pop()); // 126
199.332 - case 47: // number conversion // 146
199.333 - case 48: { var value = stack.pop(); var indx = stack.pop(); stack.pop()[indx] = value; } // 85
199.334 - case 49: gt = 25; continue; // 167 255 232
199.335 - case 52: gt = 93; continue; // 167 0 41
199.336 - case 55: stack.push(arg2); // 28
199.337 - case 56: stack.push(8); // 16 8
199.338 - case 58: // 120
199.339 - case 59: arg2 = stack.pop(); // 61
199.340 - case 60: stack.push(arg4); // 21 4
199.341 - case 62: arg6 = stack.pop() // 54 6
199.342 - case 64: stack.push(arg6); // 21 6
199.343 - case 66: arg6 += 255; // 132 6 255
199.344 - case 69: if (stack.pop() <= 0) { gt = 93; continue; } // 158 0 24
199.345 - case 72: stack.push(arg5); // 25 5
199.346 - case 74: stack.push(arg6); // 21 6
199.347 - case 76: stack.push(arg2); // 28
199.348 - case 77: stack.push(arg1); // 43
199.349 - case 78: stack.push(arg6); // 21 6
199.350 - case 80: stack.push(arg3); // 29
199.351 - case 81: stack.push(stack.pop() + stack.pop()); // 96
199.352 - case 82: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 51
199.353 - case 83: stack.push(255); // 17 0 255
199.354 - case 86: stack.push(stack.pop() & stack.pop()); // 126
199.355 - case 87: stack.push(stack.pop() | stack.pop()); // 128
199.356 - case 88: // number conversion // 146
199.357 - case 89: { var value = stack.pop(); var indx = stack.pop(); stack.pop()[indx] = value; } // 85
199.358 - case 90: gt = 64; continue; // 167 255 230
199.359 - case 93: stack.push(arg0); // 42
199.360 - case 94: stack.push(0); // 3
199.361 - case 95: { var v = stack.pop(); stack.pop().offset = v; } // 181 1 99
199.362 - case 98: stack.push(arg0); // 42
199.363 - case 99: stack.push(arg4); // 21 4
199.364 - case 101: { var v = stack.pop(); stack.pop().count = v; } // 181 1 97
199.365 - case 104: stack.push(arg0); // 42
199.366 - case 105: stack.push(arg5); // 25 5
199.367 - case 107: { var v = stack.pop(); stack.pop().value = v; } // 181 1 100
199.368 - case 110: return; // 177
199.369 - }
199.370 -}
199.371 -function java_lang_String_consVABI(arg0,arg1,arg2) {
199.372 - var arg3;
199.373 -;
199.374 - var stack = new Array(5);
199.375 - var gt = 0;
199.376 - for(;;) switch(gt) {
199.377 - case 0: stack.push(arg0); // 42
199.378 - case 1: stack.push(arg1); // 43
199.379 - case 2: stack.push(arg2); // 28
199.380 - case 3: stack.push(0); // 3
199.381 - case 4: stack.push(arg1); // 43
199.382 - case 5: stack.push(stack.pop().length); // 190
199.383 - case 6: { var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_String_consVABAIAIAI(stack.pop(), v0, v1, v2, v3); } // 183 1 141
199.384 - case 9: return; // 177
199.385 - }
199.386 -}
199.387 -function java_lang_String_checkBoundsVABII(arg0,arg1,arg2) {
199.388 - var stack = new Array();
199.389 - var gt = 0;
199.390 - for(;;) switch(gt) {
199.391 - case 0: stack.push(arg2); // 28
199.392 - case 1: if (stack.pop() >= 0) { gt = 13; continue; } // 156 0 12
199.393 - case 4: stack.push(new java_lang_StringIndexOutOfBoundsException); // 187 0 206
199.394 - case 7: stack.push(stack[stack.length - 1]); // 89
199.395 - case 8: stack.push(arg2); // 28
199.396 - case 9: { var v0 = stack.pop(); java_lang_StringIndexOutOfBoundsException_consVI(stack.pop(), v0); } // 183 1 169
199.397 - case 12: // 191
199.398 - case 13: stack.push(arg1); // 27
199.399 - case 14: if (stack.pop() >= 0) { gt = 26; continue; } // 156 0 12
199.400 - case 17: stack.push(new java_lang_StringIndexOutOfBoundsException); // 187 0 206
199.401 - case 20: stack.push(stack[stack.length - 1]); // 89
199.402 - case 21: stack.push(arg1); // 27
199.403 - case 22: { var v0 = stack.pop(); java_lang_StringIndexOutOfBoundsException_consVI(stack.pop(), v0); } // 183 1 169
199.404 - case 25: // 191
199.405 - case 26: stack.push(arg1); // 27
199.406 - case 27: stack.push(arg0); // 42
199.407 - case 28: stack.push(stack.pop().length); // 190
199.408 - case 29: stack.push(arg2); // 28
199.409 - case 30: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.410 - case 31: if (stack.pop() >= stack.pop()) { gt = 45; continue; } // 164 0 14
199.411 - case 34: stack.push(new java_lang_StringIndexOutOfBoundsException); // 187 0 206
199.412 - case 37: stack.push(stack[stack.length - 1]); // 89
199.413 - case 38: stack.push(arg1); // 27
199.414 - case 39: stack.push(arg2); // 28
199.415 - case 40: stack.push(stack.pop() + stack.pop()); // 96
199.416 - case 41: { var v0 = stack.pop(); java_lang_StringIndexOutOfBoundsException_consVI(stack.pop(), v0); } // 183 1 169
199.417 - case 44: // 191
199.418 - case 45: return; // 177
199.419 - }
199.420 -}
199.421 -function java_lang_String_consVABIILjava_lang_String(arg0,arg1,arg2,arg3,arg4) {
199.422 - var arg5;
199.423 - var arg6;
199.424 -;
199.425 - var stack = new Array(4);
199.426 - var gt = 0;
199.427 - for(;;) switch(gt) {
199.428 - case 0: stack.push(arg0); // 42
199.429 - case 1: { java_lang_Object_consV(stack.pop()); } // 183 1 130
199.430 - case 4: stack.push(arg4); // 25 4
199.431 - case 6: if (stack.pop()) { gt = 19; continue; } // 199 0 13
199.432 - case 9: stack.push(new java_lang_NullPointerException); // 187 0 198
199.433 - case 12: stack.push(stack[stack.length - 1]); // 89
199.434 - case 13: stack.push("charsetName"); // 18 7
199.435 - case 15: { var v0 = stack.pop(); java_lang_NullPointerException_consVLjava_lang_String(stack.pop(), v0); } // 183 1 129
199.436 - case 18: // 191
199.437 - case 19: stack.push(arg1); // 43
199.438 - case 20: stack.push(arg2); // 28
199.439 - case 21: stack.push(arg3); // 29
199.440 - case 22: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_String_checkBoundsVABAIAI(v0, v1, v2); } // 184 1 140
199.441 - case 25: stack.push(arg4); // 25 4
199.442 - case 27: stack.push(arg1); // 43
199.443 - case 28: stack.push(arg2); // 28
199.444 - case 29: stack.push(arg3); // 29
199.445 - case 30: { var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_StringCoding_decodeACLjava_lang_StringABAIAI(v0, v1, v2, v3)); } // 184 1 165
199.446 - case 33: arg5 = stack.pop() // 58 5
199.447 - case 35: stack.push(arg0); // 42
199.448 - case 36: stack.push(0); // 3
199.449 - case 37: { var v = stack.pop(); stack.pop().offset = v; } // 181 1 99
199.450 - case 40: stack.push(arg0); // 42
199.451 - case 41: stack.push(arg5); // 25 5
199.452 - case 43: stack.push(stack.pop().length); // 190
199.453 - case 44: { var v = stack.pop(); stack.pop().count = v; } // 181 1 97
199.454 - case 47: stack.push(arg0); // 42
199.455 - case 48: stack.push(arg5); // 25 5
199.456 - case 50: { var v = stack.pop(); stack.pop().value = v; } // 181 1 100
199.457 - case 53: return; // 177
199.458 - }
199.459 -}
199.460 -function java_lang_String_consVABIILjava_nio_charset_Charset(arg0,arg1,arg2,arg3,arg4) {
199.461 - var arg5;
199.462 - var arg6;
199.463 -;
199.464 - var stack = new Array(4);
199.465 - var gt = 0;
199.466 - for(;;) switch(gt) {
199.467 - case 0: stack.push(arg0); // 42
199.468 - case 1: { java_lang_Object_consV(stack.pop()); } // 183 1 130
199.469 - case 4: stack.push(arg4); // 25 4
199.470 - case 6: if (stack.pop()) { gt = 19; continue; } // 199 0 13
199.471 - case 9: stack.push(new java_lang_NullPointerException); // 187 0 198
199.472 - case 12: stack.push(stack[stack.length - 1]); // 89
199.473 - case 13: stack.push("charset"); // 18 6
199.474 - case 15: { var v0 = stack.pop(); java_lang_NullPointerException_consVLjava_lang_String(stack.pop(), v0); } // 183 1 129
199.475 - case 18: // 191
199.476 - case 19: stack.push(arg1); // 43
199.477 - case 20: stack.push(arg2); // 28
199.478 - case 21: stack.push(arg3); // 29
199.479 - case 22: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_String_checkBoundsVABAIAI(v0, v1, v2); } // 184 1 140
199.480 - case 25: stack.push(arg4); // 25 4
199.481 - case 27: stack.push(arg1); // 43
199.482 - case 28: stack.push(arg2); // 28
199.483 - case 29: stack.push(arg3); // 29
199.484 - case 30: { var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_StringCoding_decodeACLjava_nio_charset_CharsetABAIAI(v0, v1, v2, v3)); } // 184 1 167
199.485 - case 33: arg5 = stack.pop() // 58 5
199.486 - case 35: stack.push(arg0); // 42
199.487 - case 36: stack.push(0); // 3
199.488 - case 37: { var v = stack.pop(); stack.pop().offset = v; } // 181 1 99
199.489 - case 40: stack.push(arg0); // 42
199.490 - case 41: stack.push(arg5); // 25 5
199.491 - case 43: stack.push(stack.pop().length); // 190
199.492 - case 44: { var v = stack.pop(); stack.pop().count = v; } // 181 1 97
199.493 - case 47: stack.push(arg0); // 42
199.494 - case 48: stack.push(arg5); // 25 5
199.495 - case 50: { var v = stack.pop(); stack.pop().value = v; } // 181 1 100
199.496 - case 53: return; // 177
199.497 - }
199.498 -}
199.499 -function java_lang_String_consVABLjava_lang_String(arg0,arg1,arg2) {
199.500 - var arg3;
199.501 -;
199.502 - var stack = new Array(5);
199.503 - var gt = 0;
199.504 - for(;;) switch(gt) {
199.505 - case 0: stack.push(arg0); // 42
199.506 - case 1: stack.push(arg1); // 43
199.507 - case 2: stack.push(0); // 3
199.508 - case 3: stack.push(arg1); // 43
199.509 - case 4: stack.push(stack.pop().length); // 190
199.510 - case 5: stack.push(arg2); // 44
199.511 - case 6: { var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_String_consVABAIAIALjava_lang_String(stack.pop(), v0, v1, v2, v3); } // 183 1 154
199.512 - case 9: return; // 177
199.513 - }
199.514 -}
199.515 -function java_lang_String_consVABLjava_nio_charset_Charset(arg0,arg1,arg2) {
199.516 - var arg3;
199.517 -;
199.518 - var stack = new Array(5);
199.519 - var gt = 0;
199.520 - for(;;) switch(gt) {
199.521 - case 0: stack.push(arg0); // 42
199.522 - case 1: stack.push(arg1); // 43
199.523 - case 2: stack.push(0); // 3
199.524 - case 3: stack.push(arg1); // 43
199.525 - case 4: stack.push(stack.pop().length); // 190
199.526 - case 5: stack.push(arg2); // 44
199.527 - case 6: { var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_String_consVABAIAIALjava_nio_charset_Charset(stack.pop(), v0, v1, v2, v3); } // 183 1 156
199.528 - case 9: return; // 177
199.529 - }
199.530 -}
199.531 -function java_lang_String_consVABII(arg0,arg1,arg2,arg3) {
199.532 - var arg4;
199.533 - var arg5;
199.534 -;
199.535 - var stack = new Array(3);
199.536 - var gt = 0;
199.537 - for(;;) switch(gt) {
199.538 - case 0: stack.push(arg0); // 42
199.539 - case 1: { java_lang_Object_consV(stack.pop()); } // 183 1 130
199.540 - case 4: stack.push(arg1); // 43
199.541 - case 5: stack.push(arg2); // 28
199.542 - case 6: stack.push(arg3); // 29
199.543 - case 7: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_String_checkBoundsVABAIAI(v0, v1, v2); } // 184 1 140
199.544 - case 10: stack.push(arg1); // 43
199.545 - case 11: stack.push(arg2); // 28
199.546 - case 12: stack.push(arg3); // 29
199.547 - case 13: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_StringCoding_decodeACABAIAI(v0, v1, v2)); } // 184 1 163
199.548 - case 16: arg4 = stack.pop() // 58 4
199.549 - case 18: stack.push(arg0); // 42
199.550 - case 19: stack.push(0); // 3
199.551 - case 20: { var v = stack.pop(); stack.pop().offset = v; } // 181 1 99
199.552 - case 23: stack.push(arg0); // 42
199.553 - case 24: stack.push(arg4); // 25 4
199.554 - case 26: stack.push(stack.pop().length); // 190
199.555 - case 27: { var v = stack.pop(); stack.pop().count = v; } // 181 1 97
199.556 - case 30: stack.push(arg0); // 42
199.557 - case 31: stack.push(arg4); // 25 4
199.558 - case 33: { var v = stack.pop(); stack.pop().value = v; } // 181 1 100
199.559 - case 36: return; // 177
199.560 - }
199.561 -}
199.562 -function java_lang_String_consVAB(arg0,arg1) {
199.563 - var arg2;
199.564 -;
199.565 - var stack = new Array(4);
199.566 - var gt = 0;
199.567 - for(;;) switch(gt) {
199.568 - case 0: stack.push(arg0); // 42
199.569 - case 1: stack.push(arg1); // 43
199.570 - case 2: stack.push(0); // 3
199.571 - case 3: stack.push(arg1); // 43
199.572 - case 4: stack.push(stack.pop().length); // 190
199.573 - case 5: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_String_consVABAIAI(stack.pop(), v0, v1, v2); } // 183 1 139
199.574 - case 8: return; // 177
199.575 - }
199.576 -}
199.577 -function java_lang_String_consVLjava_lang_StringBuffer(arg0,arg1) {
199.578 - var arg2;
199.579 - var arg3;
199.580 -;
199.581 - var stack = new Array(2);
199.582 - var gt = 0;
199.583 - for(;;) switch(gt) {
199.584 - case 0: stack.push(arg0); // 42
199.585 - case 1: { java_lang_Object_consV(stack.pop()); } // 183 1 130
199.586 - case 4: stack.push(arg1); // 43
199.587 - case 5: { var self = stack.pop(); stack.push(self.toStringLjava_lang_String(self)); } // 182 1 161
199.588 - case 8: arg2 = stack.pop(); // 77
199.589 - case 9: stack.push(arg0); // 42
199.590 - case 10: stack.push(arg2); // 44
199.591 - case 11: stack.push(stack.pop().value); // 180 1 100
199.592 - case 14: { var v = stack.pop(); stack.pop().value = v; } // 181 1 100
199.593 - case 17: stack.push(arg0); // 42
199.594 - case 18: stack.push(arg2); // 44
199.595 - case 19: stack.push(stack.pop().count); // 180 1 97
199.596 - case 22: { var v = stack.pop(); stack.pop().count = v; } // 181 1 97
199.597 - case 25: stack.push(arg0); // 42
199.598 - case 26: stack.push(arg2); // 44
199.599 - case 27: stack.push(stack.pop().offset); // 180 1 99
199.600 - case 30: { var v = stack.pop(); stack.pop().offset = v; } // 181 1 99
199.601 - case 33: return; // 177
199.602 - }
199.603 -}
199.604 -function java_lang_String_consVLjava_lang_StringBuilder(arg0,arg1) {
199.605 - var arg2;
199.606 - var arg3;
199.607 -;
199.608 - var stack = new Array(2);
199.609 - var gt = 0;
199.610 - for(;;) switch(gt) {
199.611 - case 0: stack.push(arg0); // 42
199.612 - case 1: { java_lang_Object_consV(stack.pop()); } // 183 1 130
199.613 - case 4: stack.push(arg1); // 43
199.614 - case 5: { var self = stack.pop(); stack.push(self.toStringLjava_lang_String(self)); } // 182 1 162
199.615 - case 8: arg2 = stack.pop(); // 77
199.616 - case 9: stack.push(arg0); // 42
199.617 - case 10: stack.push(arg2); // 44
199.618 - case 11: stack.push(stack.pop().value); // 180 1 100
199.619 - case 14: { var v = stack.pop(); stack.pop().value = v; } // 181 1 100
199.620 - case 17: stack.push(arg0); // 42
199.621 - case 18: stack.push(arg2); // 44
199.622 - case 19: stack.push(stack.pop().count); // 180 1 97
199.623 - case 22: { var v = stack.pop(); stack.pop().count = v; } // 181 1 97
199.624 - case 25: stack.push(arg0); // 42
199.625 - case 26: stack.push(arg2); // 44
199.626 - case 27: stack.push(stack.pop().offset); // 180 1 99
199.627 - case 30: { var v = stack.pop(); stack.pop().offset = v; } // 181 1 99
199.628 - case 33: return; // 177
199.629 - }
199.630 -}
199.631 -function java_lang_String_consVIIAC(arg0,arg1,arg2,arg3) {
199.632 - var arg4;
199.633 -;
199.634 - var stack = new Array(2);
199.635 - var gt = 0;
199.636 - for(;;) switch(gt) {
199.637 - case 0: stack.push(arg0); // 42
199.638 - case 1: { java_lang_Object_consV(stack.pop()); } // 183 1 130
199.639 - case 4: stack.push(arg0); // 42
199.640 - case 5: stack.push(arg3); // 45
199.641 - case 6: { var v = stack.pop(); stack.pop().value = v; } // 181 1 100
199.642 - case 9: stack.push(arg0); // 42
199.643 - case 10: stack.push(arg1); // 27
199.644 - case 11: { var v = stack.pop(); stack.pop().offset = v; } // 181 1 99
199.645 - case 14: stack.push(arg0); // 42
199.646 - case 15: stack.push(arg2); // 28
199.647 - case 16: { var v = stack.pop(); stack.pop().count = v; } // 181 1 97
199.648 - case 19: return; // 177
199.649 - }
199.650 -}
199.651 -*/
199.652 -
199.653 -function java_lang_String_charAtCI(arg0,arg1) {
199.654 - return arg0.toString().charAt(arg1);
199.655 -}
199.656 -function java_lang_String_lengthI(arg0) {
199.657 - return arg0.toString().length;
199.658 -}
199.659 -function java_lang_String_isEmptyZ(arg0) {
199.660 - return arg0.toString().length === 0;
199.661 -}
199.662 -
199.663 -/*
199.664 -function java_lang_String_codePointAtII(arg0,arg1) {
199.665 - var arg2;
199.666 -;
199.667 - var stack = new Array(4);
199.668 - var gt = 0;
199.669 - for(;;) switch(gt) {
199.670 - case 0: stack.push(arg1); // 27
199.671 - case 1: if (stack.pop() < 0) { gt = 12; continue; } // 155 0 11
199.672 - case 4: stack.push(arg1); // 27
199.673 - case 5: stack.push(arg0); // 42
199.674 - case 6: stack.push(stack.pop().count); // 180 1 97
199.675 - case 9: if (stack.pop() > stack.pop()) { gt = 21; continue; } // 161 0 12
199.676 - case 12: stack.push(new java_lang_StringIndexOutOfBoundsException); // 187 0 206
199.677 - case 15: stack.push(stack[stack.length - 1]); // 89
199.678 - case 16: stack.push(arg1); // 27
199.679 - case 17: { var v0 = stack.pop(); java_lang_StringIndexOutOfBoundsException_consVI(stack.pop(), v0); } // 183 1 169
199.680 - case 20: // 191
199.681 - case 21: stack.push(arg0); // 42
199.682 - case 22: stack.push(stack.pop().value); // 180 1 100
199.683 - case 25: stack.push(arg0); // 42
199.684 - case 26: stack.push(stack.pop().offset); // 180 1 99
199.685 - case 29: stack.push(arg1); // 27
199.686 - case 30: stack.push(stack.pop() + stack.pop()); // 96
199.687 - case 31: stack.push(arg0); // 42
199.688 - case 32: stack.push(stack.pop().offset); // 180 1 99
199.689 - case 35: stack.push(arg0); // 42
199.690 - case 36: stack.push(stack.pop().count); // 180 1 97
199.691 - case 39: stack.push(stack.pop() + stack.pop()); // 96
199.692 - case 40: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_Character_codePointAtImplAIACAIAI(v0, v1, v2)); } // 184 1 113
199.693 - case 43: return stack.pop(); // 172
199.694 - }
199.695 -}
199.696 -function java_lang_String_codePointBeforeII(arg0,arg1) {
199.697 - var arg2;
199.698 - var arg3;
199.699 -;
199.700 - var stack = new Array(3);
199.701 - var gt = 0;
199.702 - for(;;) switch(gt) {
199.703 - case 0: stack.push(arg1); // 27
199.704 - case 1: stack.push(1); // 4
199.705 - case 2: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.706 - case 3: arg2 = stack.pop(); // 61
199.707 - case 4: stack.push(arg2); // 28
199.708 - case 5: if (stack.pop() < 0) { gt = 16; continue; } // 155 0 11
199.709 - case 8: stack.push(arg2); // 28
199.710 - case 9: stack.push(arg0); // 42
199.711 - case 10: stack.push(stack.pop().count); // 180 1 97
199.712 - case 13: if (stack.pop() > stack.pop()) { gt = 25; continue; } // 161 0 12
199.713 - case 16: stack.push(new java_lang_StringIndexOutOfBoundsException); // 187 0 206
199.714 - case 19: stack.push(stack[stack.length - 1]); // 89
199.715 - case 20: stack.push(arg1); // 27
199.716 - case 21: { var v0 = stack.pop(); java_lang_StringIndexOutOfBoundsException_consVI(stack.pop(), v0); } // 183 1 169
199.717 - case 24: // 191
199.718 - case 25: stack.push(arg0); // 42
199.719 - case 26: stack.push(stack.pop().value); // 180 1 100
199.720 - case 29: stack.push(arg0); // 42
199.721 - case 30: stack.push(stack.pop().offset); // 180 1 99
199.722 - case 33: stack.push(arg1); // 27
199.723 - case 34: stack.push(stack.pop() + stack.pop()); // 96
199.724 - case 35: stack.push(arg0); // 42
199.725 - case 36: stack.push(stack.pop().offset); // 180 1 99
199.726 - case 39: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_Character_codePointBeforeImplAIACAIAI(v0, v1, v2)); } // 184 1 114
199.727 - case 42: return stack.pop(); // 172
199.728 - }
199.729 -}
199.730 -function java_lang_String_codePointCountIII(arg0,arg1,arg2) {
199.731 - var arg3;
199.732 -;
199.733 - var stack = new Array(4);
199.734 - var gt = 0;
199.735 - for(;;) switch(gt) {
199.736 - case 0: stack.push(arg1); // 27
199.737 - case 1: if (stack.pop() < 0) { gt = 17; continue; } // 155 0 16
199.738 - case 4: stack.push(arg2); // 28
199.739 - case 5: stack.push(arg0); // 42
199.740 - case 6: stack.push(stack.pop().count); // 180 1 97
199.741 - case 9: if (stack.pop() < stack.pop()) { gt = 17; continue; } // 163 0 8
199.742 - case 12: stack.push(arg1); // 27
199.743 - case 13: stack.push(arg2); // 28
199.744 - case 14: if (stack.pop() >= stack.pop()) { gt = 25; continue; } // 164 0 11
199.745 - case 17: stack.push(new java_lang_IndexOutOfBoundsException); // 187 0 194
199.746 - case 20: stack.push(stack[stack.length - 1]); // 89
199.747 - case 21: { java_lang_IndexOutOfBoundsException_consV(stack.pop()); } // 183 1 124
199.748 - case 24: // 191
199.749 - case 25: stack.push(arg0); // 42
199.750 - case 26: stack.push(stack.pop().value); // 180 1 100
199.751 - case 29: stack.push(arg0); // 42
199.752 - case 30: stack.push(stack.pop().offset); // 180 1 99
199.753 - case 33: stack.push(arg1); // 27
199.754 - case 34: stack.push(stack.pop() + stack.pop()); // 96
199.755 - case 35: stack.push(arg2); // 28
199.756 - case 36: stack.push(arg1); // 27
199.757 - case 37: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.758 - case 38: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_Character_codePointCountImplAIACAIAI(v0, v1, v2)); } // 184 1 115
199.759 - case 41: return stack.pop(); // 172
199.760 - }
199.761 -}
199.762 -function java_lang_String_offsetByCodePointsIII(arg0,arg1,arg2) {
199.763 - var arg3;
199.764 -;
199.765 - var stack = new Array(5);
199.766 - var gt = 0;
199.767 - for(;;) switch(gt) {
199.768 - case 0: stack.push(arg1); // 27
199.769 - case 1: if (stack.pop() < 0) { gt = 12; continue; } // 155 0 11
199.770 - case 4: stack.push(arg1); // 27
199.771 - case 5: stack.push(arg0); // 42
199.772 - case 6: stack.push(stack.pop().count); // 180 1 97
199.773 - case 9: if (stack.pop() >= stack.pop()) { gt = 20; continue; } // 164 0 11
199.774 - case 12: stack.push(new java_lang_IndexOutOfBoundsException); // 187 0 194
199.775 - case 15: stack.push(stack[stack.length - 1]); // 89
199.776 - case 16: { java_lang_IndexOutOfBoundsException_consV(stack.pop()); } // 183 1 124
199.777 - case 19: // 191
199.778 - case 20: stack.push(arg0); // 42
199.779 - case 21: stack.push(stack.pop().value); // 180 1 100
199.780 - case 24: stack.push(arg0); // 42
199.781 - case 25: stack.push(stack.pop().offset); // 180 1 99
199.782 - case 28: stack.push(arg0); // 42
199.783 - case 29: stack.push(stack.pop().count); // 180 1 97
199.784 - case 32: stack.push(arg0); // 42
199.785 - case 33: stack.push(stack.pop().offset); // 180 1 99
199.786 - case 36: stack.push(arg1); // 27
199.787 - case 37: stack.push(stack.pop() + stack.pop()); // 96
199.788 - case 38: stack.push(arg2); // 28
199.789 - case 39: { var v4 = stack.pop(); var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_Character_offsetByCodePointsImplAIACAIAIAIAI(v0, v1, v2, v3, v4)); } // 184 1 116
199.790 - case 42: stack.push(arg0); // 42
199.791 - case 43: stack.push(stack.pop().offset); // 180 1 99
199.792 - case 46: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.793 - case 47: return stack.pop(); // 172
199.794 - }
199.795 -}
199.796 -*/
199.797 -
199.798 -// public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
199.799 -function java_lang_String_getCharsVIIACAI(arg0,arg1,arg2,arg3,arg4) {
199.800 - var s = arg0.toString();
199.801 - while (arg1 < arg2) {
199.802 - arg3[arg4++] = s[arg1++];
199.803 - }
199.804 -}
199.805 -
199.806 -/*
199.807 -function java_lang_String_getBytesVIIABI(arg0,arg1,arg2,arg3,arg4) {
199.808 - var arg5;
199.809 - var arg6;
199.810 - var arg7;
199.811 - var arg8;
199.812 - var arg9;
199.813 -;
199.814 - var stack = new Array(4);
199.815 - var gt = 0;
199.816 - for(;;) switch(gt) {
199.817 - case 0: stack.push(arg1); // 27
199.818 - case 1: if (stack.pop() >= 0) { gt = 13; continue; } // 156 0 12
199.819 - case 4: stack.push(new java_lang_StringIndexOutOfBoundsException); // 187 0 206
199.820 - case 7: stack.push(stack[stack.length - 1]); // 89
199.821 - case 8: stack.push(arg1); // 27
199.822 - case 9: { var v0 = stack.pop(); java_lang_StringIndexOutOfBoundsException_consVI(stack.pop(), v0); } // 183 1 169
199.823 - case 12: // 191
199.824 - case 13: stack.push(arg2); // 28
199.825 - case 14: stack.push(arg0); // 42
199.826 - case 15: stack.push(stack.pop().count); // 180 1 97
199.827 - case 18: if (stack.pop() >= stack.pop()) { gt = 30; continue; } // 164 0 12
199.828 - case 21: stack.push(new java_lang_StringIndexOutOfBoundsException); // 187 0 206
199.829 - case 24: stack.push(stack[stack.length - 1]); // 89
199.830 - case 25: stack.push(arg2); // 28
199.831 - case 26: { var v0 = stack.pop(); java_lang_StringIndexOutOfBoundsException_consVI(stack.pop(), v0); } // 183 1 169
199.832 - case 29: // 191
199.833 - case 30: stack.push(arg1); // 27
199.834 - case 31: stack.push(arg2); // 28
199.835 - case 32: if (stack.pop() >= stack.pop()) { gt = 46; continue; } // 164 0 14
199.836 - case 35: stack.push(new java_lang_StringIndexOutOfBoundsException); // 187 0 206
199.837 - case 38: stack.push(stack[stack.length - 1]); // 89
199.838 - case 39: stack.push(arg2); // 28
199.839 - case 40: stack.push(arg1); // 27
199.840 - case 41: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.841 - case 42: { var v0 = stack.pop(); java_lang_StringIndexOutOfBoundsException_consVI(stack.pop(), v0); } // 183 1 169
199.842 - case 45: // 191
199.843 - case 46: stack.push(arg4); // 21 4
199.844 - case 48: arg5 = stack.pop() // 54 5
199.845 - case 50: stack.push(arg0); // 42
199.846 - case 51: stack.push(stack.pop().offset); // 180 1 99
199.847 - case 54: stack.push(arg2); // 28
199.848 - case 55: stack.push(stack.pop() + stack.pop()); // 96
199.849 - case 56: arg6 = stack.pop() // 54 6
199.850 - case 58: stack.push(arg0); // 42
199.851 - case 59: stack.push(stack.pop().offset); // 180 1 99
199.852 - case 62: stack.push(arg1); // 27
199.853 - case 63: stack.push(stack.pop() + stack.pop()); // 96
199.854 - case 64: arg7 = stack.pop() // 54 7
199.855 - case 66: stack.push(arg0); // 42
199.856 - case 67: stack.push(stack.pop().value); // 180 1 100
199.857 - case 70: arg8 = stack.pop() // 58 8
199.858 - case 72: stack.push(arg7); // 21 7
199.859 - case 74: stack.push(arg6); // 21 6
199.860 - case 76: if (stack.pop() <= stack.pop()) { gt = 98; continue; } // 162 0 22
199.861 - case 79: stack.push(arg3); // 45
199.862 - case 80: stack.push(arg5); // 21 5
199.863 - case 82: arg5++; // 132 5 1
199.864 - case 85: stack.push(arg8); // 25 8
199.865 - case 87: stack.push(arg7); // 21 7
199.866 - case 89: arg7++; // 132 7 1
199.867 - case 92: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.868 - case 93: // number conversion // 145
199.869 - case 94: { var value = stack.pop(); var indx = stack.pop(); stack.pop()[indx] = value; } // 84
199.870 - case 95: gt = 72; continue; // 167 255 233
199.871 - case 98: return; // 177
199.872 - }
199.873 -}
199.874 -function java_lang_String_getBytesABLjava_lang_String(arg0,arg1) {
199.875 - var arg2;
199.876 -;
199.877 - var stack = new Array(4);
199.878 - var gt = 0;
199.879 - for(;;) switch(gt) {
199.880 - case 0: stack.push(arg1); // 43
199.881 - case 1: if (stack.pop()) { gt = 12; continue; } // 199 0 11
199.882 - case 4: stack.push(new java_lang_NullPointerException); // 187 0 198
199.883 - case 7: stack.push(stack[stack.length - 1]); // 89
199.884 - case 8: { java_lang_NullPointerException_consV(stack.pop()); } // 183 1 128
199.885 - case 11: // 191
199.886 - case 12: stack.push(arg1); // 43
199.887 - case 13: stack.push(arg0); // 42
199.888 - case 14: stack.push(stack.pop().value); // 180 1 100
199.889 - case 17: stack.push(arg0); // 42
199.890 - case 18: stack.push(stack.pop().offset); // 180 1 99
199.891 - case 21: stack.push(arg0); // 42
199.892 - case 22: stack.push(stack.pop().count); // 180 1 97
199.893 - case 25: { var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_StringCoding_encodeABLjava_lang_StringACAIAI(v0, v1, v2, v3)); } // 184 1 166
199.894 - case 28: return stack.pop(); // 176
199.895 - }
199.896 -}
199.897 -function java_lang_String_getBytesABLjava_nio_charset_Charset(arg0,arg1) {
199.898 - var arg2;
199.899 -;
199.900 - var stack = new Array(4);
199.901 - var gt = 0;
199.902 - for(;;) switch(gt) {
199.903 - case 0: stack.push(arg1); // 43
199.904 - case 1: if (stack.pop()) { gt = 12; continue; } // 199 0 11
199.905 - case 4: stack.push(new java_lang_NullPointerException); // 187 0 198
199.906 - case 7: stack.push(stack[stack.length - 1]); // 89
199.907 - case 8: { java_lang_NullPointerException_consV(stack.pop()); } // 183 1 128
199.908 - case 11: // 191
199.909 - case 12: stack.push(arg1); // 43
199.910 - case 13: stack.push(arg0); // 42
199.911 - case 14: stack.push(stack.pop().value); // 180 1 100
199.912 - case 17: stack.push(arg0); // 42
199.913 - case 18: stack.push(stack.pop().offset); // 180 1 99
199.914 - case 21: stack.push(arg0); // 42
199.915 - case 22: stack.push(stack.pop().count); // 180 1 97
199.916 - case 25: { var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_StringCoding_encodeABLjava_nio_charset_CharsetACAIAI(v0, v1, v2, v3)); } // 184 1 168
199.917 - case 28: return stack.pop(); // 176
199.918 - }
199.919 -}
199.920 -function java_lang_String_getBytesAB(arg0) {
199.921 - var arg1;
199.922 -;
199.923 - var stack = new Array(3);
199.924 - var gt = 0;
199.925 - for(;;) switch(gt) {
199.926 - case 0: stack.push(arg0); // 42
199.927 - case 1: stack.push(stack.pop().value); // 180 1 100
199.928 - case 4: stack.push(arg0); // 42
199.929 - case 5: stack.push(stack.pop().offset); // 180 1 99
199.930 - case 8: stack.push(arg0); // 42
199.931 - case 9: stack.push(stack.pop().count); // 180 1 97
199.932 - case 12: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_StringCoding_encodeABACAIAI(v0, v1, v2)); } // 184 1 164
199.933 - case 15: return stack.pop(); // 176
199.934 - }
199.935 -}
199.936 -function java_lang_String_equalsZLjava_lang_Object(arg0,arg1) {
199.937 - var arg2;
199.938 - var arg3;
199.939 - var arg4;
199.940 - var arg5;
199.941 - var arg6;
199.942 - var arg7;
199.943 - var arg8;
199.944 -;
199.945 - var stack = new Array(3);
199.946 - var gt = 0;
199.947 - for(;;) switch(gt) {
199.948 - case 0: stack.push(arg0); // 42
199.949 - case 1: stack.push(arg1); // 43
199.950 - case 2: // 166
199.951 - case 3: // 0
199.952 - case 4: stack.push(2); // 5
199.953 - case 5: stack.push(1); // 4
199.954 - case 6: return stack.pop(); // 172
199.955 - case 7: stack.push(arg1); // 43
199.956 - case 8: stack.push(stack.pop().$instOf_java_lang_String ? 1 : 0); // 193 0 200
199.957 - case 11: if (stack.pop() == 0) { gt = 86; continue; } // 153 0 75
199.958 - case 14: stack.push(arg1); // 43
199.959 - case 15: if(stack[stack.length - 1].$instOf_java_lang_String != 1) throw {}; // 192 0 200
199.960 - case 18: arg2 = stack.pop(); // 77
199.961 - case 19: stack.push(arg0); // 42
199.962 - case 20: stack.push(stack.pop().count); // 180 1 97
199.963 - case 23: arg3 = stack.pop(); // 62
199.964 - case 24: stack.push(arg3); // 29
199.965 - case 25: stack.push(arg2); // 44
199.966 - case 26: stack.push(stack.pop().count); // 180 1 97
199.967 - case 29: if (stack.pop() != stack.pop()) { gt = 86; continue; } // 160 0 57
199.968 - case 32: stack.push(arg0); // 42
199.969 - case 33: stack.push(stack.pop().value); // 180 1 100
199.970 - case 36: arg4 = stack.pop() // 58 4
199.971 - case 38: stack.push(arg2); // 44
199.972 - case 39: stack.push(stack.pop().value); // 180 1 100
199.973 - case 42: arg5 = stack.pop() // 58 5
199.974 - case 44: stack.push(arg0); // 42
199.975 - case 45: stack.push(stack.pop().offset); // 180 1 99
199.976 - case 48: arg6 = stack.pop() // 54 6
199.977 - case 50: stack.push(arg2); // 44
199.978 - case 51: stack.push(stack.pop().offset); // 180 1 99
199.979 - case 54: arg7 = stack.pop() // 54 7
199.980 - case 56: stack.push(arg3); // 29
199.981 - case 57: arg3 += 255; // 132 3 255
199.982 - case 60: if (stack.pop() == 0) { gt = 84; continue; } // 153 0 24
199.983 - case 63: stack.push(arg4); // 25 4
199.984 - case 65: stack.push(arg6); // 21 6
199.985 - case 67: arg6++; // 132 6 1
199.986 - case 70: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.987 - case 71: stack.push(arg5); // 25 5
199.988 - case 73: stack.push(arg7); // 21 7
199.989 - case 75: arg7++; // 132 7 1
199.990 - case 78: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.991 - case 79: if (stack.pop() == stack.pop()) { gt = 56; continue; } // 159 255 233
199.992 - case 82: stack.push(0); // 3
199.993 - case 83: return stack.pop(); // 172
199.994 - case 84: stack.push(1); // 4
199.995 - case 85: return stack.pop(); // 172
199.996 - case 86: stack.push(0); // 3
199.997 - case 87: return stack.pop(); // 172
199.998 - }
199.999 -}
199.1000 -function java_lang_String_contentEqualsZLjava_lang_StringBuffer(arg0,arg1) {
199.1001 - var arg2;
199.1002 - var arg3;
199.1003 - var arg4;
199.1004 -;
199.1005 - var stack = new Array(2);
199.1006 - var gt = 0;
199.1007 - for(;;) switch(gt) {
199.1008 - case 0: stack.push(arg1); // 43
199.1009 - case 1: stack.push(stack[stack.length - 1]); // 89
199.1010 - case 2: arg2 = stack.pop(); // 77
199.1011 - case 3: // 194
199.1012 - case 4: stack.push(arg0); // 42
199.1013 - case 5: stack.push(arg1); // 43
199.1014 - case 6: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.contentEqualsZLjava_lang_CharSequence(self, v0)); } // 182 1 146
199.1015 - case 9: stack.push(arg2); // 44
199.1016 - case 10: // 195
199.1017 - case 11: return stack.pop(); // 172
199.1018 - case 12: arg3 = stack.pop(); // 78
199.1019 - case 13: stack.push(arg2); // 44
199.1020 - case 14: // 195
199.1021 - case 15: stack.push(arg3); // 45
199.1022 - case 16: // 191
199.1023 - }
199.1024 -}
199.1025 -function java_lang_String_contentEqualsZLjava_lang_CharSequence(arg0,arg1) {
199.1026 - var arg2;
199.1027 - var arg3;
199.1028 - var arg4;
199.1029 - var arg5;
199.1030 - var arg6;
199.1031 - var arg7;
199.1032 -;
199.1033 - var stack = new Array(3);
199.1034 - var gt = 0;
199.1035 - for(;;) switch(gt) {
199.1036 - case 0: stack.push(arg0); // 42
199.1037 - case 1: stack.push(stack.pop().count); // 180 1 97
199.1038 - case 4: stack.push(arg1); // 43
199.1039 - case 5: { var self = stack.pop(); stack.push(self.lengthI(self)); } // 185 1 188
199.1040 - case 8: // 1
199.1041 - case 9: // 0
199.1042 - case 10: if (stack.pop() == stack.pop()) { gt = 15; continue; } // 159 0 5
199.1043 - case 13: stack.push(0); // 3
199.1044 - case 14: return stack.pop(); // 172
199.1045 - case 15: stack.push(arg1); // 43
199.1046 - case 16: stack.push(stack.pop().$instOf_java_lang_AbstractStringBuilder ? 1 : 0); // 193 0 186
199.1047 - case 19: if (stack.pop() == 0) { gt = 77; continue; } // 153 0 58
199.1048 - case 22: stack.push(arg0); // 42
199.1049 - case 23: stack.push(stack.pop().value); // 180 1 100
199.1050 - case 26: arg2 = stack.pop(); // 77
199.1051 - case 27: stack.push(arg1); // 43
199.1052 - case 28: if(stack[stack.length - 1].$instOf_java_lang_AbstractStringBuilder != 1) throw {}; // 192 0 186
199.1053 - case 31: { var self = stack.pop(); stack.push(self.getValueAC(self)); } // 182 1 103
199.1054 - case 34: arg3 = stack.pop(); // 78
199.1055 - case 35: stack.push(arg0); // 42
199.1056 - case 36: stack.push(stack.pop().offset); // 180 1 99
199.1057 - case 39: arg4 = stack.pop() // 54 4
199.1058 - case 41: stack.push(0); // 3
199.1059 - case 42: arg5 = stack.pop() // 54 5
199.1060 - case 44: stack.push(arg0); // 42
199.1061 - case 45: stack.push(stack.pop().count); // 180 1 97
199.1062 - case 48: arg6 = stack.pop() // 54 6
199.1063 - case 50: stack.push(arg6); // 21 6
199.1064 - case 52: arg6 += 255; // 132 6 255
199.1065 - case 55: if (stack.pop() == 0) { gt = 77; continue; } // 153 0 22
199.1066 - case 58: stack.push(arg2); // 44
199.1067 - case 59: stack.push(arg4); // 21 4
199.1068 - case 61: arg4++; // 132 4 1
199.1069 - case 64: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1070 - case 65: stack.push(arg3); // 45
199.1071 - case 66: stack.push(arg5); // 21 5
199.1072 - case 68: arg5++; // 132 5 1
199.1073 - case 71: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1074 - case 72: if (stack.pop() == stack.pop()) { gt = 50; continue; } // 159 255 234
199.1075 - case 75: stack.push(0); // 3
199.1076 - case 76: return stack.pop(); // 172
199.1077 - case 77: stack.push(arg1); // 43
199.1078 - case 78: stack.push(arg0); // 42
199.1079 - case 79: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.equalsZLjava_lang_Object(self, v0)); } // 182 1 131
199.1080 - case 82: if (stack.pop() == 0) { gt = 87; continue; } // 153 0 5
199.1081 - case 85: stack.push(1); // 4
199.1082 - case 86: return stack.pop(); // 172
199.1083 - case 87: stack.push(arg0); // 42
199.1084 - case 88: stack.push(stack.pop().value); // 180 1 100
199.1085 - case 91: arg2 = stack.pop(); // 77
199.1086 - case 92: stack.push(arg0); // 42
199.1087 - case 93: stack.push(stack.pop().offset); // 180 1 99
199.1088 - case 96: arg3 = stack.pop(); // 62
199.1089 - case 97: stack.push(0); // 3
199.1090 - case 98: arg4 = stack.pop() // 54 4
199.1091 - case 100: stack.push(arg0); // 42
199.1092 - case 101: stack.push(stack.pop().count); // 180 1 97
199.1093 - case 104: arg5 = stack.pop() // 54 5
199.1094 - case 106: stack.push(arg5); // 21 5
199.1095 - case 108: arg5 += 255; // 132 5 255
199.1096 - case 111: if (stack.pop() == 0) { gt = 136; continue; } // 153 0 25
199.1097 - case 114: stack.push(arg2); // 44
199.1098 - case 115: stack.push(arg3); // 29
199.1099 - case 116: arg3++; // 132 3 1
199.1100 - case 119: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1101 - case 120: stack.push(arg1); // 43
199.1102 - case 121: stack.push(arg4); // 21 4
199.1103 - case 123: arg4++; // 132 4 1
199.1104 - case 126: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.charAtCI(self, v0)); } // 185 1 189
199.1105 - case 129: // 2
199.1106 - case 130: // 0
199.1107 - case 131: if (stack.pop() == stack.pop()) { gt = 106; continue; } // 159 255 231
199.1108 - case 134: stack.push(0); // 3
199.1109 - case 135: return stack.pop(); // 172
199.1110 - case 136: stack.push(1); // 4
199.1111 - case 137: return stack.pop(); // 172
199.1112 - }
199.1113 -}
199.1114 -function java_lang_String_equalsIgnoreCaseZLjava_lang_String(arg0,arg1) {
199.1115 - var arg2;
199.1116 -;
199.1117 - var stack = new Array(6);
199.1118 - var gt = 0;
199.1119 - for(;;) switch(gt) {
199.1120 - case 0: stack.push(arg0); // 42
199.1121 - case 1: stack.push(arg1); // 43
199.1122 - case 2: // 166
199.1123 - case 3: // 0
199.1124 - case 4: stack.push(4); // 7
199.1125 - case 5: stack.push(1); // 4
199.1126 - case 6: gt = 44; continue; // 167 0 38
199.1127 - case 9: stack.push(arg1); // 43
199.1128 - case 10: if (!stack.pop()) { gt = 43; continue; } // 198 0 33
199.1129 - case 13: stack.push(arg1); // 43
199.1130 - case 14: stack.push(stack.pop().count); // 180 1 97
199.1131 - case 17: stack.push(arg0); // 42
199.1132 - case 18: stack.push(stack.pop().count); // 180 1 97
199.1133 - case 21: if (stack.pop() != stack.pop()) { gt = 43; continue; } // 160 0 22
199.1134 - case 24: stack.push(arg0); // 42
199.1135 - case 25: stack.push(1); // 4
199.1136 - case 26: stack.push(0); // 3
199.1137 - case 27: stack.push(arg1); // 43
199.1138 - case 28: stack.push(0); // 3
199.1139 - case 29: stack.push(arg0); // 42
199.1140 - case 30: stack.push(stack.pop().count); // 180 1 97
199.1141 - case 33: { var v4 = stack.pop(); var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.regionMatchesZZILjava_lang_StringII(self, v0, v1, v2, v3, v4)); } // 182 1 153
199.1142 - case 36: if (stack.pop() == 0) { gt = 43; continue; } // 153 0 7
199.1143 - case 39: stack.push(1); // 4
199.1144 - case 40: gt = 44; continue; // 167 0 4
199.1145 - case 43: stack.push(0); // 3
199.1146 - case 44: return stack.pop(); // 172
199.1147 - }
199.1148 -}
199.1149 -function java_lang_String_compareToILjava_lang_String(arg0,arg1) {
199.1150 - var arg2;
199.1151 - var arg3;
199.1152 - var arg4;
199.1153 - var arg5;
199.1154 - var arg6;
199.1155 - var arg7;
199.1156 - var arg8;
199.1157 - var arg9;
199.1158 - var arg10;
199.1159 - var arg11;
199.1160 - var arg12;
199.1161 - var arg13;
199.1162 -;
199.1163 - var stack = new Array(2);
199.1164 - var gt = 0;
199.1165 - for(;;) switch(gt) {
199.1166 - case 0: stack.push(arg0); // 42
199.1167 - case 1: stack.push(stack.pop().count); // 180 1 97
199.1168 - case 4: arg2 = stack.pop(); // 61
199.1169 - case 5: stack.push(arg1); // 43
199.1170 - case 6: stack.push(stack.pop().count); // 180 1 97
199.1171 - case 9: arg3 = stack.pop(); // 62
199.1172 - case 10: stack.push(arg2); // 28
199.1173 - case 11: stack.push(arg3); // 29
199.1174 - case 12: { var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_Math_minIII(v0, v1)); } // 184 1 127
199.1175 - case 15: arg4 = stack.pop() // 54 4
199.1176 - case 17: stack.push(arg0); // 42
199.1177 - case 18: stack.push(stack.pop().value); // 180 1 100
199.1178 - case 21: arg5 = stack.pop() // 58 5
199.1179 - case 23: stack.push(arg1); // 43
199.1180 - case 24: stack.push(stack.pop().value); // 180 1 100
199.1181 - case 27: arg6 = stack.pop() // 58 6
199.1182 - case 29: stack.push(arg0); // 42
199.1183 - case 30: stack.push(stack.pop().offset); // 180 1 99
199.1184 - case 33: arg7 = stack.pop() // 54 7
199.1185 - case 35: stack.push(arg1); // 43
199.1186 - case 36: stack.push(stack.pop().offset); // 180 1 99
199.1187 - case 39: arg8 = stack.pop() // 54 8
199.1188 - case 41: stack.push(arg7); // 21 7
199.1189 - case 43: stack.push(arg8); // 21 8
199.1190 - case 45: if (stack.pop() != stack.pop()) { gt = 102; continue; } // 160 0 57
199.1191 - case 48: stack.push(arg7); // 21 7
199.1192 - case 50: arg9 = stack.pop() // 54 9
199.1193 - case 52: stack.push(arg4); // 21 4
199.1194 - case 54: stack.push(arg7); // 21 7
199.1195 - case 56: stack.push(stack.pop() + stack.pop()); // 96
199.1196 - case 57: arg10 = stack.pop() // 54 10
199.1197 - case 59: stack.push(arg9); // 21 9
199.1198 - case 61: stack.push(arg10); // 21 10
199.1199 - case 63: if (stack.pop() <= stack.pop()) { gt = 99; continue; } // 162 0 36
199.1200 - case 66: stack.push(arg5); // 25 5
199.1201 - case 68: stack.push(arg9); // 21 9
199.1202 - case 70: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1203 - case 71: arg11 = stack.pop() // 54 11
199.1204 - case 73: stack.push(arg6); // 25 6
199.1205 - case 75: stack.push(arg9); // 21 9
199.1206 - case 77: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1207 - case 78: arg12 = stack.pop() // 54 12
199.1208 - case 80: stack.push(arg11); // 21 11
199.1209 - case 82: stack.push(arg12); // 21 12
199.1210 - case 84: if (stack.pop() == stack.pop()) { gt = 93; continue; } // 159 0 9
199.1211 - case 87: stack.push(arg11); // 21 11
199.1212 - case 89: stack.push(arg12); // 21 12
199.1213 - case 91: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.1214 - case 92: return stack.pop(); // 172
199.1215 - case 93: arg9++; // 132 9 1
199.1216 - case 96: gt = 59; continue; // 167 255 219
199.1217 - case 99: gt = 146; continue; // 167 0 47
199.1218 - case 102: stack.push(arg4); // 21 4
199.1219 - case 104: arg4 += 255; // 132 4 255
199.1220 - case 107: if (stack.pop() == 0) { gt = 146; continue; } // 153 0 39
199.1221 - case 110: stack.push(arg5); // 25 5
199.1222 - case 112: stack.push(arg7); // 21 7
199.1223 - case 114: arg7++; // 132 7 1
199.1224 - case 117: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1225 - case 118: arg9 = stack.pop() // 54 9
199.1226 - case 120: stack.push(arg6); // 25 6
199.1227 - case 122: stack.push(arg8); // 21 8
199.1228 - case 124: arg8++; // 132 8 1
199.1229 - case 127: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1230 - case 128: arg10 = stack.pop() // 54 10
199.1231 - case 130: stack.push(arg9); // 21 9
199.1232 - case 132: stack.push(arg10); // 21 10
199.1233 - case 134: if (stack.pop() == stack.pop()) { gt = 143; continue; } // 159 0 9
199.1234 - case 137: stack.push(arg9); // 21 9
199.1235 - case 139: stack.push(arg10); // 21 10
199.1236 - case 141: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.1237 - case 142: return stack.pop(); // 172
199.1238 - case 143: gt = 102; continue; // 167 255 215
199.1239 - case 146: stack.push(arg2); // 28
199.1240 - case 147: stack.push(arg3); // 29
199.1241 - case 148: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.1242 - case 149: return stack.pop(); // 172
199.1243 - }
199.1244 -}
199.1245 -function java_lang_String_compareToIgnoreCaseILjava_lang_String(arg0,arg1) {
199.1246 - var arg2;
199.1247 -;
199.1248 - var stack = new Array(3);
199.1249 - var gt = 0;
199.1250 - for(;;) switch(gt) {
199.1251 - case 0: stack.push(java_lang_String_CASE_INSENSITIVE_ORDER); // 178 1 102
199.1252 - case 3: stack.push(arg0); // 42
199.1253 - case 4: stack.push(arg1); // 43
199.1254 - case 5: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.compareILjava_lang_ObjectLjava_lang_Object(self, v0, v1)); } // 185 1 190
199.1255 - case 8: stack.push(0); // 3
199.1256 - case 9: // 0
199.1257 - case 10: return stack.pop(); // 172
199.1258 - }
199.1259 -}
199.1260 -function java_lang_String_regionMatchesZILjava_lang_StringII(arg0,arg1,arg2,arg3,arg4) {
199.1261 - var arg5;
199.1262 - var arg6;
199.1263 - var arg7;
199.1264 - var arg8;
199.1265 - var arg9;
199.1266 -;
199.1267 - var stack = new Array(6);
199.1268 - var gt = 0;
199.1269 - for(;;) switch(gt) {
199.1270 - case 0: stack.push(arg0); // 42
199.1271 - case 1: stack.push(stack.pop().value); // 180 1 100
199.1272 - case 4: arg5 = stack.pop() // 58 5
199.1273 - case 6: stack.push(arg0); // 42
199.1274 - case 7: stack.push(stack.pop().offset); // 180 1 99
199.1275 - case 10: stack.push(arg1); // 27
199.1276 - case 11: stack.push(stack.pop() + stack.pop()); // 96
199.1277 - case 12: arg6 = stack.pop() // 54 6
199.1278 - case 14: stack.push(arg2); // 44
199.1279 - case 15: stack.push(stack.pop().value); // 180 1 100
199.1280 - case 18: arg7 = stack.pop() // 58 7
199.1281 - case 20: stack.push(arg2); // 44
199.1282 - case 21: stack.push(stack.pop().offset); // 180 1 99
199.1283 - case 24: stack.push(arg3); // 29
199.1284 - case 25: stack.push(stack.pop() + stack.pop()); // 96
199.1285 - case 26: arg8 = stack.pop() // 54 8
199.1286 - case 28: stack.push(arg3); // 29
199.1287 - case 29: if (stack.pop() < 0) { gt = 66; continue; } // 155 0 37
199.1288 - case 32: stack.push(arg1); // 27
199.1289 - case 33: if (stack.pop() < 0) { gt = 66; continue; } // 155 0 33
199.1290 - case 36: stack.push(arg1); // 27
199.1291 - case 37: // number conversion // 133
199.1292 - case 38: stack.push(arg0); // 42
199.1293 - case 39: stack.push(stack.pop().count); // 180 1 97
199.1294 - case 42: // number conversion // 133
199.1295 - case 43: stack.push(arg4); // 21 4
199.1296 - case 45: // number conversion // 133
199.1297 - case 46: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 101
199.1298 - case 47: { var delta = stack.pop() - stack.pop(); stack.push(delta < 0 ?-1 : (delta == 0 ? 0 : 1)); } // 148
199.1299 - case 48: if (stack.pop() > 0) { gt = 66; continue; } // 157 0 18
199.1300 - case 51: stack.push(arg3); // 29
199.1301 - case 52: // number conversion // 133
199.1302 - case 53: stack.push(arg2); // 44
199.1303 - case 54: stack.push(stack.pop().count); // 180 1 97
199.1304 - case 57: // number conversion // 133
199.1305 - case 58: stack.push(arg4); // 21 4
199.1306 - case 60: // number conversion // 133
199.1307 - case 61: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 101
199.1308 - case 62: { var delta = stack.pop() - stack.pop(); stack.push(delta < 0 ?-1 : (delta == 0 ? 0 : 1)); } // 148
199.1309 - case 63: if (stack.pop() <= 0) { gt = 68; continue; } // 158 0 5
199.1310 - case 66: stack.push(0); // 3
199.1311 - case 67: return stack.pop(); // 172
199.1312 - case 68: stack.push(arg4); // 21 4
199.1313 - case 70: arg4 += 255; // 132 4 255
199.1314 - case 73: if (stack.pop() <= 0) { gt = 97; continue; } // 158 0 24
199.1315 - case 76: stack.push(arg5); // 25 5
199.1316 - case 78: stack.push(arg6); // 21 6
199.1317 - case 80: arg6++; // 132 6 1
199.1318 - case 83: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1319 - case 84: stack.push(arg7); // 25 7
199.1320 - case 86: stack.push(arg8); // 21 8
199.1321 - case 88: arg8++; // 132 8 1
199.1322 - case 91: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1323 - case 92: if (stack.pop() == stack.pop()) { gt = 68; continue; } // 159 255 232
199.1324 - case 95: stack.push(0); // 3
199.1325 - case 96: return stack.pop(); // 172
199.1326 - case 97: stack.push(1); // 4
199.1327 - case 98: return stack.pop(); // 172
199.1328 - }
199.1329 -}
199.1330 -function java_lang_String_regionMatchesZZILjava_lang_StringII(arg0,arg1,arg2,arg3,arg4,arg5) {
199.1331 - var arg6;
199.1332 - var arg7;
199.1333 - var arg8;
199.1334 - var arg9;
199.1335 - var arg10;
199.1336 - var arg11;
199.1337 - var arg12;
199.1338 - var arg13;
199.1339 - var arg14;
199.1340 -;
199.1341 - var stack = new Array(6);
199.1342 - var gt = 0;
199.1343 - for(;;) switch(gt) {
199.1344 - case 0: stack.push(arg0); // 42
199.1345 - case 1: stack.push(stack.pop().value); // 180 1 100
199.1346 - case 4: arg6 = stack.pop() // 58 6
199.1347 - case 6: stack.push(arg0); // 42
199.1348 - case 7: stack.push(stack.pop().offset); // 180 1 99
199.1349 - case 10: stack.push(arg2); // 28
199.1350 - case 11: stack.push(stack.pop() + stack.pop()); // 96
199.1351 - case 12: arg7 = stack.pop() // 54 7
199.1352 - case 14: stack.push(arg3); // 45
199.1353 - case 15: stack.push(stack.pop().value); // 180 1 100
199.1354 - case 18: arg8 = stack.pop() // 58 8
199.1355 - case 20: stack.push(arg3); // 45
199.1356 - case 21: stack.push(stack.pop().offset); // 180 1 99
199.1357 - case 24: stack.push(arg4); // 21 4
199.1358 - case 26: stack.push(stack.pop() + stack.pop()); // 96
199.1359 - case 27: arg9 = stack.pop() // 54 9
199.1360 - case 29: stack.push(arg4); // 21 4
199.1361 - case 31: if (stack.pop() < 0) { gt = 69; continue; } // 155 0 38
199.1362 - case 34: stack.push(arg2); // 28
199.1363 - case 35: if (stack.pop() < 0) { gt = 69; continue; } // 155 0 34
199.1364 - case 38: stack.push(arg2); // 28
199.1365 - case 39: // number conversion // 133
199.1366 - case 40: stack.push(arg0); // 42
199.1367 - case 41: stack.push(stack.pop().count); // 180 1 97
199.1368 - case 44: // number conversion // 133
199.1369 - case 45: stack.push(arg5); // 21 5
199.1370 - case 47: // number conversion // 133
199.1371 - case 48: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 101
199.1372 - case 49: { var delta = stack.pop() - stack.pop(); stack.push(delta < 0 ?-1 : (delta == 0 ? 0 : 1)); } // 148
199.1373 - case 50: if (stack.pop() > 0) { gt = 69; continue; } // 157 0 19
199.1374 - case 53: stack.push(arg4); // 21 4
199.1375 - case 55: // number conversion // 133
199.1376 - case 56: stack.push(arg3); // 45
199.1377 - case 57: stack.push(stack.pop().count); // 180 1 97
199.1378 - case 60: // number conversion // 133
199.1379 - case 61: stack.push(arg5); // 21 5
199.1380 - case 63: // number conversion // 133
199.1381 - case 64: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 101
199.1382 - case 65: { var delta = stack.pop() - stack.pop(); stack.push(delta < 0 ?-1 : (delta == 0 ? 0 : 1)); } // 148
199.1383 - case 66: if (stack.pop() <= 0) { gt = 71; continue; } // 158 0 5
199.1384 - case 69: stack.push(0); // 3
199.1385 - case 70: return stack.pop(); // 172
199.1386 - case 71: stack.push(arg5); // 21 5
199.1387 - case 73: arg5 += 255; // 132 5 255
199.1388 - case 76: if (stack.pop() <= 0) { gt = 155; continue; } // 158 0 79
199.1389 - case 79: stack.push(arg6); // 25 6
199.1390 - case 81: stack.push(arg7); // 21 7
199.1391 - case 83: arg7++; // 132 7 1
199.1392 - case 86: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1393 - case 87: arg10 = stack.pop() // 54 10
199.1394 - case 89: stack.push(arg8); // 25 8
199.1395 - case 91: stack.push(arg9); // 21 9
199.1396 - case 93: arg9++; // 132 9 1
199.1397 - case 96: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1398 - case 97: arg11 = stack.pop() // 54 11
199.1399 - case 99: stack.push(arg10); // 21 10
199.1400 - case 101: stack.push(arg11); // 21 11
199.1401 - case 103: if (stack.pop() != stack.pop()) { gt = 109; continue; } // 160 0 6
199.1402 - case 106: gt = 71; continue; // 167 255 221
199.1403 - case 109: stack.push(arg1); // 27
199.1404 - case 110: if (stack.pop() == 0) { gt = 153; continue; } // 153 0 43
199.1405 - case 113: stack.push(arg10); // 21 10
199.1406 - case 115: { var v0 = stack.pop(); stack.push(java_lang_Character_toUpperCaseCC(v0)); } // 184 1 105
199.1407 - case 118: arg12 = stack.pop() // 54 12
199.1408 - case 120: stack.push(arg11); // 21 11
199.1409 - case 122: { var v0 = stack.pop(); stack.push(java_lang_Character_toUpperCaseCC(v0)); } // 184 1 105
199.1410 - case 125: arg13 = stack.pop() // 54 13
199.1411 - case 127: stack.push(arg12); // 21 12
199.1412 - case 129: stack.push(arg13); // 21 13
199.1413 - case 131: if (stack.pop() != stack.pop()) { gt = 137; continue; } // 160 0 6
199.1414 - case 134: gt = 71; continue; // 167 255 193
199.1415 - case 137: stack.push(arg12); // 21 12
199.1416 - case 139: { var v0 = stack.pop(); stack.push(java_lang_Character_toLowerCaseCC(v0)); } // 184 1 104
199.1417 - case 142: stack.push(arg13); // 21 13
199.1418 - case 144: { var v0 = stack.pop(); stack.push(java_lang_Character_toLowerCaseCC(v0)); } // 184 1 104
199.1419 - case 147: if (stack.pop() != stack.pop()) { gt = 153; continue; } // 160 0 6
199.1420 - case 150: gt = 71; continue; // 167 255 177
199.1421 - case 153: stack.push(0); // 3
199.1422 - case 154: return stack.pop(); // 172
199.1423 - case 155: stack.push(1); // 4
199.1424 - case 156: return stack.pop(); // 172
199.1425 - }
199.1426 -}
199.1427 -function java_lang_String_startsWithZLjava_lang_StringI(arg0,arg1,arg2) {
199.1428 - var arg3;
199.1429 - var arg4;
199.1430 - var arg5;
199.1431 - var arg6;
199.1432 - var arg7;
199.1433 - var arg8;
199.1434 -;
199.1435 - var stack = new Array(3);
199.1436 - var gt = 0;
199.1437 - for(;;) switch(gt) {
199.1438 - case 0: stack.push(arg0); // 42
199.1439 - case 1: stack.push(stack.pop().value); // 180 1 100
199.1440 - case 4: arg3 = stack.pop(); // 78
199.1441 - case 5: stack.push(arg0); // 42
199.1442 - case 6: stack.push(stack.pop().offset); // 180 1 99
199.1443 - case 9: stack.push(arg2); // 28
199.1444 - case 10: stack.push(stack.pop() + stack.pop()); // 96
199.1445 - case 11: arg4 = stack.pop() // 54 4
199.1446 - case 13: stack.push(arg1); // 43
199.1447 - case 14: stack.push(stack.pop().value); // 180 1 100
199.1448 - case 17: arg5 = stack.pop() // 58 5
199.1449 - case 19: stack.push(arg1); // 43
199.1450 - case 20: stack.push(stack.pop().offset); // 180 1 99
199.1451 - case 23: arg6 = stack.pop() // 54 6
199.1452 - case 25: stack.push(arg1); // 43
199.1453 - case 26: stack.push(stack.pop().count); // 180 1 97
199.1454 - case 29: arg7 = stack.pop() // 54 7
199.1455 - case 31: stack.push(arg2); // 28
199.1456 - case 32: if (stack.pop() < 0) { gt = 46; continue; } // 155 0 14
199.1457 - case 35: stack.push(arg2); // 28
199.1458 - case 36: stack.push(arg0); // 42
199.1459 - case 37: stack.push(stack.pop().count); // 180 1 97
199.1460 - case 40: stack.push(arg7); // 21 7
199.1461 - case 42: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.1462 - case 43: if (stack.pop() >= stack.pop()) { gt = 48; continue; } // 164 0 5
199.1463 - case 46: stack.push(0); // 3
199.1464 - case 47: return stack.pop(); // 172
199.1465 - case 48: arg7 += 255; // 132 7 255
199.1466 - case 51: stack.push(arg7); // 21 7
199.1467 - case 53: if (stack.pop() < 0) { gt = 76; continue; } // 155 0 23
199.1468 - case 56: stack.push(arg3); // 45
199.1469 - case 57: stack.push(arg4); // 21 4
199.1470 - case 59: arg4++; // 132 4 1
199.1471 - case 62: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1472 - case 63: stack.push(arg5); // 25 5
199.1473 - case 65: stack.push(arg6); // 21 6
199.1474 - case 67: arg6++; // 132 6 1
199.1475 - case 70: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1476 - case 71: if (stack.pop() == stack.pop()) { gt = 48; continue; } // 159 255 233
199.1477 - case 74: stack.push(0); // 3
199.1478 - case 75: return stack.pop(); // 172
199.1479 - case 76: stack.push(1); // 4
199.1480 - case 77: return stack.pop(); // 172
199.1481 - }
199.1482 -}
199.1483 -function java_lang_String_startsWithZLjava_lang_String(arg0,arg1) {
199.1484 - var arg2;
199.1485 -;
199.1486 - var stack = new Array(3);
199.1487 - var gt = 0;
199.1488 - for(;;) switch(gt) {
199.1489 - case 0: stack.push(arg0); // 42
199.1490 - case 1: stack.push(arg1); // 43
199.1491 - case 2: stack.push(0); // 3
199.1492 - case 3: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.startsWithZLjava_lang_StringI(self, v0, v1)); } // 182 1 152
199.1493 - case 6: return stack.pop(); // 172
199.1494 - }
199.1495 -}
199.1496 -function java_lang_String_endsWithZLjava_lang_String(arg0,arg1) {
199.1497 - var arg2;
199.1498 -;
199.1499 - var stack = new Array(4);
199.1500 - var gt = 0;
199.1501 - for(;;) switch(gt) {
199.1502 - case 0: stack.push(arg0); // 42
199.1503 - case 1: stack.push(arg1); // 43
199.1504 - case 2: stack.push(arg0); // 42
199.1505 - case 3: stack.push(stack.pop().count); // 180 1 97
199.1506 - case 6: stack.push(arg1); // 43
199.1507 - case 7: stack.push(stack.pop().count); // 180 1 97
199.1508 - case 10: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.1509 - case 11: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.startsWithZLjava_lang_StringI(self, v0, v1)); } // 182 1 152
199.1510 - case 14: return stack.pop(); // 172
199.1511 - }
199.1512 -}
199.1513 -function java_lang_String_hashCodeI(arg0) {
199.1514 - var arg1;
199.1515 - var arg2;
199.1516 - var arg3;
199.1517 - var arg4;
199.1518 - var arg5;
199.1519 - var arg6;
199.1520 -;
199.1521 - var stack = new Array(3);
199.1522 - var gt = 0;
199.1523 - for(;;) switch(gt) {
199.1524 - case 0: stack.push(arg0); // 42
199.1525 - case 1: stack.push(stack.pop().hash); // 180 1 98
199.1526 - case 4: arg1 = stack.pop(); // 60
199.1527 - case 5: stack.push(arg0); // 42
199.1528 - case 6: stack.push(stack.pop().count); // 180 1 97
199.1529 - case 9: arg2 = stack.pop(); // 61
199.1530 - case 10: stack.push(arg1); // 27
199.1531 - case 11: if (stack.pop() != 0) { gt = 62; continue; } // 154 0 51
199.1532 - case 14: stack.push(arg2); // 28
199.1533 - case 15: if (stack.pop() <= 0) { gt = 62; continue; } // 158 0 47
199.1534 - case 18: stack.push(arg0); // 42
199.1535 - case 19: stack.push(stack.pop().offset); // 180 1 99
199.1536 - case 22: arg3 = stack.pop(); // 62
199.1537 - case 23: stack.push(arg0); // 42
199.1538 - case 24: stack.push(stack.pop().value); // 180 1 100
199.1539 - case 27: arg4 = stack.pop() // 58 4
199.1540 - case 29: stack.push(0); // 3
199.1541 - case 30: arg5 = stack.pop() // 54 5
199.1542 - case 32: stack.push(arg5); // 21 5
199.1543 - case 34: stack.push(arg2); // 28
199.1544 - case 35: if (stack.pop() <= stack.pop()) { gt = 57; continue; } // 162 0 22
199.1545 - case 38: stack.push(31); // 16 31
199.1546 - case 40: stack.push(arg1); // 27
199.1547 - case 41: stack.push(stack.pop() * stack.pop()); // 104
199.1548 - case 42: stack.push(arg4); // 25 4
199.1549 - case 44: stack.push(arg3); // 29
199.1550 - case 45: arg3++; // 132 3 1
199.1551 - case 48: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1552 - case 49: stack.push(stack.pop() + stack.pop()); // 96
199.1553 - case 50: arg1 = stack.pop(); // 60
199.1554 - case 51: arg5++; // 132 5 1
199.1555 - case 54: gt = 32; continue; // 167 255 234
199.1556 - case 57: stack.push(arg0); // 42
199.1557 - case 58: stack.push(arg1); // 27
199.1558 - case 59: { var v = stack.pop(); stack.pop().hash = v; } // 181 1 98
199.1559 - case 62: stack.push(arg1); // 27
199.1560 - case 63: return stack.pop(); // 172
199.1561 - }
199.1562 -}
199.1563 -function java_lang_String_indexOfII(arg0,arg1) {
199.1564 - var arg2;
199.1565 -;
199.1566 - var stack = new Array(3);
199.1567 - var gt = 0;
199.1568 - for(;;) switch(gt) {
199.1569 - case 0: stack.push(arg0); // 42
199.1570 - case 1: stack.push(arg1); // 27
199.1571 - case 2: stack.push(0); // 3
199.1572 - case 3: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.indexOfIII(self, v0, v1)); } // 182 1 135
199.1573 - case 6: return stack.pop(); // 172
199.1574 - }
199.1575 -}
199.1576 -function java_lang_String_indexOfIII(arg0,arg1,arg2) {
199.1577 - var arg3;
199.1578 - var arg4;
199.1579 - var arg5;
199.1580 - var arg6;
199.1581 - var arg7;
199.1582 -;
199.1583 - var stack = new Array(3);
199.1584 - var gt = 0;
199.1585 - for(;;) switch(gt) {
199.1586 - case 0: stack.push(arg0); // 42
199.1587 - case 1: stack.push(stack.pop().offset); // 180 1 99
199.1588 - case 4: stack.push(arg0); // 42
199.1589 - case 5: stack.push(stack.pop().count); // 180 1 97
199.1590 - case 8: stack.push(stack.pop() + stack.pop()); // 96
199.1591 - case 9: arg3 = stack.pop(); // 62
199.1592 - case 10: stack.push(arg0); // 42
199.1593 - case 11: stack.push(stack.pop().value); // 180 1 100
199.1594 - case 14: arg4 = stack.pop() // 58 4
199.1595 - case 16: stack.push(arg2); // 28
199.1596 - case 17: if (stack.pop() >= 0) { gt = 25; continue; } // 156 0 8
199.1597 - case 20: stack.push(0); // 3
199.1598 - case 21: arg2 = stack.pop(); // 61
199.1599 - case 22: gt = 35; continue; // 167 0 13
199.1600 - case 25: stack.push(arg2); // 28
199.1601 - case 26: stack.push(arg0); // 42
199.1602 - case 27: stack.push(stack.pop().count); // 180 1 97
199.1603 - case 30: if (stack.pop() > stack.pop()) { gt = 35; continue; } // 161 0 5
199.1604 - case 33: // 2
199.1605 - case 34: return stack.pop(); // 172
199.1606 - case 35: stack.push(arg0); // 42
199.1607 - case 36: stack.push(stack.pop().offset); // 180 1 99
199.1608 - case 39: stack.push(arg2); // 28
199.1609 - case 40: stack.push(stack.pop() + stack.pop()); // 96
199.1610 - case 41: arg5 = stack.pop() // 54 5
199.1611 - case 43: stack.push(arg1); // 27
199.1612 - case 44: stack.push(65536); // 18 3
199.1613 - case 46: if (stack.pop() <= stack.pop()) { gt = 80; continue; } // 162 0 34
199.1614 - case 49: stack.push(arg5); // 21 5
199.1615 - case 51: stack.push(arg3); // 29
199.1616 - case 52: if (stack.pop() <= stack.pop()) { gt = 78; continue; } // 162 0 26
199.1617 - case 55: stack.push(arg4); // 25 4
199.1618 - case 57: stack.push(arg5); // 21 5
199.1619 - case 59: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1620 - case 60: stack.push(arg1); // 27
199.1621 - case 61: if (stack.pop() != stack.pop()) { gt = 72; continue; } // 160 0 11
199.1622 - case 64: stack.push(arg5); // 21 5
199.1623 - case 66: stack.push(arg0); // 42
199.1624 - case 67: stack.push(stack.pop().offset); // 180 1 99
199.1625 - case 70: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.1626 - case 71: return stack.pop(); // 172
199.1627 - case 72: arg5++; // 132 5 1
199.1628 - case 75: gt = 49; continue; // 167 255 230
199.1629 - case 78: // 2
199.1630 - case 79: return stack.pop(); // 172
199.1631 - case 80: stack.push(arg1); // 27
199.1632 - case 81: stack.push(1114111); // 18 4
199.1633 - case 83: if (stack.pop() < stack.pop()) { gt = 149; continue; } // 163 0 66
199.1634 - case 86: stack.push(arg1); // 27
199.1635 - case 87: { var v0 = stack.pop(); stack.push(java_lang_Character_toCharsACI(v0)); } // 184 1 109
199.1636 - case 90: arg6 = stack.pop() // 58 6
199.1637 - case 92: stack.push(arg5); // 21 5
199.1638 - case 94: stack.push(arg3); // 29
199.1639 - case 95: if (stack.pop() <= stack.pop()) { gt = 149; continue; } // 162 0 54
199.1640 - case 98: stack.push(arg4); // 25 4
199.1641 - case 100: stack.push(arg5); // 21 5
199.1642 - case 102: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1643 - case 103: stack.push(arg6); // 25 6
199.1644 - case 105: stack.push(0); // 3
199.1645 - case 106: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1646 - case 107: if (stack.pop() != stack.pop()) { gt = 143; continue; } // 160 0 36
199.1647 - case 110: stack.push(arg5); // 21 5
199.1648 - case 112: stack.push(1); // 4
199.1649 - case 113: stack.push(stack.pop() + stack.pop()); // 96
199.1650 - case 114: stack.push(arg3); // 29
199.1651 - case 115: if (stack.pop() != stack.pop()) { gt = 121; continue; } // 160 0 6
199.1652 - case 118: gt = 149; continue; // 167 0 31
199.1653 - case 121: stack.push(arg4); // 25 4
199.1654 - case 123: stack.push(arg5); // 21 5
199.1655 - case 125: stack.push(1); // 4
199.1656 - case 126: stack.push(stack.pop() + stack.pop()); // 96
199.1657 - case 127: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1658 - case 128: stack.push(arg6); // 25 6
199.1659 - case 130: stack.push(1); // 4
199.1660 - case 131: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1661 - case 132: if (stack.pop() != stack.pop()) { gt = 143; continue; } // 160 0 11
199.1662 - case 135: stack.push(arg5); // 21 5
199.1663 - case 137: stack.push(arg0); // 42
199.1664 - case 138: stack.push(stack.pop().offset); // 180 1 99
199.1665 - case 141: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.1666 - case 142: return stack.pop(); // 172
199.1667 - case 143: arg5++; // 132 5 1
199.1668 - case 146: gt = 92; continue; // 167 255 202
199.1669 - case 149: // 2
199.1670 - case 150: return stack.pop(); // 172
199.1671 - }
199.1672 -}
199.1673 -function java_lang_String_lastIndexOfII(arg0,arg1) {
199.1674 - var arg2;
199.1675 -;
199.1676 - var stack = new Array(4);
199.1677 - var gt = 0;
199.1678 - for(;;) switch(gt) {
199.1679 - case 0: stack.push(arg0); // 42
199.1680 - case 1: stack.push(arg1); // 27
199.1681 - case 2: stack.push(arg0); // 42
199.1682 - case 3: stack.push(stack.pop().count); // 180 1 97
199.1683 - case 6: stack.push(1); // 4
199.1684 - case 7: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.1685 - case 8: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.lastIndexOfIII(self, v0, v1)); } // 182 1 136
199.1686 - case 11: return stack.pop(); // 172
199.1687 - }
199.1688 -}
199.1689 -function java_lang_String_lastIndexOfIII(arg0,arg1,arg2) {
199.1690 - var arg3;
199.1691 - var arg4;
199.1692 - var arg5;
199.1693 - var arg6;
199.1694 - var arg7;
199.1695 - var arg8;
199.1696 -;
199.1697 - var stack = new Array(3);
199.1698 - var gt = 0;
199.1699 - for(;;) switch(gt) {
199.1700 - case 0: stack.push(arg0); // 42
199.1701 - case 1: stack.push(stack.pop().offset); // 180 1 99
199.1702 - case 4: arg3 = stack.pop(); // 62
199.1703 - case 5: stack.push(arg0); // 42
199.1704 - case 6: stack.push(stack.pop().value); // 180 1 100
199.1705 - case 9: arg4 = stack.pop() // 58 4
199.1706 - case 11: stack.push(arg0); // 42
199.1707 - case 12: stack.push(stack.pop().offset); // 180 1 99
199.1708 - case 15: stack.push(arg2); // 28
199.1709 - case 16: stack.push(arg0); // 42
199.1710 - case 17: stack.push(stack.pop().count); // 180 1 97
199.1711 - case 20: if (stack.pop() > stack.pop()) { gt = 32; continue; } // 161 0 12
199.1712 - case 23: stack.push(arg0); // 42
199.1713 - case 24: stack.push(stack.pop().count); // 180 1 97
199.1714 - case 27: stack.push(1); // 4
199.1715 - case 28: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.1716 - case 29: gt = 33; continue; // 167 0 4
199.1717 - case 32: stack.push(arg2); // 28
199.1718 - case 33: stack.push(stack.pop() + stack.pop()); // 96
199.1719 - case 34: arg5 = stack.pop() // 54 5
199.1720 - case 36: stack.push(arg1); // 27
199.1721 - case 37: stack.push(65536); // 18 3
199.1722 - case 39: if (stack.pop() <= stack.pop()) { gt = 73; continue; } // 162 0 34
199.1723 - case 42: stack.push(arg5); // 21 5
199.1724 - case 44: stack.push(arg3); // 29
199.1725 - case 45: if (stack.pop() > stack.pop()) { gt = 71; continue; } // 161 0 26
199.1726 - case 48: stack.push(arg4); // 25 4
199.1727 - case 50: stack.push(arg5); // 21 5
199.1728 - case 52: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1729 - case 53: stack.push(arg1); // 27
199.1730 - case 54: if (stack.pop() != stack.pop()) { gt = 65; continue; } // 160 0 11
199.1731 - case 57: stack.push(arg5); // 21 5
199.1732 - case 59: stack.push(arg0); // 42
199.1733 - case 60: stack.push(stack.pop().offset); // 180 1 99
199.1734 - case 63: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.1735 - case 64: return stack.pop(); // 172
199.1736 - case 65: arg5 += 255; // 132 5 255
199.1737 - case 68: gt = 42; continue; // 167 255 230
199.1738 - case 71: // 2
199.1739 - case 72: return stack.pop(); // 172
199.1740 - case 73: stack.push(arg0); // 42
199.1741 - case 74: stack.push(stack.pop().offset); // 180 1 99
199.1742 - case 77: stack.push(arg0); // 42
199.1743 - case 78: stack.push(stack.pop().count); // 180 1 97
199.1744 - case 81: stack.push(stack.pop() + stack.pop()); // 96
199.1745 - case 82: arg6 = stack.pop() // 54 6
199.1746 - case 84: stack.push(arg1); // 27
199.1747 - case 85: stack.push(1114111); // 18 4
199.1748 - case 87: if (stack.pop() < stack.pop()) { gt = 154; continue; } // 163 0 67
199.1749 - case 90: stack.push(arg1); // 27
199.1750 - case 91: { var v0 = stack.pop(); stack.push(java_lang_Character_toCharsACI(v0)); } // 184 1 109
199.1751 - case 94: arg7 = stack.pop() // 58 7
199.1752 - case 96: stack.push(arg5); // 21 5
199.1753 - case 98: stack.push(arg3); // 29
199.1754 - case 99: if (stack.pop() > stack.pop()) { gt = 154; continue; } // 161 0 55
199.1755 - case 102: stack.push(arg4); // 25 4
199.1756 - case 104: stack.push(arg5); // 21 5
199.1757 - case 106: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1758 - case 107: stack.push(arg7); // 25 7
199.1759 - case 109: stack.push(0); // 3
199.1760 - case 110: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1761 - case 111: if (stack.pop() != stack.pop()) { gt = 148; continue; } // 160 0 37
199.1762 - case 114: stack.push(arg5); // 21 5
199.1763 - case 116: stack.push(1); // 4
199.1764 - case 117: stack.push(stack.pop() + stack.pop()); // 96
199.1765 - case 118: stack.push(arg6); // 21 6
199.1766 - case 120: if (stack.pop() != stack.pop()) { gt = 126; continue; } // 160 0 6
199.1767 - case 123: gt = 154; continue; // 167 0 31
199.1768 - case 126: stack.push(arg4); // 25 4
199.1769 - case 128: stack.push(arg5); // 21 5
199.1770 - case 130: stack.push(1); // 4
199.1771 - case 131: stack.push(stack.pop() + stack.pop()); // 96
199.1772 - case 132: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1773 - case 133: stack.push(arg7); // 25 7
199.1774 - case 135: stack.push(1); // 4
199.1775 - case 136: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1776 - case 137: if (stack.pop() != stack.pop()) { gt = 148; continue; } // 160 0 11
199.1777 - case 140: stack.push(arg5); // 21 5
199.1778 - case 142: stack.push(arg0); // 42
199.1779 - case 143: stack.push(stack.pop().offset); // 180 1 99
199.1780 - case 146: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.1781 - case 147: return stack.pop(); // 172
199.1782 - case 148: arg5 += 255; // 132 5 255
199.1783 - case 151: gt = 96; continue; // 167 255 201
199.1784 - case 154: // 2
199.1785 - case 155: return stack.pop(); // 172
199.1786 - }
199.1787 -}
199.1788 -function java_lang_String_indexOfILjava_lang_String(arg0,arg1) {
199.1789 - var arg2;
199.1790 -;
199.1791 - var stack = new Array(3);
199.1792 - var gt = 0;
199.1793 - for(;;) switch(gt) {
199.1794 - case 0: stack.push(arg0); // 42
199.1795 - case 1: stack.push(arg1); // 43
199.1796 - case 2: stack.push(0); // 3
199.1797 - case 3: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.indexOfILjava_lang_StringI(self, v0, v1)); } // 182 1 150
199.1798 - case 6: return stack.pop(); // 172
199.1799 - }
199.1800 -}
199.1801 -function java_lang_String_indexOfILjava_lang_StringI(arg0,arg1,arg2) {
199.1802 - var arg3;
199.1803 -;
199.1804 - var stack = new Array(7);
199.1805 - var gt = 0;
199.1806 - for(;;) switch(gt) {
199.1807 - case 0: stack.push(arg0); // 42
199.1808 - case 1: stack.push(stack.pop().value); // 180 1 100
199.1809 - case 4: stack.push(arg0); // 42
199.1810 - case 5: stack.push(stack.pop().offset); // 180 1 99
199.1811 - case 8: stack.push(arg0); // 42
199.1812 - case 9: stack.push(stack.pop().count); // 180 1 97
199.1813 - case 12: stack.push(arg1); // 43
199.1814 - case 13: stack.push(stack.pop().value); // 180 1 100
199.1815 - case 16: stack.push(arg1); // 43
199.1816 - case 17: stack.push(stack.pop().offset); // 180 1 99
199.1817 - case 20: stack.push(arg1); // 43
199.1818 - case 21: stack.push(stack.pop().count); // 180 1 97
199.1819 - case 24: stack.push(arg2); // 28
199.1820 - case 25: { var v6 = stack.pop(); var v5 = stack.pop(); var v4 = stack.pop(); var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_String_indexOfAIACAIAIACAIAIAI(v0, v1, v2, v3, v4, v5, v6)); } // 184 1 144
199.1821 - case 28: return stack.pop(); // 172
199.1822 - }
199.1823 -}
199.1824 -function java_lang_String_indexOfIACIIACIII(arg0,arg1,arg2,arg3,arg4,arg5,arg6) {
199.1825 - var arg7;
199.1826 - var arg8;
199.1827 - var arg9;
199.1828 - var arg10;
199.1829 - var arg11;
199.1830 - var arg12;
199.1831 - var stack = new Array();
199.1832 - var gt = 0;
199.1833 - for(;;) switch(gt) {
199.1834 - case 0: stack.push(arg6); // 21 6
199.1835 - case 2: stack.push(arg2); // 28
199.1836 - case 3: if (stack.pop() > stack.pop()) { gt = 17; continue; } // 161 0 14
199.1837 - case 6: stack.push(arg5); // 21 5
199.1838 - case 8: if (stack.pop() != 0) { gt = 15; continue; } // 154 0 7
199.1839 - case 11: stack.push(arg2); // 28
199.1840 - case 12: gt = 16; continue; // 167 0 4
199.1841 - case 15: // 2
199.1842 - case 16: return stack.pop(); // 172
199.1843 - case 17: stack.push(arg6); // 21 6
199.1844 - case 19: if (stack.pop() >= 0) { gt = 25; continue; } // 156 0 6
199.1845 - case 22: stack.push(0); // 3
199.1846 - case 23: arg6 = stack.pop() // 54 6
199.1847 - case 25: stack.push(arg5); // 21 5
199.1848 - case 27: if (stack.pop() != 0) { gt = 33; continue; } // 154 0 6
199.1849 - case 30: stack.push(arg6); // 21 6
199.1850 - case 32: return stack.pop(); // 172
199.1851 - case 33: stack.push(arg3); // 45
199.1852 - case 34: stack.push(arg4); // 21 4
199.1853 - case 36: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1854 - case 37: arg7 = stack.pop() // 54 7
199.1855 - case 39: stack.push(arg1); // 27
199.1856 - case 40: stack.push(arg2); // 28
199.1857 - case 41: stack.push(arg5); // 21 5
199.1858 - case 43: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.1859 - case 44: stack.push(stack.pop() + stack.pop()); // 96
199.1860 - case 45: arg8 = stack.pop() // 54 8
199.1861 - case 47: stack.push(arg1); // 27
199.1862 - case 48: stack.push(arg6); // 21 6
199.1863 - case 50: stack.push(stack.pop() + stack.pop()); // 96
199.1864 - case 51: arg9 = stack.pop() // 54 9
199.1865 - case 53: stack.push(arg9); // 21 9
199.1866 - case 55: stack.push(arg8); // 21 8
199.1867 - case 57: if (stack.pop() < stack.pop()) { gt = 164; continue; } // 163 0 107
199.1868 - case 60: stack.push(arg0); // 42
199.1869 - case 61: stack.push(arg9); // 21 9
199.1870 - case 63: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1871 - case 64: stack.push(arg7); // 21 7
199.1872 - case 66: if (stack.pop() == stack.pop()) { gt = 91; continue; } // 159 0 25
199.1873 - case 69: arg9++; // 132 9 1
199.1874 - case 72: stack.push(arg9); // 21 9
199.1875 - case 74: stack.push(arg8); // 21 8
199.1876 - case 76: if (stack.pop() < stack.pop()) { gt = 91; continue; } // 163 0 15
199.1877 - case 79: stack.push(arg0); // 42
199.1878 - case 80: stack.push(arg9); // 21 9
199.1879 - case 82: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1880 - case 83: stack.push(arg7); // 21 7
199.1881 - case 85: if (stack.pop() == stack.pop()) { gt = 91; continue; } // 159 0 6
199.1882 - case 88: gt = 69; continue; // 167 255 237
199.1883 - case 91: stack.push(arg9); // 21 9
199.1884 - case 93: stack.push(arg8); // 21 8
199.1885 - case 95: if (stack.pop() < stack.pop()) { gt = 158; continue; } // 163 0 63
199.1886 - case 98: stack.push(arg9); // 21 9
199.1887 - case 100: stack.push(1); // 4
199.1888 - case 101: stack.push(stack.pop() + stack.pop()); // 96
199.1889 - case 102: arg10 = stack.pop() // 54 10
199.1890 - case 104: stack.push(arg10); // 21 10
199.1891 - case 106: stack.push(arg5); // 21 5
199.1892 - case 108: stack.push(stack.pop() + stack.pop()); // 96
199.1893 - case 109: stack.push(1); // 4
199.1894 - case 110: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.1895 - case 111: arg11 = stack.pop() // 54 11
199.1896 - case 113: stack.push(arg4); // 21 4
199.1897 - case 115: stack.push(1); // 4
199.1898 - case 116: stack.push(stack.pop() + stack.pop()); // 96
199.1899 - case 117: arg12 = stack.pop() // 54 12
199.1900 - case 119: stack.push(arg10); // 21 10
199.1901 - case 121: stack.push(arg11); // 21 11
199.1902 - case 123: if (stack.pop() <= stack.pop()) { gt = 146; continue; } // 162 0 23
199.1903 - case 126: stack.push(arg0); // 42
199.1904 - case 127: stack.push(arg10); // 21 10
199.1905 - case 129: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1906 - case 130: stack.push(arg3); // 45
199.1907 - case 131: stack.push(arg12); // 21 12
199.1908 - case 133: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.1909 - case 134: if (stack.pop() != stack.pop()) { gt = 146; continue; } // 160 0 12
199.1910 - case 137: arg10++; // 132 10 1
199.1911 - case 140: arg12++; // 132 12 1
199.1912 - case 143: gt = 119; continue; // 167 255 232
199.1913 - case 146: stack.push(arg10); // 21 10
199.1914 - case 148: stack.push(arg11); // 21 11
199.1915 - case 150: if (stack.pop() != stack.pop()) { gt = 158; continue; } // 160 0 8
199.1916 - case 153: stack.push(arg9); // 21 9
199.1917 - case 155: stack.push(arg1); // 27
199.1918 - case 156: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.1919 - case 157: return stack.pop(); // 172
199.1920 - case 158: arg9++; // 132 9 1
199.1921 - case 161: gt = 53; continue; // 167 255 148
199.1922 - case 164: // 2
199.1923 - case 165: return stack.pop(); // 172
199.1924 - }
199.1925 -}
199.1926 -function java_lang_String_lastIndexOfILjava_lang_String(arg0,arg1) {
199.1927 - var arg2;
199.1928 -;
199.1929 - var stack = new Array(3);
199.1930 - var gt = 0;
199.1931 - for(;;) switch(gt) {
199.1932 - case 0: stack.push(arg0); // 42
199.1933 - case 1: stack.push(arg1); // 43
199.1934 - case 2: stack.push(arg0); // 42
199.1935 - case 3: stack.push(stack.pop().count); // 180 1 97
199.1936 - case 6: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.lastIndexOfILjava_lang_StringI(self, v0, v1)); } // 182 1 151
199.1937 - case 9: return stack.pop(); // 172
199.1938 - }
199.1939 -}
199.1940 -function java_lang_String_lastIndexOfILjava_lang_StringI(arg0,arg1,arg2) {
199.1941 - var arg3;
199.1942 -;
199.1943 - var stack = new Array(7);
199.1944 - var gt = 0;
199.1945 - for(;;) switch(gt) {
199.1946 - case 0: stack.push(arg0); // 42
199.1947 - case 1: stack.push(stack.pop().value); // 180 1 100
199.1948 - case 4: stack.push(arg0); // 42
199.1949 - case 5: stack.push(stack.pop().offset); // 180 1 99
199.1950 - case 8: stack.push(arg0); // 42
199.1951 - case 9: stack.push(stack.pop().count); // 180 1 97
199.1952 - case 12: stack.push(arg1); // 43
199.1953 - case 13: stack.push(stack.pop().value); // 180 1 100
199.1954 - case 16: stack.push(arg1); // 43
199.1955 - case 17: stack.push(stack.pop().offset); // 180 1 99
199.1956 - case 20: stack.push(arg1); // 43
199.1957 - case 21: stack.push(stack.pop().count); // 180 1 97
199.1958 - case 24: stack.push(arg2); // 28
199.1959 - case 25: { var v6 = stack.pop(); var v5 = stack.pop(); var v4 = stack.pop(); var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_String_lastIndexOfAIACAIAIACAIAIAI(v0, v1, v2, v3, v4, v5, v6)); } // 184 1 145
199.1960 - case 28: return stack.pop(); // 172
199.1961 - }
199.1962 -}
199.1963 -function java_lang_String_lastIndexOfIACIIACIII(arg0,arg1,arg2,arg3,arg4,arg5,arg6) {
199.1964 - var arg7;
199.1965 - var arg8;
199.1966 - var arg9;
199.1967 - var arg10;
199.1968 - var arg11;
199.1969 - var arg12;
199.1970 - var arg13;
199.1971 - var arg14;
199.1972 - var stack = new Array();
199.1973 - var gt = 0;
199.1974 - for(;;) switch(gt) {
199.1975 - case 0: stack.push(arg2); // 28
199.1976 - case 1: stack.push(arg5); // 21 5
199.1977 - case 3: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.1978 - case 4: arg7 = stack.pop() // 54 7
199.1979 - case 6: stack.push(arg6); // 21 6
199.1980 - case 8: if (stack.pop() >= 0) { gt = 13; continue; } // 156 0 5
199.1981 - case 11: // 2
199.1982 - case 12: return stack.pop(); // 172
199.1983 - case 13: stack.push(arg6); // 21 6
199.1984 - case 15: stack.push(arg7); // 21 7
199.1985 - case 17: if (stack.pop() >= stack.pop()) { gt = 24; continue; } // 164 0 7
199.1986 - case 20: stack.push(arg7); // 21 7
199.1987 - case 22: arg6 = stack.pop() // 54 6
199.1988 - case 24: stack.push(arg5); // 21 5
199.1989 - case 26: if (stack.pop() != 0) { gt = 32; continue; } // 154 0 6
199.1990 - case 29: stack.push(arg6); // 21 6
199.1991 - case 31: return stack.pop(); // 172
199.1992 - case 32: stack.push(arg4); // 21 4
199.1993 - case 34: stack.push(arg5); // 21 5
199.1994 - case 36: stack.push(stack.pop() + stack.pop()); // 96
199.1995 - case 37: stack.push(1); // 4
199.1996 - case 38: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.1997 - case 39: arg8 = stack.pop() // 54 8
199.1998 - case 41: stack.push(arg3); // 45
199.1999 - case 42: stack.push(arg8); // 21 8
199.2000 - case 44: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.2001 - case 45: arg9 = stack.pop() // 54 9
199.2002 - case 47: stack.push(arg1); // 27
199.2003 - case 48: stack.push(arg5); // 21 5
199.2004 - case 50: stack.push(stack.pop() + stack.pop()); // 96
199.2005 - case 51: stack.push(1); // 4
199.2006 - case 52: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.2007 - case 53: arg10 = stack.pop() // 54 10
199.2008 - case 55: stack.push(arg10); // 21 10
199.2009 - case 57: stack.push(arg6); // 21 6
199.2010 - case 59: stack.push(stack.pop() + stack.pop()); // 96
199.2011 - case 60: arg11 = stack.pop() // 54 11
199.2012 - case 62: stack.push(arg11); // 21 11
199.2013 - case 64: stack.push(arg10); // 21 10
199.2014 - case 66: if (stack.pop() > stack.pop()) { gt = 84; continue; } // 161 0 18
199.2015 - case 69: stack.push(arg0); // 42
199.2016 - case 70: stack.push(arg11); // 21 11
199.2017 - case 72: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.2018 - case 73: stack.push(arg9); // 21 9
199.2019 - case 75: if (stack.pop() == stack.pop()) { gt = 84; continue; } // 159 0 9
199.2020 - case 78: arg11 += 255; // 132 11 255
199.2021 - case 81: gt = 62; continue; // 167 255 237
199.2022 - case 84: stack.push(arg11); // 21 11
199.2023 - case 86: stack.push(arg10); // 21 10
199.2024 - case 88: if (stack.pop() <= stack.pop()) { gt = 93; continue; } // 162 0 5
199.2025 - case 91: // 2
199.2026 - case 92: return stack.pop(); // 172
199.2027 - case 93: stack.push(arg11); // 21 11
199.2028 - case 95: stack.push(1); // 4
199.2029 - case 96: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.2030 - case 97: arg12 = stack.pop() // 54 12
199.2031 - case 99: stack.push(arg12); // 21 12
199.2032 - case 101: stack.push(arg5); // 21 5
199.2033 - case 103: stack.push(1); // 4
199.2034 - case 104: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.2035 - case 105: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.2036 - case 106: arg13 = stack.pop() // 54 13
199.2037 - case 108: stack.push(arg8); // 21 8
199.2038 - case 110: stack.push(1); // 4
199.2039 - case 111: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.2040 - case 112: arg14 = stack.pop() // 54 14
199.2041 - case 114: stack.push(arg12); // 21 12
199.2042 - case 116: stack.push(arg13); // 21 13
199.2043 - case 118: if (stack.pop() >= stack.pop()) { gt = 144; continue; } // 164 0 26
199.2044 - case 121: stack.push(arg0); // 42
199.2045 - case 122: stack.push(arg12); // 21 12
199.2046 - case 124: arg12 += 255; // 132 12 255
199.2047 - case 127: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.2048 - case 128: stack.push(arg3); // 45
199.2049 - case 129: stack.push(arg14); // 21 14
199.2050 - case 131: arg14 += 255; // 132 14 255
199.2051 - case 134: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.2052 - case 135: if (stack.pop() == stack.pop()) { gt = 114; continue; } // 159 255 235
199.2053 - case 138: arg11 += 255; // 132 11 255
199.2054 - case 141: gt = 62; continue; // 167 255 177
199.2055 - case 144: stack.push(arg13); // 21 13
199.2056 - case 146: stack.push(arg1); // 27
199.2057 - case 147: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.2058 - case 148: stack.push(1); // 4
199.2059 - case 149: stack.push(stack.pop() + stack.pop()); // 96
199.2060 - case 150: return stack.pop(); // 172
199.2061 - }
199.2062 -}
199.2063 -function java_lang_String_substringLjava_lang_StringI(arg0,arg1) {
199.2064 - var arg2;
199.2065 -;
199.2066 - var stack = new Array(3);
199.2067 - var gt = 0;
199.2068 - for(;;) switch(gt) {
199.2069 - case 0: stack.push(arg0); // 42
199.2070 - case 1: stack.push(arg1); // 27
199.2071 - case 2: stack.push(arg0); // 42
199.2072 - case 3: stack.push(stack.pop().count); // 180 1 97
199.2073 - case 6: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.substringLjava_lang_StringII(self, v0, v1)); } // 182 1 147
199.2074 - case 9: return stack.pop(); // 176
199.2075 - }
199.2076 -}
199.2077 -function java_lang_String_substringLjava_lang_StringII(arg0,arg1,arg2) {
199.2078 - var arg3;
199.2079 -;
199.2080 - var stack = new Array(5);
199.2081 - var gt = 0;
199.2082 - for(;;) switch(gt) {
199.2083 - case 0: stack.push(arg1); // 27
199.2084 - case 1: if (stack.pop() >= 0) { gt = 13; continue; } // 156 0 12
199.2085 - case 4: stack.push(new java_lang_StringIndexOutOfBoundsException); // 187 0 206
199.2086 - case 7: stack.push(stack[stack.length - 1]); // 89
199.2087 - case 8: stack.push(arg1); // 27
199.2088 - case 9: { var v0 = stack.pop(); java_lang_StringIndexOutOfBoundsException_consVI(stack.pop(), v0); } // 183 1 169
199.2089 - case 12: // 191
199.2090 - case 13: stack.push(arg2); // 28
199.2091 - case 14: stack.push(arg0); // 42
199.2092 - case 15: stack.push(stack.pop().count); // 180 1 97
199.2093 - case 18: if (stack.pop() >= stack.pop()) { gt = 30; continue; } // 164 0 12
199.2094 - case 21: stack.push(new java_lang_StringIndexOutOfBoundsException); // 187 0 206
199.2095 - case 24: stack.push(stack[stack.length - 1]); // 89
199.2096 - case 25: stack.push(arg2); // 28
199.2097 - case 26: { var v0 = stack.pop(); java_lang_StringIndexOutOfBoundsException_consVI(stack.pop(), v0); } // 183 1 169
199.2098 - case 29: // 191
199.2099 - case 30: stack.push(arg1); // 27
199.2100 - case 31: stack.push(arg2); // 28
199.2101 - case 32: if (stack.pop() >= stack.pop()) { gt = 46; continue; } // 164 0 14
199.2102 - case 35: stack.push(new java_lang_StringIndexOutOfBoundsException); // 187 0 206
199.2103 - case 38: stack.push(stack[stack.length - 1]); // 89
199.2104 - case 39: stack.push(arg2); // 28
199.2105 - case 40: stack.push(arg1); // 27
199.2106 - case 41: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.2107 - case 42: { var v0 = stack.pop(); java_lang_StringIndexOutOfBoundsException_consVI(stack.pop(), v0); } // 183 1 169
199.2108 - case 45: // 191
199.2109 - case 46: stack.push(arg1); // 27
199.2110 - case 47: if (stack.pop() != 0) { gt = 62; continue; } // 154 0 15
199.2111 - case 50: stack.push(arg2); // 28
199.2112 - case 51: stack.push(arg0); // 42
199.2113 - case 52: stack.push(stack.pop().count); // 180 1 97
199.2114 - case 55: if (stack.pop() != stack.pop()) { gt = 62; continue; } // 160 0 7
199.2115 - case 58: stack.push(arg0); // 42
199.2116 - case 59: gt = 82; continue; // 167 0 23
199.2117 - case 62: stack.push(new java_lang_String); // 187 0 200
199.2118 - case 65: stack.push(stack[stack.length - 1]); // 89
199.2119 - case 66: stack.push(arg0); // 42
199.2120 - case 67: stack.push(stack.pop().offset); // 180 1 99
199.2121 - case 70: stack.push(arg1); // 27
199.2122 - case 71: stack.push(stack.pop() + stack.pop()); // 96
199.2123 - case 72: stack.push(arg2); // 28
199.2124 - case 73: stack.push(arg1); // 27
199.2125 - case 74: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.2126 - case 75: stack.push(arg0); // 42
199.2127 - case 76: stack.push(stack.pop().value); // 180 1 100
199.2128 - case 79: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_String_consVIIAC(stack.pop(), v0, v1, v2); } // 183 1 137
199.2129 - case 82: return stack.pop(); // 176
199.2130 - }
199.2131 -}
199.2132 -function java_lang_String_subSequenceLjava_lang_CharSequenceII(arg0,arg1,arg2) {
199.2133 - var arg3;
199.2134 -;
199.2135 - var stack = new Array(3);
199.2136 - var gt = 0;
199.2137 - for(;;) switch(gt) {
199.2138 - case 0: stack.push(arg0); // 42
199.2139 - case 1: stack.push(arg1); // 27
199.2140 - case 2: stack.push(arg2); // 28
199.2141 - case 3: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.substringLjava_lang_StringII(self, v0, v1)); } // 182 1 147
199.2142 - case 6: return stack.pop(); // 176
199.2143 - }
199.2144 -}
199.2145 -function java_lang_String_concatLjava_lang_StringLjava_lang_String(arg0,arg1) {
199.2146 - var arg2;
199.2147 - var arg3;
199.2148 - var arg4;
199.2149 -;
199.2150 - var stack = new Array(5);
199.2151 - var gt = 0;
199.2152 - for(;;) switch(gt) {
199.2153 - case 0: stack.push(arg1); // 43
199.2154 - case 1: { var self = stack.pop(); stack.push(self.lengthI(self)); } // 182 1 133
199.2155 - case 4: arg2 = stack.pop(); // 61
199.2156 - case 5: stack.push(arg2); // 28
199.2157 - case 6: if (stack.pop() != 0) { gt = 11; continue; } // 154 0 5
199.2158 - case 9: stack.push(arg0); // 42
199.2159 - case 10: return stack.pop(); // 176
199.2160 - case 11: stack.push(arg0); // 42
199.2161 - case 12: stack.push(stack.pop().count); // 180 1 97
199.2162 - case 15: stack.push(arg2); // 28
199.2163 - case 16: stack.push(stack.pop() + stack.pop()); // 96
199.2164 - case 17: stack.push(new Array(stack.pop())); // 188 5
199.2165 - case 19: arg3 = stack.pop(); // 78
199.2166 - case 20: stack.push(arg0); // 42
199.2167 - case 21: stack.push(0); // 3
199.2168 - case 22: stack.push(arg0); // 42
199.2169 - case 23: stack.push(stack.pop().count); // 180 1 97
199.2170 - case 26: stack.push(arg3); // 45
199.2171 - case 27: stack.push(0); // 3
199.2172 - case 28: { var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); self.getCharsVIIACAI(self, v0, v1, v2, v3); } // 182 1 138
199.2173 - case 31: stack.push(arg1); // 43
199.2174 - case 32: stack.push(0); // 3
199.2175 - case 33: stack.push(arg2); // 28
199.2176 - case 34: stack.push(arg3); // 45
199.2177 - case 35: stack.push(arg0); // 42
199.2178 - case 36: stack.push(stack.pop().count); // 180 1 97
199.2179 - case 39: { var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); self.getCharsVIIACAI(self, v0, v1, v2, v3); } // 182 1 138
199.2180 - case 42: stack.push(new java_lang_String); // 187 0 200
199.2181 - case 45: stack.push(stack[stack.length - 1]); // 89
199.2182 - case 46: stack.push(0); // 3
199.2183 - case 47: stack.push(arg0); // 42
199.2184 - case 48: stack.push(stack.pop().count); // 180 1 97
199.2185 - case 51: stack.push(arg2); // 28
199.2186 - case 52: stack.push(stack.pop() + stack.pop()); // 96
199.2187 - case 53: stack.push(arg3); // 45
199.2188 - case 54: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_String_consVIIAC(stack.pop(), v0, v1, v2); } // 183 1 137
199.2189 - case 57: return stack.pop(); // 176
199.2190 - }
199.2191 -}
199.2192 -function java_lang_String_replaceLjava_lang_StringCC(arg0,arg1,arg2) {
199.2193 - var arg3;
199.2194 - var arg4;
199.2195 - var arg5;
199.2196 - var arg6;
199.2197 - var arg7;
199.2198 - var arg8;
199.2199 - var arg9;
199.2200 -;
199.2201 - var stack = new Array(5);
199.2202 - var gt = 0;
199.2203 - for(;;) switch(gt) {
199.2204 - case 0: stack.push(arg1); // 27
199.2205 - case 1: stack.push(arg2); // 28
199.2206 - case 2: if (stack.pop() == stack.pop()) { gt = 140; continue; } // 159 0 138
199.2207 - case 5: stack.push(arg0); // 42
199.2208 - case 6: stack.push(stack.pop().count); // 180 1 97
199.2209 - case 9: arg3 = stack.pop(); // 62
199.2210 - case 10: // 2
199.2211 - case 11: arg4 = stack.pop() // 54 4
199.2212 - case 13: stack.push(arg0); // 42
199.2213 - case 14: stack.push(stack.pop().value); // 180 1 100
199.2214 - case 17: arg5 = stack.pop() // 58 5
199.2215 - case 19: stack.push(arg0); // 42
199.2216 - case 20: stack.push(stack.pop().offset); // 180 1 99
199.2217 - case 23: arg6 = stack.pop() // 54 6
199.2218 - case 25: arg4++; // 132 4 1
199.2219 - case 28: stack.push(arg4); // 21 4
199.2220 - case 30: stack.push(arg3); // 29
199.2221 - case 31: if (stack.pop() <= stack.pop()) { gt = 49; continue; } // 162 0 18
199.2222 - case 34: stack.push(arg5); // 25 5
199.2223 - case 36: stack.push(arg6); // 21 6
199.2224 - case 38: stack.push(arg4); // 21 4
199.2225 - case 40: stack.push(stack.pop() + stack.pop()); // 96
199.2226 - case 41: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.2227 - case 42: stack.push(arg1); // 27
199.2228 - case 43: if (stack.pop() != stack.pop()) { gt = 25; continue; } // 160 255 238
199.2229 - case 46: gt = 49; continue; // 167 0 3
199.2230 - case 49: stack.push(arg4); // 21 4
199.2231 - case 51: stack.push(arg3); // 29
199.2232 - case 52: if (stack.pop() <= stack.pop()) { gt = 140; continue; } // 162 0 88
199.2233 - case 55: stack.push(arg3); // 29
199.2234 - case 56: stack.push(new Array(stack.pop())); // 188 5
199.2235 - case 58: arg7 = stack.pop() // 58 7
199.2236 - case 60: stack.push(0); // 3
199.2237 - case 61: arg8 = stack.pop() // 54 8
199.2238 - case 63: stack.push(arg8); // 21 8
199.2239 - case 65: stack.push(arg4); // 21 4
199.2240 - case 67: if (stack.pop() <= stack.pop()) { gt = 89; continue; } // 162 0 22
199.2241 - case 70: stack.push(arg7); // 25 7
199.2242 - case 72: stack.push(arg8); // 21 8
199.2243 - case 74: stack.push(arg5); // 25 5
199.2244 - case 76: stack.push(arg6); // 21 6
199.2245 - case 78: stack.push(arg8); // 21 8
199.2246 - case 80: stack.push(stack.pop() + stack.pop()); // 96
199.2247 - case 81: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.2248 - case 82: { var value = stack.pop(); var indx = stack.pop(); stack.pop()[indx] = value; } // 85
199.2249 - case 83: arg8++; // 132 8 1
199.2250 - case 86: gt = 63; continue; // 167 255 233
199.2251 - case 89: stack.push(arg4); // 21 4
199.2252 - case 91: stack.push(arg3); // 29
199.2253 - case 92: if (stack.pop() <= stack.pop()) { gt = 128; continue; } // 162 0 36
199.2254 - case 95: stack.push(arg5); // 25 5
199.2255 - case 97: stack.push(arg6); // 21 6
199.2256 - case 99: stack.push(arg4); // 21 4
199.2257 - case 101: stack.push(stack.pop() + stack.pop()); // 96
199.2258 - case 102: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.2259 - case 103: arg8 = stack.pop() // 54 8
199.2260 - case 105: stack.push(arg7); // 25 7
199.2261 - case 107: stack.push(arg4); // 21 4
199.2262 - case 109: stack.push(arg8); // 21 8
199.2263 - case 111: stack.push(arg1); // 27
199.2264 - case 112: if (stack.pop() != stack.pop()) { gt = 119; continue; } // 160 0 7
199.2265 - case 115: stack.push(arg2); // 28
199.2266 - case 116: gt = 121; continue; // 167 0 5
199.2267 - case 119: stack.push(arg8); // 21 8
199.2268 - case 121: { var value = stack.pop(); var indx = stack.pop(); stack.pop()[indx] = value; } // 85
199.2269 - case 122: arg4++; // 132 4 1
199.2270 - case 125: gt = 89; continue; // 167 255 220
199.2271 - case 128: stack.push(new java_lang_String); // 187 0 200
199.2272 - case 131: stack.push(stack[stack.length - 1]); // 89
199.2273 - case 132: stack.push(0); // 3
199.2274 - case 133: stack.push(arg3); // 29
199.2275 - case 134: stack.push(arg7); // 25 7
199.2276 - case 136: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_String_consVIIAC(stack.pop(), v0, v1, v2); } // 183 1 137
199.2277 - case 139: return stack.pop(); // 176
199.2278 - case 140: stack.push(arg0); // 42
199.2279 - case 141: return stack.pop(); // 176
199.2280 - }
199.2281 -}
199.2282 -function java_lang_String_matchesZLjava_lang_String(arg0,arg1) {
199.2283 - var arg2;
199.2284 -;
199.2285 - var stack = new Array(2);
199.2286 - var gt = 0;
199.2287 - for(;;) switch(gt) {
199.2288 - case 0: stack.push(arg1); // 43
199.2289 - case 1: stack.push(arg0); // 42
199.2290 - case 2: { var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_util_regex_Pattern_matchesZLjava_lang_StringLjava_lang_CharSequence(v0, v1)); } // 184 1 183
199.2291 - case 5: return stack.pop(); // 172
199.2292 - }
199.2293 -}
199.2294 -function java_lang_String_containsZLjava_lang_CharSequence(arg0,arg1) {
199.2295 - var arg2;
199.2296 -;
199.2297 - var stack = new Array(2);
199.2298 - var gt = 0;
199.2299 - for(;;) switch(gt) {
199.2300 - case 0: stack.push(arg0); // 42
199.2301 - case 1: stack.push(arg1); // 43
199.2302 - case 2: { var self = stack.pop(); stack.push(self.toStringLjava_lang_String(self)); } // 182 1 132
199.2303 - case 5: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.indexOfILjava_lang_String(self, v0)); } // 182 1 149
199.2304 - case 8: // 2
199.2305 - case 9: if (stack.pop() >= stack.pop()) { gt = 16; continue; } // 164 0 7
199.2306 - case 12: stack.push(1); // 4
199.2307 - case 13: gt = 17; continue; // 167 0 4
199.2308 - case 16: stack.push(0); // 3
199.2309 - case 17: return stack.pop(); // 172
199.2310 - }
199.2311 -}
199.2312 -function java_lang_String_replaceFirstLjava_lang_StringLjava_lang_StringLjava_lang_String(arg0,arg1,arg2) {
199.2313 - var arg3;
199.2314 -;
199.2315 - var stack = new Array(2);
199.2316 - var gt = 0;
199.2317 - for(;;) switch(gt) {
199.2318 - case 0: stack.push(arg1); // 43
199.2319 - case 1: { var v0 = stack.pop(); stack.push(java_util_regex_Pattern_compileLjava_util_regex_PatternLjava_lang_String(v0)); } // 184 1 186
199.2320 - case 4: stack.push(arg0); // 42
199.2321 - case 5: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.matcherLjava_util_regex_MatcherLjava_lang_CharSequence(self, v0)); } // 182 1 185
199.2322 - case 8: stack.push(arg2); // 44
199.2323 - case 9: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.replaceFirstLjava_lang_StringLjava_lang_String(self, v0)); } // 182 1 182
199.2324 - case 12: return stack.pop(); // 176
199.2325 - }
199.2326 -}
199.2327 -function java_lang_String_replaceAllLjava_lang_StringLjava_lang_StringLjava_lang_String(arg0,arg1,arg2) {
199.2328 - var arg3;
199.2329 -;
199.2330 - var stack = new Array(2);
199.2331 - var gt = 0;
199.2332 - for(;;) switch(gt) {
199.2333 - case 0: stack.push(arg1); // 43
199.2334 - case 1: { var v0 = stack.pop(); stack.push(java_util_regex_Pattern_compileLjava_util_regex_PatternLjava_lang_String(v0)); } // 184 1 186
199.2335 - case 4: stack.push(arg0); // 42
199.2336 - case 5: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.matcherLjava_util_regex_MatcherLjava_lang_CharSequence(self, v0)); } // 182 1 185
199.2337 - case 8: stack.push(arg2); // 44
199.2338 - case 9: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.replaceAllLjava_lang_StringLjava_lang_String(self, v0)); } // 182 1 181
199.2339 - case 12: return stack.pop(); // 176
199.2340 - }
199.2341 -}
199.2342 -function java_lang_String_replaceLjava_lang_StringLjava_lang_CharSequenceLjava_lang_CharSequence(arg0,arg1,arg2) {
199.2343 - var arg3;
199.2344 -;
199.2345 - var stack = new Array(2);
199.2346 - var gt = 0;
199.2347 - for(;;) switch(gt) {
199.2348 - case 0: stack.push(arg1); // 43
199.2349 - case 1: { var self = stack.pop(); stack.push(self.toStringLjava_lang_String(self)); } // 182 1 132
199.2350 - case 4: stack.push(16); // 16 16
199.2351 - case 6: { var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_util_regex_Pattern_compileLjava_util_regex_PatternLjava_lang_StringI(v0, v1)); } // 184 1 187
199.2352 - case 9: stack.push(arg0); // 42
199.2353 - case 10: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.matcherLjava_util_regex_MatcherLjava_lang_CharSequence(self, v0)); } // 182 1 185
199.2354 - case 13: stack.push(arg2); // 44
199.2355 - case 14: { var self = stack.pop(); stack.push(self.toStringLjava_lang_String(self)); } // 182 1 132
199.2356 - case 17: { var v0 = stack.pop(); stack.push(java_util_regex_Matcher_quoteReplacementLjava_lang_StringLjava_lang_String(v0)); } // 184 1 180
199.2357 - case 20: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.replaceAllLjava_lang_StringLjava_lang_String(self, v0)); } // 182 1 181
199.2358 - case 23: return stack.pop(); // 176
199.2359 - }
199.2360 -}
199.2361 -function java_lang_String_splitALjava_lang_StringLjava_lang_StringI(arg0,arg1,arg2) {
199.2362 - var arg3;
199.2363 -;
199.2364 - var stack = new Array(3);
199.2365 - var gt = 0;
199.2366 - for(;;) switch(gt) {
199.2367 - case 0: stack.push(arg1); // 43
199.2368 - case 1: { var v0 = stack.pop(); stack.push(java_util_regex_Pattern_compileLjava_util_regex_PatternLjava_lang_String(v0)); } // 184 1 186
199.2369 - case 4: stack.push(arg0); // 42
199.2370 - case 5: stack.push(arg2); // 28
199.2371 - case 6: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.splitALjava_lang_StringLjava_lang_CharSequenceI(self, v0, v1)); } // 182 1 184
199.2372 - case 9: return stack.pop(); // 176
199.2373 - }
199.2374 -}
199.2375 -function java_lang_String_splitALjava_lang_StringLjava_lang_String(arg0,arg1) {
199.2376 - var arg2;
199.2377 -;
199.2378 - var stack = new Array(3);
199.2379 - var gt = 0;
199.2380 - for(;;) switch(gt) {
199.2381 - case 0: stack.push(arg0); // 42
199.2382 - case 1: stack.push(arg1); // 43
199.2383 - case 2: stack.push(0); // 3
199.2384 - case 3: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.splitALjava_lang_StringLjava_lang_StringI(self, v0, v1)); } // 182 1 157
199.2385 - case 6: return stack.pop(); // 176
199.2386 - }
199.2387 -}
199.2388 -function java_lang_String_toLowerCaseLjava_lang_StringLjava_util_Locale(arg0,arg1) {
199.2389 - var arg2;
199.2390 - var arg3;
199.2391 - var arg4;
199.2392 - var arg5;
199.2393 - var arg6;
199.2394 - var arg7;
199.2395 - var arg8;
199.2396 - var arg9;
199.2397 - var arg10;
199.2398 - var arg11;
199.2399 - var arg12;
199.2400 - var arg13;
199.2401 - var arg14;
199.2402 -;
199.2403 - var stack = new Array(6);
199.2404 - var gt = 0;
199.2405 - for(;;) switch(gt) {
199.2406 - case 0: stack.push(arg1); // 43
199.2407 - case 1: if (stack.pop()) { gt = 12; continue; } // 199 0 11
199.2408 - case 4: stack.push(new java_lang_NullPointerException); // 187 0 198
199.2409 - case 7: stack.push(stack[stack.length - 1]); // 89
199.2410 - case 8: { java_lang_NullPointerException_consV(stack.pop()); } // 183 1 128
199.2411 - case 11: // 191
199.2412 - case 12: stack.push(0); // 3
199.2413 - case 13: arg2 = stack.pop(); // 61
199.2414 - case 14: stack.push(arg2); // 28
199.2415 - case 15: stack.push(arg0); // 42
199.2416 - case 16: stack.push(stack.pop().count); // 180 1 97
199.2417 - case 19: if (stack.pop() <= stack.pop()) { gt = 94; continue; } // 162 0 75
199.2418 - case 22: stack.push(arg0); // 42
199.2419 - case 23: stack.push(stack.pop().value); // 180 1 100
199.2420 - case 26: stack.push(arg0); // 42
199.2421 - case 27: stack.push(stack.pop().offset); // 180 1 99
199.2422 - case 30: stack.push(arg2); // 28
199.2423 - case 31: stack.push(stack.pop() + stack.pop()); // 96
199.2424 - case 32: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.2425 - case 33: arg3 = stack.pop(); // 62
199.2426 - case 34: stack.push(arg3); // 29
199.2427 - case 35: stack.push(55296); // 18 1
199.2428 - case 37: if (stack.pop() > stack.pop()) { gt = 77; continue; } // 161 0 40
199.2429 - case 40: stack.push(arg3); // 29
199.2430 - case 41: stack.push(56319); // 18 2
199.2431 - case 43: if (stack.pop() < stack.pop()) { gt = 77; continue; } // 163 0 34
199.2432 - case 46: stack.push(arg0); // 42
199.2433 - case 47: stack.push(arg2); // 28
199.2434 - case 48: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.codePointAtII(self, v0)); } // 182 1 134
199.2435 - case 51: arg4 = stack.pop() // 54 4
199.2436 - case 53: stack.push(arg4); // 21 4
199.2437 - case 55: stack.push(arg4); // 21 4
199.2438 - case 57: { var v0 = stack.pop(); stack.push(java_lang_Character_toLowerCaseII(v0)); } // 184 1 107
199.2439 - case 60: if (stack.pop() == stack.pop()) { gt = 66; continue; } // 159 0 6
199.2440 - case 63: gt = 96; continue; // 167 0 33
199.2441 - case 66: stack.push(arg2); // 28
199.2442 - case 67: stack.push(arg4); // 21 4
199.2443 - case 69: { var v0 = stack.pop(); stack.push(java_lang_Character_charCountII(v0)); } // 184 1 106
199.2444 - case 72: stack.push(stack.pop() + stack.pop()); // 96
199.2445 - case 73: arg2 = stack.pop(); // 61
199.2446 - case 74: gt = 91; continue; // 167 0 17
199.2447 - case 77: stack.push(arg3); // 29
199.2448 - case 78: stack.push(arg3); // 29
199.2449 - case 79: { var v0 = stack.pop(); stack.push(java_lang_Character_toLowerCaseCC(v0)); } // 184 1 104
199.2450 - case 82: if (stack.pop() == stack.pop()) { gt = 88; continue; } // 159 0 6
199.2451 - case 85: gt = 96; continue; // 167 0 11
199.2452 - case 88: arg2++; // 132 2 1
199.2453 - case 91: gt = 14; continue; // 167 255 179
199.2454 - case 94: stack.push(arg0); // 42
199.2455 - case 95: return stack.pop(); // 176
199.2456 - case 96: stack.push(arg0); // 42
199.2457 - case 97: stack.push(stack.pop().count); // 180 1 97
199.2458 - case 100: stack.push(new Array(stack.pop())); // 188 5
199.2459 - case 102: arg3 = stack.pop(); // 78
199.2460 - case 103: stack.push(0); // 3
199.2461 - case 104: arg4 = stack.pop() // 54 4
199.2462 - case 106: stack.push(arg0); // 42
199.2463 - case 107: stack.push(stack.pop().value); // 180 1 100
199.2464 - case 110: stack.push(arg0); // 42
199.2465 - case 111: stack.push(stack.pop().offset); // 180 1 99
199.2466 - case 114: stack.push(arg3); // 45
199.2467 - case 115: stack.push(0); // 3
199.2468 - case 116: stack.push(arg2); // 28
199.2469 - case 117: { var v4 = stack.pop(); var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_System_arraycopyVLjava_lang_ObjectILjava_lang_ObjectII(v0, v1, v2, v3, v4); } // 184 1 171
199.2470 - case 120: stack.push(arg1); // 43
199.2471 - case 121: { var self = stack.pop(); stack.push(self.getLanguageLjava_lang_String(self)); } // 182 1 178
199.2472 - case 124: arg5 = stack.pop() // 58 5
199.2473 - case 126: stack.push(arg5); // 25 5
199.2474 - case 128: stack.push("tr"); // 18 11
199.2475 - case 130: // 165
199.2476 - case 131: // 0
199.2477 - case 132: stack.push(6405); // 17 25 5
199.2478 - case 135: stack.push("az"); // 18 5
199.2479 - case 137: // 165
199.2480 - case 138: // 0
199.2481 - case 139: stack.push(1); // 10
199.2482 - case 140: stack.push(arg5); // 25 5
199.2483 - case 142: stack.push("lt"); // 18 9
199.2484 - case 144: // 166
199.2485 - case 145: // 0
199.2486 - case 146: stack.push(4); // 7
199.2487 - case 147: stack.push(1); // 4
199.2488 - case 148: gt = 152; continue; // 167 0 4
199.2489 - case 151: stack.push(0); // 3
199.2490 - case 152: arg6 = stack.pop() // 54 6
199.2491 - case 154: stack.push(arg2); // 28
199.2492 - case 155: arg11 = stack.pop() // 54 11
199.2493 - case 157: stack.push(arg11); // 21 11
199.2494 - case 159: stack.push(arg0); // 42
199.2495 - case 160: stack.push(stack.pop().count); // 180 1 97
199.2496 - case 163: if (stack.pop() <= stack.pop()) { gt = 419; continue; } // 162 1 0
199.2497 - case 166: stack.push(arg0); // 42
199.2498 - case 167: stack.push(stack.pop().value); // 180 1 100
199.2499 - case 170: stack.push(arg0); // 42
199.2500 - case 171: stack.push(stack.pop().offset); // 180 1 99
199.2501 - case 174: stack.push(arg11); // 21 11
199.2502 - case 176: stack.push(stack.pop() + stack.pop()); // 96
199.2503 - case 177: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.2504 - case 178: arg9 = stack.pop() // 54 9
199.2505 - case 180: stack.push(arg9); // 21 9
199.2506 - case 182: // number conversion // 146
199.2507 - case 183: stack.push(55296); // 18 1
199.2508 - case 185: if (stack.pop() > stack.pop()) { gt = 214; continue; } // 161 0 29
199.2509 - case 188: stack.push(arg9); // 21 9
199.2510 - case 190: // number conversion // 146
199.2511 - case 191: stack.push(56319); // 18 2
199.2512 - case 193: if (stack.pop() < stack.pop()) { gt = 214; continue; } // 163 0 21
199.2513 - case 196: stack.push(arg0); // 42
199.2514 - case 197: stack.push(arg11); // 21 11
199.2515 - case 199: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.codePointAtII(self, v0)); } // 182 1 134
199.2516 - case 202: arg9 = stack.pop() // 54 9
199.2517 - case 204: stack.push(arg9); // 21 9
199.2518 - case 206: { var v0 = stack.pop(); stack.push(java_lang_Character_charCountII(v0)); } // 184 1 106
199.2519 - case 209: arg10 = stack.pop() // 54 10
199.2520 - case 211: gt = 217; continue; // 167 0 6
199.2521 - case 214: stack.push(1); // 4
199.2522 - case 215: arg10 = stack.pop() // 54 10
199.2523 - case 217: stack.push(arg6); // 21 6
199.2524 - case 219: if (stack.pop() != 0) { gt = 230; continue; } // 154 0 11
199.2525 - case 222: stack.push(arg9); // 21 9
199.2526 - case 224: stack.push(931); // 17 3 163
199.2527 - case 227: if (stack.pop() != stack.pop()) { gt = 242; continue; } // 160 0 15
199.2528 - case 230: stack.push(arg0); // 42
199.2529 - case 231: stack.push(arg11); // 21 11
199.2530 - case 233: stack.push(arg1); // 43
199.2531 - case 234: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_ConditionalSpecialCasing_toLowerCaseExILjava_lang_StringILjava_util_Locale(v0, v1, v2)); } // 184 1 117
199.2532 - case 237: arg8 = stack.pop() // 54 8
199.2533 - case 239: gt = 249; continue; // 167 0 10
199.2534 - case 242: stack.push(arg9); // 21 9
199.2535 - case 244: { var v0 = stack.pop(); stack.push(java_lang_Character_toLowerCaseII(v0)); } // 184 1 107
199.2536 - case 247: arg8 = stack.pop() // 54 8
199.2537 - case 249: stack.push(arg8); // 21 8
199.2538 - case 251: // 2
199.2539 - case 252: if (stack.pop() == stack.pop()) { gt = 262; continue; } // 159 0 10
199.2540 - case 255: stack.push(arg8); // 21 8
199.2541 - case 257: stack.push(65536); // 18 3
199.2542 - case 259: if (stack.pop() > stack.pop()) { gt = 399; continue; } // 161 0 140
199.2543 - case 262: stack.push(arg8); // 21 8
199.2544 - case 264: // 2
199.2545 - case 265: if (stack.pop() != stack.pop()) { gt = 280; continue; } // 160 0 15
199.2546 - case 268: stack.push(arg0); // 42
199.2547 - case 269: stack.push(arg11); // 21 11
199.2548 - case 271: stack.push(arg1); // 43
199.2549 - case 272: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_ConditionalSpecialCasing_toLowerCaseCharArrayACLjava_lang_StringILjava_util_Locale(v0, v1, v2)); } // 184 1 119
199.2550 - case 275: arg7 = stack.pop() // 58 7
199.2551 - case 277: gt = 315; continue; // 167 0 38
199.2552 - case 280: stack.push(arg10); // 21 10
199.2553 - case 282: stack.push(2); // 5
199.2554 - case 283: if (stack.pop() != stack.pop()) { gt = 308; continue; } // 160 0 25
199.2555 - case 286: stack.push(arg4); // 21 4
199.2556 - case 288: stack.push(arg8); // 21 8
199.2557 - case 290: stack.push(arg3); // 45
199.2558 - case 291: stack.push(arg11); // 21 11
199.2559 - case 293: stack.push(arg4); // 21 4
199.2560 - case 295: stack.push(stack.pop() + stack.pop()); // 96
199.2561 - case 296: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_Character_toCharsAIIACAI(v0, v1, v2)); } // 184 1 111
199.2562 - case 299: stack.push(arg10); // 21 10
199.2563 - case 301: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.2564 - case 302: stack.push(stack.pop() + stack.pop()); // 96
199.2565 - case 303: arg4 = stack.pop() // 54 4
199.2566 - case 305: gt = 409; continue; // 167 0 104
199.2567 - case 308: stack.push(arg8); // 21 8
199.2568 - case 310: { var v0 = stack.pop(); stack.push(java_lang_Character_toCharsACI(v0)); } // 184 1 109
199.2569 - case 313: arg7 = stack.pop() // 58 7
199.2570 - case 315: stack.push(arg7); // 25 7
199.2571 - case 317: stack.push(stack.pop().length); // 190
199.2572 - case 318: arg12 = stack.pop() // 54 12
199.2573 - case 320: stack.push(arg12); // 21 12
199.2574 - case 322: stack.push(arg10); // 21 10
199.2575 - case 324: if (stack.pop() >= stack.pop()) { gt = 355; continue; } // 164 0 31
199.2576 - case 327: stack.push(arg3); // 45
199.2577 - case 328: stack.push(stack.pop().length); // 190
199.2578 - case 329: stack.push(arg12); // 21 12
199.2579 - case 331: stack.push(stack.pop() + stack.pop()); // 96
199.2580 - case 332: stack.push(arg10); // 21 10
199.2581 - case 334: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.2582 - case 335: stack.push(new Array(stack.pop())); // 188 5
199.2583 - case 337: arg13 = stack.pop() // 58 13
199.2584 - case 339: stack.push(arg3); // 45
199.2585 - case 340: stack.push(0); // 3
199.2586 - case 341: stack.push(arg13); // 25 13
199.2587 - case 343: stack.push(0); // 3
199.2588 - case 344: stack.push(arg11); // 21 11
199.2589 - case 346: stack.push(arg4); // 21 4
199.2590 - case 348: stack.push(stack.pop() + stack.pop()); // 96
199.2591 - case 349: { var v4 = stack.pop(); var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_System_arraycopyVLjava_lang_ObjectILjava_lang_ObjectII(v0, v1, v2, v3, v4); } // 184 1 171
199.2592 - case 352: stack.push(arg13); // 25 13
199.2593 - case 354: arg3 = stack.pop(); // 78
199.2594 - case 355: stack.push(0); // 3
199.2595 - case 356: arg13 = stack.pop() // 54 13
199.2596 - case 358: stack.push(arg13); // 21 13
199.2597 - case 360: stack.push(arg12); // 21 12
199.2598 - case 362: if (stack.pop() <= stack.pop()) { gt = 386; continue; } // 162 0 24
199.2599 - case 365: stack.push(arg3); // 45
199.2600 - case 366: stack.push(arg11); // 21 11
199.2601 - case 368: stack.push(arg4); // 21 4
199.2602 - case 370: stack.push(stack.pop() + stack.pop()); // 96
199.2603 - case 371: stack.push(arg13); // 21 13
199.2604 - case 373: stack.push(stack.pop() + stack.pop()); // 96
199.2605 - case 374: stack.push(arg7); // 25 7
199.2606 - case 376: stack.push(arg13); // 21 13
199.2607 - case 378: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.2608 - case 379: { var value = stack.pop(); var indx = stack.pop(); stack.pop()[indx] = value; } // 85
199.2609 - case 380: arg13++; // 132 13 1
199.2610 - case 383: gt = 358; continue; // 167 255 231
199.2611 - case 386: stack.push(arg4); // 21 4
199.2612 - case 388: stack.push(arg12); // 21 12
199.2613 - case 390: stack.push(arg10); // 21 10
199.2614 - case 392: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.2615 - case 393: stack.push(stack.pop() + stack.pop()); // 96
199.2616 - case 394: arg4 = stack.pop() // 54 4
199.2617 - case 396: gt = 409; continue; // 167 0 13
199.2618 - case 399: stack.push(arg3); // 45
199.2619 - case 400: stack.push(arg11); // 21 11
199.2620 - case 402: stack.push(arg4); // 21 4
199.2621 - case 404: stack.push(stack.pop() + stack.pop()); // 96
199.2622 - case 405: stack.push(arg8); // 21 8
199.2623 - case 407: // number conversion // 146
199.2624 - case 408: { var value = stack.pop(); var indx = stack.pop(); stack.pop()[indx] = value; } // 85
199.2625 - case 409: stack.push(arg11); // 21 11
199.2626 - case 411: stack.push(arg10); // 21 10
199.2627 - case 413: stack.push(stack.pop() + stack.pop()); // 96
199.2628 - case 414: arg11 = stack.pop() // 54 11
199.2629 - case 416: gt = 157; continue; // 167 254 253
199.2630 - case 419: stack.push(new java_lang_String); // 187 0 200
199.2631 - case 422: stack.push(stack[stack.length - 1]); // 89
199.2632 - case 423: stack.push(0); // 3
199.2633 - case 424: stack.push(arg0); // 42
199.2634 - case 425: stack.push(stack.pop().count); // 180 1 97
199.2635 - case 428: stack.push(arg4); // 21 4
199.2636 - case 430: stack.push(stack.pop() + stack.pop()); // 96
199.2637 - case 431: stack.push(arg3); // 45
199.2638 - case 432: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_String_consVIIAC(stack.pop(), v0, v1, v2); } // 183 1 137
199.2639 - case 435: return stack.pop(); // 176
199.2640 - }
199.2641 -}
199.2642 -function java_lang_String_toLowerCaseLjava_lang_String(arg0) {
199.2643 - var arg1;
199.2644 -;
199.2645 - var stack = new Array(2);
199.2646 - var gt = 0;
199.2647 - for(;;) switch(gt) {
199.2648 - case 0: stack.push(arg0); // 42
199.2649 - case 1: { stack.push(java_util_Locale_getDefaultLjava_util_Locale()); } // 184 1 179
199.2650 - case 4: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.toLowerCaseLjava_lang_StringLjava_util_Locale(self, v0)); } // 182 1 158
199.2651 - case 7: return stack.pop(); // 176
199.2652 - }
199.2653 -}
199.2654 -function java_lang_String_toUpperCaseLjava_lang_StringLjava_util_Locale(arg0,arg1) {
199.2655 - var arg2;
199.2656 - var arg3;
199.2657 - var arg4;
199.2658 - var arg5;
199.2659 - var arg6;
199.2660 - var arg7;
199.2661 - var arg8;
199.2662 - var arg9;
199.2663 - var arg10;
199.2664 - var arg11;
199.2665 - var arg12;
199.2666 - var arg13;
199.2667 - var arg14;
199.2668 -;
199.2669 - var stack = new Array(6);
199.2670 - var gt = 0;
199.2671 - for(;;) switch(gt) {
199.2672 - case 0: stack.push(arg1); // 43
199.2673 - case 1: if (stack.pop()) { gt = 12; continue; } // 199 0 11
199.2674 - case 4: stack.push(new java_lang_NullPointerException); // 187 0 198
199.2675 - case 7: stack.push(stack[stack.length - 1]); // 89
199.2676 - case 8: { java_lang_NullPointerException_consV(stack.pop()); } // 183 1 128
199.2677 - case 11: // 191
199.2678 - case 12: stack.push(0); // 3
199.2679 - case 13: arg2 = stack.pop(); // 61
199.2680 - case 14: stack.push(arg2); // 28
199.2681 - case 15: stack.push(arg0); // 42
199.2682 - case 16: stack.push(stack.pop().count); // 180 1 97
199.2683 - case 19: if (stack.pop() <= stack.pop()) { gt = 93; continue; } // 162 0 74
199.2684 - case 22: stack.push(arg0); // 42
199.2685 - case 23: stack.push(stack.pop().value); // 180 1 100
199.2686 - case 26: stack.push(arg0); // 42
199.2687 - case 27: stack.push(stack.pop().offset); // 180 1 99
199.2688 - case 30: stack.push(arg2); // 28
199.2689 - case 31: stack.push(stack.pop() + stack.pop()); // 96
199.2690 - case 32: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.2691 - case 33: arg3 = stack.pop(); // 62
199.2692 - case 34: stack.push(arg3); // 29
199.2693 - case 35: stack.push(55296); // 18 1
199.2694 - case 37: if (stack.pop() > stack.pop()) { gt = 61; continue; } // 161 0 24
199.2695 - case 40: stack.push(arg3); // 29
199.2696 - case 41: stack.push(56319); // 18 2
199.2697 - case 43: if (stack.pop() < stack.pop()) { gt = 61; continue; } // 163 0 18
199.2698 - case 46: stack.push(arg0); // 42
199.2699 - case 47: stack.push(arg2); // 28
199.2700 - case 48: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.codePointAtII(self, v0)); } // 182 1 134
199.2701 - case 51: arg3 = stack.pop(); // 62
199.2702 - case 52: stack.push(arg3); // 29
199.2703 - case 53: { var v0 = stack.pop(); stack.push(java_lang_Character_charCountII(v0)); } // 184 1 106
199.2704 - case 56: arg4 = stack.pop() // 54 4
199.2705 - case 58: gt = 64; continue; // 167 0 6
199.2706 - case 61: stack.push(1); // 4
199.2707 - case 62: arg4 = stack.pop() // 54 4
199.2708 - case 64: stack.push(arg3); // 29
199.2709 - case 65: { var v0 = stack.pop(); stack.push(java_lang_Character_toUpperCaseExII(v0)); } // 184 1 108
199.2710 - case 68: arg5 = stack.pop() // 54 5
199.2711 - case 70: stack.push(arg5); // 21 5
199.2712 - case 72: // 2
199.2713 - case 73: if (stack.pop() == stack.pop()) { gt = 95; continue; } // 159 0 22
199.2714 - case 76: stack.push(arg3); // 29
199.2715 - case 77: stack.push(arg5); // 21 5
199.2716 - case 79: if (stack.pop() == stack.pop()) { gt = 85; continue; } // 159 0 6
199.2717 - case 82: gt = 95; continue; // 167 0 13
199.2718 - case 85: stack.push(arg2); // 28
199.2719 - case 86: stack.push(arg4); // 21 4
199.2720 - case 88: stack.push(stack.pop() + stack.pop()); // 96
199.2721 - case 89: arg2 = stack.pop(); // 61
199.2722 - case 90: gt = 14; continue; // 167 255 180
199.2723 - case 93: stack.push(arg0); // 42
199.2724 - case 94: return stack.pop(); // 176
199.2725 - case 95: stack.push(arg0); // 42
199.2726 - case 96: stack.push(stack.pop().count); // 180 1 97
199.2727 - case 99: stack.push(new Array(stack.pop())); // 188 5
199.2728 - case 101: arg3 = stack.pop(); // 78
199.2729 - case 102: stack.push(0); // 3
199.2730 - case 103: arg4 = stack.pop() // 54 4
199.2731 - case 105: stack.push(arg0); // 42
199.2732 - case 106: stack.push(stack.pop().value); // 180 1 100
199.2733 - case 109: stack.push(arg0); // 42
199.2734 - case 110: stack.push(stack.pop().offset); // 180 1 99
199.2735 - case 113: stack.push(arg3); // 45
199.2736 - case 114: stack.push(0); // 3
199.2737 - case 115: stack.push(arg2); // 28
199.2738 - case 116: { var v4 = stack.pop(); var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_System_arraycopyVLjava_lang_ObjectILjava_lang_ObjectII(v0, v1, v2, v3, v4); } // 184 1 171
199.2739 - case 119: stack.push(arg1); // 43
199.2740 - case 120: { var self = stack.pop(); stack.push(self.getLanguageLjava_lang_String(self)); } // 182 1 178
199.2741 - case 123: arg5 = stack.pop() // 58 5
199.2742 - case 125: stack.push(arg5); // 25 5
199.2743 - case 127: stack.push("tr"); // 18 11
199.2744 - case 129: // 165
199.2745 - case 130: // 0
199.2746 - case 131: stack.push(6405); // 17 25 5
199.2747 - case 134: stack.push("az"); // 18 5
199.2748 - case 136: // 165
199.2749 - case 137: // 0
199.2750 - case 138: stack.push(1); // 10
199.2751 - case 139: stack.push(arg5); // 25 5
199.2752 - case 141: stack.push("lt"); // 18 9
199.2753 - case 143: // 166
199.2754 - case 144: // 0
199.2755 - case 145: stack.push(4); // 7
199.2756 - case 146: stack.push(1); // 4
199.2757 - case 147: gt = 151; continue; // 167 0 4
199.2758 - case 150: stack.push(0); // 3
199.2759 - case 151: arg6 = stack.pop() // 54 6
199.2760 - case 153: stack.push(arg2); // 28
199.2761 - case 154: arg11 = stack.pop() // 54 11
199.2762 - case 156: stack.push(arg11); // 21 11
199.2763 - case 158: stack.push(arg0); // 42
199.2764 - case 159: stack.push(stack.pop().count); // 180 1 97
199.2765 - case 162: if (stack.pop() <= stack.pop()) { gt = 425; continue; } // 162 1 7
199.2766 - case 165: stack.push(arg0); // 42
199.2767 - case 166: stack.push(stack.pop().value); // 180 1 100
199.2768 - case 169: stack.push(arg0); // 42
199.2769 - case 170: stack.push(stack.pop().offset); // 180 1 99
199.2770 - case 173: stack.push(arg11); // 21 11
199.2771 - case 175: stack.push(stack.pop() + stack.pop()); // 96
199.2772 - case 176: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.2773 - case 177: arg9 = stack.pop() // 54 9
199.2774 - case 179: stack.push(arg9); // 21 9
199.2775 - case 181: // number conversion // 146
199.2776 - case 182: stack.push(55296); // 18 1
199.2777 - case 184: if (stack.pop() > stack.pop()) { gt = 213; continue; } // 161 0 29
199.2778 - case 187: stack.push(arg9); // 21 9
199.2779 - case 189: // number conversion // 146
199.2780 - case 190: stack.push(56319); // 18 2
199.2781 - case 192: if (stack.pop() < stack.pop()) { gt = 213; continue; } // 163 0 21
199.2782 - case 195: stack.push(arg0); // 42
199.2783 - case 196: stack.push(arg11); // 21 11
199.2784 - case 198: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.codePointAtII(self, v0)); } // 182 1 134
199.2785 - case 201: arg9 = stack.pop() // 54 9
199.2786 - case 203: stack.push(arg9); // 21 9
199.2787 - case 205: { var v0 = stack.pop(); stack.push(java_lang_Character_charCountII(v0)); } // 184 1 106
199.2788 - case 208: arg10 = stack.pop() // 54 10
199.2789 - case 210: gt = 216; continue; // 167 0 6
199.2790 - case 213: stack.push(1); // 4
199.2791 - case 214: arg10 = stack.pop() // 54 10
199.2792 - case 216: stack.push(arg6); // 21 6
199.2793 - case 218: if (stack.pop() == 0) { gt = 233; continue; } // 153 0 15
199.2794 - case 221: stack.push(arg0); // 42
199.2795 - case 222: stack.push(arg11); // 21 11
199.2796 - case 224: stack.push(arg1); // 43
199.2797 - case 225: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_ConditionalSpecialCasing_toUpperCaseExILjava_lang_StringILjava_util_Locale(v0, v1, v2)); } // 184 1 118
199.2798 - case 228: arg8 = stack.pop() // 54 8
199.2799 - case 230: gt = 240; continue; // 167 0 10
199.2800 - case 233: stack.push(arg9); // 21 9
199.2801 - case 235: { var v0 = stack.pop(); stack.push(java_lang_Character_toUpperCaseExII(v0)); } // 184 1 108
199.2802 - case 238: arg8 = stack.pop() // 54 8
199.2803 - case 240: stack.push(arg8); // 21 8
199.2804 - case 242: // 2
199.2805 - case 243: if (stack.pop() == stack.pop()) { gt = 253; continue; } // 159 0 10
199.2806 - case 246: stack.push(arg8); // 21 8
199.2807 - case 248: stack.push(65536); // 18 3
199.2808 - case 250: if (stack.pop() > stack.pop()) { gt = 405; continue; } // 161 0 155
199.2809 - case 253: stack.push(arg8); // 21 8
199.2810 - case 255: // 2
199.2811 - case 256: if (stack.pop() != stack.pop()) { gt = 286; continue; } // 160 0 30
199.2812 - case 259: stack.push(arg6); // 21 6
199.2813 - case 261: if (stack.pop() == 0) { gt = 276; continue; } // 153 0 15
199.2814 - case 264: stack.push(arg0); // 42
199.2815 - case 265: stack.push(arg11); // 21 11
199.2816 - case 267: stack.push(arg1); // 43
199.2817 - case 268: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_ConditionalSpecialCasing_toUpperCaseCharArrayACLjava_lang_StringILjava_util_Locale(v0, v1, v2)); } // 184 1 120
199.2818 - case 271: arg7 = stack.pop() // 58 7
199.2819 - case 273: gt = 321; continue; // 167 0 48
199.2820 - case 276: stack.push(arg9); // 21 9
199.2821 - case 278: { var v0 = stack.pop(); stack.push(java_lang_Character_toUpperCaseCharArrayACI(v0)); } // 184 1 110
199.2822 - case 281: arg7 = stack.pop() // 58 7
199.2823 - case 283: gt = 321; continue; // 167 0 38
199.2824 - case 286: stack.push(arg10); // 21 10
199.2825 - case 288: stack.push(2); // 5
199.2826 - case 289: if (stack.pop() != stack.pop()) { gt = 314; continue; } // 160 0 25
199.2827 - case 292: stack.push(arg4); // 21 4
199.2828 - case 294: stack.push(arg8); // 21 8
199.2829 - case 296: stack.push(arg3); // 45
199.2830 - case 297: stack.push(arg11); // 21 11
199.2831 - case 299: stack.push(arg4); // 21 4
199.2832 - case 301: stack.push(stack.pop() + stack.pop()); // 96
199.2833 - case 302: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_Character_toCharsAIIACAI(v0, v1, v2)); } // 184 1 111
199.2834 - case 305: stack.push(arg10); // 21 10
199.2835 - case 307: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.2836 - case 308: stack.push(stack.pop() + stack.pop()); // 96
199.2837 - case 309: arg4 = stack.pop() // 54 4
199.2838 - case 311: gt = 415; continue; // 167 0 104
199.2839 - case 314: stack.push(arg8); // 21 8
199.2840 - case 316: { var v0 = stack.pop(); stack.push(java_lang_Character_toCharsACI(v0)); } // 184 1 109
199.2841 - case 319: arg7 = stack.pop() // 58 7
199.2842 - case 321: stack.push(arg7); // 25 7
199.2843 - case 323: stack.push(stack.pop().length); // 190
199.2844 - case 324: arg12 = stack.pop() // 54 12
199.2845 - case 326: stack.push(arg12); // 21 12
199.2846 - case 328: stack.push(arg10); // 21 10
199.2847 - case 330: if (stack.pop() >= stack.pop()) { gt = 361; continue; } // 164 0 31
199.2848 - case 333: stack.push(arg3); // 45
199.2849 - case 334: stack.push(stack.pop().length); // 190
199.2850 - case 335: stack.push(arg12); // 21 12
199.2851 - case 337: stack.push(stack.pop() + stack.pop()); // 96
199.2852 - case 338: stack.push(arg10); // 21 10
199.2853 - case 340: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.2854 - case 341: stack.push(new Array(stack.pop())); // 188 5
199.2855 - case 343: arg13 = stack.pop() // 58 13
199.2856 - case 345: stack.push(arg3); // 45
199.2857 - case 346: stack.push(0); // 3
199.2858 - case 347: stack.push(arg13); // 25 13
199.2859 - case 349: stack.push(0); // 3
199.2860 - case 350: stack.push(arg11); // 21 11
199.2861 - case 352: stack.push(arg4); // 21 4
199.2862 - case 354: stack.push(stack.pop() + stack.pop()); // 96
199.2863 - case 355: { var v4 = stack.pop(); var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_System_arraycopyVLjava_lang_ObjectILjava_lang_ObjectII(v0, v1, v2, v3, v4); } // 184 1 171
199.2864 - case 358: stack.push(arg13); // 25 13
199.2865 - case 360: arg3 = stack.pop(); // 78
199.2866 - case 361: stack.push(0); // 3
199.2867 - case 362: arg13 = stack.pop() // 54 13
199.2868 - case 364: stack.push(arg13); // 21 13
199.2869 - case 366: stack.push(arg12); // 21 12
199.2870 - case 368: if (stack.pop() <= stack.pop()) { gt = 392; continue; } // 162 0 24
199.2871 - case 371: stack.push(arg3); // 45
199.2872 - case 372: stack.push(arg11); // 21 11
199.2873 - case 374: stack.push(arg4); // 21 4
199.2874 - case 376: stack.push(stack.pop() + stack.pop()); // 96
199.2875 - case 377: stack.push(arg13); // 21 13
199.2876 - case 379: stack.push(stack.pop() + stack.pop()); // 96
199.2877 - case 380: stack.push(arg7); // 25 7
199.2878 - case 382: stack.push(arg13); // 21 13
199.2879 - case 384: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.2880 - case 385: { var value = stack.pop(); var indx = stack.pop(); stack.pop()[indx] = value; } // 85
199.2881 - case 386: arg13++; // 132 13 1
199.2882 - case 389: gt = 364; continue; // 167 255 231
199.2883 - case 392: stack.push(arg4); // 21 4
199.2884 - case 394: stack.push(arg12); // 21 12
199.2885 - case 396: stack.push(arg10); // 21 10
199.2886 - case 398: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.2887 - case 399: stack.push(stack.pop() + stack.pop()); // 96
199.2888 - case 400: arg4 = stack.pop() // 54 4
199.2889 - case 402: gt = 415; continue; // 167 0 13
199.2890 - case 405: stack.push(arg3); // 45
199.2891 - case 406: stack.push(arg11); // 21 11
199.2892 - case 408: stack.push(arg4); // 21 4
199.2893 - case 410: stack.push(stack.pop() + stack.pop()); // 96
199.2894 - case 411: stack.push(arg8); // 21 8
199.2895 - case 413: // number conversion // 146
199.2896 - case 414: { var value = stack.pop(); var indx = stack.pop(); stack.pop()[indx] = value; } // 85
199.2897 - case 415: stack.push(arg11); // 21 11
199.2898 - case 417: stack.push(arg10); // 21 10
199.2899 - case 419: stack.push(stack.pop() + stack.pop()); // 96
199.2900 - case 420: arg11 = stack.pop() // 54 11
199.2901 - case 422: gt = 156; continue; // 167 254 246
199.2902 - case 425: stack.push(new java_lang_String); // 187 0 200
199.2903 - case 428: stack.push(stack[stack.length - 1]); // 89
199.2904 - case 429: stack.push(0); // 3
199.2905 - case 430: stack.push(arg0); // 42
199.2906 - case 431: stack.push(stack.pop().count); // 180 1 97
199.2907 - case 434: stack.push(arg4); // 21 4
199.2908 - case 436: stack.push(stack.pop() + stack.pop()); // 96
199.2909 - case 437: stack.push(arg3); // 45
199.2910 - case 438: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_String_consVIIAC(stack.pop(), v0, v1, v2); } // 183 1 137
199.2911 - case 441: return stack.pop(); // 176
199.2912 - }
199.2913 -}
199.2914 -function java_lang_String_toUpperCaseLjava_lang_String(arg0) {
199.2915 - var arg1;
199.2916 -;
199.2917 - var stack = new Array(2);
199.2918 - var gt = 0;
199.2919 - for(;;) switch(gt) {
199.2920 - case 0: stack.push(arg0); // 42
199.2921 - case 1: { stack.push(java_util_Locale_getDefaultLjava_util_Locale()); } // 184 1 179
199.2922 - case 4: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.toUpperCaseLjava_lang_StringLjava_util_Locale(self, v0)); } // 182 1 159
199.2923 - case 7: return stack.pop(); // 176
199.2924 - }
199.2925 -}
199.2926 -function java_lang_String_trimLjava_lang_String(arg0) {
199.2927 - var arg1;
199.2928 - var arg2;
199.2929 - var arg3;
199.2930 - var arg4;
199.2931 - var arg5;
199.2932 -;
199.2933 - var stack = new Array(3);
199.2934 - var gt = 0;
199.2935 - for(;;) switch(gt) {
199.2936 - case 0: stack.push(arg0); // 42
199.2937 - case 1: stack.push(stack.pop().count); // 180 1 97
199.2938 - case 4: arg1 = stack.pop(); // 60
199.2939 - case 5: stack.push(0); // 3
199.2940 - case 6: arg2 = stack.pop(); // 61
199.2941 - case 7: stack.push(arg0); // 42
199.2942 - case 8: stack.push(stack.pop().offset); // 180 1 99
199.2943 - case 11: arg3 = stack.pop(); // 62
199.2944 - case 12: stack.push(arg0); // 42
199.2945 - case 13: stack.push(stack.pop().value); // 180 1 100
199.2946 - case 16: arg4 = stack.pop() // 58 4
199.2947 - case 18: stack.push(arg2); // 28
199.2948 - case 19: stack.push(arg1); // 27
199.2949 - case 20: if (stack.pop() <= stack.pop()) { gt = 40; continue; } // 162 0 20
199.2950 - case 23: stack.push(arg4); // 25 4
199.2951 - case 25: stack.push(arg3); // 29
199.2952 - case 26: stack.push(arg2); // 28
199.2953 - case 27: stack.push(stack.pop() + stack.pop()); // 96
199.2954 - case 28: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.2955 - case 29: stack.push(32); // 16 32
199.2956 - case 31: if (stack.pop() < stack.pop()) { gt = 40; continue; } // 163 0 9
199.2957 - case 34: arg2++; // 132 2 1
199.2958 - case 37: gt = 18; continue; // 167 255 237
199.2959 - case 40: stack.push(arg2); // 28
199.2960 - case 41: stack.push(arg1); // 27
199.2961 - case 42: if (stack.pop() <= stack.pop()) { gt = 64; continue; } // 162 0 22
199.2962 - case 45: stack.push(arg4); // 25 4
199.2963 - case 47: stack.push(arg3); // 29
199.2964 - case 48: stack.push(arg1); // 27
199.2965 - case 49: stack.push(stack.pop() + stack.pop()); // 96
199.2966 - case 50: stack.push(1); // 4
199.2967 - case 51: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
199.2968 - case 52: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
199.2969 - case 53: stack.push(32); // 16 32
199.2970 - case 55: if (stack.pop() < stack.pop()) { gt = 64; continue; } // 163 0 9
199.2971 - case 58: arg1 += 255; // 132 1 255
199.2972 - case 61: gt = 40; continue; // 167 255 235
199.2973 - case 64: stack.push(arg2); // 28
199.2974 - case 65: if (stack.pop() > 0) { gt = 76; continue; } // 157 0 11
199.2975 - case 68: stack.push(arg1); // 27
199.2976 - case 69: stack.push(arg0); // 42
199.2977 - case 70: stack.push(stack.pop().count); // 180 1 97
199.2978 - case 73: if (stack.pop() <= stack.pop()) { gt = 85; continue; } // 162 0 12
199.2979 - case 76: stack.push(arg0); // 42
199.2980 - case 77: stack.push(arg2); // 28
199.2981 - case 78: stack.push(arg1); // 27
199.2982 - case 79: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.substringLjava_lang_StringII(self, v0, v1)); } // 182 1 147
199.2983 - case 82: gt = 86; continue; // 167 0 4
199.2984 - case 85: stack.push(arg0); // 42
199.2985 - case 86: return stack.pop(); // 176
199.2986 - }
199.2987 -}
199.2988 -*/
199.2989 -function java_lang_String_toStringLjava_lang_String(arg0) {
199.2990 - return arg0.toString();
199.2991 -}
199.2992 -/*
199.2993 -function java_lang_String_toCharArrayAC(arg0) {
199.2994 - var arg1;
199.2995 - var arg2;
199.2996 -;
199.2997 - var stack = new Array(5);
199.2998 - var gt = 0;
199.2999 - for(;;) switch(gt) {
199.3000 - case 0: stack.push(arg0); // 42
199.3001 - case 1: stack.push(stack.pop().count); // 180 1 97
199.3002 - case 4: stack.push(new Array(stack.pop())); // 188 5
199.3003 - case 6: arg1 = stack.pop(); // 76
199.3004 - case 7: stack.push(arg0); // 42
199.3005 - case 8: stack.push(0); // 3
199.3006 - case 9: stack.push(arg0); // 42
199.3007 - case 10: stack.push(stack.pop().count); // 180 1 97
199.3008 - case 13: stack.push(arg1); // 43
199.3009 - case 14: stack.push(0); // 3
199.3010 - case 15: { var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); self.getCharsVIIACAI(self, v0, v1, v2, v3); } // 182 1 138
199.3011 - case 18: stack.push(arg1); // 43
199.3012 - case 19: return stack.pop(); // 176
199.3013 - }
199.3014 -}
199.3015 -function java_lang_String_formatLjava_lang_StringLjava_lang_StringLjava_lang_Object(arg0,arg1) {
199.3016 - var stack = new Array();
199.3017 - var gt = 0;
199.3018 - for(;;) switch(gt) {
199.3019 - case 0: stack.push(new java_util_Formatter); // 187 0 211
199.3020 - case 3: stack.push(stack[stack.length - 1]); // 89
199.3021 - case 4: { java_util_Formatter_consV(stack.pop()); } // 183 1 174
199.3022 - case 7: stack.push(arg0); // 42
199.3023 - case 8: stack.push(arg1); // 43
199.3024 - case 9: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.formatALjava_util_FormatterLjava_lang_StringALjava_lang_Object(self, v0, v1)); } // 182 1 177
199.3025 - case 12: { var self = stack.pop(); stack.push(self.toStringLjava_lang_String(self)); } // 182 1 175
199.3026 - case 15: return stack.pop(); // 176
199.3027 - }
199.3028 -}
199.3029 -function java_lang_String_formatLjava_lang_StringLjava_util_LocaleLjava_lang_StringLjava_lang_Object(arg0,arg1,arg2) {
199.3030 - var stack = new Array();
199.3031 - var gt = 0;
199.3032 - for(;;) switch(gt) {
199.3033 - case 0: stack.push(new java_util_Formatter); // 187 0 211
199.3034 - case 3: stack.push(stack[stack.length - 1]); // 89
199.3035 - case 4: stack.push(arg0); // 42
199.3036 - case 5: { var v0 = stack.pop(); java_util_Formatter_consVLjava_util_Locale(stack.pop(), v0); } // 183 1 176
199.3037 - case 8: stack.push(arg1); // 43
199.3038 - case 9: stack.push(arg2); // 44
199.3039 - case 10: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.formatALjava_util_FormatterLjava_lang_StringALjava_lang_Object(self, v0, v1)); } // 182 1 177
199.3040 - case 13: { var self = stack.pop(); stack.push(self.toStringLjava_lang_String(self)); } // 182 1 175
199.3041 - case 16: return stack.pop(); // 176
199.3042 - }
199.3043 -}
199.3044 -function java_lang_String_valueOfLjava_lang_StringLjava_lang_Object(arg0) {
199.3045 - var stack = new Array();
199.3046 - var gt = 0;
199.3047 - for(;;) switch(gt) {
199.3048 - case 0: stack.push(arg0); // 42
199.3049 - case 1: if (stack.pop()) { gt = 9; continue; } // 199 0 8
199.3050 - case 4: stack.push("null"); // 18 10
199.3051 - case 6: gt = 13; continue; // 167 0 7
199.3052 - case 9: stack.push(arg0); // 42
199.3053 - case 10: { var self = stack.pop(); stack.push(self.toStringLjava_lang_String(self)); } // 182 1 132
199.3054 - case 13: return stack.pop(); // 176
199.3055 - }
199.3056 -}
199.3057 -function java_lang_String_valueOfLjava_lang_StringAC(arg0) {
199.3058 - var stack = new Array();
199.3059 - var gt = 0;
199.3060 - for(;;) switch(gt) {
199.3061 - case 0: stack.push(new java_lang_String); // 187 0 200
199.3062 - case 3: stack.push(stack[stack.length - 1]); // 89
199.3063 - case 4: stack.push(arg0); // 42
199.3064 - case 5: { var v0 = stack.pop(); java_lang_String_consVAC(stack.pop(), v0); } // 183 1 142
199.3065 - case 8: return stack.pop(); // 176
199.3066 - }
199.3067 -}
199.3068 -function java_lang_String_valueOfLjava_lang_StringACII(arg0,arg1,arg2) {
199.3069 - var stack = new Array();
199.3070 - var gt = 0;
199.3071 - for(;;) switch(gt) {
199.3072 - case 0: stack.push(new java_lang_String); // 187 0 200
199.3073 - case 3: stack.push(stack[stack.length - 1]); // 89
199.3074 - case 4: stack.push(arg0); // 42
199.3075 - case 5: stack.push(arg1); // 27
199.3076 - case 6: stack.push(arg2); // 28
199.3077 - case 7: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_String_consVACAIAI(stack.pop(), v0, v1, v2); } // 183 1 143
199.3078 - case 10: return stack.pop(); // 176
199.3079 - }
199.3080 -}
199.3081 -function java_lang_String_copyValueOfLjava_lang_StringACII(arg0,arg1,arg2) {
199.3082 - var stack = new Array();
199.3083 - var gt = 0;
199.3084 - for(;;) switch(gt) {
199.3085 - case 0: stack.push(new java_lang_String); // 187 0 200
199.3086 - case 3: stack.push(stack[stack.length - 1]); // 89
199.3087 - case 4: stack.push(arg0); // 42
199.3088 - case 5: stack.push(arg1); // 27
199.3089 - case 6: stack.push(arg2); // 28
199.3090 - case 7: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_String_consVACAIAI(stack.pop(), v0, v1, v2); } // 183 1 143
199.3091 - case 10: return stack.pop(); // 176
199.3092 - }
199.3093 -}
199.3094 -function java_lang_String_copyValueOfLjava_lang_StringAC(arg0) {
199.3095 - var stack = new Array();
199.3096 - var gt = 0;
199.3097 - for(;;) switch(gt) {
199.3098 - case 0: stack.push(arg0); // 42
199.3099 - case 1: stack.push(0); // 3
199.3100 - case 2: stack.push(arg0); // 42
199.3101 - case 3: stack.push(stack.pop().length); // 190
199.3102 - case 4: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_String_copyValueOfALjava_lang_StringACAIAI(v0, v1, v2)); } // 184 1 155
199.3103 - case 7: return stack.pop(); // 176
199.3104 - }
199.3105 -}
199.3106 -function java_lang_String_valueOfLjava_lang_StringZ(arg0) {
199.3107 - var stack = new Array();
199.3108 - var gt = 0;
199.3109 - for(;;) switch(gt) {
199.3110 - case 0: stack.push(arg0); // 26
199.3111 - case 1: if (stack.pop() == 0) { gt = 9; continue; } // 153 0 8
199.3112 - case 4: stack.push("true"); // 18 12
199.3113 - case 6: gt = 11; continue; // 167 0 5
199.3114 - case 9: stack.push("false"); // 18 8
199.3115 - case 11: return stack.pop(); // 176
199.3116 - }
199.3117 -}
199.3118 -function java_lang_String_valueOfLjava_lang_StringC(arg0) {
199.3119 - var arg1;
199.3120 - var stack = new Array();
199.3121 - var gt = 0;
199.3122 - for(;;) switch(gt) {
199.3123 - case 0: stack.push(1); // 4
199.3124 - case 1: stack.push(new Array(stack.pop())); // 188 5
199.3125 - case 3: stack.push(stack[stack.length - 1]); // 89
199.3126 - case 4: stack.push(0); // 3
199.3127 - case 5: stack.push(arg0); // 26
199.3128 - case 6: { var value = stack.pop(); var indx = stack.pop(); stack.pop()[indx] = value; } // 85
199.3129 - case 7: arg1 = stack.pop(); // 76
199.3130 - case 8: stack.push(new java_lang_String); // 187 0 200
199.3131 - case 11: stack.push(stack[stack.length - 1]); // 89
199.3132 - case 12: stack.push(0); // 3
199.3133 - case 13: stack.push(1); // 4
199.3134 - case 14: stack.push(arg1); // 43
199.3135 - case 15: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_String_consVIIAC(stack.pop(), v0, v1, v2); } // 183 1 137
199.3136 - case 18: return stack.pop(); // 176
199.3137 - }
199.3138 -}
199.3139 -function java_lang_String_valueOfLjava_lang_StringI(arg0) {
199.3140 - var stack = new Array();
199.3141 - var gt = 0;
199.3142 - for(;;) switch(gt) {
199.3143 - case 0: stack.push(arg0); // 26
199.3144 - case 1: stack.push(10); // 16 10
199.3145 - case 3: { var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_Integer_toStringLjava_lang_StringII(v0, v1)); } // 184 1 125
199.3146 - case 6: return stack.pop(); // 176
199.3147 - }
199.3148 -}
199.3149 -function java_lang_String_valueOfLjava_lang_StringJ(arg0) {
199.3150 - var arg1;
199.3151 - var stack = new Array();
199.3152 - var gt = 0;
199.3153 - for(;;) switch(gt) {
199.3154 - case 0: stack.push(arg0); // 30
199.3155 - case 1: stack.push(10); // 16 10
199.3156 - case 3: { var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_Long_toStringLjava_lang_StringJI(v0, v1)); } // 184 1 126
199.3157 - case 6: return stack.pop(); // 176
199.3158 - }
199.3159 -}
199.3160 -function java_lang_String_valueOfLjava_lang_StringF(arg0) {
199.3161 - var stack = new Array();
199.3162 - var gt = 0;
199.3163 - for(;;) switch(gt) {
199.3164 - case 0: stack.push(arg0); // 34
199.3165 - case 1: { var v0 = stack.pop(); stack.push(java_lang_Float_toStringLjava_lang_StringF(v0)); } // 184 1 122
199.3166 - case 4: return stack.pop(); // 176
199.3167 - }
199.3168 -}
199.3169 -function java_lang_String_valueOfLjava_lang_StringD(arg0) {
199.3170 - var arg1;
199.3171 - var stack = new Array();
199.3172 - var gt = 0;
199.3173 - for(;;) switch(gt) {
199.3174 - case 0: stack.push(arg0); // 38
199.3175 - case 1: { var v0 = stack.pop(); stack.push(java_lang_Double_toStringLjava_lang_StringD(v0)); } // 184 1 121
199.3176 - case 4: return stack.pop(); // 176
199.3177 - }
199.3178 -}
199.3179 -function java_lang_String_internLjava_lang_String(arg0) {
199.3180 - // no code found for null
199.3181 -}
199.3182 -function java_lang_String_compareToILjava_lang_Object(arg0,arg1) {
199.3183 - var arg2;
199.3184 -;
199.3185 - var stack = new Array(2);
199.3186 - var gt = 0;
199.3187 - for(;;) switch(gt) {
199.3188 - case 0: stack.push(arg0); // 42
199.3189 - case 1: stack.push(arg1); // 43
199.3190 - case 2: if(stack[stack.length - 1].$instOf_java_lang_String != 1) throw {}; // 192 0 200
199.3191 - case 5: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.compareToILjava_lang_String(self, v0)); } // 182 1 148
199.3192 - case 8: return stack.pop(); // 172
199.3193 - }
199.3194 -}
199.3195 -function java_lang_String_classV() {
199.3196 - var stack = new Array();
199.3197 - var gt = 0;
199.3198 - for(;;) switch(gt) {
199.3199 - case 0: stack.push(0); // 3
199.3200 - case 1: stack.push(new Array(stack.pop())); // 189 0 183
199.3201 - case 4: java_lang_String_serialPersistentFields = stack.pop(); // 179 1 101
199.3202 - case 7: stack.push(new java_lang_String$CaseInsensitiveComparator); // 187 0 202
199.3203 - case 10: stack.push(stack[stack.length - 1]); // 89
199.3204 - case 11: // 1
199.3205 - case 12: { var v0 = stack.pop(); java_lang_String$CaseInsensitiveComparator_consVLjava_lang_String$1(stack.pop(), v0); } // 183 1 160
199.3206 - case 15: java_lang_String_CASE_INSENSITIVE_ORDER = stack.pop(); // 179 1 102
199.3207 - case 18: return; // 177
199.3208 - }
199.3209 -}
199.3210 -*/
199.3211 -var java_lang_String_serialVersionUID = 0;
199.3212 -var java_lang_String_serialPersistentFields = 0;
199.3213 -var java_lang_String_CASE_INSENSITIVE_ORDER = 0;
199.3214 -function java_lang_String() {
199.3215 - /** the real value of this 'string' we delegate to */
199.3216 - this.r = '';
199.3217 -
199.3218 - var self = this;
199.3219 - /*
199.3220 - this.value = 0;
199.3221 - this.offset = 0;
199.3222 - this.count = 0;
199.3223 - this.hash = 0;
199.3224 - */
199.3225 - this.toString = function() { return self.r; };
199.3226 -}
199.3227 -java_lang_String.prototype = new String;
199.3228 -//java_lang_String_classV();
199.3229 -
199.3230 -/* new method for JavaScript String */
199.3231 -String.prototype.charAtCI = java_lang_String_charAtCI;
199.3232 -String.prototype.lengthI = java_lang_String_lengthI;
199.3233 -String.prototype.isEmptyZ = java_lang_String_isEmptyZ;
199.3234 -String.prototype.getCharsVIIACAI = java_lang_String_getCharsVIIACAI;
199.3235 -String.prototype.toStringLjava_lang_String = java_lang_String_toStringLjava_lang_String;
199.3236 -String.prototype.$instOf_java_lang_String = true;
199.3237 -String.prototype.$instOf_java_io_Serializable = true;
199.3238 -String.prototype.$instOf_java_lang_Comparable = true;
199.3239 -String.prototype.$instOf_java_lang_CharSequence = true;
199.3240 -
199.3241 -/*
199.3242 - this.lengthI = java_lang_String_lengthI;
199.3243 - this.isEmptyZ = java_lang_String_isEmptyZ;
199.3244 - this.charAtCI = java_lang_String_charAtCI;
199.3245 - this.codePointAtII = java_lang_String_codePointAtII;
199.3246 - this.codePointBeforeII = java_lang_String_codePointBeforeII;
199.3247 - this.codePointCountIII = java_lang_String_codePointCountIII;
199.3248 - this.offsetByCodePointsIII = java_lang_String_offsetByCodePointsIII;
199.3249 - this.getCharsVACI = java_lang_String_getCharsVACI;
199.3250 - this.getCharsVIIACI = java_lang_String_getCharsVIIACI;
199.3251 - this.getBytesVIIABI = java_lang_String_getBytesVIIABI;
199.3252 - this.getBytesABLjava_lang_String = java_lang_String_getBytesABLjava_lang_String;
199.3253 - this.getBytesABLjava_nio_charset_Charset = java_lang_String_getBytesABLjava_nio_charset_Charset;
199.3254 - this.getBytesAB = java_lang_String_getBytesAB;
199.3255 - this.equalsZLjava_lang_Object = java_lang_String_equalsZLjava_lang_Object;
199.3256 - this.contentEqualsZLjava_lang_StringBuffer = java_lang_String_contentEqualsZLjava_lang_StringBuffer;
199.3257 - this.contentEqualsZLjava_lang_CharSequence = java_lang_String_contentEqualsZLjava_lang_CharSequence;
199.3258 - this.equalsIgnoreCaseZLjava_lang_String = java_lang_String_equalsIgnoreCaseZLjava_lang_String;
199.3259 - this.compareToILjava_lang_String = java_lang_String_compareToILjava_lang_String;
199.3260 - this.compareToIgnoreCaseILjava_lang_String = java_lang_String_compareToIgnoreCaseILjava_lang_String;
199.3261 - this.regionMatchesZILjava_lang_StringII = java_lang_String_regionMatchesZILjava_lang_StringII;
199.3262 - this.regionMatchesZZILjava_lang_StringII = java_lang_String_regionMatchesZZILjava_lang_StringII;
199.3263 - this.startsWithZLjava_lang_StringI = java_lang_String_startsWithZLjava_lang_StringI;
199.3264 - this.startsWithZLjava_lang_String = java_lang_String_startsWithZLjava_lang_String;
199.3265 - this.endsWithZLjava_lang_String = java_lang_String_endsWithZLjava_lang_String;
199.3266 - this.hashCodeI = java_lang_String_hashCodeI;
199.3267 - this.indexOfII = java_lang_String_indexOfII;
199.3268 - this.indexOfIII = java_lang_String_indexOfIII;
199.3269 - this.lastIndexOfII = java_lang_String_lastIndexOfII;
199.3270 - this.lastIndexOfIII = java_lang_String_lastIndexOfIII;
199.3271 - this.indexOfILjava_lang_String = java_lang_String_indexOfILjava_lang_String;
199.3272 - this.indexOfILjava_lang_StringI = java_lang_String_indexOfILjava_lang_StringI;
199.3273 - this.lastIndexOfILjava_lang_String = java_lang_String_lastIndexOfILjava_lang_String;
199.3274 - this.lastIndexOfILjava_lang_StringI = java_lang_String_lastIndexOfILjava_lang_StringI;
199.3275 - this.substringLjava_lang_StringI = java_lang_String_substringLjava_lang_StringI;
199.3276 - this.substringLjava_lang_StringII = java_lang_String_substringLjava_lang_StringII;
199.3277 - this.subSequenceLjava_lang_CharSequenceII = java_lang_String_subSequenceLjava_lang_CharSequenceII;
199.3278 - this.concatLjava_lang_StringLjava_lang_String = java_lang_String_concatLjava_lang_StringLjava_lang_String;
199.3279 - this.replaceLjava_lang_StringCC = java_lang_String_replaceLjava_lang_StringCC;
199.3280 - this.matchesZLjava_lang_String = java_lang_String_matchesZLjava_lang_String;
199.3281 - this.containsZLjava_lang_CharSequence = java_lang_String_containsZLjava_lang_CharSequence;
199.3282 - this.replaceFirstLjava_lang_StringLjava_lang_StringLjava_lang_String = java_lang_String_replaceFirstLjava_lang_StringLjava_lang_StringLjava_lang_String;
199.3283 - this.replaceAllLjava_lang_StringLjava_lang_StringLjava_lang_String = java_lang_String_replaceAllLjava_lang_StringLjava_lang_StringLjava_lang_String;
199.3284 - this.replaceLjava_lang_StringLjava_lang_CharSequenceLjava_lang_CharSequence = java_lang_String_replaceLjava_lang_StringLjava_lang_CharSequenceLjava_lang_CharSequence;
199.3285 - this.splitALjava_lang_StringLjava_lang_StringI = java_lang_String_splitALjava_lang_StringLjava_lang_StringI;
199.3286 - this.splitALjava_lang_StringLjava_lang_String = java_lang_String_splitALjava_lang_StringLjava_lang_String;
199.3287 - this.toLowerCaseLjava_lang_StringLjava_util_Locale = java_lang_String_toLowerCaseLjava_lang_StringLjava_util_Locale;
199.3288 - this.toLowerCaseLjava_lang_String = java_lang_String_toLowerCaseLjava_lang_String;
199.3289 - this.toUpperCaseLjava_lang_StringLjava_util_Locale = java_lang_String_toUpperCaseLjava_lang_StringLjava_util_Locale;
199.3290 - this.toUpperCaseLjava_lang_String = java_lang_String_toUpperCaseLjava_lang_String;
199.3291 - this.trimLjava_lang_String = java_lang_String_trimLjava_lang_String;
199.3292 - this.toStringLjava_lang_String = java_lang_String_toStringLjava_lang_String;
199.3293 - this.toCharArrayAC = java_lang_String_toCharArrayAC;
199.3294 - this.internLjava_lang_String = java_lang_String_internLjava_lang_String;
199.3295 - this.compareToILjava_lang_Object = java_lang_String_compareToILjava_lang_Object;
199.3296 - */
199.3297 -
199.3298 -
199.3299 -
200.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/Array.java Thu Oct 11 06:15:22 2012 -0700
200.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Array.java Wed Jan 23 20:16:48 2013 +0100
200.3 @@ -1,20 +1,20 @@
200.4 -/*
200.5 -Java 4 Browser Bytecode Translator
200.6 -Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
200.7 -
200.8 -This program is free software: you can redistribute it and/or modify
200.9 -it under the terms of the GNU General Public License as published by
200.10 -the Free Software Foundation, version 2 of the License.
200.11 -
200.12 -This program is distributed in the hope that it will be useful,
200.13 -but WITHOUT ANY WARRANTY; without even the implied warranty of
200.14 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
200.15 -GNU General Public License for more details.
200.16 -
200.17 -You should have received a copy of the GNU General Public License
200.18 -along with this program. Look for COPYING file in the top folder.
200.19 -If not, see http://opensource.org/licenses/GPL-2.0.
200.20 -*/
200.21 +/**
200.22 + * Back 2 Browser Bytecode Translator
200.23 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
200.24 + *
200.25 + * This program is free software: you can redistribute it and/or modify
200.26 + * it under the terms of the GNU General Public License as published by
200.27 + * the Free Software Foundation, version 2 of the License.
200.28 + *
200.29 + * This program is distributed in the hope that it will be useful,
200.30 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
200.31 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
200.32 + * GNU General Public License for more details.
200.33 + *
200.34 + * You should have received a copy of the GNU General Public License
200.35 + * along with this program. Look for COPYING file in the top folder.
200.36 + * If not, see http://opensource.org/licenses/GPL-2.0.
200.37 + */
200.38 package org.apidesign.vm4brwsr;
200.39
200.40 /**
200.41 @@ -51,10 +51,24 @@
200.42 return doubles[4][0];
200.43 }
200.44
200.45 + static double[][] dbls = new double[1][2];
200.46 + public static double twoDoubles() {
200.47 + return dbls[0][0] + dbls[0][0];
200.48 + }
200.49 +
200.50 + static int[][] tints = new int[1][2];
200.51 + public static int twoInts() {
200.52 + return tints[0][0] + tints[0][0];
200.53 + }
200.54 +
200.55 private static final Array[] ARR = { new Array(), new Array(), new Array() };
200.56
200.57 - private static Array[] arr() {
200.58 - return ARR;
200.59 + private static Array[][] arr() {
200.60 + Array[][] matrix = new Array[3][3];
200.61 + for (int i = 0; i < ARR.length; i++) {
200.62 + matrix[i][i] = ARR[i];
200.63 + }
200.64 + return matrix;
200.65 }
200.66 private static <T> T[] filter(T[] in) {
200.67 return in;
200.68 @@ -62,22 +76,52 @@
200.69
200.70 public static double sum() {
200.71 double sum = 0.0;
200.72 - for (int i = 0; i < arr().length; i++) {
200.73 - sum += arr()[i].bytes();
200.74 - sum += arr()[i].shorts();
200.75 - sum += arr()[i].ints()[2];
200.76 - sum += arr()[i].floats();
200.77 - sum += filter(arr())[i].doubles();
200.78 + for (Array[] row : arr()) {
200.79 + int indx = -1;
200.80 + for (Array a : row) {
200.81 + indx++;
200.82 + if (a == null) {
200.83 + continue;
200.84 + }
200.85 + sum += a.bytes();
200.86 + sum += a.shorts();
200.87 + sum += a.ints()[2];
200.88 + sum += a.floats();
200.89 + sum += filter(row)[indx].doubles();
200.90 + }
200.91 }
200.92 return sum;
200.93 }
200.94 - public static int simple() {
200.95 - int[] arr = { 0, 1, 2, 3, 4, 5 };
200.96 + private static final int[] arr = { 0, 1, 2, 3, 4, 5 };
200.97 + public static int simple(boolean clone) {
200.98 + int[] ar;
200.99 + if (clone) {
200.100 + ar = arr.clone();
200.101 + } else {
200.102 + ar = arr;
200.103 + }
200.104
200.105 int sum = 0;
200.106 - for (int i = 0; i < arr.length; i++) {
200.107 - sum += arr[i];
200.108 + for (int a : ar) {
200.109 + sum += a;
200.110 }
200.111 return sum;
200.112 }
200.113 +
200.114 + public static int sum(int size) {
200.115 + int[] arr = new int[size];
200.116 + return arr[0] + arr[1];
200.117 + }
200.118 +
200.119 + static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) {
200.120 + while (count-- > 0) {
200.121 + dst[dstBegin++] = value[srcBegin++];
200.122 + }
200.123 + }
200.124 +
200.125 + public static char copyArray() {
200.126 + char[] arr = { '0' };
200.127 + arraycopy(arr()[0][0].chars, 0, arr, 0, 1);
200.128 + return arr[0];
200.129 + }
200.130 }
201.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/ArrayTest.java Thu Oct 11 06:15:22 2012 -0700
201.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/ArrayTest.java Wed Jan 23 20:16:48 2013 +0100
201.3 @@ -1,63 +1,86 @@
201.4 -/*
201.5 -Java 4 Browser Bytecode Translator
201.6 -Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
201.7 -
201.8 -This program is free software: you can redistribute it and/or modify
201.9 -it under the terms of the GNU General Public License as published by
201.10 -the Free Software Foundation, version 2 of the License.
201.11 -
201.12 -This program is distributed in the hope that it will be useful,
201.13 -but WITHOUT ANY WARRANTY; without even the implied warranty of
201.14 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
201.15 -GNU General Public License for more details.
201.16 -
201.17 -You should have received a copy of the GNU General Public License
201.18 -along with this program. Look for COPYING file in the top folder.
201.19 -If not, see http://opensource.org/licenses/GPL-2.0.
201.20 -*/
201.21 +/**
201.22 + * Back 2 Browser Bytecode Translator
201.23 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
201.24 + *
201.25 + * This program is free software: you can redistribute it and/or modify
201.26 + * it under the terms of the GNU General Public License as published by
201.27 + * the Free Software Foundation, version 2 of the License.
201.28 + *
201.29 + * This program is distributed in the hope that it will be useful,
201.30 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
201.31 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
201.32 + * GNU General Public License for more details.
201.33 + *
201.34 + * You should have received a copy of the GNU General Public License
201.35 + * along with this program. Look for COPYING file in the top folder.
201.36 + * If not, see http://opensource.org/licenses/GPL-2.0.
201.37 + */
201.38 package org.apidesign.vm4brwsr;
201.39
201.40 import javax.script.Invocable;
201.41 -import javax.script.ScriptException;
201.42 +import static org.testng.Assert.*;
201.43 +import org.testng.annotations.BeforeClass;
201.44 import org.testng.annotations.Test;
201.45 -import static org.testng.Assert.*;
201.46
201.47 /**
201.48 *
201.49 * @author Jaroslav Tulach <jtulach@netbeans.org>
201.50 */
201.51 public class ArrayTest {
201.52 - @Test public void verifySimpleIntOperation() throws Exception {
201.53 - assertExec("CheckTheSum", "org_apidesign_vm4brwsr_Array_simpleI",
201.54 - Double.valueOf(15)
201.55 + @Test public void intArrayShouldBeFilledWithZeroes() throws Exception {
201.56 + assertExec("0 + 0", Array.class, "sum__II",
201.57 + Double.valueOf(0), 2
201.58 );
201.59 }
201.60 + @Test public void verifySimpleIntOperation() throws Exception {
201.61 + assertExec("CheckTheSum", Array.class, "simple__IZ",
201.62 + Double.valueOf(15), false
201.63 + );
201.64 + }
201.65 +
201.66 + @Test public void cloneOnArray() throws Exception {
201.67 + assertExec("CheckTheSum on clone", Array.class, "simple__IZ",
201.68 + Double.valueOf(15), true
201.69 + );
201.70 + }
201.71 +
201.72 + @Test public void realOperationOnArrays() throws Exception {
201.73 + assertEquals(Array.sum(), 105.0, "Computes to 105");
201.74 + }
201.75 +
201.76 @Test public void verifyOperationsOnArrays() throws Exception {
201.77 - assertExec("The sum is 105", "org_apidesign_vm4brwsr_Array_sumD",
201.78 + assertExec("The sum is 105", Array.class, "sum__D",
201.79 Double.valueOf(105)
201.80 );
201.81 }
201.82 +
201.83 + @Test public void twoDoubles() throws Exception {
201.84 + assertExec("Elements are initialized", Array.class, "twoDoubles__D",
201.85 + Double.valueOf(0)
201.86 + );
201.87 + }
201.88 + @Test public void twoInts() throws Exception {
201.89 + assertExec("Elements are initialized", Array.class, "twoInts__I",
201.90 + Double.valueOf(0)
201.91 + );
201.92 + }
201.93
201.94 - private static void assertExec(String msg, String methodName, Object expRes, Object... args) throws Exception {
201.95 + @Test public void doesCopyArrayWork() throws Exception {
201.96 + assertExec("Returns 'a'", Array.class, "copyArray__C", Double.valueOf('a'));
201.97 + }
201.98 +
201.99 + private static CharSequence codeSeq;
201.100 + private static Invocable code;
201.101 +
201.102 + @BeforeClass
201.103 + public void compileTheCode() throws Exception {
201.104 StringBuilder sb = new StringBuilder();
201.105 - Invocable i = StaticMethodTest.compileClass(sb,
201.106 + code = StaticMethodTest.compileClass(sb,
201.107 "org/apidesign/vm4brwsr/Array"
201.108 );
201.109 -
201.110 - Object ret = null;
201.111 - try {
201.112 - ret = i.invokeFunction(methodName, args);
201.113 - } catch (ScriptException ex) {
201.114 - fail("Execution failed in " + sb, ex);
201.115 - } catch (NoSuchMethodException ex) {
201.116 - fail("Cannot find method in " + sb, ex);
201.117 - }
201.118 - if (ret == null && expRes == null) {
201.119 - return;
201.120 - }
201.121 - if (expRes.equals(ret)) {
201.122 - return;
201.123 - }
201.124 - assertEquals(ret, expRes, msg + "was: " + ret + "\n" + sb);
201.125 + codeSeq = sb;
201.126 + }
201.127 + private static void assertExec(String msg, Class clazz, String method, Object expRes, Object... args) throws Exception {
201.128 + StaticMethodTest.assertExec(code, codeSeq, msg, clazz, method, expRes, args);
201.129 }
201.130 }
202.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
202.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/ByteCodeToJavaScriptTest.java Wed Jan 23 20:16:48 2013 +0100
202.3 @@ -0,0 +1,55 @@
202.4 +/**
202.5 + * Back 2 Browser Bytecode Translator
202.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
202.7 + *
202.8 + * This program is free software: you can redistribute it and/or modify
202.9 + * it under the terms of the GNU General Public License as published by
202.10 + * the Free Software Foundation, version 2 of the License.
202.11 + *
202.12 + * This program is distributed in the hope that it will be useful,
202.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
202.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
202.15 + * GNU General Public License for more details.
202.16 + *
202.17 + * You should have received a copy of the GNU General Public License
202.18 + * along with this program. Look for COPYING file in the top folder.
202.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
202.20 + */
202.21 +package org.apidesign.vm4brwsr;
202.22 +
202.23 +import static org.testng.Assert.*;
202.24 +import org.testng.annotations.Test;
202.25 +
202.26 +/**
202.27 + *
202.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
202.29 + */
202.30 +public class ByteCodeToJavaScriptTest {
202.31 +
202.32 + public ByteCodeToJavaScriptTest() {
202.33 + }
202.34 +
202.35 + @Test
202.36 + public void findMethodNameManglesObjectsCorrectly() {
202.37 + StringBuilder cnt = new StringBuilder();
202.38 + char[] returnType = { 'V' };
202.39 + String ret = ByteCodeToJavaScript.findMethodName(new String[] {
202.40 + "StringTest", "replace", "(Ljava/lang/String;CC)Ljava/lang/String;"
202.41 + }, cnt, returnType);
202.42 + assertEquals(cnt.toString(), "000", "No doubles or longs");
202.43 + assertTrue(returnType[0] != 'V', "Returns string");
202.44 + assertEquals(ret, "replace__Ljava_lang_String_2Ljava_lang_String_2CC");
202.45 + }
202.46 +
202.47 + @Test
202.48 + public void manglingArrays() {
202.49 + StringBuilder cnt = new StringBuilder();
202.50 + char[] returnType = { 'V' };
202.51 + String ret = ByteCodeToJavaScript.findMethodName(new String[] {
202.52 + "VMinVM", "toJavaScript", "([B)Ljava/lang/String;"
202.53 + }, cnt, returnType);
202.54 + assertEquals(cnt.toString(), "0", "No doubles or longs");
202.55 + assertTrue(returnType[0] != 'V', "Returns string");
202.56 + assertEquals(ret, "toJavaScript__Ljava_lang_String_2_3B");
202.57 + }
202.58 +}
203.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
203.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/BytesLoader.java Wed Jan 23 20:16:48 2013 +0100
203.3 @@ -0,0 +1,76 @@
203.4 +/**
203.5 + * Back 2 Browser Bytecode Translator
203.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
203.7 + *
203.8 + * This program is free software: you can redistribute it and/or modify
203.9 + * it under the terms of the GNU General Public License as published by
203.10 + * the Free Software Foundation, version 2 of the License.
203.11 + *
203.12 + * This program is distributed in the hope that it will be useful,
203.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
203.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
203.15 + * GNU General Public License for more details.
203.16 + *
203.17 + * You should have received a copy of the GNU General Public License
203.18 + * along with this program. Look for COPYING file in the top folder.
203.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
203.20 + */
203.21 +package org.apidesign.vm4brwsr;
203.22 +
203.23 +import java.io.IOException;
203.24 +import java.io.InputStream;
203.25 +import java.net.URL;
203.26 +import java.util.Enumeration;
203.27 +import java.util.Set;
203.28 +import java.util.TreeSet;
203.29 +
203.30 +/**
203.31 + *
203.32 + * @author Jaroslav Tulach <jtulach@netbeans.org>
203.33 + */
203.34 +public final class BytesLoader {
203.35 + private static Set<String> requested = new TreeSet<String>();
203.36 +
203.37 + public byte[] get(String name) throws IOException {
203.38 + if (!requested.add(name)) {
203.39 + throw new IllegalStateException("Requested for second time: " + name);
203.40 + }
203.41 + byte[] arr = readClass(name);
203.42 + /*
203.43 + System.err.print("loader['" + name + "'] = [");
203.44 + for (int i = 0; i < arr.length; i++) {
203.45 + if (i > 0) {
203.46 + System.err.print(", ");
203.47 + }
203.48 + System.err.print(arr[i]);
203.49 + }
203.50 + System.err.println("]");
203.51 + */
203.52 + return arr;
203.53 + }
203.54 +
203.55 + static byte[] readClass(String name) throws IOException {
203.56 + URL u = null;
203.57 + Enumeration<URL> en = BytesLoader.class.getClassLoader().getResources(name);
203.58 + while (en.hasMoreElements()) {
203.59 + u = en.nextElement();
203.60 + }
203.61 + if (u == null) {
203.62 + throw new IOException("Can't find " + name);
203.63 + }
203.64 + try (InputStream is = u.openStream()) {
203.65 + byte[] arr;
203.66 + arr = new byte[is.available()];
203.67 + int offset = 0;
203.68 + while (offset < arr.length) {
203.69 + int len = is.read(arr, offset, arr.length - offset);
203.70 + if (len == -1) {
203.71 + throw new IOException("Can't read " + name);
203.72 + }
203.73 + offset += len;
203.74 + }
203.75 + return arr;
203.76 + }
203.77 + }
203.78 +
203.79 +}
204.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
204.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java Wed Jan 23 20:16:48 2013 +0100
204.3 @@ -0,0 +1,185 @@
204.4 +/**
204.5 + * Back 2 Browser Bytecode Translator
204.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
204.7 + *
204.8 + * This program is free software: you can redistribute it and/or modify
204.9 + * it under the terms of the GNU General Public License as published by
204.10 + * the Free Software Foundation, version 2 of the License.
204.11 + *
204.12 + * This program is distributed in the hope that it will be useful,
204.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
204.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
204.15 + * GNU General Public License for more details.
204.16 + *
204.17 + * You should have received a copy of the GNU General Public License
204.18 + * along with this program. Look for COPYING file in the top folder.
204.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
204.20 + */
204.21 +package org.apidesign.vm4brwsr;
204.22 +
204.23 +import javax.script.Invocable;
204.24 +import org.testng.annotations.Test;
204.25 +import static org.testng.Assert.*;
204.26 +import org.testng.annotations.BeforeClass;
204.27 +
204.28 +/**
204.29 + *
204.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
204.31 + */
204.32 +public class ClassTest {
204.33 +
204.34 + @Test public void superClassEqualsGetSuperclass() {
204.35 + assertTrue(Classes.equalsClassesOfExceptions(), "Classes are equal");
204.36 + }
204.37 +
204.38 + @Test public void jsSuperClassEqualsGetSuperclass() throws Exception {
204.39 + assertExec("Classes are equal", Classes.class, "equalsClassesOfExceptions__Z", Double.valueOf(1.0));
204.40 + }
204.41 +
204.42 + @Test public void classesAreDifferent() {
204.43 + assertTrue(Classes.differenceInClasses(), "Classes are not equal");
204.44 + }
204.45 +
204.46 + @Test public void jsClassesAreDifferent() throws Exception {
204.47 + assertExec("Classes are not equal", Classes.class, "differenceInClasses__Z", Double.valueOf(1.0));
204.48 + }
204.49 +
204.50 + @Test public void javaInstanceName() throws Exception {
204.51 + assertEquals(Classes.classForInstance(), "java.io.IOException");
204.52 + }
204.53 + @Test public void jsInstanceName() throws Exception {
204.54 + assertExec("I/O name", Classes.class, "classForInstance__Ljava_lang_String_2", "java.io.IOException");
204.55 + }
204.56 + @Test public void javaName() throws Exception {
204.57 + assertEquals(Classes.name(), "java.io.IOException");
204.58 + }
204.59 + @Test public void jsName() throws Exception {
204.60 + assertExec("I/O name", Classes.class, "name__Ljava_lang_String_2", "java.io.IOException");
204.61 + }
204.62 + @Test public void javaSimpleName() throws Exception {
204.63 + assertEquals(Classes.simpleName(), "IOException");
204.64 + }
204.65 + @Test public void jsGetsSimpleName() throws Exception {
204.66 + assertExec("I/O simple name", Classes.class, "simpleName__Ljava_lang_String_2", "IOException");
204.67 + }
204.68 + @Test public void javaCanonicalName() {
204.69 + assertEquals(Classes.canonicalName(), "java.io.IOException");
204.70 + }
204.71 + @Test public void jsCanonicalName() throws Exception {
204.72 + assertExec("I/O simple name", Classes.class, "canonicalName__Ljava_lang_String_2", "java.io.IOException");
204.73 + }
204.74 + @Test public void javaNewInstance() throws Exception {
204.75 + assertTrue(Classes.newInstance());
204.76 + }
204.77 + @Test public void jsNewInstance() throws Exception {
204.78 + assertExec("Check new instance", Classes.class, "newInstance__Z", Double.valueOf(1));
204.79 + }
204.80 + @Test public void javaNoNewInstance() throws Exception {
204.81 + assertEquals("java.lang.InstantiationException:java.lang.Float",
204.82 + Classes.newInstanceNoPubConstructor()
204.83 + );
204.84 + }
204.85 + @Test public void jsNoNewInstance() throws Exception {
204.86 + assertExec("Check problems with new instance", Classes.class, "newInstanceNoPubConstructor__Ljava_lang_String_2",
204.87 + "java.lang.InstantiationException:java.lang.Float"
204.88 + );
204.89 + }
204.90 + @Test public void jsAnnotation() throws Exception {
204.91 + assertExec("Check class annotation", Classes.class, "getMarker__I", Double.valueOf(10));
204.92 + }
204.93 + @Test public void jsStringAnnotation() throws Exception {
204.94 + assertExec("Check class annotation", Classes.class, "getNamer__Ljava_lang_String_2Z", "my text", true);
204.95 + }
204.96 + @Test public void jsStringAnnotationFromArray() throws Exception {
204.97 + assertExec("Check class annotation", Classes.class, "getNamer__Ljava_lang_String_2Z", "my text", false);
204.98 + }
204.99 + @Test public void javaInvokeMethod() throws Exception {
204.100 + assertEquals(Classes.reflectiveMethodCall(true, "name"), "java.io.IOException", "Calls the name() method via reflection");
204.101 + }
204.102 + @Test public void jsInvokeMethod() throws Exception {
204.103 + assertExec("Calls the name() method via reflection", Classes.class,
204.104 + "reflectiveMethodCall__Ljava_lang_Object_2ZLjava_lang_String_2",
204.105 + "java.io.IOException", true, "name"
204.106 + );
204.107 + }
204.108 + @Test public void jsInvokeParamMethod() throws Exception {
204.109 + assertExec("sums two numbers via reflection", Classes.class,
204.110 + "reflectiveSum__III", Double.valueOf(5), 2, 3
204.111 + );
204.112 + }
204.113 + @Test public void javaFindMethod() throws Exception {
204.114 + assertEquals(Classes.reflectiveMethodCall(false, "name"), "java.io.IOException", "Calls the name() method via reflection");
204.115 + }
204.116 + @Test public void jsFindMethod() throws Exception {
204.117 + assertExec("Calls the name() method via reflection", Classes.class,
204.118 + "reflectiveMethodCall__Ljava_lang_Object_2ZLjava_lang_String_2",
204.119 + "java.io.IOException", false, "name"
204.120 + );
204.121 + }
204.122 + @Test public void primitiveReturnType() throws Exception {
204.123 + assertExec("Tries to get an integer via reflection", Classes.class,
204.124 + "primitiveType__Ljava_lang_String_2Ljava_lang_String_2",
204.125 + Classes.primitiveType("primitive"), "primitive"
204.126 + );
204.127 + }
204.128 + @Test public void primitiveBoolReturnType() throws Exception {
204.129 + assertExec("Tries to get an integer via reflection", Classes.class,
204.130 + "primitiveType__Ljava_lang_String_2Ljava_lang_String_2",
204.131 + Classes.primitiveType("primitiveB"), "primitiveB"
204.132 + );
204.133 + }
204.134 + @Test public void javaAnnotatedMethod() throws Exception {
204.135 + assertEquals(Classes.reflectiveMethodCall(false, null), "java.io.IOException", "Calls the name() method via reflection");
204.136 + }
204.137 + @Test public void jsAnnotatedMethod() throws Exception {
204.138 + assertExec("Calls the name() method via reflection", Classes.class,
204.139 + "reflectiveMethodCall__Ljava_lang_Object_2ZLjava_lang_String_2",
204.140 + "java.io.IOException", false, null
204.141 + );
204.142 + }
204.143 + @Test public void jsClassParam() throws Exception {
204.144 + assertExec("Calls the nameOfIO()", Classes.class,
204.145 + "nameOfIO__Ljava_lang_String_2",
204.146 + "java.io.IOException"
204.147 + );
204.148 + }
204.149 + @Test public void noInterface() throws Exception {
204.150 + assertExec("Calls Class.isInterface", Classes.class,
204.151 + "isInterface__ZLjava_lang_String_2",
204.152 + 0.0, "java.lang.String"
204.153 + );
204.154 + }
204.155 + /*
204.156 + @Test public void isInterface() throws Exception {
204.157 + assertExec("Calls Class.isInterface", Classes.class,
204.158 + "isInterface__ZLjava_lang_String_2",
204.159 + 1.0, "java.lang.Runnable"
204.160 + );
204.161 + }
204.162 + */
204.163 + @Test public void integerType() throws Exception {
204.164 + assertExec("Computes the type", Classes.class,
204.165 + "intType__Ljava_lang_String_2",
204.166 + Classes.intType()
204.167 + );
204.168 + }
204.169 +
204.170 + private static CharSequence codeSeq;
204.171 + private static Invocable code;
204.172 +
204.173 + @BeforeClass
204.174 + public void compileTheCode() throws Exception {
204.175 + if (codeSeq == null) {
204.176 + StringBuilder sb = new StringBuilder();
204.177 + code = StaticMethodTest.compileClass(sb, "org/apidesign/vm4brwsr/Classes");
204.178 + codeSeq = sb;
204.179 + }
204.180 + }
204.181 +
204.182 + private void assertExec(
204.183 + String msg, Class clazz, String method, Object expRes, Object... args
204.184 + ) throws Exception {
204.185 + StaticMethodTest.assertExec(code, codeSeq, msg, clazz, method, expRes, args);
204.186 + }
204.187 +
204.188 +}
205.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
205.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Classes.java Wed Jan 23 20:16:48 2013 +0100
205.3 @@ -0,0 +1,154 @@
205.4 +/**
205.5 + * Back 2 Browser Bytecode Translator
205.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
205.7 + *
205.8 + * This program is free software: you can redistribute it and/or modify
205.9 + * it under the terms of the GNU General Public License as published by
205.10 + * the Free Software Foundation, version 2 of the License.
205.11 + *
205.12 + * This program is distributed in the hope that it will be useful,
205.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
205.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
205.15 + * GNU General Public License for more details.
205.16 + *
205.17 + * You should have received a copy of the GNU General Public License
205.18 + * along with this program. Look for COPYING file in the top folder.
205.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
205.20 + */
205.21 +package org.apidesign.vm4brwsr;
205.22 +
205.23 +import java.io.IOException;
205.24 +import java.lang.annotation.Annotation;
205.25 +import java.lang.reflect.Method;
205.26 +import java.net.MalformedURLException;
205.27 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
205.28 +
205.29 +/**
205.30 + *
205.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
205.32 + */
205.33 +@ClassesMarker(number = 10)
205.34 +@ClassesNamer(name = "my text")
205.35 +public class Classes {
205.36 + public static String nameOfIO() {
205.37 + return nameFor(IOException.class);
205.38 + }
205.39 +
205.40 + private static String nameFor(Class<?> c) {
205.41 + return c.getName();
205.42 + }
205.43 +
205.44 + public static boolean isInterface(String s) throws ClassNotFoundException {
205.45 + return Class.forName(s).isInterface();
205.46 + }
205.47 +
205.48 + public static boolean equalsClassesOfExceptions() {
205.49 + return MalformedURLException.class.getSuperclass() == IOException.class;
205.50 + }
205.51 + public static boolean differenceInClasses() {
205.52 + Class<?> c1 = MalformedURLException.class;
205.53 + Class<?> c2 = IOException.class;
205.54 + return c1 != c2;
205.55 + }
205.56 +
205.57 + public static String classForInstance() {
205.58 + return new IOException().getClass().getName().toString();
205.59 + }
205.60 +
205.61 + @ClassesMarker(number = 1)
205.62 + public static String name() {
205.63 + return IOException.class.getName().toString();
205.64 + }
205.65 + public static String simpleName() {
205.66 + return IOException.class.getSimpleName();
205.67 + }
205.68 + public static String canonicalName() {
205.69 + return IOException.class.getCanonicalName();
205.70 + }
205.71 + public static boolean newInstance() throws Exception {
205.72 + IOException ioe = IOException.class.newInstance();
205.73 + if (ioe instanceof IOException) {
205.74 + return ioe.getClass() == IOException.class;
205.75 + }
205.76 + throw new IllegalStateException("Not a subtype: " + ioe);
205.77 + }
205.78 + public static String newInstanceNoPubConstructor() throws Exception {
205.79 + try {
205.80 + Float f = Float.class.newInstance();
205.81 + return "wrong, can't instantiate: " + f;
205.82 + } catch (Exception ex) {
205.83 + return (ex.getClass().getName() + ":" + ex.getMessage()).toString().toString();
205.84 + }
205.85 + }
205.86 + public static int getMarker() {
205.87 + if (!Classes.class.isAnnotationPresent(ClassesMarker.class)) {
205.88 + return -2;
205.89 + }
205.90 + ClassesMarker cm = Classes.class.getAnnotation(ClassesMarker.class);
205.91 + return cm == null ? -1 : cm.number();
205.92 + }
205.93 + public static String getNamer(boolean direct) {
205.94 + if (direct) {
205.95 + ClassesNamer cm = Classes.class.getAnnotation(ClassesNamer.class);
205.96 + return cm == null ? null : cm.name();
205.97 + }
205.98 + for (Annotation a : Classes.class.getAnnotations()) {
205.99 + if (a instanceof ClassesNamer) {
205.100 + return ((ClassesNamer)a).name();
205.101 + }
205.102 + }
205.103 + return null;
205.104 + }
205.105 +
205.106 + public static String intType() {
205.107 + return Integer.TYPE.getName();
205.108 + }
205.109 +
205.110 + public static int primitive() {
205.111 + return 1;
205.112 + }
205.113 + public static boolean primitiveB() {
205.114 + return true;
205.115 + }
205.116 +
205.117 + public static String primitiveType(String method) throws Exception {
205.118 + return reflectiveMethodCall(false, method).getClass().getName();
205.119 + }
205.120 +
205.121 + @JavaScriptBody(args = "msg", body = "throw msg;")
205.122 + private static native void thrw(String msg);
205.123 +
205.124 + public static Object reflectiveMethodCall(boolean direct, String mn) throws Exception {
205.125 + Method find = null;
205.126 + StringBuilder sb = new StringBuilder();
205.127 + if (!direct) {
205.128 + final Class<? extends Annotation> v = ClassesMarker.class;
205.129 + for (Method m : Classes.class.getMethods()) {
205.130 + sb.append("\n").append(m.getName());
205.131 + if (mn != null) {
205.132 + if (m.getName().equals(mn)) {
205.133 + find = m;
205.134 + break;
205.135 + }
205.136 + } else {
205.137 + if (m.getAnnotation(v) != null) {
205.138 + find = m;
205.139 + break;
205.140 + }
205.141 + }
205.142 + }
205.143 + } else {
205.144 + find = Classes.class.getMethod(mn);
205.145 + }
205.146 + if (find == null) {
205.147 + thrw(sb.toString());
205.148 + throw new NullPointerException(sb.toString());
205.149 + }
205.150 + return find.invoke(null);
205.151 + }
205.152 +
205.153 + public static int reflectiveSum(int a, int b) throws Exception {
205.154 + Method m = StaticMethod.class.getMethod("sum", int.class, int.class);
205.155 + return (int) m.invoke(null, a, b);
205.156 + }
205.157 +}
206.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
206.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/ClassesMarker.java Wed Jan 23 20:16:48 2013 +0100
206.3 @@ -0,0 +1,30 @@
206.4 +/**
206.5 + * Back 2 Browser Bytecode Translator
206.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
206.7 + *
206.8 + * This program is free software: you can redistribute it and/or modify
206.9 + * it under the terms of the GNU General Public License as published by
206.10 + * the Free Software Foundation, version 2 of the License.
206.11 + *
206.12 + * This program is distributed in the hope that it will be useful,
206.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
206.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
206.15 + * GNU General Public License for more details.
206.16 + *
206.17 + * You should have received a copy of the GNU General Public License
206.18 + * along with this program. Look for COPYING file in the top folder.
206.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
206.20 + */
206.21 +package org.apidesign.vm4brwsr;
206.22 +
206.23 +import java.lang.annotation.Retention;
206.24 +import java.lang.annotation.RetentionPolicy;
206.25 +
206.26 +/**
206.27 + *
206.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
206.29 + */
206.30 +@Retention(RetentionPolicy.RUNTIME)
206.31 +public @interface ClassesMarker {
206.32 + int number();
206.33 +}
207.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
207.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/ClassesNamer.java Wed Jan 23 20:16:48 2013 +0100
207.3 @@ -0,0 +1,30 @@
207.4 +/**
207.5 + * Back 2 Browser Bytecode Translator
207.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
207.7 + *
207.8 + * This program is free software: you can redistribute it and/or modify
207.9 + * it under the terms of the GNU General Public License as published by
207.10 + * the Free Software Foundation, version 2 of the License.
207.11 + *
207.12 + * This program is distributed in the hope that it will be useful,
207.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
207.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
207.15 + * GNU General Public License for more details.
207.16 + *
207.17 + * You should have received a copy of the GNU General Public License
207.18 + * along with this program. Look for COPYING file in the top folder.
207.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
207.20 + */
207.21 +package org.apidesign.vm4brwsr;
207.22 +
207.23 +import java.lang.annotation.Retention;
207.24 +import java.lang.annotation.RetentionPolicy;
207.25 +
207.26 +/**
207.27 + *
207.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
207.29 + */
207.30 +@Retention(RetentionPolicy.RUNTIME)
207.31 +public @interface ClassesNamer {
207.32 + String name();
207.33 +}
208.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
208.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Exceptions.java Wed Jan 23 20:16:48 2013 +0100
208.3 @@ -0,0 +1,88 @@
208.4 +/**
208.5 + * Back 2 Browser Bytecode Translator
208.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
208.7 + *
208.8 + * This program is free software: you can redistribute it and/or modify
208.9 + * it under the terms of the GNU General Public License as published by
208.10 + * the Free Software Foundation, version 2 of the License.
208.11 + *
208.12 + * This program is distributed in the hope that it will be useful,
208.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
208.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
208.15 + * GNU General Public License for more details.
208.16 + *
208.17 + * You should have received a copy of the GNU General Public License
208.18 + * along with this program. Look for COPYING file in the top folder.
208.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
208.20 + */
208.21 +package org.apidesign.vm4brwsr;
208.22 +
208.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
208.24 +
208.25 +/**
208.26 + *
208.27 + * @author tom
208.28 + */
208.29 +public class Exceptions {
208.30 + private Exceptions() {
208.31 + }
208.32 +
208.33 + public static int methodWithTryCatchNoThrow() {
208.34 + int res = 0;
208.35 + try {
208.36 + res = 1;
208.37 + } catch (IllegalArgumentException e) {
208.38 + res = 2;
208.39 + }
208.40 + //join point
208.41 + return res;
208.42 + }
208.43 +
208.44 + public static int methodWithTryCatchThrow() {
208.45 + int res = 0;
208.46 + try {
208.47 + res = 1;
208.48 + throw new IllegalArgumentException();
208.49 + } catch (IllegalArgumentException e) {
208.50 + res = 2;
208.51 + }
208.52 + //join point
208.53 + return res;
208.54 + }
208.55 +
208.56 + @JavaScriptBody(args = "msg", body = "throw msg;")
208.57 + public static void thrw(String msg) {}
208.58 +
208.59 + public static String catchThrowableCatchesAll() {
208.60 + try {
208.61 + thrw("Hello!");
208.62 + return "Not here!";
208.63 + } catch (Throwable ex) {
208.64 + return ex.getMessage();
208.65 + }
208.66 + }
208.67 +
208.68 + public static String newInstance(String n) {
208.69 + try {
208.70 + Class c;
208.71 + try {
208.72 + c = Class.forName(n);
208.73 + } catch (ClassNotFoundException ex) {
208.74 + return ("CNFE:" + ex.getMessage()).toString();
208.75 + }
208.76 + return c.newInstance().getClass().getName();
208.77 + } catch (InstantiationException | IllegalAccessException ex) {
208.78 + return ex.getMessage();
208.79 + }
208.80 + }
208.81 +
208.82 + private static int counter;
208.83 + public static int readCounter(String n) throws ClassNotFoundException {
208.84 + try {
208.85 + Class.forName(n);
208.86 + } finally {
208.87 + counter++;
208.88 + }
208.89 + return counter;
208.90 + }
208.91 +}
209.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
209.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/ExceptionsTest.java Wed Jan 23 20:16:48 2013 +0100
209.3 @@ -0,0 +1,121 @@
209.4 +/**
209.5 + * Back 2 Browser Bytecode Translator
209.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
209.7 + *
209.8 + * This program is free software: you can redistribute it and/or modify
209.9 + * it under the terms of the GNU General Public License as published by
209.10 + * the Free Software Foundation, version 2 of the License.
209.11 + *
209.12 + * This program is distributed in the hope that it will be useful,
209.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
209.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
209.15 + * GNU General Public License for more details.
209.16 + *
209.17 + * You should have received a copy of the GNU General Public License
209.18 + * along with this program. Look for COPYING file in the top folder.
209.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
209.20 + */
209.21 +package org.apidesign.vm4brwsr;
209.22 +
209.23 +import javax.script.Invocable;
209.24 +import javax.script.ScriptException;
209.25 +import static org.testng.Assert.*;
209.26 +import org.testng.annotations.BeforeClass;
209.27 +import org.testng.annotations.Test;
209.28 +
209.29 +/**
209.30 + *
209.31 + * @author Tomas Zezula <tzezula@netbeans.org>
209.32 + */
209.33 +public class ExceptionsTest {
209.34 + @Test
209.35 + public void verifyMethodWithTryCatchNoThrow() throws Exception {
209.36 + assertExec(
209.37 + "No throw",
209.38 + Exceptions.class,
209.39 + "methodWithTryCatchNoThrow__I",
209.40 + new Double(1.0));
209.41 + }
209.42 +
209.43 + @Test
209.44 + public void catchJavaScriptStringAsThrowable() throws Exception {
209.45 + assertExec(
209.46 + "Throw hello!",
209.47 + Exceptions.class,
209.48 + "catchThrowableCatchesAll__Ljava_lang_String_2",
209.49 + "Hello!"
209.50 + );
209.51 + }
209.52 +
209.53 + @Test
209.54 + public void verifyMethodWithTryCatchThrow() throws Exception {
209.55 + assertExec(
209.56 + "Throw",
209.57 + Exceptions.class,
209.58 + "methodWithTryCatchThrow__I",
209.59 + new Double(2.0));
209.60 + }
209.61 +
209.62 + @Test public void createObject() throws Exception {
209.63 + assertExec("Object created", Exceptions.class,
209.64 + "newInstance__Ljava_lang_String_2Ljava_lang_String_2",
209.65 + "java.lang.Object",
209.66 + "java.lang.Object"
209.67 + );
209.68 + }
209.69 +
209.70 + @Test public void createFloatFails() throws Exception {
209.71 + assertExec("Float not created", Exceptions.class,
209.72 + "newInstance__Ljava_lang_String_2Ljava_lang_String_2",
209.73 + "java.lang.Float",
209.74 + "java.lang.Float"
209.75 + );
209.76 + }
209.77 +
209.78 + @Test public void createUnknownFails() throws Exception {
209.79 + assertExec("Object created", Exceptions.class,
209.80 + "newInstance__Ljava_lang_String_2Ljava_lang_String_2",
209.81 + "CNFE:org.apidesign.Unknown",
209.82 + "org.apidesign.Unknown"
209.83 + );
209.84 + }
209.85 +
209.86 + @Test public void testThreeCalls() throws Exception {
209.87 + Object vm = code.invokeFunction("bck2brwsr");
209.88 + Object clazz = code.invokeMethod(vm, "loadClass", Exceptions.class.getName());
209.89 +
209.90 + String method = "readCounter__ILjava_lang_String_2";
209.91 +
209.92 + try {
209.93 + Object ret = code.invokeMethod(clazz, method, "org.apidesign.Unknown");
209.94 + fail("We expect an CNFE!");
209.95 + } catch (ScriptException scriptException) {
209.96 + // script exception should be OK
209.97 + }
209.98 + {
209.99 + // 2nd invocation
209.100 + Object ret = code.invokeMethod(clazz, method, "java.lang.String");
209.101 + assertEquals(ret, Double.valueOf(2));
209.102 + }
209.103 + {
209.104 + // 3rd invocation
209.105 + Object ret = code.invokeMethod(clazz, method, "java.lang.Integer");
209.106 + assertEquals(ret, Double.valueOf(3));
209.107 + }
209.108 + }
209.109 +
209.110 + private static CharSequence codeSeq;
209.111 + private static Invocable code;
209.112 +
209.113 + @BeforeClass
209.114 + public void compileTheCode() throws Exception {
209.115 + StringBuilder sb = new StringBuilder();
209.116 + code = StaticMethodTest.compileClass(sb,
209.117 + "org/apidesign/vm4brwsr/Exceptions"
209.118 + );
209.119 + codeSeq = sb;
209.120 + }
209.121 + private static void assertExec(String msg, Class clazz, String method, Object expRes, Object... args) throws Exception {
209.122 + StaticMethodTest.assertExec(code, codeSeq, msg, clazz, method, expRes, args);
209.123 + }
209.124 +}
210.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/GetByte.java Thu Oct 11 06:15:22 2012 -0700
210.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/GetByte.java Wed Jan 23 20:16:48 2013 +0100
210.3 @@ -1,6 +1,6 @@
210.4 /**
210.5 - * Java 4 Browser Bytecode Translator
210.6 - * Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
210.7 + * Back 2 Browser Bytecode Translator
210.8 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
210.9 *
210.10 * This program is free software: you can redistribute it and/or modify
210.11 * it under the terms of the GNU General Public License as published by
211.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/Instance.java Thu Oct 11 06:15:22 2012 -0700
211.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Instance.java Wed Jan 23 20:16:48 2013 +0100
211.3 @@ -1,6 +1,6 @@
211.4 /**
211.5 - * Java 4 Browser Bytecode Translator
211.6 - * Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
211.7 + * Back 2 Browser Bytecode Translator
211.8 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
211.9 *
211.10 * This program is free software: you can redistribute it and/or modify
211.11 * it under the terms of the GNU General Public License as published by
211.12 @@ -17,12 +17,14 @@
211.13 */
211.14 package org.apidesign.vm4brwsr;
211.15
211.16 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
211.17 +
211.18 /**
211.19 *
211.20 * @author Jaroslav Tulach <jtulach@netbeans.org>
211.21 */
211.22 public class Instance {
211.23 - private int i;
211.24 + private int in;
211.25 protected short s;
211.26 public double d;
211.27 private float f;
211.28 @@ -32,7 +34,7 @@
211.29 }
211.30
211.31 public Instance(int i, double d) {
211.32 - this.i = i;
211.33 + this.in = i;
211.34 this.d = d;
211.35 }
211.36 public byte getByte() {
211.37 @@ -53,7 +55,7 @@
211.38 public static double magicOne() {
211.39 Instance i = new Instance(10, 3.3d);
211.40 i.b = (byte)0x09;
211.41 - return (i.i - i.b) * i.d;
211.42 + return (i.in - i.b) * i.d;
211.43 }
211.44 public static int virtualBytes() {
211.45 Instance i = new InstanceSub(7, 2.2d);
211.46 @@ -89,4 +91,45 @@
211.47 private static boolean isNull() {
211.48 return createInstance(true) == null;
211.49 }
211.50 +
211.51 + @JavaScriptBody(args = "obj", body = "return obj.constructor;")
211.52 + static Object constructor(Object obj) {
211.53 + return obj;
211.54 + }
211.55 +
211.56 + public static boolean sharedConstructor() {
211.57 + class X {
211.58 + }
211.59 +
211.60 + X x1 = new X();
211.61 + X x2 = new X();
211.62 +
211.63 + return constructor(x1) == constructor(x2);
211.64 + }
211.65 + public static boolean differentConstructor() {
211.66 + class X {
211.67 + }
211.68 + class Y {
211.69 + }
211.70 +
211.71 + X x = new X();
211.72 + Y y = new Y();
211.73 +
211.74 + return constructor(x) == constructor(y);
211.75 + }
211.76 + @JavaScriptBody(args = {}, body = "return {};")
211.77 + private static Object jsObj() {
211.78 + return null;
211.79 + }
211.80 +
211.81 + public static boolean iofObject() {
211.82 + return jsObj() instanceof Object;
211.83 + }
211.84 +
211.85 + public static int jscall() {
211.86 + return jsgetbytes(new Instance());
211.87 + }
211.88 +
211.89 + @JavaScriptBody(args = { "instance" }, body = "return instance.getByte__B();")
211.90 + private static native int jsgetbytes(Instance instance);
211.91 }
212.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/InstanceSub.java Thu Oct 11 06:15:22 2012 -0700
212.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/InstanceSub.java Wed Jan 23 20:16:48 2013 +0100
212.3 @@ -1,6 +1,6 @@
212.4 /**
212.5 - * Java 4 Browser Bytecode Translator
212.6 - * Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
212.7 + * Back 2 Browser Bytecode Translator
212.8 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
212.9 *
212.10 * This program is free software: you can redistribute it and/or modify
212.11 * it under the terms of the GNU General Public License as published by
212.12 @@ -22,12 +22,19 @@
212.13 * @author Jaroslav Tulach <jtulach@netbeans.org>
212.14 */
212.15 public class InstanceSub extends Instance implements GetByte {
212.16 + private double in;
212.17 +
212.18 public InstanceSub(int i, double d) {
212.19 super(i, d);
212.20 + in = 555.55;
212.21 }
212.22
212.23 @Override
212.24 public void setByte(byte b) {
212.25 super.setByte((byte) (b + 1));
212.26 }
212.27 +
212.28 + public static double recallDbl() {
212.29 + return defaultDblValue();
212.30 + }
212.31 }
213.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/InstanceSubTest.java Thu Oct 11 06:15:22 2012 -0700
213.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/InstanceSubTest.java Wed Jan 23 20:16:48 2013 +0100
213.3 @@ -1,3 +1,20 @@
213.4 +/**
213.5 + * Back 2 Browser Bytecode Translator
213.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
213.7 + *
213.8 + * This program is free software: you can redistribute it and/or modify
213.9 + * it under the terms of the GNU General Public License as published by
213.10 + * the Free Software Foundation, version 2 of the License.
213.11 + *
213.12 + * This program is distributed in the hope that it will be useful,
213.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
213.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
213.15 + * GNU General Public License for more details.
213.16 + *
213.17 + * You should have received a copy of the GNU General Public License
213.18 + * along with this program. Look for COPYING file in the top folder.
213.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
213.20 + */
213.21 package org.apidesign.vm4brwsr;
213.22
213.23 /** Checks if everything works OK, when we switch the
214.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/InstanceTest.java Thu Oct 11 06:15:22 2012 -0700
214.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/InstanceTest.java Wed Jan 23 20:16:48 2013 +0100
214.3 @@ -1,6 +1,6 @@
214.4 /**
214.5 - * Java 4 Browser Bytecode Translator
214.6 - * Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
214.7 + * Back 2 Browser Bytecode Translator
214.8 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
214.9 *
214.10 * This program is free software: you can redistribute it and/or modify
214.11 * it under the terms of the GNU General Public License as published by
214.12 @@ -18,9 +18,8 @@
214.13 package org.apidesign.vm4brwsr;
214.14
214.15 import javax.script.Invocable;
214.16 -import javax.script.ScriptException;
214.17 import org.testng.annotations.Test;
214.18 -import static org.testng.Assert.*;
214.19 +import org.testng.annotations.BeforeClass;
214.20
214.21 /**
214.22 *
214.23 @@ -30,35 +29,42 @@
214.24 @Test public void verifyDefaultDoubleValue() throws Exception {
214.25 assertExec(
214.26 "Will be zero",
214.27 - "org_apidesign_vm4brwsr_Instance_defaultDblValueD",
214.28 + Instance.class, "defaultDblValue__D",
214.29 + Double.valueOf(0)
214.30 + );
214.31 + }
214.32 + @Test public void verifyStaticMethodCall() throws Exception {
214.33 + assertExec(
214.34 + "Will be zero",
214.35 + InstanceSub.class, "recallDbl__D",
214.36 Double.valueOf(0)
214.37 );
214.38 }
214.39 @Test public void verifyAssignedByteValue() throws Exception {
214.40 assertExec(
214.41 "Will one thirty one",
214.42 - "org_apidesign_vm4brwsr_Instance_assignedByteValueB",
214.43 + Instance.class, "assignedByteValue__B",
214.44 Double.valueOf(31)
214.45 );
214.46 }
214.47 @Test public void verifyMagicOne() throws Exception {
214.48 assertExec(
214.49 "Should be three and something",
214.50 - "org_apidesign_vm4brwsr_Instance_magicOneD",
214.51 + Instance.class, "magicOne__D",
214.52 Double.valueOf(3.3)
214.53 );
214.54 }
214.55 @Test public void verifyInstanceMethods() throws Exception {
214.56 assertExec(
214.57 "Should be eleven as we invoke overwritten method, plus 44",
214.58 - "org_apidesign_vm4brwsr_Instance_virtualBytesI",
214.59 + Instance.class, "virtualBytes__I",
214.60 Double.valueOf(55)
214.61 );
214.62 }
214.63 @Test public void verifyInterfaceMethods() throws Exception {
214.64 assertExec(
214.65 "Retruns default value",
214.66 - "org_apidesign_vm4brwsr_Instance_interfaceBytesF",
214.67 + Instance.class, "interfaceBytes__F",
214.68 Double.valueOf(31)
214.69 );
214.70 }
214.71 @@ -66,7 +72,7 @@
214.72 @Test public void isNull() throws Exception {
214.73 assertExec(
214.74 "Yes, we are instance",
214.75 - "org_apidesign_vm4brwsr_Instance_isNullZ",
214.76 + Instance.class, "isNull__Z",
214.77 Double.valueOf(0.0)
214.78 );
214.79 }
214.80 @@ -74,7 +80,7 @@
214.81 @Test public void isInstanceOf() throws Exception {
214.82 assertExec(
214.83 "Yes, we are instance",
214.84 - "org_apidesign_vm4brwsr_Instance_instanceOfZZ",
214.85 + Instance.class, "instanceOf__ZZ",
214.86 Double.valueOf(1.0), true
214.87 );
214.88 }
214.89 @@ -82,7 +88,7 @@
214.90 @Test public void notInstanceOf() throws Exception {
214.91 assertExec(
214.92 "No, we are not an instance",
214.93 - "org_apidesign_vm4brwsr_Instance_instanceOfZZ",
214.94 + Instance.class, "instanceOf__ZZ",
214.95 Double.valueOf(0.0), false
214.96 );
214.97 }
214.98 @@ -90,44 +96,70 @@
214.99 @Test public void verifyCastToClass() throws Exception {
214.100 assertExec(
214.101 "Five signals all is good",
214.102 - "org_apidesign_vm4brwsr_Instance_castsWorkIZ",
214.103 + Instance.class, "castsWork__IZ",
214.104 Double.valueOf(5.0), false
214.105 );
214.106 }
214.107 @Test public void verifyCastToInterface() throws Exception {
214.108 assertExec(
214.109 "Five signals all is good",
214.110 - "org_apidesign_vm4brwsr_Instance_castsWorkIZ",
214.111 + Instance.class, "castsWork__IZ",
214.112 Double.valueOf(5.0), true
214.113 );
214.114 }
214.115
214.116 + @Test public void sharedConstructor() throws Exception {
214.117 + assertExec(
214.118 + "Constructor of first and 2nd instance should be the same",
214.119 + Instance.class, "sharedConstructor__Z",
214.120 + Double.valueOf(1.0)
214.121 + );
214.122 + }
214.123 +
214.124 + @Test public void differentConstructor() throws Exception {
214.125 + assertExec(
214.126 + "Constructor of X and Y should be the different",
214.127 + Instance.class, "differentConstructor__Z",
214.128 + Double.valueOf(0)
214.129 + );
214.130 + }
214.131 +
214.132 + @Test public void jsObjectIsLikeJavaObject() throws Exception {
214.133 + assertExec(
214.134 + "JavaScript object is instance of Java Object",
214.135 + Instance.class, "iofObject__Z",
214.136 + Double.valueOf(1)
214.137 + );
214.138 + }
214.139 +
214.140 + @Test public void jsCallingConvention() throws Exception {
214.141 + assertExec(
214.142 + "Pointer to 'this' is passed automatically (and not as a first argument)",
214.143 + Instance.class, "jscall__I",
214.144 + Double.valueOf(31)
214.145 + );
214.146 + }
214.147 +
214.148 protected String startCompilationWith() {
214.149 return "org/apidesign/vm4brwsr/Instance";
214.150 }
214.151
214.152 + private static CharSequence codeSeq;
214.153 + private static Invocable code;
214.154 +
214.155 + @BeforeClass
214.156 + public void compileTheCode() throws Exception {
214.157 + if (codeSeq == null) {
214.158 + StringBuilder sb = new StringBuilder();
214.159 + code = StaticMethodTest.compileClass(sb, startCompilationWith());
214.160 + codeSeq = sb;
214.161 + }
214.162 + }
214.163 +
214.164 private void assertExec(
214.165 - String msg, String methodName, Object expRes, Object... args
214.166 + String msg, Class clazz, String method, Object expRes, Object... args
214.167 ) throws Exception {
214.168 - StringBuilder sb = new StringBuilder();
214.169 - Invocable i = StaticMethodTest.compileClass(sb, startCompilationWith());
214.170 -
214.171 - Object ret = null;
214.172 - try {
214.173 - ret = i.invokeFunction(methodName, args);
214.174 - } catch (ScriptException ex) {
214.175 - fail("Execution failed in " + sb, ex);
214.176 - } catch (NoSuchMethodException ex) {
214.177 - fail("Cannot find method in " + sb, ex);
214.178 - }
214.179 - if (ret == null && expRes == null) {
214.180 - return;
214.181 - }
214.182 - if (expRes.equals(ret)) {
214.183 - return;
214.184 - }
214.185 - assertEquals(ret, expRes, msg + "was: " + ret + "\n" + sb);
214.186 -
214.187 + StaticMethodTest.assertExec(code, codeSeq, msg, clazz, method, expRes, args);
214.188 }
214.189
214.190 }
215.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
215.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java Wed Jan 23 20:16:48 2013 +0100
215.3 @@ -0,0 +1,187 @@
215.4 +/**
215.5 + * Back 2 Browser Bytecode Translator
215.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
215.7 + *
215.8 + * This program is free software: you can redistribute it and/or modify
215.9 + * it under the terms of the GNU General Public License as published by
215.10 + * the Free Software Foundation, version 2 of the License.
215.11 + *
215.12 + * This program is distributed in the hope that it will be useful,
215.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
215.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
215.15 + * GNU General Public License for more details.
215.16 + *
215.17 + * You should have received a copy of the GNU General Public License
215.18 + * along with this program. Look for COPYING file in the top folder.
215.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
215.20 + */
215.21 +package org.apidesign.vm4brwsr;
215.22 +
215.23 +import javax.script.Invocable;
215.24 +import javax.script.ScriptException;
215.25 +import static org.testng.Assert.*;
215.26 +import org.testng.annotations.BeforeClass;
215.27 +import org.testng.annotations.Test;
215.28 +
215.29 +/**
215.30 + *
215.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
215.32 + */
215.33 +public class NumberTest {
215.34 + @Test public void integerFromString() throws Exception {
215.35 + assertExec("Can convert string to integer", Integer.class, "parseInt__ILjava_lang_String_2",
215.36 + Double.valueOf(333), "333"
215.37 + );
215.38 + }
215.39 +
215.40 + @Test public void doubleFromString() throws Exception {
215.41 + assertExec("Can convert string to double", Double.class, "parseDouble__DLjava_lang_String_2",
215.42 + Double.valueOf(33.3), "33.3"
215.43 + );
215.44 + }
215.45 +
215.46 + @Test public void autoboxDouble() throws Exception {
215.47 + assertExec("Autoboxing of doubles is OK", Numbers.class, "autoboxDblToString__Ljava_lang_String_2",
215.48 + "3.3"
215.49 + );
215.50 + }
215.51 +
215.52 + @Test public void javalog1000() throws Exception {
215.53 + assertEquals(3.0, Math.log10(1000.0), 0.00003, "log_10(1000) == 3");
215.54 + }
215.55 +
215.56 + @Test public void jslog1000() throws Exception {
215.57 + assertExec("log_10(1000) == 3", Math.class, "log10__DD",
215.58 + Double.valueOf(3.0), 1000.0
215.59 + );
215.60 + }
215.61 +
215.62 + @Test public void javaRem() {
215.63 + assertEquals(3, Numbers.rem(303, 10));
215.64 + }
215.65 + @Test public void jsRem() throws Exception {
215.66 + assertExec("Should be three", Numbers.class, "rem__III",
215.67 + Double.valueOf(3.0), 303, 10
215.68 + );
215.69 + }
215.70 +
215.71 + @Test public void deserializeInt() throws Exception {
215.72 + int exp = Numbers.deserInt();
215.73 + assertExec("Should be the same", Numbers.class, "deserInt__I",
215.74 + Double.valueOf(exp)
215.75 + );
215.76 + }
215.77 +
215.78 + @Test public void deserializeSimpleLong() throws Exception {
215.79 + assertExec("Should be 3454", Numbers.class, "deserLong__J_3B",
215.80 + Double.valueOf(3454),
215.81 + new byte[] { (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)13, (byte)126 }
215.82 + );
215.83 + }
215.84 + /* XXX: JavaScript cannot represent as big longs as Java.
215.85 + @Test public void deserializeLargeLong() throws Exception {
215.86 + final byte[] arr = new byte[] {
215.87 + (byte)64, (byte)8, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0
215.88 + };
215.89 + long exp = Numbers.deserLong(arr);
215.90 + assertExec("Should be " + exp, "org_apidesign_vm4brwsr_Numbers_deserLong__JAB",
215.91 + Double.valueOf(exp), arr);
215.92 + }
215.93 + */
215.94 +
215.95 + @Test public void deserializeFloatInJava() throws Exception {
215.96 + float f = 54324.32423f;
215.97 + float r = Numbers.deserFloat();
215.98 + assertEquals(r, f, "Floats are the same");
215.99 + }
215.100 +
215.101 + @Test public void deserializeFloatInJS() throws Exception {
215.102 + float f = 54324.32423f;
215.103 + assertExec("Should be the same", Numbers.class, "deserFloat__F",
215.104 + Double.valueOf(f)
215.105 + );
215.106 + }
215.107 +
215.108 + @Test public void deserializeDoubleInJava() throws Exception {
215.109 + double f = 3.0;
215.110 + double r = Numbers.deserDouble();
215.111 + assertEquals(r, f, 0.001, "Doubles are the same");
215.112 + }
215.113 +
215.114 + @Test public void deserializeDoubleInJS() throws Exception {
215.115 + double f = 3.0;
215.116 + assertExec("Should be the same", Numbers.class, "deserDouble__D", f);
215.117 + }
215.118 + /*
215.119 + @Test public void serDouble() throws IOException {
215.120 + double f = 3.0;
215.121 + ByteArrayOutputStream os = new ByteArrayOutputStream();
215.122 + DataOutputStream d = new DataOutputStream(os);
215.123 + d.writeLong(3454);
215.124 + d.close();
215.125 +
215.126 + StringBuilder sb = new StringBuilder();
215.127 + byte[] arr = os.toByteArray();
215.128 + for (int i = 0; i < arr.length; i++) {
215.129 + sb.append("(byte)").append(arr[i]).append(", ");
215.130 + }
215.131 + fail("" + sb);
215.132 + }
215.133 +*/
215.134 + @Test public void fiveInStringJS() throws Exception {
215.135 + String s = Numbers.intToString();
215.136 + assertExec("Should be the same: " + s,
215.137 + Numbers.class, "intToString__Ljava_lang_String_2",
215.138 + s
215.139 + );
215.140 + }
215.141 +
215.142 + @Test public void sevenInStringJS() throws Exception {
215.143 + String s = Numbers.floatToString();
215.144 + assertExec("Should be the same: " + s,
215.145 + Numbers.class, "floatToString__Ljava_lang_String_2",
215.146 + s
215.147 + );
215.148 + }
215.149 +
215.150 + private static CharSequence codeSeq;
215.151 + private static Invocable code;
215.152 +
215.153 + @BeforeClass
215.154 + public void compileTheCode() throws Exception {
215.155 + if (codeSeq == null) {
215.156 + StringBuilder sb = new StringBuilder();
215.157 + code = StaticMethodTest.compileClass(sb, "org/apidesign/vm4brwsr/Numbers");
215.158 + codeSeq = sb;
215.159 + }
215.160 + }
215.161 +
215.162 + private static void assertExec(
215.163 + String msg, Class<?> clazz, String method, Object expRes, Object... args) throws Exception {
215.164 +
215.165 + Object ret = null;
215.166 + try {
215.167 + ret = code.invokeFunction("bck2brwsr");
215.168 + ret = code.invokeMethod(ret, "loadClass", clazz.getName());
215.169 + ret = code.invokeMethod(ret, method, args);
215.170 + } catch (ScriptException ex) {
215.171 + fail("Execution failed in\n" + StaticMethodTest.dumpJS(codeSeq), ex);
215.172 + } catch (NoSuchMethodException ex) {
215.173 + fail("Cannot find method in\n" + StaticMethodTest.dumpJS(codeSeq), ex);
215.174 + }
215.175 + if (ret == null && expRes == null) {
215.176 + return;
215.177 + }
215.178 + if (expRes.equals(ret)) {
215.179 + return;
215.180 + }
215.181 + if (expRes instanceof Double && ret instanceof Double) {
215.182 + double expD = ((Double)expRes).doubleValue();
215.183 + double retD = ((Double)ret).doubleValue();
215.184 + assertEquals(retD, expD, 0.000004, msg + " was " + ret + "\n" + StaticMethodTest.dumpJS(codeSeq));
215.185 + return;
215.186 + }
215.187 + assertEquals(ret, expRes, msg + "was: " + ret + "\n" + StaticMethodTest.dumpJS(codeSeq));
215.188 + }
215.189 +
215.190 +}
216.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
216.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java Wed Jan 23 20:16:48 2013 +0100
216.3 @@ -0,0 +1,70 @@
216.4 +/**
216.5 + * Back 2 Browser Bytecode Translator
216.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
216.7 + *
216.8 + * This program is free software: you can redistribute it and/or modify
216.9 + * it under the terms of the GNU General Public License as published by
216.10 + * the Free Software Foundation, version 2 of the License.
216.11 + *
216.12 + * This program is distributed in the hope that it will be useful,
216.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
216.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
216.15 + * GNU General Public License for more details.
216.16 + *
216.17 + * You should have received a copy of the GNU General Public License
216.18 + * along with this program. Look for COPYING file in the top folder.
216.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
216.20 + */
216.21 +package org.apidesign.vm4brwsr;
216.22 +
216.23 +import java.io.ByteArrayInputStream;
216.24 +import java.io.DataInputStream;
216.25 +import java.io.IOException;
216.26 +
216.27 +/**
216.28 + *
216.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
216.30 + */
216.31 +public class Numbers {
216.32 + private static Double autoboxDbl() {
216.33 + return 3.3;
216.34 + }
216.35 + public static String autoboxDblToString() {
216.36 + return autoboxDbl().toString().toString();
216.37 + }
216.38 + public static int rem(int a, int b) {
216.39 + return a % b;
216.40 + }
216.41 +
216.42 + static float deserFloat() throws IOException {
216.43 + byte[] arr = {(byte) 71, (byte) 84, (byte) 52, (byte) 83};
216.44 + ByteArrayInputStream is = new ByteArrayInputStream(arr);
216.45 + DataInputStream dis = new DataInputStream(is);
216.46 + float r = dis.readFloat();
216.47 + return r;
216.48 + }
216.49 + static double deserDouble() throws IOException {
216.50 + byte[] arr = {(byte)64, (byte)8, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0};
216.51 + ByteArrayInputStream is = new ByteArrayInputStream(arr);
216.52 + DataInputStream dis = new DataInputStream(is);
216.53 + return dis.readDouble();
216.54 + }
216.55 + static long deserLong(byte[] arr) throws IOException {
216.56 + ByteArrayInputStream is = new ByteArrayInputStream(arr);
216.57 + DataInputStream dis = new DataInputStream(is);
216.58 + return dis.readLong();
216.59 + }
216.60 + static int deserInt() throws IOException {
216.61 + byte[] arr = {(byte) 71, (byte) 84, (byte) 52, (byte) 83};
216.62 + ByteArrayInputStream is = new ByteArrayInputStream(arr);
216.63 + DataInputStream dis = new DataInputStream(is);
216.64 + return dis.readInt();
216.65 + }
216.66 +
216.67 + static String intToString() {
216.68 + return new Integer(5).toString().toString();
216.69 + }
216.70 + static String floatToString() {
216.71 + return new Float(7.0).toString().toString();
216.72 + }
216.73 +}
217.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
217.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Script.java Wed Jan 23 20:16:48 2013 +0100
217.3 @@ -0,0 +1,31 @@
217.4 +/**
217.5 + * Back 2 Browser Bytecode Translator
217.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
217.7 + *
217.8 + * This program is free software: you can redistribute it and/or modify
217.9 + * it under the terms of the GNU General Public License as published by
217.10 + * the Free Software Foundation, version 2 of the License.
217.11 + *
217.12 + * This program is distributed in the hope that it will be useful,
217.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
217.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
217.15 + * GNU General Public License for more details.
217.16 + *
217.17 + * You should have received a copy of the GNU General Public License
217.18 + * along with this program. Look for COPYING file in the top folder.
217.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
217.20 + */
217.21 +package org.apidesign.vm4brwsr;
217.22 +
217.23 +import org.apidesign.bck2brwsr.core.ExtraJavaScript;
217.24 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
217.25 +
217.26 +/** Test to verify external scripts are processed in lazy mode.
217.27 + *
217.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
217.29 + */
217.30 +@ExtraJavaScript(resource = "/org/apidesign/vm4brwsr/ko.js")
217.31 +public class Script {
217.32 + @JavaScriptBody(args = { }, body = "return ko !== null;")
217.33 + public static native boolean checkNotNull();
217.34 +}
218.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethod.java Thu Oct 11 06:15:22 2012 -0700
218.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethod.java Wed Jan 23 20:16:48 2013 +0100
218.3 @@ -1,20 +1,20 @@
218.4 -/*
218.5 -Java 4 Browser Bytecode Translator
218.6 -Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
218.7 -
218.8 -This program is free software: you can redistribute it and/or modify
218.9 -it under the terms of the GNU General Public License as published by
218.10 -the Free Software Foundation, version 2 of the License.
218.11 -
218.12 -This program is distributed in the hope that it will be useful,
218.13 -but WITHOUT ANY WARRANTY; without even the implied warranty of
218.14 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
218.15 -GNU General Public License for more details.
218.16 -
218.17 -You should have received a copy of the GNU General Public License
218.18 -along with this program. Look for COPYING file in the top folder.
218.19 -If not, see http://opensource.org/licenses/GPL-2.0.
218.20 -*/
218.21 +/**
218.22 + * Back 2 Browser Bytecode Translator
218.23 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
218.24 + *
218.25 + * This program is free software: you can redistribute it and/or modify
218.26 + * it under the terms of the GNU General Public License as published by
218.27 + * the Free Software Foundation, version 2 of the License.
218.28 + *
218.29 + * This program is distributed in the hope that it will be useful,
218.30 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
218.31 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
218.32 + * GNU General Public License for more details.
218.33 + *
218.34 + * You should have received a copy of the GNU General Public License
218.35 + * along with this program. Look for COPYING file in the top folder.
218.36 + * If not, see http://opensource.org/licenses/GPL-2.0.
218.37 + */
218.38 package org.apidesign.vm4brwsr;
218.39
218.40 import org.apidesign.bck2brwsr.core.JavaScriptBody;
218.41 @@ -25,6 +25,7 @@
218.42 */
218.43 public class StaticMethod {
218.44 private static int cnt;
218.45 + private static Object NULL;
218.46
218.47 public static int minusOne() {
218.48 return -1;
218.49 @@ -42,6 +43,10 @@
218.50 return toRet;
218.51 }
218.52
218.53 + public static boolean isNull() {
218.54 + return NULL == null;
218.55 + }
218.56 +
218.57 public static int sum(int x, int y) {
218.58 return x + y;
218.59 }
218.60 @@ -95,12 +100,34 @@
218.61 }
218.62
218.63 @JavaScriptBody(
218.64 - args={"i","j"}, body="return (i + j).toString();"
218.65 + args={"i","j"}, body="\n\r\treturn (i + j).toString();"
218.66 )
218.67 public static String i2s(int i, int j) {
218.68 throw new IllegalStateException();
218.69 }
218.70
218.71 + public static String castNull(boolean n) {
218.72 + Object value = n ? null : "Ahoj";
218.73 + return (String)value;
218.74 + }
218.75 +
218.76 + public static String swtch(int what) {
218.77 + switch (what) {
218.78 + case 0: return "Jarda";
218.79 + case 1: return "Darda";
218.80 + case 2: return "Parda";
218.81 + default: return "Marda";
218.82 + }
218.83 + }
218.84 + public static String swtch2(int what) {
218.85 + switch (what) {
218.86 + case 0: return "Jarda";
218.87 + case 11: return "Darda";
218.88 + case 22: return "Parda";
218.89 + default: return "Marda";
218.90 + }
218.91 + }
218.92 +
218.93 static {
218.94 // check order of initializers
218.95 StaticUse.NON_NULL.equals(new Object());
219.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java Thu Oct 11 06:15:22 2012 -0700
219.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java Wed Jan 23 20:16:48 2013 +0100
219.3 @@ -1,28 +1,34 @@
219.4 -/*
219.5 -Java 4 Browser Bytecode Translator
219.6 -Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
219.7 -
219.8 -This program is free software: you can redistribute it and/or modify
219.9 -it under the terms of the GNU General Public License as published by
219.10 -the Free Software Foundation, version 2 of the License.
219.11 -
219.12 -This program is distributed in the hope that it will be useful,
219.13 -but WITHOUT ANY WARRANTY; without even the implied warranty of
219.14 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
219.15 -GNU General Public License for more details.
219.16 -
219.17 -You should have received a copy of the GNU General Public License
219.18 -along with this program. Look for COPYING file in the top folder.
219.19 -If not, see http://opensource.org/licenses/GPL-2.0.
219.20 -*/
219.21 +/**
219.22 + * Back 2 Browser Bytecode Translator
219.23 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
219.24 + *
219.25 + * This program is free software: you can redistribute it and/or modify
219.26 + * it under the terms of the GNU General Public License as published by
219.27 + * the Free Software Foundation, version 2 of the License.
219.28 + *
219.29 + * This program is distributed in the hope that it will be useful,
219.30 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
219.31 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
219.32 + * GNU General Public License for more details.
219.33 + *
219.34 + * You should have received a copy of the GNU General Public License
219.35 + * along with this program. Look for COPYING file in the top folder.
219.36 + * If not, see http://opensource.org/licenses/GPL-2.0.
219.37 + */
219.38 package org.apidesign.vm4brwsr;
219.39
219.40 +import java.io.File;
219.41 +import java.io.FileWriter;
219.42 import java.io.IOException;
219.43 +import java.io.InputStream;
219.44 +import java.net.URL;
219.45 +import java.util.Enumeration;
219.46 import javax.script.Invocable;
219.47 import javax.script.ScriptEngine;
219.48 import javax.script.ScriptEngineManager;
219.49 import javax.script.ScriptException;
219.50 import static org.testng.Assert.*;
219.51 +import org.testng.annotations.BeforeClass;
219.52 import org.testng.annotations.Test;
219.53
219.54 /** Checks the basic behavior of the translator.
219.55 @@ -33,16 +39,24 @@
219.56 @Test public void threePlusFour() throws Exception {
219.57 assertExec(
219.58 "Should be seven",
219.59 - "org_apidesign_vm4brwsr_StaticMethod_sumIII",
219.60 + StaticMethod.class, "sum__III",
219.61 Double.valueOf(7),
219.62 3, 4
219.63 );
219.64 }
219.65
219.66 + @Test public void checkReallyInitializedValues() throws Exception {
219.67 + assertExec(
219.68 + "Return true",
219.69 + StaticMethod.class, "isNull__Z",
219.70 + Double.valueOf(1)
219.71 + );
219.72 + }
219.73 +
219.74 @Test public void powerOfThree() throws Exception {
219.75 assertExec(
219.76 "Should be nine",
219.77 - "org_apidesign_vm4brwsr_StaticMethod_powerFF",
219.78 + StaticMethod.class, "power__FF",
219.79 Double.valueOf(9),
219.80 3.0f
219.81 );
219.82 @@ -51,7 +65,7 @@
219.83 @Test public void minusOne() throws Exception {
219.84 assertExec(
219.85 "Should be minus one",
219.86 - "org_apidesign_vm4brwsr_StaticMethod_minusOneI",
219.87 + StaticMethod.class, "minusOne__I",
219.88 Double.valueOf(-1)
219.89 );
219.90 }
219.91 @@ -59,7 +73,7 @@
219.92 @Test public void doubleWithoutLong() throws Exception {
219.93 assertExec(
219.94 "Should be two",
219.95 - "org_apidesign_vm4brwsr_StaticMethod_minusDDJ",
219.96 + StaticMethod.class, "minus__DDJ",
219.97 Double.valueOf(2),
219.98 3.0d, 1l
219.99 );
219.100 @@ -68,7 +82,7 @@
219.101 @Test public void divAndRound() throws Exception {
219.102 assertExec(
219.103 "Should be rounded to one",
219.104 - "org_apidesign_vm4brwsr_StaticMethod_divIBD",
219.105 + StaticMethod.class, "div__IBD",
219.106 Double.valueOf(1),
219.107 3, 3.75
219.108 );
219.109 @@ -76,7 +90,7 @@
219.110 @Test public void mixedMethodFourParams() throws Exception {
219.111 assertExec(
219.112 "Should be two",
219.113 - "org_apidesign_vm4brwsr_StaticMethod_mixIIJBD",
219.114 + StaticMethod.class, "mix__IIJBD",
219.115 Double.valueOf(20),
219.116 2, 10l, 5, 2.0
219.117 );
219.118 @@ -84,7 +98,7 @@
219.119 @Test public void factRec() throws Exception {
219.120 assertExec(
219.121 "Factorial of 5 is 120",
219.122 - "org_apidesign_vm4brwsr_StaticMethod_factRecJI",
219.123 + StaticMethod.class, "factRec__JI",
219.124 Double.valueOf(120),
219.125 5
219.126 );
219.127 @@ -92,7 +106,7 @@
219.128 @Test public void factIter() throws Exception {
219.129 assertExec(
219.130 "Factorial of 5 is 120",
219.131 - "org_apidesign_vm4brwsr_StaticMethod_factIterJI",
219.132 + StaticMethod.class, "factIter__JI",
219.133 Double.valueOf(120),
219.134 5
219.135 );
219.136 @@ -101,7 +115,7 @@
219.137 @Test public void xor() throws Exception {
219.138 assertExec(
219.139 "Xor is 4",
219.140 - "org_apidesign_vm4brwsr_StaticMethod_xorJIJ",
219.141 + StaticMethod.class, "xor__JIJ",
219.142 Double.valueOf(4),
219.143 7,
219.144 3
219.145 @@ -111,7 +125,7 @@
219.146 @Test public void or() throws Exception {
219.147 assertExec(
219.148 "Or will be 7",
219.149 - "org_apidesign_vm4brwsr_StaticMethod_orOrAndJZII",
219.150 + StaticMethod.class, "orOrAnd__JZII",
219.151 Double.valueOf(7),
219.152 true,
219.153 4,
219.154 @@ -121,14 +135,14 @@
219.155 @Test public void nullCheck() throws Exception {
219.156 assertExec(
219.157 "Returns nothing",
219.158 - "org_apidesign_vm4brwsr_StaticMethod_noneLjava_lang_ObjectII",
219.159 + StaticMethod.class, "none__Ljava_lang_Object_2II",
219.160 null, 1, 3
219.161 );
219.162 }
219.163 @Test public void and() throws Exception {
219.164 assertExec(
219.165 "And will be 3",
219.166 - "org_apidesign_vm4brwsr_StaticMethod_orOrAndJZII",
219.167 + StaticMethod.class, "orOrAnd__JZII",
219.168 Double.valueOf(3),
219.169 false,
219.170 7,
219.171 @@ -138,7 +152,7 @@
219.172 @Test public void inc4() throws Exception {
219.173 assertExec(
219.174 "It will be 4",
219.175 - "org_apidesign_vm4brwsr_StaticMethod_inc4I",
219.176 + StaticMethod.class, "inc4__I",
219.177 Double.valueOf(4)
219.178 );
219.179 }
219.180 @@ -151,7 +165,7 @@
219.181 @Test public void shiftLeftInJS() throws Exception {
219.182 assertExec(
219.183 "Setting 9th bit",
219.184 - "org_apidesign_vm4brwsr_StaticMethod_shiftLeftIII",
219.185 + StaticMethod.class, "shiftLeft__III",
219.186 Double.valueOf(256),
219.187 1, 8
219.188 );
219.189 @@ -165,7 +179,7 @@
219.190 @Test public void shiftRightInJS() throws Exception {
219.191 assertExec(
219.192 "Get -1",
219.193 - "org_apidesign_vm4brwsr_StaticMethod_shiftArithmRightIIIZ",
219.194 + StaticMethod.class, "shiftArithmRight__IIIZ",
219.195 Double.valueOf(-1),
219.196 -8, 3, true
219.197 );
219.198 @@ -178,7 +192,7 @@
219.199 @Test public void unsignedShiftRightInJS() throws Exception {
219.200 assertExec(
219.201 "Get -1",
219.202 - "org_apidesign_vm4brwsr_StaticMethod_shiftArithmRightIIIZ",
219.203 + StaticMethod.class, "shiftArithmRight__IIIZ",
219.204 Double.valueOf(1),
219.205 8, 3, false
219.206 );
219.207 @@ -187,23 +201,84 @@
219.208 @Test public void javaScriptBody() throws Exception {
219.209 assertExec(
219.210 "JavaScript string",
219.211 - "org_apidesign_vm4brwsr_StaticMethod_i2sLjava_lang_StringII",
219.212 + StaticMethod.class, "i2s__Ljava_lang_String_2II",
219.213 "333",
219.214 330, 3
219.215 );
219.216 }
219.217
219.218 - private static void assertExec(String msg, String methodName, Object expRes, Object... args) throws Exception {
219.219 + @Test public void switchJarda() throws Exception {
219.220 + assertExec(
219.221 + "The expected value",
219.222 + StaticMethod.class, "swtch__Ljava_lang_String_2I",
219.223 + "Jarda",
219.224 + 0
219.225 + );
219.226 + }
219.227 +
219.228 + @Test public void switchDarda() throws Exception {
219.229 + assertExec(
219.230 + "The expected value",
219.231 + StaticMethod.class, "swtch__Ljava_lang_String_2I",
219.232 + "Darda",
219.233 + 1
219.234 + );
219.235 + }
219.236 + @Test public void switchParda() throws Exception {
219.237 + assertExec(
219.238 + "The expected value",
219.239 + StaticMethod.class, "swtch2__Ljava_lang_String_2I",
219.240 + "Parda",
219.241 + 22
219.242 + );
219.243 + }
219.244 + @Test public void switchMarda() throws Exception {
219.245 + assertExec(
219.246 + "The expected value",
219.247 + StaticMethod.class, "swtch__Ljava_lang_String_2I",
219.248 + "Marda",
219.249 + -433
219.250 + );
219.251 + }
219.252 +
219.253 + @Test public void checkNullCast() throws Exception {
219.254 + assertExec("Null can be cast to any type",
219.255 + StaticMethod.class, "castNull__Ljava_lang_String_2Z",
219.256 + null, true
219.257 + );
219.258 + }
219.259 +
219.260 + private static CharSequence codeSeq;
219.261 + private static Invocable code;
219.262 +
219.263 + @BeforeClass
219.264 + public void compileTheCode() throws Exception {
219.265 StringBuilder sb = new StringBuilder();
219.266 - Invocable i = compileClass(sb, "org/apidesign/vm4brwsr/StaticMethod");
219.267 -
219.268 + code = compileClass(sb, "org/apidesign/vm4brwsr/StaticMethod");
219.269 + codeSeq = sb;
219.270 + }
219.271 +
219.272 +
219.273 + private static void assertExec(
219.274 + String msg, Class clazz, String method,
219.275 + Object expRes, Object... args
219.276 + ) throws Exception {
219.277 + assertExec(code, codeSeq, msg, clazz, method, expRes, args);
219.278 + }
219.279 + static void assertExec(
219.280 + Invocable toRun, CharSequence theCode,
219.281 + String msg, Class clazz, String method,
219.282 + Object expRes, Object... args
219.283 + ) throws Exception {
219.284 Object ret = null;
219.285 try {
219.286 - ret = i.invokeFunction(methodName, args);
219.287 + ret = toRun.invokeFunction("bck2brwsr");
219.288 + ret = toRun.invokeMethod(ret, "loadClass", clazz.getName());
219.289 + ret = toRun.invokeMethod(ret, method, args);
219.290 } catch (ScriptException ex) {
219.291 - fail("Execution failed in " + sb, ex);
219.292 + fail("Execution failed in\n" + dumpJS(theCode), ex);
219.293 } catch (NoSuchMethodException ex) {
219.294 - fail("Cannot find method in " + sb, ex);
219.295 + fail("Cannot find method in\n" + dumpJS(theCode), ex);
219.296 }
219.297 if (ret == null && expRes == null) {
219.298 return;
219.299 @@ -211,24 +286,59 @@
219.300 if (expRes != null && expRes.equals(ret)) {
219.301 return;
219.302 }
219.303 - assertEquals(ret, expRes, msg + "was: " + ret + "\n" + sb);
219.304 + assertEquals(ret, expRes, msg + "was: " + ret + "\n" + dumpJS(theCode));
219.305
219.306 }
219.307
219.308 static Invocable compileClass(StringBuilder sb, String... names) throws ScriptException, IOException {
219.309 + return compileClass(sb, null, names);
219.310 + }
219.311 + static Invocable compileClass(
219.312 + StringBuilder sb, ScriptEngine[] eng, String... names
219.313 + ) throws ScriptException, IOException {
219.314 if (sb == null) {
219.315 sb = new StringBuilder();
219.316 }
219.317 - GenJS.compile(sb, names);
219.318 + Bck2Brwsr.generate(sb, new EmulationResources(), names);
219.319 ScriptEngineManager sem = new ScriptEngineManager();
219.320 ScriptEngine js = sem.getEngineByExtension("js");
219.321 + if (eng != null) {
219.322 + eng[0] = js;
219.323 + }
219.324 try {
219.325 Object res = js.eval(sb.toString());
219.326 assertTrue(js instanceof Invocable, "It is invocable object: " + res);
219.327 return (Invocable)js;
219.328 - } catch (ScriptException ex) {
219.329 - fail("Could not compile:\n" + sb, ex);
219.330 + } catch (Exception ex) {
219.331 + if (sb.length() > 2000) {
219.332 + sb = dumpJS(sb);
219.333 + }
219.334 + fail("Could not evaluate:\n" + sb, ex);
219.335 return null;
219.336 }
219.337 }
219.338 + static StringBuilder dumpJS(CharSequence sb) throws IOException {
219.339 + File f = File.createTempFile("execution", ".js");
219.340 + FileWriter w = new FileWriter(f);
219.341 + w.append(sb);
219.342 + w.close();
219.343 + return new StringBuilder(f.getPath());
219.344 + }
219.345 + private static class EmulationResources implements Bck2Brwsr.Resources {
219.346 + @Override
219.347 + public InputStream get(String name) throws IOException {
219.348 + Enumeration<URL> en = StaticMethodTest.class.getClassLoader().getResources(name);
219.349 + URL u = null;
219.350 + while (en.hasMoreElements()) {
219.351 + u = en.nextElement();
219.352 + }
219.353 + if (u == null) {
219.354 + throw new IOException("Can't find " + name);
219.355 + }
219.356 + if (u.toExternalForm().contains("rt.jar!")) {
219.357 + throw new IOException("No emulation for " + u);
219.358 + }
219.359 + return u.openStream();
219.360 + }
219.361 + }
219.362 }
220.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StaticUse.java Thu Oct 11 06:15:22 2012 -0700
220.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StaticUse.java Wed Jan 23 20:16:48 2013 +0100
220.3 @@ -1,3 +1,20 @@
220.4 +/**
220.5 + * Back 2 Browser Bytecode Translator
220.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
220.7 + *
220.8 + * This program is free software: you can redistribute it and/or modify
220.9 + * it under the terms of the GNU General Public License as published by
220.10 + * the Free Software Foundation, version 2 of the License.
220.11 + *
220.12 + * This program is distributed in the hope that it will be useful,
220.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
220.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
220.15 + * GNU General Public License for more details.
220.16 + *
220.17 + * You should have received a copy of the GNU General Public License
220.18 + * along with this program. Look for COPYING file in the top folder.
220.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
220.20 + */
220.21 package org.apidesign.vm4brwsr;
220.22
220.23 public class StaticUse {
221.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
221.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StringArrayTest.java Wed Jan 23 20:16:48 2013 +0100
221.3 @@ -0,0 +1,50 @@
221.4 +/**
221.5 + * Back 2 Browser Bytecode Translator
221.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
221.7 + *
221.8 + * This program is free software: you can redistribute it and/or modify
221.9 + * it under the terms of the GNU General Public License as published by
221.10 + * the Free Software Foundation, version 2 of the License.
221.11 + *
221.12 + * This program is distributed in the hope that it will be useful,
221.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
221.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
221.15 + * GNU General Public License for more details.
221.16 + *
221.17 + * You should have received a copy of the GNU General Public License
221.18 + * along with this program. Look for COPYING file in the top folder.
221.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
221.20 + */
221.21 +package org.apidesign.vm4brwsr;
221.22 +
221.23 +import org.testng.annotations.Test;
221.24 +import static org.testng.Assert.*;
221.25 +
221.26 +public class StringArrayTest {
221.27 + @Test public void deleteMinusIndex() throws Exception {
221.28 + String[] arr = { "Ahoj", "Kluci" };
221.29 + StringArray list = StringArray.asList(arr);
221.30 + list.delete(-1);
221.31 + assertEquals(list.toArray().length, 2, "No element removed");
221.32 + }
221.33 + @Test public void deleteTooHighIndex() throws Exception {
221.34 + String[] arr = { "Ahoj", "Kluci" };
221.35 + StringArray list = StringArray.asList(arr);
221.36 + list.delete(5);
221.37 + assertEquals(list.toArray().length, 2, "No element removed");
221.38 + }
221.39 + @Test public void deleteFirst() throws Exception {
221.40 + String[] arr = { "Ahoj", "Kluci" };
221.41 + StringArray list = StringArray.asList(arr);
221.42 + list.delete(0);
221.43 + assertEquals(list.toArray().length, 1, "First element removed");
221.44 + assertEquals(list.toArray()[0], "Kluci");
221.45 + }
221.46 + @Test public void deleteSecond() throws Exception {
221.47 + String[] arr = { "Ahoj", "Kluci" };
221.48 + StringArray list = StringArray.asList(arr);
221.49 + list.delete(1);
221.50 + assertEquals(list.toArray().length, 1, "Second element removed");
221.51 + assertEquals(list.toArray()[0], "Ahoj");
221.52 + }
221.53 +}
222.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StringSample.java Thu Oct 11 06:15:22 2012 -0700
222.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StringSample.java Wed Jan 23 20:16:48 2013 +0100
222.3 @@ -1,3 +1,20 @@
222.4 +/**
222.5 + * Back 2 Browser Bytecode Translator
222.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
222.7 + *
222.8 + * This program is free software: you can redistribute it and/or modify
222.9 + * it under the terms of the GNU General Public License as published by
222.10 + * the Free Software Foundation, version 2 of the License.
222.11 + *
222.12 + * This program is distributed in the hope that it will be useful,
222.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
222.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
222.15 + * GNU General Public License for more details.
222.16 + *
222.17 + * You should have received a copy of the GNU General Public License
222.18 + * along with this program. Look for COPYING file in the top folder.
222.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
222.20 + */
222.21 package org.apidesign.vm4brwsr;
222.22
222.23 /**
222.24 @@ -18,18 +35,80 @@
222.25 return HELLO.charAt(indx);
222.26 }
222.27
222.28 + public static boolean equalToHello(int from, int to) {
222.29 + return "Hello".equals(HELLO.substring(from, to));
222.30 + }
222.31 +
222.32 public static String fromChars(char a, char b, char c) {
222.33 char[] arr = { a, b, c };
222.34 return new String(arr).toString();
222.35 }
222.36
222.37 + public static String charsFromNumbers() {
222.38 + return chars((char)65, (char)66, (char)67);
222.39 + }
222.40 +
222.41 + public static String charsFromChars() {
222.42 + return chars('A', 'B', 'C');
222.43 + }
222.44 +
222.45 + public static String chars(char a, char b, char c) {
222.46 + return ("" + a + b +c).toString();
222.47 + }
222.48 +
222.49 + public static String replace(String s, char a, char b) {
222.50 + return s.replace(a, b);
222.51 + }
222.52 +
222.53 + public static int hashCode(String h) {
222.54 + return h.hashCode();
222.55 + }
222.56 +
222.57 + public static boolean isStringInstance() {
222.58 + return chars('a', (char)30, 'b') instanceof String;
222.59 + }
222.60 +
222.61 + public static String insertBuffer() {
222.62 + StringBuilder sb = new StringBuilder();
222.63 + sb.append("Jardo!");
222.64 + sb.insert(0, "Ahoj ");
222.65 + sb.delete(4, 8);
222.66 + return sb.toString().toString();
222.67 + }
222.68 +
222.69 + public static int countAB(String txt) {
222.70 + int cnt = 0;
222.71 + for (int i = 0; i < txt.length(); i++) {
222.72 + switch (txt.charAt(i)) {
222.73 + case 'A': cnt++; break;
222.74 + case 'B': cnt += 2; break;
222.75 + }
222.76 + }
222.77 + return cnt;
222.78 + }
222.79 +
222.80 + public static int stringSwitch(String txt) {
222.81 + switch (txt) {
222.82 + case "jedna": return 1;
222.83 + case "dve": return 2;
222.84 + case "tri": return 3;
222.85 + case "ctyri": return 4;
222.86 + }
222.87 + return -1;
222.88 + }
222.89 +
222.90 public static String toStringTest(int howMuch) {
222.91 + counter = 0;
222.92 StringSample ss = null;
222.93 for (int i = 0; i < howMuch; i++) {
222.94 ss = new StringSample();
222.95 }
222.96 return ss.toString().toString();
222.97 }
222.98 +
222.99 + public static String concatStrings() {
222.100 + return (toStringTest(1) + "\\\n\r\t").toString();
222.101 + }
222.102
222.103 @Override
222.104 public String toString() {
223.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java Thu Oct 11 06:15:22 2012 -0700
223.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java Wed Jan 23 20:16:48 2013 +0100
223.3 @@ -1,9 +1,26 @@
223.4 +/**
223.5 + * Back 2 Browser Bytecode Translator
223.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
223.7 + *
223.8 + * This program is free software: you can redistribute it and/or modify
223.9 + * it under the terms of the GNU General Public License as published by
223.10 + * the Free Software Foundation, version 2 of the License.
223.11 + *
223.12 + * This program is distributed in the hope that it will be useful,
223.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
223.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
223.15 + * GNU General Public License for more details.
223.16 + *
223.17 + * You should have received a copy of the GNU General Public License
223.18 + * along with this program. Look for COPYING file in the top folder.
223.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
223.20 + */
223.21 package org.apidesign.vm4brwsr;
223.22
223.23 import javax.script.Invocable;
223.24 -import javax.script.ScriptException;
223.25 import org.testng.annotations.Test;
223.26 import static org.testng.Assert.*;
223.27 +import org.testng.annotations.BeforeClass;
223.28
223.29 /**
223.30 *
223.31 @@ -13,23 +30,55 @@
223.32 @Test public void firstChar() throws Exception {
223.33 assertExec(
223.34 "First char in Hello is H",
223.35 - "org_apidesign_vm4brwsr_StringSample_sayHelloCI",
223.36 - "H", 0
223.37 + StringSample.class, "sayHello__CI",
223.38 + 72, 0
223.39 );
223.40 }
223.41
223.42 @Test public void fromChars() throws Exception {
223.43 assertExec(
223.44 "First char in Hello is ABC",
223.45 - "org_apidesign_vm4brwsr_StringSample_fromCharsLjava_lang_StringCCC",
223.46 + StringSample.class, "fromChars__Ljava_lang_String_2CCC",
223.47 "ABC", 'A', 'B', 'C'
223.48 );
223.49 }
223.50
223.51 + @Test public void concatChars() throws Exception {
223.52 + assertExec(
223.53 + "Composing yields ABC",
223.54 + StringSample.class, "chars__Ljava_lang_String_2CCC",
223.55 + "ABC", 'A', 'B', 'C'
223.56 + );
223.57 + }
223.58 +
223.59 + @Test public void concatCharsFromInts() throws Exception {
223.60 + assertExec(
223.61 + "Composing yields ABC",
223.62 + StringSample.class, "charsFromNumbers__Ljava_lang_String_2",
223.63 + "ABC"
223.64 + );
223.65 + }
223.66 +
223.67 + @Test public void concatCharsFromChars() throws Exception {
223.68 + assertExec(
223.69 + "Composing yields ABC",
223.70 + StringSample.class, "charsFromChars__Ljava_lang_String_2",
223.71 + "ABC"
223.72 + );
223.73 + }
223.74 +
223.75 + @Test public void instanceOfWorks() throws Exception {
223.76 + assertExec(
223.77 + "It is string",
223.78 + StringSample.class, "isStringInstance__Z",
223.79 + Double.valueOf(1.0)
223.80 + );
223.81 + }
223.82 +
223.83 @Test(timeOut=10000) public void toStringConcatenation() throws Exception {
223.84 assertExec(
223.85 "Five executions should generate 5Hello World!",
223.86 - "org_apidesign_vm4brwsr_StringSample_toStringTestLjava_lang_StringI",
223.87 + StringSample.class, "toStringTest__Ljava_lang_String_2I",
223.88 "Hello World!5", 5
223.89 );
223.90 }
223.91 @@ -37,29 +86,111 @@
223.92 assertEquals("Hello World!5", StringSample.toStringTest(5));
223.93 }
223.94
223.95 - private static void assertExec(String msg, String methodName, Object expRes, Object... args) throws Exception {
223.96 + @Test(timeOut=10000) public void stringStringConcat() throws Exception {
223.97 + assertExec(
223.98 + "Composes strings OK",
223.99 + StringSample.class, "concatStrings__Ljava_lang_String_2",
223.100 + "Hello World!1" + "\\\n\r\t"
223.101 + );
223.102 + }
223.103 +
223.104 + @Test public void equalsAndSubstring() throws Exception {
223.105 + assertExec(
223.106 + "Composes are OK",
223.107 + StringSample.class, "equalToHello__ZII",
223.108 + true, 0, 5
223.109 + );
223.110 + }
223.111 + @Test public void replaceChars() throws Exception {
223.112 + assertExec(
223.113 + "Can replace slashes by underscores",
223.114 + StringSample.class, "replace__Ljava_lang_String_2Ljava_lang_String_2CC",
223.115 + "x_y_z", "x/y/z", '/', '_'
223.116 + );
223.117 + }
223.118 + @Test public void replaceIntChars() throws Exception {
223.119 + assertExec(
223.120 + "Can replace slashes by underscores",
223.121 + StringSample.class, "replace__Ljava_lang_String_2Ljava_lang_String_2CC",
223.122 + "x_y_z", "x/y/z", (int)'/', (int)'_'
223.123 + );
223.124 + }
223.125 +
223.126 + @Test public void insertBuilder() throws Exception {
223.127 + assertExec(
223.128 + "Can insert something into a buffer?",
223.129 + StringSample.class, "insertBuffer__Ljava_lang_String_2",
223.130 + "Ahojdo!"
223.131 + );
223.132 + }
223.133 +
223.134 + @Test public void compareHashCodeHi() throws Exception {
223.135 + String j = "Hi";
223.136 + int jh = StringSample.hashCode(j);
223.137 + assertExec(
223.138 + "Hashcode is the same " +jh,
223.139 + StringSample.class, "hashCode__ILjava_lang_String_2",
223.140 + Double.valueOf(jh), j
223.141 + );
223.142 + }
223.143 + @Test public void compareHashCode1() throws Exception {
223.144 + String j = "Hello Java!";
223.145 + int jh = StringSample.hashCode(j);
223.146 + assertExec(
223.147 + "Hashcode is the same " + jh,
223.148 + StringSample.class, "hashCode__ILjava_lang_String_2",
223.149 + Double.valueOf(jh), j
223.150 + );
223.151 + }
223.152 + @Test public void stringSwitch1() throws Exception {
223.153 + assertExec(
223.154 + "Get one",
223.155 + StringSample.class, "stringSwitch__ILjava_lang_String_2",
223.156 + Double.valueOf(1), "jedna"
223.157 + );
223.158 + }
223.159 + @Test public void stringSwitch2() throws Exception {
223.160 + assertExec(
223.161 + "Get two",
223.162 + StringSample.class, "stringSwitch__ILjava_lang_String_2",
223.163 + Double.valueOf(2), "dve"
223.164 + );
223.165 + }
223.166 + @Test public void stringSwitchDefault() throws Exception {
223.167 + assertExec(
223.168 + "Get -1",
223.169 + StringSample.class, "stringSwitch__ILjava_lang_String_2",
223.170 + Double.valueOf(-1), "none"
223.171 + );
223.172 + }
223.173 +
223.174 + @Test public void countAB() throws Exception {
223.175 + assertEquals(StringSample.countAB("Ahoj Bedo!"), 3, "Verify Java code is sane");
223.176 + assertExec(
223.177 + "One A and one B adds to 3",
223.178 + StringSample.class, "countAB__ILjava_lang_String_2",
223.179 + Double.valueOf(3), "Ahoj Bedo!"
223.180 + );
223.181 +
223.182 + }
223.183 +
223.184 + private static CharSequence codeSeq;
223.185 + private static Invocable code;
223.186 +
223.187 + @BeforeClass
223.188 + public void compileTheCode() throws Exception {
223.189 StringBuilder sb = new StringBuilder();
223.190 - Invocable i = StaticMethodTest.compileClass(sb,
223.191 + code = StaticMethodTest.compileClass(sb,
223.192 "org/apidesign/vm4brwsr/StringSample",
223.193 "java/lang/String"
223.194 );
223.195 -
223.196 - Object ret = null;
223.197 - try {
223.198 - ret = i.invokeFunction(methodName, args);
223.199 - } catch (ScriptException ex) {
223.200 - fail("Execution failed in " + sb, ex);
223.201 - } catch (NoSuchMethodException ex) {
223.202 - fail("Cannot find method in " + sb, ex);
223.203 - }
223.204 - if (ret == null && expRes == null) {
223.205 - return;
223.206 - }
223.207 - if (expRes.equals(ret)) {
223.208 - return;
223.209 - }
223.210 - assertEquals(ret, expRes, msg + "was: " + ret + "\n" + sb);
223.211 -
223.212 + codeSeq = sb;
223.213 + }
223.214 +
223.215 + private static void assertExec(String msg,
223.216 + Class<?> clazz, String method, Object expRes, Object... args
223.217 + ) throws Exception {
223.218 + StaticMethodTest.assertExec(code, codeSeq, msg, clazz, method, expRes, args);
223.219 }
223.220
223.221 }
224.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
224.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/VMLazyTest.java Wed Jan 23 20:16:48 2013 +0100
224.3 @@ -0,0 +1,98 @@
224.4 +/**
224.5 + * Back 2 Browser Bytecode Translator
224.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
224.7 + *
224.8 + * This program is free software: you can redistribute it and/or modify
224.9 + * it under the terms of the GNU General Public License as published by
224.10 + * the Free Software Foundation, version 2 of the License.
224.11 + *
224.12 + * This program is distributed in the hope that it will be useful,
224.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
224.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
224.15 + * GNU General Public License for more details.
224.16 + *
224.17 + * You should have received a copy of the GNU General Public License
224.18 + * along with this program. Look for COPYING file in the top folder.
224.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
224.20 + */
224.21 +package org.apidesign.vm4brwsr;
224.22 +
224.23 +import javax.script.Invocable;
224.24 +import javax.script.ScriptContext;
224.25 +import javax.script.ScriptEngine;
224.26 +import javax.script.ScriptException;
224.27 +import org.testng.annotations.BeforeClass;
224.28 +import static org.testng.Assert.*;
224.29 +import org.testng.annotations.Test;
224.30 +
224.31 +/** Implements loading class by class.
224.32 + *
224.33 + * @author Jaroslav Tulach <jtulach@netbeans.org>
224.34 + */
224.35 +public class VMLazyTest {
224.36 +
224.37 +
224.38 + private static CharSequence codeSeq;
224.39 + private static Invocable code;
224.40 +
224.41 + @BeforeClass
224.42 + public void compileTheCode() throws Exception {
224.43 + StringBuilder sb = new StringBuilder();
224.44 + sb.append("\nvar data = {};");
224.45 + sb.append("\nfunction test(clazz, method) {");
224.46 + sb.append("\n if (!data.bck2brwsr) data.bck2brwsr = bck2brwsr(function(name) { return loader.get(name); });");
224.47 + sb.append("\n var c = data.bck2brwsr.loadClass(clazz);");
224.48 + sb.append("\n return c[method]();");
224.49 + sb.append("\n}");
224.50 +
224.51 + sb.append("\nfunction checkKO() {");
224.52 + sb.append("\n return ko !== null;");
224.53 + sb.append("\n}");
224.54 +
224.55 + ScriptEngine[] arr = { null };
224.56 + code = StaticMethodTest.compileClass(sb, arr,
224.57 + "org/apidesign/vm4brwsr/VM"
224.58 + );
224.59 + arr[0].getContext().setAttribute("loader", new BytesLoader(), ScriptContext.ENGINE_SCOPE);
224.60 + codeSeq = sb;
224.61 + }
224.62 +
224.63 + @Test public void invokeStaticMethod() throws Exception {
224.64 + assertExec("Trying to get -1", "test", Double.valueOf(-1),
224.65 + StaticMethod.class.getName(), "minusOne__I"
224.66 + );
224.67 + }
224.68 +
224.69 + @Test public void loadDependantClass() throws Exception {
224.70 + assertExec("Expecting zero", "test", Double.valueOf(0),
224.71 + InstanceSub.class.getName(), "recallDbl__D"
224.72 + );
224.73 + }
224.74 +
224.75 + @Test public void loadClassWithAssociatedScript() throws Exception {
224.76 + assertExec("ko is defined", "test", true,
224.77 + Script.class.getName(), "checkNotNull__Z"
224.78 + );
224.79 +
224.80 + Object res = code.invokeFunction("checkKO");
224.81 + assertEquals(res, true, "KO is defined on a global level");
224.82 + }
224.83 +
224.84 + private static void assertExec(String msg, String methodName, Object expRes, Object... args) throws Exception {
224.85 + Object ret = null;
224.86 + try {
224.87 + ret = code.invokeFunction(methodName, args);
224.88 + } catch (ScriptException ex) {
224.89 + fail("Execution failed in\n" + StaticMethodTest.dumpJS(codeSeq), ex);
224.90 + } catch (NoSuchMethodException ex) {
224.91 + fail("Cannot find method in\n" + StaticMethodTest.dumpJS(codeSeq), ex);
224.92 + }
224.93 + if (ret == null && expRes == null) {
224.94 + return;
224.95 + }
224.96 + if (expRes.equals(ret)) {
224.97 + return;
224.98 + }
224.99 + assertEquals(ret, expRes, msg + "was: " + ret + "\n" + StaticMethodTest.dumpJS(codeSeq));
224.100 + }
224.101 +}
225.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
225.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/VMinVM.java Wed Jan 23 20:16:48 2013 +0100
225.3 @@ -0,0 +1,46 @@
225.4 +/**
225.5 + * Back 2 Browser Bytecode Translator
225.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
225.7 + *
225.8 + * This program is free software: you can redistribute it and/or modify
225.9 + * it under the terms of the GNU General Public License as published by
225.10 + * the Free Software Foundation, version 2 of the License.
225.11 + *
225.12 + * This program is distributed in the hope that it will be useful,
225.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
225.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
225.15 + * GNU General Public License for more details.
225.16 + *
225.17 + * You should have received a copy of the GNU General Public License
225.18 + * along with this program. Look for COPYING file in the top folder.
225.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
225.20 + */
225.21 +package org.apidesign.vm4brwsr;
225.22 +
225.23 +import java.io.ByteArrayInputStream;
225.24 +import java.io.IOException;
225.25 +
225.26 +/**
225.27 + *
225.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
225.29 + */
225.30 +class VMinVM extends ByteCodeToJavaScript {
225.31 + private VMinVM(Appendable out) {
225.32 + super(out);
225.33 + }
225.34 +
225.35 + static String toJavaScript(byte[] is) throws IOException {
225.36 + StringBuilder sb = new StringBuilder();
225.37 + new VMinVM(sb).compile(new ByteArrayInputStream(is));
225.38 + return sb.toString().toString();
225.39 + }
225.40 +
225.41 + @Override
225.42 + protected boolean requireReference(String internalClassName) {
225.43 + return false;
225.44 + }
225.45 +
225.46 + @Override
225.47 + protected void requireScript(String resourcePath) {
225.48 + }
225.49 +}
226.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
226.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/VMinVMTest.java Wed Jan 23 20:16:48 2013 +0100
226.3 @@ -0,0 +1,94 @@
226.4 +/**
226.5 + * Back 2 Browser Bytecode Translator
226.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
226.7 + *
226.8 + * This program is free software: you can redistribute it and/or modify
226.9 + * it under the terms of the GNU General Public License as published by
226.10 + * the Free Software Foundation, version 2 of the License.
226.11 + *
226.12 + * This program is distributed in the hope that it will be useful,
226.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
226.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
226.15 + * GNU General Public License for more details.
226.16 + *
226.17 + * You should have received a copy of the GNU General Public License
226.18 + * along with this program. Look for COPYING file in the top folder.
226.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
226.20 + */
226.21 +package org.apidesign.vm4brwsr;
226.22 +
226.23 +import java.io.File;
226.24 +import java.io.FileWriter;
226.25 +import java.io.IOException;
226.26 +import static org.testng.Assert.*;
226.27 +import javax.script.Invocable;
226.28 +import org.testng.annotations.BeforeClass;
226.29 +import org.testng.annotations.Test;
226.30 +
226.31 +/**
226.32 + *
226.33 + * @author Jaroslav Tulach <jtulach@netbeans.org>
226.34 + */
226.35 +public class VMinVMTest {
226.36 +
226.37 + private static CharSequence codeSeq;
226.38 + private static Invocable code;
226.39 +
226.40 + @Test public void compareGeneratedCodeForArrayClass() throws Exception {
226.41 + compareCode("org/apidesign/vm4brwsr/Array.class");
226.42 + }
226.43 +
226.44 + @Test public void compareGeneratedCodeForClassesClass() throws Exception {
226.45 + compareCode("org/apidesign/vm4brwsr/Classes.class");
226.46 + }
226.47 +
226.48 + @BeforeClass
226.49 + public void compileTheCode() throws Exception {
226.50 + StringBuilder sb = new StringBuilder();
226.51 + code = StaticMethodTest.compileClass(sb,
226.52 + "org/apidesign/vm4brwsr/VMinVM"
226.53 + );
226.54 + codeSeq = sb;
226.55 + }
226.56 +
226.57 + private void compareCode(final String nm) throws Exception, IOException {
226.58 + byte[] arr = BytesLoader.readClass(nm);
226.59 + String ret1 = VMinVM.toJavaScript(arr);
226.60 +
226.61 + Object ret;
226.62 + try {
226.63 + ret = code.invokeFunction("bck2brwsr");
226.64 + ret = code.invokeMethod(ret, "loadClass", VMinVM.class.getName());
226.65 + ret = code.invokeMethod(ret, "toJavaScript__Ljava_lang_String_2_3B", arr);
226.66 + } catch (Exception ex) {
226.67 + File f = File.createTempFile("execution", ".js");
226.68 + FileWriter w = new FileWriter(f);
226.69 + w.append("var byteCode = [\n ");
226.70 + String sep = "";
226.71 + for (int i = 0; i < arr.length; i++) {
226.72 + w.append(sep).append(Integer.toString((arr[i] + 256) % 256));
226.73 + sep = ", ";
226.74 + if (i % 20 == 0) {
226.75 + w.append("\n ");
226.76 + }
226.77 + }
226.78 + w.append("\n];\n");
226.79 + w.append(codeSeq);
226.80 + w.close();
226.81 + throw new Exception(ex.getMessage() + " file: " + f, ex);
226.82 + }
226.83 +
226.84 +
226.85 + assertTrue(ret instanceof String, "It is string: " + ret);
226.86 +
226.87 + if (!ret1.toString().equals(ret)) {
226.88 + StringBuilder msg = new StringBuilder("Difference found between ");
226.89 + msg.append(StaticMethodTest.dumpJS(ret1));
226.90 + msg.append(" ");
226.91 + msg.append(StaticMethodTest.dumpJS((CharSequence) ret));
226.92 + msg.append(" compiled by ");
226.93 + msg.append(StaticMethodTest.dumpJS(codeSeq));
226.94 + fail(msg.toString());
226.95 + }
226.96 + }
226.97 +}
227.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
227.2 +++ b/vm/src/test/resources/org/apidesign/vm4brwsr/ko.js Wed Jan 23 20:16:48 2013 +0100
227.3 @@ -0,0 +1,20 @@
227.4 +/*
227.5 + * Back 2 Browser Bytecode Translator
227.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
227.7 + *
227.8 + * This program is free software: you can redistribute it and/or modify
227.9 + * it under the terms of the GNU General Public License as published by
227.10 + * the Free Software Foundation, version 2 of the License.
227.11 + *
227.12 + * This program is distributed in the hope that it will be useful,
227.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
227.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
227.15 + * GNU General Public License for more details.
227.16 + *
227.17 + * You should have received a copy of the GNU General Public License
227.18 + * along with this program. Look for COPYING file in the top folder.
227.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
227.20 + */
227.21 +this.ko = {};
227.22 +
227.23 +
228.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
228.2 +++ b/vmtest/pom.xml Wed Jan 23 20:16:48 2013 +0100
228.3 @@ -0,0 +1,62 @@
228.4 +<?xml version="1.0"?>
228.5 +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
228.6 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
228.7 + <modelVersion>4.0.0</modelVersion>
228.8 + <parent>
228.9 + <groupId>org.apidesign</groupId>
228.10 + <artifactId>bck2brwsr</artifactId>
228.11 + <version>0.3-SNAPSHOT</version>
228.12 + </parent>
228.13 + <groupId>org.apidesign.bck2brwsr</groupId>
228.14 + <artifactId>vmtest</artifactId>
228.15 + <version>0.3-SNAPSHOT</version>
228.16 +
228.17 + <name>VM Testing APIs</name>
228.18 + <url>http://bck2brwsr.apidesign.org</url>
228.19 + <build>
228.20 + <plugins>
228.21 + <plugin>
228.22 + <groupId>org.apache.maven.plugins</groupId>
228.23 + <artifactId>maven-compiler-plugin</artifactId>
228.24 + <version>2.3.2</version>
228.25 + <configuration>
228.26 + <source>1.7</source>
228.27 + <target>1.7</target>
228.28 + </configuration>
228.29 + </plugin>
228.30 + </plugins>
228.31 + </build>
228.32 + <properties>
228.33 + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
228.34 + </properties>
228.35 + <dependencies>
228.36 + <dependency>
228.37 + <groupId>org.testng</groupId>
228.38 + <artifactId>testng</artifactId>
228.39 + <scope>compile</scope>
228.40 + <exclusions>
228.41 + <exclusion>
228.42 + <artifactId>junit</artifactId>
228.43 + <groupId>junit</groupId>
228.44 + </exclusion>
228.45 + </exclusions>
228.46 + </dependency>
228.47 + <dependency>
228.48 + <groupId>${project.groupId}</groupId>
228.49 + <artifactId>vm4brwsr</artifactId>
228.50 + <version>${project.version}</version>
228.51 + <type>jar</type>
228.52 + </dependency>
228.53 + <dependency>
228.54 + <groupId>${project.groupId}</groupId>
228.55 + <artifactId>emul</artifactId>
228.56 + <version>${project.version}</version>
228.57 + <scope>test</scope>
228.58 + </dependency>
228.59 + <dependency>
228.60 + <groupId>${project.groupId}</groupId>
228.61 + <artifactId>launcher</artifactId>
228.62 + <version>${project.version}</version>
228.63 + </dependency>
228.64 + </dependencies>
228.65 +</project>
229.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
229.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/BrwsrTest.java Wed Jan 23 20:16:48 2013 +0100
229.3 @@ -0,0 +1,38 @@
229.4 +/**
229.5 + * Back 2 Browser Bytecode Translator
229.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
229.7 + *
229.8 + * This program is free software: you can redistribute it and/or modify
229.9 + * it under the terms of the GNU General Public License as published by
229.10 + * the Free Software Foundation, version 2 of the License.
229.11 + *
229.12 + * This program is distributed in the hope that it will be useful,
229.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
229.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
229.15 + * GNU General Public License for more details.
229.16 + *
229.17 + * You should have received a copy of the GNU General Public License
229.18 + * along with this program. Look for COPYING file in the top folder.
229.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
229.20 + */
229.21 +package org.apidesign.bck2brwsr.vmtest;
229.22 +
229.23 +import java.lang.annotation.ElementType;
229.24 +import java.lang.annotation.Retention;
229.25 +import java.lang.annotation.RetentionPolicy;
229.26 +import java.lang.annotation.Target;
229.27 +
229.28 +/** Annotation to indicate that given method should be executed
229.29 + * in a browser environment. Has to be used in conjunction with {@link VMTest#create(java.lang.Class)}
229.30 + * factory method.
229.31 + * <p>
229.32 + * The browser to is by default executed via {@link java.awt.Desktop#browse(java.net.URI)},
229.33 + * but one can change that by specifying <code>-Dvmtest.brwsrs=firefox,google-chrome</code>
229.34 + * property.
229.35 + *
229.36 + * @author Jaroslav Tulach <jtulach@netbeans.org>
229.37 + */
229.38 +@Retention(RetentionPolicy.RUNTIME)
229.39 +@Target(ElementType.METHOD)
229.40 +public @interface BrwsrTest {
229.41 +}
230.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
230.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/Compare.java Wed Jan 23 20:16:48 2013 +0100
230.3 @@ -0,0 +1,45 @@
230.4 +/**
230.5 + * Back 2 Browser Bytecode Translator
230.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
230.7 + *
230.8 + * This program is free software: you can redistribute it and/or modify
230.9 + * it under the terms of the GNU General Public License as published by
230.10 + * the Free Software Foundation, version 2 of the License.
230.11 + *
230.12 + * This program is distributed in the hope that it will be useful,
230.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
230.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
230.15 + * GNU General Public License for more details.
230.16 + *
230.17 + * You should have received a copy of the GNU General Public License
230.18 + * along with this program. Look for COPYING file in the top folder.
230.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
230.20 + */
230.21 +package org.apidesign.bck2brwsr.vmtest;
230.22 +
230.23 +import java.lang.annotation.ElementType;
230.24 +import java.lang.annotation.Retention;
230.25 +import java.lang.annotation.RetentionPolicy;
230.26 +import java.lang.annotation.Target;
230.27 +
230.28 +/** Can be applied on a method that yields a return value.
230.29 + * Together with {@link VMTest#create} it can be used to write
230.30 + * methods which are executed in real VM as well as JavaScript VMs and
230.31 + * their results are compared.
230.32 + *
230.33 + * @author Jaroslav Tulach <jtulach@netbeans.org>
230.34 + */
230.35 +@Retention(RetentionPolicy.RUNTIME)
230.36 +@Target(ElementType.METHOD)
230.37 +public @interface Compare {
230.38 + /** Specifies whether the system should internal JavaScript interpreter
230.39 + * as available via {@link javax.script.ScriptEngine}. Defaults to true,
230.40 + * but in some situations (benchmarking comes to my mind), one may set this
230.41 + * to <code>false</code>. In such case only browsers provided via
230.42 + * <code>vmtest.brwsrs</code> property are used. For example
230.43 + * <code>"vmtest.brwsrs=firefox,google-chrome"</code> would run the test
230.44 + * in HotSpot VM, firefox and chrome and would compare the results.
230.45 + * @return
230.46 + */
230.47 + boolean scripting() default true;
230.48 +}
231.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
231.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/HtmlFragment.java Wed Jan 23 20:16:48 2013 +0100
231.3 @@ -0,0 +1,38 @@
231.4 +/**
231.5 + * Back 2 Browser Bytecode Translator
231.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
231.7 + *
231.8 + * This program is free software: you can redistribute it and/or modify
231.9 + * it under the terms of the GNU General Public License as published by
231.10 + * the Free Software Foundation, version 2 of the License.
231.11 + *
231.12 + * This program is distributed in the hope that it will be useful,
231.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
231.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
231.15 + * GNU General Public License for more details.
231.16 + *
231.17 + * You should have received a copy of the GNU General Public License
231.18 + * along with this program. Look for COPYING file in the top folder.
231.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
231.20 + */
231.21 +package org.apidesign.bck2brwsr.vmtest;
231.22 +
231.23 +import java.lang.annotation.ElementType;
231.24 +import java.lang.annotation.Retention;
231.25 +import java.lang.annotation.RetentionPolicy;
231.26 +import java.lang.annotation.Target;
231.27 +
231.28 +/** Allows to specify an HTML fragment for a given {@link BrwsrTest}.
231.29 + * Apply either to the method or to enclosing class. The fragment will be
231.30 + * made available in the page that executes given test. Its elements shall
231.31 + * be regularly accessible from the test.
231.32 + *
231.33 + * @author Jaroslav Tulach <jtulach@netbeans.org>
231.34 + */
231.35 +@Retention(RetentionPolicy.RUNTIME)
231.36 +@Target({ ElementType.METHOD, ElementType.TYPE})
231.37 +public @interface HtmlFragment {
231.38 + /** HTML code fragment to be exposed on the testing page.
231.39 + */
231.40 + String value();
231.41 +}
232.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
232.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/VMTest.java Wed Jan 23 20:16:48 2013 +0100
232.3 @@ -0,0 +1,43 @@
232.4 +/**
232.5 + * Back 2 Browser Bytecode Translator
232.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
232.7 + *
232.8 + * This program is free software: you can redistribute it and/or modify
232.9 + * it under the terms of the GNU General Public License as published by
232.10 + * the Free Software Foundation, version 2 of the License.
232.11 + *
232.12 + * This program is distributed in the hope that it will be useful,
232.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
232.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
232.15 + * GNU General Public License for more details.
232.16 + *
232.17 + * You should have received a copy of the GNU General Public License
232.18 + * along with this program. Look for COPYING file in the top folder.
232.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
232.20 + */
232.21 +package org.apidesign.bck2brwsr.vmtest;
232.22 +
232.23 +import org.apidesign.bck2brwsr.vmtest.impl.CompareCase;
232.24 +import org.testng.annotations.Factory;
232.25 +
232.26 +/** A TestNG {@link Factory} that seeks for {@link Compare} annotations
232.27 + * in provided class and builds set of tests that compare the computations
232.28 + * in real as well as JavaScript virtual machines. Use as:<pre>
232.29 + * {@code @}{@link Factory} public static create() {
232.30 + * return @{link VMTest}.{@link #create(YourClass.class);
232.31 + * }</pre>
232.32 + *
232.33 + * @author Jaroslav Tulach <jtulach@netbeans.org>
232.34 + */
232.35 +public final class VMTest {
232.36 + /** Inspects <code>clazz</code> and for each {@lik Compare} method creates
232.37 + * instances of tests. Each instance runs the test in different virtual
232.38 + * machine and at the end they compare the results.
232.39 + *
232.40 + * @param clazz the class to inspect
232.41 + * @return the set of created tests
232.42 + */
232.43 + public static Object[] create(Class<?> clazz) {
232.44 + return CompareCase.create(clazz);
232.45 + }
232.46 +}
233.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
233.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Bck2BrwsrCase.java Wed Jan 23 20:16:48 2013 +0100
233.3 @@ -0,0 +1,116 @@
233.4 +/**
233.5 + * Back 2 Browser Bytecode Translator
233.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
233.7 + *
233.8 + * This program is free software: you can redistribute it and/or modify
233.9 + * it under the terms of the GNU General Public License as published by
233.10 + * the Free Software Foundation, version 2 of the License.
233.11 + *
233.12 + * This program is distributed in the hope that it will be useful,
233.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
233.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
233.15 + * GNU General Public License for more details.
233.16 + *
233.17 + * You should have received a copy of the GNU General Public License
233.18 + * along with this program. Look for COPYING file in the top folder.
233.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
233.20 + */
233.21 +package org.apidesign.bck2brwsr.vmtest.impl;
233.22 +
233.23 +import java.io.File;
233.24 +import java.io.FileWriter;
233.25 +import java.io.IOException;
233.26 +import java.lang.reflect.Constructor;
233.27 +import java.lang.reflect.InvocationTargetException;
233.28 +import java.lang.reflect.Method;
233.29 +import java.util.Map;
233.30 +import java.util.WeakHashMap;
233.31 +import org.apidesign.bck2brwsr.launcher.Launcher;
233.32 +import org.apidesign.bck2brwsr.launcher.MethodInvocation;
233.33 +import org.testng.ITest;
233.34 +import org.testng.annotations.Test;
233.35 +
233.36 +/**
233.37 + *
233.38 + * @author Jaroslav Tulach <jtulach@netbeans.org>
233.39 + */
233.40 +public final class Bck2BrwsrCase implements ITest {
233.41 + private final Method m;
233.42 + private final Launcher l;
233.43 + private final String type;
233.44 + private final boolean fail;
233.45 + Object value;
233.46 + private final String html;
233.47 +
233.48 + Bck2BrwsrCase(Method m, String type, Launcher l, boolean fail, String html) {
233.49 + this.l = l;
233.50 + this.m = m;
233.51 + this.type = type;
233.52 + this.fail = fail;
233.53 + this.html = html;
233.54 + }
233.55 +
233.56 + @Test(groups = "run")
233.57 + public void executeCode() throws Throwable {
233.58 + if (l != null) {
233.59 + MethodInvocation c = l.invokeMethod(m.getDeclaringClass(), m.getName(), html);
233.60 + String res = c.toString();
233.61 + value = res;
233.62 + if (fail) {
233.63 + int idx = res.indexOf(':');
233.64 + if (idx >= 0) {
233.65 + Class<? extends Throwable> thrwbl = null;
233.66 + try {
233.67 + Class<?> exCls = Class.forName(res.substring(0, idx));
233.68 + if (Throwable.class.isAssignableFrom(exCls)) {
233.69 + thrwbl = exCls.asSubclass(Throwable.class);
233.70 + }
233.71 + } catch (Exception ex) {
233.72 + // ignore
233.73 + }
233.74 + if (thrwbl != null) {
233.75 + Throwable t = null;
233.76 + try {
233.77 + for (Constructor<?> cnstr : thrwbl.getConstructors()) {
233.78 + if (cnstr.getParameterTypes().length == 1 && cnstr.getParameterTypes()[0].isAssignableFrom(String.class)) {
233.79 + t = (Throwable) cnstr.newInstance(res.substring(idx + 1));
233.80 + break;
233.81 + }
233.82 + }
233.83 + } catch (Throwable ex) {
233.84 + t = thrwbl.newInstance().initCause(ex);
233.85 + }
233.86 + if (t == null) {
233.87 + t = thrwbl.newInstance().initCause(new Exception(res.substring(idx)));
233.88 + }
233.89 + throw t;
233.90 + }
233.91 + throw new AssertionError(res);
233.92 + }
233.93 + }
233.94 + } else {
233.95 + try {
233.96 + value = m.invoke(m.getDeclaringClass().newInstance());
233.97 + } catch (InvocationTargetException ex) {
233.98 + Throwable t = ex.getTargetException();
233.99 + value = t.getClass().getName() + ":" + t.getMessage();
233.100 + }
233.101 + }
233.102 + }
233.103 +
233.104 + @Override
233.105 + public String getTestName() {
233.106 + return m.getName() + "[" + typeName() + "]";
233.107 + }
233.108 +
233.109 + final String typeName() {
233.110 + return type;
233.111 + }
233.112 + static void dumpJS(StringBuilder sb, Bck2BrwsrCase c) throws IOException {
233.113 + File f = File.createTempFile(c.m.getName(), ".js");
233.114 + try (final FileWriter w = new FileWriter(f)) {
233.115 + w.append(c.l.toString());
233.116 + }
233.117 + sb.append("Path: ").append(f.getPath());
233.118 + }
233.119 +}
234.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
234.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/CompareCase.java Wed Jan 23 20:16:48 2013 +0100
234.3 @@ -0,0 +1,151 @@
234.4 +/**
234.5 + * Back 2 Browser Bytecode Translator
234.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
234.7 + *
234.8 + * This program is free software: you can redistribute it and/or modify
234.9 + * it under the terms of the GNU General Public License as published by
234.10 + * the Free Software Foundation, version 2 of the License.
234.11 + *
234.12 + * This program is distributed in the hope that it will be useful,
234.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
234.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
234.15 + * GNU General Public License for more details.
234.16 + *
234.17 + * You should have received a copy of the GNU General Public License
234.18 + * along with this program. Look for COPYING file in the top folder.
234.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
234.20 + */
234.21 +package org.apidesign.bck2brwsr.vmtest.impl;
234.22 +
234.23 +import org.apidesign.bck2brwsr.vmtest.*;
234.24 +import java.lang.reflect.Method;
234.25 +import java.util.ArrayList;
234.26 +import java.util.List;
234.27 +import org.apidesign.bck2brwsr.launcher.Launcher;
234.28 +import org.testng.Assert;
234.29 +import org.testng.ITest;
234.30 +import org.testng.annotations.Factory;
234.31 +import org.testng.annotations.Test;
234.32 +
234.33 +/** A TestNG {@link Factory} that seeks for {@link Compare} annotations
234.34 + * in provided class and builds set of tests that compare the computations
234.35 + * in real as well as JavaScript virtual machines. Use as:<pre>
234.36 + * {@code @}{@link Factory} public static create() {
234.37 + * return @{link VMTest}.{@link #create(YourClass.class);
234.38 + * }</pre>
234.39 + *
234.40 + * @author Jaroslav Tulach <jtulach@netbeans.org>
234.41 + */
234.42 +public final class CompareCase implements ITest {
234.43 + private final Bck2BrwsrCase first, second;
234.44 + private final Method m;
234.45 +
234.46 + private CompareCase(Method m, Bck2BrwsrCase first, Bck2BrwsrCase second) {
234.47 + this.first = first;
234.48 + this.second = second;
234.49 + this.m = m;
234.50 + }
234.51 +
234.52 + /** Inspects <code>clazz</code> and for each {@lik Compare} method creates
234.53 + * instances of tests. Each instance runs the test in different virtual
234.54 + * machine and at the end they compare the results.
234.55 + *
234.56 + * @param clazz the class to inspect
234.57 + * @return the set of created tests
234.58 + */
234.59 + public static Object[] create(Class<?> clazz) {
234.60 + Method[] arr = clazz.getMethods();
234.61 + List<Object> ret = new ArrayList<>();
234.62 +
234.63 + final LaunchSetup l = LaunchSetup.INSTANCE;
234.64 + ret.add(l);
234.65 +
234.66 + String[] brwsr;
234.67 + {
234.68 + String p = System.getProperty("vmtest.brwsrs");
234.69 + if (p != null) {
234.70 + brwsr = p.split(",");
234.71 + } else {
234.72 + brwsr = new String[0];
234.73 + }
234.74 + }
234.75 +
234.76 + for (Method m : arr) {
234.77 + registerCompareCases(m, l, ret, brwsr);
234.78 + registerBrwsrCases(m, l, ret, brwsr);
234.79 + }
234.80 + return ret.toArray();
234.81 + }
234.82 +
234.83 + /** Test that compares the previous results.
234.84 + * @throws Throwable
234.85 + */
234.86 + @Test(dependsOnGroups = "run") public void compareResults() throws Throwable {
234.87 + Object v1 = first.value;
234.88 + Object v2 = second.value;
234.89 + if (v1 != null) {
234.90 + v1 = v1.toString();
234.91 + } else {
234.92 + v1 = "null";
234.93 + }
234.94 + try {
234.95 + Assert.assertEquals(v2, v1, "Comparing results");
234.96 + } catch (AssertionError e) {
234.97 + StringBuilder sb = new StringBuilder();
234.98 + sb.append(e.getMessage());
234.99 + Bck2BrwsrCase.dumpJS(sb, second);
234.100 + throw new AssertionError(sb.toString());
234.101 + }
234.102 + }
234.103 +
234.104 + /** Test name.
234.105 + * @return name of the tested method followed by a suffix
234.106 + */
234.107 + @Override
234.108 + public String getTestName() {
234.109 + return m.getName() + "[Compare " + second.typeName() + "]";
234.110 + }
234.111 +
234.112 + private static void registerCompareCases(Method m, final LaunchSetup l, List<Object> ret, String[] brwsr) {
234.113 + Compare c = m.getAnnotation(Compare.class);
234.114 + if (c == null) {
234.115 + return;
234.116 + }
234.117 + final Bck2BrwsrCase real = new Bck2BrwsrCase(m, "Java", null, false, null);
234.118 + ret.add(real);
234.119 + if (c.scripting()) {
234.120 + final Bck2BrwsrCase js = new Bck2BrwsrCase(m, "JavaScript", l.javaScript(), false, null);
234.121 + ret.add(js);
234.122 + ret.add(new CompareCase(m, real, js));
234.123 + }
234.124 + for (String b : brwsr) {
234.125 + final Launcher s = l.brwsr(b);
234.126 + ret.add(s);
234.127 + final Bck2BrwsrCase cse = new Bck2BrwsrCase(m, b, s, false, null);
234.128 + ret.add(cse);
234.129 + ret.add(new CompareCase(m, real, cse));
234.130 + }
234.131 + }
234.132 + private static void registerBrwsrCases(Method m, final LaunchSetup l, List<Object> ret, String[] brwsr) {
234.133 + BrwsrTest c = m.getAnnotation(BrwsrTest.class);
234.134 + if (c == null) {
234.135 + return;
234.136 + }
234.137 + HtmlFragment f = m.getAnnotation(HtmlFragment.class);
234.138 + if (f == null) {
234.139 + f = m.getDeclaringClass().getAnnotation(HtmlFragment.class);
234.140 + }
234.141 + String html = f == null ? null : f.value();
234.142 + if (brwsr.length == 0) {
234.143 + final Launcher s = l.brwsr(null);
234.144 + ret.add(s);
234.145 + ret.add(new Bck2BrwsrCase(m, "Brwsr", s, true, html));
234.146 + } else {
234.147 + for (String b : brwsr) {
234.148 + final Launcher s = l.brwsr(b);
234.149 + ret.add(s);
234.150 + ret.add(new Bck2BrwsrCase(m, b, s, true, html));
234.151 + }
234.152 + }
234.153 + }
234.154 +}
235.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
235.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/LaunchSetup.java Wed Jan 23 20:16:48 2013 +0100
235.3 @@ -0,0 +1,68 @@
235.4 +/**
235.5 + * Back 2 Browser Bytecode Translator
235.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
235.7 + *
235.8 + * This program is free software: you can redistribute it and/or modify
235.9 + * it under the terms of the GNU General Public License as published by
235.10 + * the Free Software Foundation, version 2 of the License.
235.11 + *
235.12 + * This program is distributed in the hope that it will be useful,
235.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
235.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
235.15 + * GNU General Public License for more details.
235.16 + *
235.17 + * You should have received a copy of the GNU General Public License
235.18 + * along with this program. Look for COPYING file in the top folder.
235.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
235.20 + */
235.21 +package org.apidesign.bck2brwsr.vmtest.impl;
235.22 +
235.23 +import java.io.IOException;
235.24 +import java.util.LinkedHashMap;
235.25 +import java.util.Map;
235.26 +import org.apidesign.bck2brwsr.launcher.Launcher;
235.27 +import org.testng.annotations.AfterGroups;
235.28 +import org.testng.annotations.BeforeGroups;
235.29 +
235.30 +/**
235.31 + *
235.32 + * @author Jaroslav Tulach <jtulach@netbeans.org>
235.33 + */
235.34 +public final class LaunchSetup {
235.35 + static LaunchSetup INSTANCE = new LaunchSetup();
235.36 +
235.37 + private final Launcher js = Launcher.createJavaScript();
235.38 + private final Map<String,Launcher> brwsrs = new LinkedHashMap<>();
235.39 +
235.40 + private LaunchSetup() {
235.41 + }
235.42 +
235.43 + public Launcher javaScript() {
235.44 + return js;
235.45 + }
235.46 +
235.47 + public synchronized Launcher brwsr(String cmd) {
235.48 + Launcher s = brwsrs.get(cmd);
235.49 + if (s == null) {
235.50 + s = Launcher.createBrowser(cmd);
235.51 + brwsrs.put(cmd, s);
235.52 + }
235.53 + return s;
235.54 + }
235.55 +
235.56 + @BeforeGroups("run")
235.57 + public void initializeLauncher() throws IOException {
235.58 + js.initialize();
235.59 + for (Launcher launcher : brwsrs.values()) {
235.60 + launcher.initialize();
235.61 + }
235.62 + }
235.63 +
235.64 + @AfterGroups("run")
235.65 + public void shutDownLauncher() throws IOException, InterruptedException {
235.66 + js.shutdown();
235.67 + for (Launcher launcher : brwsrs.values()) {
235.68 + launcher.shutdown();
235.69 + }
235.70 + }
235.71 +}
236.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
236.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/AssertionTest.java Wed Jan 23 20:16:48 2013 +0100
236.3 @@ -0,0 +1,39 @@
236.4 +/**
236.5 + * Back 2 Browser Bytecode Translator
236.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
236.7 + *
236.8 + * This program is free software: you can redistribute it and/or modify
236.9 + * it under the terms of the GNU General Public License as published by
236.10 + * the Free Software Foundation, version 2 of the License.
236.11 + *
236.12 + * This program is distributed in the hope that it will be useful,
236.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
236.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
236.15 + * GNU General Public License for more details.
236.16 + *
236.17 + * You should have received a copy of the GNU General Public License
236.18 + * along with this program. Look for COPYING file in the top folder.
236.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
236.20 + */
236.21 +package org.apidesign.bck2brwsr.tck;
236.22 +
236.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
236.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
236.25 +import org.testng.annotations.Factory;
236.26 +
236.27 +/**
236.28 + *
236.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
236.30 + */
236.31 +public class AssertionTest {
236.32 +
236.33 + @Compare public Object checkAssert() throws ClassNotFoundException {
236.34 + assert false : "Is assertion status on?";
236.35 + return null;
236.36 + }
236.37 +
236.38 + @Factory
236.39 + public static Object[] create() {
236.40 + return VMTest.create(AssertionTest.class);
236.41 + }
236.42 +}
237.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
237.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/BrwsrCheckTest.java Wed Jan 23 20:16:48 2013 +0100
237.3 @@ -0,0 +1,57 @@
237.4 +/**
237.5 + * Back 2 Browser Bytecode Translator
237.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
237.7 + *
237.8 + * This program is free software: you can redistribute it and/or modify
237.9 + * it under the terms of the GNU General Public License as published by
237.10 + * the Free Software Foundation, version 2 of the License.
237.11 + *
237.12 + * This program is distributed in the hope that it will be useful,
237.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
237.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
237.15 + * GNU General Public License for more details.
237.16 + *
237.17 + * You should have received a copy of the GNU General Public License
237.18 + * along with this program. Look for COPYING file in the top folder.
237.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
237.20 + */
237.21 +package org.apidesign.bck2brwsr.tck;
237.22 +
237.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
237.24 +import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
237.25 +import org.apidesign.bck2brwsr.vmtest.HtmlFragment;
237.26 +import org.apidesign.bck2brwsr.vmtest.VMTest;
237.27 +import org.testng.annotations.Factory;
237.28 +
237.29 +/**
237.30 + *
237.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
237.32 + */
237.33 +public class BrwsrCheckTest {
237.34 +
237.35 + @BrwsrTest public void assertWindowObjectIsDefined() {
237.36 + assert window() != null : "No window object found!";
237.37 + }
237.38 +
237.39 +
237.40 +
237.41 +
237.42 + @HtmlFragment("<h1 id='hello'>\n"
237.43 + + "Hello!\n"
237.44 + + "</h1>\n")
237.45 + @BrwsrTest public void accessProvidedFragment() {
237.46 + assert getElementById("hello") != null : "Element with 'hello' ID found";
237.47 + }
237.48 +
237.49 + @Factory
237.50 + public static Object[] create() {
237.51 + return VMTest.create(BrwsrCheckTest.class);
237.52 + }
237.53 +
237.54 +
237.55 + @JavaScriptBody(args = {}, body = "return window;")
237.56 + private static native Object window();
237.57 +
237.58 + @JavaScriptBody(args = { "id" }, body = "return window.document.getElementById(id);")
237.59 + private static native Object getElementById(String id);
237.60 +}
238.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
238.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ByteArithmeticTest.java Wed Jan 23 20:16:48 2013 +0100
238.3 @@ -0,0 +1,102 @@
238.4 +/**
238.5 + * Back 2 Browser Bytecode Translator
238.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
238.7 + *
238.8 + * This program is free software: you can redistribute it and/or modify
238.9 + * it under the terms of the GNU General Public License as published by
238.10 + * the Free Software Foundation, version 2 of the License.
238.11 + *
238.12 + * This program is distributed in the hope that it will be useful,
238.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
238.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
238.15 + * GNU General Public License for more details.
238.16 + *
238.17 + * You should have received a copy of the GNU General Public License
238.18 + * along with this program. Look for COPYING file in the top folder.
238.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
238.20 + */
238.21 +package org.apidesign.bck2brwsr.tck;
238.22 +
238.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
238.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
238.25 +import org.testng.annotations.Factory;
238.26 +
238.27 +/**
238.28 + *
238.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
238.30 + */
238.31 +public class ByteArithmeticTest {
238.32 +
238.33 + private static byte add(byte x, byte y) {
238.34 + return (byte)(x + y);
238.35 + }
238.36 +
238.37 + private static byte sub(byte x, byte y) {
238.38 + return (byte)(x - y);
238.39 + }
238.40 +
238.41 + private static byte mul(byte x, byte y) {
238.42 + return (byte)(x * y);
238.43 + }
238.44 +
238.45 + private static byte div(byte x, byte y) {
238.46 + return (byte)(x / y);
238.47 + }
238.48 +
238.49 + private static byte mod(byte x, byte y) {
238.50 + return (byte)(x % y);
238.51 + }
238.52 +
238.53 + @Compare public byte conversion() {
238.54 + return (byte)123456;
238.55 + }
238.56 +
238.57 + @Compare public byte addOverflow() {
238.58 + return add(Byte.MAX_VALUE, (byte)1);
238.59 + }
238.60 +
238.61 + @Compare public byte subUnderflow() {
238.62 + return sub(Byte.MIN_VALUE, (byte)1);
238.63 + }
238.64 +
238.65 + @Compare public byte addMaxByteAndMaxByte() {
238.66 + return add(Byte.MAX_VALUE, Byte.MAX_VALUE);
238.67 + }
238.68 +
238.69 + @Compare public byte subMinByteAndMinByte() {
238.70 + return sub(Byte.MIN_VALUE, Byte.MIN_VALUE);
238.71 + }
238.72 +
238.73 + @Compare public byte multiplyMaxByte() {
238.74 + return mul(Byte.MAX_VALUE, (byte)2);
238.75 + }
238.76 +
238.77 + @Compare public byte multiplyMaxByteAndMaxByte() {
238.78 + return mul(Byte.MAX_VALUE, Byte.MAX_VALUE);
238.79 + }
238.80 +
238.81 + @Compare public byte multiplyMinByte() {
238.82 + return mul(Byte.MIN_VALUE, (byte)2);
238.83 + }
238.84 +
238.85 + @Compare public byte multiplyMinByteAndMinByte() {
238.86 + return mul(Byte.MIN_VALUE, Byte.MIN_VALUE);
238.87 + }
238.88 +
238.89 + @Compare public byte multiplyPrecision() {
238.90 + return mul((byte)17638, (byte)1103);
238.91 + }
238.92 +
238.93 + @Compare public byte division() {
238.94 + return div((byte)1, (byte)2);
238.95 + }
238.96 +
238.97 + @Compare public byte divisionReminder() {
238.98 + return mod((byte)1, (byte)2);
238.99 + }
238.100 +
238.101 + @Factory
238.102 + public static Object[] create() {
238.103 + return VMTest.create(ByteArithmeticTest.class);
238.104 + }
238.105 +}
239.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
239.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CloneTest.java Wed Jan 23 20:16:48 2013 +0100
239.3 @@ -0,0 +1,73 @@
239.4 +/**
239.5 + * Back 2 Browser Bytecode Translator
239.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
239.7 + *
239.8 + * This program is free software: you can redistribute it and/or modify
239.9 + * it under the terms of the GNU General Public License as published by
239.10 + * the Free Software Foundation, version 2 of the License.
239.11 + *
239.12 + * This program is distributed in the hope that it will be useful,
239.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
239.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
239.15 + * GNU General Public License for more details.
239.16 + *
239.17 + * You should have received a copy of the GNU General Public License
239.18 + * along with this program. Look for COPYING file in the top folder.
239.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
239.20 + */
239.21 +package org.apidesign.bck2brwsr.tck;
239.22 +
239.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
239.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
239.25 +import org.testng.annotations.Factory;
239.26 +
239.27 +/**
239.28 + *
239.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
239.30 + */
239.31 +public class CloneTest {
239.32 + private int value;
239.33 +
239.34 + @Compare
239.35 + public Object notSupported() throws CloneNotSupportedException {
239.36 + return this.clone();
239.37 + }
239.38 +
239.39 + @Compare public String sameClass() throws CloneNotSupportedException {
239.40 + return new Clnbl().clone().getClass().getName();
239.41 + }
239.42 +
239.43 + @Compare public boolean differentInstance() throws CloneNotSupportedException {
239.44 + Clnbl orig = new Clnbl();
239.45 + return orig == orig.clone();
239.46 + }
239.47 +
239.48 + @Compare public int sameReference() throws CloneNotSupportedException {
239.49 + CloneTest self = this;
239.50 + Clnbl orig = new Clnbl();
239.51 + self.value = 33;
239.52 + orig.ref = self;
239.53 + return ((Clnbl)orig.clone()).ref.value;
239.54 + }
239.55 +
239.56 + @Compare public int sameValue() throws CloneNotSupportedException {
239.57 + Clnbl orig = new Clnbl();
239.58 + orig.value = 10;
239.59 + return ((Clnbl)orig.clone()).value;
239.60 + }
239.61 +
239.62 + @Factory
239.63 + public static Object[] create() {
239.64 + return VMTest.create(CloneTest.class);
239.65 + }
239.66 +
239.67 + public static final class Clnbl implements Cloneable {
239.68 + public CloneTest ref;
239.69 + private int value;
239.70 +
239.71 + @Override
239.72 + public Object clone() throws CloneNotSupportedException {
239.73 + return super.clone();
239.74 + }
239.75 + }
239.76 +}
240.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
240.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareByteArrayTest.java Wed Jan 23 20:16:48 2013 +0100
240.3 @@ -0,0 +1,93 @@
240.4 +/**
240.5 + * Back 2 Browser Bytecode Translator
240.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
240.7 + *
240.8 + * This program is free software: you can redistribute it and/or modify
240.9 + * it under the terms of the GNU General Public License as published by
240.10 + * the Free Software Foundation, version 2 of the License.
240.11 + *
240.12 + * This program is distributed in the hope that it will be useful,
240.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
240.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
240.15 + * GNU General Public License for more details.
240.16 + *
240.17 + * You should have received a copy of the GNU General Public License
240.18 + * along with this program. Look for COPYING file in the top folder.
240.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
240.20 + */
240.21 +package org.apidesign.bck2brwsr.tck;
240.22 +
240.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
240.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
240.25 +import org.testng.annotations.Factory;
240.26 +
240.27 +/**
240.28 + *
240.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
240.30 + */
240.31 +public class CompareByteArrayTest {
240.32 + @Compare public int byteArraySum() {
240.33 + byte[] arr = createArray();
240.34 + return sumByteArr(arr);
240.35 + }
240.36 +
240.37 + @Compare public int countZeros() {
240.38 + int zeros = 0;
240.39 + for (Byte b : createArray()) {
240.40 + if (b == 0) {
240.41 + zeros++;
240.42 + }
240.43 + }
240.44 + return zeros;
240.45 + }
240.46 +
240.47 + private static int sumByteArr(byte[] arr) {
240.48 + int sum = 0;
240.49 + for (int i = 0; i < arr.length; i++) {
240.50 + sum += arr[i];
240.51 + }
240.52 + return sum;
240.53 + }
240.54 +
240.55 + @Compare public String noOutOfBounds() {
240.56 + return atIndex(1);
240.57 + }
240.58 +
240.59 + @Compare public String outOfBounds() {
240.60 + return atIndex(5);
240.61 + }
240.62 +
240.63 + @Compare public String outOfBoundsMinus() {
240.64 + return atIndex(-1);
240.65 + }
240.66 +
240.67 + @Compare public String toOfBounds() {
240.68 + return toIndex(5);
240.69 + }
240.70 +
240.71 + @Compare public String toOfBoundsMinus() {
240.72 + return toIndex(-1);
240.73 + }
240.74 +
240.75 + private static final int[] arr = { 0, 1, 2 };
240.76 + public static String atIndex(int at) {
240.77 + return "at@" + arr[at];
240.78 + }
240.79 + public static String toIndex(int at) {
240.80 + arr[at] = 10;
240.81 + return "ok";
240.82 + }
240.83 +
240.84 +
240.85 + @Factory
240.86 + public static Object[] create() {
240.87 + return VMTest.create(CompareByteArrayTest.class);
240.88 + }
240.89 +
240.90 + private byte[] createArray() {
240.91 + byte[] arr = new byte[10];
240.92 + arr[5] = 3;
240.93 + arr[7] = 8;
240.94 + return arr;
240.95 + }
240.96 +}
241.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
241.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareHashTest.java Wed Jan 23 20:16:48 2013 +0100
241.3 @@ -0,0 +1,50 @@
241.4 +/**
241.5 + * Back 2 Browser Bytecode Translator
241.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
241.7 + *
241.8 + * This program is free software: you can redistribute it and/or modify
241.9 + * it under the terms of the GNU General Public License as published by
241.10 + * the Free Software Foundation, version 2 of the License.
241.11 + *
241.12 + * This program is distributed in the hope that it will be useful,
241.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
241.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
241.15 + * GNU General Public License for more details.
241.16 + *
241.17 + * You should have received a copy of the GNU General Public License
241.18 + * along with this program. Look for COPYING file in the top folder.
241.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
241.20 + */
241.21 +package org.apidesign.bck2brwsr.tck;
241.22 +
241.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
241.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
241.25 +import org.testng.annotations.Factory;
241.26 +
241.27 +/**
241.28 + *
241.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
241.30 + */
241.31 +public class CompareHashTest {
241.32 + @Compare public int hashOfString() {
241.33 + return "Ahoj".hashCode();
241.34 + }
241.35 +
241.36 + @Compare public int hashRemainsYieldsZero() {
241.37 + Object o = new Object();
241.38 + return o.hashCode() - o.hashCode();
241.39 + }
241.40 +
241.41 + @Compare public int initializeInStatic() {
241.42 + return StaticUse.NON_NULL.hashCode() - StaticUse.NON_NULL.hashCode();
241.43 + }
241.44 +
241.45 + @Compare public int hashOfInt() {
241.46 + return Integer.valueOf(Integer.MAX_VALUE).hashCode();
241.47 + }
241.48 +
241.49 + @Factory
241.50 + public static Object[] create() {
241.51 + return VMTest.create(CompareHashTest.class);
241.52 + }
241.53 +}
242.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
242.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareIntArrayTest.java Wed Jan 23 20:16:48 2013 +0100
242.3 @@ -0,0 +1,63 @@
242.4 +/**
242.5 + * Back 2 Browser Bytecode Translator
242.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
242.7 + *
242.8 + * This program is free software: you can redistribute it and/or modify
242.9 + * it under the terms of the GNU General Public License as published by
242.10 + * the Free Software Foundation, version 2 of the License.
242.11 + *
242.12 + * This program is distributed in the hope that it will be useful,
242.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
242.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
242.15 + * GNU General Public License for more details.
242.16 + *
242.17 + * You should have received a copy of the GNU General Public License
242.18 + * along with this program. Look for COPYING file in the top folder.
242.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
242.20 + */
242.21 +package org.apidesign.bck2brwsr.tck;
242.22 +
242.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
242.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
242.25 +import org.testng.annotations.Factory;
242.26 +
242.27 +/**
242.28 + *
242.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
242.30 + */
242.31 +public class CompareIntArrayTest {
242.32 + @Compare public int integerArraySum() {
242.33 + int[] arr = createArray();
242.34 + return sumIntArr(arr);
242.35 + }
242.36 +
242.37 + @Compare public int countZeros() {
242.38 + int zeros = 0;
242.39 + for (Integer i : createArray()) {
242.40 + if (i == 0) {
242.41 + zeros++;
242.42 + }
242.43 + }
242.44 + return zeros;
242.45 + }
242.46 +
242.47 + private static int sumIntArr(int[] arr) {
242.48 + int sum = 0;
242.49 + for (int i = 0; i < arr.length; i++) {
242.50 + sum += arr[i];
242.51 + }
242.52 + return sum;
242.53 + }
242.54 +
242.55 + @Factory
242.56 + public static Object[] create() {
242.57 + return VMTest.create(CompareIntArrayTest.class);
242.58 + }
242.59 +
242.60 + private int[] createArray() {
242.61 + int[] arr = new int[10];
242.62 + arr[5] = 3;
242.63 + arr[7] = 8;
242.64 + return arr;
242.65 + }
242.66 +}
243.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
243.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareStringsTest.java Wed Jan 23 20:16:48 2013 +0100
243.3 @@ -0,0 +1,133 @@
243.4 +/**
243.5 + * Back 2 Browser Bytecode Translator
243.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
243.7 + *
243.8 + * This program is free software: you can redistribute it and/or modify
243.9 + * it under the terms of the GNU General Public License as published by
243.10 + * the Free Software Foundation, version 2 of the License.
243.11 + *
243.12 + * This program is distributed in the hope that it will be useful,
243.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
243.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
243.15 + * GNU General Public License for more details.
243.16 + *
243.17 + * You should have received a copy of the GNU General Public License
243.18 + * along with this program. Look for COPYING file in the top folder.
243.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
243.20 + */
243.21 +package org.apidesign.bck2brwsr.tck;
243.22 +
243.23 +import java.net.MalformedURLException;
243.24 +import java.net.URL;
243.25 +import org.apidesign.bck2brwsr.vmtest.Compare;
243.26 +import org.apidesign.bck2brwsr.vmtest.VMTest;
243.27 +import org.testng.annotations.Factory;
243.28 +
243.29 +/**
243.30 + *
243.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
243.32 + */
243.33 +public class CompareStringsTest {
243.34 + @Compare public String firstChar() {
243.35 + return "" + ("Hello".toCharArray()[0]);
243.36 + }
243.37 +
243.38 + @Compare public String classCast() {
243.39 + Object o = firstChar();
243.40 + return String.class.cast(o);
243.41 + }
243.42 +
243.43 + @Compare public String classCastThrown() {
243.44 + Object o = null;
243.45 + return String.class.cast(o);
243.46 + }
243.47 +
243.48 + @Compare public boolean equalToNull() {
243.49 + return "Ahoj".equals(null);
243.50 + }
243.51 +
243.52 + @Compare public static Object compareURLs() throws MalformedURLException {
243.53 + return new URL("http://apidesign.org:8080/wiki/").toExternalForm().toString();
243.54 + }
243.55 +
243.56 + @Compare public String deleteLastTwoCharacters() {
243.57 + StringBuilder sb = new StringBuilder();
243.58 + sb.append("453.0");
243.59 + if (sb.toString().endsWith(".0")) {
243.60 + final int l = sb.length();
243.61 + sb.delete(l - 2, l);
243.62 + }
243.63 + return sb.toString().toString();
243.64 + }
243.65 +
243.66 + @Compare public String nameOfStringClass() throws Exception {
243.67 + return Class.forName("java.lang.String").getName();
243.68 + }
243.69 + @Compare public String nameOfArrayClass() throws Exception {
243.70 + return Class.forName("org.apidesign.bck2brwsr.tck.CompareHashTest").getName();
243.71 + }
243.72 +
243.73 + @Compare public String lowerHello() {
243.74 + return "HeLlO".toLowerCase();
243.75 + }
243.76 +
243.77 + @Compare public String lowerA() {
243.78 + return String.valueOf(Character.toLowerCase('A')).toString();
243.79 + }
243.80 + @Compare public String upperHello() {
243.81 + return "hello".toUpperCase();
243.82 + }
243.83 +
243.84 + @Compare public String upperA() {
243.85 + return String.valueOf(Character.toUpperCase('a')).toString();
243.86 + }
243.87 +
243.88 + @Compare public boolean matchRegExp() throws Exception {
243.89 + return "58038503".matches("\\d*");
243.90 + }
243.91 +
243.92 + @Compare public boolean doesNotMatchRegExp() throws Exception {
243.93 + return "58038503GH".matches("\\d*");
243.94 + }
243.95 +
243.96 + @Compare public boolean doesNotMatchRegExpFully() throws Exception {
243.97 + return "Hello".matches("Hell");
243.98 + }
243.99 +
243.100 + @Compare public String emptyCharArray() {
243.101 + char[] arr = new char[10];
243.102 + return new String(arr);
243.103 + }
243.104 +
243.105 + @Compare public String variousCharacterTests() throws Exception {
243.106 + StringBuilder sb = new StringBuilder();
243.107 +
243.108 + sb.append(Character.isUpperCase('a'));
243.109 + sb.append(Character.isUpperCase('A'));
243.110 + sb.append(Character.isLowerCase('a'));
243.111 + sb.append(Character.isLowerCase('A'));
243.112 +
243.113 + sb.append(Character.isLetter('A'));
243.114 + sb.append(Character.isLetterOrDigit('9'));
243.115 + sb.append(Character.isLetterOrDigit('A'));
243.116 + sb.append(Character.isLetter('0'));
243.117 +
243.118 + return sb.toString().toString();
243.119 + }
243.120 +
243.121 + @Compare
243.122 + public String nullFieldInitialized() {
243.123 + NullField nf = new NullField();
243.124 + return ("" + nf.name).toString();
243.125 + }
243.126 +
243.127 + @Factory
243.128 + public static Object[] create() {
243.129 + return VMTest.create(CompareStringsTest.class);
243.130 + }
243.131 +
243.132 + private static final class NullField {
243.133 +
243.134 + String name;
243.135 + }
243.136 +}
244.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
244.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/IntegerArithmeticTest.java Wed Jan 23 20:16:48 2013 +0100
244.3 @@ -0,0 +1,108 @@
244.4 +/**
244.5 + * Back 2 Browser Bytecode Translator
244.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
244.7 + *
244.8 + * This program is free software: you can redistribute it and/or modify
244.9 + * it under the terms of the GNU General Public License as published by
244.10 + * the Free Software Foundation, version 2 of the License.
244.11 + *
244.12 + * This program is distributed in the hope that it will be useful,
244.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
244.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
244.15 + * GNU General Public License for more details.
244.16 + *
244.17 + * You should have received a copy of the GNU General Public License
244.18 + * along with this program. Look for COPYING file in the top folder.
244.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
244.20 + */
244.21 +package org.apidesign.bck2brwsr.tck;
244.22 +
244.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
244.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
244.25 +import org.testng.annotations.Factory;
244.26 +
244.27 +/**
244.28 + *
244.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
244.30 + */
244.31 +public class IntegerArithmeticTest {
244.32 +
244.33 + private static int add(int x, int y) {
244.34 + return x + y;
244.35 + }
244.36 +
244.37 + private static int sub(int x, int y) {
244.38 + return x - y;
244.39 + }
244.40 +
244.41 + private static int mul(int x, int y) {
244.42 + return x * y;
244.43 + }
244.44 +
244.45 + private static int div(int x, int y) {
244.46 + return x / y;
244.47 + }
244.48 +
244.49 + private static int mod(int x, int y) {
244.50 + return x % y;
244.51 + }
244.52 +
244.53 + @Compare public int addOverflow() {
244.54 + return add(Integer.MAX_VALUE, 1);
244.55 + }
244.56 +
244.57 + @Compare public int subUnderflow() {
244.58 + return sub(Integer.MIN_VALUE, 1);
244.59 + }
244.60 +
244.61 + @Compare public int addMaxIntAndMaxInt() {
244.62 + return add(Integer.MAX_VALUE, Integer.MAX_VALUE);
244.63 + }
244.64 +
244.65 + @Compare public int subMinIntAndMinInt() {
244.66 + return sub(Integer.MIN_VALUE, Integer.MIN_VALUE);
244.67 + }
244.68 +
244.69 + @Compare public int multiplyMaxInt() {
244.70 + return mul(Integer.MAX_VALUE, 2);
244.71 + }
244.72 +
244.73 + @Compare public int multiplyMaxIntAndMaxInt() {
244.74 + return mul(Integer.MAX_VALUE, Integer.MAX_VALUE);
244.75 + }
244.76 +
244.77 + @Compare public int multiplyMinInt() {
244.78 + return mul(Integer.MIN_VALUE, 2);
244.79 + }
244.80 +
244.81 + @Compare public int multiplyMinIntAndMinInt() {
244.82 + return mul(Integer.MIN_VALUE, Integer.MIN_VALUE);
244.83 + }
244.84 +
244.85 + @Compare public int multiplyPrecision() {
244.86 + return mul(119106029, 1103515245);
244.87 + }
244.88 +
244.89 + @Compare public int division() {
244.90 + return div(1, 2);
244.91 + }
244.92 +
244.93 + @Compare public int divisionReminder() {
244.94 + return mod(1, 2);
244.95 + }
244.96 +
244.97 + @Compare public int sumTwoDimensions() {
244.98 + int[][] matrix = createMatrix(4, 3);
244.99 + matrix[0][0] += 10;
244.100 + return matrix[0][0];
244.101 + }
244.102 +
244.103 + static int[][] createMatrix(int x, int y) {
244.104 + return new int[x][y];
244.105 + }
244.106 +
244.107 + @Factory
244.108 + public static Object[] create() {
244.109 + return VMTest.create(IntegerArithmeticTest.class);
244.110 + }
244.111 +}
245.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
245.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionArrayTest.java Wed Jan 23 20:16:48 2013 +0100
245.3 @@ -0,0 +1,135 @@
245.4 +/**
245.5 + * Back 2 Browser Bytecode Translator
245.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
245.7 + *
245.8 + * This program is free software: you can redistribute it and/or modify
245.9 + * it under the terms of the GNU General Public License as published by
245.10 + * the Free Software Foundation, version 2 of the License.
245.11 + *
245.12 + * This program is distributed in the hope that it will be useful,
245.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
245.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
245.15 + * GNU General Public License for more details.
245.16 + *
245.17 + * You should have received a copy of the GNU General Public License
245.18 + * along with this program. Look for COPYING file in the top folder.
245.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
245.20 + */
245.21 +package org.apidesign.bck2brwsr.tck;
245.22 +
245.23 +import java.lang.reflect.Array;
245.24 +import org.apidesign.bck2brwsr.vmtest.Compare;
245.25 +import org.apidesign.bck2brwsr.vmtest.VMTest;
245.26 +import org.testng.annotations.Factory;
245.27 +
245.28 +/**
245.29 + *
245.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
245.31 + */
245.32 +public class ReflectionArrayTest {
245.33 + @Compare public int lengthOfStringArray() {
245.34 + String[] arr = (String[]) Array.newInstance(String.class, 10);
245.35 + return arr.length;
245.36 + }
245.37 +
245.38 + @Compare public int reflectiveLengthOfStringArray() {
245.39 + Object arr = Array.newInstance(String.class, 10);
245.40 + return Array.getLength(arr);
245.41 + }
245.42 +
245.43 + @Compare public int reflectiveLengthOneNonArray() {
245.44 + Object arr = "non-array";
245.45 + return Array.getLength(arr);
245.46 + }
245.47 +
245.48 + @Compare public String compTypeOfStringArray() {
245.49 + String[] arr = (String[]) Array.newInstance(String.class, 10);
245.50 + return arr.getClass().getComponentType().getName();
245.51 + }
245.52 +
245.53 + @Compare public Object negativeArrayExcp() {
245.54 + return Array.newInstance(String.class, -5);
245.55 + }
245.56 +
245.57 + @Compare public int lengthOfIntArray() {
245.58 + int[] arr = (int[]) Array.newInstance(Integer.TYPE, 10);
245.59 + return arr.length;
245.60 + }
245.61 +
245.62 + @Compare public int reflectiveLengthOfIntArray() {
245.63 + Object arr = Array.newInstance(Integer.TYPE, 10);
245.64 + return Array.getLength(arr);
245.65 + }
245.66 +
245.67 + @Compare public String compTypeOfIntArray() {
245.68 + int[] arr = (int[]) Array.newInstance(int.class, 10);
245.69 + return arr.getClass().getComponentType().getName();
245.70 + }
245.71 +
245.72 + @Compare public Object intNegativeArrayExcp() {
245.73 + return Array.newInstance(int.class, -5);
245.74 + }
245.75 +
245.76 + @Compare public Integer verifyAutobox() {
245.77 + int[] arr = (int[]) Array.newInstance(int.class, 5);
245.78 + return (Integer) Array.get(arr, 0);
245.79 + }
245.80 + @Compare public String verifyObjectArray() {
245.81 + String[] arr = (String[]) Array.newInstance(String.class, 5);
245.82 + Array.set(arr, 0, "Hello");
245.83 + return (String) Array.get(arr, 0);
245.84 + }
245.85 + @Compare public int verifyInt() {
245.86 + int[] arr = (int[]) Array.newInstance(int.class, 5);
245.87 + return Array.getInt(arr, 0);
245.88 + }
245.89 + @Compare public long verifyConvertToLong() {
245.90 + int[] arr = (int[]) Array.newInstance(int.class, 5);
245.91 + return Array.getLong(arr, 0);
245.92 + }
245.93 +
245.94 + @Compare public Object verifySetIntToObject() {
245.95 + try {
245.96 + Object[] arr = (Object[]) Array.newInstance(Object.class, 5);
245.97 + Array.setInt(arr, 0, 10);
245.98 + return Array.get(arr, 0);
245.99 + } catch (Exception exception) {
245.100 + return exception.getClass().getName();
245.101 + }
245.102 + }
245.103 + @Compare public long verifySetShort() {
245.104 + int[] arr = (int[]) Array.newInstance(int.class, 5);
245.105 + Array.setShort(arr, 0, (short)10);
245.106 + return Array.getLong(arr, 0);
245.107 + }
245.108 + @Compare public long verifyCantSetLong() {
245.109 + int[] arr = (int[]) Array.newInstance(int.class, 5);
245.110 + Array.setLong(arr, 0, 10);
245.111 + return Array.getLong(arr, 0);
245.112 + }
245.113 + @Compare public float verifyLongToFloat() {
245.114 + Object arr = Array.newInstance(float.class, 5);
245.115 + Array.setLong(arr, 0, 10);
245.116 + return Array.getFloat(arr, 0);
245.117 + }
245.118 +
245.119 + @Compare public double verifyConvertToDouble() {
245.120 + int[] arr = (int[]) Array.newInstance(int.class, 5);
245.121 + return Array.getDouble(arr, 0);
245.122 + }
245.123 +
245.124 + @Compare public int multiIntArray() {
245.125 + int[][][] arr = (int[][][]) Array.newInstance(int.class, 3, 3, 3);
245.126 + return arr[0][1][2] + 5 + arr[2][2][0];
245.127 + }
245.128 +
245.129 + @Compare public String multiIntArrayCompType() {
245.130 + return Array.newInstance(int.class, 3, 3, 3).getClass().getName();
245.131 + }
245.132 +
245.133 +
245.134 + @Factory
245.135 + public static Object[] create() {
245.136 + return VMTest.create(ReflectionArrayTest.class);
245.137 + }
245.138 +}
246.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
246.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionTest.java Wed Jan 23 20:16:48 2013 +0100
246.3 @@ -0,0 +1,192 @@
246.4 +/**
246.5 + * Back 2 Browser Bytecode Translator
246.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
246.7 + *
246.8 + * This program is free software: you can redistribute it and/or modify
246.9 + * it under the terms of the GNU General Public License as published by
246.10 + * the Free Software Foundation, version 2 of the License.
246.11 + *
246.12 + * This program is distributed in the hope that it will be useful,
246.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
246.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
246.15 + * GNU General Public License for more details.
246.16 + *
246.17 + * You should have received a copy of the GNU General Public License
246.18 + * along with this program. Look for COPYING file in the top folder.
246.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
246.20 + */
246.21 +package org.apidesign.bck2brwsr.tck;
246.22 +
246.23 +import java.lang.reflect.Method;
246.24 +import java.util.Arrays;
246.25 +import java.util.Collections;
246.26 +import java.util.List;
246.27 +import java.util.logging.Level;
246.28 +import java.util.logging.Logger;
246.29 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
246.30 +import org.apidesign.bck2brwsr.vmtest.Compare;
246.31 +import org.apidesign.bck2brwsr.vmtest.VMTest;
246.32 +import org.testng.annotations.Factory;
246.33 +
246.34 +/**
246.35 + *
246.36 + * @author Jaroslav Tulach <jtulach@netbeans.org>
246.37 + */
246.38 +public class ReflectionTest {
246.39 + @Compare public boolean nonNullThis() {
246.40 + return this == null;
246.41 + }
246.42 +
246.43 + @Compare public String intType() {
246.44 + return Integer.TYPE.toString();
246.45 + }
246.46 +
246.47 + @Compare public String voidType() throws Exception {
246.48 + return void.class.toString();
246.49 + }
246.50 +
246.51 + @Compare public String longClass() {
246.52 + return long.class.toString();
246.53 + }
246.54 +
246.55 + @Compare public String namesOfMethods() {
246.56 + StringBuilder sb = new StringBuilder();
246.57 + String[] arr = new String[20];
246.58 + int i = 0;
246.59 + for (Method m : StaticUse.class.getMethods()) {
246.60 + arr[i++] = m.getName();
246.61 + }
246.62 + for (String s : sort(arr, i)) {
246.63 + sb.append(s).append("\n");
246.64 + }
246.65 + return sb.toString();
246.66 + }
246.67 +
246.68 + @Compare public String cannotCallNonStaticMethodWithNull() throws Exception {
246.69 + StaticUse.class.getMethod("instanceMethod").invoke(null);
246.70 + return "should not happen";
246.71 + }
246.72 +
246.73 + @Compare public Object voidReturnType() throws Exception {
246.74 + return StaticUse.class.getMethod("instanceMethod").getReturnType();
246.75 + }
246.76 +
246.77 + @Compare public String newInstanceFails() throws InstantiationException {
246.78 + try {
246.79 + return "success: " + StaticUse.class.newInstance();
246.80 + } catch (IllegalAccessException ex) {
246.81 + return ex.getClass().getName();
246.82 + }
246.83 + }
246.84 +
246.85 + @Compare public String paramTypes() throws Exception {
246.86 + Method plus = StaticUse.class.getMethod("plus", int.class, Integer.TYPE);
246.87 + final Class[] pt = plus.getParameterTypes();
246.88 + return pt[0].getName();
246.89 + }
246.90 + @Compare public String paramTypesNotFound() throws Exception {
246.91 + return StaticUse.class.getMethod("plus", int.class, double.class).toString();
246.92 + }
246.93 + @Compare public int methodWithArgs() throws Exception {
246.94 + Method plus = StaticUse.class.getMethod("plus", int.class, Integer.TYPE);
246.95 + return (Integer)plus.invoke(null, 2, 3);
246.96 + }
246.97 +
246.98 + @Compare public String classGetNameForByte() {
246.99 + return byte.class.getName();
246.100 + }
246.101 + @Compare public String classGetNameForBaseObject() {
246.102 + return newObject().getClass().getName();
246.103 + }
246.104 + @Compare public String classGetNameForJavaObject() {
246.105 + return new Object().getClass().getName();
246.106 + }
246.107 + @Compare public String classGetNameForObjectArray() {
246.108 + return (new Object[3]).getClass().getName();
246.109 + }
246.110 + @Compare public String classGetNameForSimpleIntArray() {
246.111 + return (new int[3]).getClass().getName();
246.112 + }
246.113 + @Compare public boolean sameClassGetNameForSimpleCharArray() {
246.114 + return (new char[3]).getClass() == (new char[34]).getClass();
246.115 + }
246.116 + @Compare public String classGetNameForMultiIntArray() {
246.117 + return (new int[3][4][5][6][7][8][9]).getClass().getName();
246.118 + }
246.119 + @Compare public String classGetNameForMultiIntArrayInner() {
246.120 + final int[][][][][][][] arr = new int[3][4][5][6][7][8][9];
246.121 + int[][][][][][] subarr = arr[0];
246.122 + int[][][][][] subsubarr = subarr[0];
246.123 + return subsubarr.getClass().getName();
246.124 + }
246.125 + @Compare public String classGetNameForMultiStringArray() {
246.126 + return (new String[3][4][5][6][7][8][9]).getClass().getName();
246.127 + }
246.128 +
246.129 + @Compare public String classForByte() throws Exception {
246.130 + return Class.forName("[Z").getName();
246.131 + }
246.132 +
246.133 + @Compare public String classForUnknownArray() {
246.134 + try {
246.135 + return Class.forName("[W").getName();
246.136 + } catch (Exception ex) {
246.137 + return ex.getClass().getName();
246.138 + }
246.139 + }
246.140 +
246.141 + @Compare public String classForUnknownDeepArray() {
246.142 + try {
246.143 + return Class.forName("[[[[[W").getName();
246.144 + } catch (Exception ex) {
246.145 + return ex.getClass().getName();
246.146 + }
246.147 + }
246.148 +
246.149 + @Compare public String componentGetNameForObjectArray() {
246.150 + return (new Object[3]).getClass().getComponentType().getName();
246.151 + }
246.152 + @Compare public boolean sameComponentGetNameForObjectArray() {
246.153 + return (new Object[3]).getClass().getComponentType() == Object.class;
246.154 + }
246.155 + @Compare public String componentGetNameForSimpleIntArray() {
246.156 + return (new int[3]).getClass().getComponentType().getName();
246.157 + }
246.158 + @Compare public String componentGetNameForMultiIntArray() {
246.159 + return (new int[3][4][5][6][7][8][9]).getClass().getComponentType().getName();
246.160 + }
246.161 + @Compare public String componentGetNameForMultiStringArray() {
246.162 + Class<?> c = (new String[3][4][5][6][7][8][9]).getClass();
246.163 + StringBuilder sb = new StringBuilder();
246.164 + for (;;) {
246.165 + sb.append(c.getName()).append("\n");
246.166 + c = c.getComponentType();
246.167 + if (c == null) {
246.168 + break;
246.169 + }
246.170 + }
246.171 + return sb.toString();
246.172 + }
246.173 +
246.174 + @Compare public boolean isArray() {
246.175 + return new Object[0].getClass().isArray();
246.176 + }
246.177 +
246.178 + @JavaScriptBody(args = { "arr", "len" }, body="var a = arr.slice(0, len); a.sort(); return a;")
246.179 + private static String[] sort(String[] arr, int len) {
246.180 + List<String> list = Arrays.asList(arr).subList(0, len);
246.181 + Collections.sort(list);
246.182 + return list.toArray(new String[0]);
246.183 + }
246.184 +
246.185 + @JavaScriptBody(args = {}, body = "return new Object();")
246.186 + private static Object newObject() {
246.187 + return new Object();
246.188 + }
246.189 +
246.190 + @Factory
246.191 + public static Object[] create() {
246.192 + return VMTest.create(ReflectionTest.class);
246.193 + }
246.194 +
246.195 +}
247.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
247.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ResourcesTest.java Wed Jan 23 20:16:48 2013 +0100
247.3 @@ -0,0 +1,45 @@
247.4 +/**
247.5 + * Back 2 Browser Bytecode Translator
247.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
247.7 + *
247.8 + * This program is free software: you can redistribute it and/or modify
247.9 + * it under the terms of the GNU General Public License as published by
247.10 + * the Free Software Foundation, version 2 of the License.
247.11 + *
247.12 + * This program is distributed in the hope that it will be useful,
247.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
247.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
247.15 + * GNU General Public License for more details.
247.16 + *
247.17 + * You should have received a copy of the GNU General Public License
247.18 + * along with this program. Look for COPYING file in the top folder.
247.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
247.20 + */
247.21 +package org.apidesign.bck2brwsr.tck;
247.22 +
247.23 +import java.io.InputStream;
247.24 +import org.apidesign.bck2brwsr.vmtest.Compare;
247.25 +import org.apidesign.bck2brwsr.vmtest.VMTest;
247.26 +import org.testng.annotations.Factory;
247.27 +
247.28 +/**
247.29 + *
247.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
247.31 + */
247.32 +public class ResourcesTest {
247.33 +
247.34 + @Compare public String readResourceAsStream() throws Exception {
247.35 + InputStream is = getClass().getResourceAsStream("Resources.txt");
247.36 + byte[] b = new byte[30];
247.37 + int len = is.read(b);
247.38 + StringBuilder sb = new StringBuilder();
247.39 + for (int i = 0; i < len; i++) {
247.40 + sb.append((char)b[i]);
247.41 + }
247.42 + return sb.toString();
247.43 + }
247.44 +
247.45 + @Factory public static Object[] create() {
247.46 + return VMTest.create(ResourcesTest.class);
247.47 + }
247.48 +}
248.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
248.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ShortArithmeticTest.java Wed Jan 23 20:16:48 2013 +0100
248.3 @@ -0,0 +1,102 @@
248.4 +/**
248.5 + * Back 2 Browser Bytecode Translator
248.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
248.7 + *
248.8 + * This program is free software: you can redistribute it and/or modify
248.9 + * it under the terms of the GNU General Public License as published by
248.10 + * the Free Software Foundation, version 2 of the License.
248.11 + *
248.12 + * This program is distributed in the hope that it will be useful,
248.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
248.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
248.15 + * GNU General Public License for more details.
248.16 + *
248.17 + * You should have received a copy of the GNU General Public License
248.18 + * along with this program. Look for COPYING file in the top folder.
248.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
248.20 + */
248.21 +package org.apidesign.bck2brwsr.tck;
248.22 +
248.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
248.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
248.25 +import org.testng.annotations.Factory;
248.26 +
248.27 +/**
248.28 + *
248.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
248.30 + */
248.31 +public class ShortArithmeticTest {
248.32 +
248.33 + private static short add(short x, short y) {
248.34 + return (short)(x + y);
248.35 + }
248.36 +
248.37 + private static short sub(short x, short y) {
248.38 + return (short)(x - y);
248.39 + }
248.40 +
248.41 + private static short mul(short x, short y) {
248.42 + return (short)(x * y);
248.43 + }
248.44 +
248.45 + private static short div(short x, short y) {
248.46 + return (short)(x / y);
248.47 + }
248.48 +
248.49 + private static short mod(short x, short y) {
248.50 + return (short)(x % y);
248.51 + }
248.52 +
248.53 + @Compare public short conversion() {
248.54 + return (short)123456;
248.55 + }
248.56 +
248.57 + @Compare public short addOverflow() {
248.58 + return add(Short.MAX_VALUE, (short)1);
248.59 + }
248.60 +
248.61 + @Compare public short subUnderflow() {
248.62 + return sub(Short.MIN_VALUE, (short)1);
248.63 + }
248.64 +
248.65 + @Compare public short addMaxShortAndMaxShort() {
248.66 + return add(Short.MAX_VALUE, Short.MAX_VALUE);
248.67 + }
248.68 +
248.69 + @Compare public short subMinShortAndMinShort() {
248.70 + return sub(Short.MIN_VALUE, Short.MIN_VALUE);
248.71 + }
248.72 +
248.73 + @Compare public short multiplyMaxShort() {
248.74 + return mul(Short.MAX_VALUE, (short)2);
248.75 + }
248.76 +
248.77 + @Compare public short multiplyMaxShortAndMaxShort() {
248.78 + return mul(Short.MAX_VALUE, Short.MAX_VALUE);
248.79 + }
248.80 +
248.81 + @Compare public short multiplyMinShort() {
248.82 + return mul(Short.MIN_VALUE, (short)2);
248.83 + }
248.84 +
248.85 + @Compare public short multiplyMinShortAndMinShort() {
248.86 + return mul(Short.MIN_VALUE, Short.MIN_VALUE);
248.87 + }
248.88 +
248.89 + @Compare public short multiplyPrecision() {
248.90 + return mul((short)17638, (short)1103);
248.91 + }
248.92 +
248.93 + @Compare public short division() {
248.94 + return div((short)1, (short)2);
248.95 + }
248.96 +
248.97 + @Compare public short divisionReminder() {
248.98 + return mod((short)1, (short)2);
248.99 + }
248.100 +
248.101 + @Factory
248.102 + public static Object[] create() {
248.103 + return VMTest.create(ShortArithmeticTest.class);
248.104 + }
248.105 +}
249.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
249.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/StaticUse.java Wed Jan 23 20:16:48 2013 +0100
249.3 @@ -0,0 +1,31 @@
249.4 +/**
249.5 + * Back 2 Browser Bytecode Translator
249.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
249.7 + *
249.8 + * This program is free software: you can redistribute it and/or modify
249.9 + * it under the terms of the GNU General Public License as published by
249.10 + * the Free Software Foundation, version 2 of the License.
249.11 + *
249.12 + * This program is distributed in the hope that it will be useful,
249.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
249.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
249.15 + * GNU General Public License for more details.
249.16 + *
249.17 + * You should have received a copy of the GNU General Public License
249.18 + * along with this program. Look for COPYING file in the top folder.
249.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
249.20 + */
249.21 +package org.apidesign.bck2brwsr.tck;
249.22 +
249.23 +class StaticUse {
249.24 + public static final Object NON_NULL = new Object();
249.25 + private StaticUse() {
249.26 + }
249.27 +
249.28 + public void instanceMethod() {
249.29 + }
249.30 +
249.31 + public static int plus(int a, int b) {
249.32 + return a + b;
249.33 + }
249.34 +}
250.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
250.2 +++ b/vmtest/src/test/resources/org/apidesign/bck2brwsr/tck/Resources.txt Wed Jan 23 20:16:48 2013 +0100
250.3 @@ -0,0 +1,1 @@
250.4 +Ahoj