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