Skip to content

Commit 20b2d41

Browse files
committed
Fix compile errors for records with custom constructors, update JDT
1 parent 7f556af commit 20b2d41

10 files changed

Lines changed: 118 additions & 9 deletions

File tree

.github/workflows/full-check.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ jobs:
3333
- name: Checkout GWT tools into a sibling directory
3434
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 #v7.0.0
3535
with:
36-
repository: 'gwtproject/tools'
36+
repository: 'zbynek/tools'
3737
path: 'tools'
38+
ref: 'jdt'
3839
- name: Set up JDK ${{ matrix.java-version }}
3940
# GWT requires Java 17+ to build
4041
uses: actions/setup-java@1bcf9fb12cf4aa7d266a90ae39939e61372fe520 #v5.4.0

.github/workflows/quick-check.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ jobs:
2020
- name: Checkout GWT tools into a sibling directory
2121
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 #v7.0.0
2222
with:
23-
repository: 'gwtproject/tools'
23+
repository: 'zbynek/tools'
2424
path: 'tools'
25+
ref: 'jdt'
2526
- name: Set up JDK ${{ matrix.java-version }}
2627
# GWT presently requires Java 17+ to build
2728
uses: actions/setup-java@1bcf9fb12cf4aa7d266a90ae39939e61372fe520 #v5.4.0

dev/build.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
<include name="apache/tapestry-util-text-4.0.2.jar"/>
6464
<include name="apache/ant-zipscanner/ant-zipscanner-1.6.5-1-rebased.jar"/>
6565
<include name="colt/colt-1.2.jar"/>
66-
<include name="eclipse/3.33.0/*.jar"/>
66+
<include name="eclipse/3.37.0/*.jar"/>
6767
<include name="objectweb/asm-9.10.1/asm-9.10.1.jar"/>
6868
<include name="objectweb/asm-9.10.1/asm-commons-9.10.1.jar"/>
6969
<include name="objectweb/asm-9.10.1/asm-util-9.10.1.jar"/>
@@ -125,7 +125,7 @@
125125
<zipfileset src="${gwt.tools.lib}/apache/tapestry-util-text-4.0.2.jar"/>
126126
<zipfileset src="${gwt.tools.lib}/apache/ant-zipscanner/ant-zipscanner-1.6.5-1-rebased.jar"/>
127127
<zipfileset src="${gwt.tools.lib}/colt/colt-1.2.jar"/>
128-
<zipgroupfileset dir="${gwt.tools.lib}/eclipse/3.33.0">
128+
<zipgroupfileset dir="${gwt.tools.lib}/eclipse/3.37.0">
129129
<include name="**/*.jar"/>
130130
</zipgroupfileset>
131131
<zipfileset src="${gwt.tools.lib}/guava/guava-33.0/guava-33.0.0-jre-rebased.jar"/>
@@ -222,7 +222,7 @@
222222
<pathelement location="${gwt.tools.lib}/objectweb/asm-9.10.1/asm-util-9.10.1.jar"/>
223223
<pathelement
224224
location="${gwt.tools.lib}/apache/commons/commons-collections-3.2.2.jar"/>
225-
<fileset dir="${gwt.tools.lib}/eclipse/3.33.0">
225+
<fileset dir="${gwt.tools.lib}/eclipse/3.37.0">
226226
<include name="**/*.jar"/>
227227
</fileset>
228228
<pathelement

dev/core/src/com/google/gwt/dev/javac/testing/impl/JavaResourceBase.java

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,54 @@ public class JavaResourceBase {
248248
"package java.util;",
249249
"public interface Map<K,V> { }");
250250

