Tue, 22 Jul 2014 10:48:36 -0700
Merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | */ |
aoqi@0 | 23 | |
aoqi@0 | 24 | /** |
aoqi@0 | 25 | * JDK-8023373: allow super invocation for adapters |
aoqi@0 | 26 | * |
aoqi@0 | 27 | * @test |
aoqi@0 | 28 | * @run |
aoqi@0 | 29 | */ |
aoqi@0 | 30 | |
aoqi@0 | 31 | var CharArray = Java.type("char[]") |
aoqi@0 | 32 | var jString = Java.type("java.lang.String") |
aoqi@0 | 33 | var Character = Java.type("java.lang.Character") |
aoqi@0 | 34 | |
aoqi@0 | 35 | function capitalize(s) { |
aoqi@0 | 36 | if(s instanceof CharArray) { |
aoqi@0 | 37 | return new jString(s).toUpperCase() |
aoqi@0 | 38 | } |
aoqi@0 | 39 | if(s instanceof jString) { |
aoqi@0 | 40 | return s.toUpperCase() |
aoqi@0 | 41 | } |
aoqi@0 | 42 | return Character.toUpperCase(s) // must be int |
aoqi@0 | 43 | } |
aoqi@0 | 44 | |
aoqi@0 | 45 | var sw = new (Java.type("java.io.StringWriter")) |
aoqi@0 | 46 | |
aoqi@0 | 47 | var FilterWriterAdapter = Java.extend(Java.type("java.io.FilterWriter")) |
aoqi@0 | 48 | |
aoqi@0 | 49 | var cw = new FilterWriterAdapter(sw) { |
aoqi@0 | 50 | write: function(s, off, len) { |
aoqi@0 | 51 | s = capitalize(s) |
aoqi@0 | 52 | // Must handle overloads by arity |
aoqi@0 | 53 | if(off === undefined) { |
aoqi@0 | 54 | cw.super$write(s, 0, s.length()) |
aoqi@0 | 55 | } else if (typeof s === "string") { |
aoqi@0 | 56 | cw.super$write(s, off, len) |
aoqi@0 | 57 | } |
aoqi@0 | 58 | } |
aoqi@0 | 59 | } |
aoqi@0 | 60 | |
aoqi@0 | 61 | cw.write("abcd") |
aoqi@0 | 62 | cw.write("e".charAt(0)) |
aoqi@0 | 63 | cw.write("fgh".toCharArray()) |
aoqi@0 | 64 | cw.write("**ijk**", 2, 3) |
aoqi@0 | 65 | cw.write("***lmno**".toCharArray(), 3, 4) |
aoqi@0 | 66 | cw.flush() |
aoqi@0 | 67 | print(sw) |
aoqi@0 | 68 | |
aoqi@0 | 69 | // Can invoke super for Object methods |
aoqi@0 | 70 | print("cw has super hashCode(): " + (typeof cw.super$hashCode === "function")) |
aoqi@0 | 71 | print("cw has super equals(): " + (typeof cw.super$equals === "function")) |
aoqi@0 | 72 | // Can't invoke super for final methods |
aoqi@0 | 73 | print("cw has no super getClass(): " + (typeof cw.super$getClass === "undefined")) |
aoqi@0 | 74 | print("cw has no super wait(): " + (typeof cw.super$wait === "undefined")) |
aoqi@0 | 75 | |
aoqi@0 | 76 | var r = new (Java.type("java.lang.Runnable"))(function() {}) |
aoqi@0 | 77 | // Can't invoke super for abstract methods |
aoqi@0 | 78 | print("r has no super run(): " + (typeof r.super$run === "undefined")) |
aoqi@0 | 79 | // Interfaces can also invoke super Object methods |
aoqi@0 | 80 | print("r has super hashCode(): " + (typeof r.super$hashCode === "function")) |
aoqi@0 | 81 | print("r has super equals(): " + (typeof r.super$equals === "function")) |
aoqi@0 | 82 | // But still can't invoke final methods |
aoqi@0 | 83 | print("r has no super getClass(): " + (typeof r.super$getClass === "undefined")) |
aoqi@0 | 84 | print("r has no super wait(): " + (typeof r.super$wait === "undefined")) |