aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/javassist/ClassPool.java
blob: e6c756139bb130291ce9f1641bd1978ddc54542e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
/*
 * Javassist, a Java-bytecode translator toolkit.
 * Copyright (C) 1999-2004 Shigeru Chiba. All Rights Reserved.
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License.  Alternatively, the contents of this file may be used under
 * the terms of the GNU Lesser General Public License Version 2.1 or later.
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 */

package javassist;

import java.io.*;
import java.net.URL;
import java.util.Hashtable;

/**
 * A driver class for controlling bytecode editing with Javassist.
 * It manages where a class file is obtained and how it is modified.
 *
 * <p>A <code>ClassPool</code> object can be regarded as a container
 * of <code>CtClass</code> objects.  It reads class files on demand
 * from various
 * sources represented by <code>ClassPath</code> and create
 * <code>CtClass</code> objects representing those class files.
 *
 * <p>A <code>CtClass</code>
 * object contained in a <code>ClassPool</code> is written to an
 * output stream (or a file) if <code>write()</code>
 * (or <code>writeFile()</code>) is called on the 
 * <code>ClassPool</code>.
 * <code>write()</code> is typically called by a class loader,
 * which obtains the bytecode image to be loaded.
 *
 * <p>The users can modify <code>CtClass</code> objects
 * before those objects are written out.
 * To obtain a reference
 * to a <code>CtClass</code> object contained in a
 * <code>ClassPool</code>, <code>get()</code> should be
 * called on the <code>ClassPool</code>.  If a <code>CtClass</code>
 * object is modified, then the modification is reflected on the resulting
 * class file returned by <code>write()</code> in <code>ClassPool</code>.
 *
 * <p>In summary,
 *
 * <ul>
 * <li><code>get()</code> returns a reference to a <code>CtClass</code>
 *     object contained in a <code>ClassPool</code>.
 *
 * <li><code>write()</code> translates a <code>CtClass</code>
 * object contained in a <code>ClassPool</code> into a class file
 * and writes it to an output stream.
 * </ul>
 *
 * <p>The users can add a listener object receiving an event from a
 * <code>ClassPool</code>.  An event occurs when a listener is
 * added to a <code>ClassPool</code> and when <code>write()</code>
 * is called on a <code>ClassPool</code> (not when <code>get()</code>
 * is called!).  The listener class
 * must implement <code>Translator</code>.  A typical listener object
 * is used for modifying a <code>CtClass</code> object <i>on demand</i>
 * when it is written to an output stream.
 *
 * <p>The implementation of this class is thread-safe.
 *
 * <p><b>Memory consumption memo:</b>
 *
 * <p><code>ClassPool</code> objects hold all the <code>CtClass</code>es
 * that have been created so that the consistency among modified classes
 * can be guaranteed.  Thus if a large number of <code>CtClass</code>es
 * are processed, the <code>ClassPool</code> will consume a huge amount
 * of memory.  To avoid this, multiple <code>ClassPool</code> objects
 * must be used.  Note that <code>getDefault()</code> is a singleton
 * factory.
 *
 *
 * @see javassist.CtClass
 * @see javassist.ClassPath
 * @see javassist.Translator
 */
public class ClassPool extends AbsClassPool {
    protected AbsClassPool source;
    protected ClassPool parent;
    protected Translator translator;
    protected Hashtable classes;        // should be synchronous

    /**
     * Table of registered cflow variables.
     */
    private Hashtable cflow = null;     // should be synchronous.

    /**
     * Creates a class pool.
     *
     * @param src       the source of class files.  If it is null,
     *                  the class search path is initially null.
     * @param p         the parent of this class pool.
     * @see javassist.ClassPool#getDefault()
     */
    public ClassPool(ClassPool p) {
        this(new ClassPoolTail(), p);
    }

    ClassPool(AbsClassPool src, ClassPool parent) {
        this.classes = new Hashtable();
        this.source = src;
        this.parent = parent;
        if (parent == null) {
            // if this has no parent, it must include primitive types
            // even if this.source is not a ClassPoolTail.
            CtClass[] pt = CtClass.primitiveTypes;
            for (int i = 0; i < pt.length; ++i)
                classes.put(pt[i].getName(), pt[i]);
        }

        this.translator = null;
        this.cflow = null;
    }

