Class FlixelDefaultReflectionHandler

java.lang.Object
me.stringdotjar.flixelgdx.backend.reflect.FlixelDefaultReflectionHandler
All Implemented Interfaces:
FlixelReflection

public class FlixelDefaultReflectionHandler extends Object implements FlixelReflection
Default reflection handler used across platforms that rely on Java reflection.
  • Constructor Details

    • FlixelDefaultReflectionHandler

      public FlixelDefaultReflectionHandler()
  • Method Details

    • hasField

      public boolean hasField(Object target, String fieldName)
      Description copied from interface: FlixelReflection
      Checks whether a field with the given name exists on the target instance.

      Implementations should include inherited fields from superclasses. Returning false means the field cannot be resolved for read or write operations.

      Specified by:
      hasField in interface FlixelReflection
      Parameters:
      target - The object instance to inspect.
      fieldName - The field name to search for.
      Returns:
      true if the field exists on the target type, otherwise false.
    • field

      public Object field(Object target, String fieldName)
      Description copied from interface: FlixelReflection
      Reads a field value from the target instance.

      Implementations should resolve inherited fields and may allow non-public access depending on platform constraints. If the field cannot be resolved or read, an exception should be thrown.

      Specified by:
      field in interface FlixelReflection
      Parameters:
      target - The object instance to read from.
      fieldName - the field name to read
      Returns:
      the current field value
    • setField

      public void setField(Object target, String fieldName, Object value)
      Description copied from interface: FlixelReflection
      Writes a field value to the target instance.

      If a field is immutable, final, unsupported, or cannot be written safely, implementations should throw an explicit exception instead of silently failing.

      Specified by:
      setField in interface FlixelReflection
      Parameters:
      target - The object instance to modify.
      fieldName - The field name to write.
      value - The new value to store.
    • property

      public Object property(Object target, String propertyName)
      Description copied from interface: FlixelReflection
      Reads a property value from the target.

      Implementations may resolve JavaBean getters when available and fall back to direct field access when appropriate.

      Specified by:
      property in interface FlixelReflection
      Parameters:
      target - The object instance to inspect.
      propertyName - The property name to resolve.
      Returns:
      The resolved property value.
    • setProperty

      public void setProperty(Object target, String propertyName, Object value)
      Description copied from interface: FlixelReflection
      Writes a property value on the target.

      Implementations may resolve JavaBean setters when available and fall back to direct field writes when appropriate. Unsupported writes should throw an explicit exception.

      Specified by:
      setProperty in interface FlixelReflection
      Parameters:
      target - The object instance to modify.
      propertyName - The property name to resolve.
      value - The new property value.
    • fields

      public List<String> fields(Object target)
      Description copied from interface: FlixelReflection
      Returns a list of available field names for the target.

      The result should include inherited fields. Implementations may return a cached immutable list for performance.

      Specified by:
      fields in interface FlixelReflection
      Parameters:
      target - The object instance to inspect.
      Returns:
      Field names available on the target type.
    • callMethod

      public Object callMethod(Object target, String methodName, Object... args)
      Description copied from interface: FlixelReflection
      Invokes a method by name on the target.

      Implementations should resolve overloads using argument arity and type compatibility where supported by the platform runtime.

      Specified by:
      callMethod in interface FlixelReflection
      Parameters:
      target - The object instance to invoke on.
      methodName - The method name.
      args - Arguments for invocation.
      Returns:
      The invocation result, or null for void methods.
    • isObject

      public boolean isObject(Object value)
      Description copied from interface: FlixelReflection
      Returns whether a value should be treated as an object value in reflection contexts.

      This is useful for parity with dynamic reflection APIs and for differentiating scalar values from richer object structures.

      Specified by:
      isObject in interface FlixelReflection
      Parameters:
      value - Value to classify.
      Returns:
      true if the value is treated as an object value.
    • copy

      public <T> T copy(T source)
      Description copied from interface: FlixelReflection
      Creates a shallow copy of the source object.

      Implementations typically require a no-argument constructor and then copy non-static field values from source to destination.

      Specified by:
      copy in interface FlixelReflection
      Type Parameters:
      T - Source type.
      Parameters:
      source - Source instance.
      Returns:
      Copied instance.
    • compareMethods

      public boolean compareMethods(Object methodA, Object methodB)
      Description copied from interface: FlixelReflection
      Compares two method-like references for logical equality.

      Implementations may use identity and equality checks depending on how method references are represented on the current platform.

      Specified by:
      compareMethods in interface FlixelReflection
      Parameters:
      methodA - First method reference.
      methodB - Second method reference.
      Returns:
      true if both represent the same method target
    • objectFields

      public List<Field> objectFields(Class<?> type)
      Description copied from interface: FlixelReflection
      Returns all fields declared on a type and its superclasses.

      Implementations should cache the result per class to avoid repeated hierarchy traversal.

      Specified by:
      objectFields in interface FlixelReflection
      Parameters:
      type - Class to inspect.
      Returns:
      All resolved fields.
    • objectFieldsArray

      public Field[] objectFieldsArray(Class<?> type)
      Description copied from interface: FlixelReflection
      Returns all fields declared on a type and its superclasses as an array.
      Specified by:
      objectFieldsArray in interface FlixelReflection
      Parameters:
      type - Class to inspect.
      Returns:
      All resolved fields as an array.
    • isClassFinal

      public boolean isClassFinal(String classPath)
      Description copied from interface: FlixelReflection
      Checks whether the class at the given class path is declared as final.

      When a class cannot be resolved, implementations may return false to preserve compatibility with existing behavior.

      Specified by:
      isClassFinal in interface FlixelReflection
      Parameters:
      classPath - Fully qualified class name.
      Returns:
      true when the resolved class is final.