Skip to content

Commit

Permalink
Opened access to Java 11 language features.
Browse files Browse the repository at this point in the history
Moved from Java 8 to Java 11 for Compiler and JDT. Also added gramatical support for local variable type inference (var).
  • Loading branch information
sampottinger committed Aug 28, 2019
1 parent 8a502c7 commit 8e0bf4e
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 49 deletions.
4 changes: 2 additions & 2 deletions java/src/processing/mode/java/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ static public boolean compile(JavaBuild build) throws SketchException {
"-g",
"-Xemacs",
//"-noExit", // not necessary for ecj
"-source", "1.8",
"-target", "1.8",
"-source", "11",
"-target", "11",
"-encoding", "utf8",
"-classpath", classpathEmptyRemoved,
"-nowarn", // we're not currently interested in warnings (works in ecj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class PreprocessingService {

protected final JavaEditor editor;

protected final ASTParser parser = ASTParser.newParser(AST.JLS8);
protected final ASTParser parser = ASTParser.newParser(AST.JLS11);

private final Thread preprocessingThread;
private final BlockingQueue<Boolean> requestQueue = new ArrayBlockingQueue<>(1);
Expand Down
3 changes: 2 additions & 1 deletion java/src/processing/mode/java/preproc/JavaLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ THROW: 'throw';
THROWS: 'throws';
TRANSIENT: 'transient';
TRY: 'try';
VAR: 'var';
VOID: 'void';
VOLATILE: 'volatile';
WHILE: 'while';
Expand Down Expand Up @@ -189,4 +190,4 @@ fragment Letter
: [a-zA-Z$_] // these are the "java letters" below 0x7F
| ~[\u0000-\u007F\uD800-\uDBFF] // covers all characters above 0x7F which are not a surrogate
| [\uD800-\uDBFF] [\uDC00-\uDFFF] // covers UTF-16 surrogate pairs encodings for U+10000 to U+10FFFF
;
;
4 changes: 2 additions & 2 deletions java/src/processing/mode/java/preproc/JavaParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ typeList
;

typeType
: annotation? (classOrInterfaceType | primitiveType) ('[' ']')*
: annotation? (classOrInterfaceType | primitiveType | VAR) ('[' ']')*
;

primitiveType
Expand Down Expand Up @@ -612,4 +612,4 @@ explicitGenericInvocationSuffix

arguments
: '(' expressionList? ')'
;
;
13 changes: 9 additions & 4 deletions java/test/processing/mode/java/ParserTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static void expectGood(final String id, boolean ignoreWhitespace) {
}
}

/*@Test
@Test
public void bug4() {
expectGood("bug4");
}
Expand Down Expand Up @@ -170,7 +170,7 @@ public void bug136() {

@Test
public void bug196() {
expectRecognitionException("bug196", 4);
expectRecognitionException("bug196", 5);
}

@Test
Expand Down Expand Up @@ -200,7 +200,7 @@ public void bug631() {

@Test
public void bug763() {
expectRunnerException("bug763", 7);
expectRunnerException("bug763", 8);
}

@Test
Expand Down Expand Up @@ -251,7 +251,7 @@ public void bug1514a() {
@Test
public void bug1514b() {
expectGood("bug1514b");
}*/
}

@Test
public void bug1515() {
Expand Down Expand Up @@ -363,6 +363,11 @@ public void charSpecial() {
expectGood("charspecial", true);
}

@Test
public void typeInference() {
expectGood("typeinference");
}

private static boolean compile(String id, String program) {
// Create compilable AST to get syntax problems
CompilationUnit compilableCU = JdtCompilerUtil.makeAST(
Expand Down
69 changes: 30 additions & 39 deletions java/test/resources/bug598.expected
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import processing.data.*;
import processing.event.*;
import processing.opengl.*;

import static java.lang.Math.tanh;
import java.lang.Math.tanh;
import java.util.concurrent.Callable;
import java.util.List;
import java.util.Comparator;
Expand All @@ -23,49 +23,40 @@ import java.io.IOException;

public class bug598 extends PApplet {

// java 5 torture test









// java 5 torture test

private static Comparator<String> rotarapmoc = new Comparator<String>() {
public int compare(final String o1, final String o2)
{
return o1.charAt(o1.length() - 1) - o2.charAt(o2.length() - 1);
}
};

private static Comparator<String> rotarapmoc = new Comparator<String>() {
public int compare(final String o1, final String o2)
{
return o1.charAt(o1.length() - 1) - o2.charAt(o2.length() - 1);
public final <T> void printClass(T t) {
println(t.getClass());
}
};

final public <T> void printClass(T t) {
println(t.getClass());
}
final public List<String> sortem(final String... strings) {
Arrays.sort(strings, rotarapmoc);
return Arrays.asList(strings);
}
public final List<String> sortem(final String... strings) {
Arrays.sort(strings, rotarapmoc);
return Arrays.asList(strings);
}

final Map<String, Collection<Integer>>
charlesDeGaulle = new HashMap<String, Collection<Integer>>();
final Map<String, Collection<Integer>>
charlesDeGaulle = new HashMap<String, Collection<Integer>>();

public void setup() {
charlesDeGaulle.put("banana", new HashSet<Integer>());
charlesDeGaulle.get("banana").add(0);
System.out.println(sortem("aztec", "maya", "spanish", "portuguese"));
printClass(12.d);
}
public void setup() {
charlesDeGaulle.put("banana", new HashSet<Integer>());
charlesDeGaulle.get("banana").add(0);
System.out.println(sortem("aztec", "maya", "spanish", "portuguese"));
printClass(12.d);
}

static public void main(String[] passedArgs) {
String[] appletArgs = new String[] { "bug598" };
if (passedArgs != null) {
PApplet.main(concat(appletArgs, passedArgs));
} else {
PApplet.main(appletArgs);
}
}
static public void main(String[] passedArgs) {
String[] appletArgs = new String[] { "bug598" };
if (passedArgs != null) {
PApplet.main(concat(appletArgs, passedArgs));
} else {
PApplet.main(appletArgs);
}
}
}
44 changes: 44 additions & 0 deletions java/test/resources/typeinference.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import processing.core.*;
import processing.data.*;
import processing.event.*;
import processing.opengl.*;

import java.util.*;
import java.util.function.*;

import java.util.HashMap;
import java.util.ArrayList;
import java.io.File;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;

public class typeinference extends PApplet {

public void setup() {
List<String> list = new ArrayList<>();
list.add("line1\nline2");
list.add("line3");

// Local variable type inference in loop
for (var s : list) {
println(s);
}

// Local variable type inference
var testString = list.get(0);
println(testString.lines().count()); // Java 11 API
}


static public void main(String[] passedArgs) {
String[] appletArgs = new String[] { "typeinference" };
if (passedArgs != null) {
PApplet.main(concat(appletArgs, passedArgs));
} else {
PApplet.main(appletArgs);
}
}
}
17 changes: 17 additions & 0 deletions java/test/resources/typeinference.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import java.util.*;
import java.util.function.*;

void setup() {
List<String> list = new ArrayList<>();
list.add("line1\nline2");
list.add("line3");

// Local variable type inference in loop
for (var s : list) {
println(s);
}

// Local variable type inference
var testString = list.get(0);
println(testString.lines().count()); // Java 11 API
}

0 comments on commit 8e0bf4e

Please sign in to comment.