Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 16
java-version: 25
- name: Build with Gradle
run: ./gradlew build
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 14
java-version: 25
- name: Deploy with Gradle
env:
GRADLE_PUBLISH_REPO_URL: ${{ secrets.GRADLE_PUBLISH_REPO_URL }}
GRADLE_PUBLISH_MAVEN_USER: ${{ secrets.GRADLE_PUBLISH_MAVEN_USER }}
GRADLE_PUBLISH_MAVEN_PASSWORD: ${{ secrets.GRADLE_PUBLISH_MAVEN_PASSWORD }}
run: ./gradlew --no-daemon -Pversion=$(git tag --points-at HEAD) publish
run: ./gradlew --no-daemon -Pversion=$(git tag --points-at HEAD) publish
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ out/

.project
.classpath
.settings/
.settings/
/bin/
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Jabel - use modern Java 9-14 syntax when targeting Java 8
# Jabel - use modern Java 9-25 syntax when targeting Java 8

> Because life is too short to wait for your users to upgrade their Java!

Expand Down Expand Up @@ -74,8 +74,8 @@ Jabel has to be enabled as a Javac plugin in your maven-compiler-plugin:
<configuration>
<!-- Make sure we're not using Java 9+ APIs -->
<release>8</release>
<source>14</source>
<target>14</target>
<source>25</source>
<target>25</target>
<!-- The following setting can be avoided on Java 14 and higher -->
<compilerArgs>
<arg>-Xplugin:jabel</arg>
Expand Down
10 changes: 5 additions & 5 deletions example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ plugins {
id "java"
}

configure([tasks.compileJava]) {
sourceCompatibility = 16
compileJava {
sourceCompatibility = 25
targetCompatibility = 8
options.release = 8

javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(21)
languageVersion = JavaLanguageVersion.of(25)
}
}

Expand All @@ -22,8 +23,7 @@ test {
}

dependencies {
annotationProcessor project(":jabel-javac-plugin")
compileOnly project(":jabel-javac-plugin")
annotationProcessor project(":jabel-javac-plugin")//.files("build/libs/jabel-javac-plugin.jar")

testImplementation 'junit:junit:4.13.2'
}
44 changes: 44 additions & 0 deletions example/src/main/java/com/example/Java10FeaturesExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Examples made by Claude Opus 4.5

package com.example;

import java.util.ArrayList;
import java.util.HashMap;

/**
* Examples of Java 10 features desugared by the compiler: <br>
*
* <strong>LOCAL_VARIABLE_TYPE_INFERENCE (var)</strong>
* <pre>
* // Source (Java 10+):
* var str = "hello";
* var list = new ArrayList&lt;String&gt;();
* for (var i = 0; i &lt; 10; i++) { }
* for (var item : list) { }
*
* // Decompiled (Java 8):
* String str = "hello";
* ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;();
* for (int i = 0; i &lt; 10; i++) { }
* for (String item : list) { }
* </pre>
*/
public class Java10FeaturesExample {

void varExamples() {
var str = "hello";
var num = 42;
var list = new ArrayList<String>();
var map = new HashMap<String, Integer>();

list.add("item");
map.put("key", 1);

for (var i = 0; i < 3; i++) {
list.add("item" + i);
}
for (var item : list) {
System.out.println(item);
}
}
}
29 changes: 29 additions & 0 deletions example/src/main/java/com/example/Java11FeaturesExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Examples made by Claude Opus 4.5

package com.example;

import java.util.function.BiFunction;

/**
* Examples of Java 11 features desugared by the compiler: <br>
*
* <strong>VAR_SYNTAX_IMPLICIT_LAMBDAS</strong>
* <pre>
* // Source (Java 11+):
* BiFunction&lt;String, String, String&gt; f = (var a, var b) -&gt; a + b;
* // Allows annotations:
* Consumer&lt;String&gt; c = (@NonNull var s) -&gt; System.out.println(s);
*
* // Decompiled (Java 8):
* BiFunction&lt;String, String, String&gt; f = (a, b) -&gt; a + b;
* // or with explicit types:
* BiFunction&lt;String, String, String&gt; f = (String a, String b) -&gt; a + b;
* </pre>
*/
public class Java11FeaturesExample {

BiFunction<String, String, String> concat = (var a, var b) -> a + b;

BiFunction<Integer, Integer, Integer> add =
(var x, var y) -> x + y;
}
133 changes: 133 additions & 0 deletions example/src/main/java/com/example/Java14FeaturesExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// Examples made by Claude Opus 4.5

