Skip to content

Latest commit

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Code style for Airlift projects

IntelliJ IDEA 14 on Mac OS X

To install, copy IntelliJIdea14/Airlift.xml into ~/Library/Preferences/IntelliJIdea14/codestyles

IntelliJ IDEA 14 on Linux

To install, copy IntelliJIdea14/Airlift.xml into $HOME/.IdeaIC14/config/codestyles

Examples

Generated from Intellij IDEA's code formatting preview.

Tabs and Indents

publicclassFoo
{
publicint[] X = newint[] {1, 3, 57, 9, 11};
publicvoidfoo(booleana, intx, inty, intz)
{
label1:
do {
try {
if (x > 0) {
intsomeVariable = a ? x : y;
intanotherVariable = a ? x : y;
}
elseif (x < 0) {
intsomeVariable = (y + z);
someVariable = x = x + y;
}
else {
label2:
for (inti = 0; i < 5; i++) {
doSomething(i);
}
}
switch (a) {
case0:
doCase0();
break;
default:
doDefault();
}
}
catch (Exceptione) {
processException(e.getMessage(), x + y, z, a);
}
finally {
processFinally();
}
}
while (true);
if (2 < 3) {
return;
}
if (3 < 4) {
return;
}
do {
x++
}
while (x < 10000);
while (x < 50000) {
x++;
}
for (inti = 0; i < 5; i++) {
System.out.println(i);
}
}
privateclassInnerClassimplementsI1, I2
{
publicvoidbar()
throwsE1, E2
{
}
}
}

Spaces

@Annotation(param1 = "value1", param2 = "value2")
@SuppressWarnings({"ALL"})
publicclassFoo<T, U>
{
int[] X = newint[] {1, 3, 5, 6, 7, 87, 1213, 2};
publicvoidfoo(intx, inty)
{
Runnabler = () -> {
};
Runnabler1 = this::bar;
for (inti = 0; i < x; i++) {
y += (y ^ 0x123) << 2;
}
do {
try (MyResourcer1 = getResource(); MyResourcer2 = null) {
if (0 < x && x < 10) {
while (x != y) {
x = f(x * 3 + 5);
}
}
else {
synchronized (this) {
switch (e.getCode()) {
//...
}
}
}
}
catch (MyExceptione) {
}
finally {
int[] arr = (int[]) g(y);
x = y >= 0 ? arr[y] : -1;
}
}
while (true);
}
voidbar()
{
{
return;
}
}
}
classBar {}

Wrapping and Braces

/* * This is a sample file. */publicclassThisIsASampleClassextendsC1implementsI1, I2, I3, I4, I5
{
privateintf1 = 1;
privateStringfield2 = "";
publicvoidfoo1(inti1, inti2, inti3, inti4, inti5, inti6, inti7) {}
publicstaticvoidlongerMethod()
throwsException1,
Exception2, Exception3
{
// todo somethinginti = 0;
int[] a = newint[] {1, 2,
0x0052,
0x0053,
0x0054};
intvar1 = 1;
intvar2 = 2;
foo1(0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057);
intx = (3 + 4 + 5 + 6) * (7 + 8 + 9 + 10) * (11 + 12 + 13 + 14 + 0xFFFFFFFF);
Strings1, s2, s3;
s1 = s2 = s3 = "012345678901456";
asserti + j + k + l + n + m <= 2 :
"assert description";
inty = 2 > 3 ? 7 + 8 + 9 : 11 + 12 + 13;
super.getFoo().foo().getBar().bar();
label:
if (2 < 3) {
return;
}
elseif (2 > 3) {
return;
}
else {
return;
}
for (inti = 0; i < 0xFFFFFF; i += 2) {
System.out.println(i);
}
while (x < 50000) {
x++;
}
do {
x++
}
while (x < 10000);
switch (a) {
case0:
doCase0();
break;
default:
doDefault();
}
try (MyResourcer1 = getResource(); MyResourcer2 = null) {
doSomething();
}
catch (Exceptione) {
processException(e);
}
finally {
processFinally();
}
do {
x--;
}
while (x > 10)
}
publicstaticvoidtest()
throwsException
{
foo.foo().bar("arg1",
"arg2");
newObject() {};
}
classTestInnerClass {}
interfaceTestInnerInterface {}
}
enumBreed
{
Dalmatian(), Labrador(), Dachshund()
}
@Annotation1@Annotation2@Annotation3(param1 = "value1", param2 = "value2")
@Annotation4classFoo
{
@Annotation1@Annotation3(param1 = "value1", param2 = "value2")
publicstaticvoidfoo()
{
}
@Annotation1@Annotation3(param1 = "value1", param2 = "value2") publicstaticintmyFoo;
publicvoidmethod(@Annotation1@Annotation3(param1 = "value1", param2 = "value2") finalintparam)
{
@Annotation1@Annotation3(param1 = "value1", param2 = "value2") finalintlocalVariable;
}
}

Blank Lines

/* * This is a sample file. */packagecom.intellij.samples;
importcom.intellij.idea.Main;
importjavax.swing.*;
importjava.util.Vector;
publicclassFoo
{
privateintfield1;
privateintfield2;
publicvoidfoo1()
{
newRunnable()
{
publicvoidrun()
{
}
}
}
publicclassInnerClass
{
}
}
classAnotherClass
{
}
interfaceTestInterface
{
intMAX = 10;
intMIN = 1;
voidmethod1();
voidmethod2();
}

JavaDoc

General guidelines

  • Do not include @author tags. The commit history is enough for this purpose.

Example

packagesample;
publicclassSample
{
/** * This is a method description that is long enough to exceed right margin. * <p/> * Another paragraph of the description placed after blank line. * <p/> * Line with manual * line feed. * * @param i short named parameter description * @param longParameterName long named parameter description * @param missingDescription * @return return description. * @throws XXXException description. * @throws YException description. * @throws ZException * @invalidTag */publicabstractStringsampleMethod(inti, intlongParameterName, intmissingDescription)
throwsXXXException, YException, ZException;
/** * One-line comment */publicabstractStringsampleMethod2();
/** * Simple method description * * @return */publicabstractStringsampleMethod3();

About

Code style for Airlift projects

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors