Skip to content

Commit 8e8384d

Browse files
committed
.github/copilot-instructions.md
1 parent f2f1947 commit 8e8384d

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

.github/copilot-instructions.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# GitHub Copilot Instructions
2+
3+
**ALWAYS reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here.**
4+
5+
## Environment Setup
6+
- **Java 21+ REQUIRED**: Set Java 21+ as active before any build operations:
7+
```bash
8+
export JAVA_HOME=/usr/lib/jvm/temurin-21-jdk-amd64
9+
export PATH=$JAVA_HOME/bin:$PATH
10+
java -version # Should show Java 21+
11+
```
12+
13+
## Core Development Principles
14+
15+
### Code Structure
16+
- Use Records for all data structures
17+
- Use sealed interfaces for protocols
18+
- Default to package-private scope
19+
- Package code by feature, not by layer
20+
- Apply Data-Oriented Programming principles
21+
- Prefer static methods with Records as parameters
22+
- Use JEP 467 Markdown documentation comments (`///`) instead of legacy JavaDoc
23+
24+
### Functional Programming Style
25+
- Use Stream operations instead of traditional loops
26+
- Never use `for(;;)` with mutable loop variables
27+
- Use `Arrays.setAll` for array operations
28+
- Write exhaustive destructuring switch expressions
29+
- Use `final var` for local variables, parameters, and destructured fields
30+
31+
### Documentation & Logging
32+
- Use JEP 467 Markdown documentation with `///` prefix
33+
- Add appropriate logging levels:
34+
- FINE: Production-level debugging
35+
- FINER: Verbose debugging, internal flow
36+
- INFO: Important runtime information
37+
- WARNING: Potential issues
38+
- SEVERE: Critical errors
39+
- Use lambda logging for performance: `LOGGER.fine(() -> "message " + variable)`
40+
41+
### Testing & Validation
42+
- Follow TDD principles - write tests first
43+
- Never disable tests for unimplemented logic
44+
- Use appropriate assertions:
45+
1. `Objects.requireNonNull()` for public API inputs
46+
2. `assert` for internal method validation
47+
3. Use validation methods from `Objects` and `Arrays`
48+
49+
### Error Handling
50+
- Handle `JsonParseException` for malformed JSON
51+
- Consider security implications (stack overflow, malicious inputs)
52+
- Use appropriate logging levels for different error scenarios
53+
54+
### Code Examples
55+
```java
56+
// Correct Record usage
57+
record User(String name, int age, boolean active) {}
58+
59+
// Correct logging
60+
private static final Logger LOGGER = Logger.getLogger(ClassName.class.getName());
61+
LOGGER.fine(() -> "Processing user: " + user.name());
62+
63+
// Correct documentation
64+
/// Returns a JSON representation of the user.
65+
/// @param user The user to convert
66+
/// @return A JsonValue containing the user data
67+
public static JsonValue toJson(User user) {
68+
Objects.requireNonNull(user, "user must not be null");
69+
// ...implementation
70+
}
71+
72+
// Correct switch expression
73+
return switch (jsonValue) {
74+
case JsonObject obj -> handleObject(obj);
75+
case JsonArray arr -> handleArray(arr);
76+
case JsonString str -> str.value();
77+
case JsonNumber num -> num.toString();
78+
case JsonBoolean bool -> bool.value();
79+
case JsonNull _ -> "null";
80+
};
81+
```
82+
83+
### Project Architecture
84+
- Core package: `jdk.sandbox.java.util.json`
85+
- Internal implementation: `jdk.sandbox.internal.util.json`
86+
- JSON Schema validator in separate module
87+
- Use appropriate logging configuration per module
88+
89+
### Common Pitfalls to Avoid
90+
- Don't use legacy JavaDoc comments (`/** ... */`)
91+
- Don't use mutable state or OOP patterns
92+
- Don't use magic numbers - use enum constants
93+
- Don't write large if-else chains - use switch expressions
94+
- Don't filter test output - use appropriate logging levels
95+
- Don't add early returns without proper pattern matching
96+
97+
### Security Considerations
98+
- Be aware of stack exhaustion attacks with deep nesting
99+
- Validate all inputs thoroughly
100+
- Handle malicious inputs that may violate API contracts
101+
- Use appropriate logging for security-related issues
102+
103+
### Testing Workflow
104+
```bash
105+
# Compile focused module
106+
$(command -v mvnd || command -v mvn || command -v ./mvnw) -pl json-java21-api-tracker -Djava.util.logging.ConsoleHandler.level=SEVERE
107+
108+
# Debug with verbose logs
109+
$(command -v mvnd || command -v mvn || command -v ./mvnw) -pl json-java21-api-tracker -Dtest=TestClass -Djava.util.logging.ConsoleHandler.level=FINER
110+
```
111+
112+
### JSON Schema Development
113+
- Follow all repository-wide logging rules
114+
- Add INFO-level log statements at test method entry
115+
- Extend `JsonSchemaLoggingConfig` for new tests
116+
- Use appropriate metrics collection flags:
117+
- `-Djson.schema.metrics=json`
118+
- `-Djson.schema.metrics=csv`
119+
120+
Remember: This is an experimental API - focus on correctness and clarity over performance optimization.
121+

0 commit comments

Comments
 (0)