The following xml-file describes the Allman code style for IntelliJ IDEA and the Java-File below shows an example of the code style.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<code_scheme name="allman"> | |
<XML> | |
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" /> | |
</XML> | |
<codeStyleSettings language="JAVA"> | |
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" /> | |
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1" /> | |
<option name="BLANK_LINES_AFTER_CLASS_HEADER" value="1" /> | |
<option name="BRACE_STYLE" value="2" /> | |
<option name="CLASS_BRACE_STYLE" value="2" /> | |
<option name="METHOD_BRACE_STYLE" value="2" /> | |
<option name="CATCH_ON_NEW_LINE" value="true" /> | |
<option name="FINALLY_ON_NEW_LINE" value="true" /> | |
</codeStyleSettings> | |
</code_scheme> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Copyright 2015 d-fens GmbH | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
public class ThisIsASampleClass extends C1 implements I1, I2, I3, I4, I5 | |
{ | |
private int f1 = 1; | |
private String field2 = ""; | |
public void foo1(int i1, int i2, int i3, int i4, int i5, int i6, int i7) | |
{ | |
} | |
public static void longerMethod() throws Exception1, Exception2, Exception3 | |
{ | |
// todo something | |
int | |
i = 0; | |
int[] a = new int[]{1, 2, 0x0052, 0x0053, 0x0054}; | |
int[] empty = new int[]{}; | |
int var1 = 1; | |
int var2 = 2; | |
foo1(0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057); | |
int x = (3 + 4 + 5 + 6) * (7 + 8 + 9 + 10) * (11 + 12 + 13 + 14 + 0xFFFFFFFF); | |
String s1, s2, s3; | |
s1 = s2 = s3 = "012345678901456"; | |
assert i + j + k + l + n + m <= 2 : "assert description"; | |
int y = 2 > 3 ? 7 + 8 + 9 : 11 + 12 + 13; | |
super.getFoo().foo().getBar().bar(); | |
label: | |
if (2 < 3) return; | |
else if (2 > 3) return; | |
else return; | |
for (int i = 0; i < 0xFFFFFF; i += 2) | |
System.out.println(i); | |
while (x < 50000) x++; | |
do x++; while (x < 10000); | |
switch (a) | |
{ | |
case 0: | |
doCase0(); | |
break; | |
default: | |
doDefault(); | |
} | |
try (MyResource r1 = getResource(); MyResource r2 = null) | |
{ | |
doSomething(); | |
} | |
catch (Exception e) | |
{ | |
processException(e); | |
} | |
finally | |
{ | |
processFinally(); | |
} | |
do | |
{ | |
x–; | |
} while (x > 10); | |
} | |
public static void test() | |
throws Exception | |
{ | |
foo.foo().bar("arg1", | |
"arg2"); | |
new Object() | |
{ | |
}; | |
} | |
class TestInnerClass | |
{ | |
} | |
interface TestInnerInterface | |
{ | |
} | |
} | |
enum Breed | |
{ | |
Dalmatian(), Labrador(), Dachshund() | |
} | |
@Annotation1 | |
@Annotation2 | |
@Annotation3(param1 = "value1", param2 = "value2") | |
@Annotation4 | |
class Foo | |
{ | |
@Annotation1 | |
@Annotation3(param1 = "value1", param2 = "value2") | |
public static void foo() | |
{ | |
} | |
@Annotation1 | |
@Annotation3(param1 = "value1", param2 = "value2") | |
public static int myFoo; | |
public void method(@Annotation1 @Annotation3(param1 = "value1", param2 = "value2") final int param) | |
{ | |
@Annotation1 @Annotation3(param1 = "value1", param2 = "value2") final int localVariable; | |
} | |
} |
To import the settings to your IntelliJ IDEA go to Settings -> Settings -> Editor -> Code Style -> Java. Then click “Manage” and import the downloaded xml-file.
For Java development I recommend to use the following gitignore-file as a starting point.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Java | |
*.class | |
target/ | |
# Package Files | |
*.jar | |
*.war | |
*.ear | |
# IntelliJ | |
.idea/ | |
*.iml | |
*.iws | |
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | |
hs_err_pid* |