|
1 | 1 | # Project-specific Copilot instructions |
2 | 2 |
|
3 | 3 | ## How to build and run |
| 4 | + |
4 | 5 | - when working with gradle module `:tools-and-tests:tools` it is actually `:tools`. Default full build task is |
5 | 6 | `shadowJar` which builds all modules and creates an "all-in-one" jar `tools-and-tests/tools/build/libs/tools-0.21.0-SNAPSHOT-all.jar`. |
6 | 7 | - to run the block CLI tool `:tools` after building, use: `java -jar tools-and-tests/tools/build/libs/tools-0.21.0-SNAPSHOT-all.jar [args]` |
7 | 8 |
|
8 | 9 | ## Coding style and conventions |
| 10 | + |
9 | 11 | This provides explicit, actionable guidance for generating Java source that matches this repository's coding style and formatting rules. |
10 | 12 |
|
11 | 13 | - File header and license: |
12 | | - - Every Java source file must start with the SPDX license header exactly as a single-line comment: |
13 | | - // SPDX-License-Identifier: Apache-2.0 |
14 | | - - The SPDX header must be the first non-empty line in the file, followed by the `package` statement. |
15 | | - |
| 14 | + - Every Java source file must start with the SPDX license header exactly as a single-line comment: |
| 15 | + // SPDX-License-Identifier: Apache-2.0 |
| 16 | + - The SPDX header must be the first non-empty line in the file, followed by the `package` statement. |
16 | 17 | - Package and imports: |
17 | | - - Always include a `package` declaration after the SPDX header. |
18 | | - - Do not use wildcard imports (`import java.util.*`). |
19 | | - - Preferred import ordering: java.*, javax.*, org.*, com.*, then project packages (alphabetical within each group). |
20 | | - - Keep a single blank line between the package statement and imports, and a single blank line between imports and type declaration. |
21 | | - |
| 18 | + - Always include a `package` declaration after the SPDX header. |
| 19 | + - Do not use wildcard imports (`import java.util.*`). |
| 20 | + - Preferred import ordering: java.*, javax.*, org.*, com.*, then project packages (alphabetical within each group). |
| 21 | + - Keep a single blank line between the package statement and imports, and a single blank line between imports and type declaration. |
22 | 22 | - Javadoc: |
23 | | - - Provide Javadoc for all public classes, interfaces, enums, methods, and fields. |
24 | | - - For short descriptions prefer a single-line Javadoc, e.g.: |
25 | | - /** The Constants class defines the constants for the block simulator. */ |
26 | | - - For longer descriptions, use a standard block Javadoc and avoid blank lines without <p> tags if a paragraph split is required, e.g.: |
27 | | - /** |
28 | | - * Builds X and returns Y. |
29 | | - * |
30 | | - * <p>This method does ... |
31 | | - * |
32 | | - * @param input the input value |
33 | | - * @return the result |
34 | | - */ |
35 | | - - Include `@param`, `@return`, and `@throws` tags where applicable for public APIs. |
36 | | - - Close all HTML tags and use `<ul>`, `<li>` for lists (no Markdown lists inside Javadoc). |
| 23 | + - Provide Javadoc for all public classes, interfaces, enums, methods, and fields. |
| 24 | + - For short descriptions prefer a single-line Javadoc, e.g.: |
| 25 | + /** The Constants class defines the constants for the block simulator. */ |
| 26 | + - For longer descriptions, use a standard block Javadoc and avoid blank lines without <p> tags if a paragraph split is required, e.g.: |
| 27 | + /** |
| 28 | + * Builds X and returns Y. |
| 29 | + * |
| 30 | + * |
| 31 | + |
| 32 | + <p>This method does ... |
| 33 | + |
| 34 | + * |
| 35 | + * @param input the input value |
| 36 | + * @return the result |
| 37 | + */ |
| 38 | + |
| 39 | + - Include `@param`, `@return`, and `@throws` tags where applicable for public APIs. |
| 40 | + |
| 41 | + - Close all HTML tags and use `<ul>`, `<li>` for lists (no Markdown lists inside Javadoc). |
37 | 42 |
|
38 | 43 | - Naming, modifiers, and fields: |
39 | | - - Use long descriptive variable names rather than single-letter names (except loop indices i, j, k). |
40 | | - - Prefer explicit types for public method signatures and fields; prefer `final` for fields that do not change. |
41 | | - - Static constants: `public static final` with UPPER_SNAKE_CASE naming. |
42 | | - - For utility classes, add a private constructor to prevent instantiation. |
43 | 44 |
|
| 45 | + - Use long descriptive variable names rather than single-letter names (except loop indices i, j, k). |
| 46 | + - Prefer explicit types for public method signatures and fields; prefer `final` for fields that do not change. |
| 47 | + - Static constants: `public static final` with UPPER_SNAKE_CASE naming. |
| 48 | + - For utility classes, add a private constructor to prevent instantiation. |
44 | 49 | - Formatting and style: |
45 | | - - Indentation: 4 spaces. |
46 | | - - Brace style: opening brace on same line as declaration (K&R). |
47 | | - - Line length: aim for <= 120 characters. |
48 | | - - Use single blank line to separate logical blocks inside methods. |
49 | | - - Use descriptive boolean variable names (e.g., `isEnabled`, `colorfulLogFormatterEnabled`). |
50 | | - |
| 50 | + - Indentation: 4 spaces. |
| 51 | + - Brace style: opening brace on same line as declaration (K&R). |
| 52 | + - Line length: aim for <= 120 characters. |
| 53 | + - Use single blank line to separate logical blocks inside methods. |
| 54 | + - Use descriptive boolean variable names (e.g., `isEnabled`, `colorfulLogFormatterEnabled`). |
51 | 55 | - Java version and modern APIs: |
52 | | - - Target Java 21 compatibility. |
53 | | - - Prefer modern JDK APIs where appropriate: use `switch` expressions for multi-branch selection, `Objects.requireNonNullElse`, java.time classes, and `HexFormat` for hex conversions. |
54 | | - - Avoid adding third-party dependencies for simple tasks that can be done with the JDK. |
55 | | - - Prefer `record` for simple immutable data carriers where it makes sense and public API stability allows it. |
56 | | - |
| 56 | + - Target Java 21 compatibility. |
| 57 | + - Prefer modern JDK APIs where appropriate: use `switch` expressions for multi-branch selection, `Objects.requireNonNullElse`, java.time classes, and `HexFormat` for hex conversions. |
| 58 | + - Avoid adding third-party dependencies for simple tasks that can be done with the JDK. |
| 59 | + - Prefer `record` for simple immutable data carriers where it makes sense and public API stability allows it. |
57 | 60 | - Logging: |
58 | | - - Follow existing project pattern of `java.util.logging`. |
59 | | - - For obtaining a logger: `private static final Logger LOGGER = Logger.getLogger(MyClass.class.getName());` |
60 | | - |
| 61 | + - Follow existing project pattern of `java.util.logging`. |
| 62 | + - For obtaining a logger: `private static final Logger LOGGER = Logger.getLogger(MyClass.class.getName());` |
61 | 63 | - Tests: |
62 | | - - Place tests under the appropriate `src/test/java` module and match package naming of the production code. |
63 | | - - Tests should be self-contained, use expressive variable names, and include descriptive test method names. |
64 | | - |
| 64 | + - Place tests under the appropriate `src/test/java` module and match package naming of the production code. |
| 65 | + - Tests should be self-contained, use expressive variable names, and include descriptive test method names. |
65 | 66 | - Avoid: |
66 | | - - Avoid using `var` in public API signatures. Use `var` only in short local contexts where the inferred type is obvious. |
67 | | - - Avoid wildcard imports. |
68 | | - - Avoid unnecessary suppression of warnings; if suppression is used, scope it narrowly and justify in a short comment. |
69 | | - |
| 67 | + - Avoid using `var` in public API signatures. Use `var` only in short local contexts where the inferred type is obvious. |
| 68 | + - Avoid wildcard imports. |
| 69 | + - Avoid unnecessary suppression of warnings; if suppression is used, scope it narrowly and justify in a short comment. |
70 | 70 | - Examples and small templates |
71 | | - - File header template: |
72 | | - // SPDX-License-Identifier: Apache-2.0 |
73 | | - package org.hiero.block.example; |
74 | | - /** |
75 | | - * Brief single-line class description. |
76 | | - */ |
77 | | - public final class ExampleClass { |
78 | | - /** Explanation of constant. */ |
79 | | - public static final String EXAMPLE_CONSTANT = "value"; |
80 | | - /** Constructor prevents instantiation. */ |
81 | | - private ExampleClass() {} |
82 | | - } |
83 | | - |
| 71 | + - File header template: |
| 72 | + // SPDX-License-Identifier: Apache-2.0 |
| 73 | + package org.hiero.block.example; |
| 74 | + /** |
| 75 | + * Brief single-line class description. |
| 76 | + */ |
| 77 | + public final class ExampleClass { |
| 78 | + /** Explanation of constant. */ |
| 79 | + public static final String EXAMPLE_CONSTANT = "value"; |
| 80 | + /** Constructor prevents instantiation. */ |
| 81 | + private ExampleClass() {} |
| 82 | + } |
84 | 83 | - Spotless and formatting note for Copilot: |
85 | | - - The repository uses an organization-level Spotless plugin wrapper (`org.hiero.gradle.check.spotless`). Generated files should conform to the above formatting so they pass Spotless checks. |
86 | | - - If you are adding or editing Gradle files, prefer the repository's existing Gradle plugin usage over adding new formatting plugins unless approved. |
87 | | - |
| 84 | + - The repository uses an organization-level Spotless plugin wrapper (`org.hiero.gradle.check.spotless`). Generated files should conform to the above formatting so they pass Spotless checks. |
| 85 | + - If you are adding or editing Gradle files, prefer the repository's existing Gradle plugin usage over adding new formatting plugins unless approved. |
88 | 86 | - When in doubt: |
89 | | - - Match nearby files in the same package/module: copy class-level javadoc style, ordering, and formatting from local examples. |
90 | | - |
| 87 | + - Match nearby files in the same package/module: copy class-level javadoc style, ordering, and formatting from local examples. |
0 commit comments