1 19 package org.netbeans.modules.javacore.astmatching; 20 21 import java.util.Collections ; 22 import java.util.LinkedList ; 23 import java.util.List ; 24 import javax.swing.text.StyledDocument ; 25 import junit.textui.TestRunner; 26 27 import org.netbeans.jmi.javamodel.Element; 28 import org.netbeans.jmi.javamodel.JavaClass; 29 import org.netbeans.jmi.javamodel.JavaModelPackage; 30 import org.netbeans.jmi.javamodel.Method; 31 import org.netbeans.jmi.javamodel.Parameter; 32 import org.netbeans.jmi.javamodel.Type; 33 import org.netbeans.jmi.javamodel.codegen.Utility; 34 import org.netbeans.junit.NbTestCase; 35 import org.netbeans.junit.NbTestSuite; 36 37 38 41 public class MethodsTest extends NbTestCase { 42 43 private static final String method1 = "\n" + 44 "public static void main (java.lang.String args[]) {\n" + 45 "System.out.println(\"foo\");\n" + 46 "}\n"; 47 48 49 public MethodsTest(String name) { 50 super(name); 51 52 } 53 54 public static NbTestSuite suite() { 55 NbTestSuite suite = new NbTestSuite(); 56 suite.addTest(new MethodsTest("testAddMethod")); 57 suite.addTest(new MethodsTest("testChangeMethod")); 58 return suite; 60 } 61 62 63 public static void main(java.lang.String [] args) { 64 TestRunner.run(suite()); 65 } 66 67 protected void setUp() { 68 } 69 70 public void testAddMethod() { 71 JavaClass clazz = Utility.findClass("org.netbeans.test.astmatching.ClassOne"); 72 73 StyledDocument doc = Utility.getDocument(clazz); 74 Element after = clazz.getField("instanceCounter", false); 75 76 MatchUtils.addElement(doc, after, method1); 77 78 Utility.beginTrans(true); 79 try { 80 Method me = MatchUtils.getMethod(clazz, "main", "java.lang.String[]"); 81 assertNotNull(me); 82 } finally { 83 Utility.endTrans(); 84 } 85 } 86 87 public void testChangeMethod() { 88 JavaClass clazz = Utility.findClass("org.netbeans.test.astmatching.ClassOne"); 89 90 StyledDocument doc = Utility.getDocument(clazz); 91 Method m = MatchUtils.getMethod(clazz, "main", "java.lang.String[]"); 92 93 Parameter p = (Parameter) m.getParameters().iterator().next(); 94 MatchUtils.addElement(doc, p, ", int a"); 95 96 Utility.beginTrans(true); 97 try { 98 Method me = MatchUtils.getMethod(clazz, "main", "java.lang.String[],int"); 99 assertNotNull(me); 100 } finally { 101 Utility.endTrans(); 102 } 103 } 104 105 public void testRemoveMethod() { 106 107 108 } 109 110 } 111 | Popular Tags |