Skip to content

Commit 8e0bf4e

Browse files
committed
Opened access to Java 11 language features.
Moved from Java 8 to Java 11 for Compiler and JDT. Also added gramatical support for local variable type inference (var).
1 parent 8a502c7 commit 8e0bf4e

File tree

8 files changed

+107
-49
lines changed

8 files changed

+107
-49
lines changed

java/src/processing/mode/java/Compiler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ static public boolean compile(JavaBuild build) throws SketchException {
6969
"-g",
7070
"-Xemacs",
7171
//"-noExit", // not necessary for ecj
72-
"-source", "1.8",
73-
"-target", "1.8",
72+
"-source", "11",
73+
"-target", "11",
7474
"-encoding", "utf8",
7575
"-classpath", classpathEmptyRemoved,
7676
"-nowarn", // we're not currently interested in warnings (works in ecj)

java/src/processing/mode/java/pdex/PreprocessingService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public class PreprocessingService {
7272

7373
protected final JavaEditor editor;
7474

75-
protected final ASTParser parser = ASTParser.newParser(AST.JLS8);
75+
protected final ASTParser parser = ASTParser.newParser(AST.JLS11);
7676

7777
private final Thread preprocessingThread;
7878
private final BlockingQueue<Boolean> requestQueue = new ArrayBlockingQueue<>(1);

java/src/processing/mode/java/preproc/JavaLexer.g4

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ THROW: 'throw';
7676
THROWS: 'throws';
7777
TRANSIENT: 'transient';
7878
TRY: 'try';
79+
VAR: 'var';
7980
VOID: 'void';
8081
VOLATILE: 'volatile';
8182
WHILE: 'while';
@@ -189,4 +190,4 @@ fragment Letter
189190
: [a-zA-Z$_] // these are the "java letters" below 0x7F
190191
| ~[\u0000-\u007F\uD800-\uDBFF] // covers all characters above 0x7F which are not a surrogate
191192
| [\uD800-\uDBFF] [\uDC00-\uDFFF] // covers UTF-16 surrogate pairs encodings for U+10000 to U+10FFFF
192-
;
193+
;

java/src/processing/mode/java/preproc/JavaParser.g4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ typeList
582582
;
583583

584584
typeType
585-
: annotation? (classOrInterfaceType | primitiveType) ('[' ']')*
585+
: annotation? (classOrInterfaceType | primitiveType | VAR) ('[' ']')*
586586
;
587587

588588
primitiveType
@@ -612,4 +612,4 @@ explicitGenericInvocationSuffix
612612

613613
arguments
614614
: '(' expressionList? ')'
615-
;
615+
;

java/test/processing/mode/java/ParserTests.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static void expectGood(final String id, boolean ignoreWhitespace) {
138138
}
139139
}
140140

141-
/*@Test
141+
@Test
142142
public void bug4() {
143143
expectGood("bug4");
144144
}
@@ -170,7 +170,7 @@ public void bug136() {
170170

171171
@Test
172172
public void bug196() {
173-
expectRecognitionException("bug196", 4);
173+
expectRecognitionException("bug196", 5);
174174
}
175175

176176
@Test
@@ -200,7 +200,7 @@ public void bug631() {
200200

201201
@Test
202202
public void bug763() {
203-
expectRunnerException("bug763", 7);
203+
expectRunnerException("bug763", 8);
204204
}
205205

206206
@Test
@@ -251,7 +251,7 @@ public void bug1514a() {
251251
@Test
252252
public void bug1514b() {
253253
expectGood("bug1514b");
254-
}*/
254+
}
255255

