Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<Field> listAnnotatedFields(Class<?> cls) {
        ArrayList<Class<?>> clsTree = new ArrayList<Class<?>>();
        boolean enteredDroidParts = false;
        do {
            clsTree.add(0, cls);
            boolean inDroidParts = cls.getName().startsWith("org.droidparts");
            if (enteredDroidParts && !inDroidParts) {
                break;
            } else {
                enteredDroidParts = inDroidParts;
                cls = cls.getSuperclass();
            }
        } while (cls != null);
        ArrayList<Field> fields = new ArrayList<Field>();
        for (Class<?> c : clsTree) {
            for (Field f : c.getDeclaredFields()) {
                if (f.getAnnotations().length > 0) {
                    fields.add(f);
                }
            }
        }
        return fields;
    }
}