mirror of
https://github.com/cincheo/jsweet.git
synced 2025-12-15 15:29:22 +00:00
add tests and fix dependency
This commit is contained in:
parent
ac7bfbbee3
commit
c2f9ad4563
2
pom.xml
2
pom.xml
@ -197,7 +197,7 @@
|
||||
<dependency>
|
||||
<groupId>org.jsweet.candies</groupId>
|
||||
<artifactId>node</artifactId>
|
||||
<version>0.12.1-SNAPSHOT</version>
|
||||
<version>4.0.1-SNAPSHOT</version>
|
||||
<scope>test</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
1
target/.gitignore
vendored
1
target/.gitignore
vendored
@ -1 +1,2 @@
|
||||
/classes/
|
||||
/test-classes/
|
||||
|
||||
196
test/org/jsweet/test/transpiler/AbstractTest.java
Normal file
196
test/org/jsweet/test/transpiler/AbstractTest.java
Normal file
@ -0,0 +1,196 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jsweet.transpiler.JSweetProblem;
|
||||
import org.jsweet.transpiler.JSweetTranspiler;
|
||||
import org.jsweet.transpiler.ModuleKind;
|
||||
import org.jsweet.transpiler.SourceFile;
|
||||
import org.jsweet.transpiler.util.EvaluationResult;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.TestName;
|
||||
|
||||
public class AbstractTest {
|
||||
|
||||
protected static final Logger staticLogger = Logger.getLogger(AbstractTest.class);
|
||||
|
||||
protected final Logger logger = Logger.getLogger(getClass());
|
||||
|
||||
private static boolean testSuiteInitialized = false;
|
||||
|
||||
@Rule
|
||||
public final TestName testNameRule = new TestName();
|
||||
|
||||
protected File getTestFile(String name) {
|
||||
return new File("./test/" + getClass().getPackage().getName().replace('.', '/'), name + ".d.ts");
|
||||
}
|
||||
|
||||
protected final String getCurrentTestName() {
|
||||
return getClass().getSimpleName() + "." + testNameRule.getMethodName();
|
||||
}
|
||||
|
||||
public static int runTsc(String... files) throws IOException {
|
||||
String[] args;
|
||||
if (System.getProperty("os.name").startsWith("Windows")) {
|
||||
args = new String[] { "cmd", "/c", "tsc --target ES3" };
|
||||
} else {
|
||||
args = new String[] { "tsc", "--target", "ES3" };
|
||||
}
|
||||
args = ArrayUtils.addAll(args, files);
|
||||
ProcessBuilder pb = new ProcessBuilder(args);
|
||||
pb.redirectErrorStream(true);
|
||||
Process process = pb.start();
|
||||
|
||||
try {
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
System.out.println(line);
|
||||
}
|
||||
|
||||
return process.waitFor();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
protected static JSweetTranspiler transpiler;
|
||||
protected static final String TMPOUT_DIR = "tempOut";
|
||||
|
||||
@BeforeClass
|
||||
public static void globalSetUp() throws Exception {
|
||||
File outDir = new File(TMPOUT_DIR);
|
||||
if (!testSuiteInitialized) {
|
||||
staticLogger.info("*** test suite initialization ***");
|
||||
FileUtils.deleteQuietly(outDir);
|
||||
testSuiteInitialized = true;
|
||||
}
|
||||
staticLogger.info("*** create tranpiler ***");
|
||||
transpiler = new JSweetTranspiler(outDir, null, System.getProperty("java.class.path"));
|
||||
transpiler.setModuleKind(ModuleKind.none);
|
||||
}
|
||||
|
||||
private void initOutputDir() {
|
||||
transpiler.setTsOutputDir(new File(new File(TMPOUT_DIR), getCurrentTestName() + "/" + transpiler.getModuleKind()));
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
initOutputDir();
|
||||
logger.info("*********************** " + getCurrentTestName() + " ***********************");
|
||||
}
|
||||
|
||||
public AbstractTest() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected SourceFile getSourceFile(Class<?> mainClass) {
|
||||
return new SourceFile(new File("test/" + mainClass.getName().replace(".", "/") + ".java"));
|
||||
}
|
||||
|
||||
protected EvaluationResult eval(SourceFile sourceFile, JSweetProblem... expectedProblems) {
|
||||
EvaluationResult res = null;
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
res = transpiler.eval(logHandler, sourceFile);
|
||||
logHandler.assertReportedProblems(expectedProblems);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test - errors=" + logHandler.reportedProblems);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
protected void transpile(Consumer<TestTranspilationHandler> assertions, SourceFile... files) {
|
||||
transpile(new ModuleKind[] { ModuleKind.none, ModuleKind.commonjs }, assertions, files);
|
||||
}
|
||||
|
||||
protected void transpile(ModuleKind[] moduleKinds, Consumer<TestTranspilationHandler> assertions, SourceFile... files) {
|
||||
for (ModuleKind moduleKind : moduleKinds) {
|
||||
transpile(moduleKind, assertions, files);
|
||||
}
|
||||
}
|
||||
|
||||
protected void transpile(ModuleKind moduleKind, Consumer<TestTranspilationHandler> assertions, SourceFile... files) {
|
||||
ModuleKind initialModuleKind = transpiler.getModuleKind();
|
||||
File initialOutputDir = transpiler.getTsOutputDir();
|
||||
try {
|
||||
logger.info("*** module kind: " + moduleKind + " ***");
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
transpiler.setModuleKind(moduleKind);
|
||||
// if (moduleKind.equals(ModuleKind.commonjs)) {
|
||||
// transpiler.setBundle(true);
|
||||
// }
|
||||
initOutputDir();
|
||||
transpiler.transpile(logHandler, files);
|
||||
assertions.accept(logHandler);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("exception occured while running test " + getCurrentTestName() + " with module kind " + moduleKind);
|
||||
} finally {
|
||||
transpiler.setModuleKind(initialModuleKind);
|
||||
transpiler.setTsOutputDir(initialOutputDir);
|
||||
}
|
||||
}
|
||||
|
||||
protected void eval(BiConsumer<TestTranspilationHandler, EvaluationResult> assertions, SourceFile... files) {
|
||||
eval(new ModuleKind[] { ModuleKind.none, ModuleKind.commonjs }, assertions, files);
|
||||
}
|
||||
|
||||
protected void eval(ModuleKind[] moduleKinds, BiConsumer<TestTranspilationHandler, EvaluationResult> assertions, SourceFile... files) {
|
||||
for (ModuleKind moduleKind : moduleKinds) {
|
||||
eval(moduleKind, assertions, files);
|
||||
}
|
||||
}
|
||||
|
||||
protected void eval(ModuleKind moduleKind, BiConsumer<TestTranspilationHandler, EvaluationResult> assertions, SourceFile... files) {
|
||||
ModuleKind initialModuleKind = transpiler.getModuleKind();
|
||||
File initialOutputDir = transpiler.getTsOutputDir();
|
||||
try {
|
||||
logger.info("*** module kind: " + moduleKind + " ***");
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
EvaluationResult res = null;
|
||||
transpiler.setModuleKind(moduleKind);
|
||||
// touch will force the transpilation even if the files were already
|
||||
// transpiled
|
||||
SourceFile.touch(files);
|
||||
initOutputDir();
|
||||
res = transpiler.eval(logHandler, files);
|
||||
assertions.accept(logHandler, res);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("exception occured while running test " + getCurrentTestName() + " with module kind " + moduleKind);
|
||||
} finally {
|
||||
transpiler.setModuleKind(initialModuleKind);
|
||||
transpiler.setTsOutputDir(initialOutputDir);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
94
test/org/jsweet/test/transpiler/AmbientTests.java
Normal file
94
test/org/jsweet/test/transpiler/AmbientTests.java
Normal file
@ -0,0 +1,94 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.jsweet.test.transpiler.source.ambient.LibAccess;
|
||||
import org.jsweet.test.transpiler.source.ambient.LibAccessSubModule;
|
||||
import org.jsweet.test.transpiler.source.ambient.lib.Base;
|
||||
import org.jsweet.test.transpiler.source.ambient.lib.Extension;
|
||||
import org.jsweet.test.transpiler.source.ambient.lib.sub.C;
|
||||
import org.jsweet.transpiler.ModuleKind;
|
||||
import org.jsweet.transpiler.SourceFile;
|
||||
import org.jsweet.transpiler.util.EvaluationResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class AmbientTests extends AbstractTest {
|
||||
|
||||
@Test
|
||||
public void testLibAccess() throws Exception {
|
||||
File target = new File(transpiler.getTsOutputDir(), "lib.js");
|
||||
FileUtils.deleteQuietly(target);
|
||||
FileUtils.copyFile(new File("test/org/jsweet/test/transpiler/source/ambient/lib.js"), target);
|
||||
System.out.println("copied to " + target);
|
||||
|
||||
SourceFile libJs = new SourceFile(null) {
|
||||
{
|
||||
setJsFile(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return target.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void touch() {
|
||||
}
|
||||
};
|
||||
|
||||
// TODO: also test with modules (we need a requirable lib and a way to
|
||||
// specify modules in ambients)
|
||||
eval(ModuleKind.none, (logHandler, result) -> {
|
||||
Assert.assertTrue("test was not executed", result.get("baseExecuted"));
|
||||
Assert.assertTrue("extension was not executed", result.get("extensionExecuted"));
|
||||
} , libJs, getSourceFile(LibAccess.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLibAccessSubModule() throws Exception {
|
||||
File target = new File(transpiler.getTsOutputDir(), "libsub.js");
|
||||
FileUtils.deleteQuietly(target);
|
||||
FileUtils.copyFile(new File("test/org/jsweet/test/transpiler/source/ambient/libsub.js"), target);
|
||||
System.out.println("copied to " + target);
|
||||
|
||||
SourceFile libJs = new SourceFile(null) {
|
||||
{
|
||||
setJsFile(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return target.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void touch() {
|
||||
}
|
||||
};
|
||||
|
||||
// TODO: also test with modules (we need a requirable lib and a way to
|
||||
// specify modules in ambients)
|
||||
eval(ModuleKind.none, (logHandler, result) -> {
|
||||
Assert.assertTrue("test was not executed", result.get("baseExecuted"));
|
||||
Assert.assertTrue("extension was not executed", result.get("extensionExecuted"));
|
||||
} , libJs, getSourceFile(LibAccessSubModule.class), getSourceFile(Base.class),
|
||||
getSourceFile(Extension.class), getSourceFile(C.class));
|
||||
}
|
||||
|
||||
}
|
||||
89
test/org/jsweet/test/transpiler/ApiTests.java
Normal file
89
test/org/jsweet/test/transpiler/ApiTests.java
Normal file
@ -0,0 +1,89 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.jsweet.test.transpiler.source.api.CastMethods;
|
||||
import org.jsweet.test.transpiler.source.api.ForeachIteration;
|
||||
import org.jsweet.test.transpiler.source.api.JdkInvocations;
|
||||
import org.jsweet.test.transpiler.source.api.PrimitiveInstantiation;
|
||||
import org.jsweet.test.transpiler.source.api.QualifiedInstantiation;
|
||||
import org.jsweet.test.transpiler.source.api.WrongJdkInvocations;
|
||||
import org.jsweet.transpiler.JSweetProblem;
|
||||
import org.jsweet.transpiler.util.EvaluationResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ApiTests extends AbstractTest {
|
||||
|
||||
@Test
|
||||
public void testWrongJdkInvocations() {
|
||||
transpile(logHandler -> {
|
||||
Assert.assertEquals("There should be 7 errors", 7, logHandler.reportedProblems.size());
|
||||
Assert.assertEquals("Unexpected error", JSweetProblem.JDK_TYPE, logHandler.reportedProblems.get(0));
|
||||
Assert.assertEquals("Unexpected error", JSweetProblem.JDK_METHOD, logHandler.reportedProblems.get(1));
|
||||
Assert.assertEquals("Unexpected error", JSweetProblem.JDK_TYPE, logHandler.reportedProblems.get(2));
|
||||
Assert.assertEquals("Unexpected error", JSweetProblem.ERASED_METHOD, logHandler.reportedProblems.get(3));
|
||||
Assert.assertEquals("Unexpected error", JSweetProblem.JDK_METHOD, logHandler.reportedProblems.get(4));
|
||||
Assert.assertEquals("Unexpected error", JSweetProblem.JDK_METHOD, logHandler.reportedProblems.get(5));
|
||||
Assert.assertEquals("Unexpected error", JSweetProblem.JDK_METHOD, logHandler.reportedProblems.get(6));
|
||||
}, getSourceFile(WrongJdkInvocations.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJdkInvocations() {
|
||||
eval((logHandler, result) -> {
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
assertEquals("test", result.<String> get("s1"));
|
||||
assertEquals("m1", result.<String> get("s2"));
|
||||
assertEquals("e", result.<String> get("s3"));
|
||||
assertEquals("testc", result.<String> get("s4"));
|
||||
assertEquals(2, result.<Number> get("i1").intValue());
|
||||
assertEquals(-1, result.<Number> get("i2").intValue());
|
||||
}, getSourceFile(JdkInvocations.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForeachIteration() {
|
||||
eval((logHandler, r) -> {
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
Assert.assertEquals("Wrong behavior output trace", "abc", r.get("out"));
|
||||
}, getSourceFile(ForeachIteration.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveInstantiation() {
|
||||
transpile(logHandler -> {
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
}, getSourceFile(PrimitiveInstantiation.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQualifiedInstantiation() {
|
||||
transpile(logHandler -> {
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
}, getSourceFile(QualifiedInstantiation.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCastMethods() {
|
||||
transpile(logHandler -> {
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
}, getSourceFile(CastMethods.class));
|
||||
}
|
||||
|
||||
}
|
||||
72
test/org/jsweet/test/transpiler/CandiesTests.java
Normal file
72
test/org/jsweet/test/transpiler/CandiesTests.java
Normal file
@ -0,0 +1,72 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.jsweet.test.transpiler.source.candies.Angular;
|
||||
import org.jsweet.test.transpiler.source.candies.ExpressLib;
|
||||
import org.jsweet.test.transpiler.source.candies.GlobalsImport;
|
||||
import org.jsweet.test.transpiler.source.candies.JQuery;
|
||||
import org.jsweet.test.transpiler.source.candies.QualifiedNames;
|
||||
import org.jsweet.transpiler.ModuleKind;
|
||||
import org.junit.Test;
|
||||
|
||||
public class CandiesTests extends AbstractTest {
|
||||
|
||||
@Test
|
||||
public void testGlobalsImport() {
|
||||
// transpile(ModuleKind.none, logHandler -> {
|
||||
// logHandler.assertReportedProblems(JSweetProblem.INTERNAL_TSC_ERROR, //
|
||||
// JSweetProblem.INTERNAL_TSC_ERROR, JSweetProblem.INTERNAL_TSC_ERROR, //
|
||||
// JSweetProblem.INTERNAL_TSC_ERROR, JSweetProblem.INTERNAL_TSC_ERROR, //
|
||||
// JSweetProblem.INTERNAL_TSC_ERROR, JSweetProblem.INTERNAL_TSC_ERROR, //
|
||||
// JSweetProblem.INTERNAL_TSC_ERROR, JSweetProblem.INTERNAL_TSC_ERROR, //
|
||||
// JSweetProblem.INTERNAL_TSC_ERROR, JSweetProblem.INTERNAL_TSC_ERROR);
|
||||
// } , getSourceFile(GlobalsImport.class));
|
||||
transpile(ModuleKind.commonjs, logHandler -> {
|
||||
assertEquals(0, logHandler.getReportedProblems().size());
|
||||
} , getSourceFile(GlobalsImport.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQualifiedNames() {
|
||||
transpile(ModuleKind.commonjs, logHandler -> {
|
||||
assertEquals(0, logHandler.getReportedProblems().size());
|
||||
} , getSourceFile(QualifiedNames.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAngular() {
|
||||
transpile(logHandler -> {
|
||||
assertEquals(0, logHandler.getReportedProblems().size());
|
||||
} , getSourceFile(Angular.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJQuery() {
|
||||
transpile(logHandler -> {
|
||||
assertEquals(0, logHandler.getReportedProblems().size());
|
||||
} , getSourceFile(JQuery.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExpressLib() {
|
||||
transpile(ModuleKind.commonjs, logHandler -> {
|
||||
assertEquals(0, logHandler.getReportedProblems().size());
|
||||
} , getSourceFile(ExpressLib.class));
|
||||
}
|
||||
|
||||
}
|
||||
34
test/org/jsweet/test/transpiler/GenericsTests.java
Normal file
34
test/org/jsweet/test/transpiler/GenericsTests.java
Normal file
@ -0,0 +1,34 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.jsweet.test.transpiler.source.candies.QualifiedNames;
|
||||
import org.jsweet.test.transpiler.source.generics.InstantiationWithGenerics;
|
||||
import org.jsweet.transpiler.ModuleKind;
|
||||
import org.junit.Test;
|
||||
|
||||
public class GenericsTests extends AbstractTest {
|
||||
|
||||
@Test
|
||||
public void testInstantiationWithGenerics() {
|
||||
transpile(logHandler -> {
|
||||
assertEquals(0, logHandler.getReportedProblems().size());
|
||||
} , getSourceFile(InstantiationWithGenerics.class));
|
||||
}
|
||||
|
||||
}
|
||||
224
test/org/jsweet/test/transpiler/InitTests.java
Normal file
224
test/org/jsweet/test/transpiler/InitTests.java
Normal file
@ -0,0 +1,224 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.jsweet.test.transpiler.source.init.Constructor;
|
||||
import org.jsweet.test.transpiler.source.init.ConstructorField;
|
||||
import org.jsweet.test.transpiler.source.init.ConstructorFieldInInterface;
|
||||
import org.jsweet.test.transpiler.source.init.ConstructorMethod;
|
||||
import org.jsweet.test.transpiler.source.init.ConstructorMethodInInterface;
|
||||
import org.jsweet.test.transpiler.source.init.Initializer;
|
||||
import org.jsweet.test.transpiler.source.init.InitializerStatementConditionError;
|
||||
import org.jsweet.test.transpiler.source.init.InitializerStatementError;
|
||||
import org.jsweet.test.transpiler.source.init.InterfaceRawConstruction;
|
||||
import org.jsweet.test.transpiler.source.init.MultipleMains;
|
||||
import org.jsweet.test.transpiler.source.init.NoOptionalFieldsInClass;
|
||||
import org.jsweet.test.transpiler.source.init.StaticInitializer;
|
||||
import org.jsweet.test.transpiler.source.structural.OptionalField;
|
||||
import org.jsweet.test.transpiler.source.structural.OptionalFieldError;
|
||||
import org.jsweet.transpiler.JSweetProblem;
|
||||
import org.jsweet.transpiler.util.EvaluationResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class InitTests extends AbstractTest {
|
||||
|
||||
@Test
|
||||
public void testStaticInitializer() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
EvaluationResult result = transpiler.eval(logHandler, getSourceFile(StaticInitializer.class));
|
||||
assertEquals(4, result.<Number> get("n").intValue());
|
||||
assertEquals("test", result.<String> get("s"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitializer() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
EvaluationResult result = transpiler.eval(logHandler, getSourceFile(Initializer.class));
|
||||
assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
assertEquals(4, result.<Number> get("out").intValue());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitializerStatementError() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
transpiler.transpile(logHandler, getSourceFile(InitializerStatementError.class));
|
||||
assertEquals("There should be 1 problem", 1, logHandler.reportedProblems.size());
|
||||
assertTrue("Missing expected error on wrong initializer", logHandler.reportedProblems.contains(JSweetProblem.INVALID_INITIALIZER_STATEMENT));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitializerStatementWithConditionError() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
transpiler.transpile(logHandler, getSourceFile(InitializerStatementConditionError.class));
|
||||
assertEquals("Missing expected error on non-optional field", 1, logHandler.reportedProblems.size());
|
||||
assertEquals("Missing expected error on wrong initializer", JSweetProblem.INVALID_INITIALIZER_STATEMENT, logHandler.reportedProblems.get(0));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptionalField() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
transpiler.transpile(logHandler, getSourceFile(OptionalField.class));
|
||||
assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptionalFieldError() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
transpiler.transpile(logHandler, getSourceFile(OptionalFieldError.class));
|
||||
assertEquals("There should be 1 problem", 1, logHandler.reportedProblems.size());
|
||||
assertTrue("Missing expected error on optional field", logHandler.reportedProblems.contains(JSweetProblem.UNINITIALIZED_FIELD));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoOptionalFieldsInClass() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
transpiler.transpile(logHandler, getSourceFile(NoOptionalFieldsInClass.class));
|
||||
assertEquals("Missing expected warning on non-optional field", 1, logHandler.reportedProblems.size());
|
||||
assertTrue("Missing expected warning on non-optional field", logHandler.reportedProblems.contains(JSweetProblem.USELESS_OPTIONAL_ANNOTATION));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructors() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
transpiler.transpile(logHandler, getSourceFile(Constructor.class));
|
||||
assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorMethod() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
transpiler.transpile(logHandler, getSourceFile(ConstructorMethod.class));
|
||||
Assert.assertEquals("Missing constructor keyword error", 1, logHandler.reportedProblems.size());
|
||||
Assert.assertEquals("Missing constructor keyword error", JSweetProblem.CONSTRUCTOR_MEMBER, logHandler.reportedProblems.get(0));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorField() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
transpiler.transpile(logHandler, getSourceFile(ConstructorField.class));
|
||||
Assert.assertEquals("Missing constructor keyword error", 1, logHandler.reportedProblems.size());
|
||||
Assert.assertEquals("Missing constructor keyword error", JSweetProblem.CONSTRUCTOR_MEMBER, logHandler.reportedProblems.get(0));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorFieldInInterface() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
transpiler.transpile(logHandler, getSourceFile(ConstructorFieldInInterface.class));
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorMethodInInterface() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
transpiler.transpile(logHandler, getSourceFile(ConstructorMethodInInterface.class));
|
||||
Assert.assertEquals("Missing expected error on constructor method", 1, logHandler.reportedProblems.size());
|
||||
Assert.assertEquals("Missing expected error on constructor method", JSweetProblem.CONSTRUCTOR_MEMBER, logHandler.reportedProblems.get(0));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInterfaceRawConstruction() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
transpiler.transpile(logHandler, getSourceFile(InterfaceRawConstruction.class));
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleMains() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
EvaluationResult result = transpiler.eval(logHandler, getSourceFile(MultipleMains.class));
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
|
||||
assertEquals(0, result.<Number> get("a").intValue());
|
||||
assertNull(result.<Number> get("b"));
|
||||
assertEquals(1, result.<Number> get("c").intValue());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
69
test/org/jsweet/test/transpiler/OverloadTests.java
Normal file
69
test/org/jsweet/test/transpiler/OverloadTests.java
Normal file
@ -0,0 +1,69 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.jsweet.test.transpiler.source.overload.Overload;
|
||||
import org.jsweet.test.transpiler.source.overload.WrongOverload;
|
||||
import org.jsweet.test.transpiler.source.overload.WrongOverloads;
|
||||
import org.jsweet.transpiler.JSweetProblem;
|
||||
import org.jsweet.transpiler.util.EvaluationResult;
|
||||
import org.junit.Test;
|
||||
|
||||
public class OverloadTests extends AbstractTest {
|
||||
|
||||
@Test
|
||||
public void testOverload() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
EvaluationResult result = transpiler.eval(logHandler, getSourceFile(Overload.class));
|
||||
assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
assertEquals("default1", result.<String> get("res1"));
|
||||
assertEquals("s11", result.<String> get("res2"));
|
||||
assertEquals("s22", result.<String> get("res3"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongOverload() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
transpiler.transpile(logHandler, getSourceFile(WrongOverload.class));
|
||||
logHandler.assertReportedProblems(JSweetProblem.INVALID_OVERLOAD, JSweetProblem.INVALID_OVERLOAD);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongOverloads() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
transpiler.transpile(logHandler, getSourceFile(WrongOverloads.class));
|
||||
logHandler.assertReportedProblems(JSweetProblem.INVALID_OVERLOAD, JSweetProblem.INVALID_OVERLOAD, JSweetProblem.INVALID_OVERLOAD,
|
||||
JSweetProblem.INVALID_OVERLOAD, JSweetProblem.INVALID_OVERLOAD, JSweetProblem.INVALID_OVERLOAD);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
104
test/org/jsweet/test/transpiler/RequireTests.java
Normal file
104
test/org/jsweet/test/transpiler/RequireTests.java
Normal file
@ -0,0 +1,104 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.jsweet.test.transpiler.source.blocksgame.Ball;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.BlockElement;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.Factory;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.GameArea;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.GameManager;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.Globals;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.Player;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.AnimatedElement;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.Collisions;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.Direction;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.Line;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.MobileElement;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.Point;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.Rectangle;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.Vector;
|
||||
import org.jsweet.test.transpiler.source.require.TopLevel1;
|
||||
import org.jsweet.test.transpiler.source.require.TopLevel2;
|
||||
import org.jsweet.test.transpiler.source.require.a.A;
|
||||
import org.jsweet.test.transpiler.source.require.a.Use1;
|
||||
import org.jsweet.test.transpiler.source.require.a.Use2;
|
||||
import org.jsweet.test.transpiler.source.require.a.b.B1;
|
||||
import org.jsweet.test.transpiler.source.require.a.b.B2;
|
||||
import org.jsweet.test.transpiler.source.require.b.ClassImport;
|
||||
import org.jsweet.test.transpiler.source.require.b.ClassImportImplicitRequire;
|
||||
import org.jsweet.test.transpiler.source.require.b.GlobalsImport;
|
||||
import org.jsweet.transpiler.ModuleKind;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
public class RequireTests extends AbstractTest {
|
||||
|
||||
@Test
|
||||
public void testClassImportImplicitRequire() {
|
||||
transpile(ModuleKind.none, (logHandler) -> {
|
||||
assertTrue(logHandler.getReportedProblems().size() > 0);
|
||||
} , getSourceFile(A.class), getSourceFile(B1.class), getSourceFile(B2.class), getSourceFile(ClassImportImplicitRequire.class));
|
||||
|
||||
// we cannot evaluate this test without the express module
|
||||
transpile(ModuleKind.commonjs, (logHandler) -> {
|
||||
assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
} , getSourceFile(A.class), getSourceFile(B1.class), getSourceFile(B2.class), getSourceFile(ClassImportImplicitRequire.class));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassImport() {
|
||||
transpile(logHandler -> {
|
||||
assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
} , getSourceFile(A.class), getSourceFile(ClassImport.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBlocksgame() {
|
||||
transpile(logHandler -> {
|
||||
assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
} , getSourceFile(Point.class), getSourceFile(Vector.class), getSourceFile(AnimatedElement.class), getSourceFile(Line.class),
|
||||
getSourceFile(MobileElement.class), getSourceFile(Rectangle.class), getSourceFile(Direction.class), getSourceFile(Collisions.class),
|
||||
getSourceFile(Ball.class), getSourceFile(Globals.class), getSourceFile(BlockElement.class), getSourceFile(Factory.class),
|
||||
getSourceFile(GameArea.class), getSourceFile(GameManager.class), getSourceFile(Player.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalsImport() {
|
||||
transpile(logHandler -> {
|
||||
assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
} , getSourceFile(org.jsweet.test.transpiler.source.require.globals.Globals.class), getSourceFile(GlobalsImport.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImportsFromTopTevels() {
|
||||
eval((logHandler, result) -> {
|
||||
assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
assertTrue(result.get("mInvoked"));
|
||||
} , getSourceFile(A.class), getSourceFile(TopLevel1.class), getSourceFile(TopLevel2.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImportsFromNonTopTevels() {
|
||||
eval((logHandler, result) -> {
|
||||
assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
assertTrue(result.get("mInvokedOnB1"));
|
||||
} , getSourceFile(B1.class), getSourceFile(Use1.class), getSourceFile(Use2.class));
|
||||
}
|
||||
|
||||
}
|
||||
226
test/org/jsweet/test/transpiler/StructuralTests.java
Normal file
226
test/org/jsweet/test/transpiler/StructuralTests.java
Normal file
@ -0,0 +1,226 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler;
|
||||
|
||||
|
||||
import static org.jsweet.transpiler.JSweetProblem.*;
|
||||
import static org.jsweet.transpiler.JSweetProblem.GLOBAL_CONSTRUCTOR_DEF;
|
||||
import static org.jsweet.transpiler.JSweetProblem.GLOBAL_INDEXER_GET;
|
||||
import static org.jsweet.transpiler.JSweetProblem.GLOBAL_INDEXER_SET;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.jsweet.test.transpiler.source.structural.AbstractClass;
|
||||
import org.jsweet.test.transpiler.source.structural.AutoImportClassesInSamePackage;
|
||||
import org.jsweet.test.transpiler.source.structural.AutoImportClassesInSamePackageUsed;
|
||||
import org.jsweet.test.transpiler.source.structural.Enums;
|
||||
import org.jsweet.test.transpiler.source.structural.ExtendsClassInSameFile;
|
||||
import org.jsweet.test.transpiler.source.structural.ExtendsObject;
|
||||
import org.jsweet.test.transpiler.source.structural.GlobalsAccess;
|
||||
import org.jsweet.test.transpiler.source.structural.Inheritance;
|
||||
import org.jsweet.test.transpiler.source.structural.InnerClass;
|
||||
import org.jsweet.test.transpiler.source.structural.NameClashes;
|
||||
import org.jsweet.test.transpiler.source.structural.NoInstanceofForInterfaces;
|
||||
import org.jsweet.test.transpiler.source.structural.TwoClassesInSameFile;
|
||||
import org.jsweet.test.transpiler.source.structural.WrongConstructsInEnums;
|
||||
import org.jsweet.test.transpiler.source.structural.WrongConstructsInInterfaces;
|
||||
import org.jsweet.test.transpiler.source.structural.globalclasses.Globals;
|
||||
import org.jsweet.test.transpiler.source.structural.globalclasses.a.GlobalsConstructor;
|
||||
import org.jsweet.test.transpiler.source.structural.globalclasses.b.GlobalFunctionStaticGetSet;
|
||||
import org.jsweet.test.transpiler.source.structural.globalclasses.c.GlobalFunctionGetSet;
|
||||
import org.jsweet.test.transpiler.source.structural.globalclasses.d.GlobalFunctionAccessFromMain;
|
||||
import org.jsweet.test.transpiler.source.structural.globalclasses.f.GlobalFunctionStaticDelete;
|
||||
import org.jsweet.test.transpiler.source.structural.globalclasses.g.GlobalFunctionDelete;
|
||||
import org.jsweet.transpiler.JSweetProblem;
|
||||
import org.jsweet.transpiler.ModuleKind;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class StructuralTests extends AbstractTest {
|
||||
|
||||
@Test
|
||||
public void testFieldMethodNameClashes() {
|
||||
transpile(logHandler -> {
|
||||
assertEquals("There should be two problems", 2, logHandler.reportedProblems.size());
|
||||
assertTrue("Missing expected problem: " + JSweetProblem.FIELD_CONFLICTS_METHOD,
|
||||
logHandler.reportedProblems.contains(JSweetProblem.FIELD_CONFLICTS_METHOD));
|
||||
assertTrue("Missing expected problem: " + JSweetProblem.METHOD_CONFLICTS_FIELD,
|
||||
logHandler.reportedProblems.contains(JSweetProblem.METHOD_CONFLICTS_FIELD));
|
||||
} , getSourceFile(NameClashes.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTwoClassesInSameFile() {
|
||||
transpile(logHandler -> {
|
||||
assertEquals("There should be 0 problems", 0, logHandler.reportedProblems.size());
|
||||
} , getSourceFile(TwoClassesInSameFile.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtendsClassInSameFile() {
|
||||
transpile(logHandler -> {
|
||||
assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
} , getSourceFile(ExtendsClassInSameFile.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInnerClass() {
|
||||
transpile(logHandler -> {
|
||||
assertEquals("There should be 1 problem", 1, logHandler.reportedProblems.size());
|
||||
assertTrue("Missing expected problem: " + JSweetProblem.INNER_CLASS, logHandler.reportedProblems.contains(JSweetProblem.INNER_CLASS));
|
||||
} , getSourceFile(InnerClass.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInheritance() {
|
||||
transpile(logHandler -> {
|
||||
assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
} , getSourceFile(Inheritance.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongConstructsInInterfaces() {
|
||||
transpile(logHandler -> {
|
||||
assertEquals("There should be 11 errors", 11, logHandler.reportedProblems.size());
|
||||
assertEquals("Wrong error type", JSweetProblem.INTERFACE_MUST_BE_ABSTRACT, logHandler.reportedProblems.get(0));
|
||||
assertEquals("Wrong error type", JSweetProblem.INVALID_FIELD_INITIALIZER_IN_INTERFACE, logHandler.reportedProblems.get(1));
|
||||
assertEquals("Wrong error type", JSweetProblem.INVALID_STATIC_IN_INTERFACE, logHandler.reportedProblems.get(2));
|
||||
assertEquals("Wrong error type", JSweetProblem.INVALID_PRIVATE_IN_INTERFACE, logHandler.reportedProblems.get(3));
|
||||
assertEquals("Wrong error type", JSweetProblem.INVALID_METHOD_BODY_IN_INTERFACE, logHandler.reportedProblems.get(4));
|
||||
assertEquals("Wrong error type", JSweetProblem.NATIVE_MODIFIER_IS_NOT_ALLOWED, logHandler.reportedProblems.get(5));
|
||||
assertEquals("Wrong error type", JSweetProblem.INVALID_METHOD_BODY_IN_INTERFACE, logHandler.reportedProblems.get(6));
|
||||
assertEquals("Wrong error type", JSweetProblem.NATIVE_MODIFIER_IS_NOT_ALLOWED, logHandler.reportedProblems.get(7));
|
||||
assertEquals("Wrong error type", JSweetProblem.INVALID_STATIC_IN_INTERFACE, logHandler.reportedProblems.get(8));
|
||||
assertEquals("Wrong error type", JSweetProblem.INVALID_INITIALIZER_IN_INTERFACE, logHandler.reportedProblems.get(9));
|
||||
assertEquals("Wrong error type", JSweetProblem.INVALID_INITIALIZER_IN_INTERFACE, logHandler.reportedProblems.get(10));
|
||||
} , getSourceFile(WrongConstructsInInterfaces.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongConstructsInEnums() {
|
||||
transpile(logHandler -> {
|
||||
logHandler.assertReportedProblems(JSweetProblem.INVALID_FIELD_IN_ENUM, JSweetProblem.INVALID_FIELD_IN_ENUM, JSweetProblem.INVALID_FIELD_IN_ENUM,
|
||||
JSweetProblem.INVALID_CONSTRUCTOR_IN_ENUM, JSweetProblem.INVALID_METHOD_IN_ENUM, JSweetProblem.INVALID_METHOD_IN_ENUM,
|
||||
JSweetProblem.INVALID_METHOD_IN_ENUM);
|
||||
} , getSourceFile(WrongConstructsInEnums.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAbstractClass() {
|
||||
transpile(logHandler -> {
|
||||
assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
} , getSourceFile(AbstractClass.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtendsObject() {
|
||||
transpile(logHandler -> {
|
||||
assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
} , getSourceFile(ExtendsObject.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoInstanceofForInterfaces() {
|
||||
transpile(logHandler -> {
|
||||
assertEquals("There should be 2 problems", 2, logHandler.reportedProblems.size());
|
||||
assertEquals("Missing expected problem: " + JSweetProblem.INVALID_INSTANCEOF_INTERFACE, JSweetProblem.INVALID_INSTANCEOF_INTERFACE,
|
||||
logHandler.reportedProblems.get(0));
|
||||
assertEquals("Missing expected problem: " + JSweetProblem.INVALID_INSTANCEOF_INTERFACE, JSweetProblem.INVALID_INSTANCEOF_INTERFACE,
|
||||
logHandler.reportedProblems.get(1));
|
||||
} , getSourceFile(NoInstanceofForInterfaces.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnums() {
|
||||
eval((logHandler, r) -> {
|
||||
assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
Assert.assertEquals("Wrong enum behavior", 0, ((Number) r.get("value")).intValue());
|
||||
Assert.assertEquals("Wrong enum behavior", "A", r.get("nameOfA"));
|
||||
Assert.assertEquals("Wrong enum behavior", 0, ((Number) r.get("ordinalOfA")).intValue());
|
||||
Assert.assertEquals("Wrong enum behavior", 0, ((Number) r.get("valueOfA")).intValue());
|
||||
Assert.assertEquals("Wrong enum behavior", 2, ((Number) r.get("valueOfC")).intValue());
|
||||
} , getSourceFile(Enums.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoConstructorInGlobalsClass() {
|
||||
transpile(logHandler -> {
|
||||
logHandler.assertReportedProblems(//
|
||||
GLOBAL_CONSTRUCTOR_DEF, //
|
||||
GLOBAL_CANNOT_BE_INSTANTIATED);
|
||||
} , getSourceFile(GlobalsConstructor.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoGetSetInGlobalFunction() {
|
||||
transpile(logHandler -> {
|
||||
logHandler.assertReportedProblems(GLOBAL_INDEXER_GET, GLOBAL_INDEXER_SET, GLOBAL_INDEXER_GET, GLOBAL_INDEXER_SET);
|
||||
} , getSourceFile(GlobalFunctionGetSet.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoStaticGetSetInGlobalFunction() {
|
||||
transpile(logHandler -> {
|
||||
logHandler.assertReportedProblems(GLOBAL_INDEXER_GET, GLOBAL_INDEXER_SET);
|
||||
} , getSourceFile(GlobalFunctionStaticGetSet.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoStaticDeleteInGlobalFunction() {
|
||||
transpile(logHandler -> {
|
||||
logHandler.assertReportedProblems(GLOBAL_DELETE);
|
||||
} , getSourceFile(GlobalFunctionStaticDelete.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoDeleteInGlobalFunction() {
|
||||
transpile(logHandler -> {
|
||||
logHandler.assertReportedProblems(GLOBAL_DELETE);
|
||||
} , getSourceFile(GlobalFunctionDelete.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalFunctionAccessFromMain() {
|
||||
eval((logHandler, r) -> {
|
||||
assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
Assert.assertEquals(true, r.get("mainInvoked"));
|
||||
Assert.assertEquals("invoked", r.get("test"));
|
||||
Assert.assertEquals("invoked1_2", r.get("Static"));
|
||||
Assert.assertEquals("invoked1_2", r.get("test2"));
|
||||
} , getSourceFile(Globals.class),
|
||||
getSourceFile(org.jsweet.test.transpiler.source.structural.globalclasses.e.Globals.class),
|
||||
getSourceFile(GlobalFunctionAccessFromMain.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoImportClassesInSamePackage() {
|
||||
eval((logHandler, r) -> {
|
||||
assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
Assert.assertEquals("A method was not executed as expected", true, r.get("m1"));
|
||||
Assert.assertEquals("A method was not executed as expected", true, r.get("m2"));
|
||||
Assert.assertEquals("A method was not executed as expected", true, r.get("sm1"));
|
||||
Assert.assertEquals("A method was not executed as expected", true, r.get("sm2"));
|
||||
} , getSourceFile(AutoImportClassesInSamePackageUsed.class), getSourceFile(AutoImportClassesInSamePackage.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalsAccess() {
|
||||
eval((logHandler, r) -> {
|
||||
assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
Assert.assertEquals("Renaud Pawlak", r.get("result"));
|
||||
} , getSourceFile(GlobalsAccess.class));
|
||||
}
|
||||
|
||||
}
|
||||
142
test/org/jsweet/test/transpiler/SyntaxTests.java
Normal file
142
test/org/jsweet/test/transpiler/SyntaxTests.java
Normal file
@ -0,0 +1,142 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.jsweet.test.transpiler.source.syntax.AnnotationQualifiedNames;
|
||||
import org.jsweet.test.transpiler.source.syntax.FinalVariables;
|
||||
import org.jsweet.test.transpiler.source.syntax.FinalVariablesRuntime;
|
||||
import org.jsweet.test.transpiler.source.syntax.GlobalsInvocation;
|
||||
import org.jsweet.test.transpiler.source.syntax.IndexedAccessInStaticScope;
|
||||
import org.jsweet.test.transpiler.source.syntax.Keywords;
|
||||
import org.jsweet.test.transpiler.source.syntax.Labels;
|
||||
import org.jsweet.test.transpiler.source.syntax.QualifiedNames;
|
||||
import org.jsweet.test.transpiler.source.syntax.References;
|
||||
import org.jsweet.test.transpiler.source.syntax.SpecialFunctions;
|
||||
import org.jsweet.test.transpiler.source.syntax.ValidIndexedAccesses;
|
||||
import org.jsweet.test.transpiler.source.typing.InvalidIndexedAccesses;
|
||||
import org.jsweet.transpiler.JSweetProblem;
|
||||
import org.jsweet.transpiler.util.EvaluationResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SyntaxTests extends AbstractTest {
|
||||
|
||||
@Test
|
||||
public void testReferences() {
|
||||
eval((logHandler, r) -> {
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
Assert.assertEquals("foo", r.get("s"));
|
||||
Assert.assertEquals((Number) 5, r.get("i"));
|
||||
} , getSourceFile(References.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKeywords() {
|
||||
transpile((logHandler) -> {
|
||||
Assert.assertEquals("There should be no errors", 5, logHandler.reportedProblems.size());
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Assert.assertEquals("Error #" + i + " is not of the right kind", JSweetProblem.JS_KEYWORD_CONFLICT, logHandler.reportedProblems.get(i));
|
||||
}
|
||||
} , getSourceFile(Keywords.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQualifiedNames() {
|
||||
transpile((logHandler) -> {
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
} , getSourceFile(QualifiedNames.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotationQualifiedNames() {
|
||||
transpile((logHandler) -> {
|
||||
Assert.assertEquals("Missing expected error", 1, logHandler.reportedProblems.size());
|
||||
Assert.assertEquals("Wrong type of expected error", JSweetProblem.INVALID_METHOD_BODY_IN_INTERFACE, logHandler.reportedProblems.get(0));
|
||||
} , getSourceFile(AnnotationQualifiedNames.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalsInvocation() {
|
||||
transpile((logHandler) -> {
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
} , getSourceFile(GlobalsInvocation.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecialFunctions() {
|
||||
transpile((logHandler) -> {
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
} , getSourceFile(SpecialFunctions.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLabels() {
|
||||
transpile((logHandler) -> {
|
||||
Assert.assertEquals("Missing expected errors", 2, logHandler.reportedProblems.size());
|
||||
Assert.assertEquals("Wrong type of expected error", JSweetProblem.LABELS_ARE_NOT_SUPPORTED, logHandler.reportedProblems.get(0));
|
||||
Assert.assertEquals("Wrong type of expected error", JSweetProblem.LABELS_ARE_NOT_SUPPORTED, logHandler.reportedProblems.get(1));
|
||||
} , getSourceFile(Labels.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFinalVariables() {
|
||||
transpile((logHandler) -> {
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
} , getSourceFile(FinalVariables.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFinalVariablesRuntime() {
|
||||
try {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
EvaluationResult r = transpiler.eval("Java", logHandler, getSourceFile(FinalVariablesRuntime.class));
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
Assert.assertEquals("Wrong behavior output trace", "11223344", r.get("out").toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
eval((logHandler, r) -> {
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
Assert.assertEquals("Wrong behavior output trace", "11223344", r.get("out").toString());
|
||||
} , getSourceFile(FinalVariablesRuntime.class));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexedAccessInStaticScope() {
|
||||
eval((logHandler, r) -> {
|
||||
Assert.assertEquals("Wrong output value", "value", r.get("out_a"));
|
||||
Assert.assertNull("Wrong output value", r.get("out_b"));
|
||||
Assert.assertNull("var wasn't deleted", r.get("out_c"));
|
||||
} , getSourceFile(IndexedAccessInStaticScope.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidIndexedAccesses() {
|
||||
eval((logHandler, r) -> {
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
|
||||
assertEquals("value", r.get("field1"));
|
||||
assertNull(r.get("field2"));
|
||||
assertNull(r.get("field3"));
|
||||
} , getSourceFile(ValidIndexedAccesses.class));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.jsweet.transpiler.JSweetProblem;
|
||||
import org.jsweet.transpiler.JSweetTranspiler;
|
||||
import org.jsweet.transpiler.SourceFile;
|
||||
import org.jsweet.transpiler.TranspilationHandler;
|
||||
|
||||
public class TestTranspilationHandler implements TranspilationHandler {
|
||||
|
||||
List<JSweetProblem> reportedProblems = new ArrayList<>();
|
||||
List<SourcePosition> reportedSourcePositions = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void report(JSweetProblem problem, SourcePosition sourcePosition, String message) {
|
||||
System.out.println(problem.getSeverity().toString() + ": " + message + (sourcePosition == null ? "" : " at line " + sourcePosition.getStartLine()));
|
||||
reportedProblems.add(problem);
|
||||
reportedSourcePositions.add(sourcePosition);
|
||||
}
|
||||
|
||||
public void assertReportedProblems(JSweetProblem... expectedProblems) {
|
||||
List<JSweetProblem> expectedProblemsList = Arrays.asList(expectedProblems);
|
||||
assertEquals(expectedProblemsList, reportedProblems);
|
||||
}
|
||||
|
||||
public List<JSweetProblem> getReportedProblems() {
|
||||
return reportedProblems;
|
||||
}
|
||||
|
||||
public List<SourcePosition> getReportedSourcePositions() {
|
||||
return reportedSourcePositions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompleted(JSweetTranspiler transpiler, boolean fullPass, SourceFile[] files) {
|
||||
}
|
||||
|
||||
}
|
||||
59
test/org/jsweet/test/transpiler/ThrowableTests.java
Normal file
59
test/org/jsweet/test/transpiler/ThrowableTests.java
Normal file
@ -0,0 +1,59 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.jsweet.test.transpiler.source.throwable.InvalidTryCatchTest;
|
||||
import org.jsweet.test.transpiler.source.throwable.TryCatchFinallyTest;
|
||||
import org.jsweet.transpiler.JSweetProblem;
|
||||
import org.jsweet.transpiler.util.EvaluationResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ThrowableTests extends AbstractTest {
|
||||
|
||||
@Test
|
||||
public void testTryCatchFinally() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
EvaluationResult r = transpiler.eval(logHandler, getSourceFile(TryCatchFinallyTest.class));
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
Assert.assertNotNull("Test was not executed", r.get("executed"));
|
||||
Assert.assertEquals("Expected a message when the catch clause is executed", "test-message", r.get("message"));
|
||||
Assert.assertNotNull("Finally was not executed", r.get("finally_executed"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidTryCatch() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
transpiler.transpile(logHandler, getSourceFile(InvalidTryCatchTest.class));
|
||||
Assert.assertEquals("There should be 4 errors", 4, logHandler.reportedProblems.size());
|
||||
Assert.assertEquals("Unexpected error", JSweetProblem.TRY_WITH_MULTIPLE_CATCHES, logHandler.reportedProblems.get(0));
|
||||
Assert.assertEquals("Unexpected error", JSweetProblem.UNSUPPORTED_TRY_WITH_RESOURCE, logHandler.reportedProblems.get(1));
|
||||
Assert.assertEquals("Unexpected error", JSweetProblem.TRY_WITHOUT_CATCH_OR_FINALLY, logHandler.reportedProblems.get(2));
|
||||
Assert.assertEquals("Unexpected error", JSweetProblem.JDK_METHOD, logHandler.reportedProblems.get(3));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
144
test/org/jsweet/test/transpiler/TranspilerTests.java
Normal file
144
test/org/jsweet/test/transpiler/TranspilerTests.java
Normal file
@ -0,0 +1,144 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.jsweet.JSweetCommandLineLauncher;
|
||||
import org.jsweet.test.transpiler.source.overload.Overload;
|
||||
import org.jsweet.test.transpiler.source.structural.AbstractClass;
|
||||
import org.jsweet.transpiler.JSweetTranspiler;
|
||||
import org.jsweet.transpiler.ModuleKind;
|
||||
import org.jsweet.transpiler.SourceFile;
|
||||
import org.jsweet.transpiler.util.ProcessUtil;
|
||||
import org.jsweet.transpiler.util.Util;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import jsweet.util.StringTypes.tr;
|
||||
|
||||
public class TranspilerTests extends AbstractTest {
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testTranspilerWatchMode() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
File overload = getSourceFile(Overload.class).getJavaFile();
|
||||
File abstractClass = getSourceFile(AbstractClass.class).getJavaFile();
|
||||
JSweetTranspiler transpiler = new JSweetTranspiler();
|
||||
transpiler.setTscWatchMode(true);
|
||||
transpiler.setPreserveSourceLineNumbers(true);
|
||||
long t = System.currentTimeMillis();
|
||||
transpiler.transpile(logHandler, new SourceFile(overload), new SourceFile(abstractClass));
|
||||
t = System.currentTimeMillis() - t;
|
||||
assertEquals("There should be no problems", 0, logHandler.reportedProblems.size());
|
||||
assertTrue("Wrong transpiler state", transpiler.isTscWatchMode());
|
||||
assertEquals("Wrong transpiler state", 2, transpiler.getWatchedFiles().length);
|
||||
assertEquals("Wrong transpiler state", overload, transpiler.getWatchedFile(overload).getJavaFile());
|
||||
|
||||
Thread.sleep(Math.max(4000, t * 5));
|
||||
|
||||
assertTrue("File not generated", transpiler.getWatchedFile(overload).getJsFile().exists());
|
||||
|
||||
long ts1 = transpiler.getWatchedFile(overload).getJsFileLastTranspiled();
|
||||
|
||||
transpiler.getWatchedFile(overload).getTsFile().setLastModified(System.currentTimeMillis());
|
||||
|
||||
Thread.sleep(Math.max(2000, t * 4));
|
||||
|
||||
assertTrue("File not regenerated", transpiler.getWatchedFile(overload).getJsFileLastTranspiled() != ts1);
|
||||
|
||||
transpiler.transpile(logHandler, new SourceFile(overload));
|
||||
assertEquals("There should be no problems", 0, logHandler.reportedProblems.size());
|
||||
assertTrue("Wrong transpiler state", transpiler.isTscWatchMode());
|
||||
assertEquals("Wrong transpiler state", 2, transpiler.getWatchedFiles().length);
|
||||
assertEquals("Wrong transpiler state", overload, transpiler.getWatchedFile(overload).getJavaFile());
|
||||
|
||||
Thread.sleep(Math.max(2000, t * 4));
|
||||
|
||||
assertTrue("File not regenerated", transpiler.getWatchedFile(overload).getJsFileLastTranspiled() != ts1);
|
||||
|
||||
transpiler.resetTscWatchMode();
|
||||
|
||||
transpiler.transpile(logHandler, new SourceFile(overload));
|
||||
assertEquals("There should be no problems", 0, logHandler.reportedProblems.size());
|
||||
assertTrue("Wrong transpiler state", transpiler.isTscWatchMode());
|
||||
assertEquals("Wrong transpiler state", 1, transpiler.getWatchedFiles().length);
|
||||
assertEquals("Wrong transpiler state", overload, transpiler.getWatchedFile(overload).getJavaFile());
|
||||
|
||||
Thread.sleep(Math.max(1000, t * 2));
|
||||
|
||||
assertTrue("File not regenerated", transpiler.getWatchedFile(overload).getJsFileLastTranspiled() != ts1);
|
||||
|
||||
transpiler.setTscWatchMode(false);
|
||||
SourceFile sf = new SourceFile(overload);
|
||||
transpiler.transpile(logHandler, sf);
|
||||
assertEquals("There should be no problems", 0, logHandler.reportedProblems.size());
|
||||
assertTrue("Wrong transpiler state", !transpiler.isTscWatchMode());
|
||||
assertTrue("Wrong transpiler state", transpiler.getWatchedFiles() == null);
|
||||
|
||||
ts1 = sf.getJsFileLastTranspiled();
|
||||
|
||||
sf.getTsFile().setLastModified(System.currentTimeMillis());
|
||||
|
||||
Thread.sleep(Math.max(1000, t * 2));
|
||||
|
||||
assertTrue("File regenerated", sf.getJsFileLastTranspiled() == ts1);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTscInstallation() throws Throwable {
|
||||
ProcessUtil.uninstallNodePackage("typescript", true);
|
||||
transpiler.cleanWorkingDirectory();
|
||||
transpile(ModuleKind.none, h -> h.assertReportedProblems(), getSourceFile(Overload.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandLine() throws Throwable {
|
||||
File outDir = new File(new File(TMPOUT_DIR), getCurrentTestName() + "/" + ModuleKind.none);
|
||||
|
||||
Process process = ProcessUtil.runCommand("java", line -> {
|
||||
System.out.println(line);
|
||||
} , null, "-cp", System.getProperty("java.class.path"), //
|
||||
JSweetCommandLineLauncher.class.getName(), //
|
||||
"--tsout", outDir.getPath(), //
|
||||
"--jsout", outDir.getPath(), //
|
||||
"--debug", //
|
||||
"-i", "test/org/jsweet/test/transpiler/source/blocksgame");
|
||||
|
||||
assertTrue(process.exitValue() == 0);
|
||||
LinkedList<File> files = new LinkedList<>();
|
||||
Util.addFiles(".ts", outDir, files);
|
||||
assertTrue(!files.isEmpty());
|
||||
Util.addFiles(".js", outDir, files);
|
||||
assertTrue(!files.isEmpty());
|
||||
Util.addFiles(".js.map", outDir, files);
|
||||
assertTrue(!files.isEmpty());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
159
test/org/jsweet/test/transpiler/TsComparisonTest.java
Normal file
159
test/org/jsweet/test/transpiler/TsComparisonTest.java
Normal file
@ -0,0 +1,159 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.jsweet.test.transpiler.source.tscomparison.AbstractClasses;
|
||||
import org.jsweet.test.transpiler.source.tscomparison.ActualScoping;
|
||||
import org.jsweet.test.transpiler.source.tscomparison.CompileTimeWarnings;
|
||||
import org.jsweet.test.transpiler.source.tscomparison.OtherThisExample;
|
||||
import org.jsweet.test.transpiler.source.tscomparison.SaferVarargs;
|
||||
import org.jsweet.test.transpiler.source.tscomparison.StrongerTyping;
|
||||
import org.jsweet.test.transpiler.source.tscomparison.ThisIsThis;
|
||||
import org.jsweet.transpiler.SourceFile;
|
||||
import org.jsweet.transpiler.util.EvaluationResult;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TsComparisonTest extends AbstractTest {
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void strongerTypingTest() {
|
||||
// jsweet part
|
||||
SourceFile file = getSourceFile(StrongerTyping.class);
|
||||
eval(file);
|
||||
|
||||
// ts part
|
||||
evalTs(getTsSourceFile(file));
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void compileTimeWarningsTest() {
|
||||
// jsweet part
|
||||
SourceFile file = getSourceFile(CompileTimeWarnings.class);
|
||||
eval(file);
|
||||
|
||||
// ts part
|
||||
evalTs(getTsSourceFile(file));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void abstractClassesTest() {
|
||||
// jsweet part
|
||||
SourceFile file = getSourceFile(AbstractClasses.class);
|
||||
eval(file);
|
||||
|
||||
// ts part
|
||||
evalTs(getTsSourceFile(file));
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void actualScopingTest() {
|
||||
// jsweet part
|
||||
SourceFile file = getSourceFile(ActualScoping.class);
|
||||
eval(file);
|
||||
|
||||
// ts part
|
||||
evalTs(getTsSourceFile(file));
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void thisIsThisTest() {
|
||||
// jsweet part
|
||||
SourceFile file = getSourceFile(ThisIsThis.class);
|
||||
eval(file);
|
||||
|
||||
// ts part
|
||||
evalTs(getTsSourceFile(file));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void otherThisExampleTest() {
|
||||
// jsweet part
|
||||
SourceFile file = getSourceFile(OtherThisExample.class);
|
||||
eval(file);
|
||||
|
||||
|
||||
// ts part (to be done)
|
||||
//evalTs(getTsSourceFile(file));
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void saferVarargsTest() {
|
||||
// jsweet part
|
||||
|
||||
SourceFile file = getSourceFile(SaferVarargs.class);
|
||||
EvaluationResult result = eval(file);
|
||||
assertEquals("foo", result.get("firstArg"));
|
||||
|
||||
// ts part
|
||||
result = evalTs(getTsSourceFile(file));
|
||||
|
||||
assertTrue(result.get("firstArg").getClass().isArray());
|
||||
Object[] res = (Object[]) result.get("firstArg");
|
||||
assertEquals("blah", res[0]);
|
||||
assertEquals("bluh", res[1]);
|
||||
}
|
||||
|
||||
private TsSourceFile getTsSourceFile(SourceFile jsweetSourceFile) {
|
||||
String javaTestFilePath = jsweetSourceFile.getJavaFile().getAbsolutePath();
|
||||
File tsFile = new File(javaTestFilePath.substring(0, javaTestFilePath.length() - 5) + ".ts");
|
||||
TsSourceFile tsSourceFile = new TsSourceFile(tsFile);
|
||||
return tsSourceFile;
|
||||
}
|
||||
|
||||
private EvaluationResult evalTs(TsSourceFile sourceFile) {
|
||||
return evalTs(sourceFile, false);
|
||||
}
|
||||
|
||||
private EvaluationResult evalTs(TsSourceFile sourceFile, boolean expectErrors) {
|
||||
try {
|
||||
System.out.println("running tsc: " + sourceFile);
|
||||
|
||||
transpiler.setTsOutputDir(sourceFile.getTsFile().getParentFile());
|
||||
EvaluationResult result = eval(sourceFile);
|
||||
FileUtils.deleteQuietly(sourceFile.getJsFile());
|
||||
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Cannot compile Typescript file: " + sourceFile);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private class TsSourceFile extends SourceFile {
|
||||
public TsSourceFile(File tsFile) {
|
||||
super(null);
|
||||
this.setTsFile(tsFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getTsFile().toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
179
test/org/jsweet/test/transpiler/TypingTests.java
Normal file
179
test/org/jsweet/test/transpiler/TypingTests.java
Normal file
@ -0,0 +1,179 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.jsweet.test.transpiler.source.typing.ArraysOfLambdas;
|
||||
import org.jsweet.test.transpiler.source.typing.ClassTypeAsFunction;
|
||||
import org.jsweet.test.transpiler.source.typing.ClassTypeAsTypeOf;
|
||||
import org.jsweet.test.transpiler.source.typing.InvalidIndexedAccesses;
|
||||
import org.jsweet.test.transpiler.source.typing.Lambdas;
|
||||
import org.jsweet.test.transpiler.source.typing.Numbers;
|
||||
import org.jsweet.test.transpiler.source.typing.StringTypesUsage;
|
||||
import org.jsweet.test.transpiler.source.typing.Tuples;
|
||||
import org.jsweet.test.transpiler.source.typing.Unions;
|
||||
import org.jsweet.test.transpiler.source.typing.VoidType;
|
||||
import org.jsweet.test.transpiler.source.typing.WrongUnions;
|
||||
import org.jsweet.transpiler.JSweetProblem;
|
||||
import org.jsweet.transpiler.util.EvaluationResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TypingTests extends AbstractTest {
|
||||
|
||||
@Test
|
||||
public void testNumbers() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
transpiler.transpile(logHandler, getSourceFile(Numbers.class));
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLambdas() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
EvaluationResult r = transpiler.eval(logHandler, getSourceFile(Lambdas.class));
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
Assert.assertEquals("a", r.get("result"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVoidType() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
transpiler.transpile(logHandler, getSourceFile(VoidType.class));
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassTypeAsTypeOf() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
transpiler.transpile(logHandler, getSourceFile(ClassTypeAsTypeOf.class));
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassTypeAsFunction() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
transpiler.transpile(logHandler, getSourceFile(ClassTypeAsFunction.class));
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArraysOfLambdas() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
transpiler.transpile(logHandler, getSourceFile(ArraysOfLambdas.class));
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringTypesUsage() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
transpiler.transpile(logHandler, getSourceFile(StringTypesUsage.class));
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTuples() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
EvaluationResult r = transpiler.eval(logHandler, getSourceFile(Tuples.class));
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
Assert.assertEquals("test", r.get("0_init"));
|
||||
Assert.assertEquals(10, r.<Number> get("1_init").intValue());
|
||||
Assert.assertEquals("ok", r.get("0_end"));
|
||||
Assert.assertEquals(9, r.<Number> get("1_end").intValue());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnions() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
EvaluationResult r = transpiler.eval(logHandler, getSourceFile(Unions.class));
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
Assert.assertEquals("test", r.get("union"));
|
||||
Assert.assertEquals("test", r.get("s"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongUnions() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
transpiler.transpile(logHandler, getSourceFile(WrongUnions.class));
|
||||
Assert.assertEquals("Wrong number of errors", 6, logHandler.reportedProblems.size());
|
||||
logHandler.assertReportedProblems(JSweetProblem.UNION_TYPE_MISMATCH, JSweetProblem.UNION_TYPE_MISMATCH, JSweetProblem.UNION_TYPE_MISMATCH,
|
||||
JSweetProblem.UNION_TYPE_MISMATCH, JSweetProblem.UNION_TYPE_MISMATCH, JSweetProblem.UNION_TYPE_MISMATCH);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidIndexedAccesses() {
|
||||
TestTranspilationHandler logHandler = new TestTranspilationHandler();
|
||||
try {
|
||||
transpiler.transpile(logHandler, getSourceFile(InvalidIndexedAccesses.class));
|
||||
Assert.assertEquals("There should be one error", 1, logHandler.reportedProblems.size());
|
||||
Assert.assertEquals("Wrong type of expected error", JSweetProblem.INDEXED_SET_TYPE_MISMATCH, logHandler.reportedProblems.get(0));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Exception occured while running test");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
36
test/org/jsweet/test/transpiler/UtilTests.java
Normal file
36
test/org/jsweet/test/transpiler/UtilTests.java
Normal file
@ -0,0 +1,36 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.jsweet.transpiler.util.Util;
|
||||
import org.junit.Test;
|
||||
|
||||
public class UtilTests {
|
||||
|
||||
@Test
|
||||
public void testConvertToRelativePath() {
|
||||
assertEquals("../c", Util.getRelativePath("/a/b", "/a/c"));
|
||||
assertEquals("..", Util.getRelativePath("/a/b", "/a"));
|
||||
assertEquals("../e", Util.getRelativePath("/a/b/c", "/a/b/e"));
|
||||
assertEquals("d", Util.getRelativePath("/a/b/c", "/a/b/c/d"));
|
||||
assertEquals("d/e", Util.getRelativePath("/a/b/c", "/a/b/c/d/e"));
|
||||
assertEquals("../../../d/e/f", Util.getRelativePath("/a/b/c", "/d/e/f"));
|
||||
assertEquals("../..", Util.getRelativePath("/a/b/c", "/a"));
|
||||
assertEquals("..", Util.getRelativePath("/a/b/c", "/a/b"));
|
||||
}
|
||||
|
||||
}
|
||||
98
test/org/jsweet/test/transpiler/VarargsTests.java
Normal file
98
test/org/jsweet/test/transpiler/VarargsTests.java
Normal file
@ -0,0 +1,98 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.jsweet.test.transpiler.source.varargs.VarargsCalledWithArray;
|
||||
import org.jsweet.test.transpiler.source.varargs.VarargsOnAnonymous;
|
||||
import org.jsweet.test.transpiler.source.varargs.VarargsOnApi;
|
||||
import org.jsweet.test.transpiler.source.varargs.VarargsOnField;
|
||||
import org.jsweet.test.transpiler.source.varargs.VarargsOnGetter;
|
||||
import org.jsweet.test.transpiler.source.varargs.VarargsOnNew;
|
||||
import org.jsweet.test.transpiler.source.varargs.VarargsOnStaticMethod;
|
||||
import org.jsweet.test.transpiler.source.varargs.VarargsTransmission;
|
||||
import org.jsweet.transpiler.util.EvaluationResult;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
public class VarargsTests extends AbstractTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void testVarargsOnAnonymous() {
|
||||
EvaluationResult res = eval(getSourceFile(VarargsOnAnonymous.class));
|
||||
assertEquals("3", res.get("argsLength").toString());
|
||||
assertEquals("called", res.get("firstArg"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarargsOnNew() {
|
||||
eval((logHandler, res) -> {
|
||||
assertEquals("1", res.get("index").toString());
|
||||
assertEquals("3", res.get("argsLength").toString());
|
||||
assertEquals("called", res.get("firstArg"));
|
||||
} , getSourceFile(VarargsOnNew.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarargsOnField() {
|
||||
eval((logHandler, res) -> {
|
||||
assertEquals("2", res.get("argsLength").toString());
|
||||
assertEquals("field", res.get("firstArg"));
|
||||
} , getSourceFile(VarargsOnField.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarargsOnGetter() {
|
||||
eval((logHandler, res) -> {
|
||||
assertEquals(2, res.<Number> get("index"));
|
||||
assertEquals(2, res.<Number> get("argsLength"));
|
||||
assertEquals("on", res.get("firstArg"));
|
||||
} , getSourceFile(VarargsOnGetter.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarargsCalledWithArray() {
|
||||
eval((logHandler, res) -> {
|
||||
assertEquals("3", res.get("argsLength").toString());
|
||||
assertEquals("array", res.get("firstArg"));
|
||||
} , getSourceFile(VarargsCalledWithArray.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarargsOnApi() {
|
||||
eval((logHandler, res) -> {
|
||||
assertEquals(1, res.<Number> get("out"));
|
||||
assertEquals(2, res.<Number> get("d2"));
|
||||
} , getSourceFile(VarargsOnApi.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarargsOnStatic() {
|
||||
eval((logHandler, res) -> {
|
||||
assertEquals("3", res.get("argsLength").toString());
|
||||
assertEquals("static", res.get("firstArg"));
|
||||
} , getSourceFile(VarargsOnStaticMethod.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarargsTransmission() {
|
||||
eval((logHandler, res) -> {
|
||||
assertEquals("1", res.get("shouldBe1").toString());
|
||||
assertEquals("2", res.get("argsLength").toString());
|
||||
assertEquals("transmitted", res.get("firstArg"));
|
||||
} , getSourceFile(VarargsTransmission.class));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.ambient;
|
||||
|
||||
import jsweet.lang.Ambient;
|
||||
|
||||
public class LibAccess {
|
||||
public static void main(String[] args) {
|
||||
Base m = new org.jsweet.test.transpiler.source.ambient.Base();
|
||||
m.m1();
|
||||
|
||||
//MixinInterface.class.cast(m).extension();
|
||||
|
||||
((org.jsweet.test.transpiler.source.ambient.Extension) m).m2();
|
||||
|
||||
//MixinInterface.class.cast(get()).extension();
|
||||
|
||||
((Extension) get()).m2();
|
||||
|
||||
}
|
||||
|
||||
public static Base get() {
|
||||
return new Base();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO : force extends jsweet obj? + tests => only native and ctor => ctor with
|
||||
// args
|
||||
@Ambient
|
||||
//@Interface
|
||||
class Base extends jsweet.lang.Object {
|
||||
public Base() {
|
||||
}
|
||||
|
||||
public native void m1();
|
||||
|
||||
}
|
||||
|
||||
// TODO : force interface on both sides
|
||||
// @Extension(target = MixedIn.class)
|
||||
@Ambient
|
||||
//@Interface
|
||||
class Extension extends Base {
|
||||
native public void m2();
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.ambient;
|
||||
|
||||
import org.jsweet.test.transpiler.source.ambient.lib.Base;
|
||||
import org.jsweet.test.transpiler.source.ambient.lib.Extension;
|
||||
import org.jsweet.test.transpiler.source.ambient.lib.sub.C;
|
||||
|
||||
public class LibAccessSubModule {
|
||||
public static void main(String[] args) {
|
||||
Base m = new org.jsweet.test.transpiler.source.ambient.lib.Base();
|
||||
m.m1();
|
||||
|
||||
((org.jsweet.test.transpiler.source.ambient.lib.Extension) m).m2();
|
||||
|
||||
((Extension) get()).m2();
|
||||
}
|
||||
|
||||
public void m(C c) {
|
||||
c.m();
|
||||
}
|
||||
|
||||
public static Base get() {
|
||||
return new Base();
|
||||
}
|
||||
}
|
||||
|
||||
10
test/org/jsweet/test/transpiler/source/ambient/lib.js
Normal file
10
test/org/jsweet/test/transpiler/source/ambient/lib.js
Normal file
@ -0,0 +1,10 @@
|
||||
var Base = function() {
|
||||
}
|
||||
|
||||
Base.prototype.m1 = function() {
|
||||
console.info("EXPORT baseExecuted=true;")
|
||||
}
|
||||
|
||||
Base.prototype.m2 = function() {
|
||||
console.info("EXPORT extensionExecuted=true;")
|
||||
}
|
||||
27
test/org/jsweet/test/transpiler/source/ambient/lib/Base.java
Normal file
27
test/org/jsweet/test/transpiler/source/ambient/lib/Base.java
Normal file
@ -0,0 +1,27 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.ambient.lib;
|
||||
|
||||
import jsweet.lang.Ambient;
|
||||
|
||||
@Ambient
|
||||
//@Interface
|
||||
public class Base extends jsweet.lang.Object {
|
||||
public Base() {
|
||||
}
|
||||
|
||||
public native void m1();
|
||||
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.ambient.lib;
|
||||
|
||||
import jsweet.lang.Ambient;
|
||||
|
||||
@Ambient
|
||||
// @Interface
|
||||
public class Extension extends org.jsweet.test.transpiler.source.ambient.lib.Base {
|
||||
native public void m2();
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.ambient.lib.sub;
|
||||
|
||||
import jsweet.lang.Ambient;
|
||||
|
||||
@Ambient
|
||||
public class C {
|
||||
|
||||
public native void m();
|
||||
|
||||
}
|
||||
20
test/org/jsweet/test/transpiler/source/ambient/libsub.js
Normal file
20
test/org/jsweet/test/transpiler/source/ambient/libsub.js
Normal file
@ -0,0 +1,20 @@
|
||||
var lib = {
|
||||
Base : function() {
|
||||
},
|
||||
sub : {
|
||||
C : function() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lib.Base.prototype.m1 = function() {
|
||||
console.info("EXPORT baseExecuted=true;")
|
||||
}
|
||||
|
||||
lib.Base.prototype.m2 = function() {
|
||||
console.info("EXPORT extensionExecuted=true;")
|
||||
}
|
||||
|
||||
lib.sub.C.prototype.m = function() {
|
||||
console.info("EXPORT sub=true;")
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@jsweet.lang.Root
|
||||
package org.jsweet.test.transpiler.source.ambient;
|
||||
53
test/org/jsweet/test/transpiler/source/api/CastMethods.java
Normal file
53
test/org/jsweet/test/transpiler/source/api/CastMethods.java
Normal file
@ -0,0 +1,53 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.api;
|
||||
|
||||
import jsweet.lang.Boolean;
|
||||
import jsweet.lang.Number;
|
||||
import jsweet.util.Globals;
|
||||
import static jsweet.util.Globals.*;
|
||||
|
||||
public class CastMethods {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
void m() {
|
||||
Boolean b1 = Globals.bool(true);
|
||||
b1 = bool(true);
|
||||
boolean b2 = Globals.bool(b1);
|
||||
b2 = bool(b1);
|
||||
if (b2) {
|
||||
b1 = bool(b2);
|
||||
int[] array = {};
|
||||
Globals.array(array).push(1, 2, 3);
|
||||
array(array).push(1, 2, 3);
|
||||
int i = array(array(array))[1];
|
||||
m1(b1);
|
||||
m1(bool(b2));
|
||||
m2(bool(b1));
|
||||
m2(b2);
|
||||
}
|
||||
Number n = Globals.number(1);
|
||||
n.toLocaleString();
|
||||
n.toFixed();
|
||||
int i = Globals.integer(n);
|
||||
double d = Globals.number(n);
|
||||
object("");
|
||||
}
|
||||
|
||||
void m1(Boolean b) {}
|
||||
|
||||
void m2(boolean b) {}
|
||||
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.api;
|
||||
|
||||
import jsweet.lang.Array;
|
||||
import jsweet.lang.IArguments;
|
||||
import jsweet.util.Globals;
|
||||
|
||||
public class ForeachIteration {
|
||||
|
||||
void m() {
|
||||
Array<String> array = new Array<>();
|
||||
array.push("a", "b", "c");
|
||||
String seq = "";
|
||||
for (String s : array) {
|
||||
seq+=s;
|
||||
}
|
||||
Globals.$export("out", seq);
|
||||
}
|
||||
|
||||
void m2(IArguments args) {
|
||||
for (Object o : args) {
|
||||
o.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new ForeachIteration().m();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.api;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
|
||||
public class JdkInvocations {
|
||||
|
||||
String s = "test";
|
||||
|
||||
void m() {
|
||||
try {
|
||||
System.out.println("test");
|
||||
System.err.println("test");
|
||||
} catch (Exception e) {
|
||||
}
|
||||
toString();
|
||||
this.toString();
|
||||
$export("s1", s.toString());
|
||||
$export("s2", m1().toString());
|
||||
$export("s3", s.charAt(1));
|
||||
$export("s4", s.concat("c"));
|
||||
$export("i1", s.indexOf("s"));
|
||||
$export("i2", s.lastIndexOf("gg"));
|
||||
s.lastIndexOf("", 10);
|
||||
Other4 o2 = new Other4();
|
||||
o2.toString();
|
||||
}
|
||||
|
||||
String m1() {
|
||||
return "m1";
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new JdkInvocations().m();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Other4 extends Object {
|
||||
void m() {
|
||||
toString();
|
||||
this.toString();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.api;
|
||||
|
||||
import jsweet.lang.Function;
|
||||
import jsweet.lang.String;
|
||||
import jsweet.lang.Number;
|
||||
import jsweet.lang.Boolean;
|
||||
import jsweet.lang.JSON;
|
||||
|
||||
public class PrimitiveInstantiation {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void main(String[] args) {
|
||||
String s1 = new String(1.0);
|
||||
String s2 = new String("1");
|
||||
String s3 = new String();
|
||||
|
||||
Number n1 = new Number(2.0);
|
||||
Number n2 = new Number("3.0");
|
||||
Number n3 = new Number();
|
||||
|
||||
Boolean b1 = new Boolean();
|
||||
Boolean b2 = new Boolean("3.0");
|
||||
|
||||
Function f = new Function("alert('success')");
|
||||
|
||||
Object o = JSON.parse("test");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.api;
|
||||
|
||||
public class QualifiedInstantiation {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void main(String[] args) {
|
||||
jsweet.lang.Array<String> array = new jsweet.lang.Array<String>();
|
||||
jsweet.lang.Array<jsweet.lang.String> array2 = new jsweet.lang.Array<jsweet.lang.String>();
|
||||
jsweet.lang.String string = new jsweet.lang.String("1");
|
||||
jsweet.lang.Number number = new jsweet.lang.Number("3.0");
|
||||
jsweet.lang.Date date = new jsweet.lang.Date("2015-05-01");
|
||||
jsweet.lang.Error error = new jsweet.lang.Error("bloody error");
|
||||
jsweet.lang.RegExp regex = new jsweet.lang.RegExp("\\d", "g");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,80 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.api;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.util.Iterator;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import jsweet.lang.Array;
|
||||
|
||||
|
||||
public class WrongJdkInvocations {
|
||||
|
||||
String s;
|
||||
// illegal use of FileInputString
|
||||
FileInputStream fis;
|
||||
Consumer<String> c;
|
||||
|
||||
void m() {
|
||||
toString();
|
||||
this.toString();
|
||||
s.toString();
|
||||
m1().toString();
|
||||
s.charAt(1);
|
||||
s.concat("");
|
||||
s.indexOf("s");
|
||||
s.lastIndexOf("gg");
|
||||
s.lastIndexOf("", 10);
|
||||
// illegal use of codePointAt method
|
||||
s.codePointAt(1);
|
||||
Other1 o1 = new Other1();
|
||||
o1.toString();
|
||||
Other2 o2 = new Other2();
|
||||
o2.toString();
|
||||
// illegal use of Iterator
|
||||
Iterator<String> i = new Array<String>().iterator();
|
||||
// illegal use of Iterator method
|
||||
i.next();
|
||||
c.accept("a");
|
||||
// illegal use
|
||||
c.andThen(c);
|
||||
}
|
||||
|
||||
String m1() {
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Other1 {
|
||||
@Override
|
||||
public String toString() {
|
||||
// cannot call Object superclass
|
||||
return super.toString();
|
||||
}
|
||||
|
||||
void m() {
|
||||
toString();
|
||||
this.toString();
|
||||
}
|
||||
}
|
||||
|
||||
class Other2 extends Object {
|
||||
void m() {
|
||||
toString();
|
||||
this.toString();
|
||||
}
|
||||
}
|
||||
84
test/org/jsweet/test/transpiler/source/blocksgame/Ball.java
Normal file
84
test/org/jsweet/test/transpiler/source/blocksgame/Ball.java
Normal file
@ -0,0 +1,84 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.blocksgame;
|
||||
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.MobileElement;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.Point;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.Vector;
|
||||
|
||||
import jsweet.dom.CanvasRenderingContext2D;
|
||||
import jsweet.lang.Math;
|
||||
|
||||
public class Ball extends MobileElement {
|
||||
|
||||
public static double MIN_SPEED = 1;
|
||||
public static double MAX_SPEED = 20;
|
||||
|
||||
public Vector speedVector = new Vector(0, 0);
|
||||
public GameArea area;
|
||||
public double radius;
|
||||
|
||||
public Ball(GameArea area, double radius, Point position, Vector normalizedDirection, double speed) {
|
||||
super(position, 1, radius * 2, radius * 2);
|
||||
this.setSpeedVector(normalizedDirection, speed);
|
||||
this.area = area;
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
private void draw(CanvasRenderingContext2D ctx) {
|
||||
ctx.save();
|
||||
ctx.beginPath();
|
||||
ctx.fillStyle = "white";
|
||||
ctx.arc(this.position.x, this.position.y, this.radius, 0, Math.PI * 2, false);
|
||||
ctx.closePath();
|
||||
ctx.fill();
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.arc(this.position.x, this.position.y, this.radius, 0, Math.PI * 2, false);
|
||||
ctx.clip();
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.strokeStyle = "black";
|
||||
ctx.lineWidth = this.radius * 0.1;
|
||||
ctx.shadowBlur = this.radius * 0.4;
|
||||
ctx.shadowColor = "black";
|
||||
ctx.shadowOffsetX = this.position.x + this.radius * 0.8;
|
||||
ctx.shadowOffsetY = this.position.y + this.radius * 0.8;
|
||||
ctx.arc(-this.radius, -this.radius, this.radius + this.radius * 0.01, 0, Math.PI * 2, false);
|
||||
ctx.stroke();
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
public void render(CanvasRenderingContext2D ctx) {
|
||||
this.draw(ctx);
|
||||
}
|
||||
|
||||
public void setSpeedVector(Vector normalizedDirection, double speed) {
|
||||
this.speedVector.x = normalizedDirection.x * speed;
|
||||
this.speedVector.y = normalizedDirection.y * speed;
|
||||
}
|
||||
|
||||
public void setSpeed(double speed) {
|
||||
this.speedVector.normalize().times(speed);
|
||||
}
|
||||
|
||||
public double getSpeed() {
|
||||
return this.speedVector.length();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ball(" + this.radius + "," + this.getPosition() + ")";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,174 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.blocksgame;
|
||||
|
||||
import static jsweet.dom.Globals.document;
|
||||
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.AnimatedElement;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.Collisions;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.MobileElement;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.Point;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.Vector;
|
||||
|
||||
import jsweet.dom.CanvasRenderingContext2D;
|
||||
import jsweet.dom.HTMLImageElement;
|
||||
|
||||
public class BlockElement extends AnimatedElement {
|
||||
|
||||
public static int CELL_SIZE = 44;
|
||||
public static HTMLImageElement spriteBreakableBlock = (HTMLImageElement)document.getElementById("sprite-breakable-block");
|
||||
public static HTMLImageElement spriteUnbreakableBlock = (HTMLImageElement)document.getElementById("sprite-unbreakable-block");
|
||||
|
||||
public double size;
|
||||
public GameArea area;
|
||||
public int hitstoBreak;
|
||||
private Vector gravity = null;
|
||||
public boolean playerDisabled = false;
|
||||
public double x;
|
||||
public double y;
|
||||
public int cellX;
|
||||
public int cellY;
|
||||
|
||||
public BlockElement(int hitsForBreaking) {
|
||||
this.hitstoBreak = hitsForBreaking;
|
||||
}
|
||||
|
||||
protected void drawBreakable(CanvasRenderingContext2D ctx) {
|
||||
ctx.drawImage(spriteBreakableBlock, 0, 0, 100, 100, x, y, CELL_SIZE, CELL_SIZE);
|
||||
}
|
||||
|
||||
protected void drawUnbreakable(CanvasRenderingContext2D ctx) {
|
||||
ctx.drawImage(spriteUnbreakableBlock, 0, 0, 100, 100, x, y, CELL_SIZE, CELL_SIZE);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "BLOCK(" + this.hitstoBreak + ")";
|
||||
}
|
||||
|
||||
protected void clear(CanvasRenderingContext2D ctx) {
|
||||
ctx.clearRect(this.x, this.y, this.size, this.size);
|
||||
}
|
||||
|
||||
public void render(CanvasRenderingContext2D ctx) {
|
||||
if (this.isVisible()) {
|
||||
if (this.hitstoBreak == -1) {
|
||||
this.drawUnbreakable(ctx);
|
||||
} else {
|
||||
this.drawBreakable(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderAnimation(CanvasRenderingContext2D animationCtx, CanvasRenderingContext2D areaCtx) {
|
||||
if (this.hitstoBreak == -1) {
|
||||
this.drawUnbreakable(animationCtx);
|
||||
animationCtx.beginPath();
|
||||
animationCtx.fillStyle = "rgba(255,255,255,0.4)";
|
||||
animationCtx.rect(this.x, this.y, this.size, this.size);
|
||||
animationCtx.fill();
|
||||
} else {
|
||||
if (this.getAnimationStep() == 1) {
|
||||
render(areaCtx);
|
||||
}
|
||||
double factor = this.getRemainingAnimationSteps() / this.getAnimationStepCount();
|
||||
animationCtx.save();
|
||||
animationCtx.translate(this.x + this.size / 2, this.y + this.size / 2);
|
||||
animationCtx.scale(factor, factor);
|
||||
animationCtx.translate(-this.x - this.size / 2, -this.y - this.size / 2);
|
||||
this.drawBreakable(animationCtx);
|
||||
animationCtx.restore();
|
||||
}
|
||||
this.nextAnimationStep();
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return this.hitstoBreak != 0;
|
||||
}
|
||||
|
||||
public boolean contains(Point point, double radius) {
|
||||
if (point.x + radius > this.x + this.size) {
|
||||
return false;
|
||||
}
|
||||
if (point.x - radius < this.x) {
|
||||
return false;
|
||||
}
|
||||
if (point.y + radius > this.y + this.size) {
|
||||
return false;
|
||||
}
|
||||
if (point.y - radius < this.y) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean overlaps(Point point, double radius) {
|
||||
if (point.x + radius > this.x + this.size) {
|
||||
return false;
|
||||
}
|
||||
if (point.x - radius < this.x) {
|
||||
return false;
|
||||
}
|
||||
if (point.y + radius > this.y + this.size) {
|
||||
return false;
|
||||
}
|
||||
if (point.y - radius < this.y) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hit(Ball ball, Vector hitObjectDirection, Point hitPoint) {
|
||||
if (this.hitstoBreak > 0) {
|
||||
this.hitstoBreak--;
|
||||
}
|
||||
if (hitPoint == null) {
|
||||
ball.speedVector.applyBounce(hitObjectDirection);
|
||||
} else {
|
||||
MobileElement refMobile = new MobileElement(hitPoint, 10000000, 0, 0);
|
||||
Collisions.sphericCollision(refMobile, ball);
|
||||
}
|
||||
if (this.hitstoBreak == -1) {
|
||||
this.initAnimation(2);
|
||||
} else {
|
||||
this.area.blockCount--;
|
||||
this.area.remainingBlocks.innerHTML="Blocks: "+this.area.blockCount;
|
||||
if(this.area.blockCount==0) {
|
||||
this.area.end(0);
|
||||
}
|
||||
this.area.clearAll = true;
|
||||
this.initAnimation(5);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onBallOver(Ball ball) {
|
||||
if (this.gravity != null) {
|
||||
ball.speedVector.add(this.gravity);
|
||||
}
|
||||
}
|
||||
|
||||
public Point center() {
|
||||
return new Point(this.x + this.size / 2, this.y + this.size / 2);
|
||||
}
|
||||
|
||||
public void setGravity(Vector gravity) {
|
||||
this.gravity = gravity;
|
||||
}
|
||||
|
||||
public void onAddedToArea() {
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,65 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.blocksgame;
|
||||
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.Direction;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.Point;
|
||||
|
||||
public class Factory {
|
||||
|
||||
private GameManager gameManager;
|
||||
|
||||
public Factory(GameManager gameManager) {
|
||||
this.gameManager = gameManager;
|
||||
}
|
||||
|
||||
public GameArea createDefaultEmptyLevel(int width, int height) {
|
||||
GameArea area;
|
||||
Player player;
|
||||
Ball ball;
|
||||
area = new GameArea(this, width, height);
|
||||
player = new Player(area, "blue", Direction.NORTH, new Point(GameManager.SIZE * width / 2, (GameManager.SIZE * height * 5) / 6 + 20),
|
||||
GameManager.TOUCH_SIZE/1.5);
|
||||
area.setPlayer(player);
|
||||
ball = new Ball(area, GameManager.SIZE / 4, new Point(GameManager.SIZE * width / 2, (GameManager.SIZE * height * 3) / 4), Direction.SOUTH.normalized, 0);
|
||||
area.setBall(ball);
|
||||
return area;
|
||||
}
|
||||
|
||||
public GameArea createLevel() {
|
||||
GameArea area = this.createDefaultEmptyLevel(12, 16);
|
||||
area.createBorders(Direction.EAST);
|
||||
area.createBorders(Direction.WEST);
|
||||
area.createBorders(Direction.NORTH);
|
||||
area.createBorders(Direction.SOUTH);
|
||||
area.removeBlock(3, area.rows - 1);
|
||||
area.removeBlock(4, area.rows - 1);
|
||||
area.removeBlock(5, area.rows - 1);
|
||||
area.removeBlock(6, area.rows - 1);
|
||||
area.removeBlock(7, area.rows - 1);
|
||||
area.removeBlock(8, area.rows - 1);
|
||||
for (int i = 1; i < area.cols - 1; i++) {
|
||||
for (int j = 1; j < area.rows / 2; j++) {
|
||||
area.addBlock(new BlockElement(1), i, j);
|
||||
}
|
||||
}
|
||||
return area;
|
||||
}
|
||||
|
||||
public GameManager getGameManager() {
|
||||
return gameManager;
|
||||
}
|
||||
|
||||
}
|
||||
523
test/org/jsweet/test/transpiler/source/blocksgame/GameArea.java
Normal file
523
test/org/jsweet/test/transpiler/source/blocksgame/GameArea.java
Normal file
@ -0,0 +1,523 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.blocksgame;
|
||||
|
||||
import static jsweet.dom.Globals.console;
|
||||
import static jsweet.dom.Globals.document;
|
||||
import static jsweet.util.Globals.array;
|
||||
import static jsweet.util.StringTypes._2d;
|
||||
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.Direction;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.Point;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.Rectangle;
|
||||
|
||||
import jsweet.dom.CanvasRenderingContext2D;
|
||||
import jsweet.dom.Event;
|
||||
import jsweet.dom.HTMLElement;
|
||||
import jsweet.dom.MouseEvent;
|
||||
import jsweet.dom.Touch;
|
||||
import jsweet.dom.TouchEvent;
|
||||
import jsweet.lang.Date;
|
||||
import jsweet.lang.Math;
|
||||
|
||||
public class GameArea {
|
||||
|
||||
public HTMLElement sprites;
|
||||
|
||||
public double naturalSpeed = 8;
|
||||
|
||||
public double maxSpeed = 20;
|
||||
|
||||
public BlockElement[][] positions;
|
||||
|
||||
public Ball ball;
|
||||
|
||||
public Player player;
|
||||
|
||||
public Date currentDate = new Date();
|
||||
|
||||
public boolean finished;
|
||||
|
||||
public int winner = -1;
|
||||
|
||||
public int cols;
|
||||
public int rows;
|
||||
public double positionSize;
|
||||
|
||||
private int topMargin = 0;
|
||||
private int leftMargin = 0;
|
||||
private int rightMargin = 0;
|
||||
private int bottomMargin = 0;
|
||||
|
||||
private Date initialDate = null;
|
||||
private double currentTime = 0;
|
||||
public int blockCount = 0;
|
||||
|
||||
HTMLElement elapsedTime;
|
||||
public HTMLElement remainingBlocks;
|
||||
|
||||
public boolean clearAll = true;
|
||||
|
||||
public Factory factory;
|
||||
|
||||
public CanvasRenderingContext2D areaLayerCtx;
|
||||
public CanvasRenderingContext2D topLayerCtx;
|
||||
public CanvasRenderingContext2D backgroundLayerCtx;
|
||||
public CanvasRenderingContext2D ballsLayerCtx;
|
||||
|
||||
GameArea(Factory factory, int cols, int rows) {
|
||||
console.info("creating game area...");
|
||||
this.factory = factory;
|
||||
this.areaLayerCtx = factory.getGameManager().areaLayer.getContext(_2d);
|
||||
this.topLayerCtx = factory.getGameManager().topLayer.getContext(_2d);
|
||||
this.backgroundLayerCtx = factory.getGameManager().backgroundLayer.getContext(_2d);
|
||||
this.ballsLayerCtx = factory.getGameManager().ballsLayer.getContext(_2d);
|
||||
this.cols = cols;
|
||||
this.rows = rows;
|
||||
this.positionSize = GameManager.SIZE;
|
||||
this.positions = new BlockElement[cols][rows];
|
||||
for (int i = 0; i < cols; i++) {
|
||||
BlockElement[] line = {};
|
||||
array(this.positions).push(line);
|
||||
}
|
||||
this.remainingBlocks = document.getElementById("blocks");
|
||||
for (int i = 0; i < this.cols; i++) {
|
||||
for (int j = 0; j < this.rows; j++) {
|
||||
this.addBlock(new BlockElement(0), i, j);
|
||||
}
|
||||
}
|
||||
this.ball = null;
|
||||
this.elapsedTime = document.getElementById("time");
|
||||
this.sprites = document.getElementById("sprites");
|
||||
this.currentTime = 0;
|
||||
this.elapsedTime.innerHTML = "0s";
|
||||
}
|
||||
|
||||
public void changeSize(int cols, int rows) {
|
||||
BlockElement[][] newPositions = new BlockElement[cols][rows];
|
||||
for (int i = 0; i < cols; i++) {
|
||||
BlockElement[] line = {};
|
||||
array(newPositions).push(line);
|
||||
}
|
||||
for (int i = 0; i < cols; i++) {
|
||||
for (int j = 0; j < rows; j++) {
|
||||
if (i < this.cols && j < this.rows) {
|
||||
newPositions[i][j] = this.positions[i][j];
|
||||
} else {
|
||||
BlockElement block = new BlockElement(0);
|
||||
newPositions[i][j] = block;
|
||||
block.cellX = i;
|
||||
block.cellY = j;
|
||||
block.size = this.positionSize;
|
||||
block.area = this;
|
||||
block.x = i * this.positionSize;
|
||||
block.y = j * this.positionSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.cols = cols;
|
||||
this.rows = rows;
|
||||
this.positions = newPositions;
|
||||
}
|
||||
|
||||
public void initDate() {
|
||||
if (this.initialDate == null) {
|
||||
this.initialDate = new Date();
|
||||
}
|
||||
}
|
||||
|
||||
public void regulateSpeedWhenBounced(Ball ball) {
|
||||
double speed = ball.getSpeed();
|
||||
if (ball.getSpeed() > this.naturalSpeed) {
|
||||
ball.setSpeed(this.naturalSpeed + (speed - this.naturalSpeed) / 1.5);
|
||||
}
|
||||
}
|
||||
|
||||
public void regulateSpeed(Ball ball) {
|
||||
if (ball.getSpeed() > this.maxSpeed) {
|
||||
ball.setSpeed(this.maxSpeed);
|
||||
}
|
||||
ball.speedVector.y += 0.1;
|
||||
}
|
||||
|
||||
public void createDefaultBorders(boolean sideBorders) {
|
||||
for (int i = 0; i < this.rows; i++) {
|
||||
this.addBlock(new BlockElement(-1), 0, i);
|
||||
this.addBlock(new BlockElement(-1), this.cols - 1, i);
|
||||
}
|
||||
if (sideBorders) {
|
||||
for (int i = 1; i < this.cols - 1; i++) {
|
||||
this.addBlock(new BlockElement(-1), i, 0);
|
||||
this.addBlock(new BlockElement(-1), i, this.rows - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void createBorders(Direction side) {
|
||||
if (side == Direction.NORTH) {
|
||||
for (int i = 1; i < this.cols - 1; i++) {
|
||||
this.addBlock(new BlockElement(-1), i, 0);
|
||||
}
|
||||
} else if (side == Direction.SOUTH) {
|
||||
for (int i = 1; i < this.cols - 1; i++) {
|
||||
this.addBlock(new BlockElement(-1), i, this.rows - 1);
|
||||
}
|
||||
} else if (side == Direction.EAST) {
|
||||
for (int i = 0; i < this.rows; i++) {
|
||||
this.addBlock(new BlockElement(-1), 0, i);
|
||||
}
|
||||
} else if (side == Direction.WEST) {
|
||||
for (int i = 0; i < this.rows; i++) {
|
||||
this.addBlock(new BlockElement(-1), this.cols - 1, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addBlock(BlockElement block, int x, int y) {
|
||||
this.positions[x][y] = block;
|
||||
block.cellX = x;
|
||||
block.cellY = y;
|
||||
block.size = this.positionSize;
|
||||
block.area = this;
|
||||
block.x = x * this.positionSize;
|
||||
block.y = y * this.positionSize;
|
||||
block.onAddedToArea();
|
||||
this.clearAll = true;
|
||||
if (block.hitstoBreak > 0) {
|
||||
blockCount++;
|
||||
this.remainingBlocks.innerHTML="Blocks: "+blockCount;
|
||||
}
|
||||
}
|
||||
|
||||
public void disablePlayer(int x, int y) {
|
||||
BlockElement element = this.positions[x][y];
|
||||
if (element == null) {
|
||||
element = new BlockElement(0);
|
||||
this.addBlock(element, x, y);
|
||||
}
|
||||
element.playerDisabled = true;
|
||||
}
|
||||
|
||||
public boolean isPlayerDisabled(int x, int y) {
|
||||
BlockElement element = this.positions[x][y];
|
||||
if (element == null) {
|
||||
return false;
|
||||
} else {
|
||||
return element.playerDisabled;
|
||||
}
|
||||
}
|
||||
|
||||
public void removeBlock(int x, int y) {
|
||||
BlockElement b = positions[x][y];
|
||||
if (b != null && b.hitstoBreak > 0) {
|
||||
blockCount--;
|
||||
this.remainingBlocks.innerHTML="Blocks: "+blockCount;
|
||||
}
|
||||
this.addBlock(new BlockElement(0), x, y);
|
||||
this.clearAll = true;
|
||||
}
|
||||
|
||||
public double getWidth() {
|
||||
return this.cols * this.positionSize + this.leftMargin + this.rightMargin;
|
||||
}
|
||||
|
||||
public double getHeight() {
|
||||
return this.rows * this.positionSize + this.topMargin + this.bottomMargin;
|
||||
}
|
||||
|
||||
public double getGridWidth() {
|
||||
return this.cols * this.positionSize;
|
||||
}
|
||||
|
||||
public double getGridHeight() {
|
||||
return this.rows * this.positionSize;
|
||||
}
|
||||
|
||||
public void setBall(Ball ball) {
|
||||
this.ball = ball;
|
||||
ball.area = this;
|
||||
}
|
||||
|
||||
public void setPlayer(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public BlockElement getElementAt(int cellX, int cellY) {
|
||||
if (cellX < 0 || cellX >= this.cols || cellY < 0 || cellY >= this.rows) {
|
||||
return null;
|
||||
}
|
||||
return this.positions[cellX][cellY];
|
||||
}
|
||||
|
||||
public void convertPositionToDiscrete(Point point) {
|
||||
point.x = Math.floor(point.x / this.positionSize);
|
||||
point.y = Math.floor(point.y / this.positionSize);
|
||||
}
|
||||
|
||||
public int convertCoordToDiscrete(double coord) {
|
||||
return (int) Math.floor(coord / this.positionSize);
|
||||
}
|
||||
|
||||
Rectangle boundingRectangle = new Rectangle(0, 0, 0, 0);
|
||||
|
||||
public void invalidateCell(int x, int y, boolean invalidate) {
|
||||
if (this.positions[x] != null && this.positions[x][y] != null) {
|
||||
this.positions[x][y].invalidated = invalidate;
|
||||
}
|
||||
}
|
||||
|
||||
public void renderAll() {
|
||||
areaLayerCtx.clearRect(0, 0, this.getWidth(), this.getHeight());
|
||||
for (int i = 0; i < this.cols; i++) {
|
||||
for (int j = 0; j < this.rows; j++) {
|
||||
this.positions[i][j].render(areaLayerCtx);
|
||||
}
|
||||
}
|
||||
this.renderBall();
|
||||
}
|
||||
|
||||
public void render() {
|
||||
boolean clearingArea = clearAll;
|
||||
this.renderBall();
|
||||
if (clearAll) {
|
||||
areaLayerCtx.clearRect(0, 0, this.getWidth(), this.getHeight());
|
||||
clearAll = false;
|
||||
}
|
||||
for (int i = 0; i < this.cols; i++) {
|
||||
for (int j = 0; j < this.rows; j++) {
|
||||
if (clearingArea) {
|
||||
this.positions[i][j].render(areaLayerCtx);
|
||||
}
|
||||
if (this.positions[i][j].invalidated) {
|
||||
this.positions[i][j].renderAnimation(ballsLayerCtx, areaLayerCtx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.renderPlayer();
|
||||
this.renderMessage();
|
||||
}
|
||||
|
||||
public void renderMessage() {
|
||||
if (this.message == null) {
|
||||
return;
|
||||
}
|
||||
areaLayerCtx.save();
|
||||
areaLayerCtx.font = "14px impact";
|
||||
areaLayerCtx.textAlign = "center";
|
||||
areaLayerCtx.fillStyle = "black";
|
||||
double margin = this.positionSize * 2;
|
||||
areaLayerCtx.fillRect(margin, (this.rows * this.positionSize) / 2 - 20, (this.cols * this.positionSize) - 2 * margin, 40);
|
||||
areaLayerCtx.fillStyle = "white";
|
||||
areaLayerCtx.fillText(this.message, (this.cols * this.positionSize) / 2, (this.rows * this.positionSize) / 2);
|
||||
areaLayerCtx.restore();
|
||||
}
|
||||
|
||||
public void renderBall() {
|
||||
ballsLayerCtx.clearRect(0, 0, this.getWidth(), this.getHeight());
|
||||
if (ball != null) {
|
||||
ball.render(ballsLayerCtx);
|
||||
}
|
||||
}
|
||||
|
||||
public void renderPlayer() {
|
||||
topLayerCtx.clearRect(0, 0, this.getWidth(), this.getHeight());
|
||||
if (player != null) {
|
||||
player.render(topLayerCtx);
|
||||
}
|
||||
}
|
||||
|
||||
public void dump() {
|
||||
console.info("dumping game area: ");
|
||||
console.info(" - player " + player.color + ": " + player.getPosition() + " - " + player.speedVector);
|
||||
console.info(" - ball: " + ball.getPosition() + " - " + ball.speedVector);
|
||||
}
|
||||
|
||||
private double calculateMaxSpeedCoord() {
|
||||
double maxSpeedCoord = 0;
|
||||
maxSpeedCoord = Math.max(maxSpeedCoord, Math.max(Math.abs(player.speedVector.x), Math.abs(player.speedVector.y)));
|
||||
maxSpeedCoord = Math.max(maxSpeedCoord, Math.max(Math.abs(ball.speedVector.x), Math.abs(ball.speedVector.y)));
|
||||
return maxSpeedCoord;
|
||||
}
|
||||
|
||||
public boolean contains(Point point) {
|
||||
return point.x >= 0 && point.x < this.cols * this.positionSize && point.y >= 0 && point.y < this.rows * this.positionSize;
|
||||
}
|
||||
|
||||
private Point _tmpPoint = new Point(0, 0);
|
||||
private Point _oldPosition = new Point(0, 0);
|
||||
private Point ballLimit = new Point(0, 0);
|
||||
private Point _currentAreaPosition = new Point(0, 0);
|
||||
private Point _otherAreaPosition = new Point(0, 0);
|
||||
|
||||
public void calculateNextPositions() {
|
||||
if (initialDate != null) {
|
||||
double newCurrentTime = Math.floor((new Date().getTime() - this.initialDate.getTime()) / 1000);
|
||||
if (newCurrentTime > this.currentTime) {
|
||||
this.currentTime = newCurrentTime;
|
||||
elapsedTime.innerHTML = this.currentTime + "s";
|
||||
}
|
||||
}
|
||||
|
||||
player.calculateSpeedVector();
|
||||
double stepCount = this.calculateMaxSpeedCoord();
|
||||
if (stepCount < 1) {
|
||||
stepCount = 1;
|
||||
}
|
||||
|
||||
if (stepCount != 0) {
|
||||
double stepValue = 1 / stepCount;
|
||||
for (int step = 1; step <= stepCount; step++) {
|
||||
|
||||
player.move(player.speedVector.x * stepValue, player.speedVector.y * stepValue);
|
||||
|
||||
boolean hit = false;
|
||||
_currentAreaPosition.x = ball.position.x;
|
||||
_currentAreaPosition.y = ball.position.y;
|
||||
this.convertPositionToDiscrete(_currentAreaPosition);
|
||||
BlockElement element;
|
||||
Direction direction;
|
||||
this._oldPosition.x = ball.getPosition().x;
|
||||
this._oldPosition.y = ball.getPosition().y;
|
||||
ball.move(ball.speedVector.x * stepValue, ball.speedVector.y * stepValue);
|
||||
|
||||
if (player.checkHit(ball)) {
|
||||
console.info("player hits ball! ");
|
||||
player.applyHit(ball);
|
||||
ball.moveTo(ball.getPosition().x + player.speedVector.x * stepValue, ball.getPosition().y + player.speedVector.y * stepValue);
|
||||
while(player.checkHit(ball)) {
|
||||
ball.move(ball.speedVector.x * stepValue, ball.speedVector.y * stepValue);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < Direction.straightDirections.length; i++) {
|
||||
direction = Direction.straightDirections[i];
|
||||
this.ballLimit.x = ball.getPosition().x;
|
||||
this.ballLimit.y = ball.getPosition().y;
|
||||
this.ballLimit.add(ball.radius * direction.normalized.x, ball.radius * direction.normalized.y);
|
||||
this.convertPositionToDiscrete(this.ballLimit);
|
||||
_otherAreaPosition.x = _currentAreaPosition.x;
|
||||
_otherAreaPosition.y = _currentAreaPosition.y;
|
||||
_otherAreaPosition.add(direction.x, direction.y);
|
||||
element = this.getElementAt((int) this._otherAreaPosition.x, (int) this._otherAreaPosition.y);
|
||||
// there is an element in that direction
|
||||
if (element != null && element.isVisible()) {
|
||||
// wall-hit case (simple bounce)
|
||||
if (_otherAreaPosition.equals(ballLimit)) {
|
||||
hit = element.hit(ball, direction.normalized, null);
|
||||
if (hit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!hit) {
|
||||
for (int i = 0; i < Direction.oblicDirections.length; i++) {
|
||||
direction = Direction.oblicDirections[i];
|
||||
_otherAreaPosition.x = _currentAreaPosition.x;
|
||||
_otherAreaPosition.y = _currentAreaPosition.y;
|
||||
_otherAreaPosition.add(direction.x, direction.y);
|
||||
element = this.getElementAt((int) this._otherAreaPosition.x, (int) this._otherAreaPosition.y);
|
||||
// there is an element in that direction
|
||||
if (element != null && element.isVisible()) {
|
||||
// corner-hit case (simple bounce)
|
||||
this._tmpPoint.x = _otherAreaPosition.x;
|
||||
this._tmpPoint.y = _otherAreaPosition.y;
|
||||
this._tmpPoint.times(this.positionSize).add(this.positionSize / 2, this.positionSize / 2);
|
||||
this._tmpPoint.add(-direction.x * this.positionSize / 2, -direction.y * this.positionSize / 2);
|
||||
if (ball.position.distance(this._tmpPoint) <= ball.radius) {
|
||||
hit = element.hit(ball, direction.normalized, this._tmpPoint);
|
||||
if (hit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hit) {
|
||||
// console.info("regulate after hit");
|
||||
ball.moveTo(this._oldPosition.x, this._oldPosition.y);
|
||||
this.regulateSpeedWhenBounced(ball);
|
||||
}
|
||||
this._tmpPoint.x = ball.getPosition().x;
|
||||
this._tmpPoint.y = ball.getPosition().y;
|
||||
this.convertPositionToDiscrete(this._tmpPoint);
|
||||
element = this.getElementAt((int) this._tmpPoint.x, (int) this._tmpPoint.y);
|
||||
if (element != null) {
|
||||
element.onBallOver(ball);
|
||||
}
|
||||
this._oldPosition.x = ball.getPosition().x;
|
||||
this._oldPosition.y = ball.getPosition().y;
|
||||
if (this._oldPosition.x + ball.radius < 0 || this._oldPosition.x - ball.radius > this.cols * positionSize
|
||||
|| this._oldPosition.y + ball.radius < 0 || this._oldPosition.y - ball.radius > this.rows * positionSize) {
|
||||
this.end(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.regulateSpeed(ball);
|
||||
}
|
||||
|
||||
private String message = null;
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Point positionInPage;
|
||||
|
||||
public void onInputDeviceDown(Event event, boolean touchDevice) {
|
||||
if (this.initialDate == null) {
|
||||
this.initialDate = new Date();
|
||||
}
|
||||
Point point;
|
||||
if (touchDevice) {
|
||||
for (int i = 0; i < ((TouchEvent) event).changedTouches.length; i++) {
|
||||
Touch t = ((TouchEvent) event).changedTouches.item(i);
|
||||
point = this.factory.getGameManager().deviceToWorld(t.pageX, t.pageY);
|
||||
player.onInputDeviceDown(point);
|
||||
}
|
||||
} else {
|
||||
point = this.factory.getGameManager().deviceToWorld(((MouseEvent) event).pageX, ((MouseEvent) event).pageY);
|
||||
player.onInputDeviceDown(point);
|
||||
}
|
||||
}
|
||||
|
||||
public void onInputDeviceUp(Event event, boolean touchDevice) {
|
||||
player.onInputDeviceUp();
|
||||
}
|
||||
|
||||
public void onInputDeviceMove(Event event, boolean touchDevice) {
|
||||
if (touchDevice) {
|
||||
for (int i = 0; i < ((TouchEvent) event).changedTouches.length; i++) {
|
||||
Touch t = ((TouchEvent) event).changedTouches.item(i);
|
||||
Point point = this.factory.getGameManager().deviceToWorld(t.pageX, t.pageY);
|
||||
player.onInputDeviceMove(point);
|
||||
}
|
||||
} else {
|
||||
Point point = this.factory.getGameManager().deviceToWorld(((MouseEvent) event).pageX, ((MouseEvent) event).pageY);
|
||||
player.onInputDeviceMove(point);
|
||||
}
|
||||
}
|
||||
|
||||
public void end(int winner) {
|
||||
this.finished = true;
|
||||
this.winner = winner;
|
||||
}
|
||||
|
||||
public boolean inBounds(Point position) {
|
||||
return position.x >= 0 && position.x < this.cols && position.y >= 0 && position.y < this.rows;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,288 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.blocksgame;
|
||||
|
||||
import static jsweet.dom.Globals.console;
|
||||
import static jsweet.dom.Globals.document;
|
||||
import static jsweet.util.StringTypes.mousedown;
|
||||
import static jsweet.util.StringTypes.mousemove;
|
||||
import static jsweet.util.StringTypes.mouseup;
|
||||
import static jsweet.util.StringTypes.touchend;
|
||||
import static jsweet.util.StringTypes.touchmove;
|
||||
import static jsweet.util.StringTypes.touchstart;
|
||||
import static org.jsweet.test.transpiler.source.blocksgame.Globals.animate;
|
||||
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.Point;
|
||||
|
||||
import jsweet.dom.Event;
|
||||
import jsweet.dom.HTMLCanvasElement;
|
||||
import jsweet.dom.HTMLElement;
|
||||
import jsweet.dom.MouseEvent;
|
||||
import jsweet.dom.NodeList;
|
||||
import jsweet.dom.TouchEvent;
|
||||
import jsweet.lang.Math;
|
||||
|
||||
public class GameManager {
|
||||
|
||||
public static final double SIZE = 46;
|
||||
public static final double TOUCH_SIZE = 46;
|
||||
|
||||
public static final int FONT_SIZE = 24;
|
||||
|
||||
private GameArea area;
|
||||
public int currentLevel = 0;
|
||||
private boolean paused;
|
||||
public String playerClassName = "IntuitivePlayer";
|
||||
|
||||
public HTMLCanvasElement areaLayer;
|
||||
// private CanvasRenderingContext2D gameContext;
|
||||
public HTMLCanvasElement topLayer;
|
||||
public HTMLCanvasElement backgroundLayer;
|
||||
public HTMLCanvasElement ballsLayer;
|
||||
private HTMLElement textRow;
|
||||
|
||||
private Factory factory;
|
||||
|
||||
private HTMLElement gameRow;
|
||||
private HTMLElement gameContent;
|
||||
|
||||
public static Point findPos(HTMLElement obj) {
|
||||
int curleft = 0, curtop = 0;
|
||||
if (obj.offsetParent != null) {
|
||||
do {
|
||||
curleft += obj.offsetLeft;
|
||||
curtop += obj.offsetTop;
|
||||
} while ((obj = (HTMLElement) obj.offsetParent) != null);
|
||||
return new Point(curleft, curtop);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public GameManager() {
|
||||
this.factory = new Factory(this);
|
||||
this.areaLayer = (HTMLCanvasElement) document.getElementById("areaLayer");
|
||||
this.topLayer = (HTMLCanvasElement) document.getElementById("topLayer");
|
||||
this.ballsLayer = (HTMLCanvasElement) document.getElementById("ballsLayer");
|
||||
this.backgroundLayer = (HTMLCanvasElement) document.getElementById("backgroundLayer");
|
||||
this.textRow = document.getElementById("textRow");
|
||||
this.gameRow = document.getElementById("gameRow");
|
||||
this.gameContent = document.getElementById("gameContent");
|
||||
this.installListeners();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
this.areaLayer.style.border = "";
|
||||
this.textRow.style.display = GameManager.DISPLAY_STYLE;
|
||||
this.initGame();
|
||||
}
|
||||
|
||||
public GameArea getCurrentLevel() {
|
||||
return this.area;
|
||||
}
|
||||
|
||||
private static final String DISPLAY_STYLE = "block";
|
||||
|
||||
public void onLevelEnded() {
|
||||
console.info("level " + this.currentLevel + " ended: " + area.winner);
|
||||
GameArea area = this.getCurrentLevel();
|
||||
area.setMessage("Game ended.");
|
||||
if (area.winner == 0) {
|
||||
area.setMessage("Congratulations!");
|
||||
} else {
|
||||
area.setMessage("You loose. Try again.");
|
||||
}
|
||||
area.render();
|
||||
}
|
||||
|
||||
public void initGame() {
|
||||
console.info("initializing game...");
|
||||
this.area = this.factory.createLevel();
|
||||
this.layoutGame();
|
||||
}
|
||||
|
||||
double scale = 1;
|
||||
|
||||
private void layoutGame() {
|
||||
// two passes a require to calculate actual scale
|
||||
this.doLayoutGame();
|
||||
this.doLayoutGame();
|
||||
}
|
||||
|
||||
private void doLayoutGame() {
|
||||
console.info("layout game1");
|
||||
// this.content.style.width = "" + this.area.getWidth() + "px";
|
||||
HTMLElement html = document.documentElement;
|
||||
|
||||
double pageHeight = html.offsetHeight;
|
||||
this.scale = 1;
|
||||
console.info("height: " + html.offsetHeight);
|
||||
this.scale = (pageHeight / (this.area.getHeight() + this.gameRow.offsetTop));
|
||||
String scaledWidth = "" + Math.floor(this.area.getWidth() * this.scale) + "px";
|
||||
this.textRow.style.width = scaledWidth;
|
||||
this.gameRow.style.width = scaledWidth;
|
||||
this.gameRow.style.height = "" + Math.floor(this.area.getHeight() * this.scale) + "px";
|
||||
this.gameContent.style.width = "" + this.area.getWidth() + "px";
|
||||
this.gameContent.style.height = "" + this.area.getHeight() + "px";
|
||||
|
||||
NodeList l = document.querySelectorAll("body *");
|
||||
for (int i = 0; i < l.length; i++) {
|
||||
HTMLElement e = (HTMLElement) l.item(i);
|
||||
e.style.fontSize = Math.floor(FONT_SIZE * this.scale) + "px";
|
||||
}
|
||||
|
||||
this.areaLayer.width = this.area.getWidth();
|
||||
this.areaLayer.height = this.area.getHeight();
|
||||
this.topLayer.width = this.area.getWidth();
|
||||
this.topLayer.height = this.area.getHeight();
|
||||
this.backgroundLayer.width = this.area.getWidth();
|
||||
this.backgroundLayer.height = this.area.getHeight();
|
||||
this.ballsLayer.width = this.area.getWidth();
|
||||
this.ballsLayer.height = this.area.getHeight();
|
||||
|
||||
String transform = "";
|
||||
String transformOrigin = "";
|
||||
if (this.scale != 1) {
|
||||
transform += "scale(" + this.scale + "," + this.scale + ")";
|
||||
transformOrigin = "0px 0px";
|
||||
}
|
||||
|
||||
this.applyTransform(this.gameContent, transform, transformOrigin);
|
||||
|
||||
Point p = GameManager.findPos(this.gameContent);
|
||||
this.area.positionInPage = p;
|
||||
// this.area.positionInPage = new Point(p.x + translationX, p.y +
|
||||
// translationY);
|
||||
this.area.clearAll = true;
|
||||
this.area.render();
|
||||
}
|
||||
|
||||
public void applyTransform(HTMLElement element, String transform, String transformOrigin) {
|
||||
element.style.setProperty("-moz-transform-origin", transformOrigin);
|
||||
element.style.setProperty("-webkit-transform-origin", transformOrigin);
|
||||
element.style.setProperty("-ms-transform-origin", transformOrigin);
|
||||
element.style.setProperty("-o-transform-origin", transformOrigin);
|
||||
element.style.transformOrigin = transformOrigin;
|
||||
element.style.setProperty("-moz-transform", transform);
|
||||
element.style.setProperty("-webkit-transform", transform);
|
||||
element.style.setProperty("-ms-transform", transform);
|
||||
element.style.setProperty("-o-transform", transform);
|
||||
element.style.transform = transform;
|
||||
}
|
||||
|
||||
public void startGame() {
|
||||
if (this.area != null) {
|
||||
console.info("starting game...");
|
||||
this.paused = false;
|
||||
animate();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isPaused() {
|
||||
return this.paused;
|
||||
}
|
||||
|
||||
public void pauseGame() {
|
||||
this.paused = true;
|
||||
}
|
||||
|
||||
public Point deviceToWorld(double x, double y) {
|
||||
return new Point(Math.floor((x - this.area.positionInPage.x) / this.scale), Math.floor((y - this.area.positionInPage.y) / this.scale));
|
||||
}
|
||||
|
||||
public void onMouseDown(MouseEvent event) {
|
||||
event.preventDefault();
|
||||
this.area.onInputDeviceDown(event, false);
|
||||
}
|
||||
|
||||
public void onMouseUp(MouseEvent event) {
|
||||
event.preventDefault();
|
||||
if (this.area.finished) {
|
||||
this.initGame();
|
||||
this.startGame();
|
||||
}
|
||||
this.area.onInputDeviceUp(event, false);
|
||||
}
|
||||
|
||||
public void onMouseMove(MouseEvent event) {
|
||||
event.preventDefault();
|
||||
this.area.onInputDeviceMove(event, false);
|
||||
}
|
||||
|
||||
private boolean pressed = false;
|
||||
|
||||
public void onTouchStart(TouchEvent event) {
|
||||
event.preventDefault();
|
||||
if (this.area.finished) {
|
||||
this.pressed = true;
|
||||
}
|
||||
console.info(event);
|
||||
this.area.onInputDeviceDown(event, true);
|
||||
}
|
||||
|
||||
public void onTouchEnd(TouchEvent event) {
|
||||
event.preventDefault();
|
||||
if (this.area.finished && this.pressed) {
|
||||
this.pressed = false;
|
||||
this.initGame();
|
||||
this.startGame();
|
||||
}
|
||||
this.area.onInputDeviceUp(event, true);
|
||||
}
|
||||
|
||||
public void onTouchMove(TouchEvent event) {
|
||||
event.preventDefault();
|
||||
this.area.onInputDeviceMove(event, true);
|
||||
}
|
||||
|
||||
public void onMouseClick(Event event) {
|
||||
event.preventDefault();
|
||||
if (this.area.finished) {
|
||||
this.initGame();
|
||||
this.startGame();
|
||||
}
|
||||
}
|
||||
|
||||
public Factory getFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
public void installListeners() {
|
||||
this.topLayer.addEventListener(mousedown, event -> {
|
||||
this.onMouseDown(event);
|
||||
return null;
|
||||
}, true);
|
||||
this.topLayer.addEventListener(mousemove, event -> {
|
||||
this.onMouseMove(event);
|
||||
return null;
|
||||
}, true);
|
||||
this.topLayer.addEventListener(mouseup, event -> {
|
||||
this.onMouseUp(event);
|
||||
return null;
|
||||
}, true);
|
||||
this.topLayer.addEventListener(touchstart, event -> {
|
||||
this.onTouchStart(event);
|
||||
return null;
|
||||
}, true);
|
||||
this.topLayer.addEventListener(touchmove, event -> {
|
||||
this.onTouchMove(event);
|
||||
return null;
|
||||
}, true);
|
||||
this.topLayer.addEventListener(touchend, event -> {
|
||||
this.onTouchEnd(event);
|
||||
return null;
|
||||
}, true);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.blocksgame;
|
||||
|
||||
import static jsweet.dom.Globals.console;
|
||||
import static jsweet.dom.Globals.window;
|
||||
|
||||
import jsweet.dom.Event;
|
||||
import jsweet.lang.Date;
|
||||
|
||||
public class Globals {
|
||||
|
||||
static GameManager gm;
|
||||
|
||||
public static void animate() {
|
||||
GameArea area = gm.getCurrentLevel();
|
||||
if (!gm.isPaused()) {
|
||||
if (!area.finished) {
|
||||
area.currentDate = new Date();
|
||||
area.render();
|
||||
area.calculateNextPositions();
|
||||
window.requestAnimationFrame((time) -> {
|
||||
animate();
|
||||
});
|
||||
} else {
|
||||
gm.onLevelEnded();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Object start(Event event) {
|
||||
gm = new GameManager();
|
||||
gm.init();
|
||||
gm.startGame();
|
||||
return event;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
window.onload = Globals::start;
|
||||
}
|
||||
|
||||
}
|
||||
165
test/org/jsweet/test/transpiler/source/blocksgame/Player.java
Normal file
165
test/org/jsweet/test/transpiler/source/blocksgame/Player.java
Normal file
@ -0,0 +1,165 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.blocksgame;
|
||||
|
||||
import static jsweet.dom.Globals.console;
|
||||
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.Collisions;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.Direction;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.MobileElement;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.Point;
|
||||
import org.jsweet.test.transpiler.source.blocksgame.util.Vector;
|
||||
|
||||
import jsweet.dom.CanvasRenderingContext2D;
|
||||
import jsweet.lang.Math;
|
||||
|
||||
public class Player extends MobileElement {
|
||||
|
||||
private final static int WEIGHT = 10000000;
|
||||
boolean userControlling = false;
|
||||
Point requestedPosition = new Point(0, 0);
|
||||
public GameArea area;
|
||||
public String color;
|
||||
public Direction direction;
|
||||
private int hit = 0;
|
||||
|
||||
public Vector calculateSpeedVector() {
|
||||
if (userControlling) {
|
||||
this.speedVector.x = this.requestedPosition.x - this.getPosition().x;
|
||||
this.speedVector.y = this.requestedPosition.y - this.getPosition().y;
|
||||
return this.speedVector;
|
||||
} else {
|
||||
this.speedVector.times(0.9);
|
||||
this.requestedPosition.x = this.position.x + this.speedVector.x;
|
||||
this.requestedPosition.y = this.position.y + this.speedVector.y;
|
||||
return speedVector;
|
||||
}
|
||||
}
|
||||
|
||||
public double radius;
|
||||
|
||||
public Player(GameArea area, String color, Direction direction, Point position, double radius) {
|
||||
super(position, WEIGHT, 0, 0);
|
||||
this.requestedPosition.x = position.x;
|
||||
this.requestedPosition.y = position.y;
|
||||
this.area = area;
|
||||
this.color = color;
|
||||
this.direction = direction;
|
||||
this.radius = radius;
|
||||
this.width = radius * 2;
|
||||
this.height = radius * 2;
|
||||
}
|
||||
|
||||
private Point delta = new Point(0, 0);
|
||||
|
||||
public void onInputDeviceDown(Point point) {
|
||||
if (this.isHitForUserControl(point)) {
|
||||
delta.x = position.x - point.x;
|
||||
delta.y = position.y - point.y;
|
||||
this.userControlling = true;
|
||||
}
|
||||
}
|
||||
|
||||
static float f = 4;
|
||||
|
||||
public void render(CanvasRenderingContext2D ctx) {
|
||||
ctx.save();
|
||||
ctx.fillStyle = hit > 0 ? "rgb(255,0,0)" : "rgba(255,0,0,0.4)";
|
||||
ctx.beginPath();
|
||||
// ctx.arc(this.getPosition().x, this.getPosition().y, this.radius -
|
||||
// hit, 0, Math.PI * 2);
|
||||
// ctx.fill();
|
||||
// ctx.beginPath();
|
||||
ctx.moveTo(position.x - radius, position.y - radius);
|
||||
ctx.lineTo(position.x + radius, position.y - radius);
|
||||
ctx.arc(position.x + radius, position.y - radius + radius / f, radius / f, -Math.PI / 2, Math.PI / 2);
|
||||
ctx.lineTo(position.x - radius, position.y - radius + radius / (f / 2));
|
||||
ctx.arc(position.x - radius, position.y - radius + radius / f, radius / f, Math.PI / 2, -Math.PI / 2);
|
||||
|
||||
ctx.fill();
|
||||
ctx.strokeStyle = "white";
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.restore();
|
||||
if (hit > 0) {
|
||||
hit--;
|
||||
}
|
||||
}
|
||||
|
||||
private Point _p = new Point(0, 0);
|
||||
|
||||
public boolean checkHit(Ball ball) {
|
||||
_p.x = position.x + radius;
|
||||
_p.y = position.y - radius + radius / f;
|
||||
if (ball.position.distance(_p) < radius / f + ball.radius) {
|
||||
hit = 3;
|
||||
return true;
|
||||
}
|
||||
_p.x = position.x - radius;
|
||||
if (ball.position.distance(_p) < radius / f + ball.radius) {
|
||||
hit = 3;
|
||||
return true;
|
||||
}
|
||||
if (ball.position.x >= position.x - radius && ball.position.x <= position.x + radius) {
|
||||
if (ball.position.y < position.y - radius + radius / f && ball.position.y + ball.radius >= position.y - radius) {
|
||||
hit = 3;
|
||||
return true;
|
||||
}
|
||||
if (ball.position.y > position.y - radius + radius / f && ball.position.y - ball.radius <= position.y - radius + radius / (f / 2)) {
|
||||
hit = 3;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void applyHit(Ball ball) {
|
||||
if (ball.position.x < position.x - radius) {
|
||||
console.info("left");
|
||||
Collisions.sphericCollision(new MobileElement(new Point(position.x - radius, position.y - radius + radius / f), WEIGHT, (radius / f) * 2,
|
||||
(radius / f) * 2), ball);
|
||||
return;
|
||||
}
|
||||
if (ball.position.x > position.x + radius) {
|
||||
console.info("right");
|
||||
Collisions.sphericCollision(new MobileElement(new Point(position.x + radius, position.y - radius + radius / f), WEIGHT, (radius / f) * 2,
|
||||
(radius / f) * 2), ball);
|
||||
return;
|
||||
}
|
||||
if (ball.position.x >= position.x - radius && ball.position.x <= position.x + radius) {
|
||||
console.info("straigth");
|
||||
ball.speedVector.y = -ball.speedVector.y;
|
||||
ball.speedVector.y += speedVector.y;
|
||||
ball.speedVector.x -= speedVector.x;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isHitForUserControl(Point point) {
|
||||
return true; // this.getPosition().distance(point) < this.radius;
|
||||
}
|
||||
|
||||
public void onInputDeviceUp() {
|
||||
this.userControlling = false;
|
||||
}
|
||||
|
||||
public void onInputDeviceMove(Point point) {
|
||||
if (this.userControlling) {
|
||||
this.requestedPosition.x = point.x + delta.x;
|
||||
this.requestedPosition.y = point.y + delta.y;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 6.6 KiB |
@ -0,0 +1,725 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:osb="http://www.openswatchbook.org/uri/2009/osb"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="46"
|
||||
height="46"
|
||||
id="svg2"
|
||||
version="1.1"
|
||||
inkscape:version="0.48.5 r10040"
|
||||
sodipodi:docname="breakable-block.svg">
|
||||
<defs
|
||||
id="defs4">
|
||||
<linearGradient
|
||||
id="linearGradient4347">
|
||||
<stop
|
||||
id="stop4349"
|
||||
offset="0"
|
||||
style="stop-color:#26b126;stop-opacity:1;" />
|
||||
<stop
|
||||
id="stop4351"
|
||||
offset="1"
|
||||
style="stop-color:#ffffff;stop-opacity:1;" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id="linearGradient3882">
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0.990991;"
|
||||
offset="0"
|
||||
id="stop3884" />
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3886" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient3874">
|
||||
<stop
|
||||
style="stop-color:#209420;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop3876" />
|
||||
<stop
|
||||
style="stop-color:#209420;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3878" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id="linearGradient3824"
|
||||
osb:paint="solid">
|
||||
<stop
|
||||
style="stop-color:#94de94;stop-opacity:0;"
|
||||
offset="0"
|
||||
id="stop3826" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient3814">
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop3816" />
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3818" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id="linearGradient3794">
|
||||
<stop
|
||||
style="stop-color:#000000;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop3796" />
|
||||
<stop
|
||||
style="stop-color:#c1c1c1;stop-opacity:0.66666669;"
|
||||
offset="1"
|
||||
id="stop3798" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3794"
|
||||
id="linearGradient3800"
|
||||
x1="6.0987959"
|
||||
y1="38.133438"
|
||||
x2="52.060738"
|
||||
y2="-8.3588343"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="matrix(1.0244528,0,0,1.0277378,-0.07996962,1006.2827)" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3814"
|
||||
id="linearGradient3820"
|
||||
x1="32.350136"
|
||||
y1="11.440156"
|
||||
x2="-1.6793789"
|
||||
y2="58.374367"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient4347"
|
||||
id="linearGradient3840"
|
||||
x1="43.752232"
|
||||
y1="43.083183"
|
||||
x2="-5.3033009"
|
||||
y2="-5.3536301"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="matrix(1.0221837,0,0,1.0306227,-0.63872549,1005.5921)" />
|
||||
<filter
|
||||
inkscape:collect="always"
|
||||
id="filter3864"
|
||||
x="-0.11831332"
|
||||
width="1.2366266"
|
||||
y="-0.12173546"
|
||||
height="1.2434709">
|
||||
<feGaussianBlur
|
||||
inkscape:collect="always"
|
||||
stdDeviation="1.0849676"
|
||||
id="feGaussianBlur3866" />
|
||||
</filter>
|
||||
<filter
|
||||
inkscape:collect="always"
|
||||
id="filter3868"
|
||||
x="-0.12260557"
|
||||
width="1.2452111"
|
||||
y="-0.11750287"
|
||||
height="1.2350057">
|
||||
<feGaussianBlur
|
||||
inkscape:collect="always"
|
||||
stdDeviation="1.0385638"
|
||||
id="feGaussianBlur3870" />
|
||||
</filter>
|
||||
<radialGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3874"
|
||||
id="radialGradient3880"
|
||||
cx="19.489631"
|
||||
cy="1.6290494"
|
||||
fx="19.489631"
|
||||
fy="1.6290494"
|
||||
r="18.310252"
|
||||
gradientTransform="matrix(1.004895,0,0,0.1542945,-0.35936036,1008.4033)"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3882"
|
||||
id="linearGradient3888"
|
||||
x1="1.1793786"
|
||||
y1="1.6290494"
|
||||
x2="37.799883"
|
||||
y2="1.6290494"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="matrix(1.004895,0,0,5.6503417,-0.35936036,999.44972)" />
|
||||
<radialGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3874-6"
|
||||
id="radialGradient3880-9"
|
||||
cx="19.489632"
|
||||
cy="1.6290494"
|
||||
fx="19.489632"
|
||||
fy="1.6290494"
|
||||
r="18.310251"
|
||||
gradientTransform="matrix(1.004895,0,0,0.09231621,-0.35936036,1008.3272)"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient3874-6">
|
||||
<stop
|
||||
style="stop-color:#209420;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop3876-8" />
|
||||
<stop
|
||||
style="stop-color:#209420;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3878-8" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3882-4"
|
||||
id="linearGradient3888-9"
|
||||
x1="1.1793786"
|
||||
y1="1.6290494"
|
||||
x2="37.799885"
|
||||
y2="1.6290494"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="matrix(1.004895,0,0,3.3806658,-0.35936036,1002.9702)" />
|
||||
<linearGradient
|
||||
id="linearGradient3882-4">
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0.990991;"
|
||||
offset="0"
|
||||
id="stop3884-5" />
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3886-0" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
y2="1.6471285"
|
||||
x2="54.278095"
|
||||
y1="1.6290494"
|
||||
x1="1.1793786"
|
||||
gradientTransform="matrix(0,1.3078889,-13.828188,0,24.662586,1004.1286)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient3911"
|
||||
xlink:href="#linearGradient3882-4"
|
||||
inkscape:collect="always" />
|
||||
<radialGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3874-9"
|
||||
id="radialGradient3880-7"
|
||||
cx="19.489632"
|
||||
cy="1.6290494"
|
||||
fx="19.489632"
|
||||
fy="1.6290494"
|
||||
r="18.310251"
|
||||
gradientTransform="matrix(1.004895,0,0,0.1542945,-0.35936036,1008.4033)"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient3874-9">
|
||||
<stop
|
||||
style="stop-color:#209420;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop3876-5" />
|
||||
<stop
|
||||
style="stop-color:#209420;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3878-3" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3882-8"
|
||||
id="linearGradient3888-7"
|
||||
x1="1.1793786"
|
||||
y1="1.6290494"
|
||||
x2="37.799885"
|
||||
y2="1.6290494"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="matrix(1.004895,0,0,5.6503417,-0.35936036,999.44972)" />
|
||||
<linearGradient
|
||||
id="linearGradient3882-8">
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0.990991;"
|
||||
offset="0"
|
||||
id="stop3884-54" />
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3886-7" />
|
||||
</linearGradient>
|
||||
<radialGradient
|
||||
r="18.310251"
|
||||
fy="1.6290494"
|
||||
fx="19.489632"
|
||||
cy="1.6290494"
|
||||
cx="19.489632"
|
||||
gradientTransform="matrix(0,-1.004895,0.28379836,0,43.556091,1052.4955)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="radialGradient3959"
|
||||
xlink:href="#linearGradient3874-9"
|
||||
inkscape:collect="always" />
|
||||
<linearGradient
|
||||
y2="1.6290494"
|
||||
x2="37.799885"
|
||||
y1="1.6290494"
|
||||
x1="1.1793786"
|
||||
gradientTransform="matrix(0,-1.004895,10.392838,0,27.087658,1052.4955)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient3961"
|
||||
xlink:href="#linearGradient3874-9"
|
||||
inkscape:collect="always" />
|
||||
<radialGradient
|
||||
r="18.310251"
|
||||
fy="1.6290494"
|
||||
fx="19.489632"
|
||||
cy="1.6290494"
|
||||
cx="19.489632"
|
||||
gradientTransform="matrix(0,-1.004895,0.1542945,0,43.766597,1053.1205)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="radialGradient3959-7"
|
||||
xlink:href="#linearGradient3874-9-2"
|
||||
inkscape:collect="always" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient3874-9-2">
|
||||
<stop
|
||||
style="stop-color:#209420;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop3876-5-0" />
|
||||
<stop
|
||||
style="stop-color:#209420;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3878-3-9" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
y2="1.6290494"
|
||||
x2="37.799885"
|
||||
y1="1.6290494"
|
||||
x1="1.1793786"
|
||||
gradientTransform="matrix(0,-1.004895,5.6503417,0,34.813097,1053.1205)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient3961-3"
|
||||
xlink:href="#linearGradient3874-9-2"
|
||||
inkscape:collect="always" />
|
||||
<radialGradient
|
||||
r="18.310251"
|
||||
fy="1.6290494"
|
||||
fx="19.489632"
|
||||
cy="1.6290494"
|
||||
cx="19.489632"
|
||||
gradientTransform="matrix(-1.2407681,0,0,-0.31619723,48.136043,1051.104)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="radialGradient4012"
|
||||
xlink:href="#linearGradient3874-9-2"
|
||||
inkscape:collect="always" />
|
||||
<linearGradient
|
||||
y2="1.6290494"
|
||||
x2="37.799885"
|
||||
y1="1.6290494"
|
||||
x1="1.1793786"
|
||||
gradientTransform="matrix(-1.2407681,0,0,-11.579301,48.136043,1069.4525)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient4014"
|
||||
xlink:href="#linearGradient3874-9-2"
|
||||
inkscape:collect="always" />
|
||||
<radialGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3874-4"
|
||||
id="radialGradient3880-2"
|
||||
cx="19.489632"
|
||||
cy="1.6290494"
|
||||
fx="19.489632"
|
||||
fy="1.6290494"
|
||||
r="18.310251"
|
||||
gradientTransform="matrix(1.004895,0,0,0.1542945,-0.35936036,1008.4033)"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient3874-4">
|
||||
<stop
|
||||
style="stop-color:#209420;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop3876-56" />
|
||||
<stop
|
||||
style="stop-color:#209420;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3878-80" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3882-9"
|
||||
id="linearGradient3888-1"
|
||||
x1="1.1793786"
|
||||
y1="1.6290494"
|
||||
x2="37.799885"
|
||||
y2="1.6290494"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="matrix(1.004895,0,0,5.6503417,-0.35936036,999.44972)" />
|
||||
<linearGradient
|
||||
id="linearGradient3882-9">
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0.990991;"
|
||||
offset="0"
|
||||
id="stop3884-8" />
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3886-9" />
|
||||
</linearGradient>
|
||||
<radialGradient
|
||||
r="18.310251"
|
||||
fy="1.6290494"
|
||||
fx="19.489632"
|
||||
cy="1.6290494"
|
||||
cx="19.489632"
|
||||
gradientTransform="matrix(0.97930335,0,0,0.20580435,29.129583,1017.7772)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="radialGradient4062"
|
||||
xlink:href="#linearGradient3874-4"
|
||||
inkscape:collect="always" />
|
||||
<linearGradient
|
||||
y2="1.6290494"
|
||||
x2="37.799885"
|
||||
y1="1.6290494"
|
||||
x1="1.1793786"
|
||||
gradientTransform="matrix(0.97930335,0,0,7.536658,29.129583,1005.8345)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient4064"
|
||||
xlink:href="#linearGradient3882-9"
|
||||
inkscape:collect="always" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3882-9"
|
||||
id="linearGradient4101"
|
||||
x1="3.1239223"
|
||||
y1="23.107418"
|
||||
x2="43.368347"
|
||||
y2="23.107418"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="matrix(0.79595456,0,0,0.77919418,0.6332097,1007.5754)" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3882-9-2"
|
||||
id="linearGradient4101-4"
|
||||
x1="3.1239223"
|
||||
y1="23.107418"
|
||||
x2="43.368347"
|
||||
y2="23.107418"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="matrix(0.79595456,0,0,0.77919418,0.6332097,1007.5754)" />
|
||||
<linearGradient
|
||||
id="linearGradient3882-9-2">
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0.990991;"
|
||||
offset="0"
|
||||
id="stop3884-8-4" />
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3886-9-5" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
y2="23.107418"
|
||||
x2="43.368347"
|
||||
y1="23.107418"
|
||||
x1="3.1239223"
|
||||
gradientTransform="matrix(0.79595456,0,0,0.77919418,20.034451,1004.1282)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient4152"
|
||||
xlink:href="#linearGradient3882-9-2"
|
||||
inkscape:collect="always" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3882-9-24"
|
||||
id="linearGradient4101-3"
|
||||
x1="3.1239223"
|
||||
y1="23.107418"
|
||||
x2="43.368347"
|
||||
y2="23.107418"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="matrix(0.79595456,0,0,0.77919418,0.6332097,1007.5754)" />
|
||||
<linearGradient
|
||||
id="linearGradient3882-9-24">
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0.990991;"
|
||||
offset="0"
|
||||
id="stop3884-8-9" />
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3886-9-8" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
y2="23.107418"
|
||||
x2="43.368347"
|
||||
y1="23.107418"
|
||||
x1="3.1239223"
|
||||
gradientTransform="matrix(0.38085749,0,0,0.38484352,0.25053473,1032.2443)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient4152-2"
|
||||
xlink:href="#linearGradient3882-9-24"
|
||||
inkscape:collect="always" />
|
||||
<filter
|
||||
inkscape:collect="always"
|
||||
id="filter4188"
|
||||
x="-0.12035473"
|
||||
width="1.2407095"
|
||||
y="-0.11964736"
|
||||
height="1.2392947">
|
||||
<feGaussianBlur
|
||||
inkscape:collect="always"
|
||||
stdDeviation="0.74953586"
|
||||
id="feGaussianBlur4190" />
|
||||
</filter>
|
||||
<filter
|
||||
inkscape:collect="always"
|
||||
id="filter4200">
|
||||
<feGaussianBlur
|
||||
inkscape:collect="always"
|
||||
stdDeviation="0.71245308"
|
||||
id="feGaussianBlur4202" />
|
||||
</filter>
|
||||
<filter
|
||||
inkscape:collect="always"
|
||||
id="filter4212"
|
||||
x="-0.10556914"
|
||||
width="1.2111383"
|
||||
y="-0.10832783"
|
||||
height="1.2166557">
|
||||
<feGaussianBlur
|
||||
inkscape:collect="always"
|
||||
stdDeviation="1.3740167"
|
||||
id="feGaussianBlur4214" />
|
||||
</filter>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3882-9-7"
|
||||
id="linearGradient4101-46"
|
||||
x1="3.1239223"
|
||||
y1="23.107418"
|
||||
x2="43.368347"
|
||||
y2="23.107418"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="matrix(0.79595456,0,0,0.77919418,0.6332097,1007.5754)" />
|
||||
<linearGradient
|
||||
id="linearGradient3882-9-7">
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0.990991;"
|
||||
offset="0"
|
||||
id="stop3884-8-0" />
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3886-9-89" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
y2="23.107418"
|
||||
x2="43.368347"
|
||||
y1="23.107418"
|
||||
x1="3.1239223"
|
||||
gradientTransform="matrix(0.41985094,0,0,0.40591379,6.0174081,1011.2953)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient4233"
|
||||
xlink:href="#linearGradient3882-9-7"
|
||||
inkscape:collect="always" />
|
||||
<linearGradient
|
||||
y2="1.6471285"
|
||||
x2="54.278095"
|
||||
y1="1.6290494"
|
||||
x1="1.1793786"
|
||||
gradientTransform="matrix(0,1.3078889,-13.828188,0,24.662586,1004.1286)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient3911-3"
|
||||
xlink:href="#linearGradient3882-4-3"
|
||||
inkscape:collect="always" />
|
||||
<linearGradient
|
||||
id="linearGradient3882-4-3">
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0.990991;"
|
||||
offset="0"
|
||||
id="stop3884-5-4" />
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3886-0-4" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
y2="1.6471285"
|
||||
x2="54.278095"
|
||||
y1="1.6290494"
|
||||
x1="1.1793786"
|
||||
gradientTransform="matrix(1.3078889,0,0,13.828188,0.00970002,985.836)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient4273"
|
||||
xlink:href="#linearGradient3882-4-3"
|
||||
inkscape:collect="always" />
|
||||
<radialGradient
|
||||
r="18.310251"
|
||||
fy="1.6290494"
|
||||
fx="19.489632"
|
||||
cy="1.6290494"
|
||||
cx="19.489632"
|
||||
gradientTransform="matrix(-1.2407681,0,0,-0.31619723,48.136043,1051.104)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="radialGradient4012-5"
|
||||
xlink:href="#linearGradient3874-9-2-6"
|
||||
inkscape:collect="always" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient3874-9-2-6">
|
||||
<stop
|
||||
style="stop-color:#209420;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop3876-5-0-6" />
|
||||
<stop
|
||||
style="stop-color:#209420;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3878-3-9-0" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
y2="1.6290494"
|
||||
x2="37.799885"
|
||||
y1="1.6290494"
|
||||
x1="1.1793786"
|
||||
gradientTransform="matrix(-1.2407681,0,0,-11.579301,48.136043,1069.4525)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient4014-7"
|
||||
xlink:href="#linearGradient3874-9-2-6"
|
||||
inkscape:collect="always" />
|
||||
<radialGradient
|
||||
r="18.310251"
|
||||
fy="1.6290494"
|
||||
fx="19.489632"
|
||||
cy="1.6290494"
|
||||
cx="19.489632"
|
||||
gradientTransform="matrix(0,-1.2407681,0.31619723,0,43.736,1054.6693)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="radialGradient4314"
|
||||
xlink:href="#linearGradient3874-9-2-6"
|
||||
inkscape:collect="always" />
|
||||
<linearGradient
|
||||
y2="1.6290494"
|
||||
x2="37.799885"
|
||||
y1="1.6290494"
|
||||
x1="1.1793786"
|
||||
gradientTransform="matrix(0,-1.2407681,11.579301,0,25.3875,1054.6693)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient4316"
|
||||
xlink:href="#linearGradient3874-9-2-6"
|
||||
inkscape:collect="always" />
|
||||
</defs>
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="4"
|
||||
inkscape:cx="-81.900677"
|
||||
inkscape:cy="30.911591"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
inkscape:window-width="1823"
|
||||
inkscape:window-height="960"
|
||||
inkscape:window-x="115"
|
||||
inkscape:window-y="27"
|
||||
inkscape:window-maximized="0" />
|
||||
<metadata
|
||||
id="metadata7">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(0,-1006.3622)">
|
||||
<rect
|
||||
style="opacity:1;fill:url(#linearGradient3840);fill-opacity:1.0;fill-rule:nonzero;stroke:none"
|
||||
id="rect3012"
|
||||
width="46.07806"
|
||||
height="46.276295"
|
||||
x="-0.0062815552"
|
||||
y="1006.269"
|
||||
ry="0" />
|
||||
<path
|
||||
style="fill:#209420;fill-opacity:0.68965518;stroke:none;filter:url(#filter3868)"
|
||||
d="m 45.078342,1030.2651 c 0.08214,21.1277 -20.329605,21.1277 -20.329605,21.1277 l 20.329605,0.085 z"
|
||||
id="path3842"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="opacity:0.87000002;fill:#f3fbf3;fill-opacity:1;stroke:none;filter:url(#filter3864)"
|
||||
d="m 0.88388348,1028.9393 c 0.13205222,-21.4764 22.00869852,-21.39 22.00869852,-21.39 l -21.8326289,0.043 z"
|
||||
id="path3856"
|
||||
inkscape:connector-curvature="0"
|
||||
transform="matrix(1.3520034,0,0,1.3188183,0.09478141,-320.94831)" />
|
||||
<path
|
||||
style="fill:none;stroke:url(#linearGradient3911);stroke-width:4.25273228px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 2.1364854,1006.3251 0,46.5877 0,0"
|
||||
id="path3872-9"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:url(#radialGradient4012);fill-opacity:1;stroke:url(#linearGradient4014);stroke-width:3.79041243px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 46.052323,1050.59 -44.196697,0 0,0"
|
||||
id="path3872-8-4"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;stroke:url(#linearGradient4101);stroke-width:3.38799999999999990;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none;filter:url(#filter4200)"
|
||||
d="m 3.5176872,1010.3599 31.2367808,30.4413"
|
||||
id="path4093"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;stroke:url(#linearGradient4152);stroke-width:2.58800006;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;filter:url(#filter4212)"
|
||||
d="M 22.918929,1006.9127 54.15571,1037.354"
|
||||
id="path4093-7"
|
||||
inkscape:connector-curvature="0"
|
||||
transform="matrix(0.54033855,0,0,0.55433098,14.620528,450.49504)" />
|
||||
<path
|
||||
style="opacity:0.80936453;fill:none;stroke:url(#linearGradient4152-2);stroke-width:1.64702344;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;filter:url(#filter4188)"
|
||||
d="m 1.6307328,1033.6195 14.9465342,15.0349"
|
||||
id="path4093-1"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;stroke:url(#linearGradient4233);stroke-width:0.78001046;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
|
||||
d="M 7.5389154,1012.7459 24.015725,1028.604"
|
||||
id="path4093-74"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;stroke:url(#linearGradient4273);stroke-width:4.25273228px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 2.20615,1008.3621 46.5877,0 0,0"
|
||||
id="path3872-9-7"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:url(#radialGradient4314);fill-opacity:1;stroke:url(#linearGradient4316);stroke-width:3.79041243px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 44.25,1052.5855 0,-44.1966 0,0"
|
||||
id="path3872-8-4-9"
|
||||
inkscape:connector-curvature="0" />
|
||||
<rect
|
||||
style="opacity:0.35785953;fill:none;stroke:#000000;stroke-opacity:1"
|
||||
id="rect4345"
|
||||
width="45.75"
|
||||
height="46"
|
||||
x="0.25"
|
||||
y="0.12499996"
|
||||
transform="translate(0,1006.3622)"
|
||||
ry="0.17677669" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 23 KiB |
76
test/org/jsweet/test/transpiler/source/blocksgame/index.html
Normal file
76
test/org/jsweet/test/transpiler/source/blocksgame/index.html
Normal file
@ -0,0 +1,76 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Blocks game</title>
|
||||
<style type="text/css">
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: black;
|
||||
}
|
||||
|
||||
body * {
|
||||
font-family: verdana;
|
||||
font-size: 12px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
div {
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
border: 0px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<link rel="icon" type="image/png" href="../../../../../logo.png">
|
||||
<link rel="shortcut icon" href="../../../../../logo.png">
|
||||
</head>
|
||||
<body id="body" style="margin: 0; padding: 0">
|
||||
|
||||
<img id="sprite-breakable-block" src="breakable-block.png"
|
||||
style="display: none;" />
|
||||
<img id="sprite-unbreakable-block" src="unbreakable-block.png"
|
||||
style="display: none;" />
|
||||
<canvas id="spritesCanvas" style="display: none;" width="1000px"
|
||||
height="100px"></canvas>
|
||||
|
||||
<div id="textRow" style="margin-left: auto; margin-right: auto;">
|
||||
<span id="blocks" style="font-family: impact;">Blocks</span><span style="float: right"><span
|
||||
id="time" style="font-family: impact;"></span></span>
|
||||
</div>
|
||||
|
||||
<div id="gameRow"
|
||||
style="margin-left: auto; margin-right: auto; height: 40px;">
|
||||
<div id="gameContent" style="position: relative;">
|
||||
<canvas id="topLayer"
|
||||
style="position: absolute; left: 0px; top: 0px; z-index: 4;"></canvas>
|
||||
<canvas id="ballsLayer"
|
||||
style="position: absolute; left: 0px; top: 0px; z-index: 3;"></canvas>
|
||||
<canvas id="areaLayer"
|
||||
style="position: absolute; left: 0px; top: 0px; z-index: 1;"></canvas>
|
||||
<canvas id="backgroundLayer"
|
||||
style="position: absolute; left: 0px; top: 0px; z-index: 0; background-color: black;"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="util/Point.js"></script>
|
||||
<script src="util/Line.js"></script>
|
||||
<script src="util/Rectangle.js"></script>
|
||||
<script src="util/AnimatedElement.js"></script>
|
||||
<script src="util/Vector.js"></script>
|
||||
<script src="util/MobileElement.js"></script>
|
||||
<script src="util/Direction.js"></script>
|
||||
<script src="util/Collisions.js"></script>
|
||||
<script src="BlockElement.js"></script>
|
||||
<script src="Ball.js"></script>
|
||||
<script src="Player.js"></script>
|
||||
<script src="Factory.js"></script>
|
||||
<script src="GameArea.js"></script>
|
||||
<script src="GameManager.js"></script>
|
||||
<script src="globals/Globals.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@ -0,0 +1,16 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@jsweet.lang.Root
|
||||
package org.jsweet.test.transpiler.source.blocksgame;
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 6.9 KiB |
@ -0,0 +1,723 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:osb="http://www.openswatchbook.org/uri/2009/osb"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="46"
|
||||
height="46"
|
||||
id="svg2"
|
||||
version="1.1"
|
||||
inkscape:version="0.48.5 r10040"
|
||||
sodipodi:docname="unbreakable-block.svg">
|
||||
<defs
|
||||
id="defs4">
|
||||
<linearGradient
|
||||
id="linearGradient4347">
|
||||
<stop
|
||||
id="stop4349"
|
||||
offset="0"
|
||||
style="stop-color:#677067;stop-opacity:1;" />
|
||||
<stop
|
||||
id="stop4351"
|
||||
offset="1"
|
||||
style="stop-color:#ffffff;stop-opacity:1;" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id="linearGradient3882">
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0.990991;"
|
||||
offset="0"
|
||||
id="stop3884" />
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3886" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient3874">
|
||||
<stop
|
||||
style="stop-color:#209420;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop3876" />
|
||||
<stop
|
||||
style="stop-color:#209420;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3878" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id="linearGradient3824"
|
||||
osb:paint="solid">
|
||||
<stop
|
||||
style="stop-color:#94de94;stop-opacity:0;"
|
||||
offset="0"
|
||||
id="stop3826" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient3814">
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop3816" />
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3818" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id="linearGradient3794">
|
||||
<stop
|
||||
style="stop-color:#000000;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop3796" />
|
||||
<stop
|
||||
style="stop-color:#c1c1c1;stop-opacity:0.66666669;"
|
||||
offset="1"
|
||||
id="stop3798" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3794"
|
||||
id="linearGradient3800"
|
||||
x1="6.0987959"
|
||||
y1="38.133438"
|
||||
x2="52.060738"
|
||||
y2="-8.3588343"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="matrix(1.0244528,0,0,1.0277378,-0.07996962,1006.2827)" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3814"
|
||||
id="linearGradient3820"
|
||||
x1="32.350136"
|
||||
y1="11.440156"
|
||||
x2="-1.6793789"
|
||||
y2="58.374367"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient4347"
|
||||
id="linearGradient3840"
|
||||
x1="43.752232"
|
||||
y1="43.083183"
|
||||
x2="-5.3033009"
|
||||
y2="-5.3536301"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="matrix(1.0221837,0,0,1.0306227,-0.63872549,1005.5921)" />
|
||||
<filter
|
||||
inkscape:collect="always"
|
||||
id="filter3864"
|
||||
x="-0.11831332"
|
||||
width="1.2366266"
|
||||
y="-0.12173546"
|
||||
height="1.2434709">
|
||||
<feGaussianBlur
|
||||
inkscape:collect="always"
|
||||
stdDeviation="1.0849676"
|
||||
id="feGaussianBlur3866" />
|
||||
</filter>
|
||||
<filter
|
||||
inkscape:collect="always"
|
||||
id="filter3868"
|
||||
x="-0.12260557"
|
||||
width="1.2452111"
|
||||
y="-0.11750287"
|
||||
height="1.2350057">
|
||||
<feGaussianBlur
|
||||
inkscape:collect="always"
|
||||
stdDeviation="1.0385638"
|
||||
id="feGaussianBlur3870" />
|
||||
</filter>
|
||||
<radialGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3874"
|
||||
id="radialGradient3880"
|
||||
cx="19.489631"
|
||||
cy="1.6290494"
|
||||
fx="19.489631"
|
||||
fy="1.6290494"
|
||||
r="18.310252"
|
||||
gradientTransform="matrix(1.004895,0,0,0.1542945,-0.35936036,1008.4033)"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3882"
|
||||
id="linearGradient3888"
|
||||
x1="1.1793786"
|
||||
y1="1.6290494"
|
||||
x2="37.799883"
|
||||
y2="1.6290494"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="matrix(1.004895,0,0,5.6503417,-0.35936036,999.44972)" />
|
||||
<radialGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3874-6"
|
||||
id="radialGradient3880-9"
|
||||
cx="19.489632"
|
||||
cy="1.6290494"
|
||||
fx="19.489632"
|
||||
fy="1.6290494"
|
||||
r="18.310251"
|
||||
gradientTransform="matrix(1.004895,0,0,0.09231621,-0.35936036,1008.3272)"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient3874-6">
|
||||
<stop
|
||||
style="stop-color:#209420;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop3876-8" />
|
||||
<stop
|
||||
style="stop-color:#209420;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3878-8" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3882-4"
|
||||
id="linearGradient3888-9"
|
||||
x1="1.1793786"
|
||||
y1="1.6290494"
|
||||
x2="37.799885"
|
||||
y2="1.6290494"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="matrix(1.004895,0,0,3.3806658,-0.35936036,1002.9702)" />
|
||||
<linearGradient
|
||||
id="linearGradient3882-4">
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0.990991;"
|
||||
offset="0"
|
||||
id="stop3884-5" />
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3886-0" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
y2="1.6471285"
|
||||
x2="54.278095"
|
||||
y1="1.6290494"
|
||||
x1="1.1793786"
|
||||
gradientTransform="matrix(0,1.3078889,-13.828188,0,24.662586,1004.1286)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient3911"
|
||||
xlink:href="#linearGradient3882-4"
|
||||
inkscape:collect="always" />
|
||||
<radialGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3874-9"
|
||||
id="radialGradient3880-7"
|
||||
cx="19.489632"
|
||||
cy="1.6290494"
|
||||
fx="19.489632"
|
||||
fy="1.6290494"
|
||||
r="18.310251"
|
||||
gradientTransform="matrix(1.004895,0,0,0.1542945,-0.35936036,1008.4033)"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient3874-9">
|
||||
<stop
|
||||
style="stop-color:#209420;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop3876-5" />
|
||||
<stop
|
||||
style="stop-color:#209420;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3878-3" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3882-8"
|
||||
id="linearGradient3888-7"
|
||||
x1="1.1793786"
|
||||
y1="1.6290494"
|
||||
x2="37.799885"
|
||||
y2="1.6290494"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="matrix(1.004895,0,0,5.6503417,-0.35936036,999.44972)" />
|
||||
<linearGradient
|
||||
id="linearGradient3882-8">
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0.990991;"
|
||||
offset="0"
|
||||
id="stop3884-54" />
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3886-7" />
|
||||
</linearGradient>
|
||||
<radialGradient
|
||||
r="18.310251"
|
||||
fy="1.6290494"
|
||||
fx="19.489632"
|
||||
cy="1.6290494"
|
||||
cx="19.489632"
|
||||
gradientTransform="matrix(0,-1.004895,0.28379836,0,43.556091,1052.4955)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="radialGradient3959"
|
||||
xlink:href="#linearGradient3874-9"
|
||||
inkscape:collect="always" />
|
||||
<linearGradient
|
||||
y2="1.6290494"
|
||||
x2="37.799885"
|
||||
y1="1.6290494"
|
||||
x1="1.1793786"
|
||||
gradientTransform="matrix(0,-1.004895,10.392838,0,27.087658,1052.4955)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient3961"
|
||||
xlink:href="#linearGradient3874-9"
|
||||
inkscape:collect="always" />
|
||||
<radialGradient
|
||||
r="18.310251"
|
||||
fy="1.6290494"
|
||||
fx="19.489632"
|
||||
cy="1.6290494"
|
||||
cx="19.489632"
|
||||
gradientTransform="matrix(0,-1.004895,0.1542945,0,43.766597,1053.1205)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="radialGradient3959-7"
|
||||
xlink:href="#linearGradient3874-9-2"
|
||||
inkscape:collect="always" />
|
||||
<linearGradient
|
||||
id="linearGradient3874-9-2">
|
||||
<stop
|
||||
style="stop-color:#555f55;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop3876-5-0" />
|
||||
<stop
|
||||
style="stop-color:#000000;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3878-3-9" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
y2="1.6290494"
|
||||
x2="37.799885"
|
||||
y1="1.6290494"
|
||||
x1="1.1793786"
|
||||
gradientTransform="matrix(0,-1.004895,5.6503417,0,34.813097,1053.1205)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient3961-3"
|
||||
xlink:href="#linearGradient3874-9-2"
|
||||
inkscape:collect="always" />
|
||||
<radialGradient
|
||||
r="18.310251"
|
||||
fy="1.6290494"
|
||||
fx="19.489632"
|
||||
cy="1.6290494"
|
||||
cx="19.489632"
|
||||
gradientTransform="matrix(-1.2407681,0,0,-0.31619723,48.136043,1051.104)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="radialGradient4012"
|
||||
xlink:href="#linearGradient3874-9-2"
|
||||
inkscape:collect="always" />
|
||||
<linearGradient
|
||||
y2="1.6290494"
|
||||
x2="37.799885"
|
||||
y1="1.6290494"
|
||||
x1="1.1793786"
|
||||
gradientTransform="matrix(-1.2407681,0,0,-11.579301,48.136043,1069.4525)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient4014"
|
||||
xlink:href="#linearGradient3874-9-2"
|
||||
inkscape:collect="always" />
|
||||
<radialGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3874-4"
|
||||
id="radialGradient3880-2"
|
||||
cx="19.489632"
|
||||
cy="1.6290494"
|
||||
fx="19.489632"
|
||||
fy="1.6290494"
|
||||
r="18.310251"
|
||||
gradientTransform="matrix(1.004895,0,0,0.1542945,-0.35936036,1008.4033)"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient3874-4">
|
||||
<stop
|
||||
style="stop-color:#209420;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop3876-56" />
|
||||
<stop
|
||||
style="stop-color:#209420;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3878-80" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3882-9"
|
||||
id="linearGradient3888-1"
|
||||
x1="1.1793786"
|
||||
y1="1.6290494"
|
||||
x2="37.799885"
|
||||
y2="1.6290494"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="matrix(1.004895,0,0,5.6503417,-0.35936036,999.44972)" />
|
||||
<linearGradient
|
||||
id="linearGradient3882-9">
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0.990991;"
|
||||
offset="0"
|
||||
id="stop3884-8" />
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3886-9" />
|
||||
</linearGradient>
|
||||
<radialGradient
|
||||
r="18.310251"
|
||||
fy="1.6290494"
|
||||
fx="19.489632"
|
||||
cy="1.6290494"
|
||||
cx="19.489632"
|
||||
gradientTransform="matrix(0.97930335,0,0,0.20580435,29.129583,1017.7772)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="radialGradient4062"
|
||||
xlink:href="#linearGradient3874-4"
|
||||
inkscape:collect="always" />
|
||||
<linearGradient
|
||||
y2="1.6290494"
|
||||
x2="37.799885"
|
||||
y1="1.6290494"
|
||||
x1="1.1793786"
|
||||
gradientTransform="matrix(0.97930335,0,0,7.536658,29.129583,1005.8345)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient4064"
|
||||
xlink:href="#linearGradient3882-9"
|
||||
inkscape:collect="always" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3882-9"
|
||||
id="linearGradient4101"
|
||||
x1="3.1239223"
|
||||
y1="23.107418"
|
||||
x2="43.368347"
|
||||
y2="23.107418"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="matrix(0.79595456,0,0,0.77919418,0.6332097,1007.5754)" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3882-9-2"
|
||||
id="linearGradient4101-4"
|
||||
x1="3.1239223"
|
||||
y1="23.107418"
|
||||
x2="43.368347"
|
||||
y2="23.107418"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="matrix(0.79595456,0,0,0.77919418,0.6332097,1007.5754)" />
|
||||
<linearGradient
|
||||
id="linearGradient3882-9-2">
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0.990991;"
|
||||
offset="0"
|
||||
id="stop3884-8-4" />
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3886-9-5" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
y2="23.107418"
|
||||
x2="43.368347"
|
||||
y1="23.107418"
|
||||
x1="3.1239223"
|
||||
gradientTransform="matrix(0.79595456,0,0,0.77919418,20.034451,1004.1282)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient4152"
|
||||
xlink:href="#linearGradient3882-9-2"
|
||||
inkscape:collect="always" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3882-9-24"
|
||||
id="linearGradient4101-3"
|
||||
x1="3.1239223"
|
||||
y1="23.107418"
|
||||
x2="43.368347"
|
||||
y2="23.107418"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="matrix(0.79595456,0,0,0.77919418,0.6332097,1007.5754)" />
|
||||
<linearGradient
|
||||
id="linearGradient3882-9-24">
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0.990991;"
|
||||
offset="0"
|
||||
id="stop3884-8-9" />
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3886-9-8" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
y2="23.107418"
|
||||
x2="43.368347"
|
||||
y1="23.107418"
|
||||
x1="3.1239223"
|
||||
gradientTransform="matrix(0.38085749,0,0,0.38484352,0.25053473,1032.2443)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient4152-2"
|
||||
xlink:href="#linearGradient3882-9-24"
|
||||
inkscape:collect="always" />
|
||||
<filter
|
||||
inkscape:collect="always"
|
||||
id="filter4188"
|
||||
x="-0.12035473"
|
||||
width="1.2407095"
|
||||
y="-0.11964736"
|
||||
height="1.2392947">
|
||||
<feGaussianBlur
|
||||
inkscape:collect="always"
|
||||
stdDeviation="0.74953586"
|
||||
id="feGaussianBlur4190" />
|
||||
</filter>
|
||||
<filter
|
||||
inkscape:collect="always"
|
||||
id="filter4200">
|
||||
<feGaussianBlur
|
||||
inkscape:collect="always"
|
||||
stdDeviation="0.71245308"
|
||||
id="feGaussianBlur4202" />
|
||||
</filter>
|
||||
<filter
|
||||
inkscape:collect="always"
|
||||
id="filter4212"
|
||||
x="-0.10556914"
|
||||
width="1.2111383"
|
||||
y="-0.10832783"
|
||||
height="1.2166557">
|
||||
<feGaussianBlur
|
||||
inkscape:collect="always"
|
||||
stdDeviation="1.3740167"
|
||||
id="feGaussianBlur4214" />
|
||||
</filter>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient3882-9-7"
|
||||
id="linearGradient4101-46"
|
||||
x1="3.1239223"
|
||||
y1="23.107418"
|
||||
x2="43.368347"
|
||||
y2="23.107418"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="matrix(0.79595456,0,0,0.77919418,0.6332097,1007.5754)" />
|
||||
<linearGradient
|
||||
id="linearGradient3882-9-7">
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0.990991;"
|
||||
offset="0"
|
||||
id="stop3884-8-0" />
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3886-9-89" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
y2="23.107418"
|
||||
x2="43.368347"
|
||||
y1="23.107418"
|
||||
x1="3.1239223"
|
||||
gradientTransform="matrix(0.41985094,0,0,0.40591379,6.0174081,1011.2953)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient4233"
|
||||
xlink:href="#linearGradient3882-9-7"
|
||||
inkscape:collect="always" />
|
||||
<linearGradient
|
||||
y2="1.6471285"
|
||||
x2="54.278095"
|
||||
y1="1.6290494"
|
||||
x1="1.1793786"
|
||||
gradientTransform="matrix(0,1.3078889,-13.828188,0,24.662586,1004.1286)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient3911-3"
|
||||
xlink:href="#linearGradient3882-4-3"
|
||||
inkscape:collect="always" />
|
||||
<linearGradient
|
||||
id="linearGradient3882-4-3">
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0.990991;"
|
||||
offset="0"
|
||||
id="stop3884-5-4" />
|
||||
<stop
|
||||
style="stop-color:#ffffff;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3886-0-4" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
y2="1.6471285"
|
||||
x2="54.278095"
|
||||
y1="1.6290494"
|
||||
x1="1.1793786"
|
||||
gradientTransform="matrix(1.3078889,0,0,13.828188,0.00970002,985.836)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient4273"
|
||||
xlink:href="#linearGradient3882-4-3"
|
||||
inkscape:collect="always" />
|
||||
<radialGradient
|
||||
r="18.310251"
|
||||
fy="1.6290494"
|
||||
fx="19.489632"
|
||||
cy="1.6290494"
|
||||
cx="19.489632"
|
||||
gradientTransform="matrix(-1.2407681,0,0,-0.31619723,48.136043,1051.104)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="radialGradient4012-5"
|
||||
xlink:href="#linearGradient3874-9-2-6"
|
||||
inkscape:collect="always" />
|
||||
<linearGradient
|
||||
id="linearGradient3874-9-2-6">
|
||||
<stop
|
||||
style="stop-color:#585c58;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop3876-5-0-6" />
|
||||
<stop
|
||||
style="stop-color:#020802;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop3878-3-9-0" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
y2="1.6290494"
|
||||
x2="37.799885"
|
||||
y1="1.6290494"
|
||||
x1="1.1793786"
|
||||
gradientTransform="matrix(-1.2407681,0,0,-11.579301,48.136043,1069.4525)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient4014-7"
|
||||
xlink:href="#linearGradient3874-9-2-6"
|
||||
inkscape:collect="always" />
|
||||
<radialGradient
|
||||
r="18.310251"
|
||||
fy="1.6290494"
|
||||
fx="19.489632"
|
||||
cy="1.6290494"
|
||||
cx="19.489632"
|
||||
gradientTransform="matrix(0,-1.2407681,0.31619723,0,43.736,1054.6693)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="radialGradient4314"
|
||||
xlink:href="#linearGradient3874-9-2-6"
|
||||
inkscape:collect="always" />
|
||||
<linearGradient
|
||||
y2="1.6290494"
|
||||
x2="37.799885"
|
||||
y1="1.6290494"
|
||||
x1="1.1793786"
|
||||
gradientTransform="matrix(0,-1.2407681,11.579301,0,25.3875,1054.6693)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient4316"
|
||||
xlink:href="#linearGradient3874-9-2-6"
|
||||
inkscape:collect="always" />
|
||||
</defs>
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="4"
|
||||
inkscape:cx="-120.90068"
|
||||
inkscape:cy="30.911591"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
inkscape:window-width="1823"
|
||||
inkscape:window-height="960"
|
||||
inkscape:window-x="21"
|
||||
inkscape:window-y="51"
|
||||
inkscape:window-maximized="0" />
|
||||
<metadata
|
||||
id="metadata7">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title />
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(0,-1006.3622)">
|
||||
<rect
|
||||
style="opacity:1;fill:url(#linearGradient3840);fill-opacity:1.0;fill-rule:nonzero;stroke:none"
|
||||
id="rect3012"
|
||||
width="46.07806"
|
||||
height="46.276295"
|
||||
x="-0.0062815552"
|
||||
y="1006.269"
|
||||
ry="0" />
|
||||
<path
|
||||
style="fill:#5a5a5a;fill-opacity:0.68965518;stroke:none;filter:url(#filter3868)"
|
||||
d="m 45.078342,1030.2651 c 0.08214,21.1277 -20.329605,21.1277 -20.329605,21.1277 l 20.329605,0.085 z"
|
||||
id="path3842"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="opacity:0.87000002;fill:#f3fbf3;fill-opacity:1;stroke:none;filter:url(#filter3864)"
|
||||
d="m 0.88388348,1028.9393 c 0.13205222,-21.4764 22.00869852,-21.39 22.00869852,-21.39 l -21.8326289,0.043 z"
|
||||
id="path3856"
|
||||
inkscape:connector-curvature="0"
|
||||
transform="matrix(1.3520034,0,0,1.3188183,0.09478141,-320.94831)" />
|
||||
<path
|
||||
style="fill:none;stroke:url(#linearGradient3911);stroke-width:4.25273228px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 2.1364854,1006.3251 0,46.5877 0,0"
|
||||
id="path3872-9"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:url(#radialGradient4012);fill-opacity:1.0;stroke:url(#linearGradient4014);stroke-width:3.79041242999999990px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 46.052323,1050.59 -44.196697,0 0,0"
|
||||
id="path3872-8-4"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;stroke:url(#linearGradient4101);stroke-width:3.38799999999999990;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none;filter:url(#filter4200)"
|
||||
d="m 3.5176872,1010.3599 31.2367808,30.4413"
|
||||
id="path4093"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;stroke:url(#linearGradient4152);stroke-width:2.58800006;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;filter:url(#filter4212)"
|
||||
d="M 22.918929,1006.9127 54.15571,1037.354"
|
||||
id="path4093-7"
|
||||
inkscape:connector-curvature="0"
|
||||
transform="matrix(0.54033855,0,0,0.55433098,14.620528,450.49504)" />
|
||||
<path
|
||||
style="opacity:0.80936453;fill:none;stroke:url(#linearGradient4152-2);stroke-width:1.64702344;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;filter:url(#filter4188)"
|
||||
d="m 1.6307328,1033.6195 14.9465342,15.0349"
|
||||
id="path4093-1"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;stroke:url(#linearGradient4233);stroke-width:0.78001046;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
|
||||
d="M 7.5389154,1012.7459 24.015725,1028.604"
|
||||
id="path4093-74"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;stroke:url(#linearGradient4273);stroke-width:4.25273228px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 2.20615,1008.3621 46.5877,0 0,0"
|
||||
id="path3872-9-7"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:url(#radialGradient4314);fill-opacity:1;stroke:url(#linearGradient4316);stroke-width:3.79041243px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 44.25,1052.5855 0,-44.1966 0,0"
|
||||
id="path3872-8-4-9"
|
||||
inkscape:connector-curvature="0" />
|
||||
<rect
|
||||
style="opacity:0.35785953;fill:none;stroke:#000000;stroke-opacity:1"
|
||||
id="rect4345"
|
||||
width="45.75"
|
||||
height="46"
|
||||
x="0.25"
|
||||
y="0.12499996"
|
||||
transform="translate(0,1006.3622)"
|
||||
ry="0.17677669" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 23 KiB |
@ -0,0 +1,67 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.blocksgame.util;
|
||||
|
||||
import jsweet.dom.CanvasRenderingContext2D;
|
||||
|
||||
public abstract class AnimatedElement {
|
||||
|
||||
public boolean invalidated;
|
||||
private int animationStepCount = 0;
|
||||
private int remainingAnimationSteps = -1;
|
||||
|
||||
public boolean isVisible() {
|
||||
return true;
|
||||
};
|
||||
|
||||
public void setVisible(boolean visible) {
|
||||
};
|
||||
|
||||
public int getAnimationStep() {
|
||||
return this.animationStepCount - this.remainingAnimationSteps;
|
||||
}
|
||||
|
||||
public void nextAnimationStep() {
|
||||
this.remainingAnimationSteps--;
|
||||
this.invalidated = this.remainingAnimationSteps >= 0;
|
||||
}
|
||||
|
||||
public double getRemainingAnimationSteps() {
|
||||
return this.remainingAnimationSteps;
|
||||
}
|
||||
|
||||
public double getAnimationStepCount() {
|
||||
return this.animationStepCount;
|
||||
}
|
||||
|
||||
public void initAnimation(int stepCount) {
|
||||
this.animationStepCount = stepCount;
|
||||
this.remainingAnimationSteps = stepCount - 1;
|
||||
this.invalidated = true;
|
||||
}
|
||||
|
||||
public void stopAnimation() {
|
||||
this.remainingAnimationSteps = -1;
|
||||
this.invalidated = true;
|
||||
}
|
||||
|
||||
public void renderAnimation(CanvasRenderingContext2D animationCxt, CanvasRenderingContext2D areaCxt) {
|
||||
}
|
||||
|
||||
public boolean isAnimating() {
|
||||
return this.remainingAnimationSteps >= 0;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.blocksgame.util;
|
||||
|
||||
import jsweet.lang.Math;
|
||||
|
||||
public class Collisions {
|
||||
|
||||
// see http://williamecraver.wix.com/elastic-equations
|
||||
public static void sphericCollision(MobileElement refMobile, MobileElement targetMobile) {
|
||||
double th1 = refMobile.speedVector.angle();
|
||||
double th2 = targetMobile.speedVector.angle();
|
||||
double v1 = refMobile.speedVector.length();
|
||||
double v2 = targetMobile.speedVector.length();
|
||||
double m1 = refMobile.weight;
|
||||
double m2 = targetMobile.weight;
|
||||
|
||||
Vector r_per = targetMobile.getPosition().to(refMobile.getPosition());
|
||||
double phi = r_per.angle();
|
||||
|
||||
double a2 = (v2 * Math.cos(th2 - phi) * (m2 - m1) + 2 * m1 * v1 * Math.cos(th1 - phi)) / (m1 + m2);
|
||||
double b2 = v2 * Math.sin(th2 - phi);
|
||||
|
||||
targetMobile.speedVector.x = a2 * Math.cos(phi) + b2 * Math.cos(phi + Math.PI / 2);
|
||||
targetMobile.speedVector.y = a2 * Math.sin(phi) + b2 * Math.sin(phi + Math.PI / 2);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.blocksgame.util;
|
||||
|
||||
import jsweet.lang.Math;
|
||||
|
||||
public class Direction {
|
||||
|
||||
public final static double SQRT1_2 = Math.sqrt(1 / 2);
|
||||
|
||||
public static Direction NONE = new Direction(0, 0, new Vector(0, 0));
|
||||
public static Direction WEST = new Direction(-1, 0, new Vector(-1, 0));
|
||||
public static Direction EAST = new Direction(1, 0, new Vector(1, 0));
|
||||
public static Direction NORTH = new Direction(0, -1, new Vector(0, -1));
|
||||
public static Direction SOUTH = new Direction(0, 1, new Vector(0, 1));
|
||||
public static Direction NORTH_WEST = new Direction(-1, -1, new Vector(-Direction.SQRT1_2, -Direction.SQRT1_2));
|
||||
public static Direction NORTH_EAST = new Direction(1, -1, new Vector(Direction.SQRT1_2, -Direction.SQRT1_2));
|
||||
public static Direction SOUTH_WEST = new Direction(-1, 1, new Vector(-Direction.SQRT1_2, Direction.SQRT1_2));
|
||||
public static Direction SOUTH_EAST = new Direction(1, 1, new Vector(Direction.SQRT1_2, Direction.SQRT1_2));
|
||||
|
||||
public static Direction NORTH_NORTH_WEST = new Direction(-1, -2, new Vector(-Math.cos(Math.PI / 3), -Math.sin(Math.PI / 3)));
|
||||
public static Direction NORTH_NORTH_EAST = new Direction(1, -2, new Vector(Math.cos(Math.PI / 3), -Math.sin(Math.PI / 3)));
|
||||
public static Direction SOUTH_SOUTH_WEST = new Direction(-1, 2, new Vector(-Math.cos(Math.PI / 3), Math.sin(Math.PI / 3)));
|
||||
public static Direction SOUTH_SOUTH_EAST = new Direction(1, 2, new Vector(Math.cos(Math.PI / 3), Math.sin(Math.PI / 3)));
|
||||
public static Direction[] straightDirections = { Direction.EAST, Direction.NORTH, Direction.WEST, Direction.SOUTH };
|
||||
public static Direction[] oblicDirections = { Direction.NORTH_EAST, Direction.NORTH_WEST, Direction.SOUTH_WEST, Direction.SOUTH_EAST };
|
||||
|
||||
public double x;
|
||||
public double y;
|
||||
public Vector normalized;
|
||||
|
||||
public Direction(double x, double y, Vector normalized) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.normalized = normalized;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "direction(" + this.x + "," + this.y + ")(" + this.normalized.x + "," + this.normalized.y + ")";
|
||||
}
|
||||
|
||||
public boolean isStraight() {
|
||||
return !(this.x != 0 && this.y != 0);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,94 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.blocksgame.util;
|
||||
|
||||
import jsweet.lang.Error;
|
||||
|
||||
public class Line {
|
||||
|
||||
private double slope = 0;
|
||||
private double yIntercept;
|
||||
private double x;
|
||||
private boolean vertical;
|
||||
|
||||
public Line(Point p1, Point p2) {
|
||||
this.setPoints(p1, p2);
|
||||
}
|
||||
|
||||
public void setPoints(Point p1, Point p2) {
|
||||
if (p1.x == p2.x) {
|
||||
this.x = p1.x;
|
||||
this.vertical = true;
|
||||
} else {
|
||||
this.slope = (p2.y - p1.y) / (p2.x - p1.x);
|
||||
this.yIntercept = p1.y - this.slope * p1.x;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isVertical() {
|
||||
return this.vertical;
|
||||
}
|
||||
|
||||
public boolean isHorizontal() {
|
||||
return this.slope == 0;
|
||||
}
|
||||
|
||||
public double getSlope() {
|
||||
return this.slope;
|
||||
}
|
||||
|
||||
public double getYIntercept() {
|
||||
return this.yIntercept;
|
||||
}
|
||||
|
||||
public double getY(double x) {
|
||||
if (this.vertical) {
|
||||
throw new Error("invalid query on vertical lines");
|
||||
} else {
|
||||
return this.slope * x + this.yIntercept;
|
||||
}
|
||||
}
|
||||
|
||||
public Point getPointForX(double x) {
|
||||
return new Point(x, this.getY(x));
|
||||
}
|
||||
|
||||
public Point getPointForY(double y) {
|
||||
return new Point(this.getX(y), y);
|
||||
}
|
||||
|
||||
public double getX(double y) {
|
||||
if (this.slope == 0) {
|
||||
throw new Error("invalid query on horizonal lines");
|
||||
} else if (this.vertical) {
|
||||
return this.x;
|
||||
} else {
|
||||
return (y - this.yIntercept) / this.slope;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be called only when equation of the form x = a (vertical line) or
|
||||
* when the line is a point.
|
||||
*/
|
||||
public double getXWhenVertical() {
|
||||
if (this.vertical) {
|
||||
return this.x;
|
||||
} else {
|
||||
throw new Error("invalid query on non-vertical lines");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.blocksgame.util;
|
||||
|
||||
|
||||
public class MobileElement extends AnimatedElement {
|
||||
|
||||
public Point position;
|
||||
public double weight;
|
||||
public Vector speedVector = new Vector(0, 0);
|
||||
public double width = 0;
|
||||
public double height = 0;
|
||||
|
||||
public MobileElement(Point position, double weight, double width, double height) {
|
||||
this.position = position;
|
||||
this.weight = weight;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public void moveTo(double x, double y) {
|
||||
this.position.x = x;
|
||||
this.position.y = y;
|
||||
}
|
||||
|
||||
public void move(double dx, double dy) {
|
||||
this.position.x += dx;
|
||||
this.position.y += dy;
|
||||
}
|
||||
|
||||
public Point getPosition() {
|
||||
return this.position;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "mobile(" + this.position + ";" + this.speedVector + ")";
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.blocksgame.util;
|
||||
|
||||
import jsweet.lang.Math;
|
||||
|
||||
public class Point {
|
||||
public double x;
|
||||
public double y;
|
||||
|
||||
public Point(double x, double y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public Point add(double x, double y) {
|
||||
this.x += x;
|
||||
this.y += y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Point times(double factor) {
|
||||
this.x *= factor;
|
||||
this.y *= factor;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Point clone() {
|
||||
return new Point(this.x, this.y);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "POINT(" + this.x + "," + this.y + ")";
|
||||
}
|
||||
|
||||
public double distance(Point point) {
|
||||
return Math.sqrt((this.x - point.x) * (this.x - point.x) + (this.y - point.y) * (this.y - point.y));
|
||||
}
|
||||
|
||||
public boolean equals(Point point) {
|
||||
return this.x == point.x && this.y == point.y;
|
||||
}
|
||||
|
||||
public Vector to(Point endPoint) {
|
||||
return new Vector(endPoint.x - this.x, endPoint.y - this.y);
|
||||
}
|
||||
|
||||
public Vector toCoords(double endX, double endY) {
|
||||
return new Vector(endX - this.x, endY - this.y);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,73 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.blocksgame.util;
|
||||
|
||||
import jsweet.lang.Math;
|
||||
|
||||
public class Rectangle {
|
||||
|
||||
public double x1;
|
||||
public double y1;
|
||||
|
||||
public double x2;
|
||||
public double y2;
|
||||
|
||||
public Rectangle(double x, double y, double width, double height) {
|
||||
super();
|
||||
this.x1 = x;
|
||||
this.y1 = y;
|
||||
this.x2 = x + width;
|
||||
this.y2 = y + height;
|
||||
}
|
||||
|
||||
public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
|
||||
return new Rectangle(Math.min(x1, x2), Math.min(y1, y2), Math.max(x1, x2), Math.max(y1, y2));
|
||||
}
|
||||
|
||||
public Rectangle union(Rectangle rectangle) {
|
||||
return Rectangle.rectangle(Math.min(this.x1, rectangle.x1), Math.min(this.y1, rectangle.y1), Math.max(this.x2, rectangle.x2),
|
||||
Math.max(this.y2, rectangle.y2));
|
||||
}
|
||||
|
||||
public boolean intersects(Rectangle rectangle) {
|
||||
return ((this.x1 <= rectangle.x2) && (rectangle.x1 <= this.x2) && (this.y1 <= rectangle.y2) && (rectangle.y1 <= this.y2));
|
||||
}
|
||||
|
||||
public Rectangle discrete(double unit) {
|
||||
this.x1 = Math.floor(this.x1 / unit);
|
||||
this.y1 = Math.floor(this.y1 / unit);
|
||||
this.x2 = Math.floor(this.x2 / unit);
|
||||
this.y2 = Math.floor(this.y2 / unit);
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean contains(Point point) {
|
||||
return this.x1 <= point.x && this.x2 >= point.x && this.y1 <= point.y && this.y2 >= point.y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RECT[" + x1 + "," + y1 + "," + x2 + "," + y2 + "]";
|
||||
}
|
||||
|
||||
public double getWidth() {
|
||||
return x2 - x1;
|
||||
}
|
||||
|
||||
public double getHeight() {
|
||||
return y2 - y1;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,113 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.blocksgame.util;
|
||||
|
||||
import jsweet.lang.Math;
|
||||
|
||||
public class Vector {
|
||||
|
||||
public double x;
|
||||
public double y;
|
||||
|
||||
public Vector(double x, double y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public static Vector fromPolar(double radius, double angle) {
|
||||
return new Vector(Math.cos(angle) * radius, Math.sin(angle) * radius);
|
||||
}
|
||||
|
||||
public static Vector toDiscreteDirection(Vector vector) {
|
||||
double x, y;
|
||||
if (vector.x > 0) {
|
||||
x = 1;
|
||||
} else if (vector.x < 0) {
|
||||
x = -1;
|
||||
} else {
|
||||
x = 0;
|
||||
}
|
||||
if (vector.y > 0) {
|
||||
y = 1;
|
||||
} else if (vector.y < 0) {
|
||||
y = -1;
|
||||
} else {
|
||||
y = 0;
|
||||
}
|
||||
return new Vector(x, y);
|
||||
}
|
||||
|
||||
public Vector clone() {
|
||||
return new Vector(this.x, this.y);
|
||||
}
|
||||
|
||||
public Vector add(Vector vector) {
|
||||
this.x += vector.x;
|
||||
this.y += vector.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector applyBounce(Vector hitObjectDirection) {
|
||||
this.x *= hitObjectDirection.x == 0 ? 1 : -1;
|
||||
this.y *= hitObjectDirection.y == 0 ? 1 : -1;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector times(double factor) {
|
||||
this.x *= factor;
|
||||
this.y *= factor;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector invert() {
|
||||
this.x *= -1;
|
||||
this.y *= -1;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector abs() {
|
||||
this.x = Math.abs(this.x);
|
||||
this.y = Math.abs(this.y);
|
||||
return this;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "vector(" + this.x + "," + this.y + ")";
|
||||
}
|
||||
|
||||
public boolean equals(Vector vector) {
|
||||
return this.x == vector.x && this.y == vector.y;
|
||||
}
|
||||
|
||||
public double length() {
|
||||
return Math.sqrt(this.x * this.x + this.y * this.y);
|
||||
}
|
||||
|
||||
public Vector normalize() {
|
||||
double l = this.length();
|
||||
this.x /= l;
|
||||
this.y /= l;
|
||||
return this;
|
||||
}
|
||||
|
||||
public double dotProduct(Vector vector) {
|
||||
return this.x * vector.x + this.y * vector.y;
|
||||
}
|
||||
|
||||
public double angle() {
|
||||
return Math.atan2(this.y, this.x);
|
||||
}
|
||||
|
||||
}
|
||||
60
test/org/jsweet/test/transpiler/source/candies/Angular.java
Normal file
60
test/org/jsweet/test/transpiler/source/candies/Angular.java
Normal file
@ -0,0 +1,60 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.candies;
|
||||
|
||||
import static def.angularjs.Globals.angular;
|
||||
import static jsweet.util.Globals.array;
|
||||
import static jsweet.util.Globals.union;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import def.angularjs.ng.route.IRoute;
|
||||
import def.angularjs.ng.route.IRouteProvider;
|
||||
import jsweet.lang.Array;
|
||||
|
||||
public class Angular {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Array<String> modules = new Array<>("app.controllers", "app.directives", "app.filters", "app.services", "Model");
|
||||
modules.forEach(module -> angular.module(module, new String[0]));
|
||||
modules.push("ngRoute");
|
||||
modules.push("ngAnimate");
|
||||
modules.push("ngMaterial");
|
||||
modules.push("socket-io");
|
||||
|
||||
angular.module("app", array(modules));
|
||||
|
||||
// ROUTING
|
||||
angular.module("app").config(new Object[] { "$routeProvider", (Consumer<IRouteProvider>) (IRouteProvider $routeProvider) -> {
|
||||
$routeProvider.when("/", new IRoute() {
|
||||
{
|
||||
templateUrl = union("../views/login.html");
|
||||
controller = union("app.controllers.LoginController as ctrl");
|
||||
}
|
||||
}).when("/chatroom", new IRoute() {
|
||||
{
|
||||
templateUrl = union("../views/chatroom.html");
|
||||
controller = union("app.controllers.ChatController as ctrl");
|
||||
}
|
||||
}).otherwise(new IRoute() {
|
||||
{
|
||||
redirectTo = union("/");
|
||||
}
|
||||
});
|
||||
} });
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.candies;
|
||||
|
||||
import static def.body_parser.body_parser.Globals.json;
|
||||
import static def.body_parser.body_parser.Globals.urlencoded;
|
||||
import static def.express.Globals.express;
|
||||
import static def.express.express.Globals.Static;
|
||||
import static def.node.Globals.__dirname;
|
||||
import static jsweet.util.Globals.string;
|
||||
|
||||
import def.body_parser.body_parser.OptionsDto;
|
||||
import def.express.express.Express;
|
||||
import def.express.express.RequestHandler;
|
||||
|
||||
public class ExpressLib {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Express app = express();
|
||||
|
||||
// Configuration
|
||||
app.set("views", __dirname);
|
||||
app.set("view engine", "jade");
|
||||
app.use(urlencoded(new OptionsDto() {
|
||||
{
|
||||
extended = true;
|
||||
}
|
||||
}));
|
||||
app.use(json());
|
||||
app.use("/", // the URL throught which you want to access to you static
|
||||
// content
|
||||
(RequestHandler) Static(string(__dirname)) // where your static
|
||||
// content is
|
||||
// located
|
||||
// in your filesystem
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.candies;
|
||||
|
||||
import static def.body_parser.body_parser.Globals.json;
|
||||
import static def.body_parser.body_parser.Globals.urlencoded;
|
||||
import static def.express.Globals.express;
|
||||
import static def.serve_static.Globals.serve_static;
|
||||
import static def.socket_io.Globals.socket_io;
|
||||
import static def.errorhandler.Globals.errorhandler;
|
||||
import static def.jquery.Globals.$;
|
||||
|
||||
import def.body_parser.body_parser.OptionsDto;
|
||||
import def.errorhandler.Options;
|
||||
import def.express.express.Express;
|
||||
import def.express.express.RequestHandler;
|
||||
import def.node.http.Server;
|
||||
|
||||
public class GlobalsImport {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Express app = express();
|
||||
|
||||
RequestHandler h = json();
|
||||
|
||||
urlencoded(new OptionsDto() {
|
||||
{
|
||||
extended = true;
|
||||
}
|
||||
});
|
||||
|
||||
serve_static("test");
|
||||
|
||||
Server server = null;
|
||||
|
||||
errorhandler(new Options() {
|
||||
{
|
||||
log = true;
|
||||
}
|
||||
});
|
||||
|
||||
socket_io();
|
||||
|
||||
$("test").addClass("test");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
25
test/org/jsweet/test/transpiler/source/candies/JQuery.java
Normal file
25
test/org/jsweet/test/transpiler/source/candies/JQuery.java
Normal file
@ -0,0 +1,25 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.candies;
|
||||
|
||||
import static def.jquery.Globals.$;
|
||||
|
||||
public class JQuery {
|
||||
|
||||
public static void main(String[] args) {
|
||||
$("p").append(" (end)");
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.candies;
|
||||
|
||||
import static def.socket_io.Globals.socket_io;
|
||||
|
||||
public class QualifiedNames {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
def.socket_io.socketio.Server ioServer = socket_io();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.generics;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class InstantiationWithGenerics<T, V> {
|
||||
|
||||
T t;
|
||||
private V value;
|
||||
|
||||
public InstantiationWithGenerics(T input, V value) {
|
||||
this.t = input;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
InstantiationWithGenerics<String, Integer> foo = new InstantiationWithGenerics<String, Integer>("lolo", 4);
|
||||
org.jsweet.test.transpiler.source.generics.InstantiationWithGenerics<String, Integer> bar
|
||||
= new org.jsweet.test.transpiler.source.generics.InstantiationWithGenerics<String, Integer>("lolo", 4);
|
||||
C<String> c = new C<String>();
|
||||
}
|
||||
}
|
||||
|
||||
class C<T> {
|
||||
}
|
||||
31
test/org/jsweet/test/transpiler/source/init/Constructor.java
Normal file
31
test/org/jsweet/test/transpiler/source/init/Constructor.java
Normal file
@ -0,0 +1,31 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.init;
|
||||
|
||||
public class Constructor {
|
||||
|
||||
String s;
|
||||
|
||||
public Constructor(String s) {
|
||||
this.s = s;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
@SuppressWarnings("unused")
|
||||
Constructor c = new Constructor("abc");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.init;
|
||||
|
||||
public class ConstructorField {
|
||||
|
||||
String s;
|
||||
|
||||
public ConstructorField(String s) {
|
||||
this.s = s;
|
||||
}
|
||||
|
||||
int constructor;
|
||||
|
||||
public static void main(String[] args) {
|
||||
ConstructorField c = new ConstructorField("abc");
|
||||
@SuppressWarnings("unused")
|
||||
int i = c.constructor;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.init;
|
||||
|
||||
import jsweet.lang.Interface;
|
||||
|
||||
@Interface
|
||||
abstract public class ConstructorFieldInInterface {
|
||||
|
||||
int constructor;
|
||||
|
||||
}
|
||||
|
||||
class Main {
|
||||
public static void main(String[] args) {
|
||||
@SuppressWarnings("unused")
|
||||
ConstructorFieldInInterface c = new ConstructorFieldInInterface() {
|
||||
{
|
||||
constructor = 1;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.init;
|
||||
|
||||
public class ConstructorMethod {
|
||||
|
||||
String s;
|
||||
|
||||
public ConstructorMethod(String s) {
|
||||
this.s = s;
|
||||
}
|
||||
|
||||
void constructor(String s) {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
ConstructorMethod c = new ConstructorMethod("abc");
|
||||
c.constructor("abc");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.init;
|
||||
|
||||
import jsweet.lang.Interface;
|
||||
|
||||
@Interface
|
||||
abstract public class ConstructorMethodInInterface {
|
||||
|
||||
abstract int constructor();
|
||||
|
||||
}
|
||||
|
||||
31
test/org/jsweet/test/transpiler/source/init/Initializer.java
Normal file
31
test/org/jsweet/test/transpiler/source/init/Initializer.java
Normal file
@ -0,0 +1,31 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.init;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
|
||||
public class Initializer {
|
||||
|
||||
int n;
|
||||
|
||||
{
|
||||
n = 4;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
$export("out", new Initializer().n);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.init;
|
||||
|
||||
import jsweet.lang.Interface;
|
||||
|
||||
public class InitializerStatementConditionError {
|
||||
|
||||
private final static boolean SWITCH = true;
|
||||
|
||||
DataStruct5 d = new DataStruct5() {
|
||||
{
|
||||
s = "test";
|
||||
s2 = "turlututu";
|
||||
if (SWITCH) {
|
||||
s2 = "taratata";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@Interface
|
||||
abstract class DataStruct5 {
|
||||
public String s;
|
||||
public String s2;
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.init;
|
||||
|
||||
import jsweet.lang.Interface;
|
||||
|
||||
public class InitializerStatementError {
|
||||
|
||||
DataStruct4 d = new DataStruct4() {
|
||||
{
|
||||
s = "test";
|
||||
new DataStruct4() {
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@Interface
|
||||
abstract class DataStruct4 {
|
||||
public String s;
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.init;
|
||||
|
||||
import jsweet.lang.Interface;
|
||||
|
||||
public class InterfaceRawConstruction extends jsweet.lang.Object {
|
||||
|
||||
DataStruct6 d2 = new DataStruct6() {
|
||||
};
|
||||
|
||||
DataStruct6 d3 = new DataStruct6() {
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@Interface
|
||||
abstract class DataStruct6 {
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.init;
|
||||
|
||||
import jsweet.lang.Disabled;
|
||||
import static jsweet.util.Globals.$export;
|
||||
|
||||
public class MultipleMains {
|
||||
public static int counter = 0;
|
||||
|
||||
public static void main(String[] args) {
|
||||
$export("a", MultipleMains.counter++);
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
@Disabled
|
||||
public static void main(String[] args) {
|
||||
$export("b", MultipleMains.counter++);
|
||||
}
|
||||
}
|
||||
|
||||
class C {
|
||||
public static void main(String[] args) {
|
||||
$export("c", MultipleMains.counter++);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.init;
|
||||
|
||||
import jsweet.lang.Optional;
|
||||
|
||||
public class NoOptionalFieldsInClass extends jsweet.lang.Object {
|
||||
|
||||
DataStruct3 d = new DataStruct3() {
|
||||
{
|
||||
i = 1;
|
||||
s2 = "";
|
||||
$set("anyField", "anyValue");
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
class DataStruct3 {
|
||||
public String s;
|
||||
public String s2;
|
||||
@Optional
|
||||
public int i;
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.init;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
|
||||
public class StaticInitializer {
|
||||
|
||||
static int n;
|
||||
|
||||
static {
|
||||
n = 4;
|
||||
}
|
||||
|
||||
static String s;
|
||||
|
||||
static {
|
||||
s = "test";
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
$export("n", StaticInitializer.n);
|
||||
$export("s", StaticInitializer.s);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.overload;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
|
||||
public class Overload {
|
||||
|
||||
String m() {
|
||||
return this.m("default");
|
||||
}
|
||||
|
||||
String m(String s) {
|
||||
return this.m(s, 1);
|
||||
}
|
||||
|
||||
String m(String s, int i) {
|
||||
return s + i;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Overload o = new Overload();
|
||||
$export("res1", o.m());
|
||||
$export("res2", o.m("s1"));
|
||||
$export("res3", o.m("s2", 2));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.overload;
|
||||
|
||||
public class WrongOverload {
|
||||
|
||||
public WrongOverload() {
|
||||
draw();
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
}
|
||||
|
||||
public void draw(String s) {
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.overload;
|
||||
|
||||
public class WrongOverloads {
|
||||
|
||||
private void draw() {
|
||||
System.out.println("tutu");
|
||||
}
|
||||
|
||||
private void draw(String s) {
|
||||
}
|
||||
|
||||
int i;
|
||||
|
||||
String getter() {
|
||||
return "";
|
||||
}
|
||||
|
||||
void m() {
|
||||
// other statements are not allowed in overloading
|
||||
i = 0;
|
||||
this.m("");
|
||||
}
|
||||
|
||||
void m(String s) {
|
||||
// calling a method is wrong for overloading
|
||||
this.m(getter(), 1);
|
||||
}
|
||||
|
||||
// this method cannot overload the one with string
|
||||
void m(int i) {
|
||||
}
|
||||
|
||||
void m(String s, int i) {
|
||||
s = "";
|
||||
}
|
||||
|
||||
public WrongOverloads() {
|
||||
draw();
|
||||
draw("");
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.require;
|
||||
|
||||
import org.jsweet.test.transpiler.source.require.a.A;
|
||||
|
||||
public class TopLevel1 {
|
||||
|
||||
A a;
|
||||
|
||||
public static void main(String[] args) {
|
||||
new A().m();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.require;
|
||||
|
||||
import org.jsweet.test.transpiler.source.require.a.A;
|
||||
|
||||
public class TopLevel2 {
|
||||
|
||||
A a;
|
||||
|
||||
}
|
||||
24
test/org/jsweet/test/transpiler/source/require/a/A.java
Normal file
24
test/org/jsweet/test/transpiler/source/require/a/A.java
Normal file
@ -0,0 +1,24 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.require.a;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
|
||||
public class A {
|
||||
|
||||
public void m() {
|
||||
$export("mInvoked", true);
|
||||
}
|
||||
}
|
||||
27
test/org/jsweet/test/transpiler/source/require/a/Use1.java
Normal file
27
test/org/jsweet/test/transpiler/source/require/a/Use1.java
Normal file
@ -0,0 +1,27 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.require.a;
|
||||
|
||||
import org.jsweet.test.transpiler.source.require.a.b.B1;
|
||||
|
||||
public class Use1 {
|
||||
|
||||
B1 b1;
|
||||
|
||||
public static void main(String[] args) {
|
||||
new B1().m();
|
||||
}
|
||||
|
||||
}
|
||||
23
test/org/jsweet/test/transpiler/source/require/a/Use2.java
Normal file
23
test/org/jsweet/test/transpiler/source/require/a/Use2.java
Normal file
@ -0,0 +1,23 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.require.a;
|
||||
|
||||
import org.jsweet.test.transpiler.source.require.a.b.B1;
|
||||
|
||||
public class Use2 {
|
||||
|
||||
B1 b1;
|
||||
|
||||
}
|
||||
25
test/org/jsweet/test/transpiler/source/require/a/b/B1.java
Normal file
25
test/org/jsweet/test/transpiler/source/require/a/b/B1.java
Normal file
@ -0,0 +1,25 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.require.a.b;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
|
||||
public class B1 {
|
||||
|
||||
public void m() {
|
||||
$export("mInvokedOnB1", true);
|
||||
}
|
||||
|
||||
}
|
||||
25
test/org/jsweet/test/transpiler/source/require/a/b/B2.java
Normal file
25
test/org/jsweet/test/transpiler/source/require/a/b/B2.java
Normal file
@ -0,0 +1,25 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.require.a.b;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
|
||||
public class B2 {
|
||||
|
||||
public void m() {
|
||||
$export("mInvokedOnB2", true);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.require.b;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
|
||||
import org.jsweet.test.transpiler.source.require.a.A;
|
||||
|
||||
public class ClassImport {
|
||||
|
||||
public static void main(String[] args) {
|
||||
$export("mainInvoked", true);
|
||||
A a = new A();
|
||||
a.m();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.require.b;
|
||||
|
||||
import static def.express.Globals.express;
|
||||
import static jsweet.util.Globals.$export;
|
||||
|
||||
import org.jsweet.test.transpiler.source.require.a.A;
|
||||
import org.jsweet.test.transpiler.source.require.a.b.B1;
|
||||
import org.jsweet.test.transpiler.source.require.a.b.B2;
|
||||
|
||||
import def.express.express.Express;
|
||||
|
||||
public class ClassImportImplicitRequire {
|
||||
|
||||
public static void main(String[] args) {
|
||||
$export("mainInvoked", true);
|
||||
|
||||
Express app = express();
|
||||
|
||||
A a = new A();
|
||||
a.m();
|
||||
B1 b1 = new B1();
|
||||
b1.m();
|
||||
B2 b2 = new B2();
|
||||
b2.m();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.require.b;
|
||||
|
||||
import static jsweet.dom.Globals.console;
|
||||
import static org.jsweet.test.transpiler.source.require.globals.Globals.animate;
|
||||
|
||||
import org.jsweet.test.transpiler.source.require.globals.Globals;
|
||||
|
||||
public class GlobalsImport {
|
||||
|
||||
public static void main(String[] args) {
|
||||
animate();
|
||||
Globals.testGlobal();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.require.globals;
|
||||
|
||||
import static jsweet.dom.Globals.window;
|
||||
|
||||
import jsweet.dom.Event;
|
||||
import jsweet.lang.Date;
|
||||
|
||||
public class Globals {
|
||||
|
||||
public static void animate() {
|
||||
}
|
||||
|
||||
public static Object start(Event event) {
|
||||
return event;
|
||||
}
|
||||
|
||||
static {
|
||||
window.onload = Globals::start;
|
||||
}
|
||||
|
||||
public static void testGlobal() {
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@jsweet.lang.Root
|
||||
package org.jsweet.test.transpiler.source.require;
|
||||
@ -0,0 +1,34 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.structural;
|
||||
|
||||
|
||||
public abstract class AbstractClass {
|
||||
|
||||
abstract void m1();
|
||||
|
||||
abstract int m2();
|
||||
|
||||
abstract Object m3();
|
||||
|
||||
abstract String m4();
|
||||
|
||||
abstract boolean m5();
|
||||
|
||||
String regularMethod() {
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.structural;
|
||||
|
||||
public class AutoImportClassesInSamePackage {
|
||||
|
||||
public void m() {
|
||||
AutoImportClassesInSamePackageUsed c = new AutoImportClassesInSamePackageUsed();
|
||||
c.m1();
|
||||
c.m2();
|
||||
AutoImportClassesInSamePackageUsed.sm1();
|
||||
AutoImportClassesInSamePackageUsed.sm2();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new AutoImportClassesInSamePackage().m();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.structural;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
|
||||
public class AutoImportClassesInSamePackageUsed {
|
||||
|
||||
public void m1() {
|
||||
$export("m1", true);
|
||||
}
|
||||
|
||||
void m2() {
|
||||
$export("m2", true);
|
||||
}
|
||||
|
||||
public static void sm1() {
|
||||
$export("sm1", true);
|
||||
}
|
||||
|
||||
static void sm2() {
|
||||
$export("sm2", true);
|
||||
}
|
||||
|
||||
}
|
||||
40
test/org/jsweet/test/transpiler/source/structural/Enums.java
Normal file
40
test/org/jsweet/test/transpiler/source/structural/Enums.java
Normal file
@ -0,0 +1,40 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.structural;
|
||||
|
||||
import static jsweet.util.Globals.array;
|
||||
import static jsweet.util.Globals.$export;
|
||||
|
||||
public class Enums {
|
||||
|
||||
public static void main(String[] args) {
|
||||
MyEnum e = MyEnum.A;
|
||||
$export("value", e);
|
||||
$export("nameOfA", e.name());
|
||||
$export("ordinalOfA", e.ordinal());
|
||||
$export("valueOfA", MyEnum.valueOf("A"));
|
||||
$export("valueOfC", array(MyEnum.values()).indexOf(MyEnum.valueOf("C")));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
enum MyEnum {
|
||||
A, B, C
|
||||
}
|
||||
|
||||
class C {
|
||||
public void m() {
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.structural;
|
||||
|
||||
class Foo1 {
|
||||
}
|
||||
|
||||
public class ExtendsClassInSameFile extends Foo1 {
|
||||
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.structural;
|
||||
|
||||
public class ExtendsObject extends Object {
|
||||
|
||||
public ExtendsObject() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ExtendObject2 extends jsweet.lang.Object {
|
||||
|
||||
public ExtendObject2() {
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.structural;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Globals.string;
|
||||
import static org.jsweet.test.transpiler.source.structural.Globals.toTitleCase;
|
||||
|
||||
import jsweet.lang.RegExp;
|
||||
|
||||
public class GlobalsAccess {
|
||||
|
||||
public static void main(String[] args) {
|
||||
$export("result", toTitleCase("renaud pawlak"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Globals {
|
||||
|
||||
public static String toTitleCase(String str) {
|
||||
return string(str.toLowerCase()).replace(new RegExp("\\w\\S*", "g"), (tok, i) -> {
|
||||
return string(tok).charAt(0).toUpperCase() + string(tok).substr(1).toLowerCase();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.structural;
|
||||
|
||||
import jsweet.lang.Interface;
|
||||
|
||||
class AloneInTheDarkClass extends jsweet.lang.Object {
|
||||
public AloneInTheDarkClass() {
|
||||
// super() call shouldn't be generated
|
||||
|
||||
int i = 5;
|
||||
}
|
||||
}
|
||||
|
||||
public class Inheritance extends SuperClass1 {
|
||||
public Inheritance() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
class SuperClass1 extends SuperInterface1 {
|
||||
public SuperClass1() {
|
||||
}
|
||||
}
|
||||
|
||||
@Interface
|
||||
abstract class SuperInterface1 {
|
||||
}
|
||||
|
||||
@Interface
|
||||
abstract class SubInterface extends SuperInterface1 {
|
||||
}
|
||||
|
||||
// TODO: this is weird... it works in Typescript... check what it means
|
||||
@Interface
|
||||
abstract class SubInterface1 extends SuperClass1 {
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.structural;
|
||||
|
||||
public class InnerClass {
|
||||
|
||||
public class InnerClass1 {
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.structural;
|
||||
|
||||
public class NameClashes {
|
||||
|
||||
public String a;
|
||||
|
||||
public void a() {
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.structural;
|
||||
|
||||
import jsweet.lang.Interface;
|
||||
|
||||
public class NoInstanceofForInterfaces {
|
||||
|
||||
void m(Object o) {
|
||||
if (o instanceof I1) {
|
||||
}
|
||||
if (o instanceof I2) {
|
||||
}
|
||||
if (o instanceof C3) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
interface I1 {
|
||||
|
||||
}
|
||||
|
||||
@Interface
|
||||
abstract class I2 {
|
||||
}
|
||||
|
||||
class C3 {
|
||||
}
|
||||
|
||||
@ -0,0 +1,35 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.structural;
|
||||
|
||||
import jsweet.lang.Interface;
|
||||
import jsweet.lang.Optional;
|
||||
|
||||
public class OptionalField {
|
||||
|
||||
DataStruct d = new DataStruct() {
|
||||
{
|
||||
s = "test";
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@Interface
|
||||
abstract class DataStruct {
|
||||
public String s;
|
||||
@Optional
|
||||
public int i;
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
/* Copyright 2015 CINCHEO SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jsweet.test.transpiler.source.structural;
|
||||
|
||||
import jsweet.lang.Interface;
|
||||
|
||||
public class OptionalFieldError {
|
||||
|
||||
DataStruct2 d = new DataStruct2() {
|
||||
{
|
||||
s = "test";
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@Interface
|
||||
abstract class DataStruct2 {
|
||||
public String s;
|
||||
public int i;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user