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

Function readAnnotation

src/resolution/frameworks/java.ts:635–663  ·  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

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