|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.javacore.astmatching; import java.util.Collections; import java.util.LinkedList; import java.util.List; import javax.swing.text.StyledDocument; import junit.textui.TestRunner; import org.netbeans.jmi.javamodel.Element; import org.netbeans.jmi.javamodel.JavaClass; import org.netbeans.jmi.javamodel.JavaModelPackage; import org.netbeans.jmi.javamodel.Method; import org.netbeans.jmi.javamodel.Parameter; import org.netbeans.jmi.javamodel.Type; import org.netbeans.jmi.javamodel.codegen.Utility; import org.netbeans.junit.NbTestCase; import org.netbeans.junit.NbTestSuite; /** * @author Jan Becicka */ public class MethodsTest extends NbTestCase { private static final String method1 = "\n" + "public static void main (java.lang.String args[]) {\n" + "System.out.println(\"foo\");\n" + "}\n"; /** Need to be defined because of JUnit */ public MethodsTest(String name) { super(name); } public static NbTestSuite suite() { NbTestSuite suite = new NbTestSuite(); suite.addTest(new MethodsTest("testAddMethod")); suite.addTest(new MethodsTest("testChangeMethod")); //suite.addTest(new MethodsTest("testRemoveMethod")); return suite; } /** Use for execution inside IDE */ public static void main(java.lang.String[] args) { TestRunner.run(suite()); } protected void setUp() { } public void testAddMethod() { JavaClass clazz = Utility.findClass("org.netbeans.test.astmatching.ClassOne"); StyledDocument doc = Utility.getDocument(clazz); Element after = clazz.getField("instanceCounter", false); MatchUtils.addElement(doc, after, method1); Utility.beginTrans(true); try { Method me = MatchUtils.getMethod(clazz, "main", "java.lang.String[]"); assertNotNull(me); } finally { Utility.endTrans(); } } public void testChangeMethod() { JavaClass clazz = Utility.findClass("org.netbeans.test.astmatching.ClassOne"); StyledDocument doc = Utility.getDocument(clazz); Method m = MatchUtils.getMethod(clazz, "main", "java.lang.String[]"); Parameter p = (Parameter) m.getParameters().iterator().next(); MatchUtils.addElement(doc, p, ", int a"); Utility.beginTrans(true); try { Method me = MatchUtils.getMethod(clazz, "main", "java.lang.String[],int"); assertNotNull(me); } finally { Utility.endTrans(); } } public void testRemoveMethod() { } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.