    /**
     * Inserts a new translator at the head of the translator chain.
     *
     * @param trans         a new translator associated with this class pool.
     * @throws RuntimeException     if trans.start() throws an exception.
     */
    public void insertTranslator(Translator trans) throws RuntimeException {
        ClassPool next = new ClassPool(source, parent);
        next.translator = trans;
        source = next;
        try {
            trans.start(next);
        }
        catch (Exception e) {
            throw new RuntimeException(
                "Translator.start() throws an exception: "
                + e.toString());
        }
    }

    /**
     * Returns the default class pool.
     * The returned object is always identical since this method is
     * a singleton factory.
     *
     * <p>The default class pool searches the system search path,
     * which usually includes the platform library, extension
     * libraries, and the search path specified by the
     * <code>-classpath</code> option or the <code>CLASSPATH</code>
     * environment variable.
     *
     * <p>When this method is called for the first time, the default
     * class pool is created with the following code snippet:
     *
     * <ul><code>ClassPool cp = new ClassPool(null);
     * cp.appendSystemPath();
     * </code></ul>
     *
     * @param t         null or the translator linked to the class pool.
     */
    public static synchronized ClassPool getDefault() {
        if (defaultPool == null) {
            defaultPool = new ClassPool(null);
            defaultPool.appendSystemPath();
        }

        return defaultPool;
    }

    private static ClassPool defaultPool = null;

    /**
     * Provide a hook so that subclasses can do their own
     * caching of classes
     *
     * @see #removeCached(String)
     */
     protected CtClass getCached(String classname)
     {
         return (CtClass)classes.get(classname); 
     }

    /**
     * Provide a hook so that subclasses can do their own
     * caching of classes
     *
     * @see #getCached(String)
     */
     protected void removeCached(String classname)
     {
         classes.remove(classname);
     }

    /**
     * Returns the class search path.
     */
    public String toString() {
        return source.toString();
    }

    /**
     * Records a name that never exists.
     * For example, a package name can be recorded by this method.
     * This would improve execution performance
     * since <code>get()</code> does not search the class path at all
     * if the given name is an invalid name recorded by this method.
     * Note that searching the class path takes relatively long time.
     *
     * @param name          a class name (separeted by dot).
     */
    public void recordInvalidClassName(String name) {
        source.recordInvalidClassName(name);
    }

    /**
     * Returns the <code>Translator</code> object associated with
     * this <code>ClassPool</code>.
     *
     * @deprecated
     */
    Translator getTranslator() { return translator; }

    /**
     * Records the <code>$cflow</code> variable for the field specified
     * by <code>cname</code> and <code>fname</code>.
     *
     * @param name      variable name
     * @param cname     class name
     * @param fname     field name
     */
    void recordCflow(String name, String cname, String fname) {
        if (cflow == null)
            cflow = new Hashtable();

        cflow.put(name, new Object[] { cname, fname });
    }

    /**
     * Undocumented method.  Do not use; internal-use only.
     * 
     * @param name      the name of <code>$cflow</code> variable
     */
    public Object[] lookupCflow(String name) {
        if (cflow == null)
            cflow = new Hashtable();

        return (Object[])cflow.get(name);
    }

    /**
     * Writes a class file specified with <code>classname</code>
     * in the current directory.
     * It never calls <code>onWrite()</code> on a translator.
     * It is provided for debugging.
     *
     * @param classname         the name of the class written on a local disk.
     */
    public void debugWriteFile(String classname)
        throws NotFoundException, CannotCompileException, IOException
    {
        debugWriteFile(classname, ".");
    }

    /**
     * Writes a class file specified with <code>classname</code>.
     * It never calls <code>onWrite()</code> on a translator.
     * It is provided for debugging.
     *
     * @param classname         the name of the class written on a local disk.
     * @param directoryName     it must end without a directory separator.
     */
    public void debugWriteFile(String classname, String directoryName)
        throws NotFoundException, CannotCompileException, IOException
    {
        writeFile(classname, directoryName, false);
    }

    /* void writeFile(CtClass) should not be defined since writeFile()
     * may be called on the class pool that does not contain the given
     * CtClass object.
     */

    /**
     * Writes a class file specified with <code>classname</code>
     * in the current directory.
     * It calls <code>onWrite()</code> on a translator.
     *
     * @param classname         the name of the class written on a local disk.
     */
    public void writeFile(String classname)
        throws NotFoundException, CannotCompileException, IOException
    {
        writeFile(classname, ".");
    }

    /**
     * Writes a class file specified with <code>classname</code>
     * on a local disk.
     * It calls <code>onWrite()</code> on a translator.
     *
     * @param classname         the name of the class written on a local disk.
     * @param directoryName     it must end without a directory separator.
     */
    public void writeFile(String classname, String directoryName)
        throws NotFoundException, CannotCompileException, IOException
    {
        writeFile(classname, directoryName, true);
    }

    private void writeFile(String classname, String directoryName,
                           boolean callback)
        throws NotFoundException, CannotCompileException, IOException
    {
        String filename = directoryName + File.separatorChar
            + classname.replace('.', File.separatorChar) + ".class";
        int pos = filename.lastIndexOf(File.separatorChar);
        if (pos > 0) {
            String dir = filename.substring(0, pos);
            if (!dir.equals("."))
                new File(dir).mkdirs();
        }

        DataOutputStream out
            = new DataOutputStream(new BufferedOutputStream(
                                new DelayedFileOutputStream(filename)));
        write(classname, out, callback);
        out.close();
    }

    static class DelayedFileOutputStream extends OutputStream {
        private FileOutputStream file;
        private String filename;

        DelayedFileOutputStream(String name) {
            file = null;
            filename = name;
        }

        private void init() throws IOException {
            if (file == null)
                file = new FileOutputStream(filename);
        }

        public void write(int b) throws IOException {
            init();
            file.write(b);
        }

        public void write(byte[] b) throws IOException {
            init();
            file.write(b);
        }

        public void write(byte[] b, int off, int len) throws IOException {
            init();
            file.write(b, off, len);

        }

        public void flush() throws IOException {
            init();
            file.flush();
        }

        public void close() throws IOException {
            init();
            file.close();
        }
    }

    /**
     * A simple class loader used by <code>writeAsClass()</code>
     * in <code>ClassPool</code>.
     * This class loader is provided for convenience.  If you need more
     * complex functionality, you should write your own class loader.
     *
     * @see ClassPool#writeAsClass(String)
     * @see CtClass#toClass()
     */
    public static class SimpleLoader extends ClassLoader {
        /**
         * Loads a class.
         *
         * @param name		the fully qualified class name.
         * @param classfile	the class file.
         * @throws ClassFormatError	if the class file is wrong.
         */
        public Class loadClass(String name, byte[] classfile)
            throws ClassFormatError
        {
            Class c = defineClass(name, classfile, 0, classfile.length);
            resolveClass(c);
            return c;
        }
    };

    private static SimpleLoader classLoader = new SimpleLoader();

    /**
     * Returns a <code>java.lang.Class</code> object that has been loaded
     * by <code>writeAsClass()</code>.  Such an object cannot be
     * obtained by <code>java.lang.Class.forName()</code> because it has
     * been loaded by an internal class loader of Javassist.
     *
     * @see #writeAsClass(String)
     * @see javassist.CtClass#toClass()
     */
    public static Class forName(String name) throws ClassNotFoundException {
        return classLoader.loadClass(name);
    }

    /**
     * Returns a <code>java.lang.Class</code> object.
     * It calls <code>write()</code> to obtain a class file and then
     * loads the obtained class file into the JVM.  The returned
     * <code>Class</code> object represents the loaded class.
     *
     * <p>This method is provided for convenience.  If you need more
     * complex functionality, you should write your own class loader.
     *
     * <p>To load a class file, this method uses an internal class loader,
     * which is an instance of <code>ClassPool.SimpleLoader</code>.
     * Thus, that class file is not loaded by the system class loader,
     * which should have loaded this <code>ClassPool</code> class.
     * The internal class loader
     * loads only the classes explicitly specified by this method
     * <code>writeAsClass()</code>.  The other classes are loaded
     * by the parent class loader (the sytem class loader) by delegation.
     *
     * <p>For example,
     *
     * <ul><pre>class Line { Point p1, p2; }</pre></ul>
     *
     * <p>If the class <code>Line</code> is loaded by the internal class
     * loader and the class <code>Point</code> has not been loaded yet,
     * then the class <code>Point</code> that the class <code>Line</code>
     * refers to is loaded by the parent class loader.  There is no
     * chance of modifying the definition of <code>Point</code> with
     * Javassist.
     *
     * <p>The internal class loader is shared among all the instances
     * of <code>ClassPool</code>.
     *
     * @param classname         a fully-qualified class name.
     *
     * @see #forName(String)
     * @see javassist.CtClass#toClass()
     * @see javassist.Loader
     */
    public Class writeAsClass(String classname)
        throws NotFoundException, IOException, CannotCompileException
    {
        try {
            return classLoader.loadClass(classname, write(classname));
        }
        catch (ClassFormatError e) {
            throw new CannotCompileException(e, classname);
        }
    }

