Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Painless: Cleanup Cache #33963

Merged
merged 2 commits into from
Sep 26, 2018
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 @@ -19,38 +19,59 @@

package org.elasticsearch.painless.lookup;

import java.util.Objects;

public class PainlessCast {

/** Create a standard cast with no boxing/unboxing. */
public static PainlessCast originalTypetoTargetType(Class<?> originalType, Class<?> targetType, boolean explicitCast) {
Objects.requireNonNull(originalType);
Objects.requireNonNull(targetType);

return new PainlessCast(originalType, targetType, explicitCast, null, null, null, null);
}

/** Create a cast where the original type will be unboxed, and then the cast will be performed. */
public static PainlessCast unboxOriginalType(
Class<?> originalType, Class<?> targetType, boolean explicitCast, Class<?> unboxOriginalType) {

Objects.requireNonNull(originalType);
Objects.requireNonNull(targetType);
Objects.requireNonNull(unboxOriginalType);

return new PainlessCast(originalType, targetType, explicitCast, unboxOriginalType, null, null, null);
}

/** Create a cast where the target type will be unboxed, and then the cast will be performed. */
public static PainlessCast unboxTargetType(
Class<?> originalType, Class<?> targetType, boolean explicitCast, Class<?> unboxTargetType) {

Objects.requireNonNull(originalType);
Objects.requireNonNull(targetType);
Objects.requireNonNull(unboxTargetType);

return new PainlessCast(originalType, targetType, explicitCast, null, unboxTargetType, null, null);
}

/** Create a cast where the original type will be boxed, and then the cast will be performed. */
public static PainlessCast boxOriginalType(
Class<?> originalType, Class<?> targetType, boolean explicitCast, Class<?> boxOriginalType) {

Objects.requireNonNull(originalType);
Objects.requireNonNull(targetType);
Objects.requireNonNull(boxOriginalType);

return new PainlessCast(originalType, targetType, explicitCast, null, null, boxOriginalType, null);
}

/** Create a cast where the target type will be boxed, and then the cast will be performed. */
public static PainlessCast boxTargetType(
Class<?> originalType, Class<?> targetType, boolean explicitCast, Class<?> boxTargetType) {

Objects.requireNonNull(originalType);
Objects.requireNonNull(targetType);
Objects.requireNonNull(boxTargetType);

return new PainlessCast(originalType, targetType, explicitCast, null, null, null, boxTargetType);
}

Expand All @@ -73,4 +94,30 @@ private PainlessCast(Class<?> originalType, Class<?> targetType, boolean explici
this.boxOriginalType = boxOriginalType;
this.boxTargetType = boxTargetType;
}

@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}

if (object == null || getClass() != object.getClass()) {
return false;
}

PainlessCast that = (PainlessCast)object;

return explicitCast == that.explicitCast &&
Objects.equals(originalType, that.originalType) &&
Objects.equals(targetType, that.targetType) &&
Objects.equals(unboxOriginalType, that.unboxOriginalType) &&
Objects.equals(unboxTargetType, that.unboxTargetType) &&
Objects.equals(boxOriginalType, that.boxOriginalType) &&
Objects.equals(boxTargetType, that.boxTargetType);
}

@Override
public int hashCode() {
return Objects.hash(originalType, targetType, explicitCast, unboxOriginalType, unboxTargetType, boxOriginalType, boxTargetType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.lang.invoke.MethodHandle;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;

public final class PainlessClass {

Expand Down Expand Up @@ -57,4 +58,29 @@ public final class PainlessClass {

this.functionalInterfaceMethod = functionalInterfaceMethod;
}

@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}

if (object == null || getClass() != object.getClass()) {
return false;
}

PainlessClass that = (PainlessClass)object;

return Objects.equals(constructors, that.constructors) &&
Objects.equals(staticMethods, that.staticMethods) &&
Objects.equals(methods, that.methods) &&
Objects.equals(staticFields, that.staticFields) &&
Objects.equals(fields, that.fields) &&
Objects.equals(functionalInterfaceMethod, that.functionalInterfaceMethod);
}

@Override
public int hashCode() {
return Objects.hash(constructors, staticMethods, methods, staticFields, fields, functionalInterfaceMethod);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Objects;

public class PainlessClassBinding {

Expand All @@ -38,4 +39,28 @@ public class PainlessClassBinding {
this.returnType = returnType;
this.typeParameters = typeParameters;
}

@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}

if (object == null || getClass() != object.getClass()) {
return false;
}

PainlessClassBinding that = (PainlessClassBinding)object;

return Objects.equals(javaConstructor, that.javaConstructor) &&
Objects.equals(javaMethod, that.javaMethod) &&
Objects.equals(returnType, that.returnType) &&
Objects.equals(typeParameters, that.typeParameters);
}

@Override
public int hashCode() {

return Objects.hash(javaConstructor, javaMethod, returnType, typeParameters);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.lang.invoke.MethodHandle;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

final class PainlessClassBuilder {

Expand Down Expand Up @@ -57,4 +58,29 @@ PainlessClass build() {
return new PainlessClass(constructors, staticMethods, methods, staticFields, fields,
getterMethodHandles, setterMethodHandles, functionalInterfaceMethod);
}

@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}

if (object == null || getClass() != object.getClass()) {
return false;
}

PainlessClassBuilder that = (PainlessClassBuilder)object;

return Objects.equals(constructors, that.constructors) &&
Objects.equals(staticMethods, that.staticMethods) &&
Objects.equals(methods, that.methods) &&
Objects.equals(staticFields, that.staticFields) &&
Objects.equals(fields, that.fields) &&
Objects.equals(functionalInterfaceMethod, that.functionalInterfaceMethod);
}

@Override
public int hashCode() {
return Objects.hash(constructors, staticMethods, methods, staticFields, fields, functionalInterfaceMethod);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.lang.invoke.MethodType;
import java.lang.reflect.Constructor;
import java.util.List;
import java.util.Objects;

public class PainlessConstructor {

Expand All @@ -37,4 +38,26 @@ public class PainlessConstructor {
this.methodHandle = methodHandle;
this.methodType = methodType;
}

@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}

if (object == null || getClass() != object.getClass()) {
return false;
}

PainlessConstructor that = (PainlessConstructor)object;

return Objects.equals(javaConstructor, that.javaConstructor) &&
Objects.equals(typeParameters, that.typeParameters) &&
Objects.equals(methodType, that.methodType);
}

@Override
public int hashCode() {
return Objects.hash(javaConstructor, typeParameters, methodType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.lang.invoke.MethodHandle;
import java.lang.reflect.Field;
import java.util.Objects;

public final class PainlessField {

Expand All @@ -37,4 +38,25 @@ public final class PainlessField {
this.getterMethodHandle = getterMethodHandle;
this.setterMethodHandle = setterMethodHandle;
}

@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}

if (object == null || getClass() != object.getClass()) {
return false;
}

PainlessField that = (PainlessField)object;

return Objects.equals(javaField, that.javaField) &&
Objects.equals(typeParameter, that.typeParameter);
}

@Override
public int hashCode() {
return Objects.hash(javaField, typeParameter);
}
}
Loading