1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * https://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 package org.apache.bcel.classfile;
21
22 import static org.junit.jupiter.api.Assertions.assertTrue;
23
24 import java.io.InputStream;
25 import java.net.URL;
26 import java.net.URLClassLoader;
27 import java.nio.file.Files;
28 import java.nio.file.Path;
29 import java.nio.file.Paths;
30
31 import org.junit.jupiter.api.Test;
32
33 /**
34 * javap input:
35 *
36 * <pre>
37 * javap "src/test/resources/kotlin/test$method name with () in it$1.class"
38 * </pre>
39 *
40 * javap output:
41 *
42 * <pre>
43 *
44 Compiled from "test.kt"
45 final class test$method name with () in it$1 extends kotlin.jvm.internal.Lambda implements kotlin.jvm.functions.Function0<kotlin.Unit> {
46 public static final test$method name with () in it$1 INSTANCE;
47 test$method name with () in it$1();
48 public final void invoke();
49 public java.lang.Object invoke();
50 static {};
51 * </pre>
52 */
53 class InvalidMethodSigantureTest {
54
55 final class TestVisitor extends org.apache.bcel.classfile.EmptyVisitor {
56 @Override
57 public void visitField(final Field field) {
58 field.getType();
59 }
60 }
61 private static final String CLASS_NAME = "test$method name with () in it$1";
62
63 private static final String SRC_TEST_RESOURCES_KOTLIN = "src/test/resources/kotlin/";
64
65 @Test
66 void testLoadClass() throws Exception {
67 final Path path = Paths.get(SRC_TEST_RESOURCES_KOTLIN);
68 assertTrue(Files.exists(path));
69 assertTrue(Files.isDirectory(path));
70 try (URLClassLoader cl = URLClassLoader.newInstance(new URL[] { path.toUri().toURL() })) {
71 Class.forName(CLASS_NAME, false, cl);
72 }
73 }
74
75 @Test
76 //@Disabled("TODO?")
77 void testMethodWithParens() throws Exception {
78 try (InputStream inputStream = Files.newInputStream(Paths.get(SRC_TEST_RESOURCES_KOTLIN, CLASS_NAME + ".class"))) {
79 final ClassParser classParser = new ClassParser(inputStream, CLASS_NAME);
80 final JavaClass javaClass = classParser.parse();
81 final TestVisitor visitor = new TestVisitor();
82 new DescendingVisitor(javaClass, visitor).visit();
83 }
84 }
85 }