Code Conventions - open-osrs/runelite GitHub Wiki
Coding Format
A full code formatting example is available at the end of this page.
We follow standard Java conventions with the following notable exceptions:
- Tabs, not spaces.
- Brace placement is always next line.
The following are some common mistakes not covered by the code style check:
- Add the copyright header to the beginning of every new text file.
- Imports in a single logical block.
- A single blank line separating logical blocks.
- An extra tab on multi line annotations.
See Checkstyle with IntelliJ IDEA on how to set up an IntelliJ build configuration with automatic checkstyle.
To setup IntelliJ Idea with correct project code-style, download this xml and follow this guide to import it into your IDE.
Imports
We also don't like overhaul of wildcard imports, so please turn those off
- By changing
Class count to use import with '*'
to 999 - By changing
Names count to use static imports with '*'
to 10 (static imports for f.e. ItemIDs with wildcards are preferred)
See screenshot below for correct values for mentioned 2 fields.
IntelliJ's default Code Style will optimize and re-order imports. To disable the re-ordering of imports, remove the section in the Import Layout list.
Also remove the entries in Packages to Use Import with '*'
to stop the replacement of i.e import java.awt.Canvas
with import java.awt.*
.
The following gives an example of well formatted code:
/*
* Copyright (c) 2018, Tomas Slusny <[email protected]>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.tileindicators;
import com.google.inject.Provides;
import javax.inject.Inject;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.OverlayManager;
@PluginDescriptor(
name = "Tile Indicators",
description = "Highlight the tile you are currently moving to",
tags = {"highlight", "overlay"},
enabledByDefault = false
)
public class TileIndicatorsPlugin extends Plugin
{
@Inject
private OverlayManager overlayManager;
@Inject
private TileIndicatorsOverlay overlay;
@Provides
TileIndicatorsConfig provideConfig(ConfigManager configManager)
{
return configManager.getConfig(TileIndicatorsConfig.class);
}
@Override
protected void startUp() throws Exception
{
overlayManager.add(overlay);
}
@Override
protected void shutDown() throws Exception
{
overlayManager.remove(overlay);
}
}