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

Function normalizeJavaType

src/extraction/languages/java.ts:24–35  ·  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

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

Callers 2

extractJavaReturnTypeFunction · 0.85
synthesizeLombokMembersFunction · 0.85

Calls 2

getNodeTextFunction · 0.90
hasMethod · 0.80

Tested by

no test coverage detected