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

How to use
Reflections
in
com.palantir.ptoss.util

Best Java code snippets using com.palantir.ptoss.util.Reflections (Showing top 14 results out of 315)

origin: palantir/Cinch

  public void visit(Class<?> c) {
    annotatedFields.addAll(getAnnotatedFields(c, annotation));
  }
});
origin: palantir/Cinch

private List<Field> getBindableModelFields() {
  List<Field> allModelFields = Reflections.getFieldsOfTypeForClassHierarchy(object.getClass(), BindableModel.class);
  List<Field> notBindableFields = Reflections.getAnnotatedFieldsForClassHierarchy(object.getClass(), NotBindable.class);
  allModelFields = ImmutableList.copyOf(Iterables.filter(allModelFields, Predicates.not(Predicates.in(notBindableFields))));
  List<Field> nonFinalModelFields = ImmutableList.copyOf(Iterables.filter(allModelFields, Predicates.not(Reflections.IS_FIELD_FINAL)));
  if (!nonFinalModelFields.isEmpty()) {
    throw new BindingException("All BindableModels have to be final or marked with @NotBindable, but "+
      Iterables.transform(nonFinalModelFields, Reflections.FIELD_TO_NAME)+" are not.");
  }
  return allModelFields;
}
origin: palantir/Cinch

/**
 * Returns the value of the specified Field on the object bound by this {@link BindingContext}
 *
 * @param field {@link Field} to pull the value from
 * @param klass return type of value in the {@link Field}
 * @return value of type <code>klass</code> from field <code>field</code> on bound object.
 * @throws IllegalArgumentException if the passed {@link Field} is not a field on the object
 * bound by this {@link BindingContext}
 */
public <T> T getFieldObject(Field field, Class<T> klass) throws IllegalArgumentException {
  return Reflections.getFieldObject(object, field, klass);
}
origin: palantir/Cinch

/**
 * Resolves a string reference, as specified in the <code>on</code> parameter of
 * a {@link Bound} annotation to an Enum object in this runtime.
 * @param on <code>on</code> parameter from a {@link Bound} annotation.
 * @param model
 * @return the resolved object
 * @throws IllegalArgumentException if the referenced object can't be found.
 */
public static ModelUpdate findOnObject(final String on, final BindableModel model) {
  ModelUpdate onObject = null;
  if (!isNullOrBlank(on)) {
    final List<Class<?>> updateClasses = findModelUpdateClass(model);
    for (Class<?> updateClass : updateClasses) {
      try {
        onObject = (ModelUpdate)Reflections.evalEnum(updateClass, on);
        return onObject;
      } catch (IllegalArgumentException e) {
        // swallow this if we don't find the enum on one of the
        // classes, continue to next class.
      }
    }
    throw new IllegalArgumentException("could not find \"on\" parameter " + on);
  }
  return onObject;
}
origin: palantir/Cinch

private Map<String, ObjectFieldMethod> indexBindableMethods() throws IllegalArgumentException {
  // Get all fields marked @Bindable
  List<Field> bindables = getAnnotatedFields(Bindable.class);
  if (Iterables.any(bindables, Predicates.not(Reflections.IS_FIELD_FINAL))) {
    throw new BindingException("all @Bindables have to be final");
  }
  // Add all BindableModels
  bindables.addAll(getBindableModelFields());
  // Index those methods.
  List<ObjectFieldMethod> methods = getParameterlessMethodsOnFieldTypes(object, bindables);
  // Add methods for classes marked @Bindable
  if (Reflections.isClassAnnotatedForClassHierarchy(object, Bindable.class)) {
    methods.addAll(Reflections.getParameterlessMethodsForClassHierarchy(object));
  }
  return indexMethods(methods);
}
origin: palantir/Cinch

  public void visit(Class<?> c) {
    fields.addAll(getFieldsOfType(c, targetClass));
  }
});
origin: palantir/Cinch

  public void visit(Class<?> c) {
    classes.addAll(getTypesOfType(c, targetClass));
  }
});
origin: palantir/Cinch

public List<Field> getAnnotatedFields(Class<? extends Annotation> klass) {
  return Reflections.getAnnotatedFieldsForClassHierarchy(object.getClass(), klass);
}
origin: palantir/Cinch

public List<ObjectFieldMethod> getAnnotatedParameterlessMethods(final Class<? extends Annotation> annotation) {
  return Lists.newArrayList(Iterables.filter(Reflections.getParameterlessMethodsForClassHierarchy(object),
      new Predicate<ObjectFieldMethod>() {
        public boolean apply(ObjectFieldMethod input) {
          return input.getMethod().isAnnotationPresent(annotation);
        }
      }));
}
origin: palantir/Cinch

/**
 * Returns the list of {@link ModelUpdate} types in this binding context.
 * @param modelClass
 * @return the of {@link Class}es that implement {@link ModelUpdate} in this binding context.
 */