    /**
     * Returns a byte array representing the class file.
     * It calls <code>onWrite()</code> on a translator.
     *
     * @param classname         a fully-qualified class name.
     */
    public byte[] write(String classname)
        throws NotFoundException, IOException, CannotCompileException
    {
        ByteArrayOutputStream barray = new ByteArrayOutputStream();
        DataOutputStream out = new DataOutputStream(barray);
        try {
            write(classname, out, true);
        }
        finally {
            out.close();
        }

        return barray.toByteArray();
    }

    /**
     * Writes a class file specified by <code>classname</code>
     * to a given output stream.
     * It calls <code>onWrite()</code> on a translator.
     *
     * <p>This method does not close the output stream in the end.
     *
     * @param classname         a fully-qualified class name.
     * @param out               an output stream
     */
    public void write(String classname, DataOutputStream out)
        throws NotFoundException, CannotCompileException, IOException
    {
        write(classname, out, true);
    }

    private void write(String classname, DataOutputStream out,
                       boolean callback)
        throws NotFoundException, CannotCompileException, IOException
    {
        if (!write0(classname, out, callback))
            throw new NotFoundException(classname);
    }

    boolean write0(String classname, DataOutputStream out, boolean callback)
        throws NotFoundException, CannotCompileException, IOException
    {
        // first, delegate to the parent.
        if (parent != null && parent.write0(classname, out, callback))
            return true;

        CtClass clazz = (CtClass)getCached(classname);
        if (callback && translator != null
                                && (clazz == null || !clazz.isFrozen())) {
            translator.onWrite(this, classname);
            // The CtClass object might be overwritten.
            clazz = (CtClass)getCached(classname);
        }

        if (clazz == null || !clazz.isModified()) {
            if (clazz != null)
                clazz.freeze();

            return source.write0(classname, out, callback);
        }
        else {
            clazz.toBytecode(out);
            return true;
        }
    }

    /* for CtClassType.getClassFile2().  Don't delegate to the parent.
     */
    byte[] readSource(String classname)
        throws NotFoundException, IOException, CannotCompileException
    {
        return source.readSource(classname);
    }

    /*
     * Is invoked by CtClassType.setName().  Don't delegate to the parent.
     */
    synchronized void classNameChanged(String oldname, CtClass clazz) {
        CtClass c = (CtClass)getCached(oldname);
        if (c == clazz)             // must check this equation.
            removeCached(oldname);  // see getAndRename().

        String newName = clazz.getName();
        checkNotFrozen(newName);
        classes.put(newName, clazz);
    }

    /*
     * Is invoked by CtClassType.setName() and methods in this class.
     * This method throws an exception if the class is already frozen or
     * if this class pool cannot edit the class since it is in a parent
     * class pool.
     */
    void checkNotFrozen(String classname) throws RuntimeException {
        CtClass c;
        if (parent != null) {
            try {
                c = parent.get0(classname);
            }
            catch (NotFoundException e) {       // some error happens.
                throw new RuntimeException(e.toString());
            }

            if (c != null)
                throw new RuntimeException(classname
                        + " is in a parent ClassPool.  Use the parent.");
        }

        c = getCached(classname);
        if (c != null && c.isFrozen())
            throw new RuntimeException(classname +
                                       ": frozen class (cannot edit)");
    }

    /**
     * Reads a class file and constructs a <code>CtClass</code>
     * object with a new name.
     * This method is useful if you want to generate a new class as a copy
     * of another class (except the class name).  For example,
     *
     * <ul><pre>
     * getAndRename("Point", "Pair")
     * </pre></ul>
     *
     * returns a <code>CtClass</code> object representing <code>Pair</code>
     * class.  The definition of <code>Pair</code> is the same as that of
     * <code>Point</code> class except the class name since <code>Pair</code>
     * is defined by reading <code>Point.class</code>.
     *
     * @param orgName   the original (fully-qualified) class name
     * @param newName   the new class name
     */
    public CtClass getAndRename(String orgName, String newName)
        throws NotFoundException
    {
        CtClass clazz = null;
        if (parent != null)
            clazz = parent.get1(orgName);

        if (clazz == null)
            clazz = get1(orgName);

        if (clazz == null)
            throw new NotFoundException(orgName);

        clazz.setName(newName);         // indirectly calls
                                        // classNameChanged() in this class
        return clazz;
    }

