@@ -0,0 +1,3216 @@
+/*%0A * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.%0A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.%0A *%0A * This code is free software; you can redistribute it and/or modify it%0A * under the terms of the GNU General Public License version 2 only, as%0A * published by the Free Software Foundation.%0A *%0A * This code is distributed in the hope that it will be useful, but WITHOUT%0A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or%0A * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License%0A * version 2 for more details (a copy is included in the LICENSE file that%0A * accompanied this code).%0A *%0A * You should have received a copy of the GNU General Public License version%0A * 2 along with this work; if not, write to the Free Software Foundation,%0A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.%0A *%0A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA%0A * or visit www.oracle.com if you need additional information or have any%0A * questions.%0A */%0Apackage com.oracle.truffle.api.dsl.test;%0A%0Aimport java.lang.reflect.*;%0A%0Aimport org.junit.*;%0A%0Aimport com.oracle.truffle.api.dsl.*;%0Aimport com.oracle.truffle.api.dsl.test.LazyClassLoadingTestFactory.TestNodeFactory;%0Aimport com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode;%0A%0Apublic class LazyClassLoadingTest %7B%0A    @Test%0A    public void test() %7B%0A        String testClassName = getClass().getName();%0A        String factoryClassName = testClassName + %22Factory%22;%0A        String nodeFactoryClassName = factoryClassName + %22$TestNodeFactory%22;%0A%0A        Assert.assertFalse(isLoaded(factoryClassName + %22$TestNode%22));%0A        Assert.assertFalse(isLoaded(nodeFactoryClassName));%0A%0A        NodeFactory%3CTestNode%3E factory = TestNodeFactory.getInstance();%0A%0A        Assert.assertTrue(isLoaded(nodeFactoryClassName));%0A        Assert.assertFalse(isLoaded(nodeFactoryClassName + %22$TestBaseNode%22));%0A%0A        TestHelper.createRoot(factory);%0A%0A        Assert.assertTrue(isLoaded(nodeFactoryClassName + %22$TestBaseNode%22));%0A        Assert.assertTrue(isLoaded(nodeFactoryClassName + %22$TestUninitializedNode%22));%0A        Assert.assertFalse(isLoaded(nodeFactoryClassName + %22$TestGenericNode%22));%0A    %7D%0A%0A    private boolean isLoaded(String className) %7B%0A        ClassLoader classLoader = getClass().getClassLoader();%0A        Method m;%0A        try %7B%0A            m = ClassLoader.class.getDeclaredMethod(%22findLoadedClass%22, String.class);%0A            m.setAccessible(true);%0A            return m.invoke(classLoader, className) != null;%0A        %7D catch (NoSuchMethodException %7C IllegalAccessException %7C InvocationTargetException e) %7B%0A            throw new RuntimeException(e);%0A        %7D%0A    %7D%0A%0A    @SuppressWarnings(%22unused%22)%0A    @NodeChildren(%7B@NodeChild(%22left%22), @NodeChild(%22right%22)%7D)%0A    abstract static class TestNode extends ValueNode %7B%0A        @Specialization(order = 1)%0A        int add(int left, int right) %7B%0A            return 42;%0A        %7D%0A%0A        @Specialization(order = 2)%0A        int add(boolean left, boolean right) %7B%0A            return 21;%0A        %7D%0A%0A        @Specialization(order = 4)%0A        String add(boolean left, int right) %7B%0A            return %22(boolean,int)%22;%0A        %7D%0A    %7D%0A%7D%0A

add class loading test