diff options
author | wisberg <wisberg> | 2002-12-16 18:51:06 +0000 |
---|---|---|
committer | wisberg <wisberg> | 2002-12-16 18:51:06 +0000 |
commit | 144143c2970a1e874d74cdbd0f8c622d4282a3c3 (patch) | |
tree | b12383d3d9e76c7e1f25f7fbec83051ef17f81fb /tests/sourceinfo | |
parent | fafae443719b26159ab2d7dac1c9b46b5e00b671 (diff) | |
download | aspectj-144143c2970a1e874d74cdbd0f8c622d4282a3c3.tar.gz aspectj-144143c2970a1e874d74cdbd0f8c622d4282a3c3.zip |
initial version
Diffstat (limited to 'tests/sourceinfo')
-rw-r--r-- | tests/sourceinfo/Hello.java | 13 | ||||
-rw-r--r-- | tests/sourceinfo/HelloA.java | 7 | ||||
-rw-r--r-- | tests/sourceinfo/JdiTest.java | 145 |
3 files changed, 165 insertions, 0 deletions
diff --git a/tests/sourceinfo/Hello.java b/tests/sourceinfo/Hello.java new file mode 100644 index 000000000..20270fb38 --- /dev/null +++ b/tests/sourceinfo/Hello.java @@ -0,0 +1,13 @@ +/** + * @version 1.0 + * @author + */ +public class Hello { + + public static void main(String[] args) throws Exception { + System.out.println("hello"); + fromA(); + Thread.currentThread().sleep(2000); + } +} + diff --git a/tests/sourceinfo/HelloA.java b/tests/sourceinfo/HelloA.java new file mode 100644 index 000000000..5e5dca49d --- /dev/null +++ b/tests/sourceinfo/HelloA.java @@ -0,0 +1,7 @@ +aspect HelloA { + static int Hello.fromA() { + System.out.println("from A"); + return 3; + } +} + diff --git a/tests/sourceinfo/JdiTest.java b/tests/sourceinfo/JdiTest.java new file mode 100644 index 000000000..ea56ceb7a --- /dev/null +++ b/tests/sourceinfo/JdiTest.java @@ -0,0 +1,145 @@ +import com.sun.jdi.*; +import com.sun.jdi.connect.*; +import com.sun.jdi.request.ClassPrepareRequest; +import com.sun.jdi.request.EventRequestManager; + +import java.util.*; +import java.io.*; + +/** + * @version 1.0 + * @author + */ +public class JdiTest { + static Thread errThread, outThread; + + public static void main(String[] xxx) throws Exception { + LaunchingConnector lc = findLaunchingConnector(); + String mainArgs = "Hello"; + Map args = connectorArguments(lc, mainArgs); + System.out.println(args); + VirtualMachine vm = lc.launch(args); + System.out.println(vm); + redirectOutput(vm); + vm.resume(); + + while (vm.classesByName("Hello").size() == 0) {} + + + ReferenceType rt = (ReferenceType)vm.classesByName("Hello").get(0); + System.out.println(rt); + System.out.println(rt.availableStrata()); + try { + System.out.println(rt.sourceDebugExtension()); + System.out.println("Names: " + rt.sourceNames("AspectJ")); + } catch (AbsentInformationException aie) { + System.out.println("NO source debug extension"); + } + System.out.println("Name: " + rt.sourceName()); + + + for (Iterator i = rt.allLineLocations().iterator(); i.hasNext(); ) { + Location loc = (Location)i.next(); + System.out.println(" " + loc.sourceName() + ":" + loc.lineNumber()); + } + + + try { + //eventThread.join(); + errThread.join(); // Make sure output is forwarded + outThread.join(); // before we exit + } catch (InterruptedException exc) { + // we don't interrupt + } + + } + + /** + * Find a com.sun.jdi.CommandLineLaunch connector + */ + static LaunchingConnector findLaunchingConnector() { + List connectors = Bootstrap.virtualMachineManager().allConnectors(); + Iterator iter = connectors.iterator(); + while (iter.hasNext()) { + Connector connector = (Connector) iter.next(); + if (connector.name().equals("com.sun.jdi.CommandLineLaunch")) { + return (LaunchingConnector) connector; + } + } + throw new Error("No launching connector"); + } + + /** + * Return the launching connector's arguments. + */ + static Map connectorArguments(LaunchingConnector connector, String mainArgs) { + Map arguments = connector.defaultArguments(); + Connector.Argument mainArg = (Connector.Argument) arguments.get("main"); + if (mainArg == null) { + throw new Error("Bad launching connector"); + } + mainArg.setValue(mainArgs); + +// if (watchFields) { +// // We need a VM that supports watchpoints +// Connector.Argument optionArg = (Connector.Argument) arguments.get("options"); +// if (optionArg == null) { +// throw new Error("Bad launching connector"); +// } +// optionArg.setValue("-classic"); +// } + return arguments; + } + + static void redirectOutput(VirtualMachine vm) { + Process process = vm.process(); + + // Copy target's output and error to our output and error. + errThread = new StreamRedirectThread("error reader", + process.getErrorStream(), + System.err); + outThread = new StreamRedirectThread("output reader", + process.getInputStream(), + System.out); + errThread.start(); + outThread.start(); + } + +} + +class StreamRedirectThread extends Thread { + + private final Reader in; + private final Writer out; + + private static final int BUFFER_SIZE = 2048; + + /** + * Set up for copy. + * @param name Name of the thread + * @param in Stream to copy from + * @param out Stream to copy to + */ + StreamRedirectThread(String name, InputStream in, OutputStream out) { + super(name); + this.in = new InputStreamReader(in); + this.out = new OutputStreamWriter(out); + setPriority(Thread.MAX_PRIORITY-1); + } + + /** + * Copy. + */ + public void run() { + try { + char[] cbuf = new char[BUFFER_SIZE]; + int count; + while ((count = in.read(cbuf, 0, BUFFER_SIZE)) >= 0) { + out.write(cbuf, 0, count); + } + out.flush(); + } catch(IOException exc) { + System.err.println("Child I/O Transfer - " + exc); + } + } +} |