    /**
     * Reads a class file from the source and returns a reference
     * to the <code>CtClass</code>
     * object representing that class file.  If that class file has been
     * already read, this method returns a reference to the
     * <code>CtClass</code> created when that class file was read at the
     * first time.
     *
     * <p>If <code>classname</code> ends with "[]", then this method
     * returns a <code>CtClass</code> object for that array type.
     *
     * <p>To obtain an inner class, use "$" instead of "." for separating
     * the enclosing class name and the inner class name.
     *
     * @param classname         a fully-qualified class name.
     */
    public CtClass get(String classname) throws NotFoundException {
        CtClass clazz = get0(classname);
        if (clazz == null)
            throw new NotFoundException(classname);
        else
            return clazz;
    }

    /**
     * @return null     if the class could not be found.
     */
    private synchronized CtClass get0(String classname)
        throws NotFoundException
    {
        CtClass clazz;
        if (parent != null) {
            clazz = parent.get0(classname);
            if (clazz != null)
                return clazz;
        }

        clazz = getCached(classname);
        if (clazz == null) {
            clazz = get1(classname);
            if (clazz != null)
                classes.put(classname, clazz);
        }

        return clazz;
    }

    private CtClass get1(String classname) throws NotFoundException {
        if (classname.endsWith("[]")) {
            String base = classname.substring(0, classname.indexOf('['));
            if (getCached(base) == null && find(base) == null)
                return null;
            else
                return new CtArray(classname, this);
        }
        else
            if (find(classname) == null)
                return null;
            else
                return new CtClassType(classname, this);
    }

    /**
     * Obtains the URL of the class file specified by classname.
     * This method does not delegate to the parent pool.
     *
     * @param classname     a fully-qualified class name.
     * @return null if the class file could not be found.
     */
    URL find(String classname) {
        return source.find(classname);
    }

    /**
     * Reads class files from the source and returns an array of
     * <code>CtClass</code>
     * objects representing those class files.
     *
     * <p>If an element of <code>classnames</code> ends with "[]",
     * then this method
     * returns a <code>CtClass</code> object for that array type.
     *
     * @param classnames        an array of fully-qualified class name.
     */
    public CtClass[] get(String[] classnames) throws NotFoundException {
        if (classnames == null)
            return new CtClass[0];

        int num = classnames.length;
        CtClass[] result = new CtClass[num];
        for (int i = 0; i < num; ++i)
            result[i] = get(classnames[i]);

        return result;
    }

    /**
     * Reads a class file and obtains a compile-time method.
     *
     * @param classname         the class name
     * @param methodname        the method name
     *
     * @see CtClass#getDeclaredMethod(String)
     */
    public CtMethod getMethod(String classname, String methodname)
        throws NotFoundException
    {
        CtClass c = get(classname);
        return c.getDeclaredMethod(methodname);
    }

    /**
     * Creates a new class (or interface) from the given class file.
     * If there already exists a class with the same name, the new class
     * overwrites that previous class.
     *
     * <p>This method is used for creating a <code>CtClass</code> object
     * directly from a class file.  The qualified class name is obtained
     * from the class file; you do not have to explicitly give the name.
     *
     * @param classfile         class file.
     * @exception RuntimeException      if there is a frozen class with the
     *                                  the same name.
     * @see javassist.ByteArrayClassPath
     */
    public CtClass makeClass(InputStream classfile)
        throws IOException, RuntimeException
    {
        CtClass clazz = new CtClassType(classfile, this);
        clazz.checkModify();
        String classname = clazz.getName();
        checkNotFrozen(classname);
        classes.put(classname, clazz);
        return clazz;
    }

    /**
     * Creates a new public class.
     * If there already exists a class with the same name, the new class
     * overwrites that previous class.
     *
     * @param classname         a fully-qualified class name.
     * @exception RuntimeException      if the existing class is frozen.
     */
    public CtClass makeClass(String classname) throws RuntimeException {
        return makeClass(classname, null);
    }

