mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-03 05:44:10 -08:00
Rewrite with lambdas some more code
This commit is contained in:
parent
6f3d80ffe1
commit
c20209e651
|
@ -264,9 +264,9 @@ class TByteBufferImpl extends TByteBuffer {
|
||||||
int d = array[start + position + 3] & 0xFF;
|
int d = array[start + position + 3] & 0xFF;
|
||||||
position += 4;
|
position += 4;
|
||||||
if (order == TByteOrder.BIG_ENDIAN) {
|
if (order == TByteOrder.BIG_ENDIAN) {
|
||||||
return (int)((a << 24) | (b << 16) | (c << 8) | d);
|
return (a << 24) | (b << 16) | (c << 8) | d;
|
||||||
} else {
|
} else {
|
||||||
return (int)((d << 24) | (c << 16) | (b << 8) | a);
|
return (d << 24) | (c << 16) | (b << 8) | a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,9 +302,9 @@ class TByteBufferImpl extends TByteBuffer {
|
||||||
int c = array[start + index + 2] & 0xFF;
|
int c = array[start + index + 2] & 0xFF;
|
||||||
int d = array[start + index + 3] & 0xFF;
|
int d = array[start + index + 3] & 0xFF;
|
||||||
if (order == TByteOrder.BIG_ENDIAN) {
|
if (order == TByteOrder.BIG_ENDIAN) {
|
||||||
return (int)((a << 24) | (b << 16) | (c << 8) | d);
|
return (a << 24) | (b << 16) | (c << 8) | d;
|
||||||
} else {
|
} else {
|
||||||
return (int)((d << 24) | (c << 16) | (b << 8) | a);
|
return (d << 24) | (c << 16) | (b << 8) | a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,9 +355,9 @@ class TByteBufferImpl extends TByteBuffer {
|
||||||
long h = array[start + position + 7] & 0xFF;
|
long h = array[start + position + 7] & 0xFF;
|
||||||
position += 8;
|
position += 8;
|
||||||
if (order == TByteOrder.BIG_ENDIAN) {
|
if (order == TByteOrder.BIG_ENDIAN) {
|
||||||
return (long)((a << 56) | (b << 48) | (c << 40) | (d << 32) | (e << 24) | (f << 16) | (g << 8) | h);
|
return (a << 56) | (b << 48) | (c << 40) | (d << 32) | (e << 24) | (f << 16) | (g << 8) | h;
|
||||||
} else {
|
} else {
|
||||||
return (long)((h << 56) | (g << 48) | (f << 40) | (e << 32) | (d << 24) | (c << 16) | (b << 8) | a);
|
return (h << 56) | (g << 48) | (f << 40) | (e << 32) | (d << 24) | (c << 16) | (b << 8) | a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,9 +406,9 @@ class TByteBufferImpl extends TByteBuffer {
|
||||||
long h = array[start + index + 7] & 0xFF;
|
long h = array[start + index + 7] & 0xFF;
|
||||||
position += 8;
|
position += 8;
|
||||||
if (order == TByteOrder.BIG_ENDIAN) {
|
if (order == TByteOrder.BIG_ENDIAN) {
|
||||||
return (long)((a << 56) | (b << 48) | (c << 40) | (d << 32) | (e << 24) | (f << 16) | (g << 8) | h);
|
return (a << 56) | (b << 48) | (c << 40) | (d << 32) | (e << 24) | (f << 16) | (g << 8) | h;
|
||||||
} else {
|
} else {
|
||||||
return (long)((h << 56) | (g << 48) | (f << 40) | (e << 32) | (d << 24) | (c << 16) | (b << 8) | a);
|
return (h << 56) | (g << 48) | (f << 40) | (e << 32) | (d << 24) | (c << 16) | (b << 8) | a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -515,39 +515,31 @@ public final class JS {
|
||||||
JSObject c, JSObject d, JSObject e, JSObject f, JSObject g, JSObject h);
|
JSObject c, JSObject d, JSObject e, JSObject f, JSObject g, JSObject h);
|
||||||
|
|
||||||
public static <T extends JSObject> Iterable<T> iterate(final JSArrayReader<T> array) {
|
public static <T extends JSObject> Iterable<T> iterate(final JSArrayReader<T> array) {
|
||||||
return new Iterable<T>() {
|
return () -> new Iterator<T>() {
|
||||||
@Override public Iterator<T> iterator() {
|
int index;
|
||||||
return new Iterator<T>() {
|
@Override public boolean hasNext() {
|
||||||
int index;
|
return index < array.getLength();
|
||||||
@Override public boolean hasNext() {
|
}
|
||||||
return index < array.getLength();
|
@Override public T next() {
|
||||||
}
|
return array.get(index++);
|
||||||
@Override public T next() {
|
}
|
||||||
return array.get(index++);
|
@Override public void remove() {
|
||||||
}
|
throw new UnsupportedOperationException();
|
||||||
@Override public void remove() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Iterable<String> iterate(final JSStringArrayReader array) {
|
public static Iterable<String> iterate(final JSStringArrayReader array) {
|
||||||
return new Iterable<String>() {
|
return () -> new Iterator<String>() {
|
||||||
@Override public Iterator<String> iterator() {
|
int index;
|
||||||
return new Iterator<String>() {
|
@Override public boolean hasNext() {
|
||||||
int index;
|
return index < array.getLength();
|
||||||
@Override public boolean hasNext() {
|
}
|
||||||
return index < array.getLength();
|
@Override public String next() {
|
||||||
}
|
return array.get(index++);
|
||||||
@Override public String next() {
|
}
|
||||||
return array.get(index++);
|
@Override public void remove() {
|
||||||
}
|
throw new UnsupportedOperationException();
|
||||||
@Override public void remove() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,11 +166,7 @@ public class JSNativeGenerator implements Injector, DependencyPlugin, Generator
|
||||||
case "instantiate":
|
case "instantiate":
|
||||||
case "function":
|
case "function":
|
||||||
for (int i = 0; i < method.getReference().parameterCount(); ++i) {
|
for (int i = 0; i < method.getReference().parameterCount(); ++i) {
|
||||||
method.getVariable(i).addConsumer(new DependencyConsumer() {
|
method.getVariable(i).addConsumer(type -> achieveFunctorMethods(agent, type.getName(), method));
|
||||||
@Override public void consume(DependencyType type) {
|
|
||||||
achieveFunctorMethods(agent, type.getName(), method);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "unwrapString":
|
case "unwrapString":
|
||||||
|
|
|
@ -115,7 +115,7 @@ class JavascriptNativeProcessor {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Map<MethodDescriptor, MethodReference> methods = new HashMap<>();
|
Map<MethodDescriptor, MethodReference> methods = new HashMap<>();
|
||||||
getFunctorMethods(className, new HashSet<String>(), methods);
|
getFunctorMethods(className, new HashSet<>(), methods);
|
||||||
if (methods.size() == 1) {
|
if (methods.size() == 1) {
|
||||||
return methods.values().iterator().next();
|
return methods.values().iterator().next();
|
||||||
}
|
}
|
||||||
|
@ -267,7 +267,7 @@ class JavascriptNativeProcessor {
|
||||||
|
|
||||||
public void makeSync(ClassHolder cls) {
|
public void makeSync(ClassHolder cls) {
|
||||||
Set<MethodDescriptor> methods = new HashSet<>();
|
Set<MethodDescriptor> methods = new HashSet<>();
|
||||||
findInheritedMethods(cls, methods, new HashSet<String>());
|
findInheritedMethods(cls, methods, new HashSet<>());
|
||||||
for (MethodHolder method : cls.getMethods()) {
|
for (MethodHolder method : cls.getMethods()) {
|
||||||
if (methods.contains(method.getDescriptor()) && method.getAnnotations().get(Sync.class.getName()) == null) {
|
if (methods.contains(method.getDescriptor()) && method.getAnnotations().get(Sync.class.getName()) == null) {
|
||||||
AnnotationHolder annot = new AnnotationHolder(Sync.class.getName());
|
AnnotationHolder annot = new AnnotationHolder(Sync.class.getName());
|
||||||
|
@ -544,9 +544,8 @@ class JavascriptNativeProcessor {
|
||||||
// create program that invokes proxy method
|
// create program that invokes proxy method
|
||||||
program = new Program();
|
program = new Program();
|
||||||
BasicBlock block = program.createBasicBlock();
|
BasicBlock block = program.createBasicBlock();
|
||||||
List<Variable> params = new ArrayList<>();
|
|
||||||
for (int i = 0; i < paramCount; ++i) {
|
for (int i = 0; i < paramCount; ++i) {
|
||||||
params.add(program.createVariable());
|
program.createVariable();
|
||||||
}
|
}
|
||||||
if (isStatic) {
|
if (isStatic) {
|
||||||
program.createVariable();
|
program.createVariable();
|
||||||
|
|
|
@ -59,17 +59,12 @@ class NativeJavascriptClassRepository {
|
||||||
if (cls == null || !(cls.hasModifier(ElementModifier.INTERFACE) || cls.hasModifier(ElementModifier.ABSTRACT))) {
|
if (cls == null || !(cls.hasModifier(ElementModifier.INTERFACE) || cls.hasModifier(ElementModifier.ABSTRACT))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (String iface : cls.getInterfaces()) {
|
|
||||||
if (isJavaScriptClass(iface)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (cls.getParent() != null && !cls.getParent().equals(cls.getName())) {
|
if (cls.getParent() != null && !cls.getParent().equals(cls.getName())) {
|
||||||
if (isJavaScriptClass(cls.getParent())) {
|
if (isJavaScriptClass(cls.getParent())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return cls.getInterfaces().stream().anyMatch(iface -> isJavaScriptClass(iface));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean examineIfJavaScriptImplementation(String className) {
|
private boolean examineIfJavaScriptImplementation(String className) {
|
||||||
|
@ -85,11 +80,6 @@ class NativeJavascriptClassRepository {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (String iface : cls.getInterfaces()) {
|
return cls.getInterfaces().stream().anyMatch(iface -> isJavaScriptClass(iface));
|
||||||
if (isJavaScriptClass(iface)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,7 @@ package org.teavm.platform.plugin;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import org.teavm.dependency.AbstractDependencyListener;
|
import org.teavm.dependency.AbstractDependencyListener;
|
||||||
import org.teavm.dependency.DependencyAgent;
|
import org.teavm.dependency.DependencyAgent;
|
||||||
import org.teavm.dependency.DependencyConsumer;
|
|
||||||
import org.teavm.dependency.DependencyNode;
|
import org.teavm.dependency.DependencyNode;
|
||||||
import org.teavm.dependency.DependencyType;
|
|
||||||
import org.teavm.dependency.MethodDependency;
|
import org.teavm.dependency.MethodDependency;
|
||||||
import org.teavm.model.CallLocation;
|
import org.teavm.model.CallLocation;
|
||||||
import org.teavm.model.MethodReference;
|
import org.teavm.model.MethodReference;
|
||||||
|
@ -46,27 +44,24 @@ public class AnnotationDependencySupport extends AbstractDependencyListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void methodReached(final DependencyAgent agent, final MethodDependency method,
|
public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) {
|
||||||
final CallLocation location) {
|
|
||||||
if (method.getReference().getClassName().equals(Platform.class.getName()) &&
|
if (method.getReference().getClassName().equals(Platform.class.getName()) &&
|
||||||
method.getReference().getName().equals("getAnnotations")) {
|
method.getReference().getName().equals("getAnnotations")) {
|
||||||
method.getResult().propagate(agent.getType("[" + Annotation.class.getName()));
|
method.getResult().propagate(agent.getType("[" + Annotation.class.getName()));
|
||||||
agent.linkMethod(new MethodReference(PlatformAnnotationProvider.class, "getAnnotations",
|
agent.linkMethod(new MethodReference(PlatformAnnotationProvider.class, "getAnnotations",
|
||||||
Annotation[].class), location);
|
Annotation[].class), location);
|
||||||
allClasses.addConsumer(new DependencyConsumer() {
|
allClasses.addConsumer(type -> {
|
||||||
@Override public void consume(DependencyType type) {
|
if (type.getName().endsWith("$$__annotations__$$")) {
|
||||||
if (type.getName().endsWith("$$__annotations__$$")) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
String className = type.getName() + "$$__annotations__$$";
|
|
||||||
agent.linkMethod(new MethodReference(className, "<init>", ValueType.VOID), location)
|
|
||||||
.propagate(0, className)
|
|
||||||
.use();
|
|
||||||
MethodDependency readMethod = agent.linkMethod(new MethodReference(className,
|
|
||||||
"getAnnotations", ValueType.parse(Annotation[].class)), location);
|
|
||||||
readMethod.getResult().getArrayItem().connect(method.getResult().getArrayItem());
|
|
||||||
readMethod.use();
|
|
||||||
}
|
}
|
||||||
|
String className = type.getName() + "$$__annotations__$$";
|
||||||
|
agent.linkMethod(new MethodReference(className, "<init>", ValueType.VOID), location)
|
||||||
|
.propagate(0, className)
|
||||||
|
.use();
|
||||||
|
MethodDependency readMethod = agent.linkMethod(new MethodReference(className,
|
||||||
|
"getAnnotations", ValueType.parse(Annotation[].class)), location);
|
||||||
|
readMethod.getResult().getArrayItem().connect(method.getResult().getArrayItem());
|
||||||
|
readMethod.use();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,16 @@ import java.io.IOException;
|
||||||
import org.teavm.codegen.SourceWriter;
|
import org.teavm.codegen.SourceWriter;
|
||||||
import org.teavm.dependency.DependencyAgent;
|
import org.teavm.dependency.DependencyAgent;
|
||||||
import org.teavm.dependency.DependencyPlugin;
|
import org.teavm.dependency.DependencyPlugin;
|
||||||
import org.teavm.dependency.DependencyType;
|
|
||||||
import org.teavm.dependency.DependencyTypeFilter;
|
|
||||||
import org.teavm.dependency.MethodDependency;
|
import org.teavm.dependency.MethodDependency;
|
||||||
import org.teavm.javascript.spi.Generator;
|
import org.teavm.javascript.spi.Generator;
|
||||||
import org.teavm.javascript.spi.GeneratorContext;
|
import org.teavm.javascript.spi.GeneratorContext;
|
||||||
import org.teavm.model.*;
|
import org.teavm.model.CallLocation;
|
||||||
|
import org.teavm.model.ClassReader;
|
||||||
|
import org.teavm.model.ClassReaderSource;
|
||||||
|
import org.teavm.model.ElementModifier;
|
||||||
|
import org.teavm.model.MethodReader;
|
||||||
|
import org.teavm.model.MethodReference;
|
||||||
|
import org.teavm.model.ValueType;
|
||||||
import org.teavm.platform.async.AsyncCallback;
|
import org.teavm.platform.async.AsyncCallback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,7 +99,7 @@ public class AsyncMethodGenerator implements Generator, DependencyPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void methodAchieved(final DependencyAgent checker, final MethodDependency method, CallLocation location) {
|
public void methodAchieved(DependencyAgent checker, MethodDependency method, CallLocation location) {
|
||||||
MethodReference asyncRef = getAsyncReference(method.getReference());
|
MethodReference asyncRef = getAsyncReference(method.getReference());
|
||||||
MethodDependency asyncMethod = checker.linkMethod(asyncRef, location);
|
MethodDependency asyncMethod = checker.linkMethod(asyncRef, location);
|
||||||
int paramCount = method.getReference().parameterCount();
|
int paramCount = method.getReference().parameterCount();
|
||||||
|
@ -107,12 +111,8 @@ public class AsyncMethodGenerator implements Generator, DependencyPlugin {
|
||||||
MethodDependency completeMethod = checker.linkMethod(
|
MethodDependency completeMethod = checker.linkMethod(
|
||||||
new MethodReference(AsyncCallbackWrapper.class, "complete", Object.class, void.class), null);
|
new MethodReference(AsyncCallbackWrapper.class, "complete", Object.class, void.class), null);
|
||||||
if (method.getResult() != null) {
|
if (method.getResult() != null) {
|
||||||
completeMethod.getVariable(1).connect(method.getResult(), new DependencyTypeFilter() {
|
completeMethod.getVariable(1).connect(method.getResult(), type -> isSubtype(checker.getClassSource(),
|
||||||
@Override
|
type.getName(), method.getReference().getReturnType()));
|
||||||
public boolean match(DependencyType type) {
|
|
||||||
return isSubtype(checker.getClassSource(), type.getName(), method.getReference().getReturnType());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
completeMethod.use();
|
completeMethod.use();
|
||||||
|
|
||||||
|
@ -150,11 +150,6 @@ public class AsyncMethodGenerator implements Generator, DependencyPlugin {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (String iface : cls.getInterfaces()) {
|
return cls.getInterfaces().stream().anyMatch(iface -> isSubclass(classSource, iface, baseClass));
|
||||||
if (isSubclass(classSource, iface, baseClass)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,19 +37,17 @@ public class ClassLookupDependencySupport extends AbstractDependencyListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void methodReached(final DependencyAgent agent, MethodDependency method, final CallLocation location) {
|
public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) {
|
||||||
MethodReference ref = method.getReference();
|
MethodReference ref = method.getReference();
|
||||||
if (ref.getClassName().equals(Platform.class.getName()) && ref.getName().equals("lookupClass")) {
|
if (ref.getClassName().equals(Platform.class.getName()) && ref.getName().equals("lookupClass")) {
|
||||||
allClasses.addConsumer(new DependencyConsumer() {
|
allClasses.addConsumer(type -> {
|
||||||
@Override public void consume(DependencyType type) {
|
ClassReader cls = agent.getClassSource().get(type.getName());
|
||||||
ClassReader cls = agent.getClassSource().get(type.getName());
|
if (cls == null) {
|
||||||
if (cls == null) {
|
return;
|
||||||
return;
|
}
|
||||||
}
|
MethodReader initMethod = cls.getMethod(new MethodDescriptor("<clinit>", void.class));
|
||||||
MethodReader initMethod = cls.getMethod(new MethodDescriptor("<clinit>", void.class));
|
if (initMethod != null) {
|
||||||
if (initMethod != null) {
|
agent.linkMethod(initMethod.getReference(), location).use();
|
||||||
agent.linkMethod(initMethod.getReference(), location).use();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,7 @@ package org.teavm.platform.plugin;
|
||||||
|
|
||||||
import org.teavm.dependency.AbstractDependencyListener;
|
import org.teavm.dependency.AbstractDependencyListener;
|
||||||
import org.teavm.dependency.DependencyAgent;
|
import org.teavm.dependency.DependencyAgent;
|
||||||
import org.teavm.dependency.DependencyConsumer;
|
|
||||||
import org.teavm.dependency.DependencyNode;
|
import org.teavm.dependency.DependencyNode;
|
||||||
import org.teavm.dependency.DependencyType;
|
|
||||||
import org.teavm.dependency.MethodDependency;
|
import org.teavm.dependency.MethodDependency;
|
||||||
import org.teavm.model.CallLocation;
|
import org.teavm.model.CallLocation;
|
||||||
import org.teavm.model.ClassReader;
|
import org.teavm.model.ClassReader;
|
||||||
|
@ -51,19 +49,17 @@ public class EnumDependencySupport extends AbstractDependencyListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void methodReached(final DependencyAgent agent, MethodDependency method, CallLocation location) {
|
public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) {
|
||||||
if (method.getReference().getClassName().equals(Platform.class.getName()) &&
|
if (method.getReference().getClassName().equals(Platform.class.getName()) &&
|
||||||
method.getReference().getName().equals("getEnumConstants")) {
|
method.getReference().getName().equals("getEnumConstants")) {
|
||||||
allEnums.connect(method.getResult().getArrayItem());
|
allEnums.connect(method.getResult().getArrayItem());
|
||||||
final MethodReference ref = method.getReference();
|
final MethodReference ref = method.getReference();
|
||||||
allEnums.addConsumer(new DependencyConsumer() {
|
allEnums.addConsumer(type -> {
|
||||||
@Override public void consume(DependencyType type) {
|
ClassReader cls = agent.getClassSource().get(type.getName());
|
||||||
ClassReader cls = agent.getClassSource().get(type.getName());
|
MethodReader valuesMethod = cls.getMethod(new MethodDescriptor("values",
|
||||||
MethodReader method = cls.getMethod(new MethodDescriptor("values",
|
ValueType.arrayOf(ValueType.object(cls.getName()))));
|
||||||
ValueType.arrayOf(ValueType.object(cls.getName()))));
|
if (valuesMethod != null) {
|
||||||
if (method != null) {
|
agent.linkMethod(valuesMethod.getReference(), new CallLocation(ref)).use();
|
||||||
agent.linkMethod(method.getReference(), new CallLocation(ref)).use();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
method.getResult().propagate(agent.getType("[java.lang.Enum"));
|
method.getResult().propagate(agent.getType("[java.lang.Enum"));
|
||||||
|
|
|
@ -47,16 +47,13 @@ public class NewInstanceDependencySupport extends AbstractDependencyListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void methodReached(final DependencyAgent agent, MethodDependency method, CallLocation location) {
|
public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) {
|
||||||
MethodReader reader = method.getMethod();
|
MethodReader reader = method.getMethod();
|
||||||
if (reader.getOwnerName().equals(Platform.class.getName()) && reader.getName().equals("newInstanceImpl")) {
|
if (reader.getOwnerName().equals(Platform.class.getName()) && reader.getName().equals("newInstanceImpl")) {
|
||||||
allClassesNode.connect(method.getResult());
|
allClassesNode.connect(method.getResult());
|
||||||
final MethodReference methodRef = reader.getReference();
|
MethodReference methodRef = reader.getReference();
|
||||||
method.getResult().addConsumer(new DependencyConsumer() {
|
method.getResult().addConsumer(type -> attachConstructor(agent, type.getName(),
|
||||||
@Override public void consume(DependencyType type) {
|
new CallLocation(methodRef)));
|
||||||
attachConstructor(agent, type.getName(), new CallLocation(methodRef));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ public class PlatformGenerator implements Generator, Injector, DependencyPlugin
|
||||||
case "classFromResource":
|
case "classFromResource":
|
||||||
case "objectFromResource":
|
case "objectFromResource":
|
||||||
context.writeExpr(context.getArgument(0));
|
context.writeExpr(context.getArgument(0));
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,6 @@
|
||||||
package org.teavm.samples.video;
|
package org.teavm.samples.video;
|
||||||
|
|
||||||
import org.teavm.dom.browser.Window;
|
import org.teavm.dom.browser.Window;
|
||||||
import org.teavm.dom.events.EventListener;
|
|
||||||
import org.teavm.dom.events.MouseEvent;
|
|
||||||
import org.teavm.dom.html.HTMLBodyElement;
|
import org.teavm.dom.html.HTMLBodyElement;
|
||||||
import org.teavm.dom.html.HTMLButtonElement;
|
import org.teavm.dom.html.HTMLButtonElement;
|
||||||
import org.teavm.dom.html.HTMLDocument;
|
import org.teavm.dom.html.HTMLDocument;
|
||||||
|
@ -53,7 +51,7 @@ public final class Player {
|
||||||
HTMLElement p = document.createElement("p");
|
HTMLElement p = document.createElement("p");
|
||||||
p.appendChild(document.createTextNode("Your user agent does not support the HTML5 Video element."));
|
p.appendChild(document.createTextNode("Your user agent does not support the HTML5 Video element."));
|
||||||
|
|
||||||
final HTMLVideoElement video = (HTMLVideoElement)document.createElement("video");
|
HTMLVideoElement video = (HTMLVideoElement)document.createElement("video");
|
||||||
video.setAttribute("id", "video");
|
video.setAttribute("id", "video");
|
||||||
video.setControls(true);
|
video.setControls(true);
|
||||||
video.setPreload("none");
|
video.setPreload("none");
|
||||||
|
@ -69,129 +67,61 @@ public final class Player {
|
||||||
|
|
||||||
HTMLButtonElement loadButton = (HTMLButtonElement)document.createElement("button");
|
HTMLButtonElement loadButton = (HTMLButtonElement)document.createElement("button");
|
||||||
loadButton.appendChild(document.createTextNode("load()"));
|
loadButton.appendChild(document.createTextNode("load()"));
|
||||||
loadButton.addEventListener("click", new EventListener<MouseEvent>() {
|
loadButton.addEventListener("click", evt -> video.load());
|
||||||
@Override
|
|
||||||
public void handleEvent(MouseEvent evt) {
|
|
||||||
video.load();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
HTMLButtonElement playButton = (HTMLButtonElement)document.createElement("button");
|
HTMLButtonElement playButton = (HTMLButtonElement)document.createElement("button");
|
||||||
playButton.appendChild(document.createTextNode("play()"));
|
playButton.appendChild(document.createTextNode("play()"));
|
||||||
playButton.addEventListener("click", new EventListener<MouseEvent>() {
|
playButton.addEventListener("click", evt -> video.play());
|
||||||
@Override
|
|
||||||
public void handleEvent(MouseEvent evt) {
|
|
||||||
video.play();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
HTMLButtonElement pauseButton = (HTMLButtonElement)document.createElement("button");
|
HTMLButtonElement pauseButton = (HTMLButtonElement)document.createElement("button");
|
||||||
pauseButton.appendChild(document.createTextNode("pause()"));
|
pauseButton.appendChild(document.createTextNode("pause()"));
|
||||||
pauseButton.addEventListener("click", new EventListener<MouseEvent>() {
|
pauseButton.addEventListener("click", evt -> video.pause());
|
||||||
@Override
|
|
||||||
public void handleEvent(MouseEvent evt) {
|
|
||||||
video.pause();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
HTMLButtonElement currentTimePlusButton = (HTMLButtonElement)document.createElement("button");
|
HTMLButtonElement currentTimePlusButton = (HTMLButtonElement)document.createElement("button");
|
||||||
currentTimePlusButton.appendChild(document.createTextNode("currentTime+=10"));
|
currentTimePlusButton.appendChild(document.createTextNode("currentTime+=10"));
|
||||||
currentTimePlusButton.addEventListener("click", new EventListener<MouseEvent>() {
|
currentTimePlusButton.addEventListener("click", evt -> video.setCurrentTime(video.getCurrentTime() + 10));
|
||||||
@Override
|
|
||||||
public void handleEvent(MouseEvent evt) {
|
|
||||||
video.setCurrentTime(video.getCurrentTime() + 10);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
HTMLButtonElement currentTimeMinusButton = (HTMLButtonElement)document.createElement("button");
|
HTMLButtonElement currentTimeMinusButton = (HTMLButtonElement)document.createElement("button");
|
||||||
currentTimeMinusButton.appendChild(document.createTextNode("currentTime-=10"));
|
currentTimeMinusButton.appendChild(document.createTextNode("currentTime-=10"));
|
||||||
currentTimeMinusButton.addEventListener("click", new EventListener<MouseEvent>() {
|
currentTimeMinusButton.addEventListener("click", evt -> video.setCurrentTime(video.getCurrentTime() - 10));
|
||||||
@Override
|
|
||||||
public void handleEvent(MouseEvent evt) {
|
|
||||||
video.setCurrentTime(video.getCurrentTime() - 10);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
HTMLButtonElement currentTime50Button = (HTMLButtonElement)document.createElement("button");
|
HTMLButtonElement currentTime50Button = (HTMLButtonElement)document.createElement("button");
|
||||||
currentTime50Button.appendChild(document.createTextNode("currentTime=50"));
|
currentTime50Button.appendChild(document.createTextNode("currentTime=50"));
|
||||||
currentTime50Button.addEventListener("click", new EventListener<MouseEvent>() {
|
currentTime50Button.addEventListener("click", evt -> video.setCurrentTime(50));
|
||||||
@Override
|
|
||||||
public void handleEvent(MouseEvent evt) {
|
|
||||||
video.setCurrentTime(50);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
HTMLButtonElement playbackRateIncrementButton = (HTMLButtonElement)document.createElement("button");
|
HTMLButtonElement playbackRateIncrementButton = (HTMLButtonElement)document.createElement("button");
|
||||||
playbackRateIncrementButton.appendChild(document.createTextNode("playbackRate++"));
|
playbackRateIncrementButton.appendChild(document.createTextNode("playbackRate++"));
|
||||||
playbackRateIncrementButton.addEventListener("click", new EventListener<MouseEvent>() {
|
playbackRateIncrementButton.addEventListener("click", evt -> video.setPlaybackRate(
|
||||||
@Override
|
video.getPlaybackRate() + 1));
|
||||||
public void handleEvent(MouseEvent evt) {
|
|
||||||
video.setPlaybackRate(video.getPlaybackRate() + 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
HTMLButtonElement playbackRateDecrementButton = (HTMLButtonElement)document.createElement("button");
|
HTMLButtonElement playbackRateDecrementButton = (HTMLButtonElement)document.createElement("button");
|
||||||
playbackRateDecrementButton.appendChild(document.createTextNode("playbackRate--"));
|
playbackRateDecrementButton.appendChild(document.createTextNode("playbackRate--"));
|
||||||
playbackRateDecrementButton.addEventListener("click", new EventListener<MouseEvent>() {
|
playbackRateDecrementButton.addEventListener("click", evt -> video.setPlaybackRate(
|
||||||
@Override
|
video.getPlaybackRate() - 1));
|
||||||
public void handleEvent(MouseEvent evt) {
|
|
||||||
video.setPlaybackRate(video.getPlaybackRate() - 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
HTMLButtonElement playbackRatePlusButton = (HTMLButtonElement)document.createElement("button");
|
HTMLButtonElement playbackRatePlusButton = (HTMLButtonElement)document.createElement("button");
|
||||||
playbackRatePlusButton.appendChild(document.createTextNode("playbackRate+=0.1"));
|
playbackRatePlusButton.appendChild(document.createTextNode("playbackRate+=0.1"));
|
||||||
playbackRatePlusButton.addEventListener("click", new EventListener<MouseEvent>() {
|
playbackRatePlusButton.addEventListener("click", evt -> video.setPlaybackRate(video.getPlaybackRate() + 0.1));
|
||||||
@Override
|
|
||||||
public void handleEvent(MouseEvent evt) {
|
|
||||||
video.setPlaybackRate(video.getPlaybackRate() + 0.1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
HTMLButtonElement playbackRateMinusButton = (HTMLButtonElement)document.createElement("button");
|
HTMLButtonElement playbackRateMinusButton = (HTMLButtonElement)document.createElement("button");
|
||||||
playbackRateMinusButton.appendChild(document.createTextNode("playbackRate-=0.1"));
|
playbackRateMinusButton.appendChild(document.createTextNode("playbackRate-=0.1"));
|
||||||
playbackRateMinusButton.addEventListener("click", new EventListener<MouseEvent>() {
|
playbackRateMinusButton.addEventListener("click", evt -> video.setPlaybackRate(video.getPlaybackRate() - 0.1));
|
||||||
@Override
|
|
||||||
public void handleEvent(MouseEvent evt) {
|
|
||||||
video.setPlaybackRate(video.getPlaybackRate() - 0.1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
HTMLButtonElement volumePlusButton = (HTMLButtonElement)document.createElement("button");
|
HTMLButtonElement volumePlusButton = (HTMLButtonElement)document.createElement("button");
|
||||||
volumePlusButton.appendChild(document.createTextNode("volume+=0.1"));
|
volumePlusButton.appendChild(document.createTextNode("volume+=0.1"));
|
||||||
volumePlusButton.addEventListener("click", new EventListener<MouseEvent>() {
|
volumePlusButton.addEventListener("click", evt -> video.setVolume(video.getVolume() + 0.1f));
|
||||||
@Override
|
|
||||||
public void handleEvent(MouseEvent evt) {
|
|
||||||
video.setVolume(video.getVolume() + 0.1f);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
HTMLButtonElement volumeMinusButton = (HTMLButtonElement)document.createElement("button");
|
HTMLButtonElement volumeMinusButton = (HTMLButtonElement)document.createElement("button");
|
||||||
volumeMinusButton.appendChild(document.createTextNode("volume-=0.1"));
|
volumeMinusButton.appendChild(document.createTextNode("volume-=0.1"));
|
||||||
volumeMinusButton.addEventListener("click", new EventListener<MouseEvent>() {
|
volumeMinusButton.addEventListener("click", evt -> video.setVolume(video.getVolume() - 0.1f));
|
||||||
@Override
|
|
||||||
public void handleEvent(MouseEvent evt) {
|
|
||||||
video.setVolume(video.getVolume() - 0.1f);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
HTMLButtonElement muteButton = (HTMLButtonElement)document.createElement("button");
|
HTMLButtonElement muteButton = (HTMLButtonElement)document.createElement("button");
|
||||||
muteButton.appendChild(document.createTextNode("muted=true"));
|
muteButton.appendChild(document.createTextNode("muted=true"));
|
||||||
muteButton.addEventListener("click", new EventListener<MouseEvent>() {
|
muteButton.addEventListener("click", evt -> video.setMuted(true));
|
||||||
@Override
|
|
||||||
public void handleEvent(MouseEvent evt) {
|
|
||||||
video.setMuted(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
HTMLButtonElement unmuteButton = (HTMLButtonElement)document.createElement("button");
|
HTMLButtonElement unmuteButton = (HTMLButtonElement)document.createElement("button");
|
||||||
unmuteButton.appendChild(document.createTextNode("muted=false"));
|
unmuteButton.appendChild(document.createTextNode("muted=false"));
|
||||||
unmuteButton.addEventListener("click", new EventListener<MouseEvent>() {
|
unmuteButton.addEventListener("click", evt -> video.setMuted(false));
|
||||||
@Override
|
|
||||||
public void handleEvent(MouseEvent evt) {
|
|
||||||
video.setMuted(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
HTMLElement divButtons = document.createElement("div");
|
HTMLElement divButtons = document.createElement("div");
|
||||||
divButtons.setAttribute("id", "buttons");
|
divButtons.setAttribute("id", "buttons");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user