Refine search
@Override public void edit(FieldAccess f) throws CannotCompileException { try { if ( ! f.isStatic() ) { CtClass type = null; type = f.getField().getType(); FSTClazzInfo.FSTFieldInfo fieldInfo = clInfo.getFieldInfo(f.getFieldName(), null); if ( fieldInfo == null ) { return; } if ( f.isReader() ) { structGen.defineStructReadAccess(f, type, fieldInfo); } else if ( f.isWriter() ) { structGen.defineStructWriteAccess(f, type, fieldInfo); } } } catch (Exception e) { e.printStackTrace(); } } });
final String body = "___bytes.putBool" + insert + "((long)" + off + "+___offset, $1 );"; if (trackChanges) { f.replace("{" + body + "if (tracker!=null) tracker.addChange("+off+"+___offset,1,"+ fieldName +");" + "}"); } else { f.replace(body); final String body = "___bytes.put"+insert+"("+off+"+___offset,$1);"; if (trackChanges) { f.replace("{" + body + "if (tracker!=null) tracker.addChange("+off+"+___offset,1,"+ fieldName +");" + "}"); } else { f.replace(body); final String body = "___bytes.putChar"+insert+"("+off+"+___offset,$1);"; if (trackChanges) { f.replace("{" + body + "if (tracker!=null) tracker.addChange("+off+"+___offset,2,"+ fieldName +");" + "}"); } else { f.replace(body); final String body = "___bytes.putShort"+insert+"("+off+"+___offset,$1);"; if (trackChanges) {
/** * Returns the class in which the field is declared. */ private CtClass getCtClass() throws NotFoundException { return thisClass.getClassPool().get(getClassName()); }
@Override public void edit(FieldAccess f) throws CannotCompileException { try { put(f.getField().getDeclaringClass().getName() + "." + f.getFieldName(), f.getLineNumber(), key); } catch (NotFoundException e) { throw new ReflectionsException("Could not find member " + f.getFieldName() + " in " + key, e); } } });
ConstPool constPool = getConstPool(); int pos = currentPos; int index = iterator.u16bitAt(pos + 1); CodeAttribute ca = iterator.get(); try { CtClass[] params; CtClass retType; CtClass fieldType = Descriptor.toCtClass(constPool.getFieldrefType(index), thisClass.getClassPool()); boolean read = isReader(); if (read) { params = new CtClass[0]; jc.recordParams(constPool.getFieldrefClassName(index), params, true, paramVar, withinStatic()); boolean included = checkResultValue(retType, statement); if (read) included = true; storeStack(params, isStatic(), paramVar, bytecode); jc.recordLocalVariables(ca, pos); bytecode.addLoad(retVar, retType); replace0(pos, bytecode, 3);
int pos = iterator.next(); int c = iterator.byteAt(pos); || c == Opcode.PUTFIELD || c == Opcode.PUTSTATIC) { expr = new FieldAccess(pos, iterator, clazz, minfo, c); edit((FieldAccess)expr); int index = iterator.u16bitAt(pos + 1); context.newList = new NewOp(context.newList, pos, minfo.getConstPool().getClassInfo(index)); && minfo.getConstPool().isConstructor(newList.type, iterator.u16bitAt(pos + 1)) > 0) { expr = new NewExpr(pos, iterator, clazz, minfo,
if (isAccessor(fieldAccess.getField())) { if (fieldAccess.getField().getDeclaringClass().equals(ctMethod.getDeclaringClass()) || ctMethod.getDeclaringClass().subclassOf(fieldAccess.getField().getDeclaringClass())) { if ((ctMethod.getName().startsWith("get") || ctMethod.getName().startsWith("set")) && ctMethod.getName().length() > 3) { propertyName = ctMethod.getName().substring(3); if (propertyName == null || !propertyName.equals(fieldAccess.getFieldName())) { String getSet = fieldAccess.getFieldName().substring(0,1).toUpperCase() + fieldAccess.getFieldName().substring(1); if (fieldAccess.isReader() && hasAnnotation(fieldAccess.getField(), GeneratedGetAccessor.class)) { fieldAccess.replace("$_ = $0.get" + getSet + "();"); } else if (fieldAccess.isWriter() && hasAnnotation(fieldAccess.getField(), GeneratedSetAccessor.class)) { fieldAccess.replace("$0.set" + getSet + "($1);");
if (isProperty(fieldAccess.getField())) { if (fieldAccess.getField().getDeclaringClass().equals(ctMethod.getDeclaringClass()) || ctMethod.getDeclaringClass().subclassOf(fieldAccess.getField().getDeclaringClass())) { if ((ctMethod.getName().startsWith("get") || (!isFinal(fieldAccess.getField()) && ctMethod.getName().startsWith("set"))) && ctMethod.getName().length() > 3) { propertyName = ctMethod.getName().substring(3); propertyName = propertyName.substring(0, 1).toLowerCase() + propertyName.substring(1); if (propertyName == null || !propertyName.equals(fieldAccess.getFieldName())) { String invocationPoint = ctClass.getName() + "." + ctMethod.getName() + ", line " + fieldAccess.getLineNumber(); if (fieldAccess.isReader()) { fieldAccess.replace("$_ = ($r)play.classloading.enhancers.PropertiesEnhancer.FieldAccessor.invokeReadProperty($0, \"" + fieldAccess.getFieldName() + "\", \"" + fieldAccess.getClassName() + "\", \"" + invocationPoint + "\");"); } else if (!isFinal(fieldAccess.getField()) && fieldAccess.isWriter()) { fieldAccess.replace("play.classloading.enhancers.PropertiesEnhancer.FieldAccessor.invokeWriteProperty($0, \"" + fieldAccess.getFieldName() + "\", " + fieldAccess.getField().getType().getName() + ".class, $1, \"" + fieldAccess.getClassName() + "\", \"" + invocationPoint + "\");");
public void edit(FieldAccess access) throws CannotCompileException { if (COLLECTIONS.equals(access.getClassName())) { if ("EMPTY_LIST".equals(access.getFieldName())) access.replace("$_ = " + COLLECTIONS + ".emptyList();"); else if ("EMPTY_SET".equals(access.getFieldName())) access.replace("$_ = " + COLLECTIONS + ".emptySet();"); else if ("EMPTY_MAP".equals(access.getFieldName())) access.replace("$_ = " + COLLECTIONS + ".emptyMap();"); } }
@Override public void edit(FieldAccess f) throws CannotCompileException { if (f.isWriter() && f.getClassName().equals("com.wurmonline.server.creatures.Communicator") && f.getFieldName().equals("commandMessage")) { StringBuffer code = new StringBuffer(); code.append("$proceed($$);\n"); code.append(String.format("if (%s#communicatorMessageHook(this, $1, title)) { return; };\n", ProxyServerHook.class.getName())); f.replace(code.toString()); } } });
public void edit(FieldAccess fieldAccess) throws CannotCompileException { if (!fieldAccess.getClassName().equals(clazz.getName())) return; if (!fieldAccess.getFieldName().equals(field.getName())) return; if (calledByInvocationClass(fieldAccess))return; if (fieldAccess.isReader() && doGet) { replaceRead(fieldAccess); } if (fieldAccess.isWriter() && doSet) { replaceWrite(fieldAccess); } }
ClassPool classPool = ClassPool.getDefault(); CtClass greetCtClass = classPool.get(Greet.class.getName()); greetCtClass.instrument(new ExprEditor() { @Override public void edit(FieldAccess fieldAccess) throws CannotCompileException { if (fieldAccess.getFieldName().equals("knowncount")) { fieldAccess .replace(" { System.out.println(\"A read operation on a field is encountered \"); $_ = $proceed($$); } "); } } }); greetCtClass .writeFile("<ROOT DIRECTORY WHERE THE CLASSES ARE>");
CtField field; try { field = f.getField(); } catch (NotFoundException e) { return; if (f.isReader()) { replacement += castAndReturn(reference.referenceMemberType, reference.reflectionField.getName() + ".get(" + (f.isStatic() ? "null" : "$0") + ")"); } else { replacement += reference.reflectionField.getName() + ".set(" + (f.isStatic() ? "null" : "$0") + ", ($w) $1);"; if (!f.isReader()) { throw new AssertionError("You are not allowed to write to the Reflection accessor field"); f.replace(replacement);
/** * Returns the field accessed by this expression. */ public CtField getField() throws NotFoundException { CtClass cc = getCtClass(); return cc.getField(getFieldName()); }
protected void replaceWrite(FieldAccess fieldAccess) throws CannotCompileException { String fieldWrite = fieldWrite(field.getName()); if (fieldAccess.isStatic()) { String code = " { " + " " + fieldWrite + "(null, $1);" + " } " + ""; fieldAccess.replace(code); } else { String code = " { " + " " + fieldWrite + "($0, $1);" + " } " + ""; fieldAccess.replace(code); } }
@Override public void edit(FieldAccess fieldAccess) throws CannotCompileException { try { if (isThreadedFieldAccess(fieldAccess.getField())) { if (fieldAccess.isReader()) { fieldAccess.replace("$_ = ($r)play.utils.Java.invokeStatic($type, \"current\");"); } } } catch (Exception e) { Logger.error(e, "Error in ControllersEnhancer. %s.%s has not been properly enhanced (fieldAccess %s).", applicationClass.name, ctMethod.getName(), fieldAccess); throw new UnexpectedException(e); } } });
/** * Returns true if the field is static. */ public boolean isStatic() { return isStatic(opcode); }
@Override public void edit(FieldAccess f) { try { if (f.isReader()) { CtField field = f.getField(); String name = field.getName(); String dname = field.getDeclaringClass() .getName(); Class<?> declared = cp.loadClass(dname); accessed.add(declared.getDeclaredField(name)); } } catch (RuntimeException exc) { throw exc; } catch (Exception exc) { logger.warn(exc.toString(), exc); } } });
@Override public void edit(FieldAccess f) { try { if (f.isWriter()) { CtField field = f.getField(); String name = field.getName(); String dname = field.getDeclaringClass() .getName(); Class<?> declared = cp.loadClass(dname); accessed.add(declared.getDeclaredField(name)); } } catch (RuntimeException exc) { throw exc; } catch (Exception exc) { logger.warn(exc.toString(), exc); } } });
public void replace(String statement) throws CannotCompileException { ConstPool constPool = getConstPool(); int pos = currentPos; int index = iterator.u16bitAt(pos + 1); CodeAttribute ca = iterator.get(); try { CtClass[] params; CtClass retType; CtClass fieldType = Descriptor.toCtClass(constPool.getFieldrefType(index), thisClass.getClassPool()); boolean read = isReader(); if (read) { params = new CtClass[0]; jc.recordParams(constPool.getFieldrefClassName(index), params, true, paramVar, withinStatic()); boolean included = checkResultValue(retType, statement); if (read) included = true; storeStack(params, isStatic(), paramVar, bytecode); jc.recordLocalVariables(ca, pos); replace0(pos, bytecode, 3);