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

Function readAnnotation

src/resolution/frameworks/java.ts:633–661  ·  view source on GitHub ↗

* The annotation at `at` — `@Name`, `@a.b.Name`, Kotlin's `@field:Name` or * `@[A B]` — with its arguments read as a balanced group, so a `)` in a string * or a nested annotation doesn't end it. `end` is past the arguments, or past * the whitespace after a bare name. Null when no annotation is th

(s: string, at: number, lang: 'java' | 'kotlin')

Source from the content-addressed store, hash-verified

631 * arguments never close.
632 */
633function readAnnotation(s: string, at: number, lang: 'java' | 'kotlin'): { args: string; end: number } | null {
634 if (s[at] !== '@') return null;
635 let i = at + 1;
636 if (lang === 'kotlin' && s[i] === '[') {
637 const end = skipGroup(s, i);
638 return end < 0 ? null : { args: '', end };
639 }
640 const readName = (from: number): number => {
641 let j = from;
642 for (;;) {
643 const part = readIdentifier(s, j);
644 if (!part) return -1;
645 j += part.length;
646 if (s[j] !== '.') return j;
647 j++;
648 }
649 };
650 i = readName(i);
651 if (i < 0) return null;
652 // A Kotlin use-site target: `@field:Name`, `@get:Name`.
653 if (lang === 'kotlin' && s[i] === ':') {
654 i = readName(i + 1);
655 if (i < 0) return null;
656 }
657 const next = skipSpace(s, i);
658 if (s[next] !== '(') return { args: '', end: next };
659 const end = skipGroup(s, next);
660 return end < 0 ? null : { args: s.slice(next + 1, end - 1), end };
661}
662
663/**
664 * The name of the method the annotation at `at` is written on (#851): read

Callers 2

extractFunction · 0.85

Calls 3

readNameFunction · 0.85
skipGroupFunction · 0.70
skipSpaceFunction · 0.70

Tested by

no test coverage detected