Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
27 changes: 27 additions & 0 deletions .github/workflows/icu4j.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,33 @@ jobs:
cd icu4j;
mvn ${SHARED_MVN_ARGS} dependency:go-offline -P '!old_jdk_taglet'

# Using the Java style formatter google-java-style provided by the Spotless
# plugin configured in the root pom.xml using 4-space indents (AOSP style).
# Spotless is configured to run only on files in this branch (PR) that differ
# from origin/main
formatter:
name: Formatter + Style checker
needs: icu4j-mvn-init-cache
runs-on: ubuntu-latest
steps:
- name: Checkout and setup
uses: actions/checkout@v4
with:
fetch-depth: 0 # fetch all branches so that Spotless can resolve `origin/main`
- name: Restore read-only cache of local Maven repository
uses: actions/cache/restore@v4
id: cache
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
lookup-only: true
- name: Check Java style
run: |
cd icu4j;
mvn spotless:check || (echo "Style checker failed. Formatting changes can be applied by 'mvn spotless:apply'" && exit 1)

# ICU4J build and unit test using Maven
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
icu4j-mvn-build-and-test:
Expand Down
14 changes: 14 additions & 0 deletions docs/userguide/dev/codingguidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,20 @@ ICU Java classes and methods.

### Code style

ICU uses a source formatter to ensure a consistent code style automatically,
and it uses a single common formatter to avoid spurious diff noise in code reviews.
This is now enforced via a
[formatter](https://github.com/google/google-java-format)
that is configured in the Maven build
via a [Maven plugin](https://github.com/diffplug/spotless/tree/main/plugin-maven)
and checked by continuous integration on pull requests.

When creating pull requests, you can check the formatting locally using the command `mvn spotless:check`. You can apply the formatter's changes using the command `mvn spotless:apply`. Continuous integration errors for formatting can be fixed by committing the changes resulting from applying the formatter locally and pushing the new commit.

The following are further guidelines for code style,
but they will be superceded by the automated formatter in CI that is mentioned above
if the guidelines differ in style.

The standard order for modifier keywords on APIs is:

* `public static final synchronized strictfp`
Expand Down
101 changes: 50 additions & 51 deletions icu4j/demos/src/main/java/com/ibm/icu/dev/demo/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
*/
package com.ibm.icu.dev.demo;

import com.ibm.icu.dev.demo.impl.DemoApplet;
import com.ibm.icu.dev.demo.impl.DemoUtility;
import com.ibm.icu.util.VersionInfo;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Color;
Expand All @@ -22,26 +25,17 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import com.ibm.icu.dev.demo.impl.DemoApplet;
import com.ibm.icu.dev.demo.impl.DemoUtility;
import com.ibm.icu.util.VersionInfo;


/**
* @author srl
* Application to provide a panel of demos to launch
* @author srl Application to provide a panel of demos to launch
*/
public class Launcher extends DemoApplet {
private static final long serialVersionUID = -8054963875776183877L;

/**
* base package of all demos
*/

/** base package of all demos */
public static final String demoBase = "com.ibm.icu.dev.demo";
/**
* list of classes, relative to the demoBase. all must have a static void main(String[])
*/
public static final String demoList[] = {

/** list of classes, relative to the demoBase. all must have a static void main(String[]) */
public static final String demoList[] = {
"calendar.CalendarApp",
"charsetdet.DetectingViewer",
"holiday.HolidayCalendarDemo",
Expand All @@ -51,16 +45,16 @@ public class Launcher extends DemoApplet {

public class LauncherFrame extends Frame implements ActionListener {
private static final long serialVersionUID = -8054963875776183878L;

public Button buttonList[] = new Button[demoList.length]; // one button for each demo
public Label statusLabel;
private DemoApplet applet;

LauncherFrame(DemoApplet applet) {
init();
this.applet = applet;
}

public void init() {
// close down when close is clicked.
// TODO: this should be factored..
Expand All @@ -74,114 +68,119 @@ public void windowClosing(WindowEvent e) {
applet.demoClosed();
} else System.exit(0);
}
} );
});

setBackground(DemoUtility.bgColor);
setLayout(new BorderLayout());

Panel topPanel = new Panel();
topPanel.setLayout(new GridLayout(5,3));
topPanel.setLayout(new GridLayout(5, 3));

for(int i=0;i<buttonList.length;i++) {
for (int i = 0; i < buttonList.length; i++) {
String demo = demoList[i];
Button b = new Button(demo);
b.addActionListener(this);
buttonList[i]=b;
buttonList[i] = b;
topPanel.add(b);
}
add(BorderLayout.CENTER,topPanel);
add(BorderLayout.CENTER, topPanel);
statusLabel = new Label("");
statusLabel.setAlignment(Label.LEFT);
String javaVersion = "";
try {
javaVersion = "* Java: "+System.getProperty("java.version");
try {
javaVersion = "* Java: " + System.getProperty("java.version");
} catch (Throwable t) {
javaVersion = "";
}
add(BorderLayout.NORTH, new Label(
"ICU Demos * ICU version "+VersionInfo.ICU_VERSION +
" * https://icu.unicode.org/ "+javaVersion));
add(BorderLayout.SOUTH,statusLabel);
add(
BorderLayout.NORTH,
new Label(
"ICU Demos * ICU version "
+ VersionInfo.ICU_VERSION
+ " * https://icu.unicode.org/ "
+ javaVersion));
add(BorderLayout.SOUTH, statusLabel);
// set up an initial status.
showStatus(buttonList.length+" demos ready. ");
showStatus(buttonList.length + " demos ready. ");
}

/**
* Change the 'status' field, and set it to black
*
* @param status
*/
void showStatus(String status) {
statusLabel.setText(status);
statusLabel.setForeground(Color.BLACK);
statusLabel.setBackground(Color.WHITE);
// statusLabel.setFont(Font.PLAIN);
// statusLabel.setFont(Font.PLAIN);
doLayout();
}

void showStatus(String demo, String status) {
showStatus(demo+": "+status);
showStatus(demo + ": " + status);
}

void showFailure(String status) {
statusLabel.setText(status);
statusLabel.setBackground(Color.GRAY);
statusLabel.setForeground(Color.RED);
// statusLabel.setFont(Font.BOLD);
// statusLabel.setFont(Font.BOLD);
doLayout();
}

void showFailure(String demo, String status) {
showFailure(demo+": "+status);
showFailure(demo + ": " + status);
}


public void actionPerformed(ActionEvent e) {
// find button
for(int i=0;i<buttonList.length;i++) {
if(e.getSource() == buttonList[i]) {
for (int i = 0; i < buttonList.length; i++) {
if (e.getSource() == buttonList[i]) {
String demoShort = demoList[i];
String demo = demoBase+'.'+demoShort;
String demo = demoBase + '.' + demoShort;
showStatus(demoShort, "launching");
try {
Class c = Class.forName(demo);
String args[] = new String[0];
Class params[] = new Class[1];
params[0] = args.getClass();
Method m = c.getMethod("main", params );
Object[] argList = { args };
Method m = c.getMethod("main", params);
Object[] argList = {args};
m.invoke(null, argList);
showStatus(demoShort, "launched.");
} catch (ClassNotFoundException e1) {
showFailure(demoShort,e1.toString());
showFailure(demoShort, e1.toString());
e1.printStackTrace();
} catch (SecurityException se) {
showFailure(demoShort,se.toString());
showFailure(demoShort, se.toString());
se.printStackTrace();
} catch (NoSuchMethodException nsme) {
showFailure(demoShort,nsme.toString());
showFailure(demoShort, nsme.toString());
nsme.printStackTrace();
} catch (IllegalArgumentException iae) {
showFailure(demoShort,iae.toString());
showFailure(demoShort, iae.toString());
iae.printStackTrace();
} catch (IllegalAccessException iae) {
showFailure(demoShort,iae.toString());
showFailure(demoShort, iae.toString());
iae.printStackTrace();
} catch (InvocationTargetException ite) {
showFailure(demoShort,ite.toString());
showFailure(demoShort, ite.toString());
ite.printStackTrace();
}
repaint();
}
}
}

}

/* This creates a Frame for the demo applet. */
protected Frame createDemoFrame(DemoApplet applet) {
return new LauncherFrame(applet);
}

/**
* The main function which defines the behavior of the Demo
* applet when an applet is started.
* The main function which defines the behavior of the Demo applet when an applet is started.
*/
public static void main(String[] args) {
new Launcher().showDemo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,17 @@

package com.ibm.icu.dev.demo.calendar;

import java.awt.Frame;

import com.ibm.icu.dev.demo.impl.DemoApplet;
import java.awt.Frame;

/**
* CalendarApp demonstrates how Calendar works.
*/
public class CalendarApp extends DemoApplet
{
/**
* For serialization
*/
/** CalendarApp demonstrates how Calendar works. */
public class CalendarApp extends DemoApplet {
/** For serialization */
private static final long serialVersionUID = -4270137898405840825L;

/**
* The main function which defines the behavior of the CalendarDemo
* applet when an applet is started.
* The main function which defines the behavior of the CalendarDemo applet when an applet is
* started.
*/
public static void main(String argv[]) {

Expand Down
Loading