Development Environment

Terminal and Tools

I've written some ansible playbooks to configure my terminal and install all of my tools (zsh, tmux, nvim, java, js etc.)

See the dev-environment repository on GitHub for more information on running the playbooks or trying things out in docker.

JetBrains

JetBrains Toolbox App

Use the JetBrains Toolbox App to install all JetBrains tools to ensure easy automatic updates, rollbacks etc.

Enable Settings Sync

Enable settings sync to synchronize plugins, keymaps, and other settings across multiple JetBrains tools.

Plugins

Show whitespace characters

Go to SettingsEditorGeneralAppearance and enable: Show whitespaces

Show method separators

Go to SettingsEditorGeneralAppearance and enable: Show method separators

Enable Font Ligatures

Go to SettingsEditorFont and enable: Enable font ligatures

Live Templates

Live templates can be used to quickly insert code snippets, boilerplate, or other text into your code.

You can use live templates by typing the abbreviation for the template and pressing Tab to expand it.

To manage live templates, navigate to:

SettingsEditorLive Templates

IntelliJ IDEA (Java) Live Templates

By default, IDEA comes pre-configured with a number of live templates. (See List of Java live templates for more information)

In addition to the default live templates, you can create your own custom live templates. Some examples of custom live templates that I have created include the following:

Measure Elapsed Time for Selection

Abbreviation: ntm - (nano time measure)

Surround with nanoSeconds based timer to measure elapsed time.

Variable Expression
$START_TIME$ "startTime"
$ELAPSED$ "elapsed"
$CHRONO_UNIT$ "SECONDS"

Template Text:

final long $START_TIME$ = System.nanoTime();
try {
    $SELECTION$
} finally {
    final java.time.Duration $ELAPSED$ = Duration.ofNanos(System.nanoTime() - $START_TIME$);
    final java.time.temporal.ChronoUnit unit = java.time.temporal.ChronoUnit.$CHRONO_UNIT$;
    System.out.printf("Elapsed time: %d %s%n", elapsed.get(unit), unit);
}

Example:

package org.example;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

public class Example {
    public static void main(String[] args) {
        final long startTime = System.nanoTime();
        try {
            someOperation();
        } finally {
            final Duration elapsed = Duration.ofNanos(System.nanoTime() - startTime);
            final ChronoUnit unit = ChronoUnit.SECONDS;
            System.out.printf("Elapsed time: %d %s%n", elapsed.get(unit), unit);
        }
    }

    private static void someOperation() {
        try {
            Thread.sleep(1_000);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
}

Add Logger(s)

SLF4J Logger

Abbreviation: slf - (Simple Logging Facade)

Add a private static final SLF4J LOGGER field.

Variable Expression
$CLASS_NAME$ qualifiedClassName()

Template Text:

private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger($CLASS_NAME$.class);

Example:

package org.example;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Example {
    private static final Logger LOGGER = LoggerFactory.getLogger(Example.class);
}
Log4J2 Logger

Abbreviation: l4j - (Logging For Java)

Add a private static final LOG4J2 LOGGER field.

Variable Expression
$CLASS_NAME$ qualifiedClassName()

Template Text:

private static final org.apache.logging.log4j.Logger LOGGER = org.apache.logging.log4j.LogManager.getLogger($CLASS_NAME$.class);

Example:

package org.example;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class Example {
    private static final Logger LOGGER = LogManager.getLogger(Example.class);
}

References