Skip to content

Commit d08e381

Browse files
authored
chore: add editorconfig (#5)
1 parent fe73257 commit d08e381

File tree

279 files changed

+17311
-19543
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

279 files changed

+17311
-19543
lines changed

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
end_of_line = lf
7+
indent_size = 2
8+
indent_style = tab
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
12+
[*.yml]
13+
indent_style = space
14+
15+
[*.md]
16+
trim_trailing_whitespace = false

.github/workflows/build.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,29 @@ jobs:
1313

1414
strategy:
1515
matrix:
16-
java: [ '8', '11', '17', '21' ] # all the LTS versions
16+
# all the LTS versions
17+
java: [ '8', '11', '17', '21' ]
1718
fail-fast: false
1819

1920
steps:
2021
- name: Checkout code
2122
uses: actions/checkout@v4
2223

23-
- name: Set up JDK ${{ matrix.java }}
24+
- name: Set up JDK 17 (for Gradle/Spotless)
2425
uses: actions/setup-java@v4
2526
with:
26-
java-version: ${{ matrix.java }}
27+
java-version: '17'
2728
distribution: 'temurin'
2829

2930
- name: Setup Gradle
30-
uses: gradle/gradle-build-action@v3
31+
uses: gradle/actions/setup-gradle@v5
3132

32-
- name: Build with Gradle
33-
run: ./gradlew build --no-daemon
33+
- name: Check code formatting
34+
# older versions are incompatible with our spotless version
35+
if: matrix.java == '17' || matrix.java == '21'
36+
run: ./gradlew spotlessCheck --no-daemon
37+
38+
- name: Build and test with JDK ${{ matrix.java }}
39+
run: ./gradlew build --no-daemon -PjavaToolchain=${{ matrix.java }}
40+
env:
41+
GRADLE_OPTS: -Dorg.gradle.java.installations.auto-download=true

.vscode/extensions.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"editorconfig.editorconfig",
4+
"richardwillis.vscode-spotless-gradle"
5+
]
6+
}

.vscode/settings.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"java.format.enabled": false,
3+
"files.trimTrailingWhitespace": false,
4+
"spotlessGradle.diagnostics.enable": true,
5+
"spotlessGradle.format.enable": true,
6+
"editor.codeActionsOnSave": {
7+
"source.fixAll.spotlessGradle": "explicit"
8+
},
9+
"[java]": {
10+
"editor.defaultFormatter": "richardwillis.vscode-spotless-gradle"
11+
},
12+
"[gradle]": {
13+
"editor.defaultFormatter": "richardwillis.vscode-spotless-gradle"
14+
},
15+
"java.configuration.updateBuildConfiguration": "automatic"
16+
}

build.gradle

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,80 @@
11
plugins {
2-
id 'java'
3-
id 'application'
2+
id 'java'
3+
id 'application'
4+
id 'com.diffplug.spotless' version '6.25.0'
45
}
56

67
group = 'nsl'
78
version = '1.0-SNAPSHOT'
89

910
java {
10-
sourceCompatibility = JavaVersion.VERSION_1_8
11-
targetCompatibility = JavaVersion.VERSION_1_8
11+
// Use toolchain to compile with specified Java version
12+
// This allows Gradle to run with Java 11+ (for Spotless) while compiling for target version
13+
toolchain {
14+
// Default to Java 8, but can be overridden via -PjavaToolchain=X
15+
def toolchainVersion = project.hasProperty('javaToolchain') ? project.property('javaToolchain') : '8'
16+
languageVersion = JavaLanguageVersion.of(toolchainVersion)
17+
}
1218
}
1319

1420
application {
15-
mainClass = 'nsl.Main'
21+
mainClass = 'nsl.Main'
1622
}
1723

1824
repositories {
19-
mavenCentral()
25+
mavenCentral()
2026
}
2127

2228
dependencies {
23-
testImplementation 'junit:junit:4.12'
24-
testImplementation 'org.hamcrest:hamcrest-core:1.3'
29+
testImplementation 'junit:junit:4.12'
30+
testImplementation 'org.hamcrest:hamcrest-core:1.3'
2531
}
2632

2733
// Configure JAR manifest
2834
jar {
29-
manifest {
30-
attributes(
31-
'Main-Class': 'nsl.Main'
32-
)
33-
}
34-
archiveFileName = 'nsL.jar'
35+
manifest {
36+
attributes(
37+
'Main-Class': 'nsl.Main'
38+
)
39+
}
40+
archiveFileName = 'nsL.jar'
3541
}
3642

3743
// Configure source and test directories to match existing structure
3844
sourceSets {
39-
main {
40-
java {
41-
srcDir 'src'
42-
}
43-
}
44-
test {
45-
java {
46-
srcDir 'test'
47-
}
48-
}
45+
main {
46+
java {
47+
srcDir 'src'
48+
}
49+
}
50+
test {
51+
java {
52+
srcDir 'test'
53+
}
54+
}
4955
}
5056

5157
// Configure test output
5258
test {
53-
testLogging {
54-
events "passed", "skipped", "failed"
55-
exceptionFormat "full"
56-
showStandardStreams = true
57-
}
59+
testLogging {
60+
events "passed", "skipped", "failed"
61+
exceptionFormat "full"
62+
showStandardStreams = true
63+
}
64+
}
65+
66+
// Configure code formatting with Spotless
67+
spotless {
68+
java {
69+
target 'src/**/*.java', 'test/**/*.java'
70+
71+
// Use Google Java Format with explicit version for Java 21 compatibility
72+
googleJavaFormat('1.22.0')
73+
74+
// Additional formatting
75+
removeUnusedImports()
76+
indentWithTabs(2)
77+
trimTrailingWhitespace()
78+
endWithNewline()
79+
}
5880
}

settings.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Configure toolchain resolver to auto-download JDKs
2+
plugins {
3+
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
4+
}
5+
6+
rootProject.name = 'nsl-assembler'

src/nsl/CodeInfo.java

Lines changed: 81 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -7,102 +7,98 @@
77
import java.util.HashMap;
88

99
/**
10-
*
1110
* @author Stuart
1211
*/
13-
public abstract class CodeInfo
14-
{
15-
protected static CodeInfo current = null;
12+
public abstract class CodeInfo {
13+
protected static CodeInfo current = null;
1614

17-
protected final HashMap<Integer, Register> usedVars;
15+
protected final HashMap<Integer, Register> usedVars;
1816

19-
private Label labelBreak;
20-
private Label labelContinue;
17+
private Label labelBreak;
18+
private Label labelContinue;
2119

22-
protected CodeInfo()
23-
{
24-
this.usedVars = new HashMap<Integer, Register>();
25-
this.labelBreak = null;
26-
this.labelContinue = null;
27-
}
20+
protected CodeInfo() {
21+
this.usedVars = new HashMap<Integer, Register>();
22+
this.labelBreak = null;
23+
this.labelContinue = null;
24+
}
2825

29-
/**
30-
* Gets the variables used in the function.
31-
* @return the variables used in the function
32-
*/
33-
public HashMap<Integer, Register> getUsedVars()
34-
{
35-
return this.usedVars;
36-
}
26+
/**
27+
* Gets the variables used in the function.
28+
*
29+
* @return the variables used in the function
30+
*/
31+
public HashMap<Integer, Register> getUsedVars() {
32+
return this.usedVars;
33+
}
3734

38-
/**
39-
* Gets the current go-to label for a "break" instruction.
40-
* @return the current go-to label for a "break" instruction
41-
*/
42-
public Label getBreakLabel()
43-
{
44-
return this.labelBreak;
45-
}
35+
/**
36+
* Gets the current go-to label for a "break" instruction.
37+
*
38+
* @return the current go-to label for a "break" instruction
39+
*/
40+
public Label getBreakLabel() {
41+
return this.labelBreak;
42+
}
4643

47-
/**
48-
* Sets the current go-to label for a "break" instruction.
49-
* @param labelBreak the current go-to label for a "break" instruction
50-
* @return the original value
51-
*/
52-
public Label setBreakLabel(Label labelBreak)
53-
{
54-
Label old = this.labelBreak;
55-
this.labelBreak = labelBreak;
56-
return old;
57-
}
44+
/**
45+
* Sets the current go-to label for a "break" instruction.
46+
*
47+
* @param labelBreak the current go-to label for a "break" instruction
48+
* @return the original value
49+
*/
50+
public Label setBreakLabel(Label labelBreak) {
51+
Label old = this.labelBreak;
52+
this.labelBreak = labelBreak;
53+
return old;
54+
}
5855

59-
/**
60-
* Gets the current go-to label for a "continue" instruction.
61-
* @return the current go-to label for a "continue" instruction
62-
*/
63-
public Label getContinueLabel()
64-
{
65-
return this.labelContinue;
66-
}
56+
/**
57+
* Gets the current go-to label for a "continue" instruction.
58+
*
59+
* @return the current go-to label for a "continue" instruction
60+
*/
61+
public Label getContinueLabel() {
62+
return this.labelContinue;
63+
}
6764

68-
/**
69-
* Sets the current go-to label for a "continue" instruction.
70-
* @param labelBreak the current go-to label for a "continue" instruction
71-
* @return the original value
72-
*/
73-
public Label setContinueLabel(Label labelContinue)
74-
{
75-
Label old = this.labelContinue;
76-
this.labelContinue = labelContinue;
77-
return old;
78-
}
65+
/**
66+
* Sets the current go-to label for a "continue" instruction.
67+
*
68+
* @param labelBreak the current go-to label for a "continue" instruction
69+
* @return the original value
70+
*/
71+
public Label setContinueLabel(Label labelContinue) {
72+
Label old = this.labelContinue;
73+
this.labelContinue = labelContinue;
74+
return old;
75+
}
7976

80-
/**
81-
* Adds a variable to the used variables list.
82-
* @param var the variable to add
83-
*/
84-
public void addUsedVar(Register var)
85-
{
86-
Integer key = Integer.valueOf(var.getIntegerValue());
87-
if (this.usedVars.get(key) == null)
88-
this.usedVars.put(key, var);
89-
}
77+
/**
78+
* Adds a variable to the used variables list.
79+
*
80+
* @param var the variable to add
81+
*/
82+
public void addUsedVar(Register var) {
83+
Integer key = Integer.valueOf(var.getIntegerValue());
84+
if (this.usedVars.get(key) == null) this.usedVars.put(key, var);
85+
}
9086

91-
/**
92-
* Gets the current code info.
93-
* @return the current code info
94-
*/
95-
public static CodeInfo getCurrent()
96-
{
97-
return current;
98-
}
87+
/**
88+
* Gets the current code info.
89+
*
90+
* @return the current code info
91+
*/
92+
public static CodeInfo getCurrent() {
93+
return current;
94+
}
9995

100-
/**
101-
* Sets the current code info.
102-
* @param codeInfo the current code info
103-
*/
104-
public static void setCurrent(CodeInfo codeInfo)
105-
{
106-
current = codeInfo;
107-
}
96+
/**
97+
* Sets the current code info.
98+
*
99+
* @param codeInfo the current code info
100+
*/
101+
public static void setCurrent(CodeInfo codeInfo) {
102+
current = codeInfo;
103+
}
108104
}

0 commit comments

Comments
 (0)