< prev index next >

test/langtools/jdk/jshell/ClassesTest.java

Print this page


   1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8145239 8129559 8080354 8189248
  27  * @summary Tests for EvaluationState.classes
  28  * @build KullaTesting TestingInputStream ExpectedDiagnostic
  29  * @run testng ClassesTest
  30  */
  31 
  32 import java.util.ArrayList;
  33 import java.util.List;
  34 
  35 import javax.tools.Diagnostic;
  36 
  37 import jdk.jshell.Snippet;
  38 import jdk.jshell.TypeDeclSnippet;
  39 import jdk.jshell.VarSnippet;
  40 import org.testng.annotations.DataProvider;
  41 import org.testng.annotations.Test;
  42 
  43 import jdk.jshell.Diag;
  44 import jdk.jshell.Snippet.Status;
  45 import static java.util.stream.Collectors.toList;
  46 import static jdk.jshell.Snippet.Status.VALID;


 291                 list.add(new Object[]{outerClassType, innerClassType});
 292             }
 293         }
 294         return list.toArray(new Object[list.size()][]);
 295     }
 296 
 297     @Test(dataProvider = "innerClasses")
 298     public void innerClasses(ClassType outerClassType, ClassType innerClassType) {
 299         String source =
 300                 outerClassType + " A {" + (outerClassType == ClassType.ENUM ? ";" : "") +
 301                 innerClassType + " B { }" +
 302                 "}";
 303         assertEval(source);
 304         assertNumberOfActiveClasses(1);
 305         assertActiveKeys();
 306     }
 307 
 308     public void testInnerClassesCrash() {
 309         Snippet a = classKey(assertEval("class A { class B extends A {} }"));
 310         Snippet a2 = classKey(assertEval("class A { interface I1 extends I2 {} interface I2 {} }",
 311                 ste(MAIN_SNIPPET, VALID, VALID, false, null),
 312                 ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
 313         assertEval("class A { A a = new A() {}; }",
 314                 ste(MAIN_SNIPPET, VALID, VALID, true, null),
 315                 ste(a2, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
 316     }
 317 
 318     public void testInnerClassesCrash1() {
 319         assertEval("class A { class B extends A {} B getB() { return new B();} }");
 320         assertEquals(varKey(assertEval("A a = new A();")).name(), "a");
 321         VarSnippet variableKey = varKey(assertEval("a.getB();"));
 322         assertEquals(variableKey.typeName(), "A.B");
 323     }
 324 
 325     public void testInnerClassesCrash2() {
 326         assertEval("class A { interface I1 extends I2 {} interface I2 {} I1 x; }");
 327         assertEquals(varKey(assertEval("A a = new A();")).name(), "a");
 328         VarSnippet variableKey = varKey(assertEval("a.x;"));
 329         assertEquals(variableKey.typeName(), "A.I1");
 330     }
 331 
   1 /*
   2  * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8145239 8129559 8080354 8189248 8010319
  27  * @summary Tests for EvaluationState.classes
  28  * @build KullaTesting TestingInputStream ExpectedDiagnostic
  29  * @run testng ClassesTest
  30  */
  31 
  32 import java.util.ArrayList;
  33 import java.util.List;
  34 
  35 import javax.tools.Diagnostic;
  36 
  37 import jdk.jshell.Snippet;
  38 import jdk.jshell.TypeDeclSnippet;
  39 import jdk.jshell.VarSnippet;
  40 import org.testng.annotations.DataProvider;
  41 import org.testng.annotations.Test;
  42 
  43 import jdk.jshell.Diag;
  44 import jdk.jshell.Snippet.Status;
  45 import static java.util.stream.Collectors.toList;
  46 import static jdk.jshell.Snippet.Status.VALID;


 291                 list.add(new Object[]{outerClassType, innerClassType});
 292             }
 293         }
 294         return list.toArray(new Object[list.size()][]);
 295     }
 296 
 297     @Test(dataProvider = "innerClasses")
 298     public void innerClasses(ClassType outerClassType, ClassType innerClassType) {
 299         String source =
 300                 outerClassType + " A {" + (outerClassType == ClassType.ENUM ? ";" : "") +
 301                 innerClassType + " B { }" +
 302                 "}";
 303         assertEval(source);
 304         assertNumberOfActiveClasses(1);
 305         assertActiveKeys();
 306     }
 307 
 308     public void testInnerClassesCrash() {
 309         Snippet a = classKey(assertEval("class A { class B extends A {} }"));
 310         Snippet a2 = classKey(assertEval("class A { interface I1 extends I2 {} interface I2 {} }",
 311                 ste(MAIN_SNIPPET, VALID, VALID, true, null),
 312                 ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
 313         assertEval("class A { A a = new A() {}; }",
 314                 ste(MAIN_SNIPPET, VALID, VALID, true, null),
 315                 ste(a2, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
 316     }
 317 
 318     public void testInnerClassesCrash1() {
 319         assertEval("class A { class B extends A {} B getB() { return new B();} }");
 320         assertEquals(varKey(assertEval("A a = new A();")).name(), "a");
 321         VarSnippet variableKey = varKey(assertEval("a.getB();"));
 322         assertEquals(variableKey.typeName(), "A.B");
 323     }
 324 
 325     public void testInnerClassesCrash2() {
 326         assertEval("class A { interface I1 extends I2 {} interface I2 {} I1 x; }");
 327         assertEquals(varKey(assertEval("A a = new A();")).name(), "a");
 328         VarSnippet variableKey = varKey(assertEval("a.x;"));
 329         assertEquals(variableKey.typeName(), "A.I1");
 330     }
 331 
< prev index next >