0

I'm debugging a project with many classes and forms and would be very useful for me to find all the public variables used in the project. Is there any way to do this in Netbeans? Neither I have been able to find a pluging for Netbeans to achieve this.

Thanks a lot.

taringamberini
  • 2,719
  • 21
  • 29
fpinero
  • 5
  • 2

1 Answers1

1

It should be possible with http://code.google.com/p/reflections/

import static org.reflections.ReflectionUtils.getAllFields;
import static org.reflections.ReflectionUtils.withModifier;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.LinkedHashSet;
import java.util.Set;

import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner;
import org.reflections.util.ClasspathHelper;

public class PublicFieldsReflectionsTest
{
    public static void main(String[] args)
    {
        Reflections reflections = new Reflections(
            "de.your.project.prefix",
            ClasspathHelper.forClass(Object.class), 
            new SubTypesScanner(false));
        Set<Class<?>> allClasses = reflections.getSubTypesOf(Object.class);
        Set<Field> allPublicFields = new LinkedHashSet<Field>();
        for (Class<?> c : allClasses)
        {
            //System.out.println("Class "+c);
            allPublicFields.addAll(getAllFields(c, withModifier(Modifier.PUBLIC)));
        }
        for (Field field : allPublicFields)
        {
            System.out.println(field);
        }
    }
}
Marco13
  • 53,703
  • 9
  • 80
  • 159