Search in sources :

Example 1 with FieldAccess

use of javassist.expr.FieldAccess in project reflections by ronmamo.

the class MemberUsageScanner method scanMember.

private void scanMember(CtBehavior member, List<Map.Entry<String, String>> entries) throws CannotCompileException {
    // key contains this$/val$ means local field/parameter closure
    final String key = member.getDeclaringClass().getName() + "." + member.getMethodInfo().getName() + "(" + parameterNames(member.getMethodInfo()) + // + " #" + member.getMethodInfo().getLineNumber(0)
    ")";
    member.instrument(new ExprEditor() {

        @Override
        public void edit(NewExpr e) {
            try {
                add(entries, e.getConstructor().getDeclaringClass().getName() + "." + "<init>" + "(" + parameterNames(e.getConstructor().getMethodInfo()) + ")", key + " #" + e.getLineNumber());
            } catch (NotFoundException e1) {
                throw new ReflectionsException("Could not find new instance usage in " + key, e1);
            }
        }

        @Override
        public void edit(MethodCall m) {
            try {
                add(entries, m.getMethod().getDeclaringClass().getName() + "." + m.getMethodName() + "(" + parameterNames(m.getMethod().getMethodInfo()) + ")", key + " #" + m.getLineNumber());
            } catch (NotFoundException e) {
                throw new ReflectionsException("Could not find member " + m.getClassName() + " in " + key, e);
            }
        }

        @Override
        public void edit(ConstructorCall c) {
            try {
                add(entries, c.getConstructor().getDeclaringClass().getName() + "." + "<init>" + "(" + parameterNames(c.getConstructor().getMethodInfo()) + ")", key + " #" + c.getLineNumber());
            } catch (NotFoundException e) {
                throw new ReflectionsException("Could not find member " + c.getClassName() + " in " + key, e);
            }
        }

        @Override
        public void edit(FieldAccess f) {
            try {
                add(entries, f.getField().getDeclaringClass().getName() + "." + f.getFieldName(), key + " #" + f.getLineNumber());
            } catch (NotFoundException e) {
                throw new ReflectionsException("Could not find member " + f.getFieldName() + " in " + key, e);
            }
        }
    });
}
Also used : ReflectionsException(org.reflections.ReflectionsException) ExprEditor(javassist.expr.ExprEditor) NewExpr(javassist.expr.NewExpr) NotFoundException(javassist.NotFoundException) ConstructorCall(javassist.expr.ConstructorCall) FieldAccess(javassist.expr.FieldAccess) MethodCall(javassist.expr.MethodCall)

Aggregations

NotFoundException (javassist.NotFoundException)1 ConstructorCall (javassist.expr.ConstructorCall)1 ExprEditor (javassist.expr.ExprEditor)1 FieldAccess (javassist.expr.FieldAccess)1 MethodCall (javassist.expr.MethodCall)1 NewExpr (javassist.expr.NewExpr)1 ReflectionsException (org.reflections.ReflectionsException)1