1 19 package org.netbeans.modules.java.editor.codegen; 20 21 import java.io.File ; 22 import java.io.FileInputStream ; 23 import java.io.FileOutputStream ; 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 import java.io.OutputStream ; 27 import java.util.ArrayList ; 28 import java.util.Collections ; 29 import java.util.List ; 30 import java.util.Map ; 31 import javax.lang.model.element.TypeElement; 32 import javax.lang.model.element.VariableElement; 33 import javax.lang.model.util.ElementFilter; 34 import org.netbeans.api.java.source.CompilationInfo; 35 import org.netbeans.api.java.source.JavaSource; 36 import org.netbeans.api.java.source.JavaSource.Phase; 37 import org.netbeans.api.java.source.JavaSource.Priority; 38 import org.netbeans.api.java.source.SourceUtilsTestUtil; 39 import org.netbeans.junit.NbTestCase; 40 import org.openide.filesystems.FileObject; 41 import org.openide.filesystems.FileUtil; 42 43 47 public class DelegateMethodGeneratorTest extends NbTestCase { 48 49 public DelegateMethodGeneratorTest(String testName) { 50 super(testName); 51 } 52 53 protected void setUp() throws Exception { 54 } 55 56 143 private FileObject testSourceFO; 144 private JavaSource source; 145 146 private void copyToWorkDir(File resource, File toFile) throws IOException { 147 InputStream is = new FileInputStream (resource); 149 OutputStream outs = new FileOutputStream (toFile); 150 151 int read; 152 153 while ((read = is.read()) != (-1)) { 154 outs.write(read); 155 } 156 157 outs.close(); 158 159 is.close(); 160 } 161 162 private void prepareTest(String fileName) throws Exception { 163 SourceUtilsTestUtil.prepareTest(new String [0], new Object [0]); 164 165 FileObject scratch = SourceUtilsTestUtil.makeScratchDir(this); 166 FileObject cache = scratch.createFolder("cache"); 167 168 File wd = getWorkDir(); 169 File testSource = new File (wd, "test/" + fileName + ".java"); 170 171 testSource.getParentFile().mkdirs(); 172 173 File dataFolder = new File (getDataDir(), "org/netbeans/modules/java/editor/codegen/data/"); 174 175 for (File f : dataFolder.listFiles()) { 176 copyToWorkDir(f, new File (wd, "test/" + f.getName())); 177 } 178 179 testSourceFO = FileUtil.toFileObject(testSource); 180 181 assertNotNull(testSourceFO); 182 183 File testBuildTo = new File (wd, "test-build"); 184 185 testBuildTo.mkdirs(); 186 187 SourceUtilsTestUtil.prepareTest(FileUtil.toFileObject(dataFolder), FileUtil.toFileObject(testBuildTo), cache); 188 SourceUtilsTestUtil.compileRecursively(FileUtil.toFileObject(dataFolder)); 189 190 source = JavaSource.forFileObject(testSourceFO); 191 } 192 } 193 | Popular Tags |