langtools/test/jdk/jshell/ModifiersTest.java
author rfield
Fri, 04 Nov 2016 14:47:25 -0700
changeset 41940 048d559e9da7
parent 41858 5843b57ce3a6
permissions -rw-r--r--
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers 8080354: JShell: Runtime visible annotations cannot be retrieved Reviewed-by: jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     1
/*
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     4
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     8
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    13
 * accompanied this code).
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    14
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    18
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    21
 * questions.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    22
 */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    23
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    24
/*
41940
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    25
 * @test 8167643 8129559
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    26
 * @summary Tests for modifiers
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    27
 * @build KullaTesting TestingInputStream ExpectedDiagnostic
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    28
 * @run testng ModifiersTest
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    29
 */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    30
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    31
import java.util.ArrayList;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    32
import java.util.List;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    33
41940
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    34
import java.util.function.Consumer;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    35
import javax.tools.Diagnostic;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    36
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    37
import org.testng.annotations.DataProvider;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    38
import org.testng.annotations.Test;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    39
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    40
@Test
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    41
public class ModifiersTest extends KullaTesting {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    42
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    43
    @DataProvider(name = "ignoredModifiers")
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    44
    public Object[][] getTestCases() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    45
        List<Object[]> testCases = new ArrayList<>();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    46
        String[] ignoredModifiers = new String[] {
41858
5843b57ce3a6 8167643: JShell: silently ignore access modifiers (as semantically irrelevant)
rfield
parents: 33362
diff changeset
    47
            "static", "final"
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    48
        };
41940
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    49
        String[] silentlyIgnoredModifiers = new String[] {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    50
            "public", "protected", "private"
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    51
        };
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    52
        String[] before = new String[] {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    53
            "strictfp", "abstract", "@X", "@X(value=9)"
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    54
        };
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    55
        String context = "@interface X { int value() default 0; }";
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    56
        Consumer<String> eval = this::assertEval;
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    57
        Consumer<String> evalWarn = s -> assertDeclareWarn1(s, "jdk.eval.warn.illegal.modifiers");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    58
        for (String ignoredModifier : ignoredModifiers) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    59
            for (ClassType classType : ClassType.values()) {
41940
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    60
                testCases.add(new Object[] { ignoredModifier, classType, evalWarn, "", null });
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    61
            }
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    62
        }
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    63
        for (String ignoredModifier : ignoredModifiers) {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    64
            for (String preface : before) {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    65
                testCases.add(new Object[] { ignoredModifier, ClassType.CLASS, evalWarn, preface, context});
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    66
            }
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    67
        }
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    68
        for (String ignoredModifier : silentlyIgnoredModifiers) {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    69
            for (ClassType classType : ClassType.values()) {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    70
                testCases.add(new Object[] { ignoredModifier, classType, eval, "", null });
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    71
            }
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    72
        }
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    73
        for (String ignoredModifier : silentlyIgnoredModifiers) {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    74
            for (String preface : before) {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    75
                testCases.add(new Object[] { ignoredModifier, ClassType.CLASS, eval, preface, context});
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    76
            }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    77
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    78
        return testCases.toArray(new Object[testCases.size()][]);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    79
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    80
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    81
    @Test(dataProvider = "ignoredModifiers")
41940
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    82
    public void ignoredModifiers(String modifier, ClassType classType,
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    83
            Consumer<String> eval, String preface, String context) {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    84
        if (context != null) {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    85
            assertEval(context);
41858
5843b57ce3a6 8167643: JShell: silently ignore access modifiers (as semantically irrelevant)
rfield
parents: 33362
diff changeset
    86
        }
41940
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    87
        String decl = String.format("%s %s %s A {}", preface, modifier, classType);
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    88
        eval.accept(decl);
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    89
        if (context != null) {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    90
            assertNumberOfActiveClasses(2);
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    91
            assertClasses(clazz(ClassType.ANNOTATION, "X"), clazz(classType, "A"));
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    92
        } else {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    93
            assertNumberOfActiveClasses(1);
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    94
            assertClasses(clazz(classType, "A"));
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 41858
diff changeset
    95
        }
41858
5843b57ce3a6 8167643: JShell: silently ignore access modifiers (as semantically irrelevant)
rfield
parents: 33362
diff changeset
    96
        assertActiveKeys();
5843b57ce3a6 8167643: JShell: silently ignore access modifiers (as semantically irrelevant)
rfield
parents: 33362
diff changeset
    97
    }
5843b57ce3a6 8167643: JShell: silently ignore access modifiers (as semantically irrelevant)
rfield
parents: 33362
diff changeset
    98
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    99
    public void accessToStaticFieldsOfClass() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   100
        assertEval("class A {" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   101
                "int x = 14;" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   102
                "static int y = 18;" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   103
                " }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   104
        assertDeclareFail("A.x;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   105
                new ExpectedDiagnostic("compiler.err.non-static.cant.be.ref", 0, 3, 1, -1, -1, Diagnostic.Kind.ERROR));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   106
        assertEval("A.y;", "18");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   107
        assertEval("new A().x;", "14");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   108
        assertEval("A.y = 88;", "88");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   109
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   110
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   111
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   112
    public void accessToStaticMethodsOfClass() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   113
        assertEval("class A {" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   114
                "void x() {}" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   115
                "static void y() {}" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   116
                " }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   117
        assertDeclareFail("A.x();",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   118
                new ExpectedDiagnostic("compiler.err.non-static.cant.be.ref", 0, 3, 1, -1, -1, Diagnostic.Kind.ERROR));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   119
        assertEval("A.y();");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   120
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   121
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   122
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   123
    public void accessToStaticFieldsOfInterface() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   124
        assertEval("interface A {" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   125
                "int x = 14;" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   126
                "static int y = 18;" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   127
                " }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   128
        assertEval("A.x;", "14");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   129
        assertEval("A.y;", "18");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   130
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   131
        assertDeclareFail("A.x = 18;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   132
                new ExpectedDiagnostic("compiler.err.cant.assign.val.to.final.var", 0, 3, 1, -1, -1, Diagnostic.Kind.ERROR));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   133
        assertDeclareFail("A.y = 88;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   134
                new ExpectedDiagnostic("compiler.err.cant.assign.val.to.final.var", 0, 3, 1, -1, -1, Diagnostic.Kind.ERROR));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   135
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   136
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   137
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   138
    public void accessToStaticMethodsOfInterface() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   139
        assertEval("interface A { static void x() {} }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   140
        assertEval("A.x();");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   141
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   142
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   143
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   144
    public void finalMethod() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   145
        assertEval("class A { final void f() {} }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   146
        assertDeclareFail("class B extends A { void f() {} }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   147
                new ExpectedDiagnostic("compiler.err.override.meth", 20, 31, 25, -1, -1, Diagnostic.Kind.ERROR));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   148
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   149
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   150
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   151
    //TODO: is this the right semantics?
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   152
    public void finalConstructor() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   153
        assertDeclareFail("class A { final A() {} }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   154
                new ExpectedDiagnostic("compiler.err.mod.not.allowed.here", 10, 22, 16, -1, -1, Diagnostic.Kind.ERROR));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   155
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   156
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   157
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   158
    //TODO: is this the right semantics?
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   159
    public void finalDefaultMethod() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   160
        assertDeclareFail("interface A { final default void a() {} }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   161
                new ExpectedDiagnostic("compiler.err.mod.not.allowed.here", 14, 39, 33, -1, -1, Diagnostic.Kind.ERROR));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   162
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   163
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   164
}