# reflection-utils

A lightweight Java utility library that provides static helper methods for working with the Java Reflection API. It simplifies common type-inspection tasks — checking whether a type is a primitive, a collection, a boxed wrapper, an enum, and more — so you do not have to write repetitive boilerplate when building frameworks, serializers, or other reflection-heavy code.

## Dependency

```xml
<dependency>
    <groupId>io.ljunggren</groupId>
    <artifactId>reflection-utils</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</dependency>
```

## Usage

All methods are static. Import the class and call directly:

```java
import io.ljunggren.reflectionUtils.ReflectionUtils;
```

---

## Method Reference

### Get Owner Type

Returns the raw (erased) type of a parameterized type, or `null` if the type is not parameterized.

```java
Type owner = ReflectionUtils.getOwnerType(type);
```

---

### Is Parameterized

Returns `true` if the given type is a `ParameterizedType` (e.g., `List<String>`).

```java
boolean result = ReflectionUtils.isParameterized(type);
```

---

### Get Parameterized Types

Returns all type arguments of a parameterized type as an array. Returns an empty array if the type is not parameterized.

```java
Type[] types = ReflectionUtils.getParameterizedTypes(type);
```

---

### Get Parameterized Type

Returns the single type argument of a parameterized type, or `null` if there is not exactly one type argument.

```java
Type type = ReflectionUtils.getParameterizedType(type);
```

---

### Get Array Component Type

Returns the component type of an array type, or `null` if the type is not an array.

```java
Type componentType = ReflectionUtils.getArrayComponentType(type);
```

---

### Get Object Fields

Returns all fields declared on the class and its superclasses, including private fields.

```java
List<Field> fields = ReflectionUtils.getObjectFields(clazz);
```

---

### Is Primitive

Returns `true` if the type represents a Java primitive (e.g., `int`, `boolean`). Parameterized types always return `false`.

```java
boolean result = ReflectionUtils.isPrimitive(type);
boolean result = ReflectionUtils.isPrimitive(clazz);
```

---

### Is Number

Returns `true` if the value or type is assignable from `Number`.

```java
boolean result = ReflectionUtils.isNumber(t);       // instance check
boolean result = ReflectionUtils.isNumber(type);    // Type overload
boolean result = ReflectionUtils.isNumber(clazz);   // Class<?> overload
```

---

### Is Integer

Returns `true` if the value or type is `Integer`.

```java
boolean result = ReflectionUtils.isInteger(t);
boolean result = ReflectionUtils.isInteger(type);
boolean result = ReflectionUtils.isInteger(clazz);
```

---

### Is Double

Returns `true` if the value or type is `Double`.

```java
boolean result = ReflectionUtils.isDouble(t);
boolean result = ReflectionUtils.isDouble(type);
boolean result = ReflectionUtils.isDouble(clazz);
```

---

### Is Short

Returns `true` if the value or type is `Short`.

```java
boolean result = ReflectionUtils.isShort(t);
boolean result = ReflectionUtils.isShort(type);
boolean result = ReflectionUtils.isShort(clazz);
```

---

### Is Long

Returns `true` if the value or type is `Long`.

```java
boolean result = ReflectionUtils.isLong(t);
boolean result = ReflectionUtils.isLong(type);
boolean result = ReflectionUtils.isLong(clazz);
```

---

### Is Float

Returns `true` if the value or type is `Float`.

```java
boolean result = ReflectionUtils.isFloat(t);
boolean result = ReflectionUtils.isFloat(type);
boolean result = ReflectionUtils.isFloat(clazz);
```

---

### Is BigDecimal

Returns `true` if the value or type is `BigDecimal`.

```java
boolean result = ReflectionUtils.isBigDecimal(t);
boolean result = ReflectionUtils.isBigDecimal(type);
boolean result = ReflectionUtils.isBigDecimal(clazz);
```

---

### Is Byte

Returns `true` if the value or type is `Byte`.

```java
boolean result = ReflectionUtils.isByte(t);
boolean result = ReflectionUtils.isByte(type);
boolean result = ReflectionUtils.isByte(clazz);
```

---

### Is Boolean

Returns `true` if the value or type is `Boolean`.

```java
boolean result = ReflectionUtils.isBoolean(t);
boolean result = ReflectionUtils.isBoolean(type);
boolean result = ReflectionUtils.isBoolean(clazz);
```

---

### Is String

Returns `true` if the value or type is `String`.

```java
boolean result = ReflectionUtils.isString(t);
boolean result = ReflectionUtils.isString(type);
boolean result = ReflectionUtils.isString(clazz);
```

---

### Is Enum

Returns `true` if the value or type is an enum.

```java
boolean result = ReflectionUtils.isEnum(t);
boolean result = ReflectionUtils.isEnum(type);
boolean result = ReflectionUtils.isEnum(clazz);
```

---

### Is Boxed

Returns `true` if the type is a boxed primitive wrapper (e.g., `Integer`, `Boolean`). Determined by the presence of a `TYPE` field in the `java.lang` package. Parameterized types and raw primitives always return `false`.

```java
boolean result = ReflectionUtils.isBoxed(type);
boolean result = ReflectionUtils.isBoxed(clazz);
```

---

### Is List

Returns `true` if the value or type is assignable from `List`.

```java
boolean result = ReflectionUtils.isList(t);
boolean result = ReflectionUtils.isList(type);
boolean result = ReflectionUtils.isList(clazz);
```

---

### Is Map

Returns `true` if the value or type is assignable from `Map`.

```java
boolean result = ReflectionUtils.isMap(t);
boolean result = ReflectionUtils.isMap(type);
boolean result = ReflectionUtils.isMap(clazz);
```

---

### Is Array

Returns `true` if the value or type is an array.

```java
boolean result = ReflectionUtils.isArray(t);
boolean result = ReflectionUtils.isArray(type);
boolean result = ReflectionUtils.isArray(clazz);
```

---

### Is Set

Returns `true` if the value or type is assignable from `Set`.

```java
boolean result = ReflectionUtils.isSet(t);
boolean result = ReflectionUtils.isSet(type);
boolean result = ReflectionUtils.isSet(clazz);
```

---

### Is Collection

Returns `true` if the value or type is assignable from `Collection`.

```java
boolean result = ReflectionUtils.isCollection(t);
boolean result = ReflectionUtils.isCollection(type);
boolean result = ReflectionUtils.isCollection(clazz);
```

---

### Is Iterable

Returns `true` if the value or type is assignable from `Iterable`.

```java
boolean result = ReflectionUtils.isIterable(t);
boolean result = ReflectionUtils.isIterable(type);
boolean result = ReflectionUtils.isIterable(clazz);
```

---

### Has No-Args Constructor

Returns `true` if the class declares only a no-argument constructor. Returns `false` for parameterized types and `null` inputs.

```java
boolean result = ReflectionUtils.hasNoArgsConstructor(type);
boolean result = ReflectionUtils.hasNoArgsConstructor(clazz);
```

---

### Get Field Value

Reads the value of a field from a target object, bypassing access modifiers.

```java
Object value = ReflectionUtils.getFieldValue(field, target);
```

## License

MIT
