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

Function annotatedMethodName

src/resolution/frameworks/java.ts:672–733  ·  view source on GitHub ↗

* The name of the method the annotation at `at` is written on (#851): read * past it and every annotation stacked with it, the modifiers — none at all * for a package-private Java method — the type parameters and the return type * (`void`, a primitive, a qualified or nested generic type, an array

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

Source from the content-addressed store, hash-verified

670 * a constructor, a class.
671 */
672function annotatedMethodName(s: string, at: number, lang: 'java' | 'kotlin'): string | null {
673 const modifiers = lang === 'kotlin' ? KOTLIN_FUN_MODIFIERS : JAVA_METHOD_MODIFIERS;
674 // Annotations and modifiers come in any order (`public @ResponseBody String x()`).
675 const skipAnnotationsAndModifiers = (from: number): number => {
676 let i = from;
677 for (;;) {
678 i = skipSpace(s, i);
679 if (s[i] === '@') {
680 const annotation = readAnnotation(s, i, lang);
681 if (!annotation) return -1;
682 i = annotation.end;
683 continue;
684 }
685 const word = readIdentifier(s, i);
686 if (!word || !modifiers.has(word)) return i;
687 i += word.length;
688 }
689 };
690 let i = skipAnnotationsAndModifiers(at);
691 if (i < 0) return null;
692 if (lang === 'kotlin') {
693 if (readIdentifier(s, i) !== 'fun') return null;
694 i = skipSpace(s, i + 3);
695 if (s[i] === '<') {
696 i = skipGroup(s, i);
697 if (i < 0) return null;
698 i = skipSpace(s, i);
699 }
700 } else {
701 if (s[i] === '<') {
702 i = skipGroup(s, i);
703 if (i < 0) return null;
704 }
705 // Annotations on the return type: `<T> @Nullable T x()`.
706 i = skipAnnotationsAndModifiers(i);
707 if (i < 0) return null;
708 const type = readIdentifier(s, i);
709 if (!type || NOT_A_RETURN_TYPE.has(type)) return null;
710 i += type.length;
711 // Its qualifiers, type arguments and array dimensions.
712 for (;;) {
713 const j = skipSpace(s, i);
714 if (s[j] === '<') {
715 i = skipGroup(s, j);
716 if (i < 0) return null;
717 } else if (s[j] === '.') {
718 const k = skipSpace(s, j + 1);
719 const part = readIdentifier(s, k);
720 if (!part) return null;
721 i = k + part.length;
722 } else if (s[j] === '[' && s[skipSpace(s, j + 1)] === ']') {
723 i = skipSpace(s, j + 1) + 1;
724 } else {
725 break;
726 }
727 }
728 i = skipSpace(s, i);
729 }

Callers 1

extractFunction · 0.85

Calls 5

readIdentifierFunction · 0.85
hasMethod · 0.80
skipSpaceFunction · 0.70
skipGroupFunction · 0.70

Tested by

no test coverage detected