1 19 package org.netbeans.api.java.source; 20 21 import com.sun.source.tree.BlockTree; 22 import com.sun.source.util.TreePath; 23 import java.io.File ; 24 import org.netbeans.junit.NbTestCase; 25 import org.netbeans.modules.java.source.TestUtil; 26 import org.openide.filesystems.FileObject; 27 import org.openide.filesystems.FileUtil; 28 29 33 public class TreeUtilitiesTest extends NbTestCase { 34 35 public TreeUtilitiesTest(String testName) { 36 super(testName); 37 } 38 39 protected void setUp() throws Exception { 40 SourceUtilsTestUtil.prepareTest(new String [0], new Object [0]); 41 super.setUp(); 42 } 43 44 private CompilationInfo info; 45 46 private void prepareTest(String filename, String code) throws Exception { 47 File work = TestUtil.createWorkFolder(); 48 FileObject workFO = FileUtil.toFileObject(work); 49 50 assertNotNull(workFO); 51 52 FileObject sourceRoot = workFO.createFolder("src"); 53 FileObject buildRoot = workFO.createFolder("build"); 54 FileObject cache = workFO.createFolder("cache"); 55 FileObject packageRoot = sourceRoot.createFolder("test"); 56 57 SourceUtilsTestUtil.prepareTest(sourceRoot, buildRoot, cache); 58 59 FileObject testSource = packageRoot.createData(filename + ".java"); 60 61 assertNotNull(testSource); 62 63 TestUtilities.copyStringToFile(FileUtil.toFile(testSource), code); 64 65 JavaSource js = JavaSource.forFileObject(testSource); 66 67 assertNotNull(js); 68 69 info = SourceUtilsTestUtil.getCompilationInfo(js, JavaSource.Phase.RESOLVED); 70 71 assertNotNull(info); 72 } 73 74 public void testIsSynthetic1() throws Exception { 75 prepareTest("Test", "package test; public class Test {public Test(){}}"); 76 77 TreePath tp = info.getTreeUtilities().pathFor(47); 78 BlockTree bt = (BlockTree) tp.getLeaf(); 79 80 tp = new TreePath(tp, bt.getStatements().get(0)); 81 82 assertTrue(info.getTreeUtilities().isSynthetic(tp)); 83 } 84 85 public void testIsSynthetic2() throws Exception { 86 prepareTest("Test", "package test; public class Test {public Test(){super();}}"); 87 88 TreePath tp = info.getTreeUtilities().pathFor(47); 89 BlockTree bt = (BlockTree) tp.getLeaf(); 90 91 tp = new TreePath(tp, bt.getStatements().get(0)); 92 93 assertFalse(info.getTreeUtilities().isSynthetic(tp)); 94 } 95 } 96 | Popular Tags |