/** Reflect Field is not serializable, hide it. * @param s serializer * @throws IOException mandatory throwing exception */ private synchronized void writeObject(final ObjectOutputStream s) throws IOException { if ( null != field ) { this.object = field.getDeclaringClass(); this.varName = field.getName(); this.field = null; } s.defaultWriteObject(); }
/** {@inheritDoc} */ @Override public int hashCode() { return getClass().hashCode() ^ getName().hashCode() ^ getDeclaringClass().hashCode() ^ getParameterCount() ^ getReturnType().hashCode() ^ getModifiers() ^ Stream.of(getParameterTypes()) .map(t -> null == t ? 39 : t.hashCode()) .reduce(75, (a, b) -> a ^ b).intValue(); } }
/** This method wraps resolveJavaMethod() and expects a non-null method result. If the method is not found it throws a descriptive ReflectError. */ protected static Invocable resolveExpectedJavaMethod( BshClassManager bcm, Class<?> clas, Object object, String name, Object[] args, boolean staticOnly ) throws ReflectError, UtilEvalError { if ( object == Primitive.NULL ) throw new UtilTargetError( new NullPointerException( "Attempt to invoke method " +name+" on null value" ) ); Class<?>[] types = Types.getTypes(args); Invocable method = resolveJavaMethod( clas, name, types, staticOnly ); if ( null != bcm && bcm.getStrictJava() && method != null && method.getDeclaringClass().isInterface() && method.getDeclaringClass() != clas && Modifier.isStatic(method.getModifiers())) // static interface methods are class only method = null; if ( method == null ) throw new ReflectError( ( staticOnly ? "Static method " : "Method " ) + StringUtil.methodString(name, types) + " not found in class'" + clas.getName() + "'"); return method; }
/** {@inheritDoc} */ @Override public boolean equals(Object o) { if (o == null) return false; if (this == o) return true; if (this.getClass() != o.getClass()) return false; Invocable member = (Invocable) o; if (!getName().equals(member.getName()) || getDeclaringClass() != member.getDeclaringClass() || getParameterCount() != member.getParameterCount() || getReturnType() != member.getReturnType() || getModifiers() != member.getModifiers()) return false; for (int i = 0; i < getParameterCount(); i++) if (getParameterTypes()[i] != member.getParameterTypes()[i]) return false; return true; }
public Variable getVariable() { if ( null != var ) return this.var; if ( null != nameSpace ) this.var = Reflect.getVariable(nameSpace, getName()); else if ( isStatic() ) this.var = Reflect.getVariable(field.getDeclaringClass(), getName()); else this.var = Reflect.getVariable(object, getName()); return this.var; }