outline: Java private/protected fields are missing from java.yml
Summary
java-member-field drops private and protected fields from the outline. Every other Java member rule, and every other language's member rules, emit all visibilities and only set a visibility flag.
Current behaviour (measured on main)
For:
class C {
private int a;
protected int b;
int c;
public int d;
private void m1() {}
protected void m2() {}
void m3() {}
public void m4() {}
private C() {}
C(int x) {}
public C(int x, int y) {}
}the outline is:
| member | private | protected | package-private | public |
|---|---|---|---|---|
| field | missing | missing | Field private c |
Field public d |
| method | Method private m1 |
Method private m2 |
Method private m3 |
Method public m4 |
| constructor | Constructor private C |
— | Constructor private C |
Constructor public C |
java-member-field filters visibility inside the matcher:
rule:
all:
- kind: field_declaration
- has: { field: declarator, has: { field: name, pattern: $NAME } }
- not: # private/protected never produced
has:
kind: modifiers
has:
any:
- pattern: private
- pattern: protectedjava-member-method, java-member-constructor and java-member-compact-constructor have no such filter; all three set isPublic: has modifiers public.
Why this looks inconsistent
- Within Java - fields are the only member kind that hides visibility. Methods and constructors emit every visibility with an
isPublicflag. - Across languages - every bundled member rule emits all visibilities and only sets the flag: Kotlin (
isPublic: not: modifiers private|internal|protected), TypeScript/JavaScript (isPublic: not: accessibility_modifier/private_property_identifier), C# (isPublic: has modifier ^public$), C++ (isPublic: false). - Package-private - the filter keeps the least visible non-private level (package-private is emitted as
Field private c) while droppingprotected, which is more visible. On visibility grounds alone the line is drawn in the wrong place.
Options
- A. Drop the filter so
java-member-fieldbehaves like the other member rules: the field is always produced,isPublicstayshas modifiers public(so private/protected/package-private are allisPublic: false). Smallest change; fields then match methods and constructors exactly. - B. Add a separate rule for private/protected fields, leaving
java-member-fielduntouched. Additive, but leaves two field rules over the same node kind and keeps the asymmetry.
Is this deliberate?
There is no comment or test rationale explaining the exclusion. If it is intentional outline UX (hide private fields as noise), then this is a policy question rather than a bug - but the cross-language and package-private points above are the argument for revisiting it. I'd like a maintainer's call before any change goes further.
Impact
Any consumer that derives counts or metrics from the outline can see private/protected methods and constructors, but not private/protected fields.
Source: ast-grep/ast-grep