nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/AdaptationResult.java
author attila
Mon, 12 Jan 2015 11:29:42 +0100
changeset 28319 95bed8b1847f
parent 25865 d38d876f1654
child 35330 7cc832bade3c
permissions -rw-r--r--
8068580: make JavaAdapterFactory.isAutoConvertibleFromFunction more robust Reviewed-by: lagergren, sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16777
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
     1
/*
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
     4
 *
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    10
 *
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    15
 * accompanied this code).
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    16
 *
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    20
 *
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    23
 * questions.
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    24
 */
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    25
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    26
package jdk.nashorn.internal.runtime.linker;
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    27
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    28
import jdk.nashorn.internal.runtime.ECMAErrors;
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    29
import jdk.nashorn.internal.runtime.ECMAException;
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    30
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    31
/**
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    32
 * A result of generating an adapter for a class. A tuple of an outcome and - in case of an error outcome - a list of
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    33
 * classes that caused the error.
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    34
 */
19105
a01ba9d17eab 8021571: @fork tests should use VM options passed from project.properties
sundar
parents: 16777
diff changeset
    35
final class AdaptationResult {
16777
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    36
    /**
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    37
     * Contains various outcomes for attempting to generate an adapter class. These are stored in AdapterInfo instances.
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    38
     * We have a successful outcome (adapter class was generated) and four possible error outcomes: superclass is final,
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    39
     * superclass is not public, superclass has no public or protected constructor, more than one superclass was
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    40
     * specified. We don't throw exceptions when we try to generate the adapter, but rather just record these error
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    41
     * conditions as they are still useful as partial outcomes, as Nashorn's linker can still successfully check whether
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    42
     * the class can be autoconverted from a script function even when it is not possible to generate an adapter for it.
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    43
     */
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    44
    enum Outcome {
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    45
        SUCCESS,
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    46
        ERROR_FINAL_CLASS,
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    47
        ERROR_NON_PUBLIC_CLASS,
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    48
        ERROR_NO_ACCESSIBLE_CONSTRUCTOR,
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    49
        ERROR_MULTIPLE_SUPERCLASSES,
22669
75563515567f 8032681: Issues with Nashorn
attila
parents: 19105
diff changeset
    50
        ERROR_NO_COMMON_LOADER,
28319
95bed8b1847f 8068580: make JavaAdapterFactory.isAutoConvertibleFromFunction more robust
attila
parents: 25865
diff changeset
    51
        ERROR_FINAL_FINALIZER,
95bed8b1847f 8068580: make JavaAdapterFactory.isAutoConvertibleFromFunction more robust
attila
parents: 25865
diff changeset
    52
        ERROR_OTHER
16777
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    53
    }
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    54
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    55
    static final AdaptationResult SUCCESSFUL_RESULT = new AdaptationResult(Outcome.SUCCESS, "");
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    56
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    57
    private final Outcome outcome;
28319
95bed8b1847f 8068580: make JavaAdapterFactory.isAutoConvertibleFromFunction more robust
attila
parents: 25865
diff changeset
    58
    private final String[] messageArgs;
16777
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    59
28319
95bed8b1847f 8068580: make JavaAdapterFactory.isAutoConvertibleFromFunction more robust
attila
parents: 25865
diff changeset
    60
    AdaptationResult(final Outcome outcome, final String... messageArgs) {
16777
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    61
        this.outcome = outcome;
28319
95bed8b1847f 8068580: make JavaAdapterFactory.isAutoConvertibleFromFunction more robust
attila
parents: 25865
diff changeset
    62
        this.messageArgs = messageArgs;
16777
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    63
    }
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    64
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    65
    Outcome getOutcome() {
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    66
        return outcome;
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    67
    }
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    68
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    69
    ECMAException typeError() {
28319
95bed8b1847f 8068580: make JavaAdapterFactory.isAutoConvertibleFromFunction more robust
attila
parents: 25865
diff changeset
    70
        return ECMAErrors.typeError("extend." + outcome, messageArgs);
16777
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    71
    }
207a993adb9a 8011544: Allow subclassing Java classes from script without creating instances
attila
parents:
diff changeset
    72
}