Move to ANTLR 4 with Java 11 lang features and localization. (#5)

* Move to ANTLR 4 with Java 11 lang features and localization.

Introduces ANTLR4 and Java 8 language feature support within IDE while also adding additional hooks for localization of syntax error messages, addressing https://github.com/processing/processing/issues/3054 and https://github.com/processing/processing/issues/3055.

The PR is broadly a continuation of https://github.com/processing/processing/issues/3055, bringing it up to speed with the latest Processing master plus the changes introduced at https://github.com/processing/processing/pull/5753. **Requires https://github.com/processing/processing/pull/5753 as pre-requisite.** This introduces a number of edits beyond https://github.com/processing/processing/issues/3055 beyond compatibility with current Processing master and https://github.com/processing/processing/pull/5753 including:

 - Update to the grammar itself
 - Change ANTLR listeners to emit `TextTransform.Edit` to unify JDT-based `PreprocessingService` and `JavaBuild`, removing code with duplicate purpose.
 - Introduction of syntax error rewriting with support for localization.
 - Addition of complete localized strings set for English and Spanish.
 - Addition of partial localized strings set for other languages.
 - Refactor of ANTLR-related code for testability and readability
 - Expansion of tests including full parse tests for new Java features (type inference, lambdas).

* Ask travis for ant upgrade prior to run.

* Ask Travis for java11 update.

* Add openjdk ppa

* Travis no confirmation on add ppa.

* Force newer ant on travis.

* Swtich ant download to www-us mirror.

* Switch ant to 1.10.7

* Start x for unit tests in travis.

* More complete start x in travis.

* Revert x in travis.

* Try x in services.
This commit is contained in:
A Samuel Pottinger
2019-10-05 23:34:38 -07:00
committed by GitHub
parent 00dd2803f0
commit ee299ef935
254 changed files with 9327 additions and 6468 deletions

View File

@@ -0,0 +1,87 @@
package processing.mode.java;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringWriter;
import processing.app.Preferences;
import processing.app.SketchException;
import processing.mode.java.preproc.PdePreprocessor;
import processing.mode.java.preproc.PreprocessorResult;
import processing.mode.java.preproc.issue.PdePreprocessIssueException;
public class ProcessingTestUtil {
static void init() {
// noop; just causes class to be loaded
}
private static final String RESOURCES = "test/resources/";
private static final String RESOURCES_UP_DIR = "../java/test/resources";
static final UTCompiler COMPILER;
static {
try {
COMPILER = new UTCompiler(new File("bin-test"), new File("../core/bin"));
Preferences.load(new FileInputStream(res("preferences.txt")));
} catch (Exception e) {
throw new RuntimeException(e);
}
//System.err.println("ProcessingTestUtil initialized.");
}
static String normalize(final Object s) {
return String.valueOf(s).replace("\r", "");
}
static String preprocess(final String name, final File resource)
throws SketchException {
final String program = read(resource);
final StringWriter out = new StringWriter();
PreprocessorResult result = new PdePreprocessor(name, 4, true).write(out, program);
if (result.getPreprocessIssues().size() > 0) {
throw new PdePreprocessIssueException(result.getPreprocessIssues().get(0));
}
return normalize(out);
}
static String format(final File resource)
{
return format(read(resource));
}
static String format(final String programText) {
return normalize(new AutoFormat().format(programText));
}
static File res(final String resourceName) {
File target = new File(RESOURCES, resourceName);
if (target.exists()) {
return target;
}
return new File(RESOURCES_UP_DIR, resourceName);
}
static String read(final File f) {
try {
final FileInputStream fin = new FileInputStream(f);
final InputStreamReader in = new InputStreamReader(fin, "UTF-8");
try {
final StringBuilder sb = new StringBuilder();
final char[] buf = new char[1 << 12];
int len;
while ((len = in.read(buf)) != -1)
sb.append(buf, 0, len);
return normalize(sb);
} finally {
in.close();
}
} catch (Exception e) {
throw new RuntimeException("Unexpected", e);
}
}
}