mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-09 08:24:10 -08:00
Switch to Java 8
This commit is contained in:
parent
c4bb803965
commit
06372c2f9f
4
pom.xml
4
pom.xml
|
@ -175,8 +175,8 @@
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>2.5.1</version>
|
<version>2.5.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.7</source>
|
<source>1.8</source>
|
||||||
<target>1.7</target>
|
<target>1.8</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|
|
@ -156,7 +156,7 @@ public class TTreeMap<K, V> extends TAbstractMap<K, V> implements TCloneable, TS
|
||||||
}
|
}
|
||||||
int mid = (l + u) / 2;
|
int mid = (l + u) / 2;
|
||||||
Entry<? extends K, ? extends V> entry = entries[mid];
|
Entry<? extends K, ? extends V> entry = entries[mid];
|
||||||
TreeNode<K, V> node = new TreeNode<K, V>(entry.getKey());
|
TreeNode<K, V> node = new TreeNode<>(entry.getKey());
|
||||||
node.setValue(entry.getValue());
|
node.setValue(entry.getValue());
|
||||||
node.left = createNode(entries, l, mid - 1);
|
node.left = createNode(entries, l, mid - 1);
|
||||||
node.right = createNode(entries, mid + 1, u);
|
node.right = createNode(entries, mid + 1, u);
|
||||||
|
|
|
@ -348,7 +348,7 @@ public class AstIO {
|
||||||
output.writeInt(statement.getExceptionType() != null ?
|
output.writeInt(statement.getExceptionType() != null ?
|
||||||
symbolTable.lookup(statement.getExceptionType()) : -1);
|
symbolTable.lookup(statement.getExceptionType()) : -1);
|
||||||
output.writeShort(statement.getExceptionVariable() != null ?
|
output.writeShort(statement.getExceptionVariable() != null ?
|
||||||
statement.getExceptionVariable().intValue() : -1);
|
statement.getExceptionVariable() : -1);
|
||||||
writeSequence(statement.getHandler());
|
writeSequence(statement.getHandler());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IOExceptionWrapper(e);
|
throw new IOExceptionWrapper(e);
|
||||||
|
|
|
@ -33,11 +33,7 @@ public class NamingOrderer implements NameFrequencyConsumer {
|
||||||
Entry entry = entries.get(key);
|
Entry entry = entries.get(key);
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
entry = new Entry();
|
entry = new Entry();
|
||||||
entry.operation = new NamingOperation() {
|
entry.operation = naming -> naming.getFullNameFor(method);
|
||||||
@Override public void perform(NamingStrategy naming) {
|
|
||||||
naming.getFullNameFor(method);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
entries.put(key, entry);
|
entries.put(key, entry);
|
||||||
}
|
}
|
||||||
entry.frequency++;
|
entry.frequency++;
|
||||||
|
@ -50,11 +46,7 @@ public class NamingOrderer implements NameFrequencyConsumer {
|
||||||
Entry entry = entries.get(key);
|
Entry entry = entries.get(key);
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
entry = new Entry();
|
entry = new Entry();
|
||||||
entry.operation = new NamingOperation() {
|
entry.operation = naming -> naming.getNameForInit(method);
|
||||||
@Override public void perform(NamingStrategy naming) {
|
|
||||||
naming.getNameForInit(method);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
entries.put(key, entry);
|
entries.put(key, entry);
|
||||||
}
|
}
|
||||||
entry.frequency++;
|
entry.frequency++;
|
||||||
|
@ -66,11 +58,7 @@ public class NamingOrderer implements NameFrequencyConsumer {
|
||||||
Entry entry = entries.get(key);
|
Entry entry = entries.get(key);
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
entry = new Entry();
|
entry = new Entry();
|
||||||
entry.operation = new NamingOperation() {
|
entry.operation = naming -> naming.getNameFor(method);
|
||||||
@Override public void perform(NamingStrategy naming) {
|
|
||||||
naming.getNameFor(method);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
entries.put(key, entry);
|
entries.put(key, entry);
|
||||||
}
|
}
|
||||||
entry.frequency++;
|
entry.frequency++;
|
||||||
|
@ -82,11 +70,7 @@ public class NamingOrderer implements NameFrequencyConsumer {
|
||||||
Entry entry = entries.get(key);
|
Entry entry = entries.get(key);
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
entry = new Entry();
|
entry = new Entry();
|
||||||
entry.operation = new NamingOperation() {
|
entry.operation = naming -> naming.getNameFor(className);
|
||||||
@Override public void perform(NamingStrategy naming) {
|
|
||||||
naming.getNameFor(className);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
entries.put(key, entry);
|
entries.put(key, entry);
|
||||||
}
|
}
|
||||||
entry.frequency++;
|
entry.frequency++;
|
||||||
|
@ -98,11 +82,7 @@ public class NamingOrderer implements NameFrequencyConsumer {
|
||||||
Entry entry = entries.get(key);
|
Entry entry = entries.get(key);
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
entry = new Entry();
|
entry = new Entry();
|
||||||
entry.operation = new NamingOperation() {
|
entry.operation = naming -> naming.getNameFor(field);
|
||||||
@Override public void perform(NamingStrategy naming) {
|
|
||||||
naming.getNameFor(field);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
entries.put(key, entry);
|
entries.put(key, entry);
|
||||||
}
|
}
|
||||||
entry.frequency++;
|
entry.frequency++;
|
||||||
|
@ -114,11 +94,7 @@ public class NamingOrderer implements NameFrequencyConsumer {
|
||||||
Entry entry = entries.get(key);
|
Entry entry = entries.get(key);
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
entry = new Entry();
|
entry = new Entry();
|
||||||
entry.operation = new NamingOperation() {
|
entry.operation = naming -> naming.getNameForFunction(name);
|
||||||
@Override public void perform(NamingStrategy naming) {
|
|
||||||
naming.getNameForFunction(name);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
entries.put(key, entry);
|
entries.put(key, entry);
|
||||||
}
|
}
|
||||||
entry.frequency++;
|
entry.frequency++;
|
||||||
|
@ -126,11 +102,7 @@ public class NamingOrderer implements NameFrequencyConsumer {
|
||||||
|
|
||||||
public void apply(NamingStrategy naming) {
|
public void apply(NamingStrategy naming) {
|
||||||
List<Entry> entryList = new ArrayList<>(entries.values());
|
List<Entry> entryList = new ArrayList<>(entries.values());
|
||||||
Collections.sort(entryList, new Comparator<Entry>() {
|
Collections.sort(entryList, (o1, o2) -> Integer.compare(o2.frequency, o1.frequency));
|
||||||
@Override public int compare(Entry o1, Entry o2) {
|
|
||||||
return Integer.compare(o2.frequency, o1.frequency);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
for (Entry entry : entryList) {
|
for (Entry entry : entryList) {
|
||||||
entry.operation.perform(naming);
|
entry.operation.perform(naming);
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,11 +80,7 @@ public final class GraphUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int[][] findStronglyConnectedComponents(Graph graph, int[] start) {
|
public static int[][] findStronglyConnectedComponents(Graph graph, int[] start) {
|
||||||
return findStronglyConnectedComponents(graph, start, new GraphNodeFilter() {
|
return findStronglyConnectedComponents(graph, start, node -> true);
|
||||||
@Override public boolean match(int node) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -92,14 +92,11 @@ public class RangeTree {
|
||||||
for (Range range : ranges) {
|
for (Range range : ranges) {
|
||||||
rangeList.add(range);
|
rangeList.add(range);
|
||||||
}
|
}
|
||||||
Collections.sort(rangeList, new Comparator<Range>() {
|
Collections.sort(rangeList, (o1, o2) -> {
|
||||||
@Override
|
if (o1.right != o2.right) {
|
||||||
public int compare(Range o1, Range o2) {
|
return o2.right - o1.right;
|
||||||
if (o1.right != o2.right) {
|
|
||||||
return o2.right - o1.right;
|
|
||||||
}
|
|
||||||
return o1.left - o2.left;
|
|
||||||
}
|
}
|
||||||
|
return o1.left - o2.left;
|
||||||
});
|
});
|
||||||
Deque<NodeImpl> stack = new ArrayDeque<>();
|
Deque<NodeImpl> stack = new ArrayDeque<>();
|
||||||
stack.push(root);
|
stack.push(root);
|
||||||
|
|
|
@ -38,11 +38,7 @@ public class ThreadPoolFiniteExecutor implements FiniteExecutor {
|
||||||
|
|
||||||
public ThreadPoolFiniteExecutor(int numThreads) {
|
public ThreadPoolFiniteExecutor(int numThreads) {
|
||||||
for (int i = 0; i < numThreads; ++i) {
|
for (int i = 0; i < numThreads; ++i) {
|
||||||
Thread thread = new Thread() {
|
Thread thread = new Thread(() -> takeTask());
|
||||||
@Override public void run() {
|
|
||||||
takeTask();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
threads.add(thread);
|
threads.add(thread);
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,8 +107,7 @@ public class Debugger {
|
||||||
DebugInformation debugInfo = debugInformationMap.get(script);
|
DebugInformation debugInfo = debugInformationMap.get(script);
|
||||||
if (frame.getLocation() != null && frame.getLocation().getFileName() != null &&
|
if (frame.getLocation() != null && frame.getLocation().getFileName() != null &&
|
||||||
frame.getLocation().getLine() >= 0 && debugInfo != null) {
|
frame.getLocation().getLine() >= 0 && debugInfo != null) {
|
||||||
exits = addFollowing(debugInfo, frame.getLocation(), script, new HashSet<SourceLocation>(),
|
exits = addFollowing(debugInfo, frame.getLocation(), script, new HashSet<>(), successors);
|
||||||
successors);
|
|
||||||
if (enterMethod) {
|
if (enterMethod) {
|
||||||
CallSiteSuccessorFinder successorFinder = new CallSiteSuccessorFinder(debugInfo, script,
|
CallSiteSuccessorFinder successorFinder = new CallSiteSuccessorFinder(debugInfo, script,
|
||||||
successors);
|
successors);
|
||||||
|
|
|
@ -271,7 +271,7 @@ class DebugInformationWriter {
|
||||||
}
|
}
|
||||||
if (count > 1) {
|
if (count > 1) {
|
||||||
if (current > last) {
|
if (current > last) {
|
||||||
writeUnsignedNumber(((current - last) << 1) | 0);
|
writeUnsignedNumber((current - last) << 1);
|
||||||
while (last < current) {
|
while (last < current) {
|
||||||
writeUnsignedNumber(array[last++]);
|
writeUnsignedNumber(array[last++]);
|
||||||
}
|
}
|
||||||
|
@ -282,7 +282,7 @@ class DebugInformationWriter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (array.length > last) {
|
if (array.length > last) {
|
||||||
writeUnsignedNumber(((array.length - last) << 1) | 0);
|
writeUnsignedNumber((array.length - last) << 1);
|
||||||
while (last < array.length) {
|
while (last < array.length) {
|
||||||
writeUnsignedNumber(array[last++]);
|
writeUnsignedNumber(array[last++]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,40 +71,24 @@ public class DependencyChecker implements DependencyInfo {
|
||||||
this.classSource = new DependencyClassSource(classSource, diagnostics);
|
this.classSource = new DependencyClassSource(classSource, diagnostics);
|
||||||
this.classLoader = classLoader;
|
this.classLoader = classLoader;
|
||||||
this.services = services;
|
this.services = services;
|
||||||
methodReaderCache = new CachedMapper<>(new Mapper<MethodReference, MethodReader>() {
|
methodReaderCache = new CachedMapper<>(preimage -> findMethodReader(preimage));
|
||||||
@Override public MethodReader map(MethodReference preimage) {
|
fieldReaderCache = new CachedMapper<>(preimage -> findFieldReader(preimage));
|
||||||
return findMethodReader(preimage);
|
methodCache = new CachedMapper<>(preimage -> {
|
||||||
|
MethodReader method = methodReaderCache.map(preimage);
|
||||||
|
if (method != null && !method.getReference().equals(preimage)) {
|
||||||
|
return methodCache.map(method.getReference());
|
||||||
}
|
}
|
||||||
|
return createMethodDep(preimage, method);
|
||||||
});
|
});
|
||||||
fieldReaderCache = new CachedMapper<>(new Mapper<FieldReference, FieldReader>() {
|
fieldCache = new CachedMapper<>(preimage -> {
|
||||||
@Override public FieldReader map(FieldReference preimage) {
|
FieldReader field = fieldReaderCache.map(preimage);
|
||||||
return findFieldReader(preimage);
|
if (field != null && !field.getReference().equals(preimage)) {
|
||||||
}
|
return fieldCache.map(field.getReference());
|
||||||
});
|
|
||||||
methodCache = new CachedMapper<>(new Mapper<MethodReference, MethodDependency>() {
|
|
||||||
@Override public MethodDependency map(MethodReference preimage) {
|
|
||||||
MethodReader method = methodReaderCache.map(preimage);
|
|
||||||
if (method != null && !method.getReference().equals(preimage)) {
|
|
||||||
return methodCache.map(method.getReference());
|
|
||||||
}
|
|
||||||
return createMethodDep(preimage, method);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
fieldCache = new CachedMapper<>(new Mapper<FieldReference, FieldDependency>() {
|
|
||||||
@Override public FieldDependency map(FieldReference preimage) {
|
|
||||||
FieldReader field = fieldReaderCache.map(preimage);
|
|
||||||
if (field != null && !field.getReference().equals(preimage)) {
|
|
||||||
return fieldCache.map(field.getReference());
|
|
||||||
}
|
|
||||||
return createFieldNode(preimage, field);
|
|
||||||
}
|
}
|
||||||
|
return createFieldNode(preimage, field);
|
||||||
});
|
});
|
||||||
|
|
||||||
classCache = new CachedMapper<>(new Mapper<String, ClassDependency>() {
|
classCache = new CachedMapper<>(preimage -> createClassDependency(preimage));
|
||||||
@Override public ClassDependency map(String preimage) {
|
|
||||||
return createClassDependency(preimage);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
agent = new DependencyAgent(this);
|
agent = new DependencyAgent(this);
|
||||||
}
|
}
|
||||||
|
@ -183,20 +167,14 @@ public class DependencyChecker implements DependencyInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void schedulePropagation(final DependencyConsumer consumer, final DependencyType type) {
|
void schedulePropagation(DependencyConsumer consumer, DependencyType type) {
|
||||||
tasks.add(new Runnable() {
|
tasks.add(() -> consumer.consume(type));
|
||||||
@Override public void run() {
|
|
||||||
consumer.consume(type);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void schedulePropagation(final DependencyConsumer consumer, final DependencyType[] types) {
|
void schedulePropagation(DependencyConsumer consumer, DependencyType[] types) {
|
||||||
tasks.add(new Runnable() {
|
tasks.add(() -> {
|
||||||
@Override public void run() {
|
for (DependencyType type : types) {
|
||||||
for (DependencyType type : types) {
|
consumer.consume(type);
|
||||||
consumer.consume(type);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -215,12 +193,9 @@ public class DependencyChecker implements DependencyInfo {
|
||||||
added = classesAddedByRoot.add(className);
|
added = classesAddedByRoot.add(className);
|
||||||
}
|
}
|
||||||
if (!dep.isMissing() && added) {
|
if (!dep.isMissing() && added) {
|
||||||
tasks.add(new Runnable() {
|
tasks.add(() -> {
|
||||||
@Override
|
for (DependencyListener listener : listeners) {
|
||||||
public void run() {
|
listener.classReached(agent, className, callLocation);
|
||||||
for (DependencyListener listener : listeners) {
|
|
||||||
listener.classReached(agent, className, callLocation);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -289,11 +264,7 @@ public class DependencyChecker implements DependencyInfo {
|
||||||
ClassReader reader = cls.getClassReader();
|
ClassReader reader = cls.getClassReader();
|
||||||
final MethodReader method = reader.getMethod(new MethodDescriptor("<clinit>", void.class));
|
final MethodReader method = reader.getMethod(new MethodDescriptor("<clinit>", void.class));
|
||||||
if (method != null) {
|
if (method != null) {
|
||||||
tasks.add(new Runnable() {
|
tasks.add(() -> linkMethod(method.getReference(), callLocation).use());
|
||||||
@Override public void run() {
|
|
||||||
linkMethod(method.getReference(), callLocation).use();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,22 +340,18 @@ public class DependencyChecker implements DependencyInfo {
|
||||||
final MethodDependency dep = new MethodDependency(this, parameterNodes, paramCount, resultNode, thrown,
|
final MethodDependency dep = new MethodDependency(this, parameterNodes, paramCount, resultNode, thrown,
|
||||||
method, methodRef);
|
method, methodRef);
|
||||||
if (method != null) {
|
if (method != null) {
|
||||||
tasks.add(new Runnable() {
|
tasks.add(() -> {
|
||||||
@Override public void run() {
|
CallLocation caller = new CallLocation(dep.getMethod().getReference());
|
||||||
CallLocation caller = new CallLocation(dep.getMethod().getReference());
|
linkClass(dep.getMethod().getOwnerName(), caller).initClass(caller);
|
||||||
linkClass(dep.getMethod().getOwnerName(), caller).initClass(caller);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return dep;
|
return dep;
|
||||||
}
|
}
|
||||||
|
|
||||||
void scheduleMethodAnalysis(final MethodDependency dep) {
|
void scheduleMethodAnalysis(final MethodDependency dep) {
|
||||||
tasks.add(new Runnable() {
|
tasks.add(() -> {
|
||||||
@Override public void run() {
|
DependencyGraphBuilder graphBuilder = new DependencyGraphBuilder(DependencyChecker.this);
|
||||||
DependencyGraphBuilder graphBuilder = new DependencyGraphBuilder(DependencyChecker.this);
|
graphBuilder.buildGraph(dep);
|
||||||
graphBuilder.buildGraph(dep);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -414,11 +381,7 @@ public class DependencyChecker implements DependencyInfo {
|
||||||
}
|
}
|
||||||
FieldDependency dep = fieldCache.map(fieldRef);
|
FieldDependency dep = fieldCache.map(fieldRef);
|
||||||
if (!dep.isMissing()) {
|
if (!dep.isMissing()) {
|
||||||
tasks.add(new Runnable() {
|
tasks.add(() -> linkClass(fieldRef.getClassName(), location).initClass(location));
|
||||||
@Override public void run() {
|
|
||||||
linkClass(fieldRef.getClassName(), location).initClass(location);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
if (!dep.isMissing() && added) {
|
if (!dep.isMissing() && added) {
|
||||||
for (DependencyListener listener : listeners) {
|
for (DependencyListener listener : listeners) {
|
||||||
|
@ -438,18 +401,14 @@ public class DependencyChecker implements DependencyInfo {
|
||||||
return classCache.getKnown(className);
|
return classCache.getKnown(className);
|
||||||
}
|
}
|
||||||
|
|
||||||
private FieldDependency createFieldNode(final FieldReference fieldRef, FieldReader field) {
|
private FieldDependency createFieldNode(FieldReference fieldRef, FieldReader field) {
|
||||||
DependencyNode node = createNode();
|
DependencyNode node = createNode();
|
||||||
if (shouldLog) {
|
if (shouldLog) {
|
||||||
node.setTag(fieldRef.getClassName() + "#" + fieldRef.getFieldName());
|
node.setTag(fieldRef.getClassName() + "#" + fieldRef.getFieldName());
|
||||||
}
|
}
|
||||||
FieldDependency dep = new FieldDependency(node, field, fieldRef);
|
FieldDependency dep = new FieldDependency(node, field, fieldRef);
|
||||||
if (!dep.isMissing()) {
|
if (!dep.isMissing()) {
|
||||||
tasks.add(new Runnable() {
|
tasks.add(() -> linkClass(fieldRef.getClassName(), null).initClass(null));
|
||||||
@Override public void run() {
|
|
||||||
linkClass(fieldRef.getClassName(), null).initClass(null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return dep;
|
return dep;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.teavm.common.CachedMapper;
|
import org.teavm.common.CachedMapper;
|
||||||
import org.teavm.common.Mapper;
|
|
||||||
import org.teavm.diagnostics.Diagnostics;
|
import org.teavm.diagnostics.Diagnostics;
|
||||||
import org.teavm.model.ClassHolder;
|
import org.teavm.model.ClassHolder;
|
||||||
import org.teavm.model.ClassHolderTransformer;
|
import org.teavm.model.ClassHolderTransformer;
|
||||||
|
@ -38,11 +37,7 @@ class DependencyClassSource implements ClassReaderSource {
|
||||||
private Diagnostics diagnostics;
|
private Diagnostics diagnostics;
|
||||||
private Map<String, ClassHolder> generatedClasses = new HashMap<>();
|
private Map<String, ClassHolder> generatedClasses = new HashMap<>();
|
||||||
private List<ClassHolderTransformer> transformers = new ArrayList<>();
|
private List<ClassHolderTransformer> transformers = new ArrayList<>();
|
||||||
private CachedMapper<String, ClassReader> cache = new CachedMapper<>(new Mapper<String, ClassReader>() {
|
private CachedMapper<String, ClassReader> cache = new CachedMapper<>(preimage -> findAndTransformClass(preimage));
|
||||||
@Override public ClassReader map(String preimage) {
|
|
||||||
return findAndTransformClass(preimage);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
public DependencyClassSource(ClassReaderSource innerSource, Diagnostics diagnostics) {
|
public DependencyClassSource(ClassReaderSource innerSource, Diagnostics diagnostics) {
|
||||||
this.innerSource = innerSource;
|
this.innerSource = innerSource;
|
||||||
|
|
|
@ -236,12 +236,8 @@ class DependencyGraphBuilder {
|
||||||
methodDep.use();
|
methodDep.use();
|
||||||
DependencyNode[] targetParams = methodDep.getVariables();
|
DependencyNode[] targetParams = methodDep.getVariables();
|
||||||
if (parameters[0] != null && targetParams[0] != null) {
|
if (parameters[0] != null && targetParams[0] != null) {
|
||||||
parameters[0].connect(targetParams[0], new DependencyTypeFilter() {
|
parameters[0].connect(targetParams[0], thisType -> isAssignableFrom(checker.getClassSource(),
|
||||||
@Override public boolean match(DependencyType thisType) {
|
methodDep.getMethod().getOwnerName(), thisType.getName()));
|
||||||
return isAssignableFrom(checker.getClassSource(), methodDep.getMethod().getOwnerName(),
|
|
||||||
thisType.getName());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
for (int i = 1; i < parameters.length; ++i) {
|
for (int i = 1; i < parameters.length; ++i) {
|
||||||
if (parameters[i] != null && targetParams[i] != null) {
|
if (parameters[i] != null && targetParams[i] != null) {
|
||||||
|
@ -267,10 +263,8 @@ class DependencyGraphBuilder {
|
||||||
if (subtype.getParent() != null && isAssignableFrom(classSource, supertype, subtype.getParent())) {
|
if (subtype.getParent() != null && isAssignableFrom(classSource, supertype, subtype.getParent())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for (String iface : subtype.getInterfaces()) {
|
if (subtype.getInterfaces().stream().anyMatch(iface -> isAssignableFrom(classSource, supertype, iface))) {
|
||||||
if (isAssignableFrom(classSource, supertype, iface)) {
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -358,14 +352,12 @@ class DependencyGraphBuilder {
|
||||||
final ClassReader targetClass = dependencyChecker.getClassSource().get(targetClsName);
|
final ClassReader targetClass = dependencyChecker.getClassSource().get(targetClsName);
|
||||||
if (targetClass != null) {
|
if (targetClass != null) {
|
||||||
if (valueNode != null && receiverNode != null) {
|
if (valueNode != null && receiverNode != null) {
|
||||||
valueNode.connect(receiverNode, new DependencyTypeFilter() {
|
valueNode.connect(receiverNode, type -> {
|
||||||
@Override public boolean match(DependencyType type) {
|
if (targetClass.getName().equals("java.lang.Object")) {
|
||||||
if (targetClass.getName().equals("java.lang.Object")) {
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return isAssignableFrom(dependencyChecker.getClassSource(), targetClass.getName(),
|
|
||||||
type.getName());
|
|
||||||
}
|
}
|
||||||
|
return isAssignableFrom(dependencyChecker.getClassSource(), targetClass.getName(),
|
||||||
|
type.getName());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -514,11 +506,7 @@ class DependencyGraphBuilder {
|
||||||
DependencyNode arrayNode = nodes[array.getIndex()];
|
DependencyNode arrayNode = nodes[array.getIndex()];
|
||||||
final DependencyNode receiverNode = nodes[receiver.getIndex()];
|
final DependencyNode receiverNode = nodes[receiver.getIndex()];
|
||||||
if (arrayNode != null && receiverNode != null) {
|
if (arrayNode != null && receiverNode != null) {
|
||||||
arrayNode.addConsumer(new DependencyConsumer() {
|
arrayNode.addConsumer(type -> receiverNode.propagate(type));
|
||||||
@Override public void consume(DependencyType type) {
|
|
||||||
receiverNode.propagate(type);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
arrayNode.getArrayItem().connect(receiverNode.getArrayItem());
|
arrayNode.getArrayItem().connect(receiverNode.getArrayItem());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,11 +182,7 @@ public class DependencyNode implements ValueDependencyInfo {
|
||||||
if (DependencyChecker.shouldLog) {
|
if (DependencyChecker.shouldLog) {
|
||||||
arrayItemNode.tag = tag + "[";
|
arrayItemNode.tag = tag + "[";
|
||||||
}
|
}
|
||||||
arrayItemNode.addConsumer(new DependencyConsumer() {
|
arrayItemNode.addConsumer(type -> propagate(type));
|
||||||
@Override public void consume(DependencyType type) {
|
|
||||||
DependencyNode.this.propagate(type);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return arrayItemNode;
|
return arrayItemNode;
|
||||||
}
|
}
|
||||||
|
|
|
@ -378,7 +378,6 @@ class OptimizingVisitor implements StatementVisitor, ExprVisitor {
|
||||||
statements.remove(i + 1);
|
statements.remove(i + 1);
|
||||||
wieldTryCatch(first.getProtectedBody());
|
wieldTryCatch(first.getProtectedBody());
|
||||||
--i;
|
--i;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -359,7 +359,6 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
|
||||||
debugEmitter.emitClass(cls.getName());
|
debugEmitter.emitClass(cls.getName());
|
||||||
try {
|
try {
|
||||||
List<MethodNode> nonInitMethods = new ArrayList<>();
|
List<MethodNode> nonInitMethods = new ArrayList<>();
|
||||||
List<MethodNode> virtualMethods = new ArrayList<>();
|
|
||||||
MethodHolder clinit = classSource.get(cls.getName()).getMethod(
|
MethodHolder clinit = classSource.get(cls.getName()).getMethod(
|
||||||
new MethodDescriptor("<clinit>", ValueType.VOID));
|
new MethodDescriptor("<clinit>", ValueType.VOID));
|
||||||
List<MethodNode> clinitMethods = new ArrayList<>();
|
List<MethodNode> clinitMethods = new ArrayList<>();
|
||||||
|
@ -393,8 +392,6 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
|
||||||
if (!method.getModifiers().contains(NodeModifier.STATIC)) {
|
if (!method.getModifiers().contains(NodeModifier.STATIC)) {
|
||||||
if (method.getReference().getName().equals("<init>")) {
|
if (method.getReference().getName().equals("<init>")) {
|
||||||
renderInitializer(method);
|
renderInitializer(method);
|
||||||
} else {
|
|
||||||
virtualMethods.add(method);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -686,7 +683,7 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
|
||||||
variableNames.add(variableName(i));
|
variableNames.add(variableName(i));
|
||||||
}
|
}
|
||||||
TryCatchFinder tryCatchFinder = new TryCatchFinder();
|
TryCatchFinder tryCatchFinder = new TryCatchFinder();
|
||||||
for (AsyncMethodPart part : methodNode.getBody()) {
|
for (AsyncMethodPart part : methodNode.getBody()) {
|
||||||
if (!tryCatchFinder.tryCatchFound) {
|
if (!tryCatchFinder.tryCatchFound) {
|
||||||
part.getStatement().acceptVisitor(tryCatchFinder);
|
part.getStatement().acceptVisitor(tryCatchFinder);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public abstract class Expr implements Cloneable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Expr clone() {
|
public Expr clone() {
|
||||||
return clone(new HashMap<Expr, Expr>());
|
return clone(new HashMap<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Expr clone(Map<Expr, Expr> cache);
|
protected abstract Expr clone(Map<Expr, Expr> cache);
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
*/
|
*/
|
||||||
package org.teavm.model;
|
package org.teavm.model;
|
||||||
|
|
||||||
import org.teavm.common.Mapper;
|
|
||||||
import org.teavm.model.util.ModelUtils;
|
import org.teavm.model.util.ModelUtils;
|
||||||
import org.teavm.resource.MapperClassHolderSource;
|
import org.teavm.resource.MapperClassHolderSource;
|
||||||
|
|
||||||
|
@ -25,11 +24,7 @@ import org.teavm.resource.MapperClassHolderSource;
|
||||||
*/
|
*/
|
||||||
public class CopyClassHolderSource implements ClassHolderSource {
|
public class CopyClassHolderSource implements ClassHolderSource {
|
||||||
private ClassReaderSource innerSource;
|
private ClassReaderSource innerSource;
|
||||||
private MapperClassHolderSource mapperSource = new MapperClassHolderSource(new Mapper<String, ClassHolder>() {
|
private MapperClassHolderSource mapperSource = new MapperClassHolderSource(preimage -> copyClass(preimage));
|
||||||
@Override public ClassHolder map(String preimage) {
|
|
||||||
return copyClass(preimage);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
public CopyClassHolderSource(ClassReaderSource innerSource) {
|
public CopyClassHolderSource(ClassReaderSource innerSource) {
|
||||||
this.innerSource = innerSource;
|
this.innerSource = innerSource;
|
||||||
|
|
|
@ -44,7 +44,7 @@ class LocationGraphBuilder {
|
||||||
Deque<Step> stack = new ArrayDeque<>();
|
Deque<Step> stack = new ArrayDeque<>();
|
||||||
for (int i = 0; i < graph.size(); ++i) {
|
for (int i = 0; i < graph.size(); ++i) {
|
||||||
if (graph.incomingEdgesCount(i) == 0) {
|
if (graph.incomingEdgesCount(i) == 0) {
|
||||||
stack.push(new Step(null, new HashSet<InstructionLocation>(), i));
|
stack.push(new Step(null, new HashSet<>(), i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean[] visited = new boolean[graph.size()];
|
boolean[] visited = new boolean[graph.size()];
|
||||||
|
@ -84,8 +84,7 @@ class LocationGraphBuilder {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int next : graph.outgoingEdges(step.block)) {
|
for (int next : graph.outgoingEdges(step.block)) {
|
||||||
stack.push(new Step(location, started ? new HashSet<InstructionLocation>() : step.startLocations,
|
stack.push(new Step(location, started ? new HashSet<>() : step.startLocations, next));
|
||||||
next));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,7 +126,7 @@ public class GlobalValueNumbering implements MethodOptimization {
|
||||||
private List<List<Incoming>> findOutgoings(Program program) {
|
private List<List<Incoming>> findOutgoings(Program program) {
|
||||||
List<List<Incoming>> outgoings = new ArrayList<>();
|
List<List<Incoming>> outgoings = new ArrayList<>();
|
||||||
for (int i = 0; i < program.basicBlockCount(); ++i) {
|
for (int i = 0; i < program.basicBlockCount(); ++i) {
|
||||||
outgoings.add(new ArrayList<Incoming>());
|
outgoings.add(new ArrayList<>());
|
||||||
}
|
}
|
||||||
for (int i = 0; i < program.basicBlockCount(); ++i) {
|
for (int i = 0; i < program.basicBlockCount(); ++i) {
|
||||||
for (Phi phi : program.basicBlockAt(i).getPhis()) {
|
for (Phi phi : program.basicBlockAt(i).getPhis()) {
|
||||||
|
|
|
@ -125,12 +125,7 @@ public class ClasspathResourceMapper implements Mapper<String, ClassHolder>, Cla
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Mapper<String, String> classNameMapper = new Mapper<String, String>() {
|
private Mapper<String, String> classNameMapper = preimage -> renameClass(preimage);
|
||||||
@Override
|
|
||||||
public String map(String preimage) {
|
|
||||||
return renameClass(preimage);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Date getModificationDate(String className) {
|
public Date getModificationDate(String className) {
|
||||||
|
|
|
@ -122,8 +122,8 @@ public class SSATransformer {
|
||||||
List<List<TryCatchBlock>> caughtBlocks = new ArrayList<>();
|
List<List<TryCatchBlock>> caughtBlocks = new ArrayList<>();
|
||||||
List<List<Phi>> specialPhis = new ArrayList<>();
|
List<List<Phi>> specialPhis = new ArrayList<>();
|
||||||
for (int i = 0; i < program.basicBlockCount(); ++i) {
|
for (int i = 0; i < program.basicBlockCount(); ++i) {
|
||||||
caughtBlocks.add(new ArrayList<TryCatchBlock>());
|
caughtBlocks.add(new ArrayList<>());
|
||||||
specialPhis.add(new ArrayList<Phi>());
|
specialPhis.add(new ArrayList<>());
|
||||||
}
|
}
|
||||||
for (int i = 0; i < program.basicBlockCount(); ++i) {
|
for (int i = 0; i < program.basicBlockCount(); ++i) {
|
||||||
for (TryCatchBlock tryCatch : program.basicBlockAt(i).getTryCatchBlocks()) {
|
for (TryCatchBlock tryCatch : program.basicBlockAt(i).getTryCatchBlocks()) {
|
||||||
|
|
|
@ -254,24 +254,18 @@ public class TeaVMTestTool {
|
||||||
if (numThreads != 1) {
|
if (numThreads != 1) {
|
||||||
int threads = numThreads != 0 ? numThreads : Runtime.getRuntime().availableProcessors();
|
int threads = numThreads != 0 ? numThreads : Runtime.getRuntime().availableProcessors();
|
||||||
final ThreadPoolFiniteExecutor threadedExecutor = new ThreadPoolFiniteExecutor(threads);
|
final ThreadPoolFiniteExecutor threadedExecutor = new ThreadPoolFiniteExecutor(threads);
|
||||||
finalizer = new Runnable() {
|
finalizer = () -> threadedExecutor.stop();
|
||||||
@Override public void run() {
|
|
||||||
threadedExecutor.stop();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
executor = threadedExecutor;
|
executor = threadedExecutor;
|
||||||
}
|
}
|
||||||
for (final MethodReference method : testMethods) {
|
for (final MethodReference method : testMethods) {
|
||||||
final ClassHolderSource builderClassSource = classSource;
|
final ClassHolderSource builderClassSource = classSource;
|
||||||
executor.execute(new Runnable() {
|
executor.execute(() -> {
|
||||||
@Override public void run() {
|
log.debug("Building test for " + method);
|
||||||
log.debug("Building test for " + method);
|
try {
|
||||||
try {
|
decompileClassesForTest(classLoader, new CopyClassHolderSource(builderClassSource), method,
|
||||||
decompileClassesForTest(classLoader, new CopyClassHolderSource(builderClassSource), method,
|
fileNames.get(method));
|
||||||
fileNames.get(method));
|
} catch (IOException e) {
|
||||||
} catch (IOException e) {
|
log.error("Error generating JavaScript", e);
|
||||||
log.error("Error generating JavaScript", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
++methodsGenerated;
|
++methodsGenerated;
|
||||||
|
|
|
@ -350,11 +350,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AliasProvider aliasProvider = minifying ? new MinifyingAliasProvider() : new DefaultAliasProvider();
|
AliasProvider aliasProvider = minifying ? new MinifyingAliasProvider() : new DefaultAliasProvider();
|
||||||
dependencyChecker.setInterruptor(new DependencyCheckerInterruptor() {
|
dependencyChecker.setInterruptor(() -> progressListener.progressReached(0) == TeaVMProgressFeedback.CONTINUE);
|
||||||
@Override public boolean shouldContinue() {
|
|
||||||
return progressListener.progressReached(0) == TeaVMProgressFeedback.CONTINUE;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
dependencyChecker.linkMethod(new MethodReference(Class.class.getName(), "getClass",
|
dependencyChecker.linkMethod(new MethodReference(Class.class.getName(), "getClass",
|
||||||
ValueType.object("org.teavm.platform.PlatformClass"), ValueType.parse(Class.class)), null).use();
|
ValueType.object("org.teavm.platform.PlatformClass"), ValueType.parse(Class.class)), null).use();
|
||||||
dependencyChecker.linkMethod(new MethodReference(String.class, "<init>", char[].class, void.class),
|
dependencyChecker.linkMethod(new MethodReference(String.class, "<init>", char[].class, void.class),
|
||||||
|
|
|
@ -16,11 +16,12 @@
|
||||||
package org.teavm.common;
|
package org.teavm.common;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
import com.carrotsearch.hppc.IntOpenHashSet;
|
import com.carrotsearch.hppc.IntOpenHashSet;
|
||||||
import com.carrotsearch.hppc.IntSet;
|
import com.carrotsearch.hppc.IntSet;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,11 +78,7 @@ public class GraphTest {
|
||||||
builder.addEdge(5, 3);
|
builder.addEdge(5, 3);
|
||||||
Graph graph = builder.build();
|
Graph graph = builder.build();
|
||||||
|
|
||||||
int[][] sccs = GraphUtils.findStronglyConnectedComponents(graph, new int[] { 1, 2, 3 }, new GraphNodeFilter() {
|
int[][] sccs = GraphUtils.findStronglyConnectedComponents(graph, new int[] { 1, 2, 3 }, node -> node != 0);
|
||||||
@Override public boolean match(int node) {
|
|
||||||
return node != 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
sortSccs(sccs);
|
sortSccs(sccs);
|
||||||
|
|
||||||
assertThat(sccs.length, is(1));
|
assertThat(sccs.length, is(1));
|
||||||
|
@ -129,12 +126,7 @@ public class GraphTest {
|
||||||
builder.addEdge(8, 7);
|
builder.addEdge(8, 7);
|
||||||
Graph graph = builder.build();
|
Graph graph = builder.build();
|
||||||
|
|
||||||
int[][] sccs = GraphUtils.findStronglyConnectedComponents(graph, new int[] { 1, 2, 3, 4 },
|
int[][] sccs = GraphUtils.findStronglyConnectedComponents(graph, new int[] { 1, 2, 3, 4 }, node -> node != 0);
|
||||||
new GraphNodeFilter() {
|
|
||||||
@Override public boolean match(int node) {
|
|
||||||
return node != 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
sortSccs(sccs);
|
sortSccs(sccs);
|
||||||
|
|
||||||
assertThat(sccs.length, is(2));
|
assertThat(sccs.length, is(2));
|
||||||
|
@ -240,20 +232,12 @@ public class GraphTest {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private GraphNodeFilter filter = new GraphNodeFilter() {
|
private GraphNodeFilter filter = (int node) -> true;
|
||||||
@Override public boolean match(int node) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private void sortSccs(int[][] sccs) {
|
private void sortSccs(int[][] sccs) {
|
||||||
for (int i = 0; i < sccs.length; ++i) {
|
for (int i = 0; i < sccs.length; ++i) {
|
||||||
Arrays.sort(sccs[i]);
|
Arrays.sort(sccs[i]);
|
||||||
}
|
}
|
||||||
Arrays.sort(sccs, new Comparator<int[]>() {
|
Arrays.sort(sccs, (o1, o2) -> Integer.compare(o1[0], o2[0]));
|
||||||
@Override public int compare(int[] o1, int[] o2) {
|
|
||||||
return Integer.compare(o1[0], o2[0]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -99,18 +99,18 @@ public final class AsyncProgram {
|
||||||
boolean[] prime = new boolean[1000];
|
boolean[] prime = new boolean[1000];
|
||||||
prime[2] = true;
|
prime[2] = true;
|
||||||
prime[3] = true;
|
prime[3] = true;
|
||||||
nextPrime: for (int i = 5; i < prime.length; i += 2) {
|
nextPrime: for (int i = 5; i < prime.length; i += 2) {
|
||||||
int maxPrime = (int)Math.sqrt(i);
|
int maxPrime = (int)Math.sqrt(i);
|
||||||
for (int j = 3; j <= maxPrime; j += 2) {
|
for (int j = 3; j <= maxPrime; j += 2) {
|
||||||
Thread.yield();
|
Thread.yield();
|
||||||
if (prime[j] && i % j == 0) {
|
if (prime[j] && i % j == 0) {
|
||||||
continue nextPrime;
|
continue nextPrime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
prime[i] = true;
|
prime[i] = true;
|
||||||
}
|
}
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0; i < 1000; ++i) {
|
for (int i = 0; i < 1000; ++i) {
|
||||||
if (prime[i]) {
|
if (prime[i]) {
|
||||||
sb.append(i).append(' ');
|
sb.append(i).append(' ');
|
||||||
}
|
}
|
||||||
|
@ -144,9 +144,9 @@ public final class AsyncProgram {
|
||||||
|
|
||||||
private static void withoutAsync() {
|
private static void withoutAsync() {
|
||||||
report("Start sync");
|
report("Start sync");
|
||||||
for (int i = 0; i < 20; ++i) {
|
for (int i = 0; i < 20; ++i) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int j = 0; j <= i; ++j) {
|
for (int j = 0; j <= i; ++j) {
|
||||||
sb.append(j);
|
sb.append(j);
|
||||||
sb.append(' ');
|
sb.append(' ');
|
||||||
}
|
}
|
||||||
|
@ -157,9 +157,9 @@ public final class AsyncProgram {
|
||||||
|
|
||||||
private static void withAsync() throws InterruptedException {
|
private static void withAsync() throws InterruptedException {
|
||||||
report("Start async");
|
report("Start async");
|
||||||
for (int i = 0; i < 20; ++i) {
|
for (int i = 0; i < 20; ++i) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int j = 0; j <= i; ++j) {
|
for (int j = 0; j <= i; ++j) {
|
||||||
sb.append(j);
|
sb.append(j);
|
||||||
sb.append(' ');
|
sb.append(' ');
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,6 @@ package org.teavm.samples.storage;
|
||||||
|
|
||||||
import org.teavm.dom.browser.Storage;
|
import org.teavm.dom.browser.Storage;
|
||||||
import org.teavm.dom.browser.Window;
|
import org.teavm.dom.browser.Window;
|
||||||
import org.teavm.dom.events.Event;
|
|
||||||
import org.teavm.dom.events.EventListener;
|
|
||||||
import org.teavm.dom.html.HTMLButtonElement;
|
import org.teavm.dom.html.HTMLButtonElement;
|
||||||
import org.teavm.dom.html.HTMLDocument;
|
import org.teavm.dom.html.HTMLDocument;
|
||||||
import org.teavm.dom.html.HTMLElement;
|
import org.teavm.dom.html.HTMLElement;
|
||||||
|
@ -44,37 +42,28 @@ public final class Application {
|
||||||
}
|
}
|
||||||
|
|
||||||
HTMLButtonElement saveButton = (HTMLButtonElement)document.getElementById("save-button");
|
HTMLButtonElement saveButton = (HTMLButtonElement)document.getElementById("save-button");
|
||||||
saveButton.addEventListener("click", new EventListener() {
|
saveButton.addEventListener("click", e -> {
|
||||||
@Override
|
String key = ((HTMLInputElement)document.getElementById("key")).getValue();
|
||||||
public void handleEvent(Event evt) {
|
String value = ((HTMLInputElement)document.getElementById("value")).getValue();
|
||||||
String key = ((HTMLInputElement)document.getElementById("key")).getValue();
|
|
||||||
String value = ((HTMLInputElement)document.getElementById("value")).getValue();
|
|
||||||
|
|
||||||
if (key != null && key.length() > 0 && value != null && value.length() > 0) {
|
if (key != null && key.length() > 0 && value != null && value.length() > 0) {
|
||||||
storage.setItem(key, value);
|
storage.setItem(key, value);
|
||||||
draw();
|
draw();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
HTMLButtonElement deleteButton = (HTMLButtonElement)document.getElementById("delete-button");
|
HTMLButtonElement deleteButton = (HTMLButtonElement)document.getElementById("delete-button");
|
||||||
deleteButton.addEventListener("click", new EventListener() {
|
deleteButton.addEventListener("click", e -> {
|
||||||
@Override
|
String key = ((HTMLInputElement)document.getElementById("key")).getValue();
|
||||||
public void handleEvent(Event evt) {
|
|
||||||
String key = ((HTMLInputElement)document.getElementById("key")).getValue();
|
|
||||||
|
|
||||||
if (key != null && key.length() > 0) {
|
if (key != null && key.length() > 0) {
|
||||||
storage.removeItem(key);
|
storage.removeItem(key);
|
||||||
draw();
|
draw();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
HTMLButtonElement deleteAllButton = (HTMLButtonElement)document.getElementById("delete-all-button");
|
HTMLButtonElement deleteAllButton = (HTMLButtonElement)document.getElementById("delete-all-button");
|
||||||
deleteAllButton.addEventListener("click", new EventListener() {
|
deleteAllButton.addEventListener("click", e -> {
|
||||||
@Override
|
storage.clear();
|
||||||
public void handleEvent(Event evt) {
|
draw();
|
||||||
storage.clear();
|
|
||||||
draw();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
draw();
|
draw();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user