├── .dukescript ├── .gitignore ├── LICENSE ├── README.md ├── libs ├── core │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ ├── lib.core.d.ts │ │ │ └── net │ │ │ │ └── java │ │ │ │ └── html │ │ │ │ └── lib │ │ │ │ ├── Array.java │ │ │ │ ├── CoreTypes.java │ │ │ │ ├── Error.java │ │ │ │ ├── Function.java │ │ │ │ ├── Modules.java │ │ │ │ ├── Objs.java │ │ │ │ └── Union.java │ │ └── resources │ │ │ └── net │ │ │ └── java │ │ │ └── html │ │ │ └── lib │ │ │ └── hjTypings.js │ │ └── test │ │ ├── java │ │ └── net │ │ │ └── java │ │ │ └── html │ │ │ └── lib │ │ │ ├── ArrayTest.java │ │ │ ├── FunctionTest.java │ │ │ └── LibCoreTest.java │ │ └── resources │ │ └── lib.core.sigtest └── dom │ ├── pom.xml │ └── src │ └── main │ └── java │ └── net │ └── java │ └── html │ └── lib │ └── dom │ └── lib.dom.d.ts ├── mojo-base ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── dukescript │ │ │ └── libraries │ │ │ └── proc │ │ │ ├── ASTCntrl.java │ │ │ ├── Generator.java │ │ │ ├── Parser.java │ │ │ ├── Resolver.java │ │ │ ├── SyntaxKind.java │ │ │ ├── TypeScript.java │ │ │ └── Visitor.java │ └── resources │ │ └── com │ │ └── dukescript │ │ └── libraries │ │ └── proc │ │ ├── app.js │ │ └── typescript.js │ └── test │ ├── java │ └── com │ │ └── dukescript │ │ └── libraries │ │ └── proc │ │ ├── ASTTest.java │ │ └── ParserTest.java │ └── resources │ └── com │ └── dukescript │ └── libraries │ └── proc │ └── lib.core.d.ts ├── mojo-test ├── pom.xml └── src │ ├── main │ └── resources │ │ └── com │ │ └── dukescript │ │ └── libraries │ │ └── ap │ │ └── test │ │ ├── arr │ │ ├── arr.js │ │ └── arr.ts │ │ ├── constructors │ │ ├── hello.js │ │ └── hello.ts │ │ ├── fn │ │ ├── fn.js │ │ └── fn.ts │ │ ├── hello │ │ ├── hello.js │ │ └── hello.ts │ │ └── ns │ │ ├── mod-amd.js │ │ └── mod.ts │ └── test │ └── java │ └── com │ └── dukescript │ └── libraries │ └── ap │ └── test │ ├── arr │ └── ArrTest.java │ ├── constructors │ └── DuplicateConstructorDefinitionsTest.java │ ├── fn │ └── FnTest.java │ ├── hello │ ├── HelloTest.java │ └── SingletonTest.java │ └── ns │ └── NamespaceTest.java ├── mojo ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── dukescript │ └── libraries │ └── proc │ └── GenerateTypings.java ├── pom.xml ├── src └── license │ └── header.txt └── typings ├── angular ├── pom.xml └── src │ ├── main │ └── java │ │ ├── angular.d.ts │ │ └── angular.sigtest │ └── test │ └── java │ └── com │ └── dukescript │ └── libraries │ └── angular │ └── AngularTest.java ├── jquery ├── pom.xml └── src │ ├── main │ └── java │ │ ├── jquery.d.ts │ │ └── jquery.sigtest │ └── test │ ├── java │ └── com │ │ └── dukescript │ │ └── libraries │ │ └── jquery │ │ └── JQueryTest.java │ └── resources │ └── com │ └── dukescript │ └── libraries │ └── jquery │ └── index.html ├── ko ├── pom.xml └── src │ ├── main │ └── java │ │ ├── knockout.d.ts │ │ └── ko.sigtest │ └── test │ └── java │ └── com │ └── dukescript │ └── libraries │ └── ko │ └── KnockoutTest.java ├── typings-testing └── pom.xml └── underscore ├── pom.xml ├── src └── test │ └── java │ └── com │ └── dukescript │ └── libraries │ └── underscore │ └── UnderscoreTest.java └── underscore.d.ts /.dukescript: -------------------------------------------------------------------------------- 1 | #!groovy 2 | 3 | node ('Mac') { 4 | stage('Build') { 5 | checkout scm 6 | 7 | jdk = tool name: 'JDK8u221' 8 | env.JAVA_HOME = "${jdk}" 9 | 10 | if (env.GPG_DIR) { 11 | env.PATH="${env.PATH}:${env.GPG_DIR}" 12 | } 13 | 14 | pom = readFile 'pom.xml' 15 | if (pom.contains('-SNAPSHOT')) { 16 | mvnargs='' 17 | } else { 18 | mvnargs='-DskipTests' 19 | } 20 | withMaven( 21 | maven : 'M3', 22 | mavenSettingsConfig : '1745afa9-9479-4838-b15d-14029f4cfc8d' 23 | ) { 24 | withCredentials([file(credentialsId: 'PRIVATE_KEY', variable: 'KEY')]) { 25 | sh "gpg --batch --import ${env.KEY}" 26 | sh "gpgconf --kill gpg-agent" 27 | sh "gpg-agent --daemon --allow-preset-passphrase --batch" 28 | if (env.GPG_PASSPHRASE) { 29 | withCredentials([usernamePassword(credentialsId: 'd0aa9e41-82e0-4562-bb67-b42364e8aa35', 30 | passwordVariable: 'GPG_PASSWD', usernameVariable: 'GPG_ID') 31 | ]) { 32 | sh "${env.GPG_PASSPHRASE} --preset --passphrase ${GPG_PASSWD} ${GPG_ID}" 33 | } 34 | } 35 | sh "mvn ${mvnargs} clean install -Prelease -Dgpg.useagent=true" 36 | sh "mvn -DskipTests deploy -Prelease -Dgpg.useagent=true" 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | pom.xml.tag 3 | pom.xml.releaseBackup 4 | pom.xml.versionsBackup 5 | pom.xml.next 6 | release.properties 7 | dependency-reduced-pom.xml 8 | buildNumber.properties 9 | .mvn/timing.properties 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Maven Typings Plugin 2 | 3 | Convert any [TypeScript Definition](https://github.com/dukescript/definitelytyped) 4 | files into Java APIs that can be used everywhere thanks to 5 | [DukeScript presenters](https://github.com/dukescript/dukescript-presenters). 6 | 7 | Use the benefits of Java language (excellent tooling, strongly typed code, 8 | refactorings, etc.) and combine them with the dynamics of JavaScript libraries. 9 | Get the best of both worlds! 10 | 11 | ## How can I use the Plugin? 12 | 13 | Find your typings file (you can choose any from more than 1500 available 14 | in [DukeScript Definitely Typed](https://github.com/dukescript/definitelytyped) repository) 15 | and add following into your `pom.xml` file: 16 | 17 | ```xml 18 | 19 | com.dukescript.libraries 20 | typings-maven-plugin 21 | 0.2 22 | 23 | 24 | generate-sources 25 | 26 | generate 27 | 28 | 29 | 30 | 31 | path/to/your/typings.d.ts 32 | package.to.store.the.files.in 33 | 34 | 35 | 36 | net.java.html.lib.dom 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | ``` 46 | 47 | and that is it! The types and functions found in your typings file will 48 | be converted into Java classes and you can use them in your own applications. 49 | 50 | Alternatively you can contribute your typings *Java* conversions to everyone as described 51 | at [DukeScript DefinitelyTyped README](https://github.com/dukescript/DefinitelyTyped/blob/master/README.md). 52 | 53 | ## Are There any Typings Ready? 54 | 55 | Yes, the [DukeScript project](http://dukescript.com) has uploaded Java typings for 56 | the most popular JavaScript libraries to Maven. Check 57 | the [central repository](http://search.maven.org/#search|ga|1|net.java.html.lib) 58 | for current status. Visit the 59 | [DukeScript DefinitelyTyped](https://github.com/dukescript/DefinitelyTyped/blob/master/README.md) 60 | project for instructions how to use them. 61 | 62 | ## How Does it Work? 63 | 64 | There is the [Generator class](https://github.com/dukescript/maven-typings-plugin/blob/master/mojo-base/src/main/java/com/dukescript/libraries/proc/Generator.java) 65 | at the heart of the Maven typings plugin. It uses the JDK's scripting engine to start 66 | TypeScript parser (converted to JavaScript) and parse the provided typings file. 67 | Then it converts the result into Java 68 | [AST classes](https://github.com/dukescript/maven-typings-plugin/blob/master/mojo-base/src/main/java/com/dukescript/libraries/proc/ASTCntrl.java) 69 | generated by [@Model annotation](http://bits.netbeans.org/html+java/1.3/net/java/html/json/Model.html). 70 | Then the generator visits the tree of AST nodes 71 | and based on them generates appropriate Java source files. 72 | 73 | The generated 74 | code is using [@JavaScriptBody annotation](http://bits.netbeans.org/html+java/1.3/net/java/html/js/package-summary.html) 75 | which is extremely portable - the generated libraries are known to run 76 | in a JavaFX webview, in JDK's Nashorn, in a WebKit component, on Android, iOS 77 | and even directly in a browser. Find more info in 78 | [DukeScript presenters](https://github.com/dukescript/dukescript-presenters) 79 | project. 80 | 81 | Important part of the project is focus on quality. As such there are focused 82 | tests testing [various constructs](https://github.com/dukescript/maven-typings-plugin/tree/master/mojo-test/src/main/resources/com/dukescript/libraries/ap/test/hello) 83 | of the TypeScript language and whether they get properly 84 | [converted into Java](https://github.com/dukescript/maven-typings-plugin/blob/master/mojo-test/src/test/java/com/dukescript/libraries/ap/test/hello/HelloTest.java). 85 | The tests are executed with 86 | [JUnit Browser Runner](https://github.com/dukescript/junit-browser-runner) 87 | which is the most flexible way of running your tests in all supported 88 | environments. 89 | 90 | ## License 91 | 92 | The plugin is [GPLv3](https://github.com/dukescript/maven-typings-plugin/blob/master/LICENSE) 93 | licensed. Contribute to the development of the plugin by forking it on GitHub! 94 | 95 | You can use publicly available version of the Maven typings plugin to generate Java typings 96 | from any TypeScript typings file and publish the result under any license. 97 | For example the [DukeScript Definitely Typed](https://github.com/dukescript/DefinitelyTyped/blob/master/README.md) 98 | libraries are [MIT licensed](https://github.com/dukescript/DefinitelyTyped/blob/master/LICENSE). 99 | -------------------------------------------------------------------------------- /libs/core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 28 | 29 | 30 | 4.0.0 31 | 32 | com.dukescript.libraries 33 | pom 34 | 1.0-SNAPSHOT 35 | ../../ 36 | 37 | net.java.html.lib 38 | ES6 Core Library 39 | bundle 40 | 41 | net.java.html.lib 42 | 43 | 44 | 45 | 46 | org.apache.maven.plugins 47 | maven-javadoc-plugin 48 | 49 | false 50 | 51 | 52 | 53 | org.apache.maven.plugins 54 | maven-source-plugin 55 | 56 | 57 | com.dukescript.libraries 58 | typings-maven-plugin 59 | ${project.version} 60 | 61 | 62 | 63 | generate 64 | 65 | 66 | 67 | 68 | src/main/java/lib.core.d.ts 69 | net.java.html.lib 70 | 71 | 72 | 73 | org.apache.maven.plugins 74 | maven-compiler-plugin 75 | 2.5.1 76 | 77 | 1.8 78 | 1.8 79 | 80 | 81 | 82 | org.apache.felix 83 | maven-bundle-plugin 84 | 2.5.3 85 | true 86 | 87 | 88 | dependent 89 | ${publicPackages} 90 | 91 | 92 | 93 | 94 | org.netbeans.html 95 | html4j-maven-plugin 96 | ${net.java.html.version} 97 | 98 | 99 | js-classes 100 | 101 | process-js-annotations 102 | 103 | 104 | 105 | test-classes 106 | process-test-classes 107 | 108 | process-js-annotations 109 | 110 | 111 | ${project.build.directory}/test-classes 112 | 113 | 114 | 115 | 116 | 117 | org.netbeans.tools 118 | sigtest-maven-plugin 119 | 1.0 120 | 121 | 122 | sigtest-generated-classes 123 | 124 | check 125 | 126 | 127 | src/test/resources/lib.core.sigtest 128 | 129 | 130 | 131 | 132 | ${publicPackages} 133 | 134 | 135 | 136 | org.apache.maven.plugins 137 | maven-surefire-plugin 138 | 2.18.1 139 | 140 | 141 | 142 | 143 | 144 | org.netbeans.html 145 | net.java.html.boot 146 | ${net.java.html.version} 147 | compile 148 | 149 | 150 | 151 | com.dukescript.api 152 | junit-browser-runner 153 | 154 | 155 | 156 | 157 | 158 | org.netbeans.html 159 | net.java.html.boot.fx 160 | ${net.java.html.version} 161 | test 162 | 163 | 164 | 165 | 172 | 179 | 180 | 181 | 182 | org.apidesign.bck2brwsr 183 | launcher.http 184 | ${bck2brwsr.version} 185 | test 186 | 187 | 188 | org.apidesign.bck2brwsr 189 | emul 190 | ${bck2brwsr.version} 191 | rt 192 | test 193 | 194 | 195 | org.apidesign.bck2brwsr 196 | emul 197 | ${bck2brwsr.version} 198 | bck2brwsr 199 | test 200 | 201 | 202 | -------------------------------------------------------------------------------- /libs/core/src/main/java/net/java/html/lib/Error.java: -------------------------------------------------------------------------------- 1 | package net.java.html.lib; 2 | 3 | import java.lang.reflect.Type; 4 | 5 | /* 6 | * #%L 7 | * ES6 Core Library - a library from the DukeScript project. 8 | * Visit http://dukescript.com for support and commercial license. 9 | * %% 10 | * Copyright (C) 2015 - 2016 Dukehoff GmbH 11 | * %% 12 | * Permission is hereby granted, free of charge, to any person obtaining a copy 13 | * of this software and associated documentation files (the "Software"), to deal 14 | * in the Software without restriction, including without limitation the rights 15 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 16 | * copies of the Software, and to permit persons to whom the Software is 17 | * furnished to do so, subject to the following conditions: 18 | * 19 | * The above copyright notice and this permission notice shall be included in 20 | * all copies or substantial portions of the Software. 21 | * 22 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 27 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 28 | * THE SOFTWARE. 29 | * #L% 30 | */ 31 | public class Error extends net.java.html.lib.Objs { 32 | protected Error(Constructor> constructor, java.lang.Object js) { 33 | this(constructor, js, (Type[])null); 34 | } 35 | 36 | /** 37 | * @since 0.20 38 | */ 39 | protected Error(Constructor> constructor, java.lang.Object js, Type... typeParameters) { 40 | super(constructor, js, typeParameters); 41 | } 42 | 43 | /** 44 | * Casts given object to this class. 45 | * 46 | * @param obj any object 47 | * @return a view of the provided obj object 48 | */ 49 | public static Error $as(java.lang.Object obj) { 50 | return obj == null ? null : new Error($AS, obj); 51 | } 52 | /** 53 | * Function to cast given object to this class. Function that calls 54 | * {@link #$as(java.lang.Object)}. 55 | */ 56 | private static final Constructor $AS = new Constructor(Error.class) { 57 | @Override 58 | protected Error create(Object any) { 59 | return $as(any); 60 | } 61 | }; 62 | 63 | public Property name = Property.create(this, String.class, "name"); 64 | public Property message = Property.create(this, String.class, "message"); 65 | // constructor ErrorConstructor 66 | public static Error prototype = Error.$as(CoreTypes.readStaticFields$131()); 67 | public Error(java.lang.String message) { 68 | this($AS, CoreTypes.new$182(message)); 69 | } 70 | public Error() { 71 | this($AS, CoreTypes.new$183()); 72 | } 73 | public static Error newError(java.lang.String message) { 74 | return (Error)CoreTypes.newError$184(message); 75 | } 76 | public static Error newError() { 77 | return (Error)CoreTypes.newError$185(); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /libs/core/src/main/java/net/java/html/lib/Modules.java: -------------------------------------------------------------------------------- 1 | package net.java.html.lib; 2 | 3 | /* 4 | * #%L 5 | * ES6 Core Library - a library from the DukeScript project. 6 | * Visit http://dukescript.com for support and commercial license. 7 | * %% 8 | * Copyright (C) 2015 - 2016 Dukehoff GmbH 9 | * %% 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy 11 | * of this software and associated documentation files (the "Software"), to deal 12 | * in the Software without restriction, including without limitation the rights 13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | * copies of the Software, and to permit persons to whom the Software is 15 | * furnished to do so, subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be included in 18 | * all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 26 | * THE SOFTWARE. 27 | * #L% 28 | */ 29 | 30 | 31 | 32 | /** Support for integrating JavaScript modules. Whenever a typings module 33 | * needs to access its exports object, it uses the 34 | * {@link #find(java.lang.String)} method with the ID of the object to 35 | * search for. 36 | * 37 | * @since 0.4 38 | */ 39 | public final class Modules { 40 | 41 | private Modules() { 42 | } 43 | 44 | private static Provider loaders; 45 | 46 | /** Looks a JavaScript module by its id. 47 | * 48 | * @param id the string ID to search for 49 | * @return the JavaScript object or null 50 | * @since 0.4 51 | */ 52 | public static Objs find(String id) { 53 | Provider l = loaders; 54 | while (l != null) { 55 | Objs result = l.find(id); 56 | if (result != null) { 57 | return result; 58 | } 59 | l = l.next; 60 | } 61 | return null; 62 | } 63 | 64 | /** Register provide if you can look JavaScript modules by their names. 65 | * By subclassing and implementing the {@link #find(java.lang.String)} 66 | * method you can participate in lookup of module exports objects as 67 | * used by generated typings Exports classes. 68 | * @since 0.4 69 | */ 70 | public static abstract class Provider implements AutoCloseable { 71 | private Provider next; 72 | 73 | /** Constructor for subclasses. Once the provider is instantiated 74 | * it gets registered in the system and is available to answer 75 | * {@link Modules#find(java.lang.String)} queries. Use 76 | * {@link #close()} to unregister the provider. 77 | * @since 0.4 78 | */ 79 | protected Provider() { 80 | synchronized (Modules.class) { 81 | next = loaders; 82 | loaders = this; 83 | } 84 | } 85 | 86 | /** Seeks for a module with given id. 87 | * 88 | * @param id the id of the module to seek for 89 | * @return JavaScript object representing the module or null, 90 | * if this provider cannot resolve the module 91 | * @since 0.4 92 | */ 93 | protected abstract Objs find(String id); 94 | 95 | /** Unregisters this provider from the system. 96 | * @since 0.4 97 | */ 98 | @Override 99 | public final void close() { 100 | synchronized (Modules.class) { 101 | Provider l = loaders; 102 | if (l == this) { 103 | loaders = this.next; 104 | return; 105 | } 106 | while (l != null) { 107 | if (l.next == this) { 108 | l.next = this.next; 109 | break; 110 | } 111 | l = l.next; 112 | } 113 | } 114 | } 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /libs/core/src/main/java/net/java/html/lib/Union.java: -------------------------------------------------------------------------------- 1 | package net.java.html.lib; 2 | 3 | 4 | /* 5 | * #%L 6 | * DukeScript Libraries Processor - a library from the DukeScript project. 7 | * Visit http://dukescript.com for support and commercial license. 8 | * %% 9 | * Copyright (C) 2016 Eppleton IT Consulting 10 | * %% 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the "Software"), to deal 13 | * in the Software without restriction, including without limitation the rights 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | * copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | * THE SOFTWARE. 28 | * #L% 29 | */ 30 | 31 | import java.lang.reflect.Type; 32 | 33 | public abstract class Union extends Objs { 34 | Union(Object obj) { 35 | super($AS, obj); 36 | } 37 | 38 | private static Constructor $AS = new Constructor(Union.class) { 39 | @Override 40 | protected Union create(Object any) { 41 | return new Impl(any, Void.class, Void.class, Void.class, Void.class, Void.class); 42 | } 43 | 44 | @Override 45 | protected Union create(Object any, Type... typeParameters) { 46 | return new Impl(any, 47 | at(typeParameters, 0), 48 | at(typeParameters, 1), 49 | at(typeParameters, 2), 50 | at(typeParameters, 3), 51 | at(typeParameters, 4) 52 | ); 53 | } 54 | 55 | private Class> at(Type[] arr, int index) { 56 | if (arr != null && index < arr.length && arr[index] instanceof Class>) { 57 | return (Class>)arr[index]; 58 | } 59 | return Void.class; 60 | } 61 | }; 62 | 63 | /** Casts the value in this union to requested type. 64 | * 65 | * @param the requested type 66 | * @param type class of the requested type 67 | * @return value 68 | * @throws ClassCastException if the value cannot be cast 69 | */ 70 | public abstract T cast(Class type); 71 | 72 | /** 73 | * Checks if the current value can be casted to instance of given type. 74 | * 75 | * @param type the class to assign the value to 76 | * @return true, if it can be casted, false otherwise 77 | */ 78 | public abstract boolean instanceOf(Class> type); 79 | 80 | /** Creates a generic union with value, but no known types. 81 | * 82 | * @param value value for the union 83 | * @return a view of the provided obj object 84 | */ 85 | public static Union $as(Object value) { 86 | return $as(value, Void.class, Void.class, Void.class, Void.class, Void.class); 87 | } 88 | 89 | /** Creates an union for provided value and list of known types. 90 | * 91 | * @param type a 92 | * @param type b 93 | * @param value the actual value of the union 94 | * @param a class a 95 | * @param b class b 96 | * @return union that holds the value and all associated types 97 | */ 98 | public static Union.A2 $as(Object value, Class a, Class b) { 99 | return $as(value, a, b, Void.class, Void.class, Void.class); 100 | } 101 | 102 | /** Creates an union for provided value and list of known types. 103 | * 104 | * @param type a 105 | * @param type b 106 | * @param type c 107 | * @param value the actual value of the union 108 | * @param a class a 109 | * @param b class b 110 | * @param c class c 111 | * @return union that holds the value and all associated types 112 | */ 113 | public static Union.A3 $as(Object value, Class a, Class b, Class c) { 114 | return $as(value, a, b, c, Void.class, Void.class); 115 | } 116 | 117 | /** Creates an union for provided value and list of known types. 118 | * 119 | * @param type a 120 | * @param type b 121 | * @param type c 122 | * @param type d 123 | * @param value the actual value of the union 124 | * @param a class a 125 | * @param b class b 126 | * @param c class c 127 | * @param d class d 128 | * @return union that holds the value and all associated types 129 | */ 130 | public static Union.A4 $as(Object value, Class a, Class b, Class c, Class d) { 131 | return $as(value, a, b, c, d, Void.class); 132 | } 133 | 134 | /** Creates an union for provided value and list of known types. 135 | * 136 | * @param type a 137 | * @param type b 138 | * @param type c 139 | * @param type d 140 | * @param type d 141 | * @param value the actual value of the union 142 | * @param a class a 143 | * @param b class b 144 | * @param c class c 145 | * @param d class d 146 | * @param e class e 147 | * @return union that holds the value and all associated types 148 | */ 149 | public static Union.A5 $as(Object value, Class a, Class b, Class c, Class d, Class e) { 150 | return new Impl<>(value, a, b, c, d, e); 151 | } 152 | 153 | public static abstract class A2 extends Union { 154 | A2(Object value) { 155 | super(value); 156 | } 157 | } 158 | public static abstract class A3 extends A2 { 159 | A3(Object value) { 160 | super(value); 161 | } 162 | } 163 | public static abstract class A4 extends A3 { 164 | A4(Object value) { 165 | super(value); 166 | } 167 | } 168 | public static abstract class A5 extends A4 { 169 | A5(Object value) { 170 | super(value); 171 | } 172 | } 173 | 174 | private static final class Impl extends A5 { 175 | public Impl(Object value, Class a, Class b, Class c, Class d, Class e) { 176 | super(value); 177 | } 178 | 179 | @Override 180 | public T cast(Class type) { 181 | return Objs.$as(type, this); 182 | } 183 | 184 | @Override 185 | public boolean instanceOf(Class> type) { 186 | return type.isInstance($js(this)) || Objs.class.isAssignableFrom(type); 187 | } 188 | } 189 | } 190 | -------------------------------------------------------------------------------- /libs/core/src/main/resources/net/java/html/lib/hjTypings.js: -------------------------------------------------------------------------------- 1 | /* 2 | * #%L 3 | * ES6 Core Library - a library from the DukeScript project. 4 | * Visit http://dukescript.com for support and commercial license. 5 | * %% 6 | * Copyright (C) 2015 - 2016 Dukehoff GmbH 7 | * %% 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | * #L% 26 | */ 27 | (function () { 28 | var t = {}; 29 | function HtmlJavaArray() { 30 | } 31 | function HtmlJavaArrayUpdate(arr, hjArray) { 32 | hjArray.length = arr.length; 33 | hjArray.arr = arr; 34 | for (var i = 0; i < arr.length; i++) { 35 | hjArray[i] = arr[i]; 36 | } 37 | } 38 | function newArray(arr) { 39 | var obj = new HtmlJavaArray; 40 | HtmlJavaArrayUpdate(arr, obj); 41 | return obj; 42 | } 43 | 44 | HtmlJavaArray.prototype.push = function() { 45 | var ret = this.arr.push.apply(this.arr, arguments); 46 | HtmlJavaArrayUpdate(this.arr, this); 47 | return ret; 48 | }; 49 | HtmlJavaArray.prototype.reverse = function() { 50 | var ret = this.arr.reverse.apply(this.arr, arguments); 51 | HtmlJavaArrayUpdate(this.arr, this); 52 | return this; 53 | }; 54 | HtmlJavaArray.prototype.pop = function() { 55 | return this.arr.pop.apply(this.arr, arguments); 56 | }; 57 | HtmlJavaArray.prototype.$set = function(n, v) { 58 | this.arr[n] = v; 59 | HtmlJavaArrayUpdate(this.arr, this); 60 | return this; 61 | }; 62 | HtmlJavaArray.prototype.slice = function() { 63 | var ret = this.arr.slice.apply(this.arr, arguments); 64 | HtmlJavaArrayUpdate(this.arr, this); 65 | return ret; 66 | }; 67 | HtmlJavaArray.prototype.splice = function() { 68 | var ret = this.arr.splice.apply(this.arr, arguments); 69 | HtmlJavaArrayUpdate(this.arr, this); 70 | return newArray(ret); 71 | }; 72 | HtmlJavaArray.prototype.shift = function() { 73 | var ret = this.arr.shift.apply(this.arr, arguments); 74 | HtmlJavaArrayUpdate(this.arr, this); 75 | return ret === undefined ? null : ret; 76 | }; 77 | HtmlJavaArray.prototype.sort = function() { 78 | this.arr.sort.apply(this.arr, arguments); 79 | HtmlJavaArrayUpdate(this.arr, this); 80 | return this; 81 | }; 82 | HtmlJavaArray.prototype.join = function() { 83 | return this.arr.join.apply(this.arr, arguments); 84 | }; 85 | HtmlJavaArray.prototype.indexOf = function() { 86 | return this.arr.indexOf.apply(this.arr, arguments); 87 | }; 88 | HtmlJavaArray.prototype.lastIndexOf = function() { 89 | return this.arr.lastIndexOf.apply(this.arr, arguments); 90 | }; 91 | HtmlJavaArray.prototype.concat = function() { 92 | var ret = this.arr.concat.apply(this.arr, arguments); 93 | return newArray(ret); 94 | }; 95 | HtmlJavaArray.prototype.map = function() { 96 | var ret = this.arr.map.apply(this.arr, arguments); 97 | return newArray(ret); 98 | }; 99 | HtmlJavaArray.prototype.filter = function() { 100 | var ret = this.arr.filter.apply(this.arr, arguments); 101 | return newArray(ret); 102 | }; 103 | HtmlJavaArray.prototype.forEach = function() { 104 | var ret = this.arr.forEach.apply(this.arr, arguments); 105 | HtmlJavaArrayUpdate(this.arr, this); 106 | return ret; 107 | }; 108 | HtmlJavaArray.prototype.some = function() { 109 | var ret = this.arr.some.apply(this.arr, arguments); 110 | return ret; 111 | }; 112 | HtmlJavaArray.prototype.reduce = function() { 113 | var ret = this.arr.reduce.apply(this.arr, arguments); 114 | return ret; 115 | }; 116 | HtmlJavaArray.prototype.reduceRight = function() { 117 | var ret = this.arr.reduceRight.apply(this.arr, arguments); 118 | return ret; 119 | }; 120 | HtmlJavaArray.prototype.toString = function() { 121 | var ret = this.arr.toString(); 122 | return ret; 123 | }; 124 | HtmlJavaArray.prototype.toLocaleString = function() { 125 | var ret = this.arr.toLocaleString(); 126 | return ret; 127 | }; 128 | 129 | 130 | t.array = newArray; 131 | this['hj'] = t; 132 | })(); 133 | -------------------------------------------------------------------------------- /libs/core/src/test/java/net/java/html/lib/FunctionTest.java: -------------------------------------------------------------------------------- 1 | package net.java.html.lib; 2 | /* 3 | * #%L 4 | * DukeScript Libraries - a library from the DukeScript project. 5 | * Visit http://dukescript.com for support and commercial license. 6 | * %% 7 | * Copyright (C) 2015 Eppleton IT Consulting 8 | * %% 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * #L% 27 | */ 28 | 29 | import net.java.html.junit.BrowserRunner; 30 | import static org.junit.Assert.assertEquals; 31 | import org.junit.Test; 32 | import org.junit.runner.RunWith; 33 | 34 | @RunWith(BrowserRunner.class) 35 | public class FunctionTest { 36 | 37 | public FunctionTest() { 38 | } 39 | 40 | @Test 41 | public void defineAndCallFunction() { 42 | Function fn = Function.newFunction(new Function.A2() { 43 | @Override 44 | public Integer call(Number p1, Number p2) { 45 | return p1.intValue() * p2.intValue(); 46 | } 47 | }); 48 | Object res = fn.apply(null, 6, 7); 49 | assertEquals(42, ((Number)res).intValue()); 50 | 51 | // String text = fn.toString(); 52 | // assertTrue("contains x: " + text, text.contains("x")); 53 | // assertTrue("contains y: " + text, text.contains("y")); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /libs/core/src/test/java/net/java/html/lib/LibCoreTest.java: -------------------------------------------------------------------------------- 1 | package net.java.html.lib; 2 | 3 | /* 4 | * #%L 5 | * DukeScript Libraries - a library from the DukeScript project. 6 | * Visit http://dukescript.com for support and commercial license. 7 | * %% 8 | * Copyright (C) 2015 Eppleton IT Consulting 9 | * %% 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy 11 | * of this software and associated documentation files (the "Software"), to deal 12 | * in the Software without restriction, including without limitation the rights 13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | * copies of the Software, and to permit persons to whom the Software is 15 | * furnished to do so, subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be included in 18 | * all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 26 | * THE SOFTWARE. 27 | * #L% 28 | */ 29 | 30 | import java.lang.reflect.Method; 31 | import java.lang.reflect.Modifier; 32 | import static net.java.html.lib.Exports.*; 33 | import net.java.html.junit.BrowserRunner; 34 | import org.junit.Assert; 35 | import static org.junit.Assert.assertNotNull; 36 | import static org.junit.Assert.fail; 37 | import org.junit.Test; 38 | import org.junit.runner.RunWith; 39 | 40 | @RunWith(BrowserRunner.class) 41 | public class LibCoreTest { 42 | public LibCoreTest() { 43 | } 44 | 45 | @Test 46 | public void testEval() throws Exception { 47 | final Object fourtyTwo = eval("6 * 7"); 48 | assertTrue(fourtyTwo instanceof Number, "The result is number: " + fourtyTwo); 49 | assertNumber((Number) fourtyTwo, 42, "Fourty two"); 50 | } 51 | 52 | @Test 53 | public void testEvalObject() throws Exception { 54 | final Object obj = eval("var x = {}; x.x = 'Hi'; x"); 55 | assertNotNull("Value returned", obj); 56 | assertTrue(obj instanceof Objs, "The result is Objs: " + obj.getClass()); 57 | Objs js = (Objs) obj; 58 | assertEquals(js.$get("x"), "Hi", "Has property x"); 59 | } 60 | 61 | @Test 62 | public void uri() throws Exception { 63 | final java.lang.String url = "http://dukescript.com"; 64 | java.lang.String encoded = encodeURIComponent(url); 65 | assertEquals(encoded.indexOf("/"), -1, "Really encoded: " + encoded); 66 | assertEquals(decodeURIComponent(encoded), url); 67 | } 68 | 69 | @Test 70 | public void optionalParams() throws Exception { 71 | double fifteen1 = parseInt("0xF"); 72 | double fifteen2 = parseInt("F", 16); 73 | assertEquals(fifteen1, fifteen2); 74 | } 75 | 76 | @Test 77 | public void nan() throws Exception { 78 | double nan = NaN; 79 | assertTrue(isNaN(nan), "Really not a number"); 80 | } 81 | 82 | @Test 83 | public void json() throws Exception { 84 | java.lang.Object json = JSON.parse("{ \"world\" : 42 }"); 85 | java.lang.String result = JSON.stringify(json); 86 | assertTrue(result.contains("world"), "has world: " + result); 87 | assertTrue(result.contains("42"), "has 42: " + result); 88 | } 89 | 90 | @Test 91 | public void arrayOfAndSubArray() throws Exception { 92 | Int8Array value = new Int8Array(3); 93 | assertEquals(value.length.get().doubleValue(), 3.0, 0.1, "Length is 3"); 94 | } 95 | 96 | @Test 97 | public void dateOperation() throws Exception { 98 | Date eleven = new Date(2016, 1, 10); 99 | assertEquals(2016.0, eleven.getFullYear()); 100 | assertEquals(1.0, eleven.getMonth()); 101 | } 102 | 103 | @Test 104 | public void dateHasObjectMethod() throws Exception { 105 | Method hasOwnProperty = Date.class.getMethod("hasOwnProperty", java.lang.String.class); 106 | assertEquals(hasOwnProperty.getReturnType(), java.lang.Boolean.class); 107 | assertEquals(hasOwnProperty.getDeclaringClass(), /* not java.lang */ Objs.class); 108 | } 109 | 110 | @Test 111 | public void parseInJSONIsStatic() throws Exception { 112 | Method parse = JSON.class.getMethod("parse", java.lang.String.class); 113 | assertEquals(parse.getReturnType(), java.lang.Object.class); 114 | assertTrue((parse.getModifiers() & Modifier.STATIC) != 0, "parse is static"); 115 | } 116 | 117 | @Test 118 | public void strigifyJSONWithString() throws Exception { 119 | Method parse = JSON.class.getMethod("stringify", java.lang.Object.class, java.lang.Object[].class, java.lang.String.class); 120 | assertEquals(parse.getReturnType(), java.lang.String.class); 121 | assertTrue((parse.getModifiers() & Modifier.STATIC) != 0, "stringify is static"); 122 | } 123 | 124 | @Test 125 | public void strigifyJSONWithNumber() throws Exception { 126 | Method parse = JSON.class.getMethod("stringify", java.lang.Object.class, java.lang.Object[].class, double.class); 127 | assertEquals(parse.getReturnType(), java.lang.String.class); 128 | assertTrue((parse.getModifiers() & Modifier.STATIC) != 0, "stringify is static"); 129 | } 130 | 131 | @Test 132 | public void intArraySetDouble() throws Exception { 133 | Method set = Uint32Array.class.getMethod("set", double.class, double.class); 134 | assertEquals(set.getReturnType(), void.class); 135 | } 136 | 137 | @Test 138 | public void intArraySetArrayLike() throws Exception { 139 | Method set = Uint32Array.class.getMethod("set", ArrayLike.class); 140 | assertEquals(set.getReturnType(), void.class); 141 | } 142 | 143 | @Test 144 | public void intArraySetArrayLikeIndex() throws Exception { 145 | Method set = Uint32Array.class.getMethod("set", ArrayLike.class, double.class); 146 | assertEquals(set.getReturnType(), void.class); 147 | } 148 | 149 | @Test 150 | public void typeErrorIsAnError() throws Exception { 151 | TypeError te = new TypeError("an error"); 152 | Error error = te; 153 | assertEquals(te, error, "Assigned"); 154 | assertEquals(error.message.get(), "an error"); 155 | assertEquals(error.name.get(), "TypeError"); 156 | } 157 | 158 | @Test 159 | public void setGetProperties() throws Exception { 160 | Objs obj = new Objs(). 161 | $set("key", "value"). 162 | $set("key2", 10.0); 163 | 164 | assertEquals(obj.$get("key"), "value"); 165 | assertNumber((Number) obj.$get("key2"), 10.0, "should be ten now"); 166 | 167 | obj.$delete("key2"); 168 | 169 | assertEquals(obj.$get("key"), "value"); 170 | ArrayTest.assertNotANumber(obj.$get("key2")); 171 | } 172 | 173 | @Test 174 | public void toStringSync() throws Exception { 175 | Objs objs = new Objs(); 176 | assertNotNull(objs.toString()); 177 | } 178 | 179 | @Test 180 | public void toStringASync() throws Exception { 181 | Objs objs = new Objs(); 182 | String[] res = { null }; 183 | try { 184 | Thread t = new Thread() { 185 | @Override 186 | public void run() { 187 | res[0] = objs.toString(); 188 | } 189 | }; 190 | t.start(); 191 | t.join(); 192 | } catch (SecurityException ex) { 193 | // bck2brwsr doesn't support threads, skip the test 194 | return; 195 | } 196 | assertNotNull(res[0]); 197 | } 198 | 199 | @Test 200 | public void arrayForEach() throws Exception { 201 | Array arr = new Array<>(); 202 | assertNumber(arr.length.get(), 0.0, "Empty at first"); 203 | arr.push(1.1, 2.2, 3); 204 | assertNumber(arr.$get(0), 1.1, "1.1 is on position 0"); 205 | assertNumber(arr.$get(1), 2.2, "2.2 is on position 1"); 206 | assertNumber(arr.$get(2), 3.0, "3 is on position 2"); 207 | boolean[] called = { false }; 208 | double[] sum = { 0.0 }; 209 | arr.forEach(new net.java.html.lib.Function.A1() { 210 | @Override 211 | public Void call(java.lang.Number p1) { 212 | called[0] = true; 213 | sum[0] += p1.doubleValue(); 214 | return null; 215 | } 216 | }); 217 | assertTrue(called[0], "forEach invoked"); 218 | assertEquals(sum[0], 6.3, 0.1, "Sum computed"); 219 | } 220 | 221 | @Test 222 | public void keysForEach() throws Exception { 223 | Objs obj = new Objs(); 224 | for (String key : Objs.keys(obj)) { 225 | fail("No key expected in an empty object: " + key); 226 | } 227 | obj.$set("hi", "there"); 228 | obj.$set("hello", "world"); 229 | int cnt = 0; 230 | for (String key : Objs.keys(obj)) { 231 | assertTrue("hi".equals(key) || "hello".equals(key), "Key is expected: " + key); 232 | cnt++; 233 | } 234 | assertEquals(cnt, 2, "Two keys"); 235 | } 236 | 237 | private static void assertTrue(boolean cond, String msg) { 238 | Assert.assertTrue(msg, cond); 239 | } 240 | 241 | private static void assertEquals(double a, double b, double c, String msg) { 242 | Assert.assertEquals(msg, b, a, c); 243 | } 244 | 245 | private static void assertEquals(Object actual, Object expected, String msg) { 246 | Assert.assertEquals(msg, expected, actual); 247 | } 248 | private static void assertNumber(Number actual, double expected, String msg) { 249 | Assert.assertEquals(msg, expected, actual.doubleValue(), 0.01); 250 | } 251 | private static void assertEquals(Object actual, Object expected) { 252 | Assert.assertEquals(expected, actual); 253 | } 254 | } 255 | -------------------------------------------------------------------------------- /libs/dom/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 28 | 29 | 30 | 4.0.0 31 | 32 | com.dukescript.libraries 33 | pom 34 | 1.0-SNAPSHOT 35 | ../../ 36 | 37 | net.java.html.lib.dom 38 | DOM Interfaces 39 | bundle 40 | 41 | net.java.html.lib.dom 42 | 1.8 43 | 1.8 44 | 45 | 46 | 47 | 48 | org.apache.maven.plugins 49 | maven-javadoc-plugin 50 | 51 | false 52 | 53 | 54 | 55 | org.apache.maven.plugins 56 | maven-source-plugin 57 | 58 | 59 | org.netbeans.html 60 | html4j-maven-plugin 61 | ${net.java.html.version} 62 | 63 | 64 | js-classes 65 | 66 | process-js-annotations 67 | 68 | 69 | 70 | 71 | 72 | com.dukescript.libraries 73 | typings-maven-plugin 74 | ${project.version} 75 | 76 | 77 | generate-sources 78 | 79 | generate 80 | 81 | 82 | 83 | 84 | src/main/java/net/java/html/lib/dom/lib.dom.d.ts 85 | ${publicPackages} 86 | 87 | 88 | 89 | org.apache.felix 90 | maven-bundle-plugin 91 | 2.5.3 92 | true 93 | 94 | 95 | dependent 96 | ${publicPackages} 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | com.dukescript.libraries 105 | net.java.html.lib 106 | ${project.version} 107 | jar 108 | compile 109 | 110 | 111 | -------------------------------------------------------------------------------- /mojo-base/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 24 | 25 | 26 | 4.0.0 27 | com.dukescript.libraries 28 | mojo-base 29 | DukeScript Typings Processor 30 | 31 | com.dukescript.libraries 32 | pom 33 | 1.0-SNAPSHOT 34 | 35 | 36 | jar 37 | https://github.com/dukescript/dukescript-libraries 38 | Generator to convert TypeScript library into Java API 39 | 40 | 41 | 42 | gpl_v3 43 | http://www.gnu.org/licenses/gpl-3.0.html 44 | 45 | Visit http://dukescript.com for support and commercial license. 46 | 47 | 48 | 49 | 50 | UTF-8 51 | none 52 | 53 | 54 | 55 | 56 | 57 | org.netbeans.html 58 | html4j-maven-plugin 59 | ${mojo.java.html.version} 60 | 61 | 62 | js-classes 63 | 64 | process-js-annotations 65 | 66 | 67 | 68 | test-classes 69 | process-test-classes 70 | 71 | process-js-annotations 72 | 73 | 74 | ${project.build.directory}/test-classes 75 | 76 | 77 | 78 | 79 | 80 | maven-javadoc-plugin 81 | 82 | false 83 | 84 | 85 | 86 | org.apache.maven.plugins 87 | maven-source-plugin 88 | 89 | 90 | 91 | 92 | 93 | org.netbeans.html 94 | net.java.html.json 95 | ${mojo.java.html.version} 96 | compile 97 | 98 | 99 | org.netbeans.html 100 | net.java.html 101 | 102 | 103 | 104 | 105 | org.netbeans.html 106 | net.java.html.boot.script 107 | ${mojo.java.html.version} 108 | compile 109 | 110 | 111 | org.netbeans.html 112 | net.java.html 113 | 114 | 115 | org.netbeans.html 116 | net.java.html.boot 117 | 118 | 119 | 120 | 121 | org.netbeans.html 122 | ko4j 123 | ${mojo.java.html.version} 124 | compile 125 | 126 | 127 | org.netbeans.html 128 | net.java.html.boot 129 | 130 | 131 | 132 | 133 | com.dukescript.api 134 | junit-browser-runner 135 | 136 | 137 | org.netbeans.html 138 | net.java.html.boot 139 | 140 | 141 | org.netbeans.html 142 | net.java.html 143 | 144 | 145 | 146 | 147 | org.netbeans.html 148 | net.java.html 149 | ${mojo.java.html.version} 150 | 151 | 152 | org.netbeans.html 153 | net.java.html.boot 154 | ${mojo.java.html.version} 155 | 156 | 157 | org.netbeans.html 158 | net.java.html 159 | 160 | 161 | 162 | 163 | 164 | 165 | ossrh 166 | https://oss.sonatype.org/content/repositories/snapshots 167 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /mojo-base/src/main/java/com/dukescript/libraries/proc/Parser.java: -------------------------------------------------------------------------------- 1 | package com.dukescript.libraries.proc; 2 | 3 | /* 4 | * #%L 5 | * DukeScript Libraries Processor - a library from the DukeScript project. 6 | * Visit http://dukescript.com for support and commercial license. 7 | * %% 8 | * Copyright (C) 2015 Eppleton IT Consulting 9 | * %% 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as 12 | * published by the Free Software Foundation, either version 3 of the 13 | * License, or (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public 21 | * License along with this program. If not, see 22 | * . 23 | * #L% 24 | */ 25 | 26 | import java.io.Closeable; 27 | import java.io.File; 28 | import java.io.FileInputStream; 29 | import java.io.FileOutputStream; 30 | import java.io.IOException; 31 | import java.io.InputStream; 32 | import java.io.InputStreamReader; 33 | import javax.script.ScriptEngine; 34 | import javax.script.ScriptEngineManager; 35 | import net.java.html.BrwsrCtx; 36 | import net.java.html.boot.script.Scripts; 37 | import net.java.html.js.JavaScriptBody; 38 | import net.java.html.js.JavaScriptResource; 39 | import net.java.html.json.Models; 40 | import org.netbeans.html.boot.spi.Fn; 41 | 42 | @JavaScriptResource("app.js") 43 | final class Parser { 44 | private final Fn.Presenter js; 45 | Parser() throws IOException { 46 | ScriptEngine eng = findEngine(new ScriptEngineManager()); 47 | if (eng == null) { 48 | eng = findEngine(new ScriptEngineManager(ClassLoader.getSystemClassLoader())); 49 | } 50 | js = Scripts.newPresenter().engine(eng).build(); 51 | try (Closeable c = Fn.activate(js)) { 52 | TypeScript.initialize(); 53 | initialize(); 54 | } 55 | } 56 | 57 | @JavaScriptBody(args = { }, body = "") 58 | private static native void initialize(); 59 | 60 | public AST parse(String filename, InputStream is) throws IOException { 61 | InputStreamReader reader = new InputStreamReader(is, "UTF-8"); 62 | StringBuilder sb = new StringBuilder(4096); 63 | char[] arr = new char[4096]; 64 | for (;;) { 65 | int len = reader.read(arr); 66 | if (len == -1) { 67 | break; 68 | } 69 | sb.append(arr, 0, len); 70 | } 71 | final String text = sb.toString(); 72 | final BrwsrCtx ctx = BrwsrCtx.findDefault(AST.class); 73 | 74 | File tmpDir = new File(System.getProperty("java.io.tmpdir")); 75 | File cache = new File(tmpDir, "ast-" + Integer.toHexString(text.hashCode()) + ".json"); 76 | 77 | try (Closeable c = Fn.activate(js)) { 78 | NO_PARSING: if (cache.exists()) { 79 | long validTill = cache.lastModified() + 10 * 60 * 1000; // 10 min 80 | if (validTill < System.currentTimeMillis()) { 81 | break NO_PARSING; 82 | } 83 | try (InputStream cachedStream = new FileInputStream(cache)) { 84 | return Models.parse(ctx, AST.class, cachedStream); 85 | } 86 | } 87 | boolean wantText = false; 88 | Object[] astAndText = parseTypeScript(filename, text, wantText); 89 | Object ast = astAndText[0]; 90 | AST structures = Models.fromRaw(ctx, AST.class, ast); 91 | try (FileOutputStream os = new FileOutputStream(cache)) { 92 | os.write(structures.toString().getBytes("UTF-8")); 93 | } 94 | return structures; 95 | } 96 | } 97 | 98 | @JavaScriptBody(args = { "filename", "source", "wantText" }, body = 99 | "return parseTypeScript(filename, source, wantText);" 100 | ) 101 | private static native Object[] parseTypeScript(String filename, String source, boolean wantText); 102 | 103 | private static ScriptEngine findEngine(ScriptEngineManager manager) { 104 | ScriptEngine e = manager.getEngineByMimeType("text/javascript"); 105 | if (e == null) { 106 | e = manager.getEngineByName("javascript"); 107 | } 108 | return e; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /mojo-base/src/main/java/com/dukescript/libraries/proc/Resolver.java: -------------------------------------------------------------------------------- 1 | package com.dukescript.libraries.proc; 2 | 3 | /* 4 | * #%L 5 | * DukeScript Libraries Processor - a library from the DukeScript project. 6 | * Visit http://dukescript.com for support and commercial license. 7 | * %% 8 | * Copyright (C) 2015 Eppleton IT Consulting 9 | * %% 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as 12 | * published by the Free Software Foundation, either version 3 of the 13 | * License, or (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public 21 | * License along with this program. If not, see 22 | * . 23 | * #L% 24 | */ 25 | abstract class Resolver { 26 | private static Resolver current; 27 | 28 | static String findFQN(String simpleName) { 29 | return current == null ? simpleName : current.resolveFQN(simpleName); 30 | } 31 | 32 | protected Resolver() { 33 | current = this; 34 | } 35 | 36 | abstract String resolveFQN(String simpleName); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /mojo-base/src/main/java/com/dukescript/libraries/proc/SyntaxKind.java: -------------------------------------------------------------------------------- 1 | package com.dukescript.libraries.proc; 2 | 3 | /* 4 | * #%L 5 | * DukeScript Libraries Processor - a library from the DukeScript project. 6 | * Visit http://dukescript.com for support and commercial license. 7 | * %% 8 | * Copyright (C) 2015 Eppleton IT Consulting 9 | * %% 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as 12 | * published by the Free Software Foundation, either version 3 of the 13 | * License, or (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public 21 | * License along with this program. If not, see 22 | * . 23 | * #L% 24 | */ 25 | 26 | enum SyntaxKind { 27 | Unknown, 28 | EndOfFileToken, 29 | SingleLineCommentTrivia, 30 | MultiLineCommentTrivia, 31 | NewLineTrivia, 32 | WhitespaceTrivia, 33 | ShebangTrivia, 34 | ConflictMarkerTrivia, 35 | NumericLiteral, 36 | StringLiteral, 37 | RegularExpressionLiteral, 38 | NoSubstitutionTemplateLiteral, 39 | TemplateHead, 40 | TemplateMiddle, 41 | TemplateTail, 42 | OpenBraceToken, 43 | CloseBraceToken, 44 | OpenParenToken, 45 | CloseParenToken, 46 | OpenBracketToken, 47 | CloseBracketToken, 48 | DotToken, 49 | DotDotDotToken, 50 | SemicolonToken, 51 | CommaToken, 52 | LessThanToken, 53 | LessThanSlashToken, 54 | GreaterThanToken, 55 | LessThanEqualsToken, 56 | GreaterThanEqualsToken, 57 | EqualsEqualsToken, 58 | ExclamationEqualsToken, 59 | EqualsEqualsEqualsToken, 60 | ExclamationEqualsEqualsToken, 61 | EqualsGreaterThanToken, 62 | PlusToken, 63 | MinusToken, 64 | AsteriskToken, 65 | AsteriskAsteriskToken, 66 | SlashToken, 67 | PercentToken, 68 | PlusPlusToken, 69 | MinusMinusToken, 70 | LessThanLessThanToken, 71 | GreaterThanGreaterThanToken, 72 | GreaterThanGreaterThanGreaterThanToken, 73 | AmpersandToken, 74 | BarToken, 75 | CaretToken, 76 | ExclamationToken, 77 | TildeToken, 78 | AmpersandAmpersandToken, 79 | BarBarToken, 80 | QuestionToken, 81 | ColonToken, 82 | AtToken, 83 | EqualsToken, 84 | PlusEqualsToken, 85 | MinusEqualsToken, 86 | AsteriskEqualsToken, 87 | AsteriskAsteriskEqualsToken, 88 | SlashEqualsToken, 89 | PercentEqualsToken, 90 | LessThanLessThanEqualsToken, 91 | GreaterThanGreaterThanEqualsToken, 92 | GreaterThanGreaterThanGreaterThanEqualsToken, 93 | AmpersandEqualsToken, 94 | BarEqualsToken, 95 | CaretEqualsToken, 96 | Identifier, 97 | BreakKeyword, 98 | CaseKeyword, 99 | CatchKeyword, 100 | ClassKeyword, 101 | ConstKeyword, 102 | ContinueKeyword, 103 | DebuggerKeyword, 104 | DefaultKeyword, 105 | DeleteKeyword, 106 | DoKeyword, 107 | ElseKeyword, 108 | EnumKeyword, 109 | ExportKeyword, 110 | ExtendsKeyword, 111 | FalseKeyword, 112 | FinallyKeyword, 113 | ForKeyword, 114 | FunctionKeyword, 115 | IfKeyword, 116 | ImportKeyword, 117 | InKeyword, 118 | InstanceOfKeyword, 119 | NewKeyword, 120 | NullKeyword, 121 | ReturnKeyword, 122 | SuperKeyword, 123 | SwitchKeyword, 124 | ThisKeyword, 125 | ThrowKeyword, 126 | TrueKeyword, 127 | TryKeyword, 128 | TypeOfKeyword, 129 | VarKeyword, 130 | VoidKeyword, 131 | WhileKeyword, 132 | WithKeyword, 133 | ImplementsKeyword, 134 | InterfaceKeyword, 135 | LetKeyword, 136 | PackageKeyword, 137 | PrivateKeyword, 138 | ProtectedKeyword, 139 | PublicKeyword, 140 | StaticKeyword, 141 | YieldKeyword, 142 | AbstractKeyword, 143 | AsKeyword, 144 | AnyKeyword, 145 | AsyncKeyword, 146 | AwaitKeyword, 147 | BooleanKeyword, 148 | ConstructorKeyword, 149 | DeclareKeyword, 150 | GetKeyword, 151 | IsKeyword, 152 | ModuleKeyword, 153 | NamespaceKeyword, 154 | RequireKeyword, 155 | NumberKeyword, 156 | SetKeyword, 157 | StringKeyword, 158 | SymbolKeyword, 159 | TypeKeyword, 160 | FromKeyword, 161 | OfKeyword, 162 | QualifiedName, 163 | ComputedPropertyName, 164 | TypeParameter, 165 | Parameter, 166 | Decorator, 167 | PropertySignature, 168 | PropertyDeclaration, 169 | MethodSignature, 170 | MethodDeclaration, 171 | Constructor, 172 | GetAccessor, 173 | SetAccessor, 174 | CallSignature, 175 | ConstructSignature, 176 | IndexSignature, 177 | TypePredicate, 178 | TypeReference, 179 | FunctionType, 180 | ConstructorType, 181 | TypeQuery, 182 | TypeLiteral, 183 | ArrayType, 184 | TupleType, 185 | UnionType, 186 | IntersectionType, 187 | ParenthesizedType, 188 | ObjectBindingPattern, 189 | ArrayBindingPattern, 190 | BindingElement, 191 | ArrayLiteralExpression, 192 | ObjectLiteralExpression, 193 | PropertyAccessExpression, 194 | ElementAccessExpression, 195 | CallExpression, 196 | NewExpression, 197 | TaggedTemplateExpression, 198 | TypeAssertionExpression, 199 | ParenthesizedExpression, 200 | FunctionExpression, 201 | ArrowFunction, 202 | DeleteExpression, 203 | TypeOfExpression, 204 | VoidExpression, 205 | AwaitExpression, 206 | PrefixUnaryExpression, 207 | PostfixUnaryExpression, 208 | BinaryExpression, 209 | ConditionalExpression, 210 | TemplateExpression, 211 | YieldExpression, 212 | SpreadElementExpression, 213 | ClassExpression, 214 | OmittedExpression, 215 | ExpressionWithTypeArguments, 216 | AsExpression, 217 | TemplateSpan, 218 | SemicolonClassElement, 219 | Block, 220 | VariableStatement, 221 | EmptyStatement, 222 | ExpressionStatement, 223 | IfStatement, 224 | DoStatement, 225 | WhileStatement, 226 | ForStatement, 227 | ForInStatement, 228 | ForOfStatement, 229 | ContinueStatement, 230 | BreakStatement, 231 | ReturnStatement, 232 | WithStatement, 233 | SwitchStatement, 234 | LabeledStatement, 235 | ThrowStatement, 236 | TryStatement, 237 | DebuggerStatement, 238 | VariableDeclaration, 239 | VariableDeclarationList, 240 | FunctionDeclaration, 241 | ClassDeclaration, 242 | InterfaceDeclaration, 243 | TypeAliasDeclaration, 244 | EnumDeclaration, 245 | ModuleDeclaration, 246 | ModuleBlock, 247 | CaseBlock, 248 | ImportEqualsDeclaration, 249 | ImportDeclaration, 250 | ImportClause, 251 | NamespaceImport, 252 | NamedImports, 253 | ImportSpecifier, 254 | ExportAssignment, 255 | ExportDeclaration, 256 | NamedExports, 257 | ExportSpecifier, 258 | MissingDeclaration, 259 | ExternalModuleReference, 260 | JsxElement, 261 | JsxSelfClosingElement, 262 | JsxOpeningElement, 263 | JsxText, 264 | JsxClosingElement, 265 | JsxAttribute, 266 | JsxSpreadAttribute, 267 | JsxExpression, 268 | CaseClause, 269 | DefaultClause, 270 | HeritageClause, 271 | CatchClause, 272 | PropertyAssignment, 273 | ShorthandPropertyAssignment, 274 | EnumMember, 275 | SourceFile, 276 | JSDocTypeExpression, 277 | JSDocAllType, 278 | JSDocUnknownType, 279 | JSDocArrayType, 280 | JSDocUnionType, 281 | JSDocTupleType, 282 | JSDocNullableType, 283 | JSDocNonNullableType, 284 | JSDocRecordType, 285 | JSDocRecordMember, 286 | JSDocTypeReference, 287 | JSDocOptionalType, 288 | JSDocFunctionType, 289 | JSDocVariadicType, 290 | JSDocConstructorType, 291 | JSDocThisType, 292 | JSDocComment, 293 | JSDocTag, 294 | JSDocParameterTag, 295 | JSDocReturnTag, 296 | JSDocTypeTag, 297 | JSDocTemplateTag, 298 | SyntaxList, 299 | Count, 300 | FirstAssignment, 301 | LastAssignment, 302 | FirstReservedWord, 303 | LastReservedWord, 304 | FirstKeyword, 305 | LastKeyword, 306 | FirstFutureReservedWord, 307 | LastFutureReservedWord, 308 | FirstTypeNode, 309 | LastTypeNode, 310 | FirstPunctuation, 311 | LastPunctuation, 312 | FirstToken, 313 | LastToken, 314 | FirstTriviaToken, 315 | LastTriviaToken, 316 | FirstLiteralToken, 317 | LastLiteralToken, 318 | FirstTemplateToken, 319 | LastTemplateToken, 320 | FirstBinaryOperator, 321 | LastBinaryOperator, 322 | FirstNode,; 323 | 324 | boolean isTypeNode() { 325 | return this == FirstTypeNode || this == LastTypeNode; 326 | } 327 | } 328 | -------------------------------------------------------------------------------- /mojo-base/src/main/java/com/dukescript/libraries/proc/TypeScript.java: -------------------------------------------------------------------------------- 1 | package com.dukescript.libraries.proc; 2 | 3 | /* 4 | * #%L 5 | * DukeScript Libraries Processor - a library from the DukeScript project. 6 | * Visit http://dukescript.com for support and commercial license. 7 | * %% 8 | * Copyright (C) 2015 Eppleton IT Consulting 9 | * %% 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as 12 | * published by the Free Software Foundation, either version 3 of the 13 | * License, or (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public 21 | * License along with this program. If not, see 22 | * . 23 | * #L% 24 | */ 25 | 26 | import net.java.html.js.JavaScriptBody; 27 | import net.java.html.js.JavaScriptResource; 28 | 29 | @JavaScriptResource("typescript.js") 30 | class TypeScript { 31 | @JavaScriptBody(args = {}, body = "") 32 | public static native void initialize(); 33 | } 34 | -------------------------------------------------------------------------------- /mojo-base/src/main/java/com/dukescript/libraries/proc/Visitor.java: -------------------------------------------------------------------------------- 1 | package com.dukescript.libraries.proc; 2 | 3 | import java.io.IOException; 4 | 5 | /* 6 | * #%L 7 | * DukeScript Libraries Processor - a library from the DukeScript project. 8 | * Visit http://dukescript.com for support and commercial license. 9 | * %% 10 | * Copyright (C) 2015 Eppleton IT Consulting 11 | * %% 12 | * This program is free software: you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as 14 | * published by the Free Software Foundation, either version 3 of the 15 | * License, or (at your option) any later version. 16 | * 17 | * This program is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public 23 | * License along with this program. If not, see 24 | * . 25 | * #L% 26 | */ 27 | 28 | interface Visitor { 29 | void visit(T0 a, T1 b, T2 c, T3 d, T4 e, T5 f) throws IOException; 30 | } 31 | -------------------------------------------------------------------------------- /mojo-base/src/main/resources/com/dukescript/libraries/proc/app.js: -------------------------------------------------------------------------------- 1 | /* 2 | * #%L 3 | * DukeScript Libraries Processor - a library from the DukeScript project. 4 | * Visit http://dukescript.com for support and commercial license. 5 | * %% 6 | * Copyright (C) 2015 Eppleton IT Consulting 7 | * %% 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as 10 | * published by the Free Software Foundation, either version 3 of the 11 | * License, or (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public 19 | * License along with this program. If not, see 20 | * . 21 | * #L% 22 | */ 23 | 24 | /* global ts */ 25 | 26 | function log(msg) { 27 | // if (typeof console === 'undefined') { 28 | // print(msg); 29 | // } else { 30 | // console.log(msg); 31 | // } 32 | } 33 | 34 | 35 | if (typeof window === 'undefined') { 36 | window = this; 37 | } 38 | 39 | function printChildTypes(root, source) { 40 | var copy = {}; 41 | copy.children = []; 42 | var space = ''; 43 | ts.forEachChild(root, function P(n) { 44 | log(space + n.kind + ' ' + ts.SyntaxKind[n.kind]); 45 | space += ' '; 46 | nCopy = dumpObject(n, space, source); 47 | copy.children.push(nCopy); 48 | var prev = copy.children; 49 | copy.children = []; 50 | ts.forEachChild(n, P); 51 | nCopy.children = copy.children; 52 | copy.children = prev; 53 | space = space.substring(2); 54 | }); 55 | return copy; 56 | } 57 | 58 | function dumpObject(n, space, source) { 59 | function isArray(obj) { 60 | return Object.prototype.toString.call(obj) === '[object Array]'; 61 | } 62 | 63 | var copy = isArray(n) ? [] : {}; 64 | var fns = ''; 65 | if (n.pos) { 66 | var cmnts = ts.getLeadingCommentRanges(source, n.pos); 67 | if (cmnts) { 68 | var c = cmnts[0]; 69 | n.comment = source.substring(c.pos, c.end); 70 | } 71 | } 72 | for (var p in n) { 73 | if (p === 'pos' || p === 'end' || p === 'flags') { 74 | continue; 75 | } 76 | v = n[p]; 77 | if (typeof v === 'function') { 78 | fns += p + ' '; 79 | continue; 80 | } 81 | if (p === 'kind' || p === 'token') { 82 | v = ts.SyntaxKind[v]; 83 | } 84 | log(space + '[' + p + '] = ' + v); 85 | if (typeof v === 'object') { 86 | copy[p] = dumpObject(v, space + ' ', source); 87 | } else { 88 | copy[p] = v; 89 | } 90 | } 91 | log(space + 'functions: ' + fns.substring(0, 40)); 92 | return copy; 93 | } 94 | 95 | function parseTypeScript(filename, source, wantText) { 96 | var sf = ts.createSourceFile(filename, source, 2 /* Latest */); 97 | var copy = printChildTypes(sf, source); 98 | return [copy, wantText ? JSON.stringify(copy) : null]; 99 | } 100 | -------------------------------------------------------------------------------- /mojo-base/src/test/java/com/dukescript/libraries/proc/ASTTest.java: -------------------------------------------------------------------------------- 1 | package com.dukescript.libraries.proc; 2 | 3 | /* 4 | * #%L 5 | * DukeScript Libraries Processor - a library from the DukeScript project. 6 | * Visit http://dukescript.com for support and commercial license. 7 | * %% 8 | * Copyright (C) 2015 Eppleton IT Consulting 9 | * %% 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as 12 | * published by the Free Software Foundation, either version 3 of the 13 | * License, or (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public 21 | * License along with this program. If not, see 22 | * . 23 | * #L% 24 | */ 25 | 26 | import java.io.ByteArrayInputStream; 27 | import java.io.IOException; 28 | import net.java.html.BrwsrCtx; 29 | import net.java.html.json.Models; 30 | import net.java.html.junit.BrowserRunner; 31 | import static org.junit.Assert.assertEquals; 32 | import org.junit.Test; 33 | import org.junit.runner.RunWith; 34 | 35 | @RunWith(BrowserRunner.class) 36 | public class ASTTest { 37 | @Test 38 | public void substituteTypeVars() throws IOException { 39 | BrwsrCtx ctx = BrwsrCtx.findDefault(ASTTest.class); 40 | String type = "" 41 | + "{\n" 42 | + " \"kind\": \"FunctionType\",\n" 43 | + " \"typeName\": null,\n" 44 | + " \"type\": [\n" 45 | + " {\n" 46 | + " \"kind\": \"FirstTypeNode\",\n" 47 | + " \"typeName\": {\n" 48 | + " \"text\": \"Array\"\n" 49 | + " },\n" 50 | + " \"type\": [\n" 51 | + " ],\n" 52 | + " \"types\": [\n" 53 | + " ],\n" 54 | + " \"typeArguments\": [\n" 55 | + " {\n" 56 | + " \"kind\": \"FirstTypeNode\",\n" 57 | + " \"typeName\": {\n" 58 | + " \"text\": \"T\"\n" 59 | + " },\n" 60 | + " \"type\": [\n" 61 | + " ],\n" 62 | + " \"types\": [\n" 63 | + " ],\n" 64 | + " \"typeArguments\": [\n" 65 | + " ],\n" 66 | + " \"typeParameters\": [\n" 67 | + " ],\n" 68 | + " \"parameters\": [\n" 69 | + " ],\n" 70 | + " \"elementType\": [\n" 71 | + " ],\n" 72 | + " \"members\": [\n" 73 | + " ]\n" 74 | + " }\n" 75 | + " ],\n" 76 | + " \"typeParameters\": [\n" 77 | + " ],\n" 78 | + " \"parameters\": [\n" 79 | + " ],\n" 80 | + " \"elementType\": [\n" 81 | + " ],\n" 82 | + " \"members\": [\n" 83 | + " ]\n" 84 | + " }\n" 85 | + " ],\n" 86 | + " \"types\": [\n" 87 | + " ],\n" 88 | + " \"typeArguments\": [\n" 89 | + " ],\n" 90 | + " \"typeParameters\": [\n" 91 | + " ],\n" 92 | + " \"parameters\": [\n" 93 | + " {\n" 94 | + " \"name\": {\n" 95 | + " \"text\": \"arr\"\n" 96 | + " },\n" 97 | + " \"type\": {\n" 98 | + " \"kind\": \"FirstTypeNode\",\n" 99 | + " \"typeName\": {\n" 100 | + " \"text\": \"Array\"\n" 101 | + " },\n" 102 | + " \"type\": [\n" 103 | + " ],\n" 104 | + " \"types\": [\n" 105 | + " ],\n" 106 | + " \"typeArguments\": [\n" 107 | + " {\n" 108 | + " \"kind\": \"FirstTypeNode\",\n" 109 | + " \"typeName\": {\n" 110 | + " \"text\": \"T\"\n" 111 | + " },\n" 112 | + " \"type\": [\n" 113 | + " ],\n" 114 | + " \"types\": [\n" 115 | + " ],\n" 116 | + " \"typeArguments\": [\n" 117 | + " ],\n" 118 | + " \"typeParameters\": [\n" 119 | + " ],\n" 120 | + " \"parameters\": [\n" 121 | + " ],\n" 122 | + " \"elementType\": [\n" 123 | + " ],\n" 124 | + " \"members\": [\n" 125 | + " ]\n" 126 | + " }\n" 127 | + " ],\n" 128 | + " \"typeParameters\": [\n" 129 | + " ],\n" 130 | + " \"parameters\": [\n" 131 | + " ],\n" 132 | + " \"elementType\": [\n" 133 | + " ],\n" 134 | + " \"members\": [\n" 135 | + " ]\n" 136 | + " },\n" 137 | + " \"questionToken\": null,\n" 138 | + " \"dotDotDotToken\": null\n" 139 | + " }\n" 140 | + " ],\n" 141 | + " \"elementType\": [\n" 142 | + " ],\n" 143 | + " \"members\": [\n" 144 | + " ]\n" 145 | + "}"; 146 | Type astType = Models.parse(ctx, Type.class, new ByteArrayInputStream(type.getBytes())); 147 | assertEquals("Type variable T is there", "T", astType.getType().get(0).getTypeArguments().get(0).getTypeName().getSimpleName()); 148 | astType.anonimize(); 149 | assertEquals("Type variable has been anonymized", "?", astType.getType().get(0).getTypeArguments().get(0).getTypeName().getSimpleName()); 150 | } 151 | @Test 152 | public void substituteTypeVars2() throws IOException { 153 | BrwsrCtx ctx = BrwsrCtx.findDefault(ASTTest.class); 154 | String type = "" 155 | + "{\n" + 156 | " \"kind\": \"FunctionType\",\n" + 157 | " \"typeName\": null,\n" + 158 | " \"type\": [\n" + 159 | " {\n" + 160 | " \"kind\": \"UnionType\",\n" + 161 | " \"typeName\": null,\n" + 162 | " \"type\": [\n" + 163 | " ],\n" + 164 | " \"types\": [\n" + 165 | " {\n" + 166 | " \"kind\": \"FirstTypeNode\",\n" + 167 | " \"typeName\": {\n" + 168 | " \"text\": \"IPromise\"\n" + 169 | " },\n" + 170 | " \"type\": [\n" + 171 | " ],\n" + 172 | " \"types\": [\n" + 173 | " ],\n" + 174 | " \"typeArguments\": [\n" + 175 | " {\n" + 176 | " \"kind\": \"FirstTypeNode\",\n" + 177 | " \"typeName\": {\n" + 178 | " \"text\": \"T\"\n" + 179 | " },\n" + 180 | " \"type\": [\n" + 181 | " ],\n" + 182 | " \"types\": [\n" + 183 | " ],\n" + 184 | " \"typeArguments\": [\n" + 185 | " ],\n" + 186 | " \"parameters\": [\n" + 187 | " ],\n" + 188 | " \"elementType\": [\n" + 189 | " ],\n" + 190 | " \"members\": [\n" + 191 | " ]\n" + 192 | " }\n" + 193 | " ],\n" + 194 | " \"parameters\": [\n" + 195 | " ],\n" + 196 | " \"elementType\": [\n" + 197 | " ],\n" + 198 | " \"members\": [\n" + 199 | " ]\n" + 200 | " },\n" + 201 | " {\n" + 202 | " \"kind\": \"FirstTypeNode\",\n" + 203 | " \"typeName\": {\n" + 204 | " \"text\": \"T\"\n" + 205 | " },\n" + 206 | " \"type\": [\n" + 207 | " ],\n" + 208 | " \"types\": [\n" + 209 | " ],\n" + 210 | " \"typeArguments\": [\n" + 211 | " ],\n" + 212 | " \"parameters\": [\n" + 213 | " ],\n" + 214 | " \"elementType\": [\n" + 215 | " ],\n" + 216 | " \"members\": [\n" + 217 | " ]\n" + 218 | " }\n" + 219 | " ],\n" + 220 | " \"typeArguments\": [\n" + 221 | " ],\n" + 222 | " \"parameters\": [\n" + 223 | " ],\n" + 224 | " \"elementType\": [\n" + 225 | " ],\n" + 226 | " \"members\": [\n" + 227 | " ]\n" + 228 | " }\n" + 229 | " ],\n" + 230 | " \"types\": [\n" + 231 | " ],\n" + 232 | " \"typeArguments\": [\n" + 233 | " ],\n" + 234 | " \"parameters\": [\n" + 235 | " {\n" + 236 | " \"name\": {\n" + 237 | " \"text\": \"response\"\n" + 238 | " },\n" + 239 | " \"type\": {\n" + 240 | " \"kind\": \"FirstTypeNode\",\n" + 241 | " \"typeName\": {\n" + 242 | " \"text\": \"IHttpPromiseCallbackArg\"\n" + 243 | " },\n" + 244 | " \"type\": [\n" + 245 | " ],\n" + 246 | " \"types\": [\n" + 247 | " ],\n" + 248 | " \"typeArguments\": [\n" + 249 | " {\n" + 250 | " \"kind\": \"FirstTypeNode\",\n" + 251 | " \"typeName\": {\n" + 252 | " \"text\": \"T\"\n" + 253 | " },\n" + 254 | " \"type\": [\n" + 255 | " ],\n" + 256 | " \"types\": [\n" + 257 | " ],\n" + 258 | " \"typeArguments\": [\n" + 259 | " ],\n" + 260 | " \"parameters\": [\n" + 261 | " ],\n" + 262 | " \"elementType\": [\n" + 263 | " ],\n" + 264 | " \"members\": [\n" + 265 | " ]\n" + 266 | " }\n" + 267 | " ],\n" + 268 | " \"parameters\": [\n" + 269 | " ],\n" + 270 | " \"elementType\": [\n" + 271 | " ],\n" + 272 | " \"members\": [\n" + 273 | " ]\n" + 274 | " },\n" + 275 | " \"questionToken\": null,\n" + 276 | " \"dotDotDotToken\": null\n" + 277 | " }\n" + 278 | " ]\n" + 279 | "}"; 280 | Type astType = Models.parse(ctx, Type.class, new ByteArrayInputStream(type.getBytes())); 281 | assertEquals("Type variable T is there", "T", astType.getType().get(0).getTypes().get(0).getTypeArguments().get(0).getTypeName().getSimpleName()); 282 | astType.anonimize(); 283 | assertEquals("Type variable has been anonymized", "?", astType.getType().get(0).getTypes().get(0).getTypeArguments().get(0).getTypeName().getSimpleName()); 284 | } 285 | } 286 | -------------------------------------------------------------------------------- /mojo-base/src/test/java/com/dukescript/libraries/proc/ParserTest.java: -------------------------------------------------------------------------------- 1 | package com.dukescript.libraries.proc; 2 | 3 | /* 4 | * #%L 5 | * DukeScript Libraries Processor - a library from the DukeScript project. 6 | * Visit http://dukescript.com for support and commercial license. 7 | * %% 8 | * Copyright (C) 2015 Eppleton IT Consulting 9 | * %% 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as 12 | * published by the Free Software Foundation, either version 3 of the 13 | * License, or (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public 21 | * License along with this program. If not, see 22 | * . 23 | * #L% 24 | */ 25 | 26 | import java.io.IOException; 27 | 28 | import java.io.InputStream; 29 | import java.util.ArrayList; 30 | import java.util.LinkedHashMap; 31 | import java.util.List; 32 | import java.util.Map; 33 | import java.util.Set; 34 | import org.junit.Assert; 35 | import static org.junit.Assert.fail; 36 | import org.junit.BeforeClass; 37 | import org.junit.Test; 38 | 39 | public class ParserTest { 40 | private static AST ast; 41 | 42 | public ParserTest() { 43 | } 44 | 45 | @BeforeClass 46 | public static void initializeParser() throws Exception { 47 | Parser p = new Parser(); 48 | 49 | InputStream is = p.getClass().getClassLoader().getResourceAsStream("com/dukescript/libraries/proc/lib.core.d.ts"); 50 | assertNotNull(is); 51 | 52 | ast = p.parse("lib.core.d.ts", is); 53 | assertNotNull(ast, "AST created"); 54 | } 55 | 56 | @Test 57 | public void searchForFields() throws Exception { 58 | final AST first = ast.getChildren().get(0); 59 | assertEquals(first.getKind(), SyntaxKind.VariableStatement, "First object is variable"); 60 | List declarations = first.getDeclarationList().getDeclarations(); 61 | assertEquals(declarations.size(), 1, "One declaration"); 62 | AST var = declarations.get(0); 63 | assertEquals(var.getName().getSimpleName(), "NaN", "not a number is the name"); 64 | assertEquals(var.getType().getKind(), SyntaxKind.NumberKeyword); 65 | 66 | class Fields implements Visitor, Void, String, Void> { 67 | Map found = new LinkedHashMap<>(); 68 | 69 | @Override 70 | public void visit(Identifier a, Type b, Set c, Void d, String e, Void f) { 71 | Type prev = found.put(a.getSimpleName(), b); 72 | assertNull(prev, "No previous value"); 73 | } 74 | } 75 | 76 | Fields visitor = new Fields(); 77 | ast.visitFields(visitor); 78 | 79 | Map.Entry field1 = visitor.found.entrySet().iterator().next(); 80 | assertEquals(field1.getKey(), "NaN", "not a number"); 81 | assertEquals(field1.getValue().getKind(), SyntaxKind.NumberKeyword); 82 | 83 | Type objectType = visitor.found.get("Object"); 84 | assertNull(objectType, "Field with ObjectConstructor type not visited"); 85 | } 86 | 87 | @Test 88 | public void searchForFunctions() { 89 | class Functions implements Visitor, List, String, Void> { 90 | Map> found = new LinkedHashMap<>(); 91 | @Override 92 | public void visit(Identifier a, Type b, List c, List d, String e, Void ignore) { 93 | List prev = found.put(a.getSimpleName(), c); 94 | assertNull(prev, "No previous value"); 95 | } 96 | } 97 | Functions f = new Functions(); 98 | ast.visitFunctions(f); 99 | assertEquals(f.found.get("eval").get(0).getType().getKind(), SyntaxKind.StringKeyword); 100 | 101 | List parseInt = f.found.get("parseInt"); 102 | assertEquals(parseInt.size(), 2, "Two parameters"); 103 | assertFalse(parseInt.get(0).isOptional(), "First is not optional"); 104 | assertTrue(parseInt.get(1).isOptional(), "Second is optional"); 105 | } 106 | 107 | @Test 108 | public void searchForErrorDefinition() { 109 | class Interfaces implements Visitor, List, AST, List, Map>> { 110 | boolean found; 111 | List properties; 112 | AST constructor; 113 | List heritages; 114 | @Override 115 | public void visit(Identifier a, List c, List d, AST constructor, List herigateClauses, Map> ignore) throws IOException { 116 | final String name = a.getSimpleName(); 117 | if (name.endsWith("Constructor")) { 118 | fail("There should be no constructors in the interfaces: " + name); 119 | } 120 | if ("Error".equals(name)) { 121 | assertFalse(found, "Just one error"); 122 | found = true; 123 | this.properties = d; 124 | this.constructor = constructor; 125 | } 126 | if ("TypeError".equals(name)) { 127 | this.heritages = herigateClauses; 128 | } 129 | } 130 | } 131 | Interfaces interfaces = new Interfaces(); 132 | ast.visitInterfaces(interfaces); 133 | assertTrue(interfaces.found, "Interfaces found"); 134 | assertEquals(interfaces.properties.size(), 2, "Two props"); 135 | assertEquals(interfaces.properties.get(0).getName().getSimpleName(), "name", "1st name is name"); 136 | assertEquals(interfaces.properties.get(1).getName().getSimpleName(), "message", "2nd name is messsage"); 137 | assertNotNull(interfaces.constructor, "Constructor class reference provided"); 138 | assertNotNull(interfaces.heritages); 139 | assertEquals(interfaces.heritages.size(), 1, "One element: " + interfaces.heritages); 140 | assertEquals("Error", interfaces.heritages.get(0).getTypes().get(0).getExpression().get(0).getText()); 141 | } 142 | 143 | @Test 144 | public void oneConcatInArray() { 145 | class SeekArray implements Visitor, List, AST, List, Map>> { 146 | List array; 147 | @Override 148 | public void visit(Identifier a, List parameterTypes, List members, AST constructor, List herigateClauses, Map> ignore) throws IOException { 149 | final String name = a.getSimpleName(); 150 | if (name.equals("Array")) { 151 | assertNull(array, "Just one definition of Array expected"); 152 | array = members; 153 | } 154 | } 155 | } 156 | SeekArray interfaces = new SeekArray(); 157 | ast.visitInterfaces(interfaces); 158 | assertNotNull(interfaces.array, "Array found"); 159 | int concatCount = 0; 160 | int spliceCount = 0; 161 | StringBuilder found = new StringBuilder(); 162 | for (AST m : interfaces.array) { 163 | found.append(m.getName()).append("\n"); 164 | if (m.getName() != null && "concat".equals(m.getName().getSimpleName())) { 165 | concatCount++; 166 | } 167 | if (m.getName() != null && "splice".equals(m.getName().getSimpleName())) { 168 | spliceCount++; 169 | } 170 | } 171 | assertEquals(concatCount, 1, "One concat method found: " + found); 172 | assertEquals(spliceCount, 2, "Two splice methods found: " + found); 173 | } 174 | 175 | @Test 176 | public void arrayConstructors() { 177 | class SeekArray implements Visitor, List, AST, List, Map>> { 178 | AST arrayConstructor; 179 | @Override 180 | public void visit(Identifier a, List parameterTypes, List members, AST constructor, List herigateClauses, Map> ignore) throws IOException { 181 | final String name = a.getSimpleName(); 182 | if (name.equals("Array")) { 183 | assertNull(arrayConstructor, "Just one definition of Array expected"); 184 | arrayConstructor = constructor; 185 | } 186 | } 187 | } 188 | SeekArray interfaces = new SeekArray(); 189 | ast.visitInterfaces(interfaces); 190 | assertNotNull(interfaces.arrayConstructor, "Array found"); 191 | 192 | List constructors = new ArrayList<>(); 193 | for (AST m : interfaces.arrayConstructor.getMembers()) { 194 | if (m.getKind() != SyntaxKind.ConstructSignature) { 195 | continue; 196 | } 197 | constructors.add(m); 198 | } 199 | assertEquals(constructors.size(), 2, "Two constructors found"); 200 | final List first = constructors.get(0).getParameters(); 201 | assertEquals(first.size(), 1, "One argument 1st"); 202 | final List second = constructors.get(1).getParameters(); 203 | assertEquals(second.size(), 1, "One argument 2nd"); 204 | assertNotEquals(second.get(0).isOptional(), second.get(0).isVararg(), "One vararg" + second); 205 | assertNotEquals(first.get(0).isOptional(), first.get(0).isVararg(), "One optional" + first); 206 | } 207 | 208 | private static void assertNotNull(Object obj) { 209 | Assert.assertNotNull(obj); 210 | } 211 | private static void assertNotNull(Object obj, String msg) { 212 | Assert.assertNotNull(msg, obj); 213 | } 214 | private static void assertNull(Object obj) { 215 | Assert.assertNull(obj); 216 | } 217 | private static void assertNull(Object obj, String msg) { 218 | Assert.assertNull(msg, obj); 219 | } 220 | 221 | private void assertEquals(Object actual, Object expected) { 222 | Assert.assertEquals(expected, actual); 223 | } 224 | private static void assertEquals(Object actual, Object expected, String msg) { 225 | Assert.assertEquals(msg, expected, actual); 226 | } 227 | private static void assertNotEquals(Object actual, Object expected, String msg) { 228 | Assert.assertNotEquals(msg, expected, actual); 229 | } 230 | 231 | private static void assertFalse(boolean value, String msg) { 232 | Assert.assertFalse(msg, value); 233 | } 234 | 235 | private void assertTrue(boolean value, String msg) { 236 | Assert.assertTrue(msg, value); 237 | } 238 | } 239 | -------------------------------------------------------------------------------- /mojo-test/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 24 | 25 | 26 | 4.0.0 27 | 28 | com.dukescript.libraries 29 | pom 30 | 1.0-SNAPSHOT 31 | 32 | mojo-test 33 | Maven Typings Plugin Tests 34 | jar 35 | 36 | 37 | 38 | org.netbeans.html 39 | html4j-maven-plugin 40 | ${net.java.html.version} 41 | 42 | 43 | js-classes 44 | 45 | process-js-annotations 46 | 47 | 48 | 49 | 50 | 51 | org.apache.maven.plugins 52 | maven-compiler-plugin 53 | 2.3.1 54 | 55 | 1.8 56 | 1.8 57 | 58 | 59 | 60 | com.dukescript.libraries 61 | typings-maven-plugin 62 | ${project.version} 63 | 64 | 65 | generate-ns 66 | 67 | generate 68 | 69 | 70 | src/main/resources/com/dukescript/libraries/ap/test/ns/mod.ts 71 | 72 | 73 | 74 | com.dukescript.libraries.ap.test.ns 75 | 76 | 77 | 78 | generate-constructors 79 | 80 | generate 81 | 82 | 83 | src/main/resources/com/dukescript/libraries/ap/test/constructors/hello.ts 84 | 85 | 86 | 87 | com.dukescript.libraries.ap.test.constructors 88 | 89 | 90 | 91 | generate-fn 92 | 93 | generate 94 | 95 | 96 | src/main/resources/com/dukescript/libraries/ap/test/fn/fn.ts 97 | 98 | 99 | 100 | com.dukescript.libraries.ap.test.fn 101 | 102 | 103 | 104 | generate-arr 105 | 106 | generate 107 | 108 | 109 | src/main/resources/com/dukescript/libraries/ap/test/arr/arr.ts 110 | 111 | 112 | 113 | com.dukescript.libraries.ap.test.arr 114 | 115 | 116 | 117 | generate-hello 118 | 119 | generate 120 | 121 | 122 | src/main/resources/com/dukescript/libraries/ap/test/hello/hello.ts 123 | 124 | 125 | 126 | com.dukescript.libraries.ap.test.hello 127 | 128 | 129 | 130 | 131 | 132 | org.sonatype.plugins 133 | nexus-staging-maven-plugin 134 | 135 | true 136 | 137 | 138 | 139 | 140 | 141 | 142 | org.netbeans.html 143 | net.java.html.boot.script 144 | ${net.java.html.version} 145 | test 146 | 147 | 148 | com.dukescript.api 149 | junit-browser-runner 150 | 151 | 152 | ${project.groupId} 153 | net.java.html.lib 154 | ${project.version} 155 | 156 | 157 | 158 | 1.8 159 | 1.8 160 | 161 | -------------------------------------------------------------------------------- /mojo-test/src/main/resources/com/dukescript/libraries/ap/test/arr/arr.js: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * #%L 4 | * DukeScript Libraries Processor - a library from the DukeScript project. 5 | * Visit http://dukescript.com for support and commercial license. 6 | * %% 7 | * Copyright (C) 2015 Eppleton IT Consulting 8 | * %% 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public 20 | * License along with this program. If not, see 21 | * . 22 | * #L% 23 | */ 24 | 25 | function square(lx, ly, size) { 26 | return [ 27 | { x : lx, y : ly }, 28 | { x : lx + size, y : ly }, 29 | { x : lx, y : ly + size }, 30 | { x : lx + size, y : ly + size } 31 | ]; 32 | } 33 | 34 | function squareList(lx, ly, size) { 35 | var value = square(lx, ly, size); 36 | var ret = { 37 | nav : function(at) { return value[at]; } 38 | }; 39 | for (var i in value) { 40 | ret[i] = value[i]; 41 | } 42 | return ret; 43 | } 44 | 45 | function squareNav(lx, ly, size) { 46 | var value = square(lx, ly, size); 47 | return { 48 | nav : function(at) { return value[at]; } 49 | }; 50 | } 51 | 52 | function singletonArray() { 53 | return { 54 | nav: function(p) { return [p]; } 55 | }; 56 | } 57 | 58 | function navigableArray() { 59 | return { 60 | nav: function(n) { return [n]; } 61 | }; 62 | } -------------------------------------------------------------------------------- /mojo-test/src/main/resources/com/dukescript/libraries/ap/test/arr/arr.ts: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * #%L 4 | * DukeScript Libraries Processor - a library from the DukeScript project. 5 | * Visit http://dukescript.com for support and commercial license. 6 | * %% 7 | * Copyright (C) 2015 Eppleton IT Consulting 8 | * %% 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public 20 | * License along with this program. If not, see 21 | * . 22 | * #L% 23 | */ 24 | 25 | interface Point { 26 | x: number; 27 | y: number; 28 | } 29 | 30 | declare function square(lx : number, ly: number, size: number): Array; 31 | 32 | interface Navigable { 33 | nav(index: K) : V; 34 | } 35 | 36 | interface List extends Navigable { 37 | [index: number]: T; 38 | } 39 | 40 | declare function squareNav(lx : number, ly: number, size: number): Navigable; 41 | declare function squareList(lx : number, ly: number, size: number): List; 42 | 43 | interface MapSingle extends Navigable> { 44 | } 45 | 46 | declare function singletonArray(): MapSingle; 47 | 48 | interface NavArr extends Navigable { 49 | } 50 | 51 | declare function navigableArray(): NavArr; 52 | -------------------------------------------------------------------------------- /mojo-test/src/main/resources/com/dukescript/libraries/ap/test/constructors/hello.js: -------------------------------------------------------------------------------- 1 | /* 2 | * #%L 3 | * Annotation Processor Tests - a library from the DukeScript project. 4 | * Visit http://dukescript.com for support and commercial license. 5 | * %% 6 | * Copyright (C) 2015 - 2016 Dukehoff GmbH 7 | * %% 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as 10 | * published by the Free Software Foundation, either version 3 of the 11 | * License, or (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public 19 | * License along with this program. If not, see 20 | * . 21 | * #L% 22 | */ 23 | 24 | var compute = eval; 25 | 26 | function emptyVector() { 27 | return []; 28 | } 29 | 30 | function addVector(v, y) { 31 | return v.concat([y]); 32 | } 33 | 34 | function StringStack(next){ 35 | this.name = "Ahoj"; 36 | this.stack = []; 37 | this.next = next; 38 | } 39 | StringStack.prototype.push = function(item) { 40 | this.stack.push(item); 41 | }; 42 | StringStack.prototype.pop = function() { 43 | return this.stack.pop(); 44 | }; 45 | StringStack.prototype.lengths = function() { 46 | var arr = []; 47 | for (var i = 0; i < this.stack.length; i++) { 48 | arr.push(this.stack[i].length()); 49 | } 50 | return arr; 51 | }; 52 | 53 | var Attr = function() { 54 | return this; 55 | }; 56 | Attr.prototype = Object.prototype; 57 | 58 | var AttrValueInitialized = 1; 59 | var UnionInitialized = true; 60 | 61 | var singletonNumber = { 62 | value: function(x, y) { 63 | return x + y; 64 | } 65 | }; 66 | 67 | var firstValue = function() { 68 | return function(x, y) { 69 | return x; 70 | }; 71 | }; 72 | 73 | var ab = { 74 | b: { 75 | a: { 76 | b: "Hi" 77 | } 78 | } 79 | }; 80 | function fAB() { 81 | return ab; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /mojo-test/src/main/resources/com/dukescript/libraries/ap/test/constructors/hello.ts: -------------------------------------------------------------------------------- 1 | 2 | declare function compute(x: string): any; 3 | 4 | declare function emptyVector(): Array; 5 | declare function addVector(v : Array, ...e : number): Array; 6 | 7 | export class StringStack { 8 | constructor(); 9 | constructor(next?: StringStack); 10 | push(item : String): void; 11 | pop(): String; 12 | lengths(): number[]; 13 | name: String; 14 | next: StringStack; 15 | } 16 | 17 | interface Attr { 18 | } 19 | declare var Attr: { 20 | prototype: Attr; 21 | new(): Attr; 22 | } 23 | declare var attr: Attr; 24 | declare var AttrValue: number; 25 | declare var AttrValueInitialized: number; 26 | declare var UnionInitialized: number | boolean | string; 27 | 28 | interface Get { 29 | (x: T, y: T): T; 30 | } 31 | 32 | interface SingletonNumber { 33 | value: Get; 34 | } 35 | declare var singletonNumber: SingletonNumber; 36 | 37 | interface FirstValue { 38 | (value?: T): Get;; 39 | } 40 | declare var firstValue: FirstValue; 41 | 42 | type AB = A | B | string; 43 | interface A { 44 | b: AB; 45 | } 46 | 47 | interface B { 48 | a: AB; 49 | } 50 | 51 | declare var ab : AB; 52 | 53 | declare function fAB(): AB; 54 | -------------------------------------------------------------------------------- /mojo-test/src/main/resources/com/dukescript/libraries/ap/test/fn/fn.js: -------------------------------------------------------------------------------- 1 | /* 2 | * #%L 3 | * Annotation Processor Tests - a library from the DukeScript project. 4 | * Visit http://dukescript.com for support and commercial license. 5 | * %% 6 | * Copyright (C) 2015 - 2016 Dukehoff GmbH 7 | * %% 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as 10 | * published by the Free Software Foundation, either version 3 of the 11 | * License, or (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public 19 | * License along with this program. If not, see 20 | * . 21 | * #L% 22 | */ 23 | function compose(f, g) { 24 | return function(x) { 25 | return g(f(x)); 26 | }; 27 | } 28 | 29 | var fn = function() { 30 | if (arguments.length === 0) { 31 | return "Hi"; 32 | } else { 33 | return "Length" + arguments[0]; 34 | } 35 | }; 36 | fn.fourtyTwo = 42; 37 | fn.FnT = fn; 38 | fn.first = function(first, next) { 39 | return first; 40 | }; 41 | 42 | var fnT = fn; 43 | 44 | var rev = { 45 | }; 46 | rev.reverse = function(arr) { 47 | var ret = new Array(arr.length); 48 | for (var i = 0; i < arr.length; i++) { 49 | ret[i] = arr[arr.length - 1 - i]; 50 | } 51 | return ret; 52 | }; 53 | rev.notify = function() { return 42; }; 54 | 55 | function literal(s) { 56 | switch (s) { 57 | case 'boolean': return true; 58 | case 'number': return 1; 59 | } 60 | return false; 61 | } 62 | 63 | var scope = { 64 | $compute : function(c) { return c(scope); } 65 | }; 66 | 67 | var oneOf = "two"; 68 | var oneFn = function(id) { 69 | return id; 70 | }; 71 | 72 | function tripple() { 73 | return [1, "Hi", true]; 74 | } 75 | -------------------------------------------------------------------------------- /mojo-test/src/main/resources/com/dukescript/libraries/ap/test/fn/fn.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | declare function compose(f : (v : A) => B, g : (v : B) => C) : (A) => C; 4 | 5 | var fn : { 6 | (): string; 7 | (x: number): string; 8 | fourtyTwo: number; 9 | }; 10 | 11 | interface FnT { 12 | (): string; 13 | (x: number): string; 14 | fourtyTwo: number; 15 | FnT: FnT; 16 | first(x: number, name?: string): number; 17 | first(y: number, count?: number): number; 18 | first(z: string, name?: string): string; 19 | } 20 | var fnT : FnT; 21 | 22 | interface Rev { 23 | reverse: (arr: Array) => Array; 24 | notify(x?: number): number; 25 | } 26 | var rev: Rev; 27 | 28 | interface Literal { 29 | (name: 'number'): number; 30 | (name: 'boolean'): boolean; 31 | (name: string): boolean; 32 | tripple: [number, string, boolean]; 33 | } 34 | var literal: Literal; 35 | 36 | type OneOf = string | number; 37 | var oneOf: OneOf; 38 | declare function oneFn(x: OneOf): OneOf; 39 | 40 | interface IScope { 41 | $compute(callback : (scope: IScope) => T): T; 42 | } 43 | var scope: IScope; 44 | 45 | interface Watch { 46 | $watch(watchExpression: (scope: IScope) => any, listener?: string): Function; 47 | $watch(watchExpression: (scope: IScope) => T, listener?: (newValue: T, oldValue: T, scope: IScope) => any): Function; 48 | } 49 | 50 | declare function tripple(): [number, string, boolean]; 51 | -------------------------------------------------------------------------------- /mojo-test/src/main/resources/com/dukescript/libraries/ap/test/hello/hello.js: -------------------------------------------------------------------------------- 1 | /* 2 | * #%L 3 | * Annotation Processor Tests - a library from the DukeScript project. 4 | * Visit http://dukescript.com for support and commercial license. 5 | * %% 6 | * Copyright (C) 2015 - 2016 Dukehoff GmbH 7 | * %% 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as 10 | * published by the Free Software Foundation, either version 3 of the 11 | * License, or (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public 19 | * License along with this program. If not, see 20 | * . 21 | * #L% 22 | */ 23 | 24 | var compute = eval; 25 | 26 | function emptyVector() { 27 | return []; 28 | } 29 | 30 | function addVector(v, y) { 31 | return v.concat([y]); 32 | } 33 | 34 | function StringStack(next){ 35 | this.name = "Ahoj"; 36 | this.stack = []; 37 | this.next = next; 38 | } 39 | StringStack.prototype.push = function(item) { 40 | this.stack.push(item); 41 | }; 42 | StringStack.prototype.pop = function() { 43 | return this.stack.pop(); 44 | }; 45 | StringStack.prototype.lengths = function() { 46 | var arr = []; 47 | for (var i = 0; i < this.stack.length; i++) { 48 | arr.push(this.stack[i].length); 49 | } 50 | return arr; 51 | }; 52 | 53 | var Attr = function() { 54 | return this; 55 | }; 56 | Attr.prototype = Object.prototype; 57 | 58 | var AttrValueInitialized = 1; 59 | var UnionInitialized = true; 60 | 61 | var singletonNumber = { 62 | value: function(x, y) { 63 | return x + y; 64 | } 65 | }; 66 | 67 | var firstValue = function() { 68 | return function(x, y) { 69 | return x; 70 | }; 71 | }; 72 | 73 | var ab = { 74 | b: { 75 | a: { 76 | b: "Hi" 77 | } 78 | } 79 | }; 80 | function fAB() { 81 | return ab; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /mojo-test/src/main/resources/com/dukescript/libraries/ap/test/hello/hello.ts: -------------------------------------------------------------------------------- 1 | 2 | declare function compute(x: string): any; 3 | 4 | declare function emptyVector(): Array; 5 | declare function addVector(v : Array, ...e : number): Array; 6 | 7 | export class StringStack { 8 | constructor(next?: StringStack); 9 | push(item : String): void; 10 | pop(): String; 11 | lengths(): number[]; 12 | name: String; 13 | next: StringStack; 14 | } 15 | 16 | interface Attr { 17 | } 18 | declare var Attr: { 19 | prototype: Attr; 20 | new(): Attr; 21 | } 22 | declare var attr: Attr; 23 | declare var AttrValue: number; 24 | declare var AttrValueInitialized: number; 25 | declare var UnionInitialized: number | boolean | string; 26 | 27 | interface Get { 28 | (x: T, y: T): T; 29 | } 30 | 31 | interface SingletonNumber { 32 | value: Get; 33 | } 34 | declare var singletonNumber: SingletonNumber; 35 | 36 | interface FirstValue { 37 | (value?: T): Get; 38 | } 39 | declare var firstValue: FirstValue; 40 | 41 | type AB = A | B | string; 42 | interface A { 43 | b: AB; 44 | } 45 | 46 | interface B { 47 | a: AB; 48 | } 49 | 50 | declare var ab : AB; 51 | 52 | declare function fAB(): AB; 53 | -------------------------------------------------------------------------------- /mojo-test/src/main/resources/com/dukescript/libraries/ap/test/ns/mod-amd.js: -------------------------------------------------------------------------------- 1 | /* 2 | * #%L 3 | * Annotation Processor Tests - a library from the DukeScript project. 4 | * Visit http://dukescript.com for support and commercial license. 5 | * %% 6 | * Copyright (C) 2015 - 2016 Dukehoff GmbH 7 | * %% 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as 10 | * published by the Free Software Foundation, either version 3 of the 11 | * License, or (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public 19 | * License along with this program. If not, see 20 | * . 21 | * #L% 22 | */ 23 | var __extends = (this && this.__extends) || function (d, b) { 24 | for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; 25 | function __() { this.constructor = d; } 26 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 27 | }; 28 | 29 | function define(deps, fn) { 30 | fn(null, this); 31 | } 32 | 33 | define(["require", "exports"], function (require, exports) { 34 | var geo; 35 | (function (geo) { 36 | var Circle = (function () { 37 | function Circle() { 38 | } 39 | return Circle; 40 | })(); 41 | geo.Circle = Circle; 42 | var Elipse = (function (_super) { 43 | __extends(Elipse, _super); 44 | function Elipse() { 45 | _super.apply(this, arguments); 46 | } 47 | return Elipse; 48 | })(Circle); 49 | geo.Elipse = Elipse; 50 | geo.createCircle = function() { 51 | geo.countCircle++; 52 | return new Circle(); 53 | }; 54 | geo.countCircle = 0; 55 | })(geo = exports.geo || (exports.geo = {})); 56 | 57 | exports.math = { 58 | hello : function () { 59 | return "Hello"; 60 | } 61 | }; 62 | }); 63 | -------------------------------------------------------------------------------- /mojo-test/src/main/resources/com/dukescript/libraries/ap/test/ns/mod.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * #%L 3 | * Annotation Processor Tests - a library from the DukeScript project. 4 | * Visit http://dukescript.com for support and commercial license. 5 | * %% 6 | * Copyright (C) 2015 - 2016 Dukehoff GmbH 7 | * %% 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as 10 | * published by the Free Software Foundation, either version 3 of the 11 | * License, or (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public 19 | * License along with this program. If not, see 20 | * . 21 | * #L% 22 | */ 23 | 24 | export var circle: geo.Circle; 25 | export var geo: any; 26 | 27 | export module geo { 28 | export class Circle { 29 | } 30 | export class Elipse extends Circle { 31 | } 32 | export function createCircle(): Circle; 33 | export var countCircle: number; 34 | } 35 | 36 | declare var math: math.MathStatic; 37 | declare namespace math { 38 | interface MathStatic { 39 | hello(): ComNum; 40 | } 41 | export module complex { 42 | interface ComNum { 43 | toString(): String; 44 | } 45 | } 46 | } 47 | 48 | export module geo2d { 49 | import * as geo from "geo"; 50 | export interface Elipse extends geo.Elipse { 51 | } 52 | } 53 | 54 | export module geo3d { 55 | import * as geo from "geo"; 56 | export interface Elipse extends math.complex.ComNum, geo.Elipse { 57 | } 58 | } 59 | 60 | export module geo3dplus { 61 | import * as geo3d from "geo3d"; 62 | export interface Elipse extends geo3d.Elipse { 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /mojo-test/src/test/java/com/dukescript/libraries/ap/test/arr/ArrTest.java: -------------------------------------------------------------------------------- 1 | package com.dukescript.libraries.ap.test.arr; 2 | 3 | /* 4 | * #%L 5 | * DukeScript Libraries Processor - a library from the DukeScript project. 6 | * Visit http://dukescript.com for support and commercial license. 7 | * %% 8 | * Copyright (C) 2015 Eppleton IT Consulting 9 | * %% 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as 12 | * published by the Free Software Foundation, either version 3 of the 13 | * License, or (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public 21 | * License along with this program. If not, see 22 | * . 23 | * #L% 24 | */ 25 | 26 | import net.java.html.junit.BrowserRunner; 27 | import net.java.html.lib.Array; 28 | import static org.junit.Assert.assertEquals; 29 | import org.junit.Test; 30 | import org.junit.runner.RunWith; 31 | 32 | @RunWith(BrowserRunner.class) 33 | public class ArrTest { 34 | @Test 35 | public void unitSquare() { 36 | Array corners = Exports.square(0, 0, 1); 37 | 38 | assertEquals(0, corners.$get(0).x().doubleValue(), 0.1); 39 | assertEquals(0, corners.$get(0).y().doubleValue(), 0.1); 40 | 41 | assertEquals(1, corners.$get(1).x().doubleValue(), 0.1); 42 | assertEquals(0, corners.$get(1).y().doubleValue(), 0.1); 43 | 44 | assertEquals(0, corners.$get(2).x().doubleValue(), 0.1); 45 | assertEquals(1, corners.$get(2).y().doubleValue(), 0.1); 46 | 47 | assertEquals(1, corners.$get(3).x().doubleValue(), 0.1); 48 | assertEquals(1, corners.$get(3).y().doubleValue(), 0.1); 49 | } 50 | 51 | @Test 52 | public void unitSquareNavigable() { 53 | Navigable corners = Exports.squareNav(0, 0, 1); 54 | assertNavigableUnitSquare(corners); 55 | } 56 | 57 | private static void assertNavigableUnitSquare(Navigable corners) { 58 | assertEquals(0, corners.nav(0).x().doubleValue(), 0.1); 59 | assertEquals(0, corners.nav(0).y().doubleValue(), 0.1); 60 | 61 | assertEquals(1, corners.nav(1).x().doubleValue(), 0.1); 62 | assertEquals(0, corners.nav(1).y().doubleValue(), 0.1); 63 | 64 | assertEquals(0, corners.nav(2).x().doubleValue(), 0.1); 65 | assertEquals(1, corners.nav(2).y().doubleValue(), 0.1); 66 | 67 | assertEquals(1, corners.nav(3).x().doubleValue(), 0.1); 68 | assertEquals(1, corners.nav(3).y().doubleValue(), 0.1); 69 | } 70 | 71 | @Test 72 | public void unitSquareList() { 73 | List corners = Exports.squareList(0, 0, 1); 74 | 75 | assertEquals(0, corners.$get(0).x().doubleValue(), 0.1); 76 | assertEquals(0, corners.$get(0).y().doubleValue(), 0.1); 77 | 78 | assertEquals(1, corners.$get(1).x().doubleValue(), 0.1); 79 | assertEquals(0, corners.$get(1).y().doubleValue(), 0.1); 80 | 81 | assertEquals(0, corners.$get(2).x().doubleValue(), 0.1); 82 | assertEquals(1, corners.$get(2).y().doubleValue(), 0.1); 83 | 84 | assertEquals(1, corners.$get(3).x().doubleValue(), 0.1); 85 | assertEquals(1, corners.$get(3).y().doubleValue(), 0.1); 86 | 87 | assertNavigableUnitSquare(corners); 88 | } 89 | 90 | @Test 91 | public void singletonArray() { 92 | MapSingle map = Exports.singletonArray(); 93 | Array corners = Exports.square(0, 0, 10); 94 | final Point lastOne = corners.$get(corners.length() - 1); 95 | Array lastArr = Array.$as(map.nav(lastOne), Point.class); 96 | 97 | assertEquals(1, lastArr.length()); 98 | assertEquals(lastOne.x().doubleValue(), lastArr.$get(0).x().doubleValue(), 0.1); 99 | assertEquals(lastOne.y().doubleValue(), lastArr.$get(0).y().doubleValue(), 0.1); 100 | } 101 | 102 | @Test 103 | public void navigableArray() { 104 | NavArr arr = Exports.navigableArray(); 105 | Array res = arr.nav(42); 106 | assertEquals(1, res.length()); 107 | assertEquals(42, res.$get(0)); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /mojo-test/src/test/java/com/dukescript/libraries/ap/test/constructors/DuplicateConstructorDefinitionsTest.java: -------------------------------------------------------------------------------- 1 | package com.dukescript.libraries.ap.test.constructors; 2 | 3 | /* 4 | * #%L 5 | * Annotation Processor Tests - a library from the DukeScript project. 6 | * Visit http://dukescript.com for support and commercial license. 7 | * %% 8 | * Copyright (C) 2015 - 2016 Dukehoff GmbH 9 | * %% 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as 12 | * published by the Free Software Foundation, either version 3 of the 13 | * License, or (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public 21 | * License along with this program. If not, see 22 | * . 23 | * #L% 24 | */ 25 | 26 | 27 | import net.java.html.junit.BrowserRunner; 28 | import static org.junit.Assert.*; 29 | import org.junit.Test; 30 | import org.junit.runner.RunWith; 31 | 32 | @RunWith(BrowserRunner.class) 33 | public class DuplicateConstructorDefinitionsTest { 34 | @Test 35 | public void testEvalObject() throws Exception { 36 | // Just do something with the generated stuff 37 | StringStack stringStack = new StringStack(); 38 | assertNotNull("No Object created", stringStack); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /mojo-test/src/test/java/com/dukescript/libraries/ap/test/fn/FnTest.java: -------------------------------------------------------------------------------- 1 | package com.dukescript.libraries.ap.test.fn; 2 | 3 | /* 4 | * #%L 5 | * Annotation Processor Tests - a library from the DukeScript project. 6 | * Visit http://dukescript.com for support and commercial license. 7 | * %% 8 | * Copyright (C) 2015 - 2016 Dukehoff GmbH 9 | * %% 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as 12 | * published by the Free Software Foundation, either version 3 of the 13 | * License, or (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public 21 | * License along with this program. If not, see 22 | * . 23 | * #L% 24 | */ 25 | 26 | import net.java.html.lib.Function; 27 | import net.java.html.lib.Objs; 28 | import net.java.html.junit.BrowserRunner; 29 | import net.java.html.lib.Union; 30 | import static org.junit.Assert.assertEquals; 31 | import static org.junit.Assert.assertNotNull; 32 | import static org.junit.Assert.assertTrue; 33 | import org.junit.Test; 34 | import org.junit.runner.RunWith; 35 | 36 | @RunWith(BrowserRunner.class) 37 | public class FnTest { 38 | @Test 39 | public void workWithFunctions() { 40 | Function.A1 f = Math::abs; 41 | Function.A1 g = Integer::toHexString; 42 | Function.A1 h = Exports.compose(f, g); 43 | 44 | assertEquals("ff", h.call(-255)); 45 | 46 | Function raw = (Function) h; 47 | assertEquals("f", raw.apply(null, -15)); 48 | } 49 | 50 | 51 | @Test 52 | public void functionWithProperties() { 53 | Objs obj = Exports.fn; 54 | assertNotNull("fn", obj); 55 | assertEquals(42, obj.$get("fourtyTwo")); 56 | assertEquals("Hi", Exports.fn()); 57 | assertEquals("Length4", Exports.fn(4)); 58 | } 59 | 60 | @Test 61 | public void typedFunctionWithProperties() { 62 | FnT obj = Exports.fnT; 63 | assertNotNull("fnT", obj); 64 | assertEquals(42, obj.fourtyTwo.get()); 65 | assertEquals("Hi", Exports.fnT()); 66 | // assertEquals("Length4", Exports.fnT(4)); 67 | } 68 | 69 | @Test 70 | public void typedFunctionWithPropertiesOnObject() { 71 | FnT obj = Exports.fnT; 72 | assertNotNull("fnT", obj.FnT); 73 | assertEquals(42, obj.FnT.get().fourtyTwo.get()); 74 | assertEquals("Hi", obj.FnT()); 75 | // assertEquals("Length4", Exports.fnT(4)); 76 | } 77 | 78 | @Test 79 | public void firstAsNumber() { 80 | FnT obj = Exports.fnT; 81 | assertEquals(42.1, obj.first(42.1), 0.1); 82 | } 83 | @Test 84 | public void firstAsString() { 85 | FnT obj = Exports.fnT; 86 | assertEquals(obj.first("Hi"), "Hi"); 87 | } 88 | @Test 89 | public void notifyWithOneParam() { 90 | Rev rev = Exports.rev; 91 | Number n = rev.notify(33); 92 | assertEquals(42, n.intValue()); 93 | } 94 | 95 | @Test 96 | public void stringLiteralBoolean() { 97 | boolean b = Exports.literal((Boolean)null); 98 | assertTrue(b); 99 | } 100 | 101 | @Test 102 | public void stringLiteralNumber() { 103 | double d = Exports.literal((Number)null); 104 | assertEquals(1.0, d, 0.1); 105 | } 106 | 107 | @Test 108 | public void stringLiteralDefault() { 109 | Object any = Exports.literal("any"); 110 | assertEquals(Boolean.FALSE, any); 111 | } 112 | 113 | @Test 114 | public void scopeCompute() { 115 | Number n = Exports.scope.$compute((Object p1) -> 42); 116 | assertEquals(42, n.intValue()); 117 | } 118 | 119 | @Test 120 | public void trippleTest() { 121 | Object[] arr = Exports.tripple(); 122 | assertEquals(3, arr.length); 123 | assertTrue(arr[0] instanceof Number); 124 | assertTrue(arr[1] instanceof String); 125 | assertTrue(arr[2] instanceof Boolean); 126 | } 127 | 128 | @Test 129 | public void oneFnString() { 130 | Union.A2 value = Exports.oneFn("one"); 131 | assertEquals("one", value.cast(String.class)); 132 | } 133 | 134 | @Test 135 | public void oneFnNumber() { 136 | Union.A2 value = Exports.oneFn(1); 137 | assertEquals("One is returned", 1.0, (double) value.cast(Number.class), 0.1); 138 | } 139 | 140 | @Test 141 | public void oneOf() { 142 | Object value = Exports.oneOf.cast(String.class); 143 | assertEquals("two", value); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /mojo-test/src/test/java/com/dukescript/libraries/ap/test/hello/HelloTest.java: -------------------------------------------------------------------------------- 1 | package com.dukescript.libraries.ap.test.hello; 2 | 3 | /* 4 | * #%L 5 | * Annotation Processor Tests - a library from the DukeScript project. 6 | * Visit http://dukescript.com for support and commercial license. 7 | * %% 8 | * Copyright (C) 2015 - 2016 Dukehoff GmbH 9 | * %% 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as 12 | * published by the Free Software Foundation, either version 3 of the 13 | * License, or (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public 21 | * License along with this program. If not, see 22 | * . 23 | * #L% 24 | */ 25 | 26 | import java.lang.reflect.ParameterizedType; 27 | import java.lang.reflect.Type; 28 | import net.java.html.lib.Array; 29 | import net.java.html.junit.BrowserRunner; 30 | import net.java.html.lib.Objs; 31 | import net.java.html.lib.Union; 32 | import static org.junit.Assert.*; 33 | import org.junit.Test; 34 | import org.junit.runner.RunWith; 35 | 36 | @RunWith(BrowserRunner.class) 37 | public class HelloTest { 38 | @Test 39 | public void testEvalObject() throws Exception { 40 | final Object obj = Exports.compute("var x = {}; x.x = 'Hi'; x"); 41 | assertNotNull("Value returned", obj); 42 | assertTrue("The result is Objs: " + obj.getClass(), obj instanceof Objs); 43 | Objs js = (Objs) obj; 44 | assertEquals("Has property x", js.$get("x"), "Hi"); 45 | } 46 | 47 | @Test 48 | public void workWithAnArray() { 49 | Array obj = Exports.emptyVector(); 50 | assertNotNull(obj); 51 | Array one = Exports.addVector(obj, 1); 52 | Array two = Exports.addVector(one, 2); 53 | assertEquals("Two elements", 2, two.length.get().doubleValue(), 0.1); 54 | two.push(3.0); 55 | assertEquals("Three elements", 3, two.length.get().intValue()); 56 | } 57 | 58 | @Test 59 | public void parametrizedType() throws Exception { 60 | Type type = Exports.class.getMethod("emptyVector").getGenericReturnType(); 61 | assertTrue("Array has a parameter" + type, type instanceof ParameterizedType); 62 | ParameterizedType pt = (ParameterizedType) type; 63 | assertEquals("One type", 1, pt.getActualTypeArguments().length); 64 | Type first = pt.getActualTypeArguments()[0]; 65 | assertTrue(first instanceof Class); 66 | assertEquals("Parametrized by number", Number.class, first); 67 | } 68 | 69 | @Test 70 | public void ownStringStack() { 71 | StringStack stack = new StringStack(); 72 | stack.push("World"); 73 | stack.push("Hello"); 74 | assertEquals("HelloWorld", stack.pop() + stack.pop()); 75 | } 76 | 77 | @Test 78 | public void returnArrayWraper() { 79 | StringStack stack = new StringStack(); 80 | stack.push("Hi"); 81 | stack.push("World"); 82 | Array lens = stack.lengths(); 83 | assertNotNull("Lengths found", lens); 84 | assertEquals("Two items", 2, lens.length.get().intValue()); 85 | assertEquals("two for Hi", 2, lens.$get(0).intValue()); 86 | assertEquals("five for World", 5, lens.$get(1).intValue()); 87 | } 88 | 89 | @Test 90 | public void nextStack() { 91 | StringStack stack = new StringStack(new StringStack()); 92 | assertEquals("Ahoj", stack.name.get()); 93 | assertNotNull(stack.next.get()); 94 | assertNull(stack.next.get().next.get()); 95 | } 96 | 97 | @Test 98 | public void changeStackName() { 99 | StringStack stack = new StringStack(); 100 | assertEquals("Ahoj", stack.name.get()); 101 | stack.name.set("Hi"); 102 | String ret = stack.name.get(); 103 | assertEquals("Hi", stack.name.get()); 104 | assertEquals("Hi", ret); 105 | } 106 | 107 | @Test 108 | public void accessUnionType() { 109 | assertFalse("Not instance of number", Exports.UnionInitialized.instanceOf(Number.class)); 110 | assertFalse("Not instance of string", Exports.UnionInitialized.instanceOf(String.class)); 111 | assertTrue("instance of boolean", Exports.UnionInitialized.instanceOf(Boolean.class)); 112 | assertEquals(Boolean.TRUE, Exports.UnionInitialized.cast(Boolean.class)); 113 | } 114 | 115 | @Test 116 | public void complexUnionType() { 117 | Union.A3 abUnion = Exports.ab; 118 | A abViewAsA = abUnion.cast(A.class); 119 | assertNotNull(abViewAsA); 120 | assertEquals(abViewAsA.getClass(), A.class); 121 | Union.A3 abaUnion = abViewAsA.b.get(); 122 | B abaViewAsB = abaUnion.cast(B.class); 123 | Union.A3 abbaUnion = abaViewAsB.a.get(); 124 | Union.A3 terminalUnion = abbaUnion.cast(A.class).b.get(); 125 | assertEquals("Hi", terminalUnion.cast(String.class)); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /mojo-test/src/test/java/com/dukescript/libraries/ap/test/hello/SingletonTest.java: -------------------------------------------------------------------------------- 1 | package com.dukescript.libraries.ap.test.hello; 2 | 3 | /* 4 | * #%L 5 | * Annotation Processor Tests - a library from the DukeScript project. 6 | * Visit http://dukescript.com for support and commercial license. 7 | * %% 8 | * Copyright (C) 2015 - 2016 Dukehoff GmbH 9 | * %% 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as 12 | * published by the Free Software Foundation, either version 3 of the 13 | * License, or (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public 21 | * License along with this program. If not, see 22 | * . 23 | * #L% 24 | */ 25 | 26 | import net.java.html.junit.BrowserRunner; 27 | import static org.junit.Assert.*; 28 | import org.junit.Test; 29 | import org.junit.runner.RunWith; 30 | 31 | @RunWith(BrowserRunner.class) 32 | public class SingletonTest { 33 | @Test 34 | public void getTheValue() { 35 | Number obj = Exports.singletonNumber.value(30, 12); 36 | assertEquals(42, obj.intValue()); 37 | } 38 | 39 | @Test 40 | public void getFirstValue() { 41 | Object obj = Exports.firstValue().$apply("Hi", "There"); 42 | assertEquals("Hi", obj); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /mojo-test/src/test/java/com/dukescript/libraries/ap/test/ns/NamespaceTest.java: -------------------------------------------------------------------------------- 1 | package com.dukescript.libraries.ap.test.ns; 2 | 3 | /* 4 | * #%L 5 | * Annotation Processor Tests - a library from the DukeScript project. 6 | * Visit http://dukescript.com for support and commercial license. 7 | * %% 8 | * Copyright (C) 2015 - 2016 Dukehoff GmbH 9 | * %% 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as 12 | * published by the Free Software Foundation, either version 3 of the 13 | * License, or (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public 21 | * License along with this program. If not, see 22 | * . 23 | * #L% 24 | */ 25 | 26 | import com.dukescript.libraries.ap.test.ns.geo.Circle; 27 | import com.dukescript.libraries.ap.test.ns.geo.Elipse; 28 | import net.java.html.junit.BrowserRunner; 29 | import net.java.html.lib.Modules; 30 | import net.java.html.lib.Objs; 31 | import org.junit.After; 32 | import org.junit.Assert; 33 | import static org.junit.Assert.assertNotNull; 34 | import org.junit.Before; 35 | import org.junit.Test; 36 | import org.junit.runner.RunWith; 37 | 38 | @RunWith(BrowserRunner.class) 39 | public class NamespaceTest { 40 | private ProviderImpl provider; 41 | 42 | @Before 43 | public void registerModuleProvider() { 44 | provider = new ProviderImpl(); 45 | } 46 | 47 | @After 48 | public void unregisterModuleProvider() { 49 | provider.close(); 50 | } 51 | 52 | @Test 53 | public void elipseIsCircle() { 54 | Elipse elipse = null; 55 | Circle circle = elipse; 56 | Assert.assertNull("Check the value", circle); 57 | } 58 | 59 | @Test 60 | public void elipseGeo2d() { 61 | Elipse elipse; 62 | elipse = com.dukescript.libraries.ap.test.ns.geo2d.Elipse.$as(this); 63 | Assert.assertNotNull("Geo2d is elipse", elipse); 64 | } 65 | 66 | @Test 67 | public void elipseGeo3d() { 68 | Elipse elipse; 69 | elipse = com.dukescript.libraries.ap.test.ns.geo3d.Elipse.$as(this); 70 | Assert.assertNotNull("Geo3d is elipse", elipse); 71 | } 72 | 73 | @Test 74 | public void elipseGeoBoth() { 75 | com.dukescript.libraries.ap.test.ns.geo3d.Elipse elipse; 76 | elipse = com.dukescript.libraries.ap.test.ns.geo3dplus.Elipse.$as(this); 77 | Assert.assertNotNull("Geo3d is elipse", elipse); 78 | } 79 | 80 | @Test 81 | public void checkNamespaces() { 82 | String text = Exports.math.hello().toString(); 83 | Assert.assertEquals("Hello", text); 84 | } 85 | 86 | @Test 87 | public void staticModuleFunction() { 88 | Circle c = com.dukescript.libraries.ap.test.ns.geo.Exports.createCircle(); 89 | assertNotNull("Circle is returned", c); 90 | } 91 | 92 | @Test 93 | public void staticModuleValue() { 94 | final Objs.Property countCircle = com.dukescript.libraries.ap.test.ns.geo.Exports.countCircle; 95 | int before = countCircle.get().intValue(); 96 | Circle c = com.dukescript.libraries.ap.test.ns.geo.Exports.createCircle(); 97 | assertNotNull("Circle is returned", c); 98 | int after = countCircle.get().intValue(); 99 | Assert.assertEquals("Plus one", before + 1, after); 100 | } 101 | 102 | private static final class ProviderImpl extends Modules.Provider { 103 | @Override 104 | protected Objs find(String id) { 105 | if (id.equals("geo")) { 106 | return Objs.$as(Exports.geo); 107 | } 108 | return null; 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /mojo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 24 | 25 | 26 | 4.0.0 27 | 28 | com.dukescript.libraries 29 | pom 30 | 1.0-SNAPSHOT 31 | 32 | typings-maven-plugin 33 | DukeScript Typings Mojo Generator 34 | maven-plugin 35 | 36 | 1.8 37 | 1.8 38 | 39 | 40 | 41 | 42 | org.apache.maven.plugins 43 | maven-plugin-plugin 44 | 3.6.0 45 | 46 | 47 | java-annotations 48 | 49 | true 50 | 51 | 52 | 53 | mojo-descriptor 54 | process-classes 55 | 56 | descriptor 57 | 58 | 59 | 60 | 61 | 62 | maven-javadoc-plugin 63 | 64 | false 65 | 66 | 67 | 68 | org.apache.maven.plugins 69 | maven-source-plugin 70 | 71 | 72 | 73 | 74 | 75 | org.apache.maven 76 | maven-plugin-api 77 | 3.0.4 78 | jar 79 | 80 | 81 | org.sonatype.sisu 82 | sisu-guava 83 | 84 | 85 | org.codehaus.plexus 86 | plexus-utils 87 | 88 | 89 | 90 | 91 | org.apache.maven 92 | maven-artifact 93 | 3.0.4 94 | jar 95 | 96 | 97 | org.apache.maven.plugin-tools 98 | maven-plugin-annotations 99 | 3.0 100 | jar 101 | 102 | 103 | org.apache.maven 104 | maven-artifact 105 | 106 | 107 | 108 | 109 | org.apache.maven 110 | maven-core 111 | 3.0.4 112 | jar 113 | 114 | 115 | org.codehaus.plexus 116 | plexus-utils 117 | 118 | 119 | 120 | 121 | ${project.groupId} 122 | mojo-base 123 | ${project.version} 124 | 125 | 126 | org.codehaus.plexus 127 | plexus-utils 128 | 2.0.6 129 | 130 | 131 | -------------------------------------------------------------------------------- /mojo/src/main/java/com/dukescript/libraries/proc/GenerateTypings.java: -------------------------------------------------------------------------------- 1 | package com.dukescript.libraries.proc; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.FileOutputStream; 6 | import java.io.FileWriter; 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | import java.io.Writer; 10 | import java.lang.reflect.Modifier; 11 | import java.net.MalformedURLException; 12 | import java.net.URL; 13 | import java.net.URLClassLoader; 14 | import java.nio.file.Files; 15 | import java.util.ArrayList; 16 | import java.util.Enumeration; 17 | import java.util.List; 18 | import java.util.Map; 19 | import java.util.Properties; 20 | import org.apache.maven.artifact.DependencyResolutionRequiredException; 21 | import org.apache.maven.plugin.AbstractMojo; 22 | import org.apache.maven.plugin.MojoExecutionException; 23 | import org.apache.maven.plugin.MojoFailureException; 24 | import org.apache.maven.plugins.annotations.Component; 25 | import org.apache.maven.plugins.annotations.LifecyclePhase; 26 | import org.apache.maven.plugins.annotations.Mojo; 27 | import org.apache.maven.plugins.annotations.ResolutionScope; 28 | import org.apache.maven.project.MavenProject; 29 | import org.apache.maven.project.MavenProjectHelper; 30 | 31 | /* 32 | * #%L 33 | * DukeScript Libraries Processor - a library from the DukeScript project. 34 | * Visit http://dukescript.com for support and commercial license. 35 | * %% 36 | * Copyright (C) 2015 Eppleton IT Consulting 37 | * %% 38 | * This program is free software: you can redistribute it and/or modify 39 | * it under the terms of the GNU General Public License as 40 | * published by the Free Software Foundation, either version 3 of the 41 | * License, or (at your option) any later version. 42 | * 43 | * This program is distributed in the hope that it will be useful, 44 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 45 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 46 | * GNU General Public License for more details. 47 | * 48 | * You should have received a copy of the GNU General Public 49 | * License along with this program. If not, see 50 | * . 51 | * #L% 52 | */ 53 | @Mojo(name = "generate", 54 | requiresDependencyResolution = ResolutionScope.COMPILE, 55 | defaultPhase = LifecyclePhase.GENERATE_SOURCES 56 | ) 57 | public final class GenerateTypings extends AbstractMojo { 58 | @org.apache.maven.plugins.annotations.Parameter(defaultValue = "${project}") 59 | private MavenProject prj; 60 | 61 | @Component 62 | private MavenProjectHelper projectHelper; 63 | 64 | @org.apache.maven.plugins.annotations.Parameter 65 | private File typings; 66 | 67 | @org.apache.maven.plugins.annotations.Parameter(alias = "package") 68 | private String packageName; 69 | 70 | @org.apache.maven.plugins.annotations.Parameter 71 | private List imports; 72 | 73 | @org.apache.maven.plugins.annotations.Parameter 74 | private List scripts; 75 | 76 | @org.apache.maven.plugins.annotations.Parameter(defaultValue = "${project.build.directory}/generated-sources/typings/") 77 | private File output; 78 | 79 | @org.apache.maven.plugins.annotations.Parameter(defaultValue = "${project.build.outputDirectory}") 80 | private File classes; 81 | 82 | @org.apache.maven.plugins.annotations.Parameter(defaultValue = "") 83 | private String globalModuleName; 84 | 85 | @Override 86 | public void execute() throws MojoExecutionException, MojoFailureException { 87 | if (typings == null) { 88 | throw new MojoExecutionException("Specify typings to point to TypeScript typings file"); 89 | } 90 | if (!typings.canRead()) { 91 | throw new MojoExecutionException("typings file doesn't seem to exist: " + typings); 92 | } 93 | if (packageName == null) { 94 | throw new MojoExecutionException("package must be set!"); 95 | } 96 | if (output.isDirectory()) { 97 | File pkgOutput = new File(output, packageName.replace('.', File.separatorChar)); 98 | if (pkgOutput.isDirectory()) { 99 | prj.addCompileSourceRoot(output.getPath()); 100 | getLog().info("Skipping, output directory already exists: " + pkgOutput); 101 | return; 102 | } 103 | } 104 | List arr = new ArrayList<>(); 105 | try { 106 | for (String path : prj.getCompileClasspathElements()) { 107 | arr.add(new File(path).toURI().toURL()); 108 | } 109 | } catch (DependencyResolutionRequiredException | MalformedURLException ex) { 110 | throw new MojoExecutionException("", ex); 111 | } 112 | URLClassLoader loader = new URLClassLoader(arr.toArray(new URL[0])); 113 | MojoGenerator generator = new MojoGenerator(loader); 114 | 115 | String[] libraryScripts = array(scripts); 116 | for (int i = 0; i < libraryScripts.length; i++) { 117 | try { 118 | URL url = new URL(libraryScripts[i]); 119 | final String urlString = url.toExternalForm(); 120 | String urlName = urlString.substring(urlString.lastIndexOf('/') + 1); 121 | File copyTo = new File(new File(classes, packageName.replace('.', File.separatorChar)), urlName); 122 | if (!copyTo.exists()) { 123 | copyTo.getParentFile().mkdirs(); 124 | getLog().info("Downloading " + url + " to " + copyTo); 125 | try { 126 | Files.copy(url.openStream(), copyTo.toPath()); 127 | } catch (IOException ex) { 128 | throw new MojoExecutionException("Cannot copy " + url + " to " + copyTo); 129 | } 130 | } else { 131 | getLog().debug("File " + copyTo + " exists. Skipping download of " + url); 132 | } 133 | libraryScripts[i] = copyTo.getName(); 134 | getLog().debug("Using " + libraryScripts[i] + " "); 135 | } catch (MalformedURLException ex) { 136 | // OK, keep the script name 137 | } 138 | } 139 | 140 | 141 | try (FileInputStream is = new FileInputStream(typings)) { 142 | List activeImports; 143 | if (imports == null) { 144 | activeImports = generator.loadImports(); 145 | } else { 146 | activeImports = imports; 147 | } 148 | generator.generateSources(array(activeImports), 149 | libraryScripts, 150 | packageName, typings.getName(), is, typings 151 | ); 152 | prj.addCompileSourceRoot(output.getPath()); 153 | } catch (IOException ex) { 154 | throw new MojoFailureException("Cannot process " + typings, ex); 155 | } 156 | } 157 | 158 | private String[] array(List arr) { 159 | return arr == null ? new String[0] : arr.toArray(new String[0]); 160 | } 161 | 162 | private final class MojoGenerator extends Generator { 163 | private final ClassLoader classpath; 164 | 165 | public MojoGenerator(ClassLoader classpath) { 166 | this.classpath = classpath; 167 | } 168 | 169 | @Override 170 | protected String globalModuleName() { 171 | return globalModuleName == null || globalModuleName.isEmpty() ? null : globalModuleName; 172 | } 173 | 174 | @Override 175 | protected Writer createSourceFile(String fqn, Object location) throws IOException { 176 | int lastDot = fqn.lastIndexOf('.'); 177 | File dir = new File(output, fqn.substring(0, lastDot + 1).replace('.', File.separatorChar)); 178 | if (!dir.isDirectory() && !dir.mkdirs()) { 179 | throw new IOException("Cannot create " + dir); 180 | } 181 | return new FileWriter(new File(dir, fqn.substring(lastDot + 1) + ".java")); 182 | } 183 | 184 | @Override 185 | protected void registerPackages(String... packages) throws IOException { 186 | File imports = new File(new File(new File(classes, "META-INF"), "typings"), "package.properties"); 187 | Properties props = new Properties(); 188 | if (imports.exists()) { 189 | try (InputStream is = new FileInputStream(imports)) { 190 | props.load(is); 191 | } 192 | } else { 193 | imports.getParentFile().mkdirs(); 194 | } 195 | for (String p : packages) { 196 | props.setProperty(p, typings.getName()); 197 | } 198 | try (FileOutputStream os = new FileOutputStream(imports)) { 199 | props.store(os, null); 200 | } 201 | } 202 | 203 | List loadImports() throws IOException { 204 | List allImports = new ArrayList<>(); 205 | Enumeration en = classpath.getResources("META-INF/typings/package.properties"); 206 | while (en.hasMoreElements()) { 207 | URL resource = en.nextElement(); 208 | Properties props = new Properties(); 209 | try (InputStream is = resource.openStream()) { 210 | props.load(is); 211 | } 212 | for (Map.Entry entry : props.entrySet()) { 213 | Object packageImport = entry.getKey(); 214 | allImports.add(packageImport.toString()); 215 | } 216 | } 217 | return allImports; 218 | } 219 | 220 | @Override 221 | protected Object findType(String fqn) { 222 | if (fqn.startsWith("java.lang.")) { 223 | try { 224 | Class> clazz = Class.forName(fqn); 225 | if ((clazz.getModifiers() & Modifier.PUBLIC) != 0) { 226 | return clazz; 227 | } else { 228 | return null; 229 | } 230 | } catch (ClassNotFoundException ex) { 231 | return null; 232 | } 233 | } 234 | final String classResource = fqn.replace('.', '/') + ".class"; 235 | final URL res = classpath.getResource(classResource); 236 | if (res != null) { 237 | return res; 238 | } 239 | File srcRoot = new File(prj.getBuild().getSourceDirectory()); 240 | String javaResource = fqn.replace('.', '/') + ".java"; 241 | File src = new File(srcRoot, javaResource); 242 | return src.isFile() ? src : null; 243 | } 244 | 245 | @Override 246 | protected void note(String message, Object e) { 247 | getLog().info(message); 248 | } 249 | 250 | @Override 251 | protected void error(String message, Object e) { 252 | getLog().error(message); 253 | } 254 | } 255 | } 256 | -------------------------------------------------------------------------------- /src/license/header.txt: -------------------------------------------------------------------------------- 1 | ${projectName} - a library from the DukeScript project. 2 | Visit http://dukescript.com for support and commercial license. 3 | 4 | -------------------------------------------------------------------------------- /typings/angular/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 28 | 29 | 30 | 4.0.0 31 | 32 | com.dukescript.libraries 33 | pom 34 | 1.0-SNAPSHOT 35 | ../../ 36 | 37 | net.java.html.lib.angular 38 | Java Typings for Angular 39 | jar 40 | 41 | 42 | 43 | com.dukescript.libraries 44 | typings-maven-plugin 45 | ${project.version} 46 | 47 | 48 | generate-sources 49 | 50 | generate 51 | 52 | 53 | 54 | 55 | src/main/java/angular.d.ts 56 | net.java.html.lib.angular 57 | 58 | 59 | 60 | 61 | 62 | 63 | org.netbeans.html 64 | html4j-maven-plugin 65 | ${net.java.html.version} 66 | 67 | 68 | js-classes 69 | 70 | process-js-annotations 71 | 72 | 73 | 74 | test-classes 75 | process-test-classes 76 | 77 | process-js-annotations 78 | 79 | 80 | ${project.build.directory}/test-classes 81 | 82 | 83 | 84 | 85 | 86 | org.netbeans.tools 87 | sigtest-maven-plugin 88 | 1.0 89 | 90 | 91 | signatures-of-generated-classes 92 | 93 | check 94 | 95 | 96 | true 97 | 98 | 99 | 100 | 101 | src/main/java/angular.sigtest 102 | net.java.html.lib.angular:net.java.html.lib.angular.ng:net.java.html.lib.angular.ng.auto 103 | 104 | 105 | 106 | org.sonatype.plugins 107 | nexus-staging-maven-plugin 108 | 109 | true 110 | 111 | 112 | 113 | 114 | 115 | 116 | ${project.groupId} 117 | net.java.html.lib 118 | ${project.version} 119 | 120 | 121 | ${project.groupId} 122 | net.java.html.lib.dom 123 | ${project.version} 124 | 125 | 126 | ${project.groupId} 127 | net.java.html.lib.jquery 128 | ${project.version} 129 | 130 | 131 | com.dukescript.libraries 132 | typings-testing 133 | ${project.version} 134 | test 135 | 136 | 137 | 138 | 1.8 139 | 1.8 140 | 141 | -------------------------------------------------------------------------------- /typings/angular/src/test/java/com/dukescript/libraries/angular/AngularTest.java: -------------------------------------------------------------------------------- 1 | package com.dukescript.libraries.angular; 2 | 3 | import net.java.html.lib.Function; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | import net.java.html.junit.BrowserRunner; 7 | import net.java.html.junit.HTMLContent; 8 | import static net.java.html.lib.angular.Exports.angular; 9 | import net.java.html.lib.angular.ng.IModule; 10 | import net.java.html.lib.angular.ng.IScope; 11 | import static net.java.html.lib.jquery.Exports.$; 12 | import net.java.html.lib.jquery.JQuery; 13 | import static org.junit.Assert.assertNotEquals; 14 | import static org.junit.Assert.assertNotNull; 15 | import static org.junit.Assert.assertTrue; 16 | import org.junit.runner.RunWith; 17 | 18 | /* 19 | * #%L 20 | * DukeScript Libraries Processor - a library from the DukeScript project. 21 | * Visit http://dukescript.com for support and commercial license. 22 | * %% 23 | * Copyright (C) 2015 Eppleton IT Consulting 24 | * %% 25 | * Permission is hereby granted, free of charge, to any person obtaining a copy 26 | * of this software and associated documentation files (the "Software"), to deal 27 | * in the Software without restriction, including without limitation the rights 28 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 29 | * copies of the Software, and to permit persons to whom the Software is 30 | * furnished to do so, subject to the following conditions: 31 | * 32 | * The above copyright notice and this permission notice shall be included in 33 | * all copies or substantial portions of the Software. 34 | * 35 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 36 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 37 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 38 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 39 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 40 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 41 | * THE SOFTWARE. 42 | * #L% 43 | */ 44 | 45 | @RunWith(BrowserRunner.class) 46 | @HTMLContent("\n" + 47 | "\n" + 48 | " Hello {{sometext}}!\n" + 49 | " Enlarge!\n" + 50 | "\n" + 51 | "") 52 | public class AngularTest { 53 | IScope scope; 54 | 55 | String assertContainsText(String msg) { 56 | JQuery element = $("#text"); 57 | String txt = element.text(); 58 | if (msg == null) { 59 | return txt; 60 | } 61 | if (txt.contains(msg)) { 62 | return txt; 63 | } 64 | Assert.assertEquals(msg, txt); 65 | return txt; 66 | } 67 | 68 | @Test 69 | public Runnable[] simpleAngularModule() throws Exception { 70 | assertNotNull("Angular global found", angular); 71 | IModule module = angular.module("example", new String[0]); 72 | Function initFn = Function.newFunction((Function.A1) (Object arg1) -> { 73 | scope = IScope.$as(arg1); 74 | scope.$set("sometext", "DukeScript"); 75 | scope.$set("changetext", (Function.A0) () -> { 76 | scope.$set("sometext", "Great " + scope.$get("sometext")); 77 | return null; 78 | }); 79 | return null; 80 | }); 81 | net.java.html.lib.angular.Function.$as(initFn).$inject.set(new String[] { "$scope" }); 82 | 83 | assertTrue("is function", angular.isFunction(initFn)); 84 | module.controller("SampleController", new Object[] { "$scope", initFn }); 85 | 86 | return new Runnable[] { 87 | () -> assertContainsText("Hello DukeScript!"), 88 | () -> { 89 | $("#change").click(); 90 | }, 91 | () -> { 92 | $("#change").click(); 93 | }, 94 | () -> { 95 | $("#change").click(); 96 | }, 97 | () -> { 98 | $("#change").click(); 99 | }, 100 | () -> { 101 | assertContainsText("Great DukeScript!"); 102 | } 103 | }; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /typings/jquery/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 28 | 29 | 30 | 4.0.0 31 | 32 | com.dukescript.libraries 33 | pom 34 | 1.0-SNAPSHOT 35 | ../../ 36 | 37 | net.java.html.lib.jquery 38 | Java Typings for JQuery 39 | 40 | net.java.html.lib.jquery 41 | 1.8 42 | 1.8 43 | 44 | bundle 45 | 46 | 47 | 48 | com.dukescript.libraries 49 | typings-maven-plugin 50 | ${project.version} 51 | 52 | 53 | generate-sources 54 | 55 | generate 56 | 57 | 58 | 59 | 60 | src/main/java/jquery.d.ts 61 | 62 | 63 | 64 | ${publicPackages} 65 | 66 | 67 | 68 | org.netbeans.html 69 | html4j-maven-plugin 70 | ${net.java.html.version} 71 | 72 | 73 | js-classes 74 | 75 | process-js-annotations 76 | 77 | 78 | 79 | test-classes 80 | process-test-classes 81 | 82 | process-js-annotations 83 | 84 | 85 | ${project.build.directory}/test-classes 86 | 87 | 88 | 89 | 90 | 91 | org.netbeans.tools 92 | sigtest-maven-plugin 93 | 1.0 94 | 95 | 96 | ko-generated-classes 97 | 98 | check 99 | 100 | 101 | src/main/java/jquery.sigtest 102 | true 103 | 104 | 105 | 106 | 107 | ${publicPackages} 108 | 109 | 110 | 111 | org.apache.felix 112 | maven-bundle-plugin 113 | 2.5.3 114 | true 115 | 116 | 117 | dependent 118 | ${publicPackages} 119 | 120 | 121 | 122 | 123 | org.sonatype.plugins 124 | nexus-staging-maven-plugin 125 | 126 | true 127 | 128 | 129 | 130 | 131 | 132 | 133 | ${project.groupId} 134 | net.java.html.lib 135 | ${project.version} 136 | 137 | 138 | ${project.groupId} 139 | net.java.html.lib.dom 140 | ${project.version} 141 | 142 | 143 | com.dukescript.libraries 144 | typings-testing 145 | ${project.version} 146 | test 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /typings/jquery/src/test/java/com/dukescript/libraries/jquery/JQueryTest.java: -------------------------------------------------------------------------------- 1 | package com.dukescript.libraries.jquery; 2 | 3 | import net.java.html.lib.dom.Document; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | import static net.java.html.lib.dom.Exports.window; 7 | import net.java.html.lib.dom.HTMLElement; 8 | import net.java.html.junit.BrowserRunner; 9 | import net.java.html.junit.HTMLContent; 10 | import net.java.html.lib.Function; 11 | import static net.java.html.lib.jquery.Exports.$; 12 | import org.junit.runner.RunWith; 13 | import net.java.html.lib.jquery.JQuery; 14 | import net.java.html.lib.jquery.JQueryEventObject; 15 | 16 | /* 17 | * #%L 18 | * DukeScript Libraries Processor - a library from the DukeScript project. 19 | * Visit http://dukescript.com for support and commercial license. 20 | * %% 21 | * Copyright (C) 2015 Eppleton IT Consulting 22 | * %% 23 | * Permission is hereby granted, free of charge, to any person obtaining a copy 24 | * of this software and associated documentation files (the "Software"), to deal 25 | * in the Software without restriction, including without limitation the rights 26 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | * copies of the Software, and to permit persons to whom the Software is 28 | * furnished to do so, subject to the following conditions: 29 | * 30 | * The above copyright notice and this permission notice shall be included in 31 | * all copies or substantial portions of the Software. 32 | * 33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 39 | * THE SOFTWARE. 40 | * #L% 41 | */ 42 | 43 | @RunWith(BrowserRunner.class) 44 | @HTMLContent("\n" 45 | + "Press me!\n" 46 | + "Clear me!\n" 47 | + "Nothing yet\n" 48 | ) 49 | public class JQueryTest { 50 | String assertText(String msg) { 51 | final Document doc = window.document(); 52 | final HTMLElement element = doc.getElementById("text"); 53 | String txt = element.innerHTML(); 54 | if (msg == null) { 55 | return txt; 56 | } 57 | Assert.assertEquals(msg, txt); 58 | return txt; 59 | } 60 | 61 | @Test 62 | public void simpleJQuerySelector() throws Exception { 63 | final String message = "Hello from JQuery!"; 64 | $("#text").text(message); 65 | assertText(message); 66 | } 67 | 68 | @Test 69 | public void callbackWithObjectArgs() throws Exception { 70 | final String message = "Hello from JQuery!"; 71 | final JQuery textElement = $("#text"); 72 | textElement.text(message); 73 | assertText(message); 74 | $("#press").click(new Function.A1() { 75 | @Override 76 | public Object call(Object p1) { 77 | textElement.text("Clicked!"); 78 | return null; 79 | } 80 | }); 81 | $("#press").click(); 82 | assertText("Clicked!"); 83 | } 84 | 85 | @Test 86 | public void callbackWithRealArgs() throws Exception { 87 | final String message = "Hello from JQuery!"; 88 | final JQuery textElement = $("#text"); 89 | textElement.text(message); 90 | assertText(message); 91 | $("#clear").click(new Function.A1() { 92 | @Override 93 | public Object call(JQueryEventObject p1) { 94 | textElement.text("Cleared!"); 95 | return null; 96 | } 97 | }); 98 | $("#clear").click(); 99 | assertText("Cleared!"); 100 | } 101 | 102 | @Test 103 | public void lamdaWithObjectArgs() throws Exception { 104 | final String message = "Hello from JQuery!"; 105 | final JQuery textElement = $("#text"); 106 | textElement.text(message); 107 | assertText(message); 108 | $("#press").click((Object p1) -> { 109 | textElement.text("Clicked!"); 110 | return null; 111 | }); 112 | $("#press").click(); 113 | assertText("Clicked!"); 114 | } 115 | 116 | @Test 117 | public void lamdaWithRealArgs() throws Exception { 118 | final String message = "Hello from JQuery!"; 119 | final JQuery textElement = $("#text"); 120 | textElement.text(message); 121 | assertText(message); 122 | $("#clear").click((JQueryEventObject p1) -> { 123 | textElement.text("Cleared!"); 124 | return null; 125 | }); 126 | $("#clear").click(); 127 | assertText("Cleared!"); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /typings/jquery/src/test/resources/com/dukescript/libraries/jquery/index.html: -------------------------------------------------------------------------------- 1 | 27 | 28 | JQuery Test 29 | Not initialized 30 | 31 | -------------------------------------------------------------------------------- /typings/ko/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 28 | 29 | 30 | 4.0.0 31 | 32 | com.dukescript.libraries 33 | pom 34 | 1.0-SNAPSHOT 35 | ../../ 36 | 37 | net.java.html.lib.ko 38 | Java Typings for Knockout 39 | jar 40 | 41 | 1.8 42 | 1.8 43 | 44 | 45 | 46 | 47 | com.dukescript.libraries 48 | typings-maven-plugin 49 | ${project.version} 50 | 51 | 52 | generate-sources 53 | 54 | generate 55 | 56 | 57 | 58 | 59 | src/main/java/knockout.d.ts 60 | net.java.html.lib.ko 61 | 62 | 63 | 64 | org.netbeans.html 65 | html4j-maven-plugin 66 | ${net.java.html.version} 67 | 68 | 69 | js-classes 70 | 71 | process-js-annotations 72 | 73 | 74 | 75 | test-classes 76 | process-test-classes 77 | 78 | process-js-annotations 79 | 80 | 81 | ${project.build.directory}/test-classes 82 | 83 | 84 | 85 | 86 | 87 | org.netbeans.tools 88 | sigtest-maven-plugin 89 | 1.0 90 | 91 | 92 | ko-generated-classes 93 | 94 | check 95 | 96 | 97 | 98 | 99 | src/main/java/ko.sigtest 100 | net.java.html.lib.ko 101 | false 102 | 103 | 104 | 105 | org.sonatype.plugins 106 | nexus-staging-maven-plugin 107 | 108 | true 109 | 110 | 111 | 112 | 113 | 114 | 115 | ${project.groupId} 116 | net.java.html.lib 117 | ${project.version} 118 | 119 | 120 | ${project.groupId} 121 | net.java.html.lib.dom 122 | ${project.version} 123 | 124 | 125 | 126 | 127 | 128 | com.dukescript.libraries 129 | typings-testing 130 | ${project.version} 131 | test 132 | 133 | 134 | org.netbeans.html 135 | ko4j 136 | ${net.java.html.version} 137 | test 138 | 139 | 140 | -------------------------------------------------------------------------------- /typings/ko/src/test/java/com/dukescript/libraries/ko/KnockoutTest.java: -------------------------------------------------------------------------------- 1 | package com.dukescript.libraries.ko; 2 | 3 | import net.java.html.js.JavaScriptBody; 4 | import net.java.html.json.Model; 5 | import net.java.html.json.Models; 6 | import net.java.html.junit.BrowserRunner; 7 | import net.java.html.junit.HTMLContent; 8 | import net.java.html.lib.Objs; 9 | import net.java.html.lib.Function; 10 | import net.java.html.lib.ko.KnockoutObservable; 11 | import static net.java.html.lib.ko.Exports.ko; 12 | import static net.java.html.lib.dom.Exports.window; 13 | import org.junit.Assert; 14 | import static org.junit.Assert.fail; 15 | import org.junit.Test; 16 | import org.junit.runner.RunWith; 17 | 18 | /* 19 | * #%L 20 | * DukeScript Libraries Processor - a library from the DukeScript project. 21 | * Visit http://dukescript.com for support and commercial license. 22 | * %% 23 | * Copyright (C) 2015 Eppleton IT Consulting 24 | * %% 25 | * Permission is hereby granted, free of charge, to any person obtaining a copy 26 | * of this software and associated documentation files (the "Software"), to deal 27 | * in the Software without restriction, including without limitation the rights 28 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 29 | * copies of the Software, and to permit persons to whom the Software is 30 | * furnished to do so, subject to the following conditions: 31 | * 32 | * The above copyright notice and this permission notice shall be included in 33 | * all copies or substantial portions of the Software. 34 | * 35 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 36 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 37 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 38 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 39 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 40 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 41 | * THE SOFTWARE. 42 | * #L% 43 | */ 44 | 45 | @Model(className = "KnockoutModel", properties = { 46 | }) 47 | @RunWith(BrowserRunner.class) 48 | @HTMLContent("\n" + 49 | " Test\n" + 50 | " \n" + 51 | " Home\n" + 52 | " Page 1\n" + 53 | " Page 2\n" + 54 | " \n" + 55 | " Not initialized\n" + 56 | "") 57 | public class KnockoutTest { 58 | void initializeRoute() { 59 | Models.toRaw(new KnockoutModel()); 60 | Objs routing = new Objs(); 61 | class Init implements Function.A2, Void> { 62 | @Override 63 | public Void call(Object p1, Function.A0 p2) { 64 | Function.A0 onHashChange = () -> { 65 | String hash = window.location().hash().substring(2); 66 | int at = hash.lastIndexOf("/"); 67 | String after = hash.substring(at + 1); 68 | Function.A1 callback = (Function.A1) p2.call(); 69 | callback.call(after); 70 | return null; 71 | }; 72 | window.$set("onhashchange", onHashChange); 73 | return null; 74 | } 75 | } 76 | routing.$set("init", new Init()); 77 | ko.bindingHandlers().$set("route", routing); 78 | } 79 | 80 | String assertText(String msg) { 81 | String txt = window.document().getElementById("text").innerHTML(); 82 | if (msg == null) { 83 | return txt; 84 | } 85 | Assert.assertEquals(msg, txt); 86 | return txt; 87 | } 88 | 89 | @JavaScriptBody(args = {}, body = 90 | "var e = window.document.getElementById('home');\n " 91 | + "var ev = window.document.createEvent('MouseEvents');\n " 92 | + "ev.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);\n " 93 | + "e.dispatchEvent(ev);\n " 94 | + "if (!e.checked) {\n" 95 | + " e.checked = true;\n " 96 | + " e.dispatchEvent(ev);\n " 97 | + "}\n" 98 | ) 99 | public native void triggerClick(); 100 | 101 | /* 102 | void triggerClick() { 103 | Document d = window.document.call(); 104 | HTMLElement e = d.getElementById("home"); 105 | MouseEvent ev = (MouseEvent)d.createEvent("MouseEvents"); 106 | ev.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); 107 | e.dispatchEvent(ev); 108 | if (!e.checked) { 109 | e.checked = true; 110 | e.dispatchEvent(ev); 111 | } 112 | } 113 | */ 114 | 115 | @Test 116 | public Runnable[] initPresenter() throws Exception { 117 | initializeRoute(); 118 | return new Runnable[] { 119 | () -> { 120 | Objs obj = new Objs(); 121 | KnockoutObservable msg = ko.observable("It runs!"); 122 | obj.$set("msg", msg); 123 | ko.applyBindings(obj); 124 | assertText("It runs!"); 125 | msg.$apply("It runs even better!"); 126 | assertText("It runs even better!"); 127 | }, 128 | () -> { 129 | triggerClick(); 130 | }, 131 | () -> { 132 | String t = assertText(null); 133 | if (!"home".equals(t)) { 134 | fail("Wrong currentText: " + t); 135 | } 136 | } 137 | }; 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /typings/typings-testing/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 28 | 29 | 4.0.0 30 | 31 | com.dukescript.libraries 32 | pom 33 | 1.0-SNAPSHOT 34 | ../../pom.xml 35 | 36 | Testing Environment for Typings 37 | typings-testing 38 | jar 39 | 40 | 41 | 42 | org.sonatype.plugins 43 | nexus-staging-maven-plugin 44 | 45 | true 46 | 47 | 48 | 49 | 50 | 51 | 52 | com.dukescript.api 53 | junit-browser-runner 54 | compile 55 | 56 | 57 | 58 | 59 | 60 | org.netbeans.html 61 | net.java.html.boot.fx 62 | ${net.java.html.version} 63 | 64 | 65 | 66 | 73 | 80 | 81 | 82 | 83 | org.apidesign.bck2brwsr 84 | launcher.http 85 | ${bck2brwsr.version} 86 | 87 | 88 | org.apidesign.bck2brwsr 89 | emul 90 | rt 91 | ${bck2brwsr.version} 92 | 93 | 94 | org.apidesign.bck2brwsr 95 | emul 96 | bck2brwsr 97 | ${bck2brwsr.version} 98 | 99 | 100 | -------------------------------------------------------------------------------- /typings/underscore/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 28 | 29 | 30 | 4.0.0 31 | 32 | com.dukescript.libraries 33 | pom 34 | 1.0-SNAPSHOT 35 | ../../ 36 | 37 | net.java.html.lib.underscore 38 | Java Typings for Underscore 39 | jar 40 | 41 | 42 | 43 | com.dukescript.libraries 44 | typings-maven-plugin 45 | ${project.version} 46 | 47 | 48 | generate-sources 49 | 50 | generate 51 | 52 | 53 | 54 | 55 | underscore.d.ts 56 | net.java.html.lib.underscore 57 | 58 | 59 | 60 | 61 | 62 | 63 | org.netbeans.html 64 | html4j-maven-plugin 65 | ${net.java.html.version} 66 | 67 | 68 | js-classes 69 | 70 | process-js-annotations 71 | 72 | 73 | 74 | test-classes 75 | process-test-classes 76 | 77 | process-js-annotations 78 | 79 | 80 | ${project.build.directory}/test-classes 81 | 82 | 83 | 84 | 85 | 86 | org.sonatype.plugins 87 | nexus-staging-maven-plugin 88 | 89 | true 90 | 91 | 92 | 93 | 94 | 95 | 96 | ${project.groupId} 97 | net.java.html.lib 98 | ${project.version} 99 | 100 | 101 | ${project.groupId} 102 | net.java.html.lib.dom 103 | ${project.version} 104 | 105 | 106 | 107 | 108 | 109 | com.dukescript.libraries 110 | typings-testing 111 | ${project.version} 112 | test 113 | 114 | 115 | 116 | 1.8 117 | 1.8 118 | 119 | -------------------------------------------------------------------------------- /typings/underscore/src/test/java/com/dukescript/libraries/underscore/UnderscoreTest.java: -------------------------------------------------------------------------------- 1 | package com.dukescript.libraries.underscore; 2 | 3 | import net.java.html.junit.BrowserRunner; 4 | import net.java.html.junit.HTMLContent; 5 | import net.java.html.lib.underscore.Exports; 6 | import static org.junit.Assert.assertEquals; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | /* 11 | * #%L 12 | * DukeScript Libraries Processor - a library from the DukeScript project. 13 | * Visit http://dukescript.com for support and commercial license. 14 | * %% 15 | * Copyright (C) 2015 Eppleton IT Consulting 16 | * %% 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy 18 | * of this software and associated documentation files (the "Software"), to deal 19 | * in the Software without restriction, including without limitation the rights 20 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 21 | * copies of the Software, and to permit persons to whom the Software is 22 | * furnished to do so, subject to the following conditions: 23 | * 24 | * The above copyright notice and this permission notice shall be included in 25 | * all copies or substantial portions of the Software. 26 | * 27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 28 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 29 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 30 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 31 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 32 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 33 | * THE SOFTWARE. 34 | * #L% 35 | */ 36 | 37 | @RunWith(BrowserRunner.class) 38 | @HTMLContent("") 39 | public class UnderscoreTest { 40 | 41 | @Test 42 | public void initPresenter() throws Exception { 43 | String hi = Exports._.escape("hi"); 44 | assertEquals("hi", hi); 45 | } 46 | } 47 | --------------------------------------------------------------------------------
obj
exports
null
Exports
true
false