    /**
     * Creates a new public class.
     * If there already exists a class/interface with the same name,
     * the new class overwrites that previous class.
     *
     * @param classname         a fully-qualified class name.
     * @param superclass        the super class.
     * @exception RuntimeException      if the existing class is frozen.
     */
    public synchronized CtClass makeClass(String classname, CtClass superclass)
        throws RuntimeException
    {
        checkNotFrozen(classname);
        CtClass clazz = new CtNewClass(classname, this, false, superclass);
        classes.put(classname, clazz);
        return clazz;
    }

    /**
     * Creates a new public interface.
     * If there already exists a class/interface with the same name,
     * the new interface overwrites that previous one.
     *
     * @param name              a fully-qualified interface name.
     * @exception RuntimeException      if the existing interface is frozen.
     */
    public CtClass makeInterface(String name) throws RuntimeException {
        return makeInterface(name, null);
    }

    /**
     * Creates a new public interface.
     * If there already exists a class/interface with the same name,
     * the new interface overwrites that previous one.
     *
     * @param name              a fully-qualified interface name.
     * @param superclass        the super interface.
     * @exception RuntimeException      if the existing interface is frozen.
     */
    public synchronized CtClass makeInterface(String name, CtClass superclass)
        throws RuntimeException
    {
        checkNotFrozen(name);
        CtClass clazz = new CtNewClass(name, this, true, superclass);
        classes.put(name, clazz);
        return clazz;
    }

    /**
     * Appends the system search path to the end of the
     * search path.  The system search path
     * usually includes the platform library, extension
     * libraries, and the search path specified by the
     * <code>-classpath</code> option or the <code>CLASSPATH</code>
     * environment variable.
     *
     * @return the appended class path.
     */
    public ClassPath appendSystemPath() {
        return source.appendSystemPath();
    }

    /**
     * Insert a <code>ClassPath</code> object at the head of the
     * search path.
     *
     * @return the inserted class path.
     *
     * @see javassist.ClassPath
     * @see javassist.URLClassPath
     * @see javassist.ByteArrayClassPath
     */
    public ClassPath insertClassPath(ClassPath cp) {
        return source.insertClassPath(cp);
    }

    /**
     * Appends a <code>ClassPath</code> object to the end of the
     * search path.
     *
     * @return the appended class path.
     *
     * @see javassist.ClassPath
     * @see javassist.URLClassPath
     * @see javassist.ByteArrayClassPath
     */
    public ClassPath appendClassPath(ClassPath cp) {
        return source.appendClassPath(cp);
    }

    /**
     * Inserts a directory or a jar (or zip) file at the head of the
     * search path.
     *
     * @param pathname  the path name of the directory or jar file.
     *                  It must not end with a path separator ("/").
     * @return          the inserted class path.
     * @exception NotFoundException     if the jar file is not found.
     */
    public ClassPath insertClassPath(String pathname)
        throws NotFoundException
    {
        return source.insertClassPath(pathname);
    }

    /**
     * Appends a directory or a jar (or zip) file to the end of the
     * search path.
     *
     * @param pathname  the path name of the directory or jar file.
     *                  It must not end with a path separator ("/").
     * @return          the appended class path.
     * @exception NotFoundException     if the jar file is not found.
     */
    public ClassPath appendClassPath(String pathname)
        throws NotFoundException
    {
        return source.appendClassPath(pathname);
    }

    /**
     * Detatches the <code>ClassPath</code> object from the search path.
     * The detached <code>ClassPath</code> object cannot be added
     * to the pathagain.
     */
    public void removeClassPath(ClassPath cp) {
        source.removeClassPath(cp);
    }

    /**
     * Appends directories and jar files for search.
     *
     * <p>The elements of the given path list must be separated by colons
     * in Unix or semi-colons in Windows.
     *
     * @param pathlist          a (semi)colon-separated list of
     *                          the path names of directories and jar files.
     *                          The directory name must not end with a path
     *                          separator ("/").
     *
     * @exception NotFoundException     if a jar file is not found.
     */
    public void appendPathList(String pathlist) throws NotFoundException {
        char sep = File.pathSeparatorChar;
        int i = 0;
        for (;;) {
            int j = pathlist.indexOf(sep, i);
            if (j < 0) {
                appendClassPath(pathlist.substring(i));
                break;
            }
            else {
                appendClassPath(pathlist.substring(i, j));
                i = j + 1;
            }
        }
    }
}