package com.example;

/**
* Examples of Java 14 features desugared by the compiler: <br>
*
* <strong>SWITCH_MULTIPLE_CASE_LABELS</strong>
* <pre>
* // Source (Java 14+):
* case SAT, SUN -&gt; "weekend";
*
* // Decompiled (Java 8):
* case SAT:
* case SUN:
* return "weekend";
* </pre>
* <p>
* <strong>SWITCH_RULE (arrow syntax)</strong>
* <pre>
* // Source (Java 14+):
* case MON -&gt; "monday";
*
* // Decompiled (Java 8):
* case MON:
* return "monday";
* </pre>
* <p>
* <strong>SWITCH_EXPRESSION</strong>
* <pre>
* // Source (Java 14+):
* String result = switch (day) {
* case MON -&gt; "monday";
* default -&gt; { yield "other"; }
* };
*
* // Decompiled (Java 8):
* String result;
* switch (day) {
* case MON:
* result = "monday";
* break;
* default:
* result = "other";
* }
* </pre>
*/
public class Java14FeaturesExample {

enum Day { MON, TUE, WED, THU, FRI, SAT, SUN }

class Builder{
public int n;
public Builder build(Object o){
n++;
return this;
}
}

String switchMultipleLabels(Day day) {
return switch (day) {
case SAT, SUN -> "weekend";
case MON, TUE, WED, THU, FRI -> "weekday";
};
}

String switchRule(Day day) {
return (switch (day) {
case MON -> "monday";
case TUE -> "tuesday";
default -> "other";
}).toLowerCase();
}

int switchExpressionWithYield(Day day) {
return switch (day) {
case MON -> 1;
case TUE -> 2;
default -> {
int result = day.ordinal();
yield result;
}
};
}

void statementSwitchWithArrow(Day day) {
switch (day) {
case SAT -> System.out.println("Saturday");
case SUN -> System.out.println("Sunday");
}
System.out.println("Weekday");
}

void noDefaultInjectedCase(int a) {
switch (a) {
case 1 -> {
System.out.println("Wrong value!!");
return;
}
}
System.out.println("Passed!");
}

int[] asArrayElements(int a, int b) {
return new int[]{
switch (a) { case 1 -> 10; default -> 0; },
switch (b) { case 2 -> 20; default -> 0; }
};
}

String chained(String str) {
return switch (
switch (str) {
case "test": {
str = "pok";
yield "A";
}
default: yield "B";
}
) {
case "A" -> str.isEmpty() ? "got-A" : "err";
default -> "got-B";
};
}

int twiceOf(int n) {
return new Builder().build(1).build(switch (n) {
case 1 -> 10;
case 2 -> 20;
default -> n * n;
}).build(4).n;
}
}
48 changes: 48 additions & 0 deletions example/src/main/java/com/example/Java15FeaturesExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Examples made by Claude Opus 4.5

package com.example;

/**
* Examples of Java 15 features desugared by the compiler: <br>
*
* <strong>TEXT_BLOCKS</strong>
* <pre>
* // Source (Java 15+):
* String s = """
* Hello
* World
* """;
* String cont = """
* Single \
* line""";
*
* // Decompiled (Java 8):
* String s = "Hello\nWorld\n";
* String cont = "Single line";
* </pre>
*/
public class Java15FeaturesExample {

String basic = """
Hello
World
""";

String json = """
{"name": "test", "value": 42}
""";

String withTrailingSpace = """
Line with space \s
Next line
""";

String lineContinuation = """
Single \
line""";

String formatted = String.format("""
Name: %s
Age: %d
""", "Alice", 25);
}
Loading