Tabnine Logo
Class.getFields
Code IndexAdd Tabnine to your IDE (free)

How to use
getFields
method
in
java.lang.Class

Best Java code snippets using java.lang.Class.getFields (Showing top 20 results out of 34,974)

origin: spring-projects/spring-framework

private static void ensureSpringRulesAreNotPresent(Class<?> testClass) {
  for (Field field : testClass.getFields()) {
    Assert.state(!SpringClassRule.class.isAssignableFrom(field.getType()), () -> String.format(
        "Detected SpringClassRule field in test class [%s], " +
        "but SpringClassRule cannot be used with the SpringJUnit4ClassRunner.", testClass.getName()));
    Assert.state(!SpringMethodRule.class.isAssignableFrom(field.getType()), () -> String.format(
        "Detected SpringMethodRule field in test class [%s], " +
        "but SpringMethodRule cannot be used with the SpringJUnit4ClassRunner.", testClass.getName()));
  }
}
origin: skylot/jadx

private void readAndroidRStyleClass() {
  try {
    Class<?> rStyleCls = Class.forName(ANDROID_R_STYLE_CLS);
    for (Field f : rStyleCls.getFields()) {
      styleMap.put(f.getInt(f.getType()), f.getName());
    }
  } catch (Exception th) {
    LOG.error("Android R class loading failed", th);
  }
}
origin: spring-projects/spring-loaded

public static List<Field> callGetFields(Class thiz)
throws SecurityException
{
  return Arrays.asList(thiz.getFields());
}
origin: stackoverflow.com

 public void listRaw(){
  Field[] fields=R.raw.class.getFields();
  for(int count=0; count < fields.length; count++){
    Log.i("Raw Asset: ", fields[count].getName());
  }
}
origin: stanfordnlp/CoreNLP

/**
 * Go through all of the paths via reflection, and print them out in a TSV format.
 * This is useful for command line scripts.
 *
 * @param args Ignored.
 */
public static void main(String[] args) throws IllegalAccessException {
 for (Field field : DefaultPaths.class.getFields()) {
  System.out.println(field.getName() + "\t" + field.get(null));
 }
}

origin: stanfordnlp/CoreNLP

/**
 * Go through all of the paths via reflection, and print them out in a TSV format.
 * This is useful for command line scripts.
 *
 * @param args Ignored.
 */
public static void main(String[] args) throws IllegalAccessException {
 for (Field field : LanguageInfo.class.getFields()) {
  System.out.println(field.getName() + "\t" + field.get(null));
 }
}
origin: apache/flink

private int countFieldsInClass(Class<?> clazz) {
  int fieldCount = 0;
  for(Field field : clazz.getFields()) { // get all fields
    if(	!Modifier.isStatic(field.getModifiers()) &&
      !Modifier.isTransient(field.getModifiers())
      ) {
      fieldCount++;
    }
  }
  return fieldCount;
}
origin: libgdx/libgdx

/** Returns an array of {@link Field} containing the public fields of the class represented by the supplied Class. */
static public Field[] getFields (Class c) {
  java.lang.reflect.Field[] fields = c.getFields();
  Field[] result = new Field[fields.length];
  for (int i = 0, j = fields.length; i < j; i++) {
    result[i] = new Field(fields[i]);
  }
  return result;
}
origin: libgdx/libgdx

/** Returns an array of {@link Field} containing the public fields of the class represented by the supplied Class. */
static public Field[] getFields (Class c) {
  java.lang.reflect.Field[] fields = c.getFields();
  Field[] result = new Field[fields.length];
  for (int i = 0, j = fields.length; i < j; i++) {
    result[i] = new Field(fields[i]);
  }
  return result;
}
origin: stackoverflow.com

 for (Field f: MyClass.class.getFields()) {
  Column column = f.getAnnotation(Column.class);
  if (column != null)
    System.out.println(column.columnName());
}
origin: pxb1988/dex2jar

public static void main(String... strings) throws IllegalArgumentException, IllegalAccessException {
  for (Field f : SectionItem.class.getFields()) {
    if (f.getType().equals(int.class)) {
      if (0 != (f.getModifiers() & Modifier.STATIC)) {
        System.out.printf("%s(0x%04x,0,0),//\n", f.getName(), f.get(null));
      }
    }
  }
}
origin: apache/storm