public static List<Class<?>> findModelUpdateClass(final BindableModel modelClass) {
  List<Class<?>> classes = Reflections.getTypesOfTypeForClassHierarchy(
      modelClass.getClass(), ModelUpdate.class);
  Predicate<Class<?>> isEnum = new Predicate<Class<?>>() {
    public boolean apply(final Class<?> input) {
      return input.isEnum();
    }
  };
  // Look for ModelUpdate classes in implemented interfaces
  classes = Lists.newArrayList(Iterables.filter(classes, isEnum));
  for (Class<?> iface : modelClass.getClass().getInterfaces()) {
    classes.addAll(Lists.newArrayList(Iterables.filter(
        Reflections.getTypesOfTypeForClassHierarchy(
        iface, ModelUpdate.class), isEnum)));
  }
  if (classes.size() == 0) {
    return null;
  }
  return classes;
}
origin: palantir/Cinch

/**
 * Create a BindingContext for the given, non-null object.  Throws a {@link BindingException}
 * if there is a problem.
 * @param object the object - cannot be null
 */
public BindingContext(Object object) {
  Preconditions.checkNotNull(object, "object");
  this.object = object;
  try {
    bindableModels = indexBindableModels();
    bindableMethods = indexBindableMethods();
    bindableModelMethods = indexBindableModelMethods();
    bindableConstants = indexBindableConstants();
    bindableGetters = indexBindableProperties(Reflections.getterFunction(PropertyDescriptor.class, Method.class, "readMethod"));
    bindableSetters = indexBindableProperties(Reflections.getterFunction(PropertyDescriptor.class, Method.class, "writeMethod"));
  } catch (Exception e) {
    throw new BindingException("could not create BindingContext", e);
  }
}
origin: palantir/Cinch

  public void testEnumTypes() throws Exception {
    Object o = Reflections.evalEnum(TestEnum.class, "FOO");
    assertTrue("Object is not a ModelUpdate instance",ModelUpdate.class.isAssignableFrom(o.getClass()));

  }
}
origin: palantir/Cinch

  public static Binding bindJToggleButtonToEnum(final String value, final Class<?> enumType,
      final Mutator mutator, final AbstractButton button) {
    final Object enumValue = Reflections.evalEnum(enumType, value);
    button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        try {
          mutator.set(enumValue);
        } catch (Exception ex) {
          Wiring.logger.error("exception in JToggleButton binding", ex); //$NON-NLS-1$
        }
      }
    });

    Binding binding = new Binding() {
      public <T extends Enum<?> & ModelUpdate> void update(T... changed) {
        try {
          button.setSelected(mutator.get() == enumValue);
        } catch (Exception ex) {
          Wiring.logger.error("exception in JToggleButton binding", ex); //$NON-NLS-1$
        }
      }
    };
    mutator.getModel().bind(binding);
    return binding;
  }
}
origin: palantir/Cinch

private static List<ObjectFieldMethod> getParameterlessMethodsOnFieldTypes(Object object, List<Field> fields) throws IllegalArgumentException {
  List<ObjectFieldMethod> methods = Lists.newArrayList();
  for (Field field : fields) {
    Object fieldObject = Reflections.getFieldObject(object, field, Object.class);
    methods.addAll(getParameterlessMethods(fieldObject, field));
  }
  return methods;
}
com.palantir.ptoss.utilReflections

Javadoc

A collection of utility methods and classes to handle all the of the Java Reflection calls need to wire and fire bindings.

Most used methods

  • evalEnum
    Looks up an Enum value by its String name.
  • getAnnotatedFields
    Returns the list of fields on this class annotated with the passed Annotation
  • getAnnotatedFieldsForClassHierarchy
    Returns the list of fields on this class or any of its ancestors annotated with the passed Annotatio
  • getFieldObject
    Given an Object and a Field of a known Class type, get the field. This will return the value of the
  • getFieldsOfType
    Gets all fields from a given class that are assignable from the target class.
  • getFieldsOfTypeForClassHierarchy
    Gets all fields assignable from targetClass in the passed class's type hierarchy.
  • getParameterlessMethodsForClassHierarchy
    Returns all methods in the passed object's class hierarchy that do no not take parameters
  • getTypesOfType
    Gets all inner classes from a given class that are assignable from the target class.
  • getTypesOfTypeForClassHierarchy
    Gets all inner classes assignable from targetClass in the passed class's type hierarchy.
  • getterFunction
    Returns a Function that will read values from the named field from a passed object.
  • isClassAnnotatedForClassHierarchy
    Checks whether or not the specified Annotation exists in the passed Object's class hierarchy.
  • isFieldFinal
    Returns whether or not the given Field is final.
  • isClassAnnotatedForClassHierarchy,
  • isFieldFinal,
  • isFieldStatic,
  • isMethodPublic,
  • visitClassHierarchy

Popular in Java

  • Creating JSON documents from java classes using gson
  • addToBackStack (FragmentTransaction)
  • setScale (BigDecimal)
  • runOnUiThread (Activity)
  • VirtualMachine (com.sun.tools.attach)
    A Java virtual machine. A VirtualMachine represents a Java virtual machine to which this Java vir
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • ResultSet (java.sql)
    An interface for an object which represents a database table entry, returned as the result of the qu
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • Executor (java.util.concurrent)
    An object that executes submitted Runnable tasks. This interface provides a way of decoupling task s
  • Get (org.apache.hadoop.hbase.client)
    Used to perform Get operations on a single row. To get everything for a row, instantiate a Get objec
  • Top 12 Jupyter Notebook extensions
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