251+
public static final MockJavaResource METHOD_HANDLE =
252+
createMockJavaResource("java.lang.invoke.MethodHandle",
253+
"""
254+
package java.lang.invoke;
255+
public abstract class MethodHandle { }
256+
""");
257+
258+
public static final MockJavaResource METHOD_HANDLES =
259+
createMockJavaResource("java.lang.invoke.MethodHandles",
260+
"""
261+
package java.lang.invoke;
262+
public class MethodHandles {
263+
public static final class Lookup {
264+
public MethodHandle findVirtual(Class<?> refc, String name,
265+
MethodType type) {
266+
return null;
267+
}
268+
269+
public MethodHandle findStatic(Class<?> refc, String name,
270+
MethodType type) {
271+
return null;
272+
}
273+
}
274+
275+
public static Lookup lookup() {
276+
return null;
277+
}
278+
}
279+
""");
280+
281+
public static final MockJavaResource METHOD_TYPE =
282+
createMockJavaResource("java.lang.invoke.MethodType",
283+
"""
284+
package java.lang.invoke;
285+
public final class MethodType {
286+
public static MethodType methodType(Class<?> rtype, Class<?> ptype0,
287+
Class<?>... ptypes) {
288+
return null;
289+
}
290+
public static MethodType methodType(Class<?> rtype) {
291+
return null;
292+
}
293+
public static MethodType genericMethodType(int objectArgCount) {
294+
return null;
295+
}
296+
}
297+
""");
298+
251299
public static final MockJavaResource NO_CLASS_DEF_FOUND_ERROR =
252300
createMockJavaResource("java.lang.NoClassDefFoundError",
253301
"package java.lang;",
@@ -364,6 +412,13 @@ public class JavaResourceBase {
364412
"public final class StringBuilder {",
365413
"}");
366414

415+
public static final MockJavaResource STRING_CONCAT_FACTORY =
416+
createMockJavaResource("java.lang.invoke.StringConcatFactory",
417+
"""
418+
package java.lang.invoke;
419+
public final class StringConcatFactory {}
420+
""");
421+
367422
public static final MockJavaResource SUPPRESS_WARNINGS =
368423
createMockJavaResource("java.lang.SuppressWarnings",
369424
"package java.lang;",
@@ -467,7 +522,8 @@ public static MockJavaResource[] getStandardResources() {
467522
AUTOCLOSEABLE, ANNOTATION, ARRAY_LIST, BYTE, BOOLEAN, CHARACTER, CHAR_SEQUENCE, CLASS,
468523
CLASS_NOT_FOUND_EXCEPTION, CLONEABLE, COLLECTION, COMPARABLE, DOUBLE, ENUM, EXCEPTION,
469524
ERROR, FUNCTIONALINTERFACE, FLOAT, INTEGER, IS_SERIALIZABLE, JAVASCRIPTEXCEPTION,
470-
JAVASCRIPTOBJECT, LIST, LONG, MAP, NO_CLASS_DEF_FOUND_ERROR, NUMBER, OBJECT, OBJECTMETHODS,
525+
JAVASCRIPTOBJECT, LIST, LONG, MAP, METHOD_HANDLES, NO_CLASS_DEF_FOUND_ERROR,
526+
NUMBER, OBJECT, OBJECTMETHODS, METHOD_HANDLE, METHOD_TYPE, STRING_CONCAT_FACTORY,
471527
OBJECTS, RECORD, RUNTIME_EXCEPTION, SERIALIZABLE, SHORT, STRING, STRING_BUILDER,
472528
SUPPRESS_WARNINGS, SYSTEM, THROWABLE, SPECIALIZE_METHOD, DO_NOT_AUTOBOX, JSTYPE,
473529
JSCONSTRUCTOR, JSPACKAGE, JSPROPERTY, JSMETHOD, JSIGNORE, JSFUNCTION, JSOVERLAY,

dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
import com.google.gwt.dev.js.ast.JsNode;
115115
import com.google.gwt.dev.js.ast.JsParameter;
116116
import com.google.gwt.dev.util.StringInterner;
117+
import com.google.gwt.dev.util.collect.HashSet;
117118
import com.google.gwt.dev.util.collect.Stack;
118119
import com.google.gwt.thirdparty.guava.common.base.Function;
119120
import com.google.gwt.thirdparty.guava.common.base.Joiner;
@@ -711,6 +712,9 @@ private TypeBinding getFirstNonObjectInIntersection(IntersectionTypeBinding18 re
711712

712713
@Override
713714
public void endVisit(ConstructorDeclaration x, ClassScope scope) {
715+
if (skippedConstructors.contains(x)) {
716+
return;
717+
}
714718
try {
715719
List<JStatement> statements = pop(x.statements);
716720
JStatement constructorCall = pop(x.constructorCall);
@@ -2596,6 +2600,9 @@ public boolean visit(Block x, BlockScope scope) {
25962600

25972601
@Override
25982602
public boolean visit(ConstructorDeclaration x, ClassScope scope) {
2603+
if (skippedConstructors.contains(x)) {
2604+
return false;
2605+
}
25992606
try {
26002607
JConstructor method = (JConstructor) typeMap.get(x.binding);
26012608
assert !method.isExternal();
@@ -4131,6 +4138,7 @@ private boolean isBinaryBinding(ReferenceBinding binding) {
41314138
private boolean generateJsInteropExports;
41324139

41334140
private WhitelistRegexFilter jsInteropExportFilter;
4141+
private final Set<AbstractMethodDeclaration> skippedConstructors = new HashSet<>();
41344142

41354143
/**
41364144
* Externalized class and method form for Exceptions.safeClose() to provide support
@@ -4331,6 +4339,10 @@ private void createMembers(TypeDeclaration x) {
43314339

43324340
if (x.methods != null) {
43334341
for (AbstractMethodDeclaration method : x.methods) {
4342+
if (method.binding == null && x.binding.isRecord() && method.isConstructor()) {
4343+
skippedConstructors.add(method);
4344+
continue;
4345+
}
43344346
createMethod(method);
43354347
}
43364348
}
@@ -4400,6 +4412,9 @@ private void createMethod(AbstractMethodDeclaration x) {
44004412
if (x instanceof Clinit) {
44014413
return;
44024414
}
4415+
if (x.binding == null) {
4416+
throw new IllegalArgumentException("Missing method binding for " + x);
4417+
}
44034418
SourceInfo info = makeSourceInfo(x);
44044419
MethodBinding b = x.binding;
44054420
ReferenceBinding declaringClass = (ReferenceBinding) b.declaringClass.erasure();
@@ -4630,7 +4645,7 @@ private void createTypes(TypeDeclaration x) {
46304645
}
46314646
} catch (Throwable e) {
46324647
InternalCompilerException ice = translateException(null, e);
4633-
StringBuffer sb = new StringBuffer();
4648+
StringBuilder sb = new StringBuilder();
46344649
x.printHeader(0, sb);
46354650
ice.addNode(x.getClass().getName(), sb.toString(), info);
46364651
throw ice;
@@ -4679,7 +4694,7 @@ private void resolveTypeRefs(TypeDeclaration x) {
46794694
private InternalCompilerException getInternalCompilerException(TypeDeclaration x, Throwable e) {
46804695
JDeclaredType type = (JDeclaredType) typeMap.get(x.binding);
46814696
InternalCompilerException ice = translateException(null, e);
4682-
StringBuffer sb = new StringBuffer();
4697+
StringBuilder sb = new StringBuilder();
46834698
x.printHeader(0, sb);
46844699
ice.addNode(x.getClass().getName(), sb.toString(), type.getSourceInfo());
46854700
return ice;

dev/core/test/com/google/gwt/dev/jjs/impl/SampleBytecodeOnlyMarkerAnnotation.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
*/
1414
package com.google.gwt.dev.jjs.impl;
1515

16+
import java.lang.annotation.ElementType;
17+
import java.lang.annotation.Target;
18+
1619
/**
1720
* Annotation with no bytecode for GWT, and no members.
1821
*/
22+
@Target({ElementType.METHOD, ElementType.TYPE_USE})
1923
public @interface SampleBytecodeOnlyMarkerAnnotation {
2024
}

dev/core/test/com/google/gwt/dev/jjs/impl/SampleBytecodeOnlyNormalAnnotation.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
*/
1414
package com.google.gwt.dev.jjs.impl;
1515

16+
import java.lang.annotation.ElementType;
17+
import java.lang.annotation.Target;
18+
1619
/**
1720
* Annotation with no bytecode for GWT, and multiple members.
1821
*/
22+
@Target({ElementType.METHOD, ElementType.TYPE_USE})
1923
public @interface SampleBytecodeOnlyNormalAnnotation {
2024
int a();
2125
int b();

dev/core/test/com/google/gwt/dev/jjs/impl/SampleBytecodeOnlySingleMemberAnnotation.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
*/
1414
package com.google.gwt.dev.jjs.impl;
1515

16+
import java.lang.annotation.ElementType;
17+
import java.lang.annotation.Target;
18+
1619
/**
1720
* Annotation with no bytecode for GWT, and a single member.
1821
*/
22+
@Target({ElementType.METHOD, ElementType.TYPE_USE})
1923
public @interface SampleBytecodeOnlySingleMemberAnnotation {
2024
String value();
2125
}

maven/poms/gwt/pom-template.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@
267267
<dependency>
268268
<groupId>org.eclipse.jdt</groupId>
269269
<artifactId>org.eclipse.jdt.core</artifactId>
270-
<version>3.33.0</version>
270+
<version>3.37.0</version>
271271
</dependency>
272272
</dependencies>
273273
</dependencyManagement>

user/test-super/com/google/gwt/dev/jjs/super/com/google/gwt/dev/jjs/test/Java17Test.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.util.Arrays;
2222
import java.util.List;
23+
import java.util.Objects;
2324
import jsinterop.annotations.JsMethod;
2425
import jsinterop.annotations.JsProperty;
2526
import jsinterop.annotations.JsType;
@@ -140,6 +141,18 @@ record RecordWithStaticField() {
140141
public static String foo = "bar";
141142
}
142143

144+
record RecordWithDefaultConstructor(String foo) {
145+
public RecordWithDefaultConstructor {
146+
Objects.requireNonNull(foo);
147+
}
148+
}
149+
150+
record RecordWithExtraConstructor(String foo) {
151+
RecordWithExtraConstructor(int fooInt) {
152+
this(fooInt + "");
153+
}
154+
}
155+
143156
/**
144157
* Record type that takes a record as a component
145158
*/
@@ -207,6 +220,17 @@ public String toString() {
207220
assertFalse(new TopLevelRecord(null, 3).equals(new TopLevelRecord("abc", 3)));
208221
}
209222

223+
public void testRecordConstructors() {
224+
assertEquals("7", new RecordWithExtraConstructor(7).foo());
225+
assertEquals("7", new RecordWithDefaultConstructor("7").foo());
226+
try {
227+
new RecordWithDefaultConstructor(null).foo();
228+
fail("Should have thrown NPE");
229+
} catch (RuntimeException expected) {
230+
// expected
231+
}
232+
}
233+
210234
/**
211235
* Simple record with one property accessor, one default method accessor
212236
*/

0 commit comments

Comments
 (0)