private static String getSqlTypeName(int sqlType) {
  try {
    Integer val = new Integer(sqlType);
    for (Field field : Types.class.getFields()) {
      if (val.equals(field.get(null))) {
        return field.getName();
      }
    }
  } catch (IllegalAccessException e) {
    throw new RuntimeException("Could not get sqlTypeName ", e);
  }
  throw new RuntimeException("Unknown sqlType " + sqlType);
}
origin: jenkinsci/jenkins

/**
 * Given the class, list up its {@link PropertyType}s from its public fields/getters.
 */
private Map<String, PropertyType> buildPropertyTypes(Class<?> clazz) {
  Map<String, PropertyType> r = new HashMap<String, PropertyType>();
  for (Field f : clazz.getFields())
    r.put(f.getName(),new PropertyType(f));
  for (Method m : clazz.getMethods())
    if(m.getName().startsWith("get"))
      r.put(Introspector.decapitalize(m.getName().substring(3)),new PropertyType(m));
  return r;
}
origin: spring-projects/spring-framework

/**
 * Create a new Constants converter class wrapping the given class.
 * <p>All <b>public</b> static final variables will be exposed, whatever their type.
 * @param clazz the class to analyze
 * @throws IllegalArgumentException if the supplied {@code clazz} is {@code null}
 */
public Constants(Class<?> clazz) {
  Assert.notNull(clazz, "Class must not be null");
  this.className = clazz.getName();
  Field[] fields = clazz.getFields();
  for (Field field : fields) {
    if (ReflectionUtils.isPublicStaticFinal(field)) {
      String name = field.getName();
      try {
        Object value = field.get(null);
        this.fieldCache.put(name, value);
      }
      catch (IllegalAccessException ex) {
        // just leave this field and continue
      }
    }
  }
}
origin: apache/incubator-dubbo

private static Field getField(Class<?> cls, String fieldName) {
  Field result = null;
  if (CLASS_FIELD_CACHE.containsKey(cls) && CLASS_FIELD_CACHE.get(cls).containsKey(fieldName)) {
    return CLASS_FIELD_CACHE.get(cls).get(fieldName);
  }
  try {
    result = cls.getDeclaredField(fieldName);
    result.setAccessible(true);
  } catch (NoSuchFieldException e) {
    for (Field field : cls.getFields()) {
      if (fieldName.equals(field.getName()) && ReflectUtils.isPublicInstanceField(field)) {
        result = field;
        break;
      }
    }
  }
  if (result != null) {
    ConcurrentMap<String, Field> fields = CLASS_FIELD_CACHE.get(cls);
    if (fields == null) {
      fields = new ConcurrentHashMap<String, Field>();
      CLASS_FIELD_CACHE.putIfAbsent(cls, fields);
    }
    fields = CLASS_FIELD_CACHE.get(cls);
    fields.putIfAbsent(fieldName, result);
  }
  return result;
}
origin: apache/incubator-dubbo

private static Field getField(Class<?> cls, String fieldName) {
  Field result = null;
  if (CLASS_FIELD_CACHE.containsKey(cls) && CLASS_FIELD_CACHE.get(cls).containsKey(fieldName)) {
    return CLASS_FIELD_CACHE.get(cls).get(fieldName);
  }
  try {
    result = cls.getDeclaredField(fieldName);
    result.setAccessible(true);
  } catch (NoSuchFieldException e) {
    for (Field field : cls.getFields()) {
      if (fieldName.equals(field.getName()) && ReflectUtils.isPublicInstanceField(field)) {
        result = field;
        break;
      }
    }
  }
  if (result != null) {
    ConcurrentMap<String, Field> fields = CLASS_FIELD_CACHE.get(cls);
    if (fields == null) {
      fields = new ConcurrentHashMap<String, Field>();
      CLASS_FIELD_CACHE.putIfAbsent(cls, fields);
    }
    fields = CLASS_FIELD_CACHE.get(cls);
    fields.putIfAbsent(fieldName, result);
  }
  return result;
}
origin: spring-projects/spring-framework

/**
 * Find a field of a certain name on a specified class.
 */
