Class ClassFunctionalTools
java.lang.Object
org.machanism.machai.gw.maven.tools.ClassFunctionalTools
- All Implemented Interfaces:
org.machanism.machai.ai.tools.FunctionTools
public class ClassFunctionalTools
extends Object
implements org.machanism.machai.ai.tools.FunctionTools
Provides function-tool integrations for discovering Java classes and reading
reflective metadata from the classpath of one or more Maven projects.
Instances maintain a cache of ClassInfoHolder objects keyed by Maven
project base directory, allowing tool invocations to resolve classes relative
to the current working project.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate Map<File, ClassInfoHolder> Holds class metadata by Maven project base directory.private static final StringMessage returned when a tool call is made for a project that has not been scanned and registered in this instance.private static final String -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty instance.ClassFunctionalTools(org.apache.maven.project.MavenProject project) Creates a new instance backed by the supplied Maven project's classpath. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddAnnotations(Map<String, Object> info, Class<?> clazz) private voidaddConstructors(Map<String, Object> info, Class<?> clazz) private voidprivate voidaddInterfaces(Map<String, Object> info, Class<?> clazz) private voidaddLocationMetadata(Map<String, Object> info, ClassInfoHolder classInfoHolder, String className) private voidaddMethods(Map<String, Object> info, Class<?> clazz) private voidaddSuperclass(Map<String, Object> info, Class<?> clazz) Finds fully qualified class names whose simple names match the supplied regular expression.private <T extends Member>
voidforEachNonPrivate(T[] members, Consumer<T> consumer) getClassInfo(String className, File projectDir) Returns reflective information for the specified class.populateClassInfo(ClassInfoHolder classInfoHolder, String className, Class<?> clazz) voidscanProjectClasses(org.apache.maven.project.MavenProject project) Registers a project by scanning and caching class metadata for its base directory.toParameterTypes(Class<?>[] parameterTypes)
-
Field Details
-
FT_NOT_SUPPORTED_FOR_PROJECT_MSG
Message returned when a tool call is made for a project that has not been scanned and registered in this instance.- See Also:
-
CLASS_NAME_PROPERTY
- See Also:
-
MODIFIERS_PROPERTY
- See Also:
-
classInfoProjectMap
Holds class metadata by Maven project base directory.
-
-
Constructor Details
-
ClassFunctionalTools
public ClassFunctionalTools(org.apache.maven.project.MavenProject project) Creates a new instance backed by the supplied Maven project's classpath.- Parameters:
project- the Maven project used to resolve classpath and output directories
-
ClassFunctionalTools
public ClassFunctionalTools()Creates an empty instance. Projects must be registered later throughscanProjectClasses(MavenProject)before tool invocations can resolve class information.
-
-
Method Details
-
scanProjectClasses
public void scanProjectClasses(org.apache.maven.project.MavenProject project) Registers a project by scanning and caching class metadata for its base directory.- Parameters:
project- the Maven project to register
-
findClass
Finds fully qualified class names whose simple names match the supplied regular expression. -
getClassInfo
public Map<String,Object> getClassInfo(String className, File projectDir) throws ClassNotFoundException Returns reflective information for the specified class.The generated output may include modifiers, superclass, interfaces, non-private fields, constructors, non-private methods, annotations, class path, and dependency artifact coordinates.
- Parameters:
className- fully qualified class name to inspectprojectDir- the Maven project base directory used to resolve class metadata- Returns:
- a HashMap describing the requested class or containing an
errorproperty when the class or project context cannot be resolved - Throws:
ClassNotFoundException
-
populateClassInfo
-
addSuperclass
-
addInterfaces
-
addFields
-
addConstructors
-
addMethods
-
addAnnotations
-
addLocationMetadata
private void addLocationMetadata(Map<String, Object> info, ClassInfoHolder classInfoHolder, String className) -
toParameterTypes
-
forEachNonPrivate
-