Skip to content

Implement Java 1.4 regular expression APIs - #193

Merged
dlunch merged 1 commit into
mainfrom
agent/string-split
Jul 31, 2026
Merged

Implement Java 1.4 regular expression APIs#193
dlunch merged 1 commit into
mainfrom
agent/string-split

Conversation

@dlunch

@dlunch dlunch commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Summary

  • add java.lang.CharSequence and integrate it with String and StringBuffer
  • implement Java 1.4 java.util.regex.Pattern, Matcher, and PatternSyntaxException
  • add String.matches, replaceFirst, replaceAll, and both split overloads through the regex APIs
  • use regex 1.13.1 directly without translating historical Java regex syntax

Behavior

Matcher state, captures, replacement expansion, split limits, and public offsets follow the Java 1.4 API shape. Rust byte offsets are converted to Java UTF-16 indices. Full matches use an internal anchored wrapper, with a fallback for terminal extended-mode comments while preserving the original pattern source.

Validation

  • cargo test --workspace --quiet (504 passed, 1 existing ignored)
  • cargo test -p java_runtime regex (45 passed)
  • cargo check -p java_runtime --lib
  • cargo fmt --all -- --check
  • cargo clippy -p java_runtime --lib --tests -- -D warnings

Copilot AI review requested due to automatic review settings July 25, 2026 23:17
@codecov

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.42474% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.77%. Comparing base (1d26040) to head (0281488).

Files with missing lines Patch % Lines
...ava_runtime/src/classes/java/util/regex/matcher.rs 98.78% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #193      +/-   ##
==========================================
+ Coverage   90.49%   90.77%   +0.27%     
==========================================
  Files         265      269       +4     
  Lines       32349    33390    +1041     
==========================================
+ Hits        29275    30310    +1035     
- Misses       3074     3080       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds Java 1.4-compatible regular expression APIs to the java_runtime crate, introducing java.lang.CharSequence support and implementing java.util.regex.Pattern, Matcher, and PatternSyntaxException, plus String convenience methods that route through the regex API.

Changes:

  • Add java/lang/CharSequence and implement/integrate it with String and StringBuffer (incl. subSequence behavior).
  • Implement java/util/regex core classes (Pattern, Matcher, PatternSyntaxException) backed by Rust regex.
  • Add comprehensive runtime-level tests for matcher state, replacements, split semantics, flag validation, and exception formatting.

Reviewed changes

Copilot reviewed 20 out of 21 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
java_runtime/tests/classes/java/util/regex/test_split.rs Adds tests for Pattern.split (limits, UTF-16 boundaries, null handling).
java_runtime/tests/classes/java/util/regex/test_replacement.rs Adds tests for Matcher replacement APIs (appendReplacement, appendTail, replaceAll/First) and exception ordering.
java_runtime/tests/classes/java/util/regex/test_pattern.rs Adds tests for Pattern surface, flags validation, pass-through syntax, and null handling.
java_runtime/tests/classes/java/util/regex/test_pattern_syntax_exception.rs Adds tests for PatternSyntaxException API contract and message formatting behavior.
java_runtime/tests/classes/java/util/regex/test_matcher.rs Adds extensive tests for Matcher state machine, UTF-16 offsets, snapshot behavior, and error ordering.
java_runtime/tests/classes/java/util/regex/mod.rs Wires regex test modules into the test tree.
java_runtime/tests/classes/java/util/mod.rs Registers the new regex test module under java/util.
java_runtime/tests/classes/java/lang/test_string.rs Adds tests for CharSequence integration and String regex convenience methods.
java_runtime/tests/classes/java/lang/test_string_buffer.rs Adds tests for StringBuffer CharSequence behavior and snapshot semantics.
java_runtime/src/loader.rs Registers CharSequence and the new java.util.regex runtime classes.
java_runtime/src/classes/java/util/regex/pattern.rs Implements java.util.regex.Pattern including compile, matches, split, and flag mapping into Rust regex.
java_runtime/src/classes/java/util/regex/matcher.rs Implements java.util.regex.Matcher including match/search state, capture offsets, and replacement expansion.
java_runtime/src/classes/java/util/regex/pattern_syntax_exception.rs Implements java.util.regex.PatternSyntaxException and Java 1.4-style message formatting.
java_runtime/src/classes/java/util/regex.rs Adds the java_runtime::classes::java::util::regex module and exports.
java_runtime/src/classes/java/util.rs Exposes the new regex module under java.util.
java_runtime/src/classes/java/lang/string.rs Makes String implement CharSequence and adds regex convenience methods (matches, replaceFirst/All, split).
java_runtime/src/classes/java/lang/string_buffer.rs Makes StringBuffer implement CharSequence and adds subSequence.
java_runtime/src/classes/java/lang/char_sequence.rs Adds the java.lang.CharSequence interface definition.
java_runtime/src/classes/java/lang.rs Registers/exports CharSequence from java.lang.
java_runtime/Cargo.toml Adds the regex dependency for the runtime implementation.
Cargo.lock Locks regex and related dependency versions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread java_runtime/src/classes/java/util/regex/pattern.rs
Comment thread java_runtime/src/classes/java/util/regex/matcher.rs

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 02814889c0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread java_runtime/src/classes/java/util/regex/matcher.rs
Comment thread java_runtime/src/classes/java/util/regex/pattern.rs
Comment thread java_runtime/src/classes/java/util/regex/pattern.rs
@dlunch
dlunch merged commit 6203996 into main Jul 31, 2026
14 checks passed
@dlunch
dlunch deleted the agent/string-split branch July 31, 2026 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants