< prev index next >

test/langtools/jdk/jshell/ForwardReferenceTest.java

Print this page


   1 /*
   2  * Copyright (c) 2016, 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 8173232
  26  * @summary Test of forward referencing of snippets.
  27  * @build KullaTesting TestingInputStream
  28  * @run testng ForwardReferenceTest
  29  */
  30 
  31 import java.util.List;
  32 import jdk.jshell.Snippet;
  33 import jdk.jshell.MethodSnippet;
  34 import jdk.jshell.VarSnippet;
  35 import jdk.jshell.DeclarationSnippet;
  36 import org.testng.annotations.Test;
  37 
  38 import jdk.jshell.SnippetEvent;
  39 import jdk.jshell.UnresolvedReferenceException;
  40 import static org.testng.Assert.assertEquals;
  41 import static jdk.jshell.Snippet.Status.*;
  42 import static org.testng.Assert.assertTrue;
  43 
  44 @Test
  45 public class ForwardReferenceTest extends KullaTesting {


 298         assertEval("class B { }",
 299                 DiagCheck.DIAG_OK,
 300                 DiagCheck.DIAG_ERROR,
 301                 ste(MAIN_SNIPPET, VALID, VALID, true, null),
 302                 ste(b, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
 303                 ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET));
 304         assertDeclareFail("A.f();", "compiler.err.cant.resolve.location");
 305         assertActiveKeys();
 306     }
 307 
 308     public void testForwardVariable() {
 309         assertEval("int f() { return x; }", added(RECOVERABLE_DEFINED));
 310         assertEvalUnresolvedException("f();", "f", 1, 0);
 311         assertActiveKeys();
 312     }
 313 
 314     public void testLocalClassInUnresolved() {
 315         Snippet f = methodKey(assertEval("void f() { class A {} g(); }", added(RECOVERABLE_DEFINED)));
 316         assertEval("void g() {}",
 317                 added(VALID),
 318                 ste(f, RECOVERABLE_DEFINED, VALID, false, null));
 319         assertEval("f();", "");
 320     }
 321 }
   1 /*
   2  * Copyright (c) 2016, 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 8173232 8010319
  26  * @summary Test of forward referencing of snippets.
  27  * @build KullaTesting TestingInputStream
  28  * @run testng ForwardReferenceTest
  29  */
  30 
  31 import java.util.List;
  32 import jdk.jshell.Snippet;
  33 import jdk.jshell.MethodSnippet;
  34 import jdk.jshell.VarSnippet;
  35 import jdk.jshell.DeclarationSnippet;
  36 import org.testng.annotations.Test;
  37 
  38 import jdk.jshell.SnippetEvent;
  39 import jdk.jshell.UnresolvedReferenceException;
  40 import static org.testng.Assert.assertEquals;
  41 import static jdk.jshell.Snippet.Status.*;
  42 import static org.testng.Assert.assertTrue;
  43 
  44 @Test
  45 public class ForwardReferenceTest extends KullaTesting {


 298         assertEval("class B { }",
 299                 DiagCheck.DIAG_OK,
 300                 DiagCheck.DIAG_ERROR,
 301                 ste(MAIN_SNIPPET, VALID, VALID, true, null),
 302                 ste(b, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
 303                 ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET));
 304         assertDeclareFail("A.f();", "compiler.err.cant.resolve.location");
 305         assertActiveKeys();
 306     }
 307 
 308     public void testForwardVariable() {
 309         assertEval("int f() { return x; }", added(RECOVERABLE_DEFINED));
 310         assertEvalUnresolvedException("f();", "f", 1, 0);
 311         assertActiveKeys();
 312     }
 313 
 314     public void testLocalClassInUnresolved() {
 315         Snippet f = methodKey(assertEval("void f() { class A {} g(); }", added(RECOVERABLE_DEFINED)));
 316         assertEval("void g() {}",
 317                 added(VALID),
 318                 ste(f, RECOVERABLE_DEFINED, VALID, true, null));
 319         assertEval("f();", "");
 320     }
 321 }
< prev index next >