]> source.dussan.org Git - aspectj.git/commitdiff
bug 102479 example for getting messages from ajc programmatically
authorwisberg <wisberg>
Fri, 4 Nov 2005 09:02:09 +0000 (09:02 +0000)
committerwisberg <wisberg>
Fri, 4 Nov 2005 09:02:09 +0000 (09:02 +0000)
docs/devGuideDB/ajc.xml

index 95b096649667c15bc10a6af0f8d0052eb61a32a5..ea2cab2daa3844ddce05ff611211cd58a637b741 100644 (file)
@@ -652,8 +652,29 @@ commands to your environment as needed.
       <para>To access compiler messages programmatically, use the methods
          <literal>setHolder(IMessageHolder holder)</literal> and/or
          <literal>run(String[] args, IMessageHolder holder)</literal>.
+                 <literal>ajc</literal> reports each message to the holder
+                 using <literal>IMessageHolder.handleMessage(..)</literal>.
+                 If you just want to collect the messages, use
+                 <literal>MessageHandler</literal> as your               
+                 <literal>IMessageHolder</literal>.
+                 For example, compile and run the following with 
+                 <literal>aspectjtools.jar</literal> on the classpath:
       </para>
-
+        <programlisting>
+import org.aspectj.bridge.*;
+import org.aspectj.tools.ajc.Main;
+import java.util.Arrays;
+
+public class WrapAjc {
+  public static void main(String[] args) {
+    Main compiler = new Main();
+    MessageHandler m = new MessageHandler();
+    compiler.run(args, m);
+    IMessage[] ms = m.getMessages(null, true);
+    System.out.println("messages: " + Arrays.asList(ms));
+  }
+}
+        </programlisting>
     </refsect2>
 
     <refsect2>