256256
@Test
257257
public void bug1515() {
@@ -363,6 +363,11 @@ public void charSpecial() {
363363
expectGood("charspecial", true);
364364
}
365365

366+
@Test
367+
public void typeInference() {
368+
expectGood("typeinference");
369+
}
370+
366371
private static boolean compile(String id, String program) {
367372
// Create compilable AST to get syntax problems
368373
CompilationUnit compilableCU = JdtCompilerUtil.makeAST(

java/test/resources/bug598.expected

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import processing.data.*;
33
import processing.event.*;
44
import processing.opengl.*;
55

6-
import static java.lang.Math.tanh;
6+
import java.lang.Math.tanh;
77
import java.util.concurrent.Callable;
88
import java.util.List;
99
import java.util.Comparator;
@@ -23,49 +23,40 @@ import java.io.IOException;
2323

2424
public class bug598 extends PApplet {
2525

26-
// java 5 torture test
27-
28-
29-
30-
31-
32-
33-
34-
35-
26+
// java 5 torture test
3627

28+
private static Comparator<String> rotarapmoc = new Comparator<String>() {
29+
public int compare(final String o1, final String o2)
30+
{
31+
return o1.charAt(o1.length() - 1) - o2.charAt(o2.length() - 1);
32+
}
33+
};
3734

38-
private static Comparator<String> rotarapmoc = new Comparator<String>() {
39-
public int compare(final String o1, final String o2)
40-
{
41-
return o1.charAt(o1.length() - 1) - o2.charAt(o2.length() - 1);
35+
public final <T> void printClass(T t) {
36+
println(t.getClass());
4237
}
43-
};
4438

45-
final public <T> void printClass(T t) {
46-
println(t.getClass());
47-
}
48-
final public List<String> sortem(final String... strings) {
49-
Arrays.sort(strings, rotarapmoc);
50-
return Arrays.asList(strings);
51-
}
39+
public final List<String> sortem(final String... strings) {
40+
Arrays.sort(strings, rotarapmoc);
41+
return Arrays.asList(strings);
42+
}
5243

53-
final Map<String, Collection<Integer>>
54-
charlesDeGaulle = new HashMap<String, Collection<Integer>>();
44+
final Map<String, Collection<Integer>>
45+
charlesDeGaulle = new HashMap<String, Collection<Integer>>();
5546

56-
public void setup() {
57-
charlesDeGaulle.put("banana", new HashSet<Integer>());
58-
charlesDeGaulle.get("banana").add(0);
59-
System.out.println(sortem("aztec", "maya", "spanish", "portuguese"));
60-
printClass(12.d);
61-
}
47+
public void setup() {
48+
charlesDeGaulle.put("banana", new HashSet<Integer>());
49+
charlesDeGaulle.get("banana").add(0);
50+
System.out.println(sortem("aztec", "maya", "spanish", "portuguese"));
51+
printClass(12.d);
52+
}
6253

63-
static public void main(String[] passedArgs) {
64-
String[] appletArgs = new String[] { "bug598" };
65-
if (passedArgs != null) {
66-
PApplet.main(concat(appletArgs, passedArgs));
67-
} else {
68-
PApplet.main(appletArgs);
69-
}
70-
}
54+
static public void main(String[] passedArgs) {
55+
String[] appletArgs = new String[] { "bug598" };
56+
if (passedArgs != null) {
57+
PApplet.main(concat(appletArgs, passedArgs));
58+
} else {
59+
PApplet.main(appletArgs);
60+
}
61+
}
7162
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import processing.core.*;
2+
import processing.data.*;
3+
import processing.event.*;
4+
import processing.opengl.*;
5+
6+
import java.util.*;
7+
import java.util.function.*;
8+
9+
import java.util.HashMap;
10+
import java.util.ArrayList;
11+
import java.io.File;
12+
import java.io.BufferedReader;
13+
import java.io.PrintWriter;
14+
import java.io.InputStream;
15+
import java.io.OutputStream;
16+
import java.io.IOException;
17+
18+
public class typeinference extends PApplet {
19+
20+
public void setup() {
21+
List<String> list = new ArrayList<>();
22+
list.add("line1\nline2");
23+
list.add("line3");
24+
25+
// Local variable type inference in loop
26+
for (var s : list) {
27+
println(s);
28+
}
29+
30+
// Local variable type inference
31+
var testString = list.get(0);
32+
println(testString.lines().count()); // Java 11 API
33+
}
34+
35+
36+
static public void main(String[] passedArgs) {
37+
String[] appletArgs = new String[] { "typeinference" };
38+
if (passedArgs != null) {
39+
PApplet.main(concat(appletArgs, passedArgs));
40+
} else {
41+
PApplet.main(appletArgs);
42+
}
43+
}
44+
}

java/test/resources/typeinference.pde

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import java.util.*;
2+
import java.util.function.*;
3+
4+
void setup() {
5+
List<String> list = new ArrayList<>();
6+
list.add("line1\nline2");
7+
list.add("line3");
8+
9+
// Local variable type inference in loop
10+
for (var s : list) {
11+
println(s);
12+
}
13+
14+
// Local variable type inference
15+
var testString = list.get(0);
16+
println(testString.lines().count()); // Java 11 API
17+
}

0 commit comments

Comments
 (0)