@Nullable
protected Field findField(String name, Class<?> clazz, boolean mustBeStatic) {
  Field[] fields = clazz.getFields();
  for (Field field : fields) {
    if (field.getName().equals(name) && (!mustBeStatic || Modifier.isStatic(field.getModifiers()))) {
      return field;
    }
  }
  // We'll search superclasses and implemented interfaces explicitly,
  // although it shouldn't be necessary - however, see SPR-10125.
  if (clazz.getSuperclass() != null) {
    Field field = findField(name, clazz.getSuperclass(), mustBeStatic);
    if (field != null) {
      return field;
    }
  }
  for (Class<?> implementedInterface : clazz.getInterfaces()) {
    Field field = findField(name, implementedInterface, mustBeStatic);
    if (field != null) {
      return field;
    }
  }
  return null;
}
origin: jfinal/jfinal

public FieldGetter takeOver(Class<?> targetClass, String fieldName) {
  java.lang.reflect.Field[] fieldArray = targetClass.getFields();
  for (java.lang.reflect.Field field : fieldArray) {
    if (field.getName().equals(fieldName)) {
      return new RealFieldGetter(field);
    }
  }
  
  return null;
}
 
origin: apache/flink

static List<OptionWithMetaInfo> extractConfigOptions(Class<?> clazz) {
  try {
    List<OptionWithMetaInfo> configOptions = new ArrayList<>(8);
    Field[] fields = clazz.getFields();
    for (Field field : fields) {
      if (isConfigOption(field) && shouldBeDocumented(field)) {
        configOptions.add(new OptionWithMetaInfo((ConfigOption<?>) field.get(null), field));
      }
    }
    return configOptions;
  } catch (Exception e) {
    throw new RuntimeException("Failed to extract config options from class " + clazz + '.', e);
  }
}
origin: jenkinsci/jenkins

private ParsedQuickSilver(Class<? extends SearchableModelObject> clazz) {
  QuickSilver qs;
  for (Method m : clazz.getMethods()) {
    qs = m.getAnnotation(QuickSilver.class);
    if(qs!=null) {
      String url = stripGetPrefix(m);
      if(qs.value().length==0)
        getters.add(new MethodGetter(url,splitName(url),m));
      else {
        for (String name : qs.value())
          getters.add(new MethodGetter(url,name,m));
      }
    }
  }
  for (Field f : clazz.getFields()) {
    qs = f.getAnnotation(QuickSilver.class);
    if(qs!=null) {
      if(qs.value().length==0)
        getters.add(new FieldGetter(f.getName(),splitName(f.getName()),f));
      else {
        for (String name : qs.value())
          getters.add(new FieldGetter(f.getName(),name,f));
      }
    }
  }
}
java.langClassgetFields

Javadoc

Returns an array containing Field objects for all public fields for the class C represented by this Class. Fields may be declared in C, the interfaces it implements or in the superclasses of C. The elements in the returned array are in no particular order.

If there are no public fields or if this class represents an array class, a primitive type or void then an empty array is returned.

Popular methods of Class

  • getName
    Returns the name of the class represented by this Class. For a description of the format which is us
  • getSimpleName
  • getClassLoader
  • isAssignableFrom
    Determines if the class or interface represented by this Class object is either the same as, or is a
  • forName
    Returns the Class object associated with the class or interface with the given string name, using th
  • newInstance
    Returns a new instance of the class represented by this Class, created by invoking the default (that
  • getMethod
    Returns a Method object that reflects the specified public member method of the class or interface r
  • getResourceAsStream
    Finds a resource with a given name. The rules for searching resources associated with a given class
  • getSuperclass
    Returns the Class representing the superclass of the entity (class, interface, primitive type or voi
  • getConstructor
  • cast
    Casts an object to the class or interface represented by this Class object.
  • isInstance
  • cast,
  • isInstance,
  • getCanonicalName,
  • getDeclaredField,
  • isArray,
  • getAnnotation,
  • getDeclaredFields,
  • getResource,
  • getDeclaredMethod,
  • getMethods

Popular in Java

  • Making http post requests using okhttp
  • scheduleAtFixedRate (Timer)
  • notifyDataSetChanged (ArrayAdapter)
  • getSharedPreferences (Context)
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • Socket (java.net)
    Provides a client-side TCP socket.
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • JFileChooser (javax.swing)
  • Loader (org.hibernate.loader)
    Abstract superclass of object loading (and querying) strategies. This class implements useful common
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now