public boolean isStatic() { if ( null != field ) return field.isStatic(); if ( null == this.var ) return false; return var.hasModifier("static"); }
private static void checkFoundStaticMethod( Invocable method, boolean staticOnly, Class<?> clas ) throws UtilEvalError { // We're looking for a static method but found an instance method if ( method != null && staticOnly && !method.isStatic() ) throw new UtilEvalError( "Cannot reach instance method: " + StringUtil.methodString( method.getName(), method.getParameterTypes() ) + " from static context: "+ clas.getName() ); }
/** @throws ReflectError if the field is not found. */ /* Note: this should really just throw NoSuchFieldException... need to change related signatures and code. */ protected static Invocable resolveExpectedJavaField( Class<?> clas, String fieldName, boolean staticOnly) throws UtilEvalError, ReflectError { Invocable field = BshClassManager.memberCache .get(clas).findField(fieldName); if (null == field) throw new ReflectError("No such field: " + fieldName + " for class: " + clas.getName()); if ( staticOnly && !field.isStatic() ) throw new UtilEvalError( "Can't reach instance field: " + fieldName + " from static context: " + clas.getName() ); return field; }
/** All purpose MethodHandle invoke implementation, with or without args. * @param base represents the base object instance. * @param pars parameter arguments * @return invocation result * @throws Throwable combined exceptions */ private synchronized Object invokeTarget(Object base, Object[] pars) throws Throwable { Reflect.logInvokeMethod("Invoking method (entry): ", this, pars); List<Object> params = collectParamaters(base, pars); Reflect.logInvokeMethod("Invoking method (after): ", this, params); if (getParameterCount() > 0) return getMethodHandle().invokeWithArguments(params); if (isStatic() || this instanceof ConstructorInvocable) return getMethodHandle().invoke(); return getMethodHandle().invoke(params.get(0)); }