FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Many changes to improve the decoupling and testability of the preproc… · HAPI-Tech-Solution/processing@c6aa0ea · GitHub

Repository navigation

Commit c6aa0ea

Browse files
jdf
committed
Many changes to improve the decoupling and testability of the preprocessor. For example, you no longer have to set up anything on the filesystem in order to preprocess.
1 parent 328234a commit c6aa0ea

5 files changed

Lines changed: 147 additions & 134 deletions

File tree

‎android/tool/src/processing/app/tools/android/Build.java‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.io.PrintWriter;
1010
import java.text.SimpleDateFormat;
1111
import java.util.HashMap;
12+
import java.util.List;
1213
import org.apache.tools.ant.BuildException;
1314
import org.apache.tools.ant.DefaultLogger;
1415
import org.apache.tools.ant.Project;
@@ -107,8 +108,7 @@ public boolean createProject() {
107108

108109
// grab code from current editing window
109110
sketch.prepare();
110-
className = sketch.preprocess(buildPath, new Preproc(buildPath, sketch
111-
.getName()));
111+
className = sketch.preprocess(buildPath, new Preproc(sketch.getName()));
112112
if (className != null) {
113113
final File androidXML = new File(androidFolder, "AndroidManifest.xml");
114114
writeAndroidManifest(androidXML, sketch.getName(), className);
@@ -325,17 +325,18 @@ String getPathForAPK(final String target) {
325325

326326
class Preproc extends PdePreprocessor {
327327

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);
331330
}
332331

333332
@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) {
335336
out.println("package " + getPackageName() + ";");
336337
out.println();
337338
// add two lines for the package above
338-
return 2 + super.writeImports(out);
339+
return 2 + super.writeImports(out, programImports, codeFolderImports);
339340
}
340341

341342
@Override

‎app/src/processing/app/Sketch.java‎

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ public void prepare() {
12031203
*/
12041204
public String preprocess(String buildPath) throws RunnerException {
12051205
try {
1206-
return preprocess(buildPath, new PdePreprocessor(buildPath, name));
1206+
return preprocess(buildPath, new PdePreprocessor(name));
12071207
} catch (IOException e) {
12081208
throw new RunnerException("Error while preprocessing", true);
12091209
}
@@ -1250,30 +1250,20 @@ public String preprocess(String buildPath, PdePreprocessor preprocessor) throws
12501250
}
12511251
}
12521252

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;
12561254
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+
}
12581263
} catch (FileNotFoundException fnfe) {
12591264
fnfe.printStackTrace();
12601265
String msg = "Build folder disappeared or could not be written";
12611266
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;
12771267
} catch (antlr.RecognitionException re) {
12781268
// re also returns a column that we're not bothering with for now
12791269

@@ -1394,7 +1384,7 @@ public String preprocess(String buildPath, PdePreprocessor preprocessor) throws
13941384
// grab the imports from the code just preproc'd
13951385

13961386
importedLibraries = new ArrayList<File>();
1397-
for (String item : preprocessor.getExtraImports()) {
1387+
for (String item : result.extraImports) {
13981388
// remove things up to the last dot
13991389
int dot = item.lastIndexOf('.');
14001390
// http://dev.processing.org/bugs/show_bug.cgi?id=1145
@@ -1433,15 +1423,14 @@ public String preprocess(String buildPath, PdePreprocessor preprocessor) throws
14331423
throw new RunnerException("Problem moving " + filename +
14341424
" to the build folder");
14351425
}
1436-
// sc.setPreprocName(filename);
14371426

14381427
} else if (sc.isExtension("pde")) {
14391428
// The compiler and runner will need this to have a proper offset
1440-
sc.addPreprocOffset(headerOffset);
1429+
sc.addPreprocOffset(result.headerOffset);
14411430
}
14421431
}
14431432
foundMain = preprocessor.getFoundMain();
1444-
return primaryClassName;
1433+
return result.className;
14451434
}
14461435

14471436
public boolean getFoundMain() {

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL