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

Function synthesizeLombokMembers

src/extraction/languages/java.ts:119–252  ·  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

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

Callers 1

synthesizeJavaMembersFunction · 0.85

Calls 11

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
addMethod · 0.45

Tested by

no test coverage detected