From 72711b923e141cab4d9d5b0fb4d9968a14e3ec15 Mon Sep 17 00:00:00 2001 From: "wangzekun.zekin" Date: Fri, 8 May 2026 19:26:50 +0800 Subject: [PATCH 1/2] fix(java): simplify NodeID name to methodName(paramTypes) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Java method NodeIDs were using the JAR-provided Descriptor/RawText directly, which often included modifiers, return type, throws clause, parameter names and annotations. Rebuild the name from MethodDetail's parameter list (TypeRawText, falling back to TypeFqcn) so NodeIDs are stable and concise — e.g. queryJwtToken(String,String,String). --- lang/collect/collect.go | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/lang/collect/collect.go b/lang/collect/collect.go index 27cbaa17..f115858b 100644 --- a/lang/collect/collect.go +++ b/lang/collect/collect.go @@ -830,10 +830,7 @@ func (c *Collector) ScannerByJavaIPC(ctx context.Context) ([]*DocumentSymbol, er if m == nil { continue } - name := m.Descriptor - if name == "" { - name = m.GetName() - } + name := buildJavaMethodID(m) if name == "" { continue } @@ -2524,6 +2521,36 @@ func (c *Collector) extractRootIdentifier(node *sitter.Node, content []byte) str return "" } +// buildJavaMethodID generates the simplified NodeID.Name for a Java method: +// methodName(ParamRawType1,ParamRawType2,...) +// Strips access modifiers, static/final/etc., annotations, return type, throws, +// and parameter names. Prefers ParameterDetail.TypeRawText (preserves generics +// and array notation as written) and falls back to TypeFqcn. +func buildJavaMethodID(m *javapb.MethodDetail) string { + if m == nil { + return "" + } + name := m.GetName() + if name == "" { + return "" + } + types := make([]string, 0, len(m.Parameters)) + for _, p := range m.Parameters { + if p == nil { + continue + } + t := p.TypeRawText + if t == "" { + t = p.TypeFqcn + } + if t == "" { + continue + } + types = append(types, t) + } + return name + "(" + strings.Join(types, ",") + ")" +} + // parseMethodSignature 从方法节点解析签名,保留方法名和参数类型 // 例如: public String queryJwtToken(String id, String tenantId, String idType) -> queryJwtToken(String, String, String) // 例如: forwardLarkEvent(Map) -> forwardLarkEvent(Map) From 6eecc8d07645957dccdf6c4a0f89c098704b31d3 Mon Sep 17 00:00:00 2001 From: "wangzekun.zekin" Date: Fri, 8 May 2026 20:26:20 +0800 Subject: [PATCH 2/2] fix(java): strip modifiers/return type from method NodeID GetName() only splits Descriptor at '(' so when the JAR returns the long form (e.g. "abstract void foo()"), modifiers and return type leaked into the NodeID name. Take the last whitespace-delimited token after GetName(), and drop empty parens for no-arg methods so the exported "Class.method" form stays clean. --- lang/collect/collect.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lang/collect/collect.go b/lang/collect/collect.go index f115858b..49a4d265 100644 --- a/lang/collect/collect.go +++ b/lang/collect/collect.go @@ -2530,7 +2530,13 @@ func buildJavaMethodID(m *javapb.MethodDetail) string { if m == nil { return "" } - name := m.GetName() + name := strings.TrimSpace(m.GetName()) + // GetName() may still contain modifiers + return type when the JAR's + // Descriptor uses the long form (e.g. "abstract void foo"). Take the last + // token after any space. + if sp := strings.LastIndexByte(name, ' '); sp >= 0 { + name = name[sp+1:] + } if name == "" { return "" } @@ -2548,6 +2554,9 @@ func buildJavaMethodID(m *javapb.MethodDetail) string { } types = append(types, t) } + if len(types) == 0 { + return name + } return name + "(" + strings.Join(types, ",") + ")" }