MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / normalizeJavaType

Function normalizeJavaType

src/extraction/languages/java.ts:25–36  ·  view source on GitHub ↗

* Normalize a Java type node to the bare class name a chained * `foo.getThing().bar()` could be called on (the #645/#608 mechanism): * primitives/void/arrays yield undefined (no class to chain on), `List ` * is unwrapped to its base `List`, and a dotted package/outer-class qualifier * (`java

(typeNode: SyntaxNode | null, source: string)

Source from the content-addressed store, hash-verified

23 * (`java.util.List`) is stripped to the simple name.
24 */
25function normalizeJavaType(typeNode: SyntaxNode | null, source: string): string | undefined {
26 if (!typeNode) return undefined;
27 if (JAVA_NON_CLASS_RETURN_NODES.has(typeNode.type)) return undefined;
28 // An array (`Foo[]`) isn't a receiver you call instance methods on.
29 if (typeNode.type === 'array_type') return undefined;
30 // Strip type arguments (`List<Foo>` → `List`) — the chain resolves on the base.
31 const raw = getNodeText(typeNode, source).trim().replace(/<[^>]*>/g, '');
32 // Strip a dotted package / outer-class qualifier (`java.util.List` → `List`).
33 const last = raw.split('.').pop()?.trim();
34 if (!last || !/^[A-Za-z_]\w*$/.test(last)) return undefined;
35 return last;
36}
37
38/**
39 * A Java method's declared return type. Reads the `type` field; constructors

Callers 3

extractJavaReturnTypeFunction · 0.85
synthesizeLombokMembersFunction · 0.85

Calls 2

getNodeTextFunction · 0.90
hasMethod · 0.80

Tested by

no test coverage detected