1 19 package org.netbeans.api.java.source.gen; 20 21 import com.sun.source.tree.ClassTree; 22 import com.sun.source.tree.ExpressionTree; 23 import com.sun.source.tree.LiteralTree; 24 import com.sun.source.tree.Tree; 25 import com.sun.source.tree.VariableTree; 26 import java.io.IOException ; 27 import java.util.ArrayList ; 28 import java.util.Collections ; 29 import java.util.List ; 30 import javax.lang.model.element.Modifier; 31 import junit.textui.TestRunner; 32 import org.netbeans.api.java.source.transform.Transformer; 33 import org.netbeans.junit.NbTestCase; 34 import org.netbeans.junit.NbTestSuite; 35 import org.openide.filesystems.FileStateInvalidException; 36 37 43 public class FieldTest4 extends GeneratorTest { 44 45 46 public FieldTest4(String name) { 47 super(name); 48 } 49 50 public static NbTestSuite suite() { 51 NbTestSuite suite = new NbTestSuite(FieldTest4.class); 52 return suite; 53 } 54 55 protected void setUp() throws Exception { 56 super.setUp(); 57 testFile = getFile(getSourceDir(), getSourcePckg() + "FieldTest4.java"); 58 } 59 60 63 public void testAddField() throws IOException { 64 process( 65 new Transformer<Void , Object >() { 66 public Void visitClass(ClassTree node, Object p) { 67 super.visitClass(node, p); 68 VariableTree vtecko = make.Variable( 69 make.Modifiers(Collections.singleton(Modifier.PROTECTED)), 70 "newField", 71 make.Identifier("String"), 72 null 73 ); 74 List <Tree> memberDecl = new ArrayList <Tree>(node.getMembers()); 75 memberDecl.add(vtecko); 76 ClassTree ct = make.Class(node.getModifiers(), 77 node.getSimpleName(), 78 node.getTypeParameters(), 79 node.getExtendsClause(), 80 (List <ExpressionTree>) node.getImplementsClause(), 81 memberDecl); 82 model.setElement(ct, model.getElement(node)); 83 model.setType(ct, model.getType(node)); 84 copyCommentTo(node, ct); 85 changes.rewrite(node, ct); 86 return null; 87 } 88 } 89 ); 90 assertFiles("testAddField_FieldTest4.pass"); 91 } 92 93 96 public static void main(String [] args) { 97 TestRunner.run(suite()); 98 } 99 100 String getSourcePckg() { 101 return "org/netbeans/test/codegen/"; 102 } 103 104 String getGoldenPckg() { 105 return "org/netbeans/jmi/javamodel/codegen/FieldTest4/"; 106 } 107 } 108 | Popular Tags |