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

Function annotatedMethodName

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

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

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