Skip to content

Commit 06b3397

Browse files
committed
spotless reformat
1 parent 4df5895 commit 06b3397

File tree

84 files changed

+1079
-1121
lines changed

Some content is hidden

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

84 files changed

+1079
-1121
lines changed

build.gradle

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,26 +71,8 @@ tasks.withType(Test).configureEach {
7171
}
7272

7373
spotless {
74-
75-
format 'misc', {
76-
// define the files to apply `misc` to
77-
target '*.gradle', '.gitattributes', '.gitignore', '.editorconfig', '*.cff' , '*.md', 'gradlew', 'gradlew.bat'
78-
79-
// define the steps to apply to those files
80-
trimTrailingWhitespace()
81-
indentWithTabs() // or spaces. Takes an integer argument if you don't like 4
82-
endWithNewline()
83-
}
8474
java {
85-
// don't need to set target, it is inferred from java
86-
87-
// apply a specific flavor of google-java-format
88-
googleJavaFormat('1.17.0').aosp().reflowLongStrings().skipJavadocFormatting()
89-
// fix formatting of type annotations
90-
formatAnnotations()
91-
// make sure every file has the following copyright header.
92-
// optionally, Spotless can set copyright years by digging
93-
// through git history (see "license" section below)
94-
licenseHeader '/* (C)$YEAR */'
75+
googleJavaFormat().aosp().reflowLongStrings()
76+
target '**/*.java'
9577
}
9678
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package CBuilder;
22

33
/**
4-
* Something that returns the C representation of a MiniPython object, e. g. a function call or a literal.
4+
* Something that returns the C representation of a MiniPython object, e. g. a function call or a
5+
* literal.
56
*/
67
public interface Expression extends Statement {
78

@@ -11,5 +12,4 @@ public interface Expression extends Statement {
1112
* @return A String with the c-code that evaluates to the containing MiniPython object.
1213
*/
1314
String buildExpression();
14-
1515
}

src/main/java/CBuilder/ManualTest.java

Lines changed: 166 additions & 117 deletions
Large diffs are not rendered by default.

src/main/java/CBuilder/ProgramBuilder.java

Lines changed: 79 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package CBuilder;
22

3+
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
4+
35
import CBuilder.objects.MPyClass;
46
import CBuilder.objects.functions.Function;
57
import CBuilder.objects.functions.ReturnStatement;
68
import CBuilder.variables.VariableDeclaration;
7-
89
import java.io.IOException;
910
import java.net.URI;
1011
import java.net.URISyntaxException;
@@ -16,59 +17,45 @@
1617
import java.util.stream.Collectors;
1718
import java.util.stream.Stream;
1819

19-
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
20-
21-
/**
22-
* Entrypoint to creating C code from a MiniPython AST.
23-
*/
20+
/** Entrypoint to creating C code from a MiniPython AST. */
2421
public class ProgramBuilder {
2522

26-
/**
27-
* Definition of the c-runtime header files.
28-
*/
23+
/** Definition of the c-runtime header files. */
2924
private static final String[] headers = {
30-
// allow usage of assertions
31-
"assert",
32-
// aliases mapping python names to the internal c names
33-
"mpy_aliases",
34-
// ref-counting
35-
"mpy_obj",
36-
// initialisation
37-
"builtins-setup",
38-
// building function args
39-
"function-args",
40-
"literals/tuple",
41-
"literals/int",
42-
"literals/boolean",
43-
"literals/str",
44-
"type-hierarchy/object",
45-
// custom objects
46-
"type-hierarchy/type",
25+
// allow usage of assertions
26+
"assert",
27+
// aliases mapping python names to the internal c names
28+
"mpy_aliases",
29+
// ref-counting
30+
"mpy_obj",
31+
// initialisation
32+
"builtins-setup",
33+
// building function args
34+
"function-args",
35+
"literals/tuple",
36+
"literals/int",
37+
"literals/boolean",
38+
"literals/str",
39+
"type-hierarchy/object",
40+
// custom objects
41+
"type-hierarchy/type",
4742
};
4843

49-
/**
50-
* A list of all statements in the global scope.
51-
*/
44+
/** A list of all statements in the global scope. */
5245
private final List<Statement> statements;
5346

54-
/**
55-
* A list of all defined variables in the global scope.
56-
*/
47+
/** A list of all defined variables in the global scope. */
5748
private final List<VariableDeclaration> globalVariables;
5849

59-
/**
60-
* A list of all defined functions in the global scope.
61-
*/
50+
/** A list of all defined functions in the global scope. */
6251
private final List<Function> globalFunctions;
6352

64-
/**
65-
* A list of all defined classes in th global scope.
66-
*/
53+
/** A list of all defined classes in th global scope. */
6754
private final List<MPyClass> classes;
6855

6956
/**
70-
* Create a new program with empty global scope.
71-
* Allows to manually specify options regarding c-code generation.
57+
* Create a new program with empty global scope. Allows to manually specify options regarding
58+
* c-code generation.
7259
*/
7360
public ProgramBuilder() {
7461
statements = new LinkedList<>();
@@ -78,14 +65,15 @@ public ProgramBuilder() {
7865
}
7966

8067
/**
81-
* Add a new statement to the global scope.
82-
* The resulting statement list more or less represents the program's main method.
68+
* Add a new statement to the global scope. The resulting statement list more or less represents
69+
* the program's main method.
8370
*
8471
* @param statement The statement to add.
8572
*/
8673
public void addStatement(Statement statement) {
8774
if (statement instanceof ReturnStatement) {
88-
// I'd prefer to have this type safe (i. e. different statement interfaces for global/non-global scope,
75+
// I'd prefer to have this type safe (i. e. different statement interfaces for
76+
// global/non-global scope,
8977
// but this is just a prototype after all and shouldn't happen too often anyway)
9078
throw new IllegalArgumentException("Cannot return from global scope");
9179
}
@@ -204,8 +192,11 @@ public String buildProgram() {
204192

205193
body.append("return 0;\n");
206194

207-
program.append(body.toString().lines().map(string -> "\t" + string + "\n").collect(
208-
Collectors.joining()));
195+
program.append(
196+
body.toString()
197+
.lines()
198+
.map(string -> "\t" + string + "\n")
199+
.collect(Collectors.joining()));
209200
program.append("}\n");
210201

211202
return program.toString();
@@ -235,7 +226,12 @@ public void writeProgram(Path destDir) {
235226

236227
try {
237228
Path output = Path.of(destDir.toString(), "src/program.c");
238-
java.nio.file.Files.writeString(output, this.buildProgram(), java.nio.file.StandardOpenOption.CREATE, java.nio.file.StandardOpenOption.WRITE, java.nio.file.StandardOpenOption.TRUNCATE_EXISTING);
229+
java.nio.file.Files.writeString(
230+
output,
231+
this.buildProgram(),
232+
java.nio.file.StandardOpenOption.CREATE,
233+
java.nio.file.StandardOpenOption.WRITE,
234+
java.nio.file.StandardOpenOption.TRUNCATE_EXISTING);
239235
} catch (java.io.IOException e) {
240236
throw new RuntimeException("Failed to write 'program.c'!", e);
241237
}
@@ -250,13 +246,18 @@ public void writeProgram(Path destDir) {
250246
*/
251247
public void copyFolder(Path srcDir, Path destDir) throws IOException {
252248
try (Stream<Path> stream = Files.walk(srcDir)) {
253-
stream.forEach(source -> {
254-
try {
255-
Files.copy(source, destDir.resolve(srcDir.relativize(source)), REPLACE_EXISTING);
256-
} catch (IOException e) {
257-
throw new RuntimeException("Failed to copy template folder to output directory", e);
258-
}
259-
});
249+
stream.forEach(
250+
source -> {
251+
try {
252+
Files.copy(
253+
source,
254+
destDir.resolve(srcDir.relativize(source)),
255+
REPLACE_EXISTING);
256+
} catch (IOException e) {
257+
throw new RuntimeException(
258+
"Failed to copy template folder to output directory", e);
259+
}
260+
});
260261
}
261262
}
262263

@@ -265,29 +266,37 @@ public void copyFolder(Path srcDir, Path destDir) throws IOException {
265266
*
266267
* @param resourcePath The Path to the jar archive.
267268
* @param targetLocation The output directory.
268-
* @throws URISyntaxException Will be thrown if the c-runtime can not be found in the application resources.
269+
* @throws URISyntaxException Will be thrown if the c-runtime can not be found in the
270+
* application resources.
269271
* @throws IOException Will be thrown if a needed file or folder is not accessible.
270272
*/
271-
public void copyFolderFromJar(String resourcePath, final Path targetLocation) throws URISyntaxException, IOException {
273+
public void copyFolderFromJar(String resourcePath, final Path targetLocation)
274+
throws URISyntaxException, IOException {
272275
URI resource = getClass().getResource("/c-runtime").toURI();
273276

274277
try (FileSystem fileSystem = FileSystems.newFileSystem(resource, Map.of())) {
275278
final Path jarArchive = fileSystem.getPath(resourcePath);
276-
Files.walkFileTree(jarArchive, new SimpleFileVisitor<>() {
277-
@Override
278-
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
279-
Files.createDirectories(targetLocation.resolve(jarArchive.relativize(dir).toString()));
280-
return FileVisitResult.CONTINUE;
281-
}
282-
283-
@Override
284-
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
285-
Files.copy(file, targetLocation.resolve(jarArchive.relativize(file).toString()), REPLACE_EXISTING);
286-
return FileVisitResult.CONTINUE;
287-
}
288-
289-
});
279+
Files.walkFileTree(
280+
jarArchive,
281+
new SimpleFileVisitor<>() {
282+
@Override
283+
public FileVisitResult preVisitDirectory(
284+
Path dir, BasicFileAttributes attrs) throws IOException {
285+
Files.createDirectories(
286+
targetLocation.resolve(jarArchive.relativize(dir).toString()));
287+
return FileVisitResult.CONTINUE;
288+
}
289+
290+
@Override
291+
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
292+
throws IOException {
293+
Files.copy(
294+
file,
295+
targetLocation.resolve(jarArchive.relativize(file).toString()),
296+
REPLACE_EXISTING);
297+
return FileVisitResult.CONTINUE;
298+
}
299+
});
290300
}
291301
}
292-
293302
}

src/main/java/CBuilder/Reference.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
package CBuilder;
22

3-
/**
4-
* Representation of a reference to a MiniPython variable, i. e. a variable name.
5-
*/
3+
/** Representation of a reference to a MiniPython variable, i. e. a variable name. */
64
public class Reference implements Expression {
75

8-
/**
9-
* The name of the reference.
10-
*/
6+
/** The name of the reference. */
117
protected String name;
128

139
/**
@@ -24,7 +20,9 @@ public Reference(String name) {
2420
*
2521
* @return The name of the reference.
2622
*/
27-
public String getName() { return this.name; }
23+
public String getName() {
24+
return this.name;
25+
}
2826

2927
@Override
3028
public String buildExpression() {
@@ -35,5 +33,4 @@ public String buildExpression() {
3533
public String buildStatement() {
3634
return name + ";\n";
3735
}
38-
3936
}

src/main/java/CBuilder/Statement.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package CBuilder;
22

33
/**
4-
* C representation of anything that does something in MiniPython, e. g. assignments, control structures, function calls.
4+
* C representation of anything that does something in MiniPython, e. g. assignments, control
5+
* structures, function calls.
56
*/
67
public interface Statement {
78

@@ -11,5 +12,4 @@ public interface Statement {
1112
* @return A String which represents the c-code of the statement.
1213
*/
1314
String buildStatement();
14-
1515
}

src/main/java/CBuilder/conditions/IfThenElseStatement.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,19 @@
44
import CBuilder.conditions.conditionalStatement.ElifStatement;
55
import CBuilder.conditions.conditionalStatement.ElseStatement;
66
import CBuilder.conditions.conditionalStatement.IfStatement;
7-
87
import java.util.List;
98
import java.util.Optional;
109

11-
/**
12-
* A MiniPython if (/else if/else) block.
13-
*/
10+
/** A MiniPython if (/else if/else) block. */
1411
public class IfThenElseStatement implements Statement {
1512

16-
/**
17-
* The containing if block.
18-
*/
13+
/** The containing if block. */
1914
private IfStatement ifStatement;
2015

21-
/**
22-
* A list of the containing elif blocks.
23-
*/
16+
/** A list of the containing elif blocks. */
2417
private Optional<List<ElifStatement>> elifStatements;
2518

26-
/**
27-
* The containing else block.
28-
*/
19+
/** The containing else block. */
2920
private Optional<ElseStatement> elseStatement;
3021

3122
/**
@@ -35,7 +26,10 @@ public class IfThenElseStatement implements Statement {
3526
* @param elifStatements An optional list of elif statements.
3627
* @param elseStatement An optional else statement.
3728
*/
38-
public IfThenElseStatement(IfStatement ifStatement, Optional<List<ElifStatement>> elifStatements, Optional<ElseStatement> elseStatement) {
29+
public IfThenElseStatement(
30+
IfStatement ifStatement,
31+
Optional<List<ElifStatement>> elifStatements,
32+
Optional<ElseStatement> elseStatement) {
3933
this.ifStatement = ifStatement;
4034
this.elifStatements = elifStatements;
4135
this.elseStatement = elseStatement;

0 commit comments

Comments
 (0)