From 6892c4f0cabeac7345d3c963c9c630641320847a Mon Sep 17 00:00:00 2001 From: Vladislav Gordievskiy Date: Mon, 18 May 2020 09:08:28 +0200 Subject: [PATCH] Fix of exporting a wasm function for scala objects (#498). Fix #497 Co-authored-by: VGORDIEVSKII --- .../org/teavm/classlib/impl/ScalaHacks.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/classlib/src/main/java/org/teavm/classlib/impl/ScalaHacks.java b/classlib/src/main/java/org/teavm/classlib/impl/ScalaHacks.java index d7721628a..3c4918feb 100644 --- a/classlib/src/main/java/org/teavm/classlib/impl/ScalaHacks.java +++ b/classlib/src/main/java/org/teavm/classlib/impl/ScalaHacks.java @@ -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); + } + } + } }