Class CodeModel
java.lang.Object
uno.anahata.ai.nb.tools.java2.CodeModel
Provides tools for interacting with the Java code model in NetBeans.
This includes finding types, getting members, and retrieving source code.
-
Method Summary
Modifier and TypeMethodDescriptionfindTypes(String query, boolean caseSensitive, boolean preferOpenProjects, Integer startIndex, Integer pageSize) Finds multiple Java types matching a query and returns a paginated result of minimalist, machine-readable keys.static StringgetMemberJavadocs(JavaMember member) Gets the Javadoc for a specific JavaMember.static Page<JavaMember> getMembers(JavaType javaType, Integer startIndex, Integer pageSize, List<ElementKind> kindFilters) Gets a paginated list of all members (fields, constructors, methods) for a given type.static StringgetMemberSources(JavaMember member) Gets the source code for a specific JavaMember.static FileInfogetSources(String typeName, String projectDirectoryPath) Gets the source for a type using a specific project's classpath.static StringgetTypeJavadocs(JavaType javaType) Gets the Javadoc for a given JavaType.static StringgetTypeSources(JavaType javaType) Gets the source file for a given JavaType.
-
Method Details
-
findTypes
public static Page<JavaType> findTypes(String query, boolean caseSensitive, boolean preferOpenProjects, Integer startIndex, Integer pageSize) Finds multiple Java types matching a query and returns a paginated result of minimalist, machine-readable keys.- Parameters:
query- The search query for the types (e.g., simple name, FQN, wildcards).caseSensitive- Whether the search should be case-sensitive.preferOpenProjects- Whether to prioritize results from open projects.startIndex- The starting index (0-based) for pagination.pageSize- The maximum number of results to return per page.- Returns:
- a paginated result of JavaType objects.
-
getTypeSources
-
getTypeJavadocs
-
getMemberSources
Gets the source code for a specific JavaMember.- Parameters:
member- The keychain DTO for the member to inspect.- Returns:
- the source code of the member.
- Throws:
Exception- if the source cannot be retrieved.
-
getMemberJavadocs
Gets the Javadoc for a specific JavaMember.- Parameters:
member- The keychain DTO for the member to inspect.- Returns:
- the Javadoc comment.
- Throws:
Exception- if the Javadoc cannot be retrieved.
-
getMembers
public static Page<JavaMember> getMembers(JavaType javaType, Integer startIndex, Integer pageSize, List<ElementKind> kindFilters) throws Exception Gets a paginated list of all members (fields, constructors, methods) for a given type.- Parameters:
javaType- The keychain DTO for the type to inspect.startIndex- The starting index (0-based) for pagination.pageSize- The maximum number of results to return per page.kindFilters- Optional list of member kinds to filter by (e.g., ['METHOD', 'FIELD']).- Returns:
- a paginated result of JavaMember objects.
- Throws:
Exception- if the members cannot be retrieved.
-
getSources
Gets the source for a type using a specific project's classpath. This is the 'Ctrl+Click', context-aware, one-turn tool.- Parameters:
typeName- The simple or FQN of the type.projectDirectoryPath- The absolute path of the project directory to use for context.- Returns:
- a FileInfo object containing the source code.
- Throws:
Exception- if the source cannot be found.
-
