summaryrefslogtreecommitdiffstats
path: root/tutorial/tutorial2.html
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2005-08-18 15:22:38 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2005-08-18 15:22:38 +0000
commit2d60b1690e44dd33553e28618c7c0b25e4b34d9f (patch)
treeb9a6b9c069e8ed045258c00d25708156401a838c /tutorial/tutorial2.html
parentff329de74b48a2a8431024ae1097abbdac60aa8f (diff)
downloadjavassist-2d60b1690e44dd33553e28618c7c0b25e4b34d9f.tar.gz
javassist-2d60b1690e44dd33553e28618c7c0b25e4b34d9f.zip
modified the compiler to support "import".
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@195 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'tutorial/tutorial2.html')
-rw-r--r--tutorial/tutorial2.html46
1 files changed, 38 insertions, 8 deletions
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 @@
<br><li><a href="#alter">Altering a method body</a>
<br><li><a href="#add">Adding a new method or field</a>
<br><li><a href="#runtime">Runtime support classes</a>
+<br><li><a href="#import">Import</a>
<br><li><a href="#limit">Limitations</a>
</ul>
@@ -1456,8 +1457,44 @@ Javassist classes are never used at runtime of the modified classes.
<p><br>
+<a name="import">
+<h3>4.5 Import</h3>
+
+<p>All the class names in source code must be fully qualified
+(they must include package names).
+However, the <code>java.lang</code> package is an
+exception; for example, the Javassist compiler can
+resolve <code>Object</code> as
+well as <code>java.lang.Object</code>.
+
+<p>To tell the compiler to search other packages when resolving a
+class name, call <code>importPackage()</code> in <code>ClassPool</code>.
+For example,
+
+<ul><pre>
+ClassPool pool = ClassPool.getDefault();
+pool.importPackage("java.awt");
+CtClass cc = pool.makeClass("Test");
+CtField f = CtField.make("public Point p;", cc);
+cc.addField(f);
+</pre></ul>
+
+<p>The seconde line instructs the compiler
+to import the <code>java.awt</code> package.
+Thus, the third line will not throw an exception.
+The compiler can recognize <code>Point</code>
+as <code>java.awt.Point</code>.
+
+<p>Note that <code>importPackage()</code> <em>does not</em> affect
+the <code>get()</code> method in <code>ClassPool</code>.
+Only the compiler considers the imported packages.
+The parameter to <code>get()</code>
+must be always a fully qualified name.
+
+<p><br>
+
<a name="limit">
-<h3>4.5 Limitations</h3>
+<h3>4.6 Limitations</h3>
<p>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 <code>javassist.bytecode.annotation</code> package.
-<p><li>All the class names must be fully qualified (they must include
-package names). This is because the compiler does not support
-<code>import</code>
-declarations. However, the <code>java.lang</code> package is an
-exception; for example, the compiler accepts <code>Object</code> as
-well as <code>java.lang.Object</code>.
-
<p><li>Array initializers, a comma-separated list of expressions
enclosed by braces <code>{</code> and <code>}</code>, are not
supported.