From 2d60b1690e44dd33553e28618c7c0b25e4b34d9f Mon Sep 17 00:00:00 2001 From: chiba Date: Thu, 18 Aug 2005 15:22:38 +0000 Subject: modified the compiler to support "import". git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@195 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- tutorial/tutorial2.html | 46 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) (limited to 'tutorial') diff --git a/tutorial/tutorial2.html b/tutorial/tutorial2.html index 910123b9..5befd301 100644 --- a/tutorial/tutorial2.html +++ b/tutorial/tutorial2.html @@ -19,6 +19,7 @@
  • Altering a method body
  • Adding a new method or field
  • Runtime support classes +
  • Import
  • Limitations @@ -1456,8 +1457,44 @@ Javassist classes are never used at runtime of the modified classes.


    + +

    4.5 Import

    + +

    All the class names in source code must be fully qualified +(they must include package names). +However, the java.lang package is an +exception; for example, the Javassist compiler can +resolve Object as +well as java.lang.Object. + +

    To tell the compiler to search other packages when resolving a +class name, call importPackage() in ClassPool. +For example, + +

      +ClassPool pool = ClassPool.getDefault();
      +pool.importPackage("java.awt");
      +CtClass cc = pool.makeClass("Test");
      +CtField f = CtField.make("public Point p;", cc);
      +cc.addField(f);
      +
    + +

    The seconde line instructs the compiler +to import the java.awt package. +Thus, the third line will not throw an exception. +The compiler can recognize Point +as java.awt.Point. + +

    Note that importPackage() does not affect +the get() method in ClassPool. +Only the compiler considers the imported packages. +The parameter to get() +must be always a fully qualified name. + +


    +
    -

    4.5 Limitations

    +

    4.6 Limitations

    In the current implementation, the Java compiler included in Javassist has several limitations with respect to the language that the compiler can @@ -1468,13 +1505,6 @@ has not been supported. Annotations are supported only by the low level API of Javassist. See the javassist.bytecode.annotation package. -

  • All the class names must be fully qualified (they must include -package names). This is because the compiler does not support -import -declarations. However, the java.lang package is an -exception; for example, the compiler accepts Object as -well as java.lang.Object. -

  • Array initializers, a comma-separated list of expressions enclosed by braces { and }, are not supported. -- cgit v1.2.3