From 68522811f2116fd53279e4cab6b7cf870e148bfa Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Wed, 23 Jan 2019 19:24:42 +0300 Subject: [PATCH] Fix issue with incremental compilation and JSBody annotation --- .../org/teavm/jso/impl/JSClassProcessor.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java b/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java index f0e702957..48b91b2ae 100644 --- a/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java +++ b/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java @@ -77,7 +77,6 @@ class JSClassProcessor { private final List replacement = new ArrayList<>(); private final JSTypeHelper typeHelper; private final Diagnostics diagnostics; - private int methodIndexGenerator; private final Map overriddenMethodCache = new HashMap<>(); private JSValueMarshaller marshaller; private IncrementalDependencyRegistration incrementalCache; @@ -576,9 +575,12 @@ class JSClassProcessor { ? ValueType.VOID : ValueType.parse(JSObject.class); + ClassReader ownerClass = classSource.get(methodToProcess.getOwnerName()); + int methodIndex = indexOfMethod(ownerClass, methodToProcess); + // create proxy method MethodReference proxyMethod = new MethodReference(methodToProcess.getOwnerName(), - methodToProcess.getName() + "$js_body$_" + methodIndexGenerator++, proxyParamTypes); + methodToProcess.getName() + "$js_body$_" + methodIndex, proxyParamTypes); String script = bodyAnnot.getValue("script").getString(); String[] parameterNames = paramsValue != null ? paramsValue.getList().stream() .map(AnnotationValue::getString) @@ -617,6 +619,17 @@ class JSClassProcessor { } } + private int indexOfMethod(ClassReader cls, MethodReader method) { + int index = 0; + for (MethodReader m : cls.getMethods()) { + if (m.getDescriptor().equals(method.getDescriptor())) { + return index; + } + ++index; + } + return -1; + } + void createJSMethods(ClassHolder cls) { for (MethodHolder method : cls.getMethods().toArray(new MethodHolder[0])) { MethodReference methodRef = method.getReference();