Package java.lang.reflect

Examples of java.lang.reflect.Field$FieldData


        runProcessor(visitor);
    }

    public void testVisitField() throws Exception {

        Field expectedField = AnnotatedGreeterImpl.class.getDeclaredField("foo");

        expectedAnnotations.add(Resource.class);
        prepareCommonExpectations(visitor);
        visitor.visitField(EasyMock.eq(expectedField),
                           (Annotation)EasyMock.isA(Resource.class));
View Full Code Here


       
    }

    public void testVisitMethod() throws Exception {

        Field expectedField = AnnotatedGreeterImpl.class.getDeclaredField("foo");
        Method expectedMethod1 = AnnotatedGreeterImpl.class.getDeclaredMethod("sayHi");
        Method expectedMethod2 = AnnotatedGreeterImpl.class.getDeclaredMethod("sayHi", String.class);
        Method expectedMethod3 = AnnotatedGreeterImpl.class.getDeclaredMethod("greetMe", String.class);
        Method expectedMethod4 =
            AnnotatedGreeterImpl.class.getDeclaredMethod("setContext", WebServiceContext.class);
View Full Code Here

                    if (fields != null)
                    {
                        final int numberOfFields = fields.length;
                        for (int ctr = 0; ctr < numberOfFields; ctr++)
                        {
                            final Field field = fields[ctr];
                            final Object value = field.get(this);
                            if (value != null)
                            {
                                this.properties.put(
                                    field.getName(),
                                    value);
                            }
                        }
                    }
View Full Code Here

        throws NoSuchFieldException, SecurityException {
  // be very careful not to change the stack depth of this
  // checkMemberAccess call for security reasons
  // see java.lang.SecurityManager.checkMemberAccess
        checkMemberAccess(Member.PUBLIC, ClassLoader.getCallerClassLoader());
        Field field = getField0(name);
        if (field == null) {
            throw new NoSuchFieldException(name);
        }
        return field;
    }
View Full Code Here

        throws NoSuchFieldException, SecurityException {
  // be very careful not to change the stack depth of this
  // checkMemberAccess call for security reasons
  // see java.lang.SecurityManager.checkMemberAccess
        checkMemberAccess(Member.DECLARED, ClassLoader.getCallerClassLoader());
        Field field = searchFields(privateGetDeclaredFields(false), name);
        if (field == null) {
            throw new NoSuchFieldException(name);
        }
        return field;
    }
View Full Code Here

        // privateGetPublicFields(). It fetches only the declared
        // public fields for each class, however, to reduce the number
        // of Field objects which have to be created for the common
        // case where the field being requested is declared in the
        // class which is being queried.
        Field res = null;
        // Search declared public fields
        if ((res = searchFields(privateGetDeclaredFields(true), name)) != null) {
            return res;
        }
        // Direct superinterfaces, recursively
View Full Code Here

            final Object instance, final Object value) throws ArchiveInjectionException {

        // Value is obtained, set it
        // Get Field from the class
        JField jField = fieldMetadata.getJField();
        Field field = null;
        try {
            field = clazz.getDeclaredField(jField.getName());
        } catch (NoSuchFieldException e) {
            throw new ArchiveInjectionException("Cannot get field '" + jField + "' on the class '" + clazz.getName() + "'", e);
        }

        // if instance is null, we're using static injection.
        // But check that in this case, the field is a static field !
        int modifier = field.getModifiers();
        if (!Modifier.isStatic(modifier)) {
            logger.error("The field ''{0}'' of the class ''{1}'' is not a static field and as the injection is being done in a static way, this field won't be defined !",
                            field, clazz);
            return;
        }


        boolean accessible = field.isAccessible();
        try {
            // needs to be allowed to change value of the field
            field.setAccessible(true);

            // Set value
            try {
                field.set(instance, value);
            } catch (IllegalAccessException e) {
                throw new ArchiveInjectionException("Cannot set given value on the field '" + jField + "'.", e);
            }
        } finally {
            // set back accessible attribute
            field.setAccessible(accessible);
        }

    }
View Full Code Here

        Class c = (Class)oldInstance;
        // As of 1.3 it is not possible to call Class.forName("int"),
        // so we have to generate different code for primitive types.
        // This is needed for arrays whose subtype may be primitive.
        if (c.isPrimitive()) {
            Field field = null;
      try {
    field = ReflectionUtils.typeToClass(c).getDeclaredField("TYPE");
      } catch (NoSuchFieldException ex) {
                System.err.println("Unknown primitive type: " + c);
            }
View Full Code Here

}

// Fields
class java_lang_reflect_Field_PersistenceDelegate extends PersistenceDelegate {
    protected Expression instantiate(Object oldInstance, Encoder out) {
        Field f = (Field)oldInstance;
        return new Expression(oldInstance,
                f.getDeclaringClass(),
                "getField",
                new Object[]{f.getName()});
    }
View Full Code Here

    }
}

class StaticFieldsPersistenceDelegate extends PersistenceDelegate {
    protected void installFields(Encoder out, Class<?> cls) {
        Field fields[] = cls.getFields();
        for(int i = 0; i < fields.length; i++) {
            Field field = fields[i];
            // Don't install primitives, their identity will not be preserved
            // by wrapping.
            if (Object.class.isAssignableFrom(field.getType())) {
                out.writeExpression(new Expression(field, "get", new Object[]{null}));
            }
        }
    }
View Full Code Here

TOP

Related Classes of java.lang.reflect.Field$FieldData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.