void validateFinalIsSet(boolean isStatic) { if (!hasModifier("final") || this.value != null) return; if (isStatic == hasModifier("static")) throw new RuntimeException((isStatic ? "Static f" : "F") +"inal variable "+name+" is not initialized."); }
public boolean isStatic() { if ( null != field ) return field.isStatic(); if ( null == this.var ) return false; return var.hasModifier("static"); }
public boolean isFinal() { if ( getVariable() == null ) return false; return var.hasModifier("final"); }
public void setConstant() { if (hasModifier("private") || hasModifier("protected")) throw new IllegalArgumentException("Illegal modifier for interface field " + getName() + ". Only public static & final are permitted."); getModifiers().setConstant(); }
Variable var = ns.getVariableImpl(fieldName, true); Object val = Primitive.VOID; if ( null != var && (!var.hasModifier("private") || haveAccessibility()) ) val = ns.unwrapVariable(var); Variable var = ns.getVariableImpl(fieldName, true); Object val = Primitive.VOID; if ( null != var && (!var.hasModifier("private") || haveAccessibility()) ) val = ns.unwrapVariable(var);
/** Set the value of the typed variable. @param value should be an object or wrapped bsh Primitive type. if value is null the appropriate default value will be set for the type: e.g. false for boolean, zero for integer types. */ public void setValue( Object value, int context ) throws UtilEvalError { // prevent final variable re-assign if (hasModifier("final")) { if (this.value != null) throw new UtilEvalError("Cannot re-assign final variable "+name+"."); if (value == null) return; } // TODO: should add isJavaCastable() test for strictJava // (as opposed to isJavaAssignable()) if ( type != null && type != Object.class && value != null ) { this.value = Types.castObject( value, type, context == DECLARATION ? Types.CAST : Types.ASSIGNMENT ); value = this.value; } this.value = value; if ( this.value == null && context != DECLARATION ) this.value = Primitive.getDefaultValue( type ); if ( lhs != null ) this.value = lhs.assign( this.value, false/*strictjava*/ ); }
/** Set the value of the typed variable. @param value should be an object or wrapped bsh Primitive type. if value is null the appropriate default value will be set for the type: e.g. false for boolean, zero for integer types. */ public void setValue( Object value, int context ) throws UtilEvalError { // check this.value if ( hasModifier("final") && this.value != null ) throw new UtilEvalError ("Final variable, can't re-assign."); if ( value == null ) value = Primitive.getDefaultValue( type ); if ( lhs != null ) { lhs.assign( value, false/*strictjava*/ ); return; } // TODO: should add isJavaCastable() test for strictJava // (as opposed to isJavaAssignable()) if ( type != null ) value = Types.castObject( value, type, context == DECLARATION ? Types.CAST : Types.ASSIGNMENT ); this.value= value; }
/** Get an LHS reference to an object field. This method also deals with the field style property access. In the field does not exist we check for a property setter. */ static LHS getLHSObjectField( Object object, String fieldName ) throws UtilEvalError, ReflectError { if ( object instanceof This ) return new LHS( ((This)object).namespace, fieldName, false ); try { Invocable f = resolveExpectedJavaField( object.getClass(), fieldName, false/*staticOnly*/ ); return new LHS(object, f); } catch ( ReflectError e ) { NameSpace ns = getThisNS(object); if (isGeneratedClass(object.getClass()) && null != ns && ns.isClass) { Variable var = ns.getVariableImpl(fieldName, true); if ( null != var && (!var.hasModifier("private") || haveAccessibility()) ) return new LHS(ns, fieldName); } // not a field, try property access if ( hasObjectPropertySetter( object.getClass(), fieldName ) ) return new LHS( object, fieldName ); else throw e; } }
/** Generate the static initialization of the enum constants. Called from clinit. * @param fqClassName fully qualified class name * @param classDescript class descriptor string * @param cv clinit method visitor */ private void generateEnumStaticInit(String fqClassName, String classDescript, MethodVisitor cv) { int ordinal = ICONST_0; for ( Variable var : vars ) if ( var.hasModifier("enum") ) { cv.visitTypeInsn(NEW, fqClassName); cv.visitInsn(DUP); cv.visitLdcInsn(var.getName()); if ( ICONST_5 >= ordinal ) cv.visitInsn(ordinal++); else cv.visitIntInsn(BIPUSH, ordinal++ - ICONST_0); cv.visitMethodInsn(INVOKESPECIAL, fqClassName, "<init>", "(Ljava/lang/String;I)V", false); cv.visitFieldInsn(PUTSTATIC, fqClassName, var.getName(), classDescript); } }
static LHS getLHSStaticField(Class<?> clas, String fieldName) throws UtilEvalError, ReflectError { try { Invocable f = resolveExpectedJavaField( clas, fieldName, true/*onlystatic*/); return new LHS(f); } catch ( ReflectError e ) { NameSpace ns = getThisNS(clas); if (isGeneratedClass(clas) && null != ns && ns.isClass) { Variable var = ns.getVariableImpl(fieldName, true); if ( null != var && (!var.hasModifier("private") || haveAccessibility()) ) return new LHS(ns, fieldName); } // not a field, try property access if ( hasObjectPropertySetter( clas, fieldName ) ) return new LHS( clas, fieldName ); else throw e; } }
if (var.hasModifier("private") || type == null) { continue;
if (var.hasModifier("private")) continue; } else if ( type == ENUM && var.hasModifier("enum") ) { modifiers |= ACC_ENUM | ACC_FINAL; fType = classDescript;