org.instancio.Node Maven / Gradle / Ivy
/*
* Copyright 2022-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.instancio;
import org.instancio.settings.AssignmentType;
import org.instancio.settings.Keys;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Optional;
/**
* Represents a single {@code Node} of a node hierarchy
* created for a given {@link Type}. A node can represent:
*
*
* - the root class
* - field of a class
* - an element of a collection, or in general, a generic type argument,
* for example, the type of an {@link Optional} value
*
*
* @since 2.11.0
*/
public interface Node {
/**
* Returns the target class of this node.
*
* If this node represents a field, generally the target class
* will be the same as {@link Field#getType()}. However, there are
* cases where the target class may differ, for example:
*
*
* - when a subtype is specified, then
* the node's target class will represent the subtype.
* - when the node represents a generic type, then
* the target class will represent the resolved type argument.
*
*
* @return target class of this node, never {@code null}
* @since 2.11.0
*/
Class> getTargetClass();
/**
* Returns the field of this node, if available.
*
* @return field of this node, or {@code null} if the node has no field
* @since 2.11.0
*/
Field getField();
/**
* Returns the parent of this node,
* or {@code null} if this node is the root.
*
* @return parent of this node
* @since 3.5.0
*/
Node getParent();
/**
* Returns the setter of this node, if available, and if
* {@link Keys#ASSIGNMENT_TYPE} is set to {@link AssignmentType#METHOD}.
*
* @return setter of this node, or {@code null} if the node has no setter
* @since 4.0.0
*/
Method getSetter();
}