Skip to content

Commit

Permalink
Merge branch 'gwtproject:main' into java-17-support-test
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed Feb 5, 2024
1 parent 36ca133 commit 7a0dc8f
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 17 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/full-check.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Run all tests and builds all aspects of GWT using Java 8, 11, and 17. Runs
# Run all tests and builds all aspects of GWT using Java 11, 17, and 21. Runs
# nightly (plus or minus timzeones) on the main branch, and will also run right
# away on a push to a release branch. Release zips are uploaded as part of the
# build, though maven snapshots are not yet deployed.
Expand All @@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java-version: [ '11', '17' ]
java-version: [ '11', '17', '21' ]
steps:
- name: Checkout GWT itself into one directory
uses: actions/checkout@v4
Expand All @@ -29,8 +29,7 @@ jobs:
- name: Checkout GWT tools into a sibling directory
uses: actions/checkout@v4
with:
repository: 'vegegoku/tools'
ref: 'java-17-support'
repository: 'gwtproject/tools'
path: 'tools'
- name: Set up JDK ${{ matrix.java-version }}
# GWT requires Java 11+ to build
Expand All @@ -52,7 +51,7 @@ jobs:
GWT_VERSION=HEAD-SNAPSHOT
# Run the ant tasks, disabling watchFileChanges to work around a github actions limitation
ant clean test dist doc \
-Dtest.jvmargs='-ea -noverify -Dgwt.watchFileChanges=false' \
-Dtest.jvmargs='-ea -Dgwt.watchFileChanges=false' \
-Dtest.web.htmlunit.disable=true \
-Dtest.nometa.htmlunit.disable=true \
-Dtest.emma.htmlunit.disable=true
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/quick-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java-version: ['11', '17']
java-version: ['11', '17', '21']
steps:
- name: Checkout GWT itself into one directory
uses: actions/checkout@v4
Expand All @@ -19,8 +19,7 @@ jobs:
- name: Checkout GWT tools into a sibling directory
uses: actions/checkout@v4
with:
repository: 'vegegoku/tools'
ref: 'java-17-support'
repository: 'gwtproject/tools'
path: 'tools'
- name: Set up JDK ${{ matrix.java-version }}
# GWT presently requires Java 11+ to build
Expand Down
21 changes: 18 additions & 3 deletions dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
import org.eclipse.jdt.internal.compiler.ast.StringLiteral;
import org.eclipse.jdt.internal.compiler.ast.StringLiteralConcatenation;
import org.eclipse.jdt.internal.compiler.ast.SuperReference;
import org.eclipse.jdt.internal.compiler.ast.SwitchExpression;
import org.eclipse.jdt.internal.compiler.ast.SwitchStatement;
import org.eclipse.jdt.internal.compiler.ast.SynchronizedStatement;
import org.eclipse.jdt.internal.compiler.ast.ThisReference;
Expand Down Expand Up @@ -538,10 +539,10 @@ public void endVisit(BreakStatement x, BlockScope scope) {
@Override
public void endVisit(CaseStatement x, BlockScope scope) {
if (x.isExpr) {
InternalCompilerException excption =
InternalCompilerException exception =
new InternalCompilerException("Switch expressions not yet supported");
excption.addNode(new JCaseStatement(makeSourceInfo(x), null));
throw excption;
exception.addNode(new JCaseStatement(makeSourceInfo(x), null));
throw exception;
}
try {
SourceInfo info = makeSourceInfo(x);
Expand Down Expand Up @@ -2546,6 +2547,14 @@ public boolean visit(Initializer x, MethodScope scope) {
}
}

@Override
public boolean visit(SwitchExpression x, BlockScope blockScope) {
InternalCompilerException exception =
new InternalCompilerException("Switch expressions not yet supported");
exception.addNode(new JCaseStatement(makeSourceInfo(x), null));
throw exception;
}

@Override
public boolean visit(LocalDeclaration x, BlockScope scope) {
try {
Expand Down Expand Up @@ -2764,6 +2773,12 @@ protected void pushBinaryOp(BinaryExpression x, JBinaryOperator op) {
}

protected boolean visit(TypeDeclaration x) {
if (x.isRecord()) {
InternalCompilerException exception =
new InternalCompilerException("Records not yet supported");
exception.addNode(new JClassType(makeSourceInfo(x), intern(x.name), false, false));
throw exception;
}
JDeclaredType type = (JDeclaredType) typeMap.get(x.binding);
assert !type.isExternal();
classStack.push(curClass);
Expand Down
35 changes: 34 additions & 1 deletion dev/core/test/com/google/gwt/dev/jjs/impl/Java17AstTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Google Inc.
* Copyright 2024 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -100,6 +100,20 @@ public void testSealedClassesNotPermitted() {
}
}

public void testRecordsNotSupported() {
try {
addSnippetClassDecl("public record Point(int x, int y) {}");
compileSnippet("void", "Point rectangle = new Point(0, 0);");
fail("Compile should have failed but succeeded.");
} catch (Exception e) {
if (!(e.getCause() instanceof UnableToCompleteException)
&& !(e instanceof UnableToCompleteException)) {
e.printStackTrace();
fail();
}
}
}

public void testSwitchExpressionsNotSupported() {
try {
compileSnippet("void", "var month = Months.JUNE;" +
Expand All @@ -120,6 +134,25 @@ public void testSwitchExpressionsNotSupported() {
}
}

public void testSwitchExpressionsInitializerShouldFail() {
try {
compileSnippet("void", " int i = switch(1) {\n" +
" case 1:\n" +
" yield 2;\n" +
" default:\n" +
" yield 7;\n" +
" };");
fail("Compile should have failed but succeeded, switch expressions as initializer should fail.");
} catch (Exception e) {
if (!(e.getCause() instanceof InternalCompilerException)
&& !(e instanceof InternalCompilerException)) {
e.printStackTrace();
fail();
}
assertEquals("Switch expressions not yet supported", e.getMessage());
}
}

@Override
protected void optimizeJava() {
}
Expand Down
6 changes: 1 addition & 5 deletions user/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
<property name="gwt.root" location=".."/>
<property name="project.tail" value="user"/>
<property name="test.args" value="-ea -sourceLevel auto"/>
<!--
Adding "-noverify" is a workaround for https://bugs.openjdk.org/browse/JDK-8323657
so that tests can be compiled under Java9+.
-->
<property name="test.jvmargs" value="-ea -noverify"/>
<property name="test.jvmargs" value="-ea"/>

<!-- support old variables names -->
<condition property="gwt.hosts.web.selenium" value="${gwt.selenium.hosts}">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2019 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.gwt.dev.jjs.test;

import com.google.gwt.core.client.GwtScriptOnly;
import com.google.gwt.junit.client.GWTTestCase;

import java.util.Arrays;
import java.util.List;

/**
* Tests Java 17 features. It is super sourced so that gwt can be compiles under Java 11.
*
* IMPORTANT: For each test here there must exist the corresponding method in the non super sourced
* version.
*
* Eventually this test will graduate and not be super sourced.
*/
@GwtScriptOnly
public class Java17Test extends GWTTestCase {

public interface TextBlock {
String text = """
line 1
line 2
line 3
""";
}

public sealed class Shape permits Square, Circle {

}

public final class Square extends Shape {

}

public final class Circle extends Shape {

}

@Override
public String getModuleName() {
return "com.google.gwt.dev.jjs.test.Java17Test";
}

public void testTextBlocks() {
List<String> lines = Arrays.asList(TextBlock.text.split("\n"));
assertEquals(3, lines.size());
assertEquals("line 1", lines.get(0));
assertEquals("line 2", lines.get(1));
assertEquals("line 3", lines.get(2));
}

public void testSealedClassesPermitted() {
Shape square = new Square();
Shape circle = new Circle();

checkIfCompiled(square, circle);
}

private void checkIfCompiled(Shape square, Shape circle) {
assertTrue(square instanceof Square);
assertTrue(circle instanceof Circle);
}
}
2 changes: 2 additions & 0 deletions user/test/com/google/gwt/dev/jjs/CompilerSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.gwt.dev.jjs.test.InnerOuterSuperTest;
import com.google.gwt.dev.jjs.test.Java10Test;
import com.google.gwt.dev.jjs.test.Java11Test;
import com.google.gwt.dev.jjs.test.Java17Test;
import com.google.gwt.dev.jjs.test.Java7Test;
import com.google.gwt.dev.jjs.test.Java8Test;
import com.google.gwt.dev.jjs.test.Java9Test;
Expand Down Expand Up @@ -77,6 +78,7 @@ public static Test suite() {
suite.addTestSuite(Java9Test.class);
suite.addTestSuite(Java10Test.class);
suite.addTestSuite(Java11Test.class);
suite.addTestSuite(Java17Test.class);
suite.addTestSuite(JavaAccessFromJavaScriptTest.class);
suite.addTestSuite(JsniConstructorTest.class);
suite.addTestSuite(JsniDispatchTest.class);
Expand Down
19 changes: 19 additions & 0 deletions user/test/com/google/gwt/dev/jjs/Java17Test.gwt.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!-- -->
<!-- Copyright 2019 Google Inc. -->
<!-- Licensed under the Apache License, Version 2.0 (the "License"); you -->
<!-- may not use this file except in compliance with the License. You may -->
<!-- may obtain a copy of the License at -->
<!-- -->
<!-- http://www.apache.org/licenses/LICENSE-2.0 -->
<!-- -->
<!-- Unless required by applicable law or agreed to in writing, software -->
<!-- distributed under the License is distributed on an "AS IS" BASIS, -->
<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -->
<!-- implied. License for the specific language governing permissions and -->
<!-- limitations under the License. -->

<!-- Contains tests for breaking out of the client source path -->
<module>
<inherits name="com.google.gwt.core.Core" />
<super-source path='super' />
</module>
56 changes: 56 additions & 0 deletions user/test/com/google/gwt/dev/jjs/test/Java17Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2019 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.gwt.dev.jjs.test;

import com.google.gwt.dev.util.arg.SourceLevel;
import com.google.gwt.junit.DoNotRunWith;
import com.google.gwt.junit.JUnitShell;
import com.google.gwt.junit.Platform;
import com.google.gwt.junit.client.GWTTestCase;

/**
* Dummy test case. Java17Test is super sourced so that GWT can be compiled by Java 8.
*
* NOTE: Make sure this class has the same test methods of its supersourced variant.
*/
@DoNotRunWith(Platform.Devel)
public class Java17Test extends GWTTestCase {

@Override
public String getModuleName() {
return "com.google.gwt.dev.jjs.Java17Test";
}

@Override
public void runTest() throws Throwable {
// Only run these tests if -sourceLevel 17 (or greater) is enabled.
if (isGwtSourceLevel17()) {
super.runTest();
}
}

public void testTextBlocks() {
assertFalse(isGwtSourceLevel17());
}

public void testSealedClassesPermitted() {
assertFalse(isGwtSourceLevel17());
}

private boolean isGwtSourceLevel17() {
return JUnitShell.getCompilerOptions().getSourceLevel().compareTo(SourceLevel.JAVA17) >= 0;
}
}

0 comments on commit 7a0dc8f

Please sign in to comment.