Skip to content

Java

Managed Regex since v1.0

☕ Detects public types and members across classes, interfaces, enums, and records. Generics included.

.java

What gets detected

The public surface spec-sync tracks for Java.

  • public class / interface / enum / record / @interface (annotation)
  • public abstract class / sealed class
  • public methods and fields (including static, final, synchronized, generic)

Detection rules

Public type declarations

Matches public class, interface, enum, record, and annotation types. Handles abstract, final, sealed, and static modifiers.

public class AuthService {}
public interface Authenticator {}
public enum AuthStatus { ACTIVE, EXPIRED }
public record UserProfile(String name, int age) {}
public @interface Cacheable {}

Public methods and fields

Matches public members including static, final, synchronized, abstract, and native modifiers. Generic return types are supported.

public String validate(String token) {}
public static final String DEFAULT_TOKEN = "abc";
public <E> List<E> findAll() {}
public Map<String, Object> getMetadata() {}

Javadoc stripping

/** ... */ Javadoc blocks are stripped before matching to prevent false positives from documentation examples.

/**
 * @param token the JWT token
 * public String example() (this is NOT captured)
 */
public String validate(String token) {}  // this IS captured

Example: spec & source

The *.spec.md contract on the left, the Java source it documents on the right. spec-sync matches the two.

Spec (*.spec.md)

---
module: auth
version: 1
status: stable
files:
  - src/main/java/com/example/auth/AuthService.java
---

## Purpose

Java auth service for the JVM platform.

## Public API

| Symbol | Kind | Description |
|--------|------|-------------|
| `AuthService` | class | Main auth class |
| `Authenticator` | interface | Auth contract |
| `validate` | method | Validates a JWT token |
| `DEFAULT_TTL` | field | Default TTL in seconds |

## Change Log

| Date | Change |
|------|--------|
| 2026-01-01 | Initial |

Source

package com.example.auth;

public class AuthService {
    public static final int DEFAULT_TTL = 3600;

    public String validate(String token) {
        return token != null ? token : null;
    }

    private void internalCheck() {}
}

public interface Authenticator {
    boolean authenticate(String token);
}

public enum AuthStatus { ACTIVE, EXPIRED }

Test-file patterns

Files matching these are excluded from the detected surface.

Pattern Explanation
**/*Test.java JUnit test classes: auto-excluded
**/*Tests.java Alternate test naming: auto-excluded

Caveats

  • private, protected, and package-private (no modifier) members are excluded.
  • Annotation processors that generate public classes at compile time are not detected.
  • Inner classes are captured if they have the public modifier.
  • Lambda expressions and anonymous classes are not captured.

Related languages