Skip to content

Commit f9dd657

Browse files
vogellaclaude
andcommitted
Update AGENTS.md with enhanced SWT development guidance
Builds on original copilot-instructions.md with: - Auto-generated file warnings (os.c, os_stats.*) - Critical resource disposal rules (Color/Font auto-disposed) - Threading requirements for SWT - GTK function addition workflow - OSGi bundle dependency notes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 9f1d531 commit f9dd657

File tree

1 file changed

+53
-13
lines changed

1 file changed

+53
-13
lines changed

AGENTS.md

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# GitHub Copilot Instructions for Eclipse Platform SWT
1+
# AGENTS.md - Eclipse SWT Guide for AI Tools
22

33
## Project Overview
44

@@ -43,10 +43,17 @@ mvn clean verify -DskipTests
4343
```
4444

4545
### Building Natives
46-
To rebuild native libraries:
47-
1. Ensure the appropriate binary project is imported in your workspace (e.g., `binaries/org.eclipse.swt.gtk.linux.x86_64`)
48-
2. Native build scripts are platform-specific and located in the binary fragments
49-
3. For GTK on Linux: See `docs/gtk-dev-guide.md` for detailed instructions
46+
47+
**GTK (Linux):**
48+
```bash
49+
cd bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library
50+
./build.sh -gtk-all install # Build both GTK3 and GTK4
51+
```
52+
53+
**CRITICAL**: Files like `os.c`, `os_stats.c`, `os_stats.h` are **auto-generated**. Never edit them directly!
54+
Instead: modify Java source (e.g., `OS.java`), clean/rebuild the project, then run `./build.sh`.
55+
56+
See `docs/gtk-dev-guide.md` for detailed instructions.
5057

5158
## Coding Standards
5259

@@ -66,8 +73,13 @@ To rebuild native libraries:
6673
### Code Organization
6774
- Platform-independent code: `bundles/org.eclipse.swt/Eclipse SWT/common/`
6875
- Platform-specific code: `bundles/org.eclipse.swt/Eclipse SWT/{gtk,win32,cocoa}/`
76+
- JNI layer: `bundles/org.eclipse.swt/Eclipse SWT PI/{gtk,win32,cocoa}/`
6977
- Emulated widgets: `bundles/org.eclipse.swt/Eclipse SWT/emulated/`
7078

79+
### OSGi Bundle Dependencies
80+
SWT is an OSGi bundle. Check `bundles/org.eclipse.swt/META-INF/MANIFEST.MF` before using external classes.
81+
If needed, add packages to `Import-Package` or `Require-Bundle`.
82+
7183
## Testing
7284

7385
### Running Tests
@@ -147,12 +159,40 @@ mvn test -Dtest=ClassName
147159
- **GitHub Discussions**: Use for questions and general discussions
148160
- **GitHub Issues**: Use for bug reports and feature requests
149161

150-
## Tips for Copilot
162+
## Critical Development Rules
163+
164+
### Resource Disposal
165+
**YOU MUST DISPOSE:** `Image`, `GC`, `Cursor`, `Region`, `Path`, `Pattern`
166+
**Auto-disposed (no manual disposal needed):** `Color`, `Font` (as of recent SWT versions)
167+
**DO NOT DISPOSE:** System colors/fonts, `ImageRegistry` images, Display/Shell (framework-managed)
168+
169+
```java
170+
Image image = new Image(display, 100, 100);
171+
try {
172+
// Use image
173+
} finally {
174+
image.dispose();
175+
}
176+
```
177+
178+
### Threading
179+
**All SWT code must run on the Display thread!**
180+
```java
181+
display.asyncExec(() -> button.setText("Updated"));
182+
```
151183

152-
- When generating SWT code, always include proper resource disposal
153-
- Remember that SWT is not thread-safe - UI operations need Display.syncExec/asyncExec
154-
- Platform-specific code should go in the appropriate platform directory
155-
- When adding native methods, declare them in `OS.java` first
156-
- Follow existing code patterns in the repository for consistency
157-
- Use snippets in `examples/org.eclipse.swt.snippets/` as reference examples
158-
- Consider cross-platform compatibility when making changes
184+
### Adding GTK Functions
185+
1. Add native method declaration to `OS.java` with JavaDoc annotations (`@param cast=`, `@method flags=dynamic`)
186+
2. Clean and rebuild `org.eclipse.swt` project (regenerates `os.c`)
187+
3. Rebuild natives: `cd bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library && ./build.sh -gtk3 install`
188+
189+
## Tips for AI Tools
190+
191+
- Always include proper resource disposal in generated code
192+
- Ensure UI operations use `Display.syncExec/asyncExec`
193+
- Platform-specific code goes in `{gtk,win32,cocoa}/` directories
194+
- When adding native methods, declare in `OS.java` first
195+
- Never edit auto-generated files (`os.c`, `os_stats.*`)
196+
- Use snippets in `examples/org.eclipse.swt.snippets/` as reference
197+
- Test cross-platform compatibility
198+
- Check MANIFEST.MF for OSGi dependencies

0 commit comments

Comments
 (0)