# (DD10) Business Logic — PatternBExtractor.extractFieldName() [5 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.optage.parser.PatternBExtractor` |
| Layer | Utility |
| Module | `parser` (Package: `com.optage.parser`) |

## 1. Role

### PatternBExtractor.extractFieldName()

This method extracts the Java field identifier from the left-hand side of a field declaration fragment that has already been split away from an inline comment. In business terms, it supports metadata parsing for source-code labeling by isolating the technical field name that will later be paired with a business label or annotation. The method is intentionally narrow and deterministic: it does not interpret the broader statement, only identifies the first valid Java identifier that appears before the assignment operator. This makes it a reusable parsing helper inside the extractor, where it acts as a routing/dispatch utility for field-name recognition across many candidate lines. The method has only two outcomes: a matching field name is returned when the pattern is found, or `null` is returned when the fragment does not contain an assignable field declaration.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["extractFieldName(fieldPart)"])
    PATTERN["Compile regex pattern for field name before assignment"]
    MATCHER["Create matcher for fieldPart"]
    FIND{"matcher.find()?"}
    GROUP["Return matcher.group(1)"]
    NULLRET["Return null"]
    END_NODE(["Return / Next"])

    START --> PATTERN
    PATTERN --> MATCHER
    MATCHER --> FIND
    FIND -->|Yes| GROUP
    FIND -->|No| NULLRET
    GROUP --> END_NODE
    NULLRET --> END_NODE
```

**Constant Resolution:** No project constant files are referenced by this method. The only pattern used is an inline regular expression literal.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `fieldPart` | `String` | The left-hand portion of a source-code field declaration, typically the text before an inline comment. It represents the technical statement fragment from which the method must derive the field identifier. Its content determines whether a valid Java-style variable name can be extracted before the `=` sign. |

External state read by the method: none. The method uses only the incoming argument and locally instantiated regex objects.

## 4. CRUD Operations / Called Services

This method does not perform CRUD against entities, tables, or service components. It only performs local parsing with `Pattern.compile`, `pattern.matcher`, `matcher.find`, and `matcher.group`, which are technical library operations rather than business persistence operations.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `Pattern.compile` | - | - | Compiles the regular expression used to identify the field name token. |
| - | `pattern.matcher` | - | - | Creates a matcher over the supplied field fragment. |
| - | `matcher.find` | - | - | Searches for the first assignment-style field-name match. |
| - | `matcher.group` | - | - | Returns the captured identifier from the regex group. |

## 5. Dependency Trace

### Pre-computed evidence from code analysis graph:

No screen/batch entry points found within 8 hops. Direct callers found: 1 methods.
Terminal operations from this method: -

The only direct caller identified in the codebase is the sibling method `PatternBExtractor.extract(String code)`, which invokes this helper while parsing each candidate field declaration line. No screen, batch, controller, or CBS entry point was found within the available search scope. Because this method is private and self-contained, its dependency trace terminates within the same class and does not reach any persistence or service layer endpoint.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Utility: `PatternBExtractor.extract` | `PatternBExtractor.extract` -> `PatternBExtractor.extractFieldName` | `local regex parse [R] in-memory field token` |

## 6. Per-Branch Detail Blocks

**Block 1** — **EXEC** `(compile regex pattern)` (L39)

> Builds the regular expression used to recognize a Java identifier immediately before the assignment operator.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `Pattern pattern = Pattern.compile("\\b([a-zA-Z_][a-zA-Z0-9_]*)\\s*=");` // compile field-name matcher |

**Block 2** — **EXEC** `(create matcher for incoming field fragment)` (L40)

> Applies the compiled pattern to the caller-supplied left-hand-side fragment.

| # | Type | Code |
|---|------|------|
| 1 | SET | `Matcher matcher = pattern.matcher(fieldPart);` // bind input fragment to matcher |

**Block 3** — **IF** `(matcher.find())` (L41)

> Determines whether the fragment actually contains a valid field name that can be extracted.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `matcher.find()` // search for first valid field token |

**Block 3.1** — **THEN** `(match found)` (L41)

> Returns the first captured identifier from the regex group.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return matcher.group(1);` // return field name token |

**Block 3.2** — **ELSE** `(no match found)` (L41)

> Returns `null` to indicate that the fragment does not represent a parsable field declaration.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return null;` // no valid field name present |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|-------------------|
| `fieldPart` | Field | Left-hand fragment of a source-code declaration, excluding the inline comment; used as the input for field-name extraction. |
| `fieldName` | Field | Parsed Java-style variable name obtained from the declaration fragment. |
| `Matcher` | Technical term | Java regex engine object used to search for a pattern within text. |
| `Pattern` | Technical term | Compiled regular expression definition used for matching. |
| `extractFieldName` | Method | Helper routine that isolates the field identifier from a declaration fragment. |
| `extract` | Method | Parent parsing method that scans source lines and delegates field-name extraction to this helper. |
| inline comment | Business term | Text appended after `//` that is treated separately from the code fragment during parsing. |
| assignment operator (`=`) | Technical term | Token that indicates the boundary after the field identifier in a declaration. |
| Java identifier | Technical term | Valid variable name syntax consisting of letters, digits, and underscores, starting with a letter or underscore. |