Class CodeModel

java.lang.Object
uno.anahata.ai.nb.tools.java2.CodeModel

public class CodeModel extends Object
Provides tools for interacting with the Java code model in NetBeans. This includes finding types, getting members, and retrieving source code.
  • 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

      public static String getTypeSources(JavaType javaType) throws Exception
      Gets the source file for a given JavaType.
      Parameters:
      javaType - The minimalist keychain DTO from a findTypes call.
      Returns:
      the content of the source file.
      Throws:
      Exception - if the source cannot be retrieved.
    • getTypeJavadocs

      public static String getTypeJavadocs(JavaType javaType) throws Exception
      Gets the Javadoc for a given JavaType.
      Parameters:
      javaType - The keychain DTO for the type to inspect.
      Returns:
      the Javadoc comment.
      Throws:
      Exception - if the Javadoc cannot be retrieved.
    • getMemberSources

      public static String getMemberSources(JavaMember member) throws Exception
      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

      public static String getMemberJavadocs(JavaMember member) throws Exception
      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

      public static FileInfo getSources(String typeName, String projectDirectoryPath) throws Exception
      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.