Class JavaCodeSerializer

  • All Implemented Interfaces:
    Serializer

    public class JavaCodeSerializer
    extends java.lang.Object
    implements Serializer
    Serialization of Reflections to java code

    Serializes types and types elements into interfaces respectively to fully qualified name,

    For example, after saving with JavaCodeSerializer:

       reflections.save(filename, new JavaCodeSerializer());
     

    Saved file should look like:

         public interface MyModel {
          public interface my {
           public interface package1 {
            public interface MyClass1 {
             public interface fields {
              public interface f1 {}
              public interface f2 {}
             }
             public interface methods {
              public interface m1 {}
              public interface m2 {}
             }
            ...
     }
     

    Use the different resolve methods to resolve the serialized element into Class, Field or Method. for example:

      Class m1Ref = MyModel.my.package1.MyClass1.methods.m1.class;
      Method method = JavaCodeSerializer.resolve(m1Ref);
     

    The save(org.reflections.Reflections, String) method filename should be in the pattern: path/path/path/package.package.classname

    depends on Reflections configured with TypeElementsScanner

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.lang.String getNonDuplicateName​(java.lang.String candidate, java.util.List<java.lang.String> prev)  
      private java.lang.String getNonDuplicateName​(java.lang.String candidate, java.util.List<java.lang.String> prev, int offset)  
      private java.lang.String normalize​(java.lang.String candidate)  
      Reflections read​(java.io.InputStream inputStream)
      reads the input stream into a new Reflections instance, populating it's store
      static java.lang.annotation.Annotation resolveAnnotation​(java.lang.Class annotation)  
      static java.lang.Class<?> resolveClass​(java.lang.Class aClass)  
      static java.lang.Class<?> resolveClassOf​(java.lang.Class element)  
      static java.lang.reflect.Field resolveField​(java.lang.Class aField)  
      static java.lang.reflect.Method resolveMethod​(java.lang.Class aMethod)  
      java.io.File save​(Reflections reflections, java.lang.String name)
      name should be in the pattern: path/path/path/package.package.classname, for example
      java.lang.String toString​(Reflections reflections)
      returns a string serialization of the given Reflections instance
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JavaCodeSerializer

        public JavaCodeSerializer()
    • Method Detail

      • read

        public Reflections read​(java.io.InputStream inputStream)
        Description copied from interface: Serializer
        reads the input stream into a new Reflections instance, populating it's store
        Specified by:
        read in interface Serializer
      • save

        public java.io.File save​(Reflections reflections,
                                 java.lang.String name)
        name should be in the pattern: path/path/path/package.package.classname, for example
        /data/projects/my/src/main/java/org.my.project.MyStore
        would create class MyStore in package org.my.project in the path /data/projects/my/src/main/java
        Specified by:
        save in interface Serializer
      • toString

        public java.lang.String toString​(Reflections reflections)
        Description copied from interface: Serializer
        returns a string serialization of the given Reflections instance
        Specified by:
        toString in interface Serializer
      • getNonDuplicateName

        private java.lang.String getNonDuplicateName​(java.lang.String candidate,
                                                     java.util.List<java.lang.String> prev,
                                                     int offset)
      • normalize

        private java.lang.String normalize​(java.lang.String candidate)
      • getNonDuplicateName

        private java.lang.String getNonDuplicateName​(java.lang.String candidate,
                                                     java.util.List<java.lang.String> prev)
      • resolveClassOf

        public static java.lang.Class<?> resolveClassOf​(java.lang.Class element)
                                                 throws java.lang.ClassNotFoundException
        Throws:
        java.lang.ClassNotFoundException
      • resolveClass

        public static java.lang.Class<?> resolveClass​(java.lang.Class aClass)
      • resolveField

        public static java.lang.reflect.Field resolveField​(java.lang.Class aField)
      • resolveAnnotation

        public static java.lang.annotation.Annotation resolveAnnotation​(java.lang.Class annotation)
      • resolveMethod

        public static java.lang.reflect.Method resolveMethod​(java.lang.Class aMethod)