@Override public GlobalVariable field(String name) { if(value != null && value instanceof IClass) { try { Field field = ((IClass)value).getField(name); if(Modifiers.isStatic(field.getModifiers())) { return new StaticGlobalVariable((IClass)value, field); } else { throw new ASMSupportException("No such field " + name); } } catch (NoSuchFieldException e) { throw new ASMSupportException(e); } } return null; } }
@Override public void execute(ClassExecuteContext context) { if(value != null && !Modifiers.isStatic(modifiers)) { throw new ASMSupportException("The initial value '" + value + "' of field '" + name + "' is invalided, cause by the field is not static, and the initial value only support static field."); } if(value != null && value instanceof Boolean) { value = (Boolean) value ? 1 : 0; } context.getClassVisitor().visitField( fe.getModifiers(), name, fe.getType().getDescription(), null, value).visitEnd(); }
@Override public GlobalVariable field(String name) { if(this.getResultType() instanceof ArrayClass){ throw new ASMSupportException("Cannot get global variable from array type variable : " + this); } try { Field field = getResultType().getField(name); if(Modifiers.isStatic(field.getModifiers())){ return new StaticGlobalVariable(field.getDeclaringClass(), field); } else { return new NonStaticGlobalVariable(this, field); } } catch (NoSuchFieldException e) { throw new ASMSupportException(e); } }
@Override public final GlobalVariable field(String name) { if(this.getResultType() instanceof ArrayClass){ throw new ASMSupportException("Cannot get global variable from array type variable : " + this); } try { Field field = getMeta().getType().getField(name); if(Modifiers.isStatic(field.getModifiers())){ return new StaticGlobalVariable(field.getDeclaringClass(), field); } else { return new NonStaticGlobalVariable(this, field); } } catch (NoSuchFieldException e) { throw new ASMSupportException(e); } }
@Override public void push(MethodExecuteContext context) { if (!IClassUtils.visible(context.getMethod().getDeclaringClass(), meta.getDirectOwnerType(), meta.getDeclaringClass(), meta.getModifiers())) { throw new IllegalArgumentException("Cannot access field " + meta.getDeclaringClass() + "#" + meta.getName() + " from " + context.getMethod().getDeclaringClass()); } if (LOG.isPrintEnabled()) { LOG.print("get field " + meta.getName() + " from class " + meta.getDirectOwnerType().getName() + " and push to stack!"); } context.getInstructions().getStatic(owner.getType(), meta.getName(), meta.getType().getType()); }
@Override public void push(MethodExecuteContext context) { if(!IClassUtils.visible(context.getMethod().getDeclaringClass(), meta.getDirectOwnerType(), meta.getDeclaringClass(), meta.getModifiers())){ throw new IllegalArgumentException("Cannot access field " + meta.getDeclaringClass() + "#" + meta.getName() + " from " + context.getMethod().getDeclaringClass()); } if(LOG.isPrintEnabled()){ LOG.print("Get field " + meta.getName() + " from variable " + meta.getName() + " and push to stack!"); } owner.push(context); context.getInstructions().getField(meta.getDirectOwnerType().getType(), meta.getName(), meta.getType().getType()); }