Skip to content

Commit f40a76e

Browse files
committed
Use pattern variables.
1 parent 4b44a45 commit f40a76e

File tree

2 files changed

+18
-36
lines changed

2 files changed

+18
-36
lines changed

wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/Linker.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,10 +1048,9 @@ public int hashCode() {
10481048

10491049
@Override
10501050
public boolean equals(Object object) {
1051-
if (!(object instanceof ExportGlobalSym)) {
1051+
if (!(object instanceof ExportGlobalSym that)) {
10521052
return false;
10531053
}
1054-
final ExportGlobalSym that = (ExportGlobalSym) object;
10551054
return this.moduleName.equals(that.moduleName) && this.globalName.equals(that.globalName);
10561055
}
10571056
}
@@ -1076,10 +1075,9 @@ public int hashCode() {
10761075

10771076
@Override
10781077
public boolean equals(Object object) {
1079-
if (!(object instanceof InitializeGlobalSym)) {
1078+
if (!(object instanceof InitializeGlobalSym that)) {
10801079
return false;
10811080
}
1082-
final InitializeGlobalSym that = (InitializeGlobalSym) object;
10831081
return this.globalIndex == that.globalIndex && this.moduleName.equals(that.moduleName);
10841082
}
10851083
}
@@ -1139,10 +1137,9 @@ public int hashCode() {
11391137

11401138
@Override
11411139
public boolean equals(Object object) {
1142-
if (!(object instanceof ExportFunctionSym)) {
1140+
if (!(object instanceof ExportFunctionSym that)) {
11431141
return false;
11441142
}
1145-
final ExportFunctionSym that = (ExportFunctionSym) object;
11461143
return this.moduleName.equals(that.moduleName) && this.functionName.equals(that.functionName);
11471144
}
11481145
}
@@ -1170,10 +1167,9 @@ public int hashCode() {
11701167

11711168
@Override
11721169
public boolean equals(Object object) {
1173-
if (!(object instanceof ImportMemorySym)) {
1170+
if (!(object instanceof ImportMemorySym that)) {
11741171
return false;
11751172
}
1176-
final ImportMemorySym that = (ImportMemorySym) object;
11771173
return this.moduleName.equals(that.moduleName) && this.importDescriptor.equals(that.importDescriptor) && this.memoryIndex == that.memoryIndex;
11781174
}
11791175
}
@@ -1198,10 +1194,9 @@ public int hashCode() {
11981194

11991195
@Override
12001196
public boolean equals(Object object) {
1201-
if (!(object instanceof ExportMemorySym)) {
1197+
if (!(object instanceof ExportMemorySym that)) {
12021198
return false;
12031199
}
1204-
final ExportMemorySym that = (ExportMemorySym) object;
12051200
return this.moduleName.equals(that.moduleName) && this.memoryName.equals(that.memoryName);
12061201
}
12071202
}
@@ -1226,10 +1221,9 @@ public int hashCode() {
12261221

12271222
@Override
12281223
public boolean equals(Object object) {
1229-
if (!(object instanceof DataSym)) {
1224+
if (!(object instanceof DataSym that)) {
12301225
return false;
12311226
}
1232-
final DataSym that = (DataSym) object;
12331227
return this.dataSegmentId == that.dataSegmentId && this.moduleName.equals(that.moduleName);
12341228
}
12351229
}
@@ -1254,10 +1248,9 @@ public int hashCode() {
12541248

12551249
@Override
12561250
public boolean equals(Object object) {
1257-
if (!(object instanceof ImportTableSym)) {
1251+
if (!(object instanceof ImportTableSym that)) {
12581252
return false;
12591253
}
1260-
final ImportTableSym that = (ImportTableSym) object;
12611254
return this.moduleName.equals(that.moduleName) && this.importDescriptor.equals(that.importDescriptor);
12621255
}
12631256
}
@@ -1282,10 +1275,9 @@ public int hashCode() {
12821275

12831276
@Override
12841277
public boolean equals(Object object) {
1285-
if (!(object instanceof ExportTableSym)) {
1278+
if (!(object instanceof ExportTableSym that)) {
12861279
return false;
12871280
}
1288-
final ExportTableSym that = (ExportTableSym) object;
12891281
return this.moduleName.equals(that.moduleName) && this.tableName.equals(that.tableName);
12901282
}
12911283
}
@@ -1310,10 +1302,9 @@ public int hashCode() {
13101302

13111303
@Override
13121304
public boolean equals(Object object) {
1313-
if (!(object instanceof ElemSym)) {
1305+
if (!(object instanceof ElemSym that)) {
13141306
return false;
13151307
}
1316-
final ElemSym that = (ElemSym) object;
13171308
return this.elemSegmentId == that.elemSegmentId && this.moduleName.equals(that.moduleName);
13181309
}
13191310
}

wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/api/WebAssembly.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -432,13 +432,12 @@ public WasmTable tableAlloc(int initial, int maximum, TableKind elemKind, Object
432432

433433
private static Object tableGrow(Object[] args) {
434434
checkArgumentCount(args, 2);
435-
if (!(args[0] instanceof WasmTable)) {
435+
if (!(args[0] instanceof WasmTable table)) {
436436
throw new WasmJsApiException(WasmJsApiException.Kind.TypeError, "First argument must be wasm table");
437437
}
438438
if (!(args[1] instanceof Integer)) {
439439
throw new WasmJsApiException(WasmJsApiException.Kind.TypeError, "Second argument must be integer");
440440
}
441-
WasmTable table = (WasmTable) args[0];
442441
int delta = (Integer) args[1];
443442
if (args.length > 2) {
444443
return tableGrow(table, delta, args[2]);
@@ -456,13 +455,12 @@ public static int tableGrow(WasmTable table, int delta, Object ref) {
456455

457456
private static Object tableRead(Object[] args) {
458457
checkArgumentCount(args, 2);
459-
if (!(args[0] instanceof WasmTable)) {
458+
if (!(args[0] instanceof WasmTable table)) {
460459
throw new WasmJsApiException(WasmJsApiException.Kind.TypeError, "First argument must be wasm table");
461460
}
462461
if (!(args[1] instanceof Integer)) {
463462
throw new WasmJsApiException(WasmJsApiException.Kind.TypeError, "Second argument must be integer");
464463
}
465-
WasmTable table = (WasmTable) args[0];
466464
int index = (Integer) args[1];
467465
return tableRead(table, index);
468466
}
@@ -477,13 +475,12 @@ public static Object tableRead(WasmTable table, int index) {
477475

478476
private Object tableWrite(Object[] args) {
479477
checkArgumentCount(args, 3);
480-
if (!(args[0] instanceof WasmTable)) {
478+
if (!(args[0] instanceof WasmTable table)) {
481479
throw new WasmJsApiException(WasmJsApiException.Kind.TypeError, "First argument must be wasm table");
482480
}
483481
if (!(args[1] instanceof Integer)) {
484482
throw new WasmJsApiException(WasmJsApiException.Kind.TypeError, "Second argument must be integer");
485483
}
486-
WasmTable table = (WasmTable) args[0];
487484
int index = (Integer) args[1];
488485
return tableWrite(table, index, args[2]);
489486
}
@@ -515,10 +512,9 @@ public Object tableWrite(WasmTable table, int index, Object element) {
515512

516513
private static Object tableSize(Object[] args) {
517514
checkArgumentCount(args, 1);
518-
if (!(args[0] instanceof WasmTable)) {
515+
if (!(args[0] instanceof WasmTable table)) {
519516
throw new WasmJsApiException(WasmJsApiException.Kind.TypeError, "First argument must be wasm table");
520517
}
521-
WasmTable table = (WasmTable) args[0];
522518
return tableSize(table);
523519
}
524520

@@ -613,13 +609,12 @@ public static WasmMemory memAlloc(int initial, int maximum, boolean shared) {
613609

614610
private static Object memGrow(Object[] args) {
615611
checkArgumentCount(args, 2);
616-
if (!(args[0] instanceof WasmMemory)) {
612+
if (!(args[0] instanceof WasmMemory memory)) {
617613
throw new WasmJsApiException(WasmJsApiException.Kind.TypeError, "First argument must be wasm memory");
618614
}
619615
if (!(args[1] instanceof Integer)) {
620616
throw new WasmJsApiException(WasmJsApiException.Kind.TypeError, "Second argument must be integer");
621617
}
622-
WasmMemory memory = (WasmMemory) args[0];
623618
int delta = (Integer) args[1];
624619
return memGrow(memory, delta);
625620
}
@@ -818,10 +813,9 @@ public WasmGlobal globalAlloc(ValueType valueType, boolean mutable, Object value
818813

819814
private static Object globalRead(Object[] args) {
820815
checkArgumentCount(args, 1);
821-
if (!(args[0] instanceof WasmGlobal)) {
816+
if (!(args[0] instanceof WasmGlobal global)) {
822817
throw new WasmJsApiException(WasmJsApiException.Kind.TypeError, "First argument must be wasm global");
823818
}
824-
WasmGlobal global = (WasmGlobal) args[0];
825819
return globalRead(global);
826820
}
827821

@@ -845,10 +839,9 @@ public static Object globalRead(WasmGlobal global) {
845839

846840
private Object globalWrite(Object[] args) {
847841
checkArgumentCount(args, 2);
848-
if (!(args[0] instanceof WasmGlobal)) {
842+
if (!(args[0] instanceof WasmGlobal global)) {
849843
throw new WasmJsApiException(WasmJsApiException.Kind.TypeError, "First argument must be wasm global");
850844
}
851-
WasmGlobal global = (WasmGlobal) args[0];
852845
return globalWrite(global, args[1]);
853846
}
854847

@@ -904,14 +897,12 @@ public Object globalWrite(WasmGlobal global, Object value) {
904897

905898
private static Object instanceExport(Object[] args) {
906899
checkArgumentCount(args, 2);
907-
if (!(args[0] instanceof WasmInstance)) {
900+
if (!(args[0] instanceof WasmInstance instance)) {
908901
throw new WasmJsApiException(WasmJsApiException.Kind.TypeError, "First argument must be wasm instance");
909902
}
910-
if (!(args[1] instanceof String)) {
903+
if (!(args[1] instanceof String name)) {
911904
throw new WasmJsApiException(WasmJsApiException.Kind.TypeError, "Second argument must be string");
912905
}
913-
WasmInstance instance = (WasmInstance) args[0];
914-
String name = (String) args[1];
915906
return instanceExport(instance, name);
916907
}
917908

0 commit comments

Comments
 (0)