Example usage for com.google.gwt.core.ext.typeinfo JClassType findField

List of usage examples for com.google.gwt.core.ext.typeinfo JClassType findField

Introduction

In this page you can find the example usage for com.google.gwt.core.ext.typeinfo JClassType findField.

Prototype

JField findField(String name);

Source Link

Usage

From source file:com.gwtent.gen.GenUtils.java

License:Apache License

/**
 * Find a field, if not found in current classtype, then search it in supper classs
 * @param classType/*from w  w  w  .  jav  a2  s  . c om*/
 * @param fieldName
 * @return
 */
public static JField findField(JClassType classType, String fieldName) {
    JField result = null;
    JClassType parent = classType;
    while (parent != null) {
        result = parent.findField(fieldName);
        if (result != null)
            return result;

        parent = parent.getSuperclass();
    }

    return null;
}

From source file:com.sencha.gxt.data.rebind.ValueProviderCreator.java

License:sencha.com license

private JField getField(JClassType type, String p) {
    for (JClassType superType : type.getFlattenedSupertypeHierarchy()) {
        JField field = superType.findField(p);
        if (field != null && field.isPublic()) {
            return field;
        }//  w w  w  . j  a  v  a 2 s.co  m
    }
    return null;
}

From source file:de.knightsoftnet.validators.rebind.GwtSpecificValidatorCreator.java

License:Apache License

private boolean isPropertyConstrained(final PropertyDescriptor ppropertyDescription, final boolean useField) {
    // cascaded counts as constrained
    // we must know if the @Valid annotation is on a field or a getter
    final JClassType jClass = this.beanHelper.getJClass();
    if (useField && jClass.findField(ppropertyDescription.getPropertyName()).isAnnotationPresent(Valid.class)) {
        return true;
    } else if (!useField
            && jClass.findMethod(asGetter(ppropertyDescription), NO_ARGS).isAnnotationPresent(Valid.class)) {
        return true;
    }/*from   w  w  w .  ja  va2  s. co  m*/
    // for non-cascaded properties
    for (final ConstraintDescriptor<?> constraint : ppropertyDescription.getConstraintDescriptors()) {
        final org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl<?> constraintHibernate = (org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl<?>) constraint;
        if (constraintHibernate.getElementType() == (useField ? ElementType.FIELD : ElementType.METHOD)) {
            return true;
        }
    }
    return false;
}

From source file:fr.onevu.gwt.uibinder.rebind.UiBinderParser.java

License:Apache License

private void createSingleImport(XMLElement elem, JClassType enclosingType, String rawFieldName,
        String constantName) throws UnableToCompleteException {
    JField field = enclosingType.findField(constantName);
    if (field == null) {
        writer.die(elem, "Unable to locate a field named %s in %s", constantName,
                enclosingType.getQualifiedSourceName());
    } else if (!field.isStatic()) {
        writer.die(elem, "Field %s in type %s is not static", constantName,
                enclosingType.getQualifiedSourceName());
    }/*ww w. j a v  a  2 s  .  c o m*/

    JType importType = field.getType();
    JClassType fieldType;
    if (importType instanceof JPrimitiveType) {
        fieldType = oracle.findType(((JPrimitiveType) importType).getQualifiedBoxedSourceName());
    } else {
        fieldType = (JClassType) importType;
    }

    FieldWriter fieldWriter = fieldManager.registerField(fieldType, constantName);
    fieldWriter.setInitializer(rawFieldName);
}

From source file:org.cruxframework.crux.core.utils.JClassUtils.java

License:Apache License

/**
 * Retrieve a field from class. Searches also into the class hierarchy 
 * @param clazz class to search the field
 * @param fieldName field name/*from  w w  w  .j a v  a 2s  . c  om*/
 * @return the field
 */
public static JField getField(JClassType clazz, String fieldName) {
    JField field = null;
    JClassType superClass = clazz;
    while (field == null && superClass != null) {
        field = superClass.findField(fieldName);
        superClass = superClass.getSuperclass();
    }
    return field;
}

From source file:org.jboss.errai.codegen.meta.impl.gwt.GWTClass.java

License:Apache License

@Override
public MetaField getField(final String name) {
    JClassType type = getEnclosedMetaObject().isClassOrInterface();
    if (type == null) {
        if ("length".equals(name) && getEnclosedMetaObject().isArray() != null) {
            return new MetaField.ArrayLengthMetaField(this);
        }//from ww  w.  j  av  a  2s .  co m
        return null;
    }

    JField field = type.findField(name);
    while ((field == null || (field != null && !field.isPublic())) && (type = type.getSuperclass()) != null
            && !type.getQualifiedSourceName().equals("java.lang.Object")) {
        field = type.findField(name);

        for (final JClassType interfaceType : type.getImplementedInterfaces()) {
            field = interfaceType.findField(name);
        }
    }

    if (field == null) {
        throw new RuntimeException("no such field: " + name + " in class: " + this);
    }

    return new GWTField(oracle, field);
}

From source file:org.jboss.errai.codegen.meta.impl.gwt.GWTClass.java

License:Apache License

@Override
public MetaField getDeclaredField(final String name) {
    JClassType type = getEnclosedMetaObject().isClassOrInterface();
    if (type == null) {
        if ("length".equals(name) && getEnclosedMetaObject().isArray() != null) {
            return new MetaField.ArrayLengthMetaField(this);
        }// w w w . j  a va 2s.c om
        return null;
    }

    JField field = type.findField(name);

    if (field == null) {
        return null;
    }

    return new GWTField(oracle, field);
}