| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 328234a commit c6aa0ea
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,7 @@ | |||
| 9 | 9 | import java.io.PrintWriter; | |
| 10 | 10 | import java.text.SimpleDateFormat; | |
| 11 | 11 | import java.util.HashMap; | |
| 12 | + import java.util.List; | ||
| 12 | 13 | import org.apache.tools.ant.BuildException; | |
| 13 | 14 | import org.apache.tools.ant.DefaultLogger; | |
| 14 | 15 | import org.apache.tools.ant.Project; | |
@@ -107,8 +108,7 @@ public boolean createProject() { | |||
| 107 | 108 | ||
| 108 | 109 | // grab code from current editing window | |
| 109 | 110 | sketch.prepare(); | |
| 110 | - className = sketch.preprocess(buildPath, new Preproc(buildPath, sketch | ||
| 111 | - .getName())); | ||
| 111 | + className = sketch.preprocess(buildPath, new Preproc(sketch.getName())); | ||
| 112 | 112 | if (className != null) { | |
| 113 | 113 | final File androidXML = new File(androidFolder, "AndroidManifest.xml"); | |
| 114 | 114 | writeAndroidManifest(androidXML, sketch.getName(), className); | |
@@ -325,17 +325,18 @@ String getPathForAPK(final String target) { | |||
| 325 | 325 | ||
| 326 | 326 | class Preproc extends PdePreprocessor { | |
| 327 | 327 | ||
| 328 | - public Preproc(final String buildPath, final String sketchName) | ||
| 329 | - throws IOException { | ||
| 330 | - super(buildPath, sketchName); | ||
| 328 | + public Preproc(final String sketchName) throws IOException { | ||
| 329 | + super(sketchName); | ||
| 331 | 330 | } | |
| 332 | 331 | ||
| 333 | 332 | @Override | |
| 334 | - public int writeImports(final PrintStream out) { | ||
| 333 | + protected int writeImports(final PrintStream out, | ||
| 334 | + final List<String> programImports, | ||
| 335 | + final List<String> codeFolderImports) { | ||
| 335 | 336 | out.println("package " + getPackageName() + ";"); | |
| 336 | 337 | out.println(); | |
| 337 | 338 | // add two lines for the package above | |
| 338 | - return 2 + super.writeImports(out); | ||
| 339 | + return 2 + super.writeImports(out, programImports, codeFolderImports); | ||
| 339 | 340 | } | |
| 340 | 341 | ||
| 341 | 342 | @Override | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1203,7 +1203,7 @@ public void prepare() { | |||
| 1203 | 1203 | */ | |
| 1204 | 1204 | public String preprocess(String buildPath) throws RunnerException { | |
| 1205 | 1205 | try { | |
| 1206 | - return preprocess(buildPath, new PdePreprocessor(buildPath, name)); | ||
| 1206 | + return preprocess(buildPath, new PdePreprocessor(name)); | ||
| 1207 | 1207 | } catch (IOException e) { | |
| 1208 | 1208 | throw new RunnerException("Error while preprocessing", true); | |
| 1209 | 1209 | } | |
@@ -1250,30 +1250,20 @@ public String preprocess(String buildPath, PdePreprocessor preprocessor) throws | |||
| 1250 | 1250 | } | |
| 1251 | 1251 | } | |
| 1252 | 1252 | ||
| 1253 | - // Note that the headerOffset isn't applied until compile and run, because | ||
| 1254 | - // it only applies to the code after it's been written to the .java file. | ||
| 1255 | - int headerOffset = 0; | ||
| 1253 | + final PreprocessResult result; | ||
| 1256 | 1254 | try { | |
| 1257 | - headerOffset = preprocessor.writePrefix(bigCode.toString(), codeFolderPackages); | ||
| 1255 | + final File java = new File(buildPath, name + ".java"); | ||
| 1256 | + final PrintStream stream = new PrintStream(new FileOutputStream(java)); | ||
| 1257 | + try { | ||
| 1258 | + result = preprocessor.write(stream, bigCode.toString(), | ||
| 1259 | + codeFolderPackages); | ||
| 1260 | + } finally { | ||
| 1261 | + stream.close(); | ||
| 1262 | + } | ||
| 1258 | 1263 | } catch (FileNotFoundException fnfe) { | |
| 1259 | 1264 | fnfe.printStackTrace(); | |
| 1260 | 1265 | String msg = "Build folder disappeared or could not be written"; | |
| 1261 | 1266 | throw new RunnerException(msg); | |
| 1262 | - } | ||
| 1263 | - | ||
| 1264 | - // 2. run preproc on that code using the sugg class name | ||
| 1265 | - // to create a single .java file and write to buildpath | ||
| 1266 | - | ||
| 1267 | - String primaryClassName = null; | ||
| 1268 | - | ||
| 1269 | - try { | ||
| 1270 | - final String className = preprocessor.write(); | ||
| 1271 | - if (className == null) { | ||
| 1272 | - throw new RunnerException("Could not find main class"); | ||
| 1273 | - } | ||
| 1274 | - | ||
| 1275 | - // store this for the compiler and the runtime | ||
| 1276 | - primaryClassName = className; | ||
| 1277 | 1267 | } catch (antlr.RecognitionException re) { | |
| 1278 | 1268 | // re also returns a column that we're not bothering with for now | |
| 1279 | 1269 | ||
@@ -1394,7 +1384,7 @@ public String preprocess(String buildPath, PdePreprocessor preprocessor) throws | |||
| 1394 | 1384 | // grab the imports from the code just preproc'd | |
| 1395 | 1385 | ||
| 1396 | 1386 | importedLibraries = new ArrayList<File>(); | |
| 1397 | - for (String item : preprocessor.getExtraImports()) { | ||
| 1387 | + for (String item : result.extraImports) { | ||
| 1398 | 1388 | // remove things up to the last dot | |
| 1399 | 1389 | int dot = item.lastIndexOf('.'); | |
| 1400 | 1390 | // http://dev.processing.org/bugs/show_bug.cgi?id=1145 | |
@@ -1433,15 +1423,14 @@ public String preprocess(String buildPath, PdePreprocessor preprocessor) throws | |||
| 1433 | 1423 | throw new RunnerException("Problem moving " + filename + | |
| 1434 | 1424 | " to the build folder"); | |
| 1435 | 1425 | } | |
| 1436 | - // sc.setPreprocName(filename); | ||
| 1437 | 1426 | ||
| 1438 | 1427 | } else if (sc.isExtension("pde")) { | |
| 1439 | 1428 | // The compiler and runner will need this to have a proper offset | |
| 1440 | - sc.addPreprocOffset(headerOffset); | ||
| 1429 | + sc.addPreprocOffset(result.headerOffset); | ||
| 1441 | 1430 | } | |
| 1442 | 1431 | } | |
| 1443 | 1432 | foundMain = preprocessor.getFoundMain(); | |
| 1444 | - return primaryClassName; | ||
| 1433 | + return result.className; | ||
| 1445 | 1434 | } | |
| 1446 | 1435 | ||
| 1447 | 1436 | public boolean getFoundMain() { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments