# HG changeset patch # User Jaroslav Tulach # Date 1452859715 -3600 # Node ID f21fa2508650d498bdd4f4c46298cdff2afac8d0 # Parent 6429e051b1de46c663ff766cdf3ed4dbc85b8824# Parent b189d001b9bd43056c3e5353c4e71f2a0d4b121b Merge of various fixes into main development line diff -r 6429e051b1de -r f21fa2508650 boot/src/main/java/org/netbeans/html/boot/impl/JavaScriptProcesor.java --- a/boot/src/main/java/org/netbeans/html/boot/impl/JavaScriptProcesor.java Wed Jan 13 05:53:12 2016 +0100 +++ b/boot/src/main/java/org/netbeans/html/boot/impl/JavaScriptProcesor.java Fri Jan 15 13:08:35 2016 +0100 @@ -72,10 +72,10 @@ import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import javax.lang.model.type.ArrayType; -import javax.lang.model.type.DeclaredType; import javax.lang.model.type.ExecutableType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.Types; import javax.tools.Diagnostic; import javax.tools.FileObject; import javax.tools.StandardLocation; @@ -302,7 +302,8 @@ tm = ((ArrayType)tm).getComponentType(); } sb.append('L'); - Element elm = processingEnv.getTypeUtils().asElement(tm); + Types tu = processingEnv.getTypeUtils(); + Element elm = tu.asElement(tu.erasure(tm)); dumpElems(sb, elm, ';'); } } @@ -414,7 +415,7 @@ return; } final TypeElement selfType = (TypeElement)m.getEnclosingElement(); - + Types tu = processingEnv.getTypeUtils(); source.append("\n public java.lang.Object ") .append(mangled) @@ -424,7 +425,7 @@ StringBuilder convert = new StringBuilder(); if (!isStatic) { if (selfObj) { - source.append("Object self"); + source.append("java.lang.Object self"); convert.append(" if (p instanceof org.netbeans.html.boot.spi.Fn.FromJavaScript) {\n"); convert.append(" self"). append(" = ((org.netbeans.html.boot.spi.Fn.FromJavaScript)p).toJava(self"). @@ -443,7 +444,7 @@ ++cnt; final TypeMirror t = ve.asType(); if (!t.getKind().isPrimitive() && !"java.lang.String".equals(t.toString())) { // NOI18N - source.append("Object"); + source.append("java.lang.Object"); convert.append(" if (p instanceof org.netbeans.html.boot.spi.Fn.FromJavaScript) {\n"); convert.append(" arg").append(cnt). append(" = ((org.netbeans.html.boot.spi.Fn.FromJavaScript)p).toJava(arg").append(cnt). @@ -464,7 +465,7 @@ } source.append(" "); if (m.getReturnType().getKind() != TypeKind.VOID) { - source.append("Object $ret = "); + source.append("java.lang.Object $ret = "); } if (isStatic) { source.append(((TypeElement)m.getEnclosingElement()).getQualifiedName()); @@ -484,7 +485,7 @@ sep = ""; for (VariableElement ve : m.getParameters()) { source.append(sep); - source.append("(").append(ve.asType()); + source.append("(").append(tu.erasure(ve.asType())); source.append(")arg").append(++cnt); sep = ", "; } diff -r 6429e051b1de -r f21fa2508650 boot/src/test/java/org/netbeans/html/boot/impl/CountFnCreationTest.java --- a/boot/src/test/java/org/netbeans/html/boot/impl/CountFnCreationTest.java Wed Jan 13 05:53:12 2016 +0100 +++ b/boot/src/test/java/org/netbeans/html/boot/impl/CountFnCreationTest.java Fri Jan 15 13:08:35 2016 +0100 @@ -49,8 +49,6 @@ import java.net.URL; import java.util.Collection; import java.util.Enumeration; -import java.util.logging.Level; -import java.util.logging.Logger; import net.java.html.js.JavaScriptBody; import net.java.html.js.JavaScriptResource; import org.netbeans.html.boot.spi.Fn; @@ -118,7 +116,7 @@ } @Override - public Object invoke(Object thiz, Object... args) throws Exception { + public java.lang.Object invoke(java.lang.Object thiz, java.lang.Object... args) throws Exception { return null; } } diff -r 6429e051b1de -r f21fa2508650 boot/src/test/java/org/netbeans/html/boot/impl/FnTest.java --- a/boot/src/test/java/org/netbeans/html/boot/impl/FnTest.java Wed Jan 13 05:53:12 2016 +0100 +++ b/boot/src/test/java/org/netbeans/html/boot/impl/FnTest.java Fri Jan 15 13:08:35 2016 +0100 @@ -106,16 +106,16 @@ sb.append("};"); sb.append("})()"); try { - final Object val = eng.eval(sb.toString()); + final java.lang.Object val = eng.eval(sb.toString()); return new Fn(this) { @Override - public Object invoke(Object thiz, Object... args) throws Exception { - List all = new ArrayList(args.length + 1); + public java.lang.Object invoke(java.lang.Object thiz, java.lang.Object... args) throws Exception { + List all = new ArrayList(args.length + 1); all.add(thiz == null ? val : thiz); all.addAll(Arrays.asList(args)); Invocable inv = (Invocable)eng; try { - Object ret = inv.invokeMethod(val, "call", all.toArray()); + java.lang.Object ret = inv.invokeMethod(val, "call", all.toArray()); return val.equals(ret) ? null : ret; } catch (ScriptException ex) { throw ex; diff -r 6429e051b1de -r f21fa2508650 boot/src/test/java/org/netbeans/html/boot/impl/JavaScriptProcesorTest.java --- a/boot/src/test/java/org/netbeans/html/boot/impl/JavaScriptProcesorTest.java Wed Jan 13 05:53:12 2016 +0100 +++ b/boot/src/test/java/org/netbeans/html/boot/impl/JavaScriptProcesorTest.java Fri Jan 15 13:08:35 2016 +0100 @@ -155,7 +155,7 @@ @Test public void generatesCallbacksThatReturnObject() throws Exception { Class callbacksForTestPkg = Class.forName("org.netbeans.html.boot.impl.$JsCallbacks$"); Method m = callbacksForTestPkg.getDeclaredMethod("java_lang_Runnable$run$", Runnable.class); - assertEquals(m.getReturnType(), Object.class, "All methods always return object"); + assertEquals(m.getReturnType(), java.lang.Object.class, "All methods always return object"); } @Test public void hasInstanceField() throws Exception { diff -r 6429e051b1de -r f21fa2508650 boot/src/test/java/org/netbeans/html/boot/impl/JsClassLoaderBase.java --- a/boot/src/test/java/org/netbeans/html/boot/impl/JsClassLoaderBase.java Wed Jan 13 05:53:12 2016 +0100 +++ b/boot/src/test/java/org/netbeans/html/boot/impl/JsClassLoaderBase.java Fri Jan 15 13:08:35 2016 +0100 @@ -46,8 +46,8 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.logging.Level; -import java.util.logging.Logger; +import java.util.HashMap; +import java.util.Map; import org.netbeans.html.boot.spi.Fn; import org.testng.Assert; import static org.testng.Assert.*; @@ -72,7 +72,7 @@ @Test public void noParamMethod() throws Throwable { Method plus = methodClass.getMethod("fortyTwo"); try { - final Object val = plus.invoke(null); + final java.lang.Object val = plus.invoke(null); assertTrue(val instanceof Number, "A number returned " + val); assertEquals(((Number)val).intValue(), 42); } catch (InvocationTargetException ex) { @@ -100,7 +100,7 @@ @Test public void instanceMethod() throws Throwable { Method plus = methodClass.getMethod("plusInst", int.class); - Object inst = methodClass.newInstance(); + java.lang.Object inst = methodClass.newInstance(); try { assertEquals(plus.invoke(inst, 10), 10); } catch (InvocationTargetException ex) { @@ -118,7 +118,7 @@ } @Test public void getThis() throws Throwable { - Object th = methodClass.newInstance(); + java.lang.Object th = methodClass.newInstance(); Method st = methodClass.getMethod("getThis"); try { assertEquals(st.invoke(th), th); @@ -166,7 +166,7 @@ @Test public void callJavaScriptMethodOnOwnClass() throws Throwable { try { - Object thiz = methodClass.newInstance(); + java.lang.Object thiz = methodClass.newInstance(); Method st = methodClass.getMethod("returnYourSelf", methodClass); assertEquals(st.invoke(null, thiz), thiz, "Returns this"); } catch (InvocationTargetException ex) { @@ -190,7 +190,7 @@ Class enmClazz2 = enmClazz.asSubclass(Enum.class); Method st = methodClass.getMethod("fromEnum", enmClazz); - Object valueB = Enum.valueOf(enmClazz2, "B"); + java.lang.Object valueB = Enum.valueOf(enmClazz2, "B"); assertEquals(st.invoke(null, valueB), "B", "Converts to string"); } @@ -210,7 +210,7 @@ } @Test public void recordError() throws Throwable { - Method st = methodClass.getMethod("recordError", Object.class); + Method st = methodClass.getMethod("recordError", java.lang.Object.class); assertEquals(st.invoke(methodClass.newInstance(), "Hello"), "Hello", "The same parameter returned"); } @@ -239,18 +239,25 @@ @Test public void arrayInOut() throws Throwable { String[] arr = { "Ahoj" }; - Method st = methodClass.getMethod("arr", Object[].class); - Object ret = st.invoke(null, (Object) arr); - assertTrue(ret instanceof Object[], "Expecting array: " + ret); - Object[] res = (Object[]) ret; + Method st = methodClass.getMethod("arr", java.lang.Object[].class); + java.lang.Object ret = st.invoke(null, (java.lang.Object) arr); + assertTrue(ret instanceof java.lang.Object[], "Expecting array: " + ret); + java.lang.Object[] res = (java.lang.Object[]) ret; assertEquals(res.length, 1, "One element"); assertEquals(res[0], "Ahoj", "The right string"); } + + @Test public void parametricCallback() throws Throwable { + Map map = new HashMap(); + Method st = methodClass.getMethod("callParamTypes", Map.class, int.class); + st.invoke(null, map, 42); + assertEquals(map.get("key"), Integer.valueOf(42), "The right value"); + } @Test public void checkTheTypeOfThrownException() throws Throwable { FnContext.currentPresenter(null); assertNull(Fn.activePresenter(), "No presenter is activer right now"); - Object res = null; + java.lang.Object res = null; try { Method st = methodClass.getMethod("plus", int.class, int.class); try { diff -r 6429e051b1de -r f21fa2508650 boot/src/test/java/org/netbeans/html/boot/impl/JsClassLoaderTest.java --- a/boot/src/test/java/org/netbeans/html/boot/impl/JsClassLoaderTest.java Wed Jan 13 05:53:12 2016 +0100 +++ b/boot/src/test/java/org/netbeans/html/boot/impl/JsClassLoaderTest.java Fri Jan 15 13:08:35 2016 +0100 @@ -44,7 +44,6 @@ import java.io.Closeable; import java.io.Reader; -import org.netbeans.html.boot.spi.Fn; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; @@ -56,6 +55,7 @@ import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; +import org.netbeans.html.boot.spi.Fn; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; @@ -101,16 +101,16 @@ sb.append("};"); sb.append("})()"); try { - final Object val = eng.eval(sb.toString()); + final java.lang.Object val = eng.eval(sb.toString()); return new Fn(this) { @Override - public Object invoke(Object thiz, Object... args) throws Exception { - List all = new ArrayList(args.length + 1); + public java.lang.Object invoke(java.lang.Object thiz, java.lang.Object... args) throws Exception { + List all = new ArrayList(args.length + 1); all.add(thiz == null ? val : thiz); all.addAll(Arrays.asList(args)); Invocable inv = (Invocable)eng; try { - Object ret = inv.invokeMethod(val, "call", all.toArray()); + java.lang.Object ret = inv.invokeMethod(val, "call", all.toArray()); return val.equals(ret) ? null : ret; } catch (Exception ex) { throw ex; diff -r 6429e051b1de -r f21fa2508650 boot/src/test/java/org/netbeans/html/boot/impl/JsMethods.java --- a/boot/src/test/java/org/netbeans/html/boot/impl/JsMethods.java Wed Jan 13 05:53:12 2016 +0100 +++ b/boot/src/test/java/org/netbeans/html/boot/impl/JsMethods.java Fri Jan 15 13:08:35 2016 +0100 @@ -42,6 +42,7 @@ */ package org.netbeans.html.boot.impl; +import java.util.Map; import net.java.html.js.JavaScriptBody; import net.java.html.js.JavaScriptResource; @@ -52,10 +53,10 @@ */ @JavaScriptResource("jsmethods.js") public class JsMethods { - private Object value; + private java.lang.Object value; @JavaScriptBody(args = {}, body = "return 42;") - public static Object fortyTwo() { + public static java.lang.Object fortyTwo() { return -42; } @@ -66,10 +67,10 @@ public static native int plus(int x); @JavaScriptBody(args = {}, body = "return this;") - public static native Object staticThis(); + public static native java.lang.Object staticThis(); @JavaScriptBody(args = {}, body = "return this;") - public native Object getThis(); + public native java.lang.Object getThis(); @JavaScriptBody(args = {"x"}, body = "return x;") public native int plusInst(int x); @@ -110,7 +111,7 @@ public static native String fromEnum(Enm v); @JavaScriptBody(args = "arr", body = "return arr;") - public static native Object[] arr(Object[] arr); + public static native java.lang.Object[] arr(java.lang.Object[] arr); @JavaScriptBody(args = { "useA", "useB", "a", "b" }, body = "var l = 0;" + "if (useA) l += a;\n" @@ -119,11 +120,11 @@ ) public static native long chooseLong(boolean useA, boolean useB, long a, long b); - protected void onError(Object o) throws Exception { + protected void onError(java.lang.Object o) throws Exception { value = o; } - Object getError() { + java.lang.Object getError() { return value; } @@ -131,7 +132,7 @@ "this.@org.netbeans.html.boot.impl.JsMethods::onError(Ljava/lang/Object;)(err);" + "return this.@org.netbeans.html.boot.impl.JsMethods::getError()();" ) - public native Object recordError(Object err); + public native java.lang.Object recordError(java.lang.Object err); @JavaScriptBody(args = { "x", "y" }, body = "return x + y;") public static int plusOrMul(int x, int y) { @@ -139,9 +140,15 @@ } @JavaScriptBody(args = { "x" }, keepAlive = false, body = "throw 'Do not call me!'") - public static native int checkAllowGC(Object x); + public static native int checkAllowGC(java.lang.Object x); + + @JavaScriptBody(args = { "map", "value" }, javacall = true, body = + "map.@java.util.Map::put(Ljava/lang/Object;Ljava/lang/Object;)('key',value);" + ) + public static native void callParamTypes(Map map, int value); enum Enm { A, B; } } + diff -r 6429e051b1de -r f21fa2508650 boot/src/test/java/org/netbeans/html/boot/impl/KeepAliveTest.java --- a/boot/src/test/java/org/netbeans/html/boot/impl/KeepAliveTest.java Wed Jan 13 05:53:12 2016 +0100 +++ b/boot/src/test/java/org/netbeans/html/boot/impl/KeepAliveTest.java Fri Jan 15 13:08:35 2016 +0100 @@ -48,8 +48,6 @@ import java.util.Collection; import org.netbeans.html.boot.spi.Fn; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -57,7 +55,7 @@ private Class jsMethods; @Test public void keepAliveIsSetToFalse() throws Exception { Closeable c = Fn.activate(this); - Number ret = (Number)jsMethods.getMethod("checkAllowGC", Object.class).invoke(null, this); + Number ret = (Number)jsMethods.getMethod("checkAllowGC", java.lang.Object.class).invoke(null, this); c.close(); assertEquals(ret.intValue(), 0, "keepAlive is set to false"); } @@ -79,7 +77,7 @@ public Fn defineFn(String code, String[] names, final boolean[] keepAlive) { return new Fn(this) { @Override - public Object invoke(Object thiz, Object... args) throws Exception { + public java.lang.Object invoke(java.lang.Object thiz, java.lang.Object... args) throws Exception { boolean res = true; if (keepAlive != null) { for (int i = 0; i < keepAlive.length; i++) { diff -r 6429e051b1de -r f21fa2508650 boot/src/test/java/org/netbeans/html/boot/impl/Object.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/boot/src/test/java/org/netbeans/html/boot/impl/Object.java Fri Jan 15 13:08:35 2016 +0100 @@ -0,0 +1,49 @@ +/** + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.html.boot.impl; + +/** Fake class to cause confusion in the generated code and force it + * to use fully qualified names + */ +final class Object { +}