Java Method Sorter

April 1, 2026 · View on GitHub

A Visual Studio Code extension that sorts methods in Java classes to increase code readability.

Features

  • Sort methods in Java classes based on multiple criteria:
    • Access level (public, protected, package, private)
    • Constructor separation
    • Invocation order (depth-first or breadth-first)
    • Lexical (alphabetical) ordering
  • Cluster overloaded methods together
  • Cluster getter and setter methods together
  • Shuffle methods randomly (for testing purposes)
  • Context menu integration
  • Keyboard shortcut support

Usage

Sort Methods

  1. Open a Java source file
  2. Right-click in the editor and select tlcsdmSort Methods
  3. Or use the keyboard shortcut Alt+S
  4. Or run the command "Sort Methods" from the Command Palette (Ctrl+Shift+P)

Shuffle Methods Randomly

  1. Open a Java source file
  2. Right-click in the editor and select tlcsdmShuffle Methods Randomly
  3. Or run the command "Shuffle Methods Randomly" from the Command Palette

Configuration

Configure the sorting behavior through VS Code settings:

SettingDescriptionDefault
tlcsdm.methodsorter.sortingStrategyInvocation ordering strategy: depth-first or breadth-firstdepth-first
tlcsdm.methodsorter.applyWorkingListHeuristicsApply heuristics to determine start pointstrue
tlcsdm.methodsorter.respectBeforeAfterRelationRespect before/after relation in method orderingtrue
tlcsdm.methodsorter.clusterOverloadedMethodsKeep overloaded methods togetherfalse
tlcsdm.methodsorter.clusterGetterSetterKeep getter and setter methods togetherfalse
tlcsdm.methodsorter.separateByAccessLevelSeparate methods by access leveltrue
tlcsdm.methodsorter.separateConstructorsSeparate constructors from other methodstrue
tlcsdm.methodsorter.applyLexicalOrderingApply lexical ordering as a secondary sorttrue

Sorting Order

When all options are enabled, methods are sorted in the following order:

  1. Constructors - Constructors come first
  2. Static methods - Static methods are grouped together
  3. Access level - Methods are grouped by access level:
    • Public methods
    • Protected methods
    • Package-private methods
    • Private methods
  4. Invocation order - Methods that call other methods come before the methods they call
  5. Lexical order - Alphabetical ordering of method names
  6. Original position - Maintains original order when all other criteria are equal

Installation

From VS Code Marketplace

  1. Open VS Code
  2. Go to Extensions (Ctrl+Shift+X)
  3. Search for "tlcsdm-java-method-sorter"
  4. Click Install

From VSIX File

  1. Download the .vsix file from Releases
  2. In VS Code, open Command Palette (Ctrl+Shift+P)
  3. Search for "Extensions: Install from VSIX..."
  4. Select the downloaded .vsix file

From Jenkins

Download from Jenkins

Build

This project uses TypeScript and npm (Node.js 22).

# Install dependencies
npm install

# Compile
npm run compile

# Watch mode (for development)
npm run watch

# Lint
npm run lint

# Package
npx @vscode/vsce package

# Test
npm run test

License

This project is licensed under the MIT License - see the LICENSE file for details.