JS backend: fixed Map set/get -- should work with jet Map/MutableMap.
Added to PatternBuilder the ability to check that method has been overridden.
This commit is contained in:
@@ -5,9 +5,11 @@ import js.native
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.lang.*;
|
import java.lang.*;
|
||||||
|
|
||||||
|
|
||||||
native
|
native
|
||||||
public val noImpl : Nothing = throw Exception();
|
public val noImpl : Nothing = throw Exception()
|
||||||
|
|
||||||
|
/** Provides [] access to maps */
|
||||||
|
native public fun <K, V> MutableMap<K, V>.set(key: K, value: V): Unit = noImpl
|
||||||
|
|
||||||
library("println")
|
library("println")
|
||||||
public fun println() {}
|
public fun println() {}
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
package java.util
|
package java.util
|
||||||
|
|
||||||
import java.lang.*
|
|
||||||
|
|
||||||
/** Provides [] access to maps */
|
|
||||||
native
|
|
||||||
public fun <K, V> MutableMap<K, V>.set(key: K, value: V): Unit = noImpl
|
|
||||||
|
|
||||||
library("collectionsMax")
|
library("collectionsMax")
|
||||||
public fun max<T>(col: Collection<T>, comp: Comparator<T>): T = js.noImpl
|
public fun max<T>(col: Collection<T>, comp: Comparator<T>): T = js.noImpl
|
||||||
|
|
||||||
|
|||||||
+3
-4
@@ -159,11 +159,10 @@ public final class TopLevelFIF extends CompositeFIF {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
String[] javaUtil = {"java", "util"};
|
add(pattern("jet", "Map", "get").checkOverridden(), NATIVE_MAP_GET);
|
||||||
add(pattern(javaUtil, "set").receiverExists(), NATIVE_MAP_SET);
|
add(pattern("js", "set").receiverExists(), NATIVE_MAP_SET);
|
||||||
add(pattern("jet", "Map", "get"), NATIVE_MAP_GET);
|
|
||||||
add(pattern(javaUtil, "HashMap", "get"), NATIVE_MAP_GET);
|
|
||||||
|
|
||||||
|
String[] javaUtil = {"java", "util"};
|
||||||
add(pattern(javaUtil, "HashMap", "<init>"), new MapSelectImplementationIntrinsic(false));
|
add(pattern(javaUtil, "HashMap", "<init>"), new MapSelectImplementationIntrinsic(false));
|
||||||
add(pattern(javaUtil, "HashSet", "<init>"), new MapSelectImplementationIntrinsic(true));
|
add(pattern(javaUtil, "HashSet", "<init>"), new MapSelectImplementationIntrinsic(true));
|
||||||
}
|
}
|
||||||
|
|||||||
+61
-1
@@ -28,6 +28,7 @@ import org.jetbrains.k2js.translate.context.Namer;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public final class PatternBuilder {
|
public final class PatternBuilder {
|
||||||
|
|
||||||
@@ -141,6 +142,7 @@ public final class PatternBuilder {
|
|||||||
private boolean receiverParameterExists;
|
private boolean receiverParameterExists;
|
||||||
|
|
||||||
private String[] root;
|
private String[] root;
|
||||||
|
private boolean checkOverridden;
|
||||||
|
|
||||||
public DescriptorPredicateImpl(String... names) {
|
public DescriptorPredicateImpl(String... names) {
|
||||||
this.names = names;
|
this.names = names;
|
||||||
@@ -156,6 +158,41 @@ public final class PatternBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DescriptorPredicateImpl checkOverridden() {
|
||||||
|
this.checkOverridden = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean check(FunctionDescriptor functionDescriptor) {
|
||||||
|
DeclarationDescriptor descriptor = functionDescriptor.getContainingDeclaration();
|
||||||
|
String[] list;
|
||||||
|
int nameIndex;
|
||||||
|
if (root == null) {
|
||||||
|
list = names;
|
||||||
|
nameIndex = list.length - 2;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
assert names.length == 1;
|
||||||
|
list = root;
|
||||||
|
nameIndex = list.length - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (nameIndex == -1) {
|
||||||
|
return isRootNamespace(descriptor);
|
||||||
|
}
|
||||||
|
else if (isRootNamespace(descriptor)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!descriptor.getName().asString().equals(list[nameIndex--])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while ((descriptor = descriptor.getContainingDeclaration()) != null);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(@NotNull FunctionDescriptor functionDescriptor) {
|
public boolean apply(@NotNull FunctionDescriptor functionDescriptor) {
|
||||||
if ((functionDescriptor.getReceiverParameter() == null) == receiverParameterExists) {
|
if ((functionDescriptor.getReceiverParameter() == null) == receiverParameterExists) {
|
||||||
@@ -196,7 +233,30 @@ public final class PatternBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!descriptor.getName().asString().equals(list[nameIndex--])) {
|
if (!descriptor.getName().asString().equals(list[nameIndex--])) {
|
||||||
return false;
|
// we check overridden on any mismatch - we can have classes with equal name from different packages
|
||||||
|
return checkOverridden && checkOverridden(functionDescriptor);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkOverridden(FunctionDescriptor functionDescriptor) {
|
||||||
|
Set<? extends FunctionDescriptor> overriddenDescriptors = functionDescriptor.getOverriddenDescriptors();
|
||||||
|
if (overriddenDescriptors.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (FunctionDescriptor overridden : overriddenDescriptors) {
|
||||||
|
if (overridden.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
||||||
|
for (FunctionDescriptor realOverridden : overridden.getOverriddenDescriptors()) {
|
||||||
|
if (check(realOverridden) || checkOverridden(realOverridden)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (check(overridden) || checkOverridden(overridden)) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package foo
|
package foo
|
||||||
|
|
||||||
import java.util.*
|
import java.util.HashMap
|
||||||
|
|
||||||
native
|
native
|
||||||
val classes: Map<String, Any> = noImpl
|
val classes: Map<String, Any> = noImpl
|
||||||
|
|||||||
Reference in New Issue
Block a user