Skip to content

Commit

Permalink
Merge pull request #9235 from eclipse/jetty-12.0.x-9233-core-common-u…
Browse files Browse the repository at this point in the history
…til-cleanup

Issue #9233 - cleanup of websocket-core-common util package
  • Loading branch information
lachlan-roberts authored Feb 9, 2023
2 parents 342bd40 + c9004ee commit 3ed9302
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 234 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import org.eclipse.jetty.websocket.core.exception.InvalidSignatureException;
import org.slf4j.Logger;
Expand Down Expand Up @@ -57,7 +58,7 @@ public boolean matches(Arg other)
if ((this.name != null) || (other.name != null))
{
// They have to match
if (this.name.equals(other.name))
if (Objects.equals(this.name, other.name))
{
if (convertible)
{
Expand All @@ -79,7 +80,7 @@ public boolean matches(Arg other)
return false;
}

// Not named, then its a simple type / assignable match
// Not named, then it's a simple type / assignable match
return (other.type.isAssignableFrom(this.type));
}

Expand Down Expand Up @@ -112,11 +113,6 @@ public boolean isRequired()
{
return required;
}

public boolean isConvertible()
{
return convertible;
}
}

public interface ParamIdentifier
Expand Down Expand Up @@ -218,7 +214,7 @@ private static MethodHandle mutatedInvoker(MethodHandles.Lookup lookup, Class<?>
Class<?>[] parameterTypes = method.getParameterTypes();

// Construct Actual Calling Args.
// This is the array of args, arriving as all of the named variables (usually static in nature),
// This is the array of args, arriving as all the named variables (usually static in nature),
// then the raw calling arguments (very dynamic in nature)
Arg[] callingArgs = new Arg[rawCallingArgs.length + (namedVariables == null ? 0 : namedVariables.length)];
{
Expand Down Expand Up @@ -253,13 +249,11 @@ private static MethodHandle mutatedInvoker(MethodHandles.Lookup lookup, Class<?>
}

// Parameter to Calling Argument mapping.
// The size of this array must be the the same as the parameterArgs array (or bigger)
// The size of this array must be the same as the parameterArgs array (or bigger)
if (callingArgs.length < parameterTypes.length)
{
if (!throwOnFailure)
{
return null;
}

StringBuilder err = new StringBuilder();
err.append("Target method ");
Expand All @@ -275,17 +269,12 @@ private static MethodHandle mutatedInvoker(MethodHandles.Lookup lookup, Class<?>
List<Class<?>> cTypes = new ArrayList<>();
{
cTypes.add(targetClass); // targetClass always at index 0
for (int i = 0; i < callingArgs.length; i++)
for (Arg arg : callingArgs)
{
Arg arg = callingArgs[i];
if (arg.name != null)
{
hasNamedCallingArgs = true;
}
if (arg.convertible)
{
hasConvertibleTypes = true;
}
cTypes.add(arg.getType());
}
}
Expand All @@ -304,9 +293,7 @@ private static MethodHandle mutatedInvoker(MethodHandles.Lookup lookup, Class<?>
// If callingType and rawType are the same (and there's no named args),
// then there's no need to reorder / permute / drop args
if (!hasNamedCallingArgs && !hasNamedParamArgs && rawType.equals(callingType))
{
return methodHandle;
}

// If we reached this point, then we know that the callingType and rawType don't
// match, so we have to drop and/or permute(reorder) the arguments
Expand Down Expand Up @@ -341,9 +328,7 @@ private static MethodHandle mutatedInvoker(MethodHandles.Lookup lookup, Class<?>
if (ref < 0)
{
if (!throwOnFailure)
{
return null;
}

StringBuilder err = new StringBuilder();
err.append("Invalid mapping of type [");
Expand All @@ -364,14 +349,12 @@ private static MethodHandle mutatedInvoker(MethodHandles.Lookup lookup, Class<?>
{
for (int uci = 0; uci < usedCallingArgs.length; uci++)
{
if (usedCallingArgs[uci] == false)
if (!usedCallingArgs[uci])
{
if (callingArgs[uci].required)
{
if (!throwOnFailure)
{
return null;
}

StringBuilder err = new StringBuilder();
err.append("Missing required argument [");
Expand Down Expand Up @@ -407,9 +390,8 @@ private static MethodHandle mutatedInvoker(MethodHandles.Lookup lookup, Class<?>
// Use converted Types for callingArgs
cTypes = new ArrayList<>();
cTypes.add(targetClass); // targetClass always at index 0
for (int i = 0; i < callingArgs.length; i++)
for (Arg arg : callingArgs)
{
Arg arg = callingArgs[i];
cTypes.add(arg.getConvertedType());
}
callingType = MethodType.methodType(method.getReturnType(), cTypes);
Expand Down Expand Up @@ -478,18 +460,4 @@ private static void appendTypeList(StringBuilder str, Arg[] args)
}
str.append(")");
}

private static void appendTypeList(StringBuilder str, Class<?>[] types)
{
str.append("(");
boolean comma = false;
for (Class<?> type : types)
{
if (comma)
str.append(", ");
str.append(type.getName());
comma = true;
}
str.append(")");
}
}
Loading

0 comments on commit 3ed9302

Please sign in to comment.