mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8263358: Update java.lang to use instanceof pattern variable
Reviewed-by: iris, chegar, mchung, dfuchs
This commit is contained in:
parent
ae9af57bf6
commit
329697b02e
18 changed files with 63 additions and 112 deletions
|
@ -673,9 +673,8 @@ public final class ProcessBuilder
|
|||
public boolean equals(Object obj) {
|
||||
if (obj == this)
|
||||
return true;
|
||||
if (! (obj instanceof Redirect))
|
||||
if (! (obj instanceof Redirect r))
|
||||
return false;
|
||||
Redirect r = (Redirect) obj;
|
||||
if (r.type() != this.type())
|
||||
return false;
|
||||
assert this.file() != null;
|
||||
|
|
|
@ -519,14 +519,9 @@ final class ProcessHandleImpl implements ProcessHandle {
|
|||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj instanceof ProcessHandleImpl) {
|
||||
ProcessHandleImpl other = (ProcessHandleImpl) obj;
|
||||
return (pid == other.pid) &&
|
||||
(startTime == other.startTime
|
||||
|| startTime == 0
|
||||
|| other.startTime == 0);
|
||||
}
|
||||
return false;
|
||||
return (obj instanceof ProcessHandleImpl other)
|
||||
&& (pid == other.pid)
|
||||
&& (startTime == other.startTime || startTime == 0 || other.startTime == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -113,11 +113,10 @@ final class PublicMethods {
|
|||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Key)) return false;
|
||||
Key that = (Key) o;
|
||||
//noinspection StringEquality (guaranteed interned String(s))
|
||||
return name == that.name &&
|
||||
Arrays.equals(ptypes, that.ptypes);
|
||||
return (o instanceof Key that)
|
||||
&& name == that.name
|
||||
&& Arrays.equals(ptypes, that.ptypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1427,11 +1427,8 @@ public class Runtime {
|
|||
public boolean equalsIgnoreOptional(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!(obj instanceof Version))
|
||||
return false;
|
||||
|
||||
Version that = (Version)obj;
|
||||
return (this.version().equals(that.version())
|
||||
return (obj instanceof Version that)
|
||||
&& (this.version().equals(that.version())
|
||||
&& this.pre().equals(that.pre())
|
||||
&& this.build().equals(that.build()));
|
||||
}
|
||||
|
|
|
@ -129,8 +129,7 @@ class Shutdown {
|
|||
}
|
||||
if (hook != null) hook.run();
|
||||
} catch (Throwable t) {
|
||||
if (t instanceof ThreadDeath) {
|
||||
ThreadDeath td = (ThreadDeath)t;
|
||||
if (t instanceof ThreadDeath td) {
|
||||
throw td;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -406,16 +406,14 @@ public final class StackTraceElement implements java.io.Serializable {
|
|||
public boolean equals(Object obj) {
|
||||
if (obj==this)
|
||||
return true;
|
||||
if (!(obj instanceof StackTraceElement))
|
||||
return false;
|
||||
StackTraceElement e = (StackTraceElement)obj;
|
||||
return Objects.equals(classLoaderName, e.classLoaderName) &&
|
||||
Objects.equals(moduleName, e.moduleName) &&
|
||||
Objects.equals(moduleVersion, e.moduleVersion) &&
|
||||
e.declaringClass.equals(declaringClass) &&
|
||||
e.lineNumber == lineNumber &&
|
||||
Objects.equals(methodName, e.methodName) &&
|
||||
Objects.equals(fileName, e.fileName);
|
||||
return (obj instanceof StackTraceElement e)
|
||||
&& e.lineNumber == lineNumber
|
||||
&& e.declaringClass.equals(declaringClass)
|
||||
&& Objects.equals(classLoaderName, e.classLoaderName)
|
||||
&& Objects.equals(moduleName, e.moduleName)
|
||||
&& Objects.equals(moduleVersion, e.moduleVersion)
|
||||
&& Objects.equals(methodName, e.methodName)
|
||||
&& Objects.equals(fileName, e.fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1818,13 +1818,9 @@ public final class String
|
|||
if (this == anObject) {
|
||||
return true;
|
||||
}
|
||||
if (anObject instanceof String) {
|
||||
String aString = (String)anObject;
|
||||
if (!COMPACT_STRINGS || this.coder == aString.coder) {
|
||||
return StringLatin1.equals(value, aString.value);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return (anObject instanceof String aString)
|
||||
&& (!COMPACT_STRINGS || this.coder == aString.coder)
|
||||
&& StringLatin1.equals(value, aString.value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -350,12 +350,11 @@ public abstract class DynamicConstantDesc<T>
|
|||
@Override
|
||||
public final boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof DynamicConstantDesc)) return false;
|
||||
DynamicConstantDesc<?> desc = (DynamicConstantDesc<?>) o;
|
||||
return Objects.equals(bootstrapMethod, desc.bootstrapMethod) &&
|
||||
Arrays.equals(bootstrapArgs, desc.bootstrapArgs) &&
|
||||
Objects.equals(constantName, desc.constantName) &&
|
||||
Objects.equals(constantType, desc.constantType);
|
||||
return (o instanceof DynamicConstantDesc<?> desc)
|
||||
&& Objects.equals(bootstrapMethod, desc.bootstrapMethod)
|
||||
&& Arrays.equals(bootstrapArgs, desc.bootstrapArgs)
|
||||
&& Objects.equals(constantName, desc.constantName)
|
||||
&& Objects.equals(constantType, desc.constantType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -302,8 +302,7 @@ class InvokerBytecodeGenerator {
|
|||
}
|
||||
|
||||
private static String debugString(Object arg) {
|
||||
if (arg instanceof MethodHandle) {
|
||||
MethodHandle mh = (MethodHandle) arg;
|
||||
if (arg instanceof MethodHandle mh) {
|
||||
MemberName member = mh.internalMemberName();
|
||||
if (member != null)
|
||||
return member.toString();
|
||||
|
@ -627,8 +626,7 @@ class InvokerBytecodeGenerator {
|
|||
|
||||
private void emitReferenceCast(Class<?> cls, Object arg) {
|
||||
Name writeBack = null; // local to write back result
|
||||
if (arg instanceof Name) {
|
||||
Name n = (Name) arg;
|
||||
if (arg instanceof Name n) {
|
||||
if (lambdaForm.useCount(n) > 1) {
|
||||
// This guy gets used more than once.
|
||||
writeBack = n;
|
||||
|
@ -1679,8 +1677,7 @@ class InvokerBytecodeGenerator {
|
|||
|
||||
private void emitPushArgument(Class<?> ptype, Object arg) {
|
||||
BasicType bptype = basicType(ptype);
|
||||
if (arg instanceof Name) {
|
||||
Name n = (Name) arg;
|
||||
if (arg instanceof Name n) {
|
||||
emitLoadInsn(n.type, n.index());
|
||||
emitImplicitConversion(n.type, ptype, n);
|
||||
} else if (arg == null && bptype == L_TYPE) {
|
||||
|
|
|
@ -568,8 +568,7 @@ class LambdaForm {
|
|||
Name n = names[i];
|
||||
assert(n.index() == i);
|
||||
for (Object arg : n.arguments) {
|
||||
if (arg instanceof Name) {
|
||||
Name n2 = (Name) arg;
|
||||
if (arg instanceof Name n2) {
|
||||
int i2 = n2.index;
|
||||
assert(0 <= i2 && i2 < names.length) : n.debugString() + ": 0 <= i2 && i2 < names.length: 0 <= " + i2 + " < " + names.length;
|
||||
assert(names[i2] == n2) : Arrays.asList("-1-", i, "-2-", n.debugString(), "-3-", i2, "-4-", n2.debugString(), "-5-", names[i2].debugString(), "-6-", this);
|
||||
|
@ -1133,9 +1132,9 @@ class LambdaForm {
|
|||
public boolean equals(Object other) {
|
||||
if (this == other) return true;
|
||||
if (other == null) return false;
|
||||
if (!(other instanceof NamedFunction)) return false;
|
||||
NamedFunction that = (NamedFunction) other;
|
||||
return this.member != null && this.member.equals(that.member);
|
||||
return (other instanceof NamedFunction that)
|
||||
&& this.member != null
|
||||
&& this.member.equals(that.member);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1407,8 +1406,7 @@ class LambdaForm {
|
|||
boolean replaced = false;
|
||||
eachArg:
|
||||
for (int j = 0; j < arguments.length; j++) {
|
||||
if (arguments[j] instanceof Name) {
|
||||
Name n = (Name) arguments[j];
|
||||
if (arguments[j] instanceof Name n) {
|
||||
int check = n.index;
|
||||
// harmless check to see if the thing is already in newNames:
|
||||
if (check >= 0 && check < newNames.length && n == newNames[check])
|
||||
|
@ -1435,8 +1433,7 @@ class LambdaForm {
|
|||
@SuppressWarnings("LocalVariableHidesMemberVariable")
|
||||
Object[] arguments = this.arguments;
|
||||
for (int j = 0; j < arguments.length; j++) {
|
||||
if (arguments[j] instanceof Name) {
|
||||
Name n = (Name) arguments[j];
|
||||
if (arguments[j] instanceof Name n) {
|
||||
if (n.isParam() && n.index < INTERNED_ARGUMENT_LIMIT)
|
||||
arguments[j] = internArgument(n);
|
||||
}
|
||||
|
|
|
@ -337,9 +337,8 @@ class LambdaFormEditor {
|
|||
k = m.get(key);
|
||||
} else if (c == null) {
|
||||
return null;
|
||||
} else if (c instanceof Transform) {
|
||||
} else if (c instanceof Transform t) {
|
||||
// one-element cache avoids overhead of an array
|
||||
Transform t = (Transform)c;
|
||||
if (t.equals(key)) k = t;
|
||||
} else {
|
||||
Transform[] ta = (Transform[])c;
|
||||
|
@ -389,8 +388,7 @@ class LambdaFormEditor {
|
|||
return form;
|
||||
}
|
||||
Transform[] ta;
|
||||
if (c instanceof Transform) {
|
||||
Transform k = (Transform)c;
|
||||
if (c instanceof Transform k) {
|
||||
if (k.equals(key)) {
|
||||
LambdaForm result = k.get();
|
||||
if (result == null) {
|
||||
|
|
|
@ -147,12 +147,10 @@ final class MemberName implements Member, Cloneable {
|
|||
|
||||
// type is not a MethodType yet. Convert it thread-safely.
|
||||
synchronized (this) {
|
||||
if (type instanceof String) {
|
||||
String sig = (String) type;
|
||||
if (type instanceof String sig) {
|
||||
MethodType res = MethodType.fromDescriptor(sig, getClassLoader());
|
||||
type = res;
|
||||
} else if (type instanceof Object[]) {
|
||||
Object[] typeInfo = (Object[]) type;
|
||||
} else if (type instanceof Object[] typeInfo) {
|
||||
Class<?>[] ptypes = (Class<?>[]) typeInfo[1];
|
||||
Class<?> rtype = (Class<?>) typeInfo[0];
|
||||
MethodType res = MethodType.makeImpl(rtype, ptypes, true);
|
||||
|
@ -235,8 +233,7 @@ final class MemberName implements Member, Cloneable {
|
|||
|
||||
// type is not a Class yet. Convert it thread-safely.
|
||||
synchronized (this) {
|
||||
if (type instanceof String) {
|
||||
String sig = (String) type;
|
||||
if (type instanceof String sig) {
|
||||
MethodType mtype = MethodType.fromDescriptor("()"+sig, getClassLoader());
|
||||
Class<?> res = mtype.returnType();
|
||||
type = res;
|
||||
|
@ -938,8 +935,7 @@ final class MemberName implements Member, Cloneable {
|
|||
} else {
|
||||
Module m;
|
||||
Class<?> plc;
|
||||
if (from instanceof MethodHandles.Lookup) {
|
||||
MethodHandles.Lookup lookup = (MethodHandles.Lookup)from;
|
||||
if (from instanceof MethodHandles.Lookup lookup) {
|
||||
from = lookup.lookupClass();
|
||||
m = lookup.lookupClass().getModule();
|
||||
plc = lookup.previousLookupClass();
|
||||
|
|
|
@ -2262,10 +2262,9 @@ public class MethodHandles {
|
|||
// workaround to read `this_class` using readConst and validate the value
|
||||
int thisClass = reader.readUnsignedShort(reader.header + 2);
|
||||
Object constant = reader.readConst(thisClass, new char[reader.getMaxStringLength()]);
|
||||
if (!(constant instanceof Type)) {
|
||||
if (!(constant instanceof Type type)) {
|
||||
throw new ClassFormatError("this_class item: #" + thisClass + " not a CONSTANT_Class_info");
|
||||
}
|
||||
Type type = ((Type) constant);
|
||||
if (!type.getDescriptor().startsWith("L")) {
|
||||
throw new ClassFormatError("this_class item: #" + thisClass + " not a CONSTANT_Class_info");
|
||||
}
|
||||
|
|
|
@ -605,8 +605,7 @@ final class VarHandles {
|
|||
}
|
||||
|
||||
private static void noCheckedExceptions(MethodHandle handle) {
|
||||
if (handle instanceof DirectMethodHandle) {
|
||||
DirectMethodHandle directHandle = (DirectMethodHandle)handle;
|
||||
if (handle instanceof DirectMethodHandle directHandle) {
|
||||
byte refKind = directHandle.member.getReferenceKind();
|
||||
MethodHandleInfo info = new InfoFromMemberName(
|
||||
MethodHandles.Lookup.IMPL_LOOKUP,
|
||||
|
|
|
@ -310,10 +310,8 @@ public class ModuleDescriptor
|
|||
*/
|
||||
@Override
|
||||
public boolean equals(Object ob) {
|
||||
if (!(ob instanceof Requires))
|
||||
return false;
|
||||
Requires that = (Requires)ob;
|
||||
return name.equals(that.name) && mods.equals(that.mods)
|
||||
return (ob instanceof Requires that)
|
||||
&& name.equals(that.name) && mods.equals(that.mods)
|
||||
&& Objects.equals(compiledVersion, that.compiledVersion)
|
||||
&& Objects.equals(rawCompiledVersion, that.rawCompiledVersion);
|
||||
}
|
||||
|
@ -531,10 +529,8 @@ public class ModuleDescriptor
|
|||
*/
|
||||
@Override
|
||||
public boolean equals(Object ob) {
|
||||
if (!(ob instanceof Exports))
|
||||
return false;
|
||||
Exports other = (Exports)ob;
|
||||
return Objects.equals(this.mods, other.mods)
|
||||
return (ob instanceof Exports other)
|
||||
&& Objects.equals(this.mods, other.mods)
|
||||
&& Objects.equals(this.source, other.source)
|
||||
&& Objects.equals(this.targets, other.targets);
|
||||
}
|
||||
|
@ -736,12 +732,10 @@ public class ModuleDescriptor
|
|||
*/
|
||||
@Override
|
||||
public boolean equals(Object ob) {
|
||||
if (!(ob instanceof Opens))
|
||||
return false;
|
||||
Opens other = (Opens)ob;
|
||||
return Objects.equals(this.mods, other.mods)
|
||||
&& Objects.equals(this.source, other.source)
|
||||
&& Objects.equals(this.targets, other.targets);
|
||||
return (ob instanceof Opens other)
|
||||
&& Objects.equals(this.mods, other.mods)
|
||||
&& Objects.equals(this.source, other.source)
|
||||
&& Objects.equals(this.targets, other.targets);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -872,11 +866,9 @@ public class ModuleDescriptor
|
|||
*/
|
||||
@Override
|
||||
public boolean equals(Object ob) {
|
||||
if (!(ob instanceof Provides))
|
||||
return false;
|
||||
Provides other = (Provides)ob;
|
||||
return Objects.equals(this.service, other.service) &&
|
||||
Objects.equals(this.providers, other.providers);
|
||||
return (ob instanceof Provides other)
|
||||
&& Objects.equals(this.service, other.service)
|
||||
&& Objects.equals(this.providers, other.providers);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2241,10 +2233,8 @@ public class ModuleDescriptor
|
|||
public boolean equals(Object ob) {
|
||||
if (ob == this)
|
||||
return true;
|
||||
if (!(ob instanceof ModuleDescriptor))
|
||||
return false;
|
||||
ModuleDescriptor that = (ModuleDescriptor)ob;
|
||||
return (name.equals(that.name)
|
||||
return (ob instanceof ModuleDescriptor that)
|
||||
&& (name.equals(that.name)
|
||||
&& modifiers.equals(that.modifiers)
|
||||
&& requires.equals(that.requires)
|
||||
&& Objects.equals(packages, that.packages)
|
||||
|
|
|
@ -138,12 +138,9 @@ public final class ResolvedModule {
|
|||
*/
|
||||
@Override
|
||||
public boolean equals(Object ob) {
|
||||
if (!(ob instanceof ResolvedModule))
|
||||
return false;
|
||||
|
||||
ResolvedModule that = (ResolvedModule) ob;
|
||||
return Objects.equals(this.cf, that.cf)
|
||||
&& Objects.equals(this.mref, that.mref);
|
||||
return (ob instanceof ResolvedModule that)
|
||||
&& Objects.equals(this.cf, that.cf)
|
||||
&& Objects.equals(this.mref, that.mref);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -714,8 +714,7 @@ public final class Method extends Executable {
|
|||
getConstantPool(getDeclaringClass()),
|
||||
getDeclaringClass());
|
||||
if (result instanceof ExceptionProxy) {
|
||||
if (result instanceof TypeNotPresentExceptionProxy) {
|
||||
TypeNotPresentExceptionProxy proxy = (TypeNotPresentExceptionProxy)result;
|
||||
if (result instanceof TypeNotPresentExceptionProxy proxy) {
|
||||
throw new TypeNotPresentException(proxy.typeName(), proxy.getCause());
|
||||
}
|
||||
throw new AnnotationFormatError("Invalid default: " + this);
|
||||
|
|
|
@ -77,12 +77,9 @@ public final class Parameter implements AnnotatedElement {
|
|||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Parameter) {
|
||||
Parameter other = (Parameter)obj;
|
||||
return (other.executable.equals(executable) &&
|
||||
other.index == index);
|
||||
}
|
||||
return false;
|
||||
return (obj instanceof Parameter other)
|
||||
&& other.executable.equals(executable)
|
||||
&& other.index == index;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue