IntelliJ IDEA
package chain
code folding
IDE tips
programming tools

How to expand folded package chain in Intellij IDEA?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

In IntelliJ IDEA, expanding a folded package chain is a common task when navigating your project's structure to gain a clearer view of your codebase. IntelliJ offers robust navigational features to manage these tasks efficiently. This article provides a comprehensive guide on how to expand folded package chains, examining the technical components and offering examples to streamline your usage of IntelliJ IDEA.

Understanding Folded Package Chains

What Are Folded Package Chains?

Folded package chains are a concise visualization tool in IntelliJ that displays a shorthand of nested packages in the Project tool window. Instead of displaying each package level in the hierarchy, IntelliJ compresses the hierarchy so you can focus on higher-level organizational aspects without being bogged down in details. When you want a more granular view, you need to expand these folded package chains.

Why Expand Package Chains?

Expanding package chains can be necessary when:

  • You want to understand the complete structure of your codebase.
  • You're looking for a specific class or file deep within the hierarchy.
  • You're refactoring and need to relocate classes or packages.

Step-by-Step Guide to Expand Folded Package Chains

Manual Expansion

  1. Navigate to the Project Tool Window:
    • Open IntelliJ IDEA.
    • Ensure the Project tool window is visible (usually located on the left-hand side).
  2. Locate the Folded Package Chain:
    • Identify the package chain you wish to expand. It will look like a concatenated path, e.g., com.example.myproject.
  3. Expand the Package:
    • Click the small triangle or arrow indicator next to the concatenated package name. It will reveal the packages within the chain and present them in an expanded view.

Using the Keyboard Shortcut

  • IntelliJ IDEA provides keyboard shortcuts to navigate and expand items without using the mouse.
  • To expand the currently selected node in the Project tool window:
    • Use Right Arrow (for Windows/Linux) or Cmd + Right Arrow (for macOS).
    • To expand all subnodes: Ctrl + Plus (numpad) or Cmd + Plus (for macOS).

Configuring Package Presentation

You can alter how package chains appear by customizing package presentation:

  1. Open Settings:
    • Go to File | Settings (or IntelliJ IDEA | Preferences on macOS).
  2. Navigate to Project View:
    • Go to Appearance & Behavior | System Settings | Project View.
  3. Uncheck the Compact Middle Packages:
    • By default, IntelliJ compresses middle packages to keep the view more compact. Uncheck it to expand all packages by default.

Example

Imagine the following package structure:

 
1src
2└── com
3    └── example
4        └── myproject
5            ├── utilities
6            │   └── Helper.java
7            └── services
8                └── MyService.java

In the Project tool window, this might initially appear as com.example.myproject, which you can expand to show utilities and services packages.

Key Points and Data Summary

FeatureActionShortcut
Manual ExpansionClick the arrow next to the package in ProjectN/A
Expand Using KeyboardRight Arrow / Cmd + Right ArrowRight Arrow (Win/Linux) Cmd + Right Arrow (macOS)
Expand All SubnodesCtrl + Plus / Cmd + PlusCtrl + Plus (Win/Linux) Cmd + Plus (macOS)
Disable Compact Middle PackagesSettings > Appearance > Project View > Uncheck OptionN/A

Additional Tips

  • Use the Structure Tool Window: While expanding packages gives a broader view, use the Structure tool window for detailed class-level insights.
  • Favorites and Scope: Customize your view with favorites or restrict views using scopes to focus on specific parts of your project. This can reduce the need to expand many package levels unnecessarily.

By mastering expanding folded package chains and understanding IntelliJ IDEA's project navigation options, you can significantly streamline your workflow and improve the efficiency of your navigation through large codebases.


Course illustration
Course illustration

All Rights Reserved.