Java Code Examples for org.reflections.util.ClasspathHelper#forClass()

The following examples show how to use org.reflections.util.ClasspathHelper#forClass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModelInfoLookup.java    From archie with Apache License 2.0 5 votes vote down vote up
/**
 * Add all subtypes of the given class
 * @param baseClass
 */
protected void addSubtypesOf(Class baseClass) {
    Reflections reflections = new Reflections(ClasspathHelper.forClass(baseClass), new SubTypesScanner(false));
    Set<Class<?>> classes = reflections.getSubTypesOf(baseClass);

    System.out.println("type names size: " + classes.size());
    classes.forEach(this::addClass);
}
 
Example 2
Source File: FunctionalTypeTest.java    From FreeBuilder with Apache License 2.0 5 votes vote down vote up
private UnaryOperatorFinder() {
  Reflections reflections = new Reflections(
      "java.util.function", ClasspathHelper.forClass(UnaryOperator.class));
  unaryOperatorClasses = reflections
      .getTypesAnnotatedWith(FunctionalInterface.class)
      .stream()
      .flatMap(cls -> Arrays.stream(cls.getMethods()))
      .filter(method -> Modifier.isAbstract(method.getModifiers()))
      .filter(method -> method.getParameterTypes().length == 1)
      .filter(method -> method.getGenericParameterTypes()[0]
          .equals(method.getGenericReturnType()))
      .collect(toMap(
          method -> TypeToken.of(method.getGenericReturnType()),
          Method::getDeclaringClass));
}
 
Example 3
Source File: GUIWriter.java    From niftyeditor with Apache License 2.0 5 votes vote down vote up
public GUIWriter(GUI gui)throws JAXBException, ClassNotFoundException, IOException{
    this.gui = gui;
    Reflections reflections = new Reflections ("jada.ngeditor.model",ClasspathHelper.forClass(GElement.class), 
                         new SubTypesScanner(false), new TypeAnnotationsScanner());
    Set<Class<?>> setXmlRoot = reflections.getTypesAnnotatedWith(XmlRootElement.class);
    Class[] classes = setXmlRoot.toArray(new Class[0]);
    
    JAXBContext jc = JAXBContext.newInstance("jada.ngeditor.model:jada.ngeditor.model.elements:jada.ngeditor.model.elements.specials:jada.ngeditor.model.elements.effects",this.getClass().getClassLoader());       
   
    m = jc.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "https://raw.githubusercontent.com/void256/nifty-gui/1.4/nifty-core/src/main/resources/nifty.xsd https://raw.githubusercontent.com/void256/nifty-gui/1.4/nifty-core/src/main/resources/nifty.xsd");
}
 
Example 4
Source File: ClassUtils.java    From niftyeditor with Apache License 2.0 4 votes vote down vote up
public static  Set<Class<? extends GElement>> findAllGElements(){
     Reflections reflections = new Reflections ("jada.ngeditor.model",ClasspathHelper.forClass(GElement.class), 
    new SubTypesScanner(false));
        Set<Class<? extends GElement>> subTypesOf = reflections.getSubTypesOf(GElement.class);
        return subTypesOf;
}