Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,7 @@ private int getOrderIndex(Either<ImCompiletimeExpr, ImFunction> e) {
} else {
ImFunction f = e.getRight();
for (FunctionFlag flag : f.getFlags()) {
if (flag instanceof FunctionFlagCompiletime) {
FunctionFlagCompiletime cflag = (FunctionFlagCompiletime) flag;
if (flag instanceof FunctionFlagCompiletime cflag) {
return cflag.getOrderIndex();

}
Expand Down Expand Up @@ -323,14 +322,14 @@ private void executeCompiletimeExpr(ImCompiletimeExpr cte) {
newExpr = ImHelper.nullExpr();
} else {
@Nullable ImType exprType = null;
if(expr instanceof ImFunctionCall) {
exprType = ((ImFunctionCall) expr).getFunc().getReturnType();
} else if(expr instanceof ImVarAccess) {
exprType = ((ImVarAccess)expr).getVar().getType();
} else if(expr instanceof ImVarArrayAccess) {
ImType type = ((ImVarArrayAccess)expr).getVar().getType();
if(type instanceof ImArrayLikeType) {
exprType = ((ImArrayLikeType) type).getEntryType();
if(expr instanceof ImFunctionCall imFunctionCall) {
exprType = imFunctionCall.getFunc().getReturnType();
} else if(expr instanceof ImVarAccess imVarAccess) {
exprType = imVarAccess.getVar().getType();
} else if(expr instanceof ImVarArrayAccess imVarArrayAccess) {
ImType type = imVarArrayAccess.getVar().getType();
if(type instanceof ImArrayLikeType imArrayLikeType) {
exprType = imArrayLikeType.getEntryType();
}
}
if(exprType != null && !TypesHelper.isIntType(exprType) && !TypesHelper.isRealType(exprType)) {
Expand Down Expand Up @@ -408,8 +407,7 @@ public ImVar initFor(IlConstHandle a) {
ImExpr init;

Object obj = a.getObj();
if (obj instanceof HashtableProvider.WurstHashtable) {
HashtableProvider.WurstHashtable map = (HashtableProvider.WurstHashtable) obj;
if (obj instanceof HashtableProvider.WurstHashtable map) {
ImType type = TypesHelper.imHashTable();
ImVar res = JassIm.ImVar(trace, type, type + "_compiletime", false);
imProg.getGlobals().add(res);
Expand Down Expand Up @@ -449,21 +447,21 @@ private String literalText(ILconstString value, Element trace) {
}

private ImExpr constantToExpr(Element trace, ILconst value, @Nullable ImType expectedType) {
if (value instanceof ILconstBool) {
return JassIm.ImBoolVal(((ILconstBool) value).getVal());
} else if (value instanceof ILconstInt) {
return JassIm.ImIntVal(((ILconstInt) value).getVal());
} else if (value instanceof ILconstReal) {
return JassIm.ImRealVal("" + ((ILconstReal) value).getVal());
} else if (value instanceof ILconstString) {
return JassIm.ImStringVal(literalText((ILconstString) value, trace));
if (value instanceof ILconstBool iLconstBool) {
return JassIm.ImBoolVal(iLconstBool.getVal());
} else if (value instanceof ILconstInt iLconstInt) {
return JassIm.ImIntVal(iLconstInt.getVal());
} else if (value instanceof ILconstReal iLconstReal) {
return JassIm.ImRealVal("" + iLconstReal.getVal());
} else if (value instanceof ILconstString iLconstString) {
return JassIm.ImStringVal(literalText(iLconstString, trace));
} else if (value instanceof ILconstNull) {
return expectedType == null ? ImHelper.nullExpr() : JassIm.ImNull(expectedType.copy());
} else if (value instanceof ILconstTuple) {
} else if (value instanceof ILconstTuple iLconstTuple) {
List<ImExpr> list = new ArrayList<>();
ImTupleType tupleType = expectedType instanceof ImTupleType ? (ImTupleType) expectedType : null;
ImTupleType tupleType = expectedType instanceof ImTupleType imTupleType ? imTupleType : null;
int index = 0;
for (ILconst e : ((ILconstTuple) value).values()) {
for (ILconst e : iLconstTuple.values()) {
ImType elementType = tupleType != null && index < tupleType.getTypes().size()
? tupleType.getTypes().get(index) : null;
ImExpr imExpr = constantToExpr(trace, e, elementType);
Expand All @@ -475,8 +473,7 @@ private ImExpr constantToExpr(Element trace, ILconst value, @Nullable ImType exp
list
)
);
} else if (value instanceof IlConstHandle) {
IlConstHandle h = (IlConstHandle) value;
} else if (value instanceof IlConstHandle h) {
ImVar hVar = globalForHandle.getFor(h);
return JassIm.ImVarAccess(hVar);
} else if (value instanceof ILconstObject) {
Expand Down Expand Up @@ -599,8 +596,7 @@ private ImFunction getCompiletimeStateInitFunction() {
ImFunctionCall call = JassIm.ImFunctionCall(trace, res, JassIm.ImTypeArguments(), JassIm.ImExprs(), true, CallType.NORMAL);
while (iterator.hasNext()) {
ImStmt stmt = iterator.next();
if (stmt instanceof ImFunctionCall) {
ImFunctionCall fc = (ImFunctionCall) stmt;
if (stmt instanceof ImFunctionCall fc) {
if (fc.getFunc() == globalInitFunc) {
// call initCompiletimeState right after globalInitFunc
iterator.add(call);
Expand Down Expand Up @@ -703,15 +699,15 @@ private void insertCompiletimeMigratedStateInitCalls(List<PackageStateReplay> pa
if (stateInit != null) {
for (int i = 0; i < mainBody.size(); i++) {
ImStmt stmt = mainBody.get(i);
if (stmt instanceof ImFunctionCall && ((ImFunctionCall) stmt).getFunc() == stateInit) {
if (stmt instanceof ImFunctionCall imFunctionCall && imFunctionCall.getFunc() == stateInit) {
mainBody.add(i + 1, newCompiletimeStateInitCall(mainReplay));
return;
}
}
}
for (int i = 0; i < mainBody.size(); i++) {
ImStmt stmt = mainBody.get(i);
if (stmt instanceof ImFunctionCall && ((ImFunctionCall) stmt).getFunc() == globalInitFunction) {
if (stmt instanceof ImFunctionCall imFunctionCall && imFunctionCall.getFunc() == globalInitFunction) {
mainBody.add(i + 1, newCompiletimeStateInitCall(mainReplay));
return;
}
Expand Down Expand Up @@ -902,9 +898,9 @@ private void emitCompiletimeArrayEntries(ImFunction target, ImVar var, ILconstAr
for (it.unimi.dsi.fastutil.ints.Int2ObjectMap.Entry<ILconst> entry : values.entries()) {
List<Integer> nextIndexes = new ArrayList<>(indexes);
nextIndexes.add(entry.getIntKey());
if (entry.getValue() instanceof ILconstArray && entryType instanceof ImArrayLikeType) {
if (entry.getValue() instanceof ILconstArray && entryType instanceof ImArrayLikeType imArrayLikeType) {
emitCompiletimeArrayEntries(target, var, (ILconstArray) entry.getValue(), nextIndexes,
((ImArrayLikeType) entryType).getEntryType(), runtimeArrayWrites, modifiedIndexes,
imArrayLikeType.getEntryType(), runtimeArrayWrites, modifiedIndexes,
unsupportedEntries);
} else if (!modifiedIndexes.contains(nextIndexes)) {
continue;
Expand Down Expand Up @@ -970,7 +966,7 @@ public void visit(ImSet set) {
ImVarArrayAccess access = (ImVarArrayAccess) set.getLeft();
List<Integer> indexes = new ArrayList<>();
for (ImExpr index : access.getIndexes()) {
indexes.add(index instanceof ImIntVal ? ((ImIntVal) index).getValI() : null);
indexes.add(index instanceof ImIntVal imIntVal ? imIntVal.getValI() : null);
}
runtimeArrayWrites.add(new RuntimeArrayWrite(access.getVar(), indexes));
}
Expand Down Expand Up @@ -1006,8 +1002,7 @@ private boolean matches(RuntimeArrayWrite other) {

@Override
public boolean equals(Object other) {
if (!(other instanceof RuntimeArrayWrite)) return false;
RuntimeArrayWrite that = (RuntimeArrayWrite) other;
if (!(other instanceof RuntimeArrayWrite that)) return false;
return var == that.var && indexes.equals(that.indexes);
}

Expand All @@ -1020,7 +1015,7 @@ public int hashCode() {
private static RuntimeArrayWrite runtimeArrayWrite(ImVar var, List<ImExpr> indexes) {
List<Integer> constantIndexes = new ArrayList<>();
for (ImExpr index : indexes) {
constantIndexes.add(index instanceof ImIntVal ? ((ImIntVal) index).getValI() : null);
constantIndexes.add(index instanceof ImIntVal imIntVal ? imIntVal.getValI() : null);
}
return new RuntimeArrayWrite(var, constantIndexes);
}
Expand All @@ -1030,14 +1025,14 @@ private boolean isPersistableCompiletimeValue(ILconst value) {
|| value instanceof ILconstString || value instanceof ILconstNull || value instanceof ILconstObject) {
return true;
}
if (value instanceof ILconstTuple) {
for (ILconst element : ((ILconstTuple) value).values()) {
if (value instanceof ILconstTuple iLconstTuple) {
for (ILconst element : iLconstTuple.values()) {
if (!isPersistableCompiletimeValue(element)) return false;
}
return true;
}
if (value instanceof IlConstHandle) {
Object obj = ((IlConstHandle) value).getObj();
if (value instanceof IlConstHandle ilConstHandle) {
Object obj = ilConstHandle.getObj();
return obj instanceof HashtableProvider.WurstHashtable;
}
return false;
Expand All @@ -1063,44 +1058,40 @@ private ImExpr constantToExprHashtable(Element trace, ImVar htVar, IlConstHandle
int parentKey = entry.parentKey;
int childKey = entry.childKey;
Object v = entry.value;
if (v instanceof ILconstInt) {
if (v instanceof ILconstInt iv) {
if (saveInteger == null) {
saveInteger = findNative("SaveInteger", errorPos);
}
ILconstInt iv = (ILconstInt) v;
batch.add(JassIm.ImFunctionCall(trace, saveInteger, JassIm.ImTypeArguments(), JassIm.ImExprs(
JassIm.ImVarAccess(htVar),
JassIm.ImIntVal(parentKey),
JassIm.ImIntVal(childKey),
JassIm.ImIntVal(iv.getVal())
), false, CallType.NORMAL));
} else if (v instanceof ILconstReal) {
} else if (v instanceof ILconstReal iv) {
if (saveReal == null) {
saveReal = findNative("SaveReal", errorPos);
}
ILconstReal iv = (ILconstReal) v;
batch.add(JassIm.ImFunctionCall(trace, saveReal, JassIm.ImTypeArguments(), JassIm.ImExprs(
JassIm.ImVarAccess(htVar),
JassIm.ImIntVal(parentKey),
JassIm.ImIntVal(childKey),
JassIm.ImRealVal("" + iv.getVal())
), false, CallType.NORMAL));
} else if (v instanceof ILconstString) {
} else if (v instanceof ILconstString iv) {
if (saveStr == null) {
saveStr = findNative("SaveStr", errorPos);
}
ILconstString iv = (ILconstString) v;
batch.add(JassIm.ImFunctionCall(trace, saveStr, JassIm.ImTypeArguments(), JassIm.ImExprs(
JassIm.ImVarAccess(htVar),
JassIm.ImIntVal(parentKey),
JassIm.ImIntVal(childKey),
JassIm.ImStringVal(literalText(iv, trace))
), false, CallType.NORMAL));
} else if (v instanceof ILconstBool) {
} else if (v instanceof ILconstBool iv) {
if (saveBoolean == null) {
saveBoolean = findNative("SaveBoolean", errorPos);
}
ILconstBool iv = (ILconstBool) v;
batch.add(JassIm.ImFunctionCall(trace, saveBoolean, JassIm.ImTypeArguments(), JassIm.ImExprs(
JassIm.ImVarAccess(htVar),
JassIm.ImIntVal(parentKey),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,8 @@ private static boolean tryExportWithWrapper(Appendable out, ObjectFileType fileT
StdlibObjectMappings.FieldMethodInfo info = fieldMethods.get(fieldKey(m, fileType));
if (info != null && canUseWrapperForMod(m, info)) {
out.append("\t..").append(info.methodName()).append("(");
if (info.hasLevel() && m instanceof ObjMod.Obj.ExtendedMod) {
out.append(String.valueOf(((ObjMod.Obj.ExtendedMod) m).getLevel())).append(", ");
if (info.hasLevel() && m instanceof ObjMod.Obj.ExtendedMod extendedMod) {
out.append(String.valueOf(extendedMod.getLevel())).append(", ");
}
out.append(formatWrapperValue(m, info)).append(")\n");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,7 @@ public TimerMockHandler getTimerMockHandler() {

public void runProgram() {
for (JassVar var : prog.getGlobals()) {
if (var instanceof JassInitializedVar) {
JassInitializedVar iVar = (JassInitializedVar) var;
if (var instanceof JassInitializedVar iVar) {
if (iVar.getIsBj()) {
// Evaluated on first read, as the IM interpreter does, so that an initialiser without
// a native mock only matters to a program that reads the global.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public NativeJassFunction getFunctionPair(String funcName) {
}

private void addProvider(Provider provider) {
if (provider instanceof OutputProvider) {
outputProviders.add((OutputProvider) provider);
if (provider instanceof OutputProvider outputProvider) {
outputProviders.add(outputProvider);
}
for (Method method : provider.getClass().getMethods()) {
Implements annotation = method.getAnnotation(Implements.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public IlConstHandle GetExpiredTimer() {

public void TimerStart(IlConstHandle whichTimer, ILconstReal timeout, ILconstBool periodic, ILconstAbstract handlerFunc) {
TimerMock timerMock = (TimerMock) whichTimer.getObj();
if (handlerFunc instanceof ILconstFuncRef) {
timerMock.start(timeout, periodic, (ILconstFuncRef) handlerFunc);
if (handlerFunc instanceof ILconstFuncRef iLconstFuncRef) {
timerMock.start(timeout, periodic, iLconstFuncRef);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ private String fetchConfigWithTimeout(String key, String defaultValue) {
try {
List<Object> config = res.get(FETCH_TIMEOUT_MS, TimeUnit.MILLISECONDS);
for (Object c : config) {
if (c instanceof JsonObject) {
JsonObject cfg = (JsonObject) c;
if (c instanceof JsonObject cfg) {

// Update cache with full config
cachedConfig.set(new CachedConfig(cfg));
Expand Down Expand Up @@ -134,8 +133,7 @@ private void refreshCacheAsync() {
languageClient.configuration(new ConfigurationParams(Collections.singletonList(ci)))
.thenAccept(config -> {
for (Object c : config) {
if (c instanceof JsonObject) {
JsonObject cfg = (JsonObject) c;
if (c instanceof JsonObject cfg) {
cachedConfig.set(new CachedConfig(cfg));
WLogger.trace("Config cache refreshed successfully");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,9 @@ public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof LookupKey)) {
if (!(obj instanceof LookupKey other)) {
return false;
}
LookupKey other = (LookupKey) obj;
return symbolName.equals(other.symbolName)
&& symbolKind == other.symbolKind
&& sourceFile.equals(other.sourceFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@ private Workitem getNextWorkItem() {
return new Workitem(change.toString(), () -> {
ModelManager.Changes affected = null;
if (isWurstDependencyFile(change)) {
if (change instanceof FileReconcile) {
FileReconcile fr = (FileReconcile) change;
if (change instanceof FileReconcile fr) {
affected = modelManager.syncCompilationUnitContent(fr.getFilename(), fr.getContents());
} else if (change instanceof FileSystemUpdated || change instanceof FileDeleted) {
// Dependency roots may have changed (e.g. grill install), sync full dependency state.
Expand All @@ -239,8 +238,7 @@ private Workitem getNextWorkItem() {
affected = modelManager.syncCompilationUnit(change.getFilename());
} else if (change instanceof FileUpdated) {
affected = modelManager.syncCompilationUnit(change.getFilename());
} else if (change instanceof FileReconcile) {
FileReconcile fr = (FileReconcile) change;
} else if (change instanceof FileReconcile fr) {
affected = modelManager.syncCompilationUnitContent(fr.getFilename(), fr.getContents());
} else {
WLogger.info("unhandled change request: " + change);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ private void clearCompilationUnit(CompilationUnit cu) {
// clear module instantiations
for (WPackage p : cu.getPackages()) {
for (WEntity elem : p.getElements()) {
if (elem instanceof ClassOrModuleInstanciation) {
clearModuleInstantiation(((ClassOrModuleInstanciation) elem));
if (elem instanceof ClassOrModuleInstanciation classOrModuleInstanciation) {
clearModuleInstantiation(classOrModuleInstanciation);
}
}
}
Expand Down
Loading
Loading