Java inline fqn cleanup

From chromium/chromium · View interactive version

Java inline fqn cleanup is an AI agent skill from the GitHub repository chromium/chromium. Identify and clean up inline fully qualified Java names (FQNs) in first-party code, replacing them with standard imports.

How to use this skill

Skill file

Code Health: Java Inline FQN Cleanup

Clean up inline fully qualified names (FQNs) in Java code by replacing them with

proper import statements at the top of the file, and then formatting/optimizing

the import order.

Overview

Using fully qualified class names inline (e.g. android.view.View view = ...)

instead of importing them makes code harder to read and breaks standard style

conventions. This skill helps automate the discovery, safety analysis, and

clean-up of these inline qualifiers in Chromium's first-party Java files.

Goal: Clean up inline fully qualified names (FQNs) in first-party Java files

and replace them with standard imports.

Workflow

[!IMPORTANT] Execution Protocol: Execute all steps continuously in one

autonomous run, without skipping steps or pausing between files or steps. Stop

only at explicit ask_question gates or documented interactive stops. Use

rg (ripgrep) for searches.

Step 1: Workspace Preparation

Run the workspace preparation script:

python3 agents/projects/code-health/hub/scripts/prepare_workspace.py --stash

on a dirty or diverged tree.

Step 2: Discovery & Batch Selection

Follow the

Discovery & Batch Selection

workflow, passing --json so each file's valid and banned FQN lists are

included and untruncated when reporting the batch.

Step 3: Refactoring & Implementation

CRITICAL RULE: Standard file editing tools must be used to apply the

cleanups directly to the Java files. DO NOT create, write, or execute any

custom python or bash scripts to perform the text replacements.

examples and exceptions (e.g., handling java.lang.\* and Local R classes)

before applying replacements.

Process the candidates by handling them one file at a time, and applying

modifications inside each file one FQN at a time (rather than refactoring

all files or FQNs at once). This ensures stability and allows for precise

verification. Process all files and FQNs sequentially within the same run,

without pausing for user confirmation between edits, then proceed directly to

Step 4. For each file in the batch, apply the following cleanup rules:

  1. Avoid Name Collisions & Shadowing: Check if the simple class name of the

FQN is already imported, defined, or implicitly resolved in that file (e.g.,

via wildcard imports, implicit package-private classes, or other imported

annotations with the same name). If there is a collision or shadowing risk,

do not modify the line (the FQN must remain inline).

  1. Banned FQNs: If the discovery JSON lists any FQNs in a file's banned

list, completely ignore those specific FQNs. They are either raw package

paths or invalid classes, and attempting to import them will break the build.

  1. First-Party Code Only: Do not modify any files in third_party/ or

auto-generated directories.

  1. Import Strategy for Static Members: When cleaning up inline FQNs for

static constants, properties (e.g. TabProperties), feature flags

(ChromeFeatureList), or enums (TabLaunchType), **prefer importing the

class itself rather than importing its members statically**.

import static org.chromium.chrome.browser.tasks.tab_management.TabProperties.IS_SELECTED;

import org.chromium.chrome.browser.tasks.tab_management.TabProperties;

and use TabProperties.IS_SELECTED in the code.

clear context of where the constant is defined and avoids namespace

conflicts when multiple imported properties classes share the same field

names (e.g. TabProperties.TITLE vs FolderProperties.TITLE).

  1. Clean up Javadocs & Comments: Replace inline FQNs found inside code

comments and Javadoc links (e.g. {@link android.webkit.WebSettings} ->

{@link WebSettings}). However, never modify URLs (like https://... or

other web links) inside comments.

  1. Nested and Inner Classes: For inline references to nested or inner

classes (e.g. org.chromium.chrome.browser.profiles.ProfileKey.Theme),

prefer importing the top-level outer class

(import org.chromium.chrome.browser.profiles.ProfileKey;) and referring to

it as ProfileKey.Theme in the code, rather than importing the nested class

directly.

in that specific file, match the existing style.

  1. Apply Replacements:

Step 4: Formatting & Automated Review

  1. Format & Lint: Run

python3 agents/projects/code-health/hub/scripts/format_and_lint.py (must

exit 0).

  1. Automated Review: Follow

Automated Review, passing

review_rules.md as

<SKILL_SPECIFIC_CLEANUP_RULES>.

Step 5: Verification

Follow the Verification workflow.

Step 6: Submission

1. Prepare Commit Message

Ensure the full [Code Health][LSC] <Title> subject is at most 72 characters

(use a short component name or shorten the title if needed), and generate

../commit:

python3 agents/projects/code-health/hub/scripts/prepare_commit_message.py \
  --skill java-inline-fqn-cleanup \
  --title "Clean up inline FQNs in <Component>" \
  --description - \
  --out-commit ../commit <<'EOF'
Remove inline fully qualified class names and replace them with standard
imports in <Component/Directory>.
EOF
2. Validate Commit File
python3 agents/projects/code-health/hub/scripts/prepare_commit_message.py \
  --skill java-inline-fqn-cleanup \
  --validate ../commit

If validation fails, fix the commit title or description and re-run Steps 1–2

until validation exits 0.

3. Submit CL

Invoke the Submission workflow, passing:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.