Tabnine Logo
Generic
Code IndexAdd Tabnine to your IDE (free)

How to use
Generic
in
com.wizzardo.tools.reflection

Best Java code snippets using com.wizzardo.tools.reflection.Generic (Showing top 20 results out of 315)

origin: com.wizzardo.tools/tools-reflection

public G getType(String name) {
  return type(name);
}
origin: com.wizzardo.tools/tools-reflection

public static <T> Generic<T, Fields, Generic> of(Class<T> clazz) {
  return new Generic<T, Fields, Generic>(clazz);
}
origin: wizzardo/tools

public Fields(Class clazz, FieldMapper<T, Generic> mapper) {
  this(Generic.of(clazz), mapper);
}
origin: com.wizzardo.tools/tools-reflection

public Generic(Class<T> c, G... generics) {
  clazz = c;
  parent = null;
  if (generics == null)
    typeParameters = createArray(0);
  else
    typeParameters = generics;
  types = getTypes(c, typeParameters);
  Type[] interfaces = clazz.getGenericInterfaces();
  this.interfaces = createArray(interfaces.length);
  initInterfaces(this.interfaces, interfaces, types, new HashMap<Type, Generic<T, F, G>>());
}
origin: wizzardo/tools

public Generic(Class<T> c, G... generics) {
  init();
  clazz = c;
  parent = null;
  if (generics == null)
    typeParameters = createArray(0);
  else
    typeParameters = generics;
  types = getTypes(c, typeParameters);
  Type[] interfaces = clazz.getGenericInterfaces();
  this.interfaces = createArray(interfaces.length);
  initInterfaces(this.interfaces, interfaces, types, new HashMap<Type, Generic<T, F, G>>());
}
origin: wizzardo/tools

@Test
public void interfacesTest() {
  Generic generic = new Generic(String.class);
  Assert.assertEquals(String.class, generic.clazz);
  Assert.assertEquals(3, generic.interfaces.length);
  for (int i = 0; i < generic.interfaces.length; i++) {
    Generic g = generic.interfaces[i];
    if (g.clazz == Serializable.class)
      continue;
    if (g.clazz == CharSequence.class)
      continue;
    if (g.clazz == Comparable.class) {
      Assert.assertEquals(1, g.typesCount());
      Generic type = g.type(0);
      Assert.assertEquals(String.class, type.clazz);
      Assert.assertSame(generic.interfaces, type.interfaces);
      continue;
    }
    Assert.assertTrue(false);
  }
}
origin: wizzardo/tools

  @Test
  public void wildcardTypeTest() {
    Fields<FieldInfo> fields = new Fields<FieldInfo>(WildcardTypeTestPojo.class);
    Assert.assertEquals(2,fields.size());

    FieldInfo fieldInfo;
    fieldInfo = fields.get("superNumbers");
    Assert.assertEquals(List.class, fieldInfo.generic.clazz);
    Assert.assertEquals(1, fieldInfo.generic.typesCount());
    Assert.assertEquals(Number.class, fieldInfo.generic.type(0).clazz);
    Assert.assertEquals(0, fieldInfo.generic.type(0).typesCount());

    fieldInfo = fields.get("extendsNumbers");
    Assert.assertEquals(List.class, fieldInfo.generic.clazz);
    Assert.assertEquals(1, fieldInfo.generic.typesCount());
    Assert.assertEquals(Number.class, fieldInfo.generic.type(0).clazz);
    Assert.assertEquals(0, fieldInfo.generic.type(0).typesCount());
  }
}
origin: wizzardo/tools

@Test
public void interfacesTest_2() {
  Generic generic = new Generic(ChildInterface.class);
  Assert.assertEquals(ChildInterface.class, generic.clazz);
  Assert.assertEquals(1, generic.interfaces.length);
  Generic parent = generic.interfaces[0];
  Assert.assertEquals(ParentInterface.class, parent.clazz);
  Assert.assertEquals(String.class, parent.type(0).clazz);
  Assert.assertEquals(1, parent.interfaces.length);
  Generic supr = parent.interfaces[0];
  Assert.assertEquals(SuperInterface.class, supr.clazz);
  Assert.assertEquals(String.class, supr.type(0).clazz);
}
origin: com.wizzardo.tools/tools-reflection

protected void fillMethods(List<GenericMethod> methods, Generic generic) {
  Method[] declaredMethods = generic.clazz.getDeclaredMethods();
  for (Method method : declaredMethods) {
    Generic returnType = new Generic(method.getGenericReturnType(), generic.types);
    Type[] genericParameterTypes = method.getGenericParameterTypes();
    List<Generic> args = new ArrayList<Generic>(genericParameterTypes.length);
    for (Type genericParameterType : genericParameterTypes) {
      args.add(new Generic(genericParameterType, generic.types));
    }
    methods.add(new GenericMethod(method, returnType, Collections.unmodifiableList(args)));
  }
  for (Generic g : generic.interfaces) {
    fillMethods(methods, g);
  }
  if (generic.parent != null)
    fillMethods(methods, generic.parent);
}
origin: com.wizzardo.tools/tools-reflection

  this.typeParameters = createArray(args.length);
  for (int i = 0; i < args.length; i++) {
    this.typeParameters[i] = create(args[i], types, cyclicDependencies);
    this.types.put(variables[i].getName(), this.typeParameters[i]);
    parent = create(clazz.getGenericSuperclass(), this.types, cyclicDependencies);
  else
    parent = null;
    if (g == null) {
      Type type = variable.getBounds()[0];
      g = create(type, types, cyclicDependencies);
    clazz = (Class<T>) Object.class;
    parent = null;
    typeParameters = createArray(0);
  typeParameters = createArray(1);
  typeParameters[0] = create(((GenericArrayType) c).getGenericComponentType());
} else if (c instanceof WildcardType) {
  WildcardType wildcardType = (WildcardType) c;
  Type type = wildcardType.getLowerBounds().length > 0 ? wildcardType.getLowerBounds()[0] : wildcardType.getUpperBounds()[0];
  Generic<T, F, G> g = create(type);
  clazz = g.clazz;
  typeParameters = g.typeParameters;
  if (cl.isArray()) {
    clazz = (Class<T>) Array.class;
    typeParameters = createArray(1);
origin: wizzardo/tools

@Test
public void firstTest() throws NoSuchFieldException {
  Generic generic = new Generic(AnotherWrapper.class);
  Assert.assertEquals(AnotherWrapper.class.getSimpleName(), generic.toString());
  Assert.assertEquals(AnotherWrapper.class, generic.clazz);
  Assert.assertEquals(ListWrapper.class, generic.parent.clazz);
  Assert.assertEquals(Wrapper.class, generic.parent.parent.clazz);
  Assert.assertEquals(Object.class, generic.parent.parent.parent.clazz);
  Assert.assertEquals(null, generic.parent.parent.parent.parent);
  Generic type = generic.getGenericType(Wrapper.class.getDeclaredField("value"));
  Assert.assertEquals(List.class, type.clazz);
  Assert.assertEquals(Wrapper.class, type.typeParameters[0].clazz);
  Assert.assertEquals(String.class, type.typeParameters[0].typeParameters[0].clazz);
}
origin: wizzardo/tools

public int getTypesCount() {
  return typesCount();
}
origin: wizzardo/tools

@Test
public void thirdTest() throws NoSuchFieldException {
  Generic generic = new Generic(KeyValueStrings.class);
  Assert.assertEquals(KeyValueStrings.class, generic.clazz);
  Assert.assertEquals(KeyValueWrapper.class, generic.parent.clazz);
  Assert.assertEquals(KeyValue.class, generic.parent.parent.clazz);
  Assert.assertEquals(Object.class, generic.parent.parent.parent.clazz);
  Assert.assertEquals(null, generic.parent.parent.parent.parent);
  Generic type = generic.getGenericType(KeyValue.class.getDeclaredField("key"));
  Assert.assertEquals(String.class, type.clazz);
}
origin: wizzardo/tools

@Test
public void methodsTest() {
  Generic<ChildInterface, Fields, Generic> generic = Generic.of(ChildInterface.class);
  List<GenericMethod> methods = generic.methods();
  GenericMethod method = methods.get(0);
  Assert.assertEquals("get", method.method.getName());
  Assert.assertEquals(String.class, method.returnType.clazz);
  Assert.assertEquals(0, method.args.size());
}
origin: wizzardo/tools

@Test
public void fieldsTest() throws NoSuchFieldException {
  Generic generic = new Generic(ArrayHolder.class);
  Fields map = generic.getFields();
  Assert.assertEquals(2, map.size());
  Assert.assertTrue(map.containsKey("array"));
  Assert.assertTrue(map.containsKey("list"));
  Assert.assertTrue(map == generic.getFields());
}
origin: com.wizzardo.tools/tools-reflection

public List<GenericMethod> methods() {
  List<GenericMethod> methods = new ArrayList<GenericMethod>();
  fillMethods(methods, this);
  return methods;
}
origin: com.wizzardo.tools/tools-reflection

protected void initInterfaces(Generic[] result, Type[] interfaces, Map<String, G> types, Map<Type, Generic<T, F, G>> cyclicDependencies) {
  for (int i = 0; i < interfaces.length; i++) {
    result[i] = create(interfaces[i], types, cyclicDependencies);
  }
}
origin: wizzardo/tools

@Override
public JsonGeneric getGenericType(Field f) {
  return super.getGenericType(f);
}
origin: wizzardo/tools

public Generic(Class<T> c, Class... generics) {
  init();
  clazz = c;
  parent = null;
  if (generics == null) {
    typeParameters = createArray(0);
  } else {
    typeParameters = createArray(generics.length);
    for (int i = 0; i < generics.length; i++) {
      typeParameters[i] = create(generics[i]);
    }
  }
  types = getTypes(c, typeParameters);
  Type[] interfaces = clazz.getGenericInterfaces();
  this.interfaces = createArray(interfaces.length);
  initInterfaces(this.interfaces, interfaces, types, new HashMap<Type, Generic<T, F, G>>());
}
origin: wizzardo/tools

protected void fillMethods(List<GenericMethod> methods, Generic generic) {
  Method[] declaredMethods = generic.clazz.getDeclaredMethods();
  for (Method method : declaredMethods) {
    Generic returnType = new Generic(method.getGenericReturnType(), generic.types);
    Type[] genericParameterTypes = method.getGenericParameterTypes();
    List<Generic> args = new ArrayList<Generic>(genericParameterTypes.length);
    for (Type genericParameterType : genericParameterTypes) {
      args.add(new Generic(genericParameterType, generic.types));
    }
    methods.add(new GenericMethod(method, returnType, Collections.unmodifiableList(args)));
  }
  for (Generic g : generic.interfaces) {
    fillMethods(methods, g);
  }
  if (generic.parent != null)
    fillMethods(methods, generic.parent);
}
com.wizzardo.tools.reflectionGeneric

Most used methods

  • type
  • <init>
  • of
  • typesCount
  • create
  • createArray
  • fillMethods
  • getGenericType
  • getTypes
  • initInterfaces
  • types
  • getFields
  • types,
  • getFields,
  • init,
  • methods,
  • parent,
  • toString

Popular in Java

  • Reading from database using SQL prepared statement
  • runOnUiThread (Activity)
  • getSharedPreferences (Context)
  • startActivity (Activity)
  • ObjectMapper (com.fasterxml.jackson.databind)
    ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Pl
  • BufferedImage (java.awt.image)
    The BufferedImage subclass describes an java.awt.Image with an accessible buffer of image data. All
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • Pattern (java.util.regex)
    Patterns are compiled regular expressions. In many cases, convenience methods such as String#matches
  • Top PhpStorm plugins
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