junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/ReflectiveInvocationContext.java
raw symbols SCIP| 1 | /* |
| 2 | * Copyright 2015-2024 the original author or authors. |
| 3 | * |
| 4 | * All rights reserved. This program and the accompanying materials are |
| 5 | * made available under the terms of the Eclipse Public License v2.0 which |
| 6 | * accompanies this distribution and is available at |
| 7 | * |
| 8 | * https://www.eclipse.org/legal/epl-v20.html |
| 9 | */ |
| 10 | |
| 11 | package org.junit.jupiter.api.extension; |
| 12 | |
| 13 | import static org.apiguardian.api.API.Status.STABLE; |
| 14 | |
| 15 | import java.lang.reflect.Executable; |
| 16 | import java.util.List; |
| 17 | import java.util.Optional; |
| 18 | |
| 19 | import org.apiguardian.api.API; |
| 20 | |
| 21 | /** |
| 22 | * {@code ReflectiveInvocationContext} encapsulates the <em>context</em> of |
| 23 | * a reflective invocation of an executable (method or constructor). |
| 24 | * |
| 25 | * <p>This interface is not intended to be implemented by clients. |
| 26 | * |
| 27 | * @since 5.5 |
| 28 | */ |
| 29 | @API(status = STABLE, since = "5.10") |
| 30 | public interface ReflectiveInvocationContext<T extends Executable> { |
| 31 | |
| 32 | /** |
| 33 | * Get the target class of this invocation context. |
| 34 | * |
| 35 | * <p>If this invocation context represents an instance method, this |
| 36 | * method returns the class of the object the method will be invoked on, |
| 37 | * not the class it is declared in. Otherwise, if this invocation |
| 38 | * represents a static method or constructor, this method returns the |
| 39 | * class the method or constructor is declared in. |
| 40 | * |
| 41 | * @return the target class of this invocation context; never |
| 42 | * {@code null} |
| 43 | */ |
| 44 | Class<?> getTargetClass(); |
| 45 | |
| 46 | /** |
| 47 | * Get the method or constructor of this invocation context. |
| 48 | * |
| 49 | * @return the executable of this invocation context; never {@code null} |
| 50 | */ |
| 51 | T getExecutable(); |
| 52 | |
| 53 | /** |
| 54 | * Get the arguments of the executable in this invocation context. |
| 55 | * |
| 56 | * @return the arguments of the executable in this invocation context; |
| 57 | * immutable and never {@code null} |
| 58 | */ |
| 59 | List<Object> getArguments(); |
| 60 | |
| 61 | /** |
| 62 | * Get the target object of this invocation context, if available. |
| 63 | * |
| 64 | * <p>If this invocation context represents an instance method, this |
| 65 | * method returns the object the method will be invoked on. Otherwise, |
| 66 | * if this invocation context represents a static method or |
| 67 | * constructor, this method returns {@link Optional#empty() empty()}. |
| 68 | * |
| 69 | * @return the target of the executable of this invocation context; never |
| 70 | * {@code null} but potentially empty |
| 71 | */ |
| 72 | Optional<Object> getTarget(); |
| 73 | |
| 74 | } |