Skip to content

Commit 3f44e6d

Browse files
shai-almogclaude
andcommitted
Fix JavaDoc snippet validator and the snippets it surfaced
The headless snippet validator stopped catching real issues after a chain of refactors: PlaygroundProjectExporter pulled in net.sf.zipme.* breaking the harness build, the resolveDisplayBinding wrappers were reverted out of PlaygroundRunner.bindGlobals so it tripped on ExceptionInInitializerError, and CN1's Base64 grew a Simd dep that forced Display.impl to be live before any encoding could happen. Repairs: - Add ZipSupport cn1lib to the harness classpath - Restore resolveDisplay/UiManagerBinding in PlaygroundRunner - Encode URIs via java.util.Base64 instead of reflecting into CN1's - Best-effort Display.init from the locally-built JavaSE jar so "Undefined argument: icon" surfaces instead of an NPE - Tighten the harness so undefined-identifier eval errors fail, while genuine headless-runtime failures still pass Then fix the snippets the now-working validator flags: - SpanLabel/SpanButton/MultiButton/CheckBox/RadioButton/ButtonGroup/ Label/ImageViewer: add the missing Form/Image setup and hi.show() - Preferences (and io/package-info copy): declare String myToken - MathUtil.compare(float|double): turn the bare compareTo line into a runnable Form demo - Component.getAllStyles / Graphics.fillArc: rewrite the broken "new Painter(cmp) { switch (style) ... }" pseudo-code (Painter is an interface; style/cmp were undefined) as a runnable Painter demo - Validator: wrap the Constraint sample in a runnable Form - system/package-info: relabel the Objective-C example block from java to objc - Add the four genuinely-illustrative GroupLayout/LayoutStyle method- signature snippets to the exclusions list with documented reasons Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 3fb1ec7 commit 3f44e6d

19 files changed

Lines changed: 233 additions & 92 deletions

File tree

CodenameOne/src/com/codename1/components/ImageViewer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@
4747
///
4848
/// ```java
4949
/// Form hi = new Form("ImageViewer", new BorderLayout());
50+
/// Image duke = FontImage.createMaterial(FontImage.MATERIAL_INFO, "Label", 3.0f);
5051
/// ImageViewer iv = new ImageViewer(duke);
5152
/// hi.add(BorderLayout.CENTER, iv);
53+
/// hi.show();
5254
/// ```
5355
///
5456
/// You can simulate pinch to zoom on the simulator by dragging the right button away from the top left corner to

CodenameOne/src/com/codename1/components/MultiButton.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
/// a lead component. Up to 4 rows are supported.
5151
///
5252
/// ```java
53+
/// Form hi = new Form("Test MultiButton", BoxLayout.y());
54+
///
55+
/// Image icon = FontImage.createMaterial(FontImage.MATERIAL_INFO, "Button", 3.0f);
56+
/// Image emblem = FontImage.createMaterial(FontImage.MATERIAL_ARROW_FORWARD, "Button", 3.0f);
57+
///
5358
/// MultiButton twoLinesNoIcon = new MultiButton("MultiButton");
5459
/// twoLinesNoIcon.setTextLine2("Line 2");
5560
/// MultiButton oneLineIconEmblem = new MultiButton("Icon + Emblem");
@@ -83,6 +88,7 @@
8388
/// add(twoLinesIconEmblemHorizontal).
8489
/// add(twoLinesIconCheckBox).
8590
/// add(fourLinesIcon);
91+
/// hi.show();
8692
/// ```
8793
///
8894
/// @author Shai Almog

CodenameOne/src/com/codename1/components/SpanButton.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,14 @@
4949
/// button has the UIID style of a button.
5050
///
5151
/// ```java
52+
/// Form hi = new Form("Test SpanButton", BoxLayout.y());
53+
///
54+
/// Image icon = FontImage.createMaterial(FontImage.MATERIAL_INFO, "Button", 3.0f);
55+
///
5256
/// SpanButton sb = new SpanButton("SpanButton is a composite component (lead component) that looks/acts like a Button but can break lines rather than crop them when the text is very long.");
5357
/// sb.setIcon(icon);
5458
/// hi.add(sb);
59+
/// hi.show();
5560
/// ```
5661
///
5762
/// @author Shai Almog

CodenameOne/src/com/codename1/components/SpanLabel.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
/// on a text area combined with a label.
4545
///
4646
/// ```java
47+
/// Form hi = new Form("Test SpanLabel", BoxLayout.y());
48+
///
49+
/// Image icon = FontImage.createMaterial(FontImage.MATERIAL_INFO, "Label", 3.0f);
50+
///
4751
/// SpanLabel d = new SpanLabel("Default SpanLabel that can seamlessly line break when the text is really long.");
4852
/// d.setIcon(icon);
4953
/// SpanLabel l = new SpanLabel("NORTH Positioned Icon SpanLabel that can seamlessly line break when the text is really long.");
@@ -56,6 +60,7 @@
5660
/// c.setIcon(icon);
5761
/// c.setIconPosition(BorderLayout.EAST);
5862
/// hi.add(d).add(l).add(r).add(c);
63+
/// hi.show();
5964
/// ```
6065
///
6166
/// @author Shai Almog

CodenameOne/src/com/codename1/io/Preferences.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
///
3636
/// ```java
3737
/// // save a token to storage
38+
/// String myToken = "abc123";
3839
/// Preferences.set("token", myToken);
3940
///
4041
/// // get the token from storage or null if it isn't there

CodenameOne/src/com/codename1/io/package-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
///
5959
/// ```java
6060
/// // save a token to storage
61+
/// String myToken = "abc123";
6162
/// Preferences.set("token", myToken);
6263
///
6364
/// // get the token from storage or null if it isn't there

CodenameOne/src/com/codename1/system/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
/// combined where the "." elements are replaced by underscores. This class can be implemented in Objective-C
6464
/// (by providing both a header and an "m" file) or in Swift. Objective-C classes follow this convention e.g.:
6565
///
66-
/// ```java
66+
/// ```objc
6767
/// @interface com_my_code_MyNative : NSObject {
6868
/// }
6969
/// - (id)init;

CodenameOne/src/com/codename1/ui/ButtonGroup.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
/// the specific `ButtonGroup`.
3737
///
3838
/// ```java
39+
/// Form hi = new Form("Test ButtonGroup", BoxLayout.y());
40+
///
41+
/// Image icon = FontImage.createMaterial(FontImage.MATERIAL_INFO, "CheckBox", 3.0f);
42+
///
3943
/// CheckBox cb1 = new CheckBox("CheckBox No Icon");
4044
/// cb1.setSelected(true);
4145
/// CheckBox cb2 = new CheckBox("CheckBox With Icon", icon);
@@ -49,6 +53,7 @@
4953
/// new ButtonGroup(rb1, rb2, rb3);
5054
/// rb2.setSelected(true);
5155
/// hi.add(cb1).add(cb2).add(cb3).add(cb4).add(rb1).add(rb2).add(rb3);
56+
/// hi.show();
5257
/// ```
5358
///
5459
/// @author Nir Shabi

CodenameOne/src/com/codename1/ui/CheckBox.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
/// mode using the `com.codename1.ui.Button#setToggle(boolean)` API.
3939
///
4040
/// ```java
41+
/// Form hi = new Form("Test CheckBox", BoxLayout.y());
42+
///
43+
/// Image icon = FontImage.createMaterial(FontImage.MATERIAL_INFO, "CheckBox", 3.0f);
44+
///
4145
/// CheckBox cb1 = new CheckBox("CheckBox No Icon");
4246
/// cb1.setSelected(true);
4347
/// CheckBox cb2 = new CheckBox("CheckBox With Icon", icon);
@@ -51,6 +55,7 @@
5155
/// new ButtonGroup(rb1, rb2, rb3);
5256
/// rb2.setSelected(true);
5357
/// hi.add(cb1).add(cb2).add(cb3).add(cb4).add(rb1).add(rb2).add(rb3);
58+
/// hi.show();
5459
/// ```
5560
///
5661
/// @author Chen Fishbein

CodenameOne/src/com/codename1/ui/Component.java

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -692,50 +692,29 @@ public Object getNativeOverlay() {
692692
/// style will be meaningless and will return 0 values. Usage:
693693
///
694694
/// ```java
695-
/// Painter p = new Painter(cmp) {
695+
/// Form hi = new Form("Painter via getAllStyles", new BorderLayout());
696+
/// Container cmp = new Container();
697+
/// cmp.setPreferredSize(new Dimension(300, 300));
698+
/// Painter p = new Painter() {
696699
/// public void paint(Graphics g, Rectangle rect) {
697700
/// boolean antiAliased = g.isAntiAliased();
698701
/// g.setAntiAliased(true);
699-
/// int r = Math.min(rect.getWidth(), rect.getHeight())/2;
700-
/// int x = rect.getX() + rect.getWidth()/2 - r;
701-
/// int y = rect.getY() + rect.getHeight()/2 - r;
702-
/// switch (style) {
703-
/// case CircleButtonStrokedDark:
704-
/// case CircleButtonStrokedLight: {
705-
/// if (cmp.getStyle().getBgTransparency() != 0) {
706-
/// int alpha = cmp.getStyle().getBgTransparency();
707-
/// if (alpha <0) {
708-
/// alpha = 0xff;
709-
/// }
710-
/// g.setColor(cmp.getStyle().getBgColor());
711-
/// g.setAlpha(alpha);
712-
/// g.fillArc(x, y, 2*r-1, 2*r-1, 0, 360);
713-
/// g.setAlpha(0xff);
714-
/// }
715-
/// g.setColor(cmp.getStyle().getFgColor());
716-
/// g.drawArc(x, y, 2*r-1, 2*r-1, 0, 360);
717-
/// break;
718-
/// }
719-
/// case CircleButtonFilledDark:
720-
/// case CircleButtonFilledLight:
721-
/// case CircleButtonTransparentDark:
722-
/// case CircleButtonTransparentLight: {
723-
/// int alpha = cmp.getStyle().getBgTransparency();
724-
/// if (alpha < 0) {
725-
/// alpha = 0xff;
726-
/// }
727-
/// g.setAlpha(alpha);
728-
/// g.setColor(cmp.getStyle().getBgColor());
729-
/// g.fillArc(x, y, 2*r, 2*r, 0, 360);
730-
/// g.setAlpha(0xff);
731-
/// break;
732-
/// }
733-
/// }
734-
///
702+
/// int r = Math.min(rect.getWidth(), rect.getHeight()) / 2;
703+
/// int x = rect.getX() + rect.getWidth() / 2 - r;
704+
/// int y = rect.getY() + rect.getHeight() / 2 - r;
705+
/// g.setColor(cmp.getStyle().getBgColor());
706+
/// g.fillArc(x, y, 2 * r, 2 * r, 0, 360);
707+
/// g.setColor(cmp.getStyle().getFgColor());
708+
/// g.drawArc(x, y, 2 * r - 1, 2 * r - 1, 0, 360);
735709
/// g.setAntiAliased(antiAliased);
736710
/// }
737711
/// };
712+
/// cmp.getAllStyles().setBgColor(0x4488ff);
713+
/// cmp.getAllStyles().setBgTransparency(255);
714+
/// cmp.getAllStyles().setFgColor(0xffffff);
738715
/// cmp.getAllStyles().setBgPainter(p);
716+
/// hi.add(BorderLayout.CENTER, cmp);
717+
/// hi.show();
739718
/// ```
740719
///
741720
/// #### Returns

0 commit comments

Comments
 (0)