Fix of exporting a wasm function for scala objects (#498). Fix #497

Co-authored-by: VGORDIEVSKII <vgordievskii@luxoft.com>
This commit is contained in:
Vladislav Gordievskiy 2020-05-18 09:08:28 +02:00 committed by GitHub
parent 333ee95604
commit 6892c4f0ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,6 +16,9 @@
package org.teavm.classlib.impl;
import java.util.Properties;
import org.teavm.interop.Export;
import org.teavm.model.AnnotationContainer;
import org.teavm.model.AnnotationHolder;
import org.teavm.model.BasicBlock;
import org.teavm.model.ClassHierarchy;
import org.teavm.model.ClassHolder;
@ -32,6 +35,8 @@ import org.teavm.model.instructions.PutFieldInstruction;
public class ScalaHacks implements ClassHolderTransformer {
private static final String ATTR_NAME_CLASS = "java.util.jar.Attributes$Name";
private static final String SCALA_INTERNAL_CLASS_MARKER = "$";
@Override
public void transformClass(ClassHolder cls, ClassHolderTransformerContext context) {
switch (cls.getName()) {
@ -41,6 +46,12 @@ public class ScalaHacks implements ClassHolderTransformer {
case "scala.util.Properties$":
transformProperties(cls);
break;
default:
{
if (cls.getName().endsWith(SCALA_INTERNAL_CLASS_MARKER)) {
checkAndRemoveExportAnnotation(cls);
}
} break;
}
}
@ -86,4 +97,14 @@ public class ScalaHacks implements ClassHolderTransformer {
}
}
}
private void checkAndRemoveExportAnnotation(ClassHolder cls) {
for (MethodHolder method : cls.getMethods()) {
AnnotationContainer items = method.getAnnotations();
AnnotationHolder exportAnn = items.get(Export.class.getTypeName());
if (exportAnn != null) {
method.getAnnotations().remove(exportAnn);
}
}
}
}