-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1370 from jplag/feature/java-21
Java 21
- Loading branch information
Showing
18 changed files
with
199 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
core/src/test/resources/de/jplag/samples/NewJavaFeatures/A/Java21.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
public class Java21 { | ||
private static final record Circle(int radius) { | ||
} | ||
|
||
private static final record Rect(int width, int height) { | ||
} | ||
|
||
private static final record Both(Circle circle, Rect rect) { | ||
} | ||
|
||
private static final record Square(int length) { | ||
} | ||
|
||
public void main() { | ||
Shape s = new Circle(); | ||
switch (s) { | ||
case Cricle(int r) -> System.out.println(r); | ||
case Shape s -> System.out.println(c); | ||
case Both(Circle c, Rect(int w, int _)) -> System.out.println("something"); | ||
case Square -> { | ||
int l = ((Square) s).length; | ||
System.out.println(STR."Square with length \{Math.abs(l)}"); | ||
} | ||
} | ||
|
||
|
||
if (s instanceof Circle(int r)) { | ||
|
||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
core/src/test/resources/de/jplag/samples/NewJavaFeatures/B/Java21.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
public class Java21 { | ||
private static final record Circle(int radius) { | ||
} | ||
|
||
private static final record Rect(int width, int height) { | ||
} | ||
|
||
private static final record Both(Circle circle, Rect rect) { | ||
} | ||
|
||
private static final record Square(int length) { | ||
} | ||
|
||
public void main() { | ||
Shape s = new Circle(); | ||
switch (s) { | ||
case Cricle(int r) -> System.out.println(r); | ||
case Shape s -> System.out.println(c); | ||
case Both(Circle c, Rect(int _, int w)) -> System.out.println("something"); | ||
case Square -> { | ||
int l = ((Square) s).length; | ||
System.out.println(STR."Square with length \{Math.abs(l)}"); | ||
} | ||
} | ||
|
||
|
||
if (s instanceof Circle(int r)) { | ||
|
||
} | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
core/src/test/resources/de/jplag/samples/NewJavaFeatures/blacklist.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
Java17Preview.java | ||
30 changes: 30 additions & 0 deletions
30
languages/java/src/main/java/de/jplag/java/FixedSourcePositions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package de.jplag.java; | ||
|
||
import com.sun.source.tree.CompilationUnitTree; | ||
import com.sun.source.tree.Tree; | ||
import com.sun.source.util.SourcePositions; | ||
|
||
/** | ||
* Fixes the source positions, so that the end position is always at least the same as the start position. | ||
*/ | ||
public class FixedSourcePositions implements SourcePositions { | ||
private final SourcePositions base; | ||
|
||
/** | ||
* New instance | ||
* @param base The source positions to use as the base | ||
*/ | ||
public FixedSourcePositions(SourcePositions base) { | ||
this.base = base; | ||
} | ||
|
||
@Override | ||
public long getStartPosition(CompilationUnitTree compilationUnitTree, Tree tree) { | ||
return this.base.getStartPosition(compilationUnitTree, tree); | ||
} | ||
|
||
@Override | ||
public long getEndPosition(CompilationUnitTree compilationUnitTree, Tree tree) { | ||
return Math.max(this.getStartPosition(compilationUnitTree, tree), this.base.getEndPosition(compilationUnitTree, tree)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
languages/java/src/test/resources/de/jplag/java/AnonymousVariables.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
public class AnonymousVariables { | ||
public void test(Object o) { | ||
String _ = ""; | ||
|
||
if (o instanceof String _) { | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
languages/java/src/test/resources/de/jplag/java/PatternMatching.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
public class PatternMatchingManual { | ||
private static final record Test(int x) { | ||
} | ||
|
||
public void test() { | ||
Object a = new Test(1); | ||
if (a instanceof Test testA) { | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
languages/java/src/test/resources/de/jplag/java/PatternMatchingManual.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
public class PatternMatchingManual { | ||
private static final record Test(int x) { | ||
} | ||
|
||
public void test() { | ||
Object a = new Test(1); | ||
if (a instanceof Test) { | ||
Test testA = (Test) a; | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
languages/java/src/test/resources/de/jplag/java/StringConcat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
public class StringConcat { | ||
void test() { | ||
int param1 = 1; | ||
String param2 = "test"; | ||
|
||
String result = "prefix " + param1 + " infix " + param2.length() + "suffix"; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
languages/java/src/test/resources/de/jplag/java/StringTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
public class StringTemplate { | ||
void test() { | ||
int param1 = 1; | ||
String param2 = "test"; | ||
|
||
String result = STR."prefix \{param1} infix + \{param2.length()} suffix"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters