Android Open Source - morpheus Nullable Utils






From Project

Back to project page morpheus.

License

The source code is released under:

Apache License

If you think the Android project morpheus listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.github.stephanenicolas.morpheus.commons;
/*from  w w  w. j a  v a2s.c  om*/
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import javassist.CtField;
import javassist.NotFoundException;

public final class NullableUtils {
  private NullableUtils() {
  }

  public static boolean isNotNullable(CtField field) {
    return !isNullable(field);
  }

  public static boolean isNullable(CtField field) {
    try {
      for (Object annotation : field.getAnnotations()) {

        Class annotationClass = Annotation.class;

        //workaround for robolectric
        //https://github.com/robolectric/robolectric/pull/1240
        Method method = annotationClass.getMethod("annotationType");
        Class type = (Class) method.invoke(annotation);
        if ("Nullable".equals(type.getSimpleName())) return true;
      }
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    return false;
  }
}




Java Source Code List

com.example.morpheus.MainActivity.java
com.github.stephanenicolas.morpheus.commons.CtClassFilter.java
com.github.stephanenicolas.morpheus.commons.JavassistUtils.java
com.github.stephanenicolas.morpheus.commons.NullableUtils.java