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  package org.apache.bcel.verifier.tests;
18  
19  import java.io.IOException;
20  import java.io.OutputStream;
21  
22  import org.apache.bcel.Const;
23  import org.apache.bcel.generic.ClassGen;
24  import org.apache.bcel.generic.InstructionConst;
25  import org.apache.bcel.generic.InstructionList;
26  import org.apache.bcel.generic.MethodGen;
27  import org.apache.bcel.generic.Type;
28  
29  public class TestThrow01Creator extends TestCreator {
30      private final ClassGen cg;
31  
32      public TestThrow01Creator() {
33          cg = new ClassGen(TEST_PACKAGE + ".TestThrow01", "java.lang.Object", "TestThrow01.java", Const.ACC_PUBLIC | Const.ACC_SUPER, new String[] {});
34      }
35  
36      @Override
37      public void create(final OutputStream out) throws IOException {
38          final InstructionList il = new InstructionList();
39          final MethodGen method = new MethodGen(Const.ACC_STATIC, Type.VOID, Type.NO_ARGS, new String[0], "b", cg.getClassName(), il, cg.getConstantPool());
40          il.append(InstructionConst.getInstruction(Const.ATHROW));
41          method.setMaxStack();
42          method.setMaxLocals();
43          cg.addMethod(method.getMethod());
44          il.dispose();
45          cg.getJavaClass().dump(out);
46      }
47  }