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

Function synthesizeLombokMembers

src/extraction/languages/java.ts:118–251  ·  view source on GitHub ↗

* Synthesize the members Lombok generates at compile time. Covers the common, * mechanical annotations: * * @Getter / @Setter (class- or field-level) → getX()/isX(), setX() * @Data → getters + setters (non-final) *

(classNode: SyntaxNode, ctx: ExtractorContext)

Source from the content-addressed store, hash-verified

116 * naming. A member the source already declares is never overridden.
117 */
118function synthesizeLombokMembers(classNode: SyntaxNode, ctx: ExtractorContext): void {
119 const classAnns = lombokAnnotationNames(classNode);
120 const classGetter = classAnns.has('Getter');
121 const classSetter = classAnns.has('Setter');
122 const isData = classAnns.has('Data');
123 const isValue = classAnns.has('Value');
124 const hasBuilder = classAnns.has('Builder') || classAnns.has('SuperBuilder');
125 const hasToString = isData || isValue || classAnns.has('ToString');
126 const hasEquals = isData || isValue || classAnns.has('EqualsAndHashCode');
127 const logAnn = [...classAnns].find((a) => LOMBOK_LOG_ANNOTATIONS.has(a));
128
129 const body = getChildByField(classNode, 'body');
130 if (!body) return;
131 const fields = body.namedChildren.filter((c: SyntaxNode) => c.type === 'field_declaration');
132
133 // Leave immediately when nothing Lombok is present, so a non-Lombok class
134 // pays nothing beyond one scan of its direct field declarations (and an
135 // annotated class skips even that — this hook runs for every Java class).
136 const classHasLombok =
137 classGetter || classSetter || isData || isValue || hasBuilder || hasToString || hasEquals || !!logAnn;
138 if (!classHasLombok && !fields.some((f: SyntaxNode) => lombokAnnotationNames(f).size > 0)) {
139 return;
140 }
141
142 // Members already declared directly in this class. Lombok never overrides an
143 // explicit member, so we skip a name the source already has. Methods and
144 // fields are tracked separately: they're distinct namespaces in Java (a
145 // boolean field `isRunning` and its generated getter `isRunning()` coexist),
146 // and the node id is keyed by kind so they never actually collide.
147 const classId = ctx.nodeStack[ctx.nodeStack.length - 1];
148 const classRec = ctx.nodes.find((n) => n.id === classId);
149 const classQN = classRec?.qualifiedName;
150 const takenMethods = new Set<string>();
151 const takenFields = new Set<string>();
152 if (classQN) {
153 for (const n of ctx.nodes) {
154 if (n.filePath === ctx.filePath && n.qualifiedName === `${classQN}::${n.name}`) {
155 if (n.kind === 'method' || n.kind === 'function') takenMethods.add(n.name);
156 else if (n.kind === 'field' || n.kind === 'variable' || n.kind === 'constant' || n.kind === 'property') {
157 takenFields.add(n.name);
158 }
159 }
160 }
161 }
162
163 const classNameNode = getChildByField(classNode, 'name') ?? classNode;
164 const className = classRec?.name ?? getNodeText(classNameNode, ctx.source).trim();
165
166 const emitMethod = (
167 name: string,
168 anchor: SyntaxNode,
169 signature: string,
170 fromAnnotation: string,
171 extra: { returnType?: string; isStatic?: boolean } = {}
172 ): void => {
173 if (!name || takenMethods.has(name)) return;
174 takenMethods.add(name);
175 ctx.createNode('method', name, anchor, {

Callers

nothing calls this directly

Calls 10

getChildByFieldFunction · 0.90
getNodeTextFunction · 0.90
lombokAnnotationNamesFunction · 0.85
modifierTextOfFunction · 0.85
normalizeJavaTypeFunction · 0.85
lombokGetterNameFunction · 0.85
emitMethodFunction · 0.85
lombokSetterNameFunction · 0.85
hasMethod · 0.80
createNodeMethod · 0.65

Tested by

no test coverage detected