Coding styles¶
OmegaT project uses following coding style rules and coding policy.
Code Style Basics¶
Each java file has a GPL3 copyright header. OmegaT has a unit test to check header.
Source code has a maximum 120 characters in each line.
The Maximum line length of comments in sources is 80 characters
Indentation is 4 spaces. Don’t use TAB character.
We don’t use asterisk import. You should expand all individual imports.
You are recommended to put javadoc comments for all your public methods.
We don’t set method arguments “final”, but you are recommended to treat it as final.
I18N/L10N/Bundles¶
Bundle properties should be ASCII, 7bit clean. All translations should be escaped.
It will change to be UTF-8 after OmegaT version 6.1 beta release.
API design¶
Stable APIs should be under “org.omegat.core” package.
Should not remove API, otherwise, please give
@Deprecationfor old API.Please care for backward compatibility, please mind plugin developers.
Swing GUI design¶
We use a Java Swing technology for GUI parts.
GUI parts can be;
written by hand, or
We don’t accept other GUI builder materials;
such as JetBrains IntelliJ GUI builder, JForm Designer, Eclipse Window builder.
If you want, you are recommended to implement it as a plugin.
GUI programming hints¶
We encourage developers to take an approach of MVC design.
You can design GUI parts as View, such as
o.o.g.p.v.AppearancePreferencePanelclass.You can write logics as Controller, such as
o.o.g.p.v.AppearanceContollerclass.Sometimes a custom Model is required for complex design, such as
o.o.g.p.v.PluginInfoTableModel
Labels translation¶
Please define localized labels got by
OStrings.getStringfrom bundle.For further maintenance, it is better to make UI components visibility as
package-privateand set its label in Controller class, using a syntax likeMnemonics.setLocalizedText(ViewClass.uiComponentField, OString.getString("TF_LABEL_FOO"));
Source code location to maintain¶
Typical UI components are defined;
Preference pane contents: classes under o.o.g.preferences.view package
Dialogs: o.o.g.dialogs
aligner: sub-project folder under aligner/src/main/java folder
password dialog for team project: under o.o.c.team2.impl package.
Warning:
When UI parts has a comment like
/** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponentsIt is generated by NetBeans GUI Editor. You should use the editor to manipulate the file. Please find a file that has same file name but extension is “.form”
XML parser¶
We move XML parser to be StAX based instead of JAXB because of performance.
We use Jackson XML serialization library.
Modules¶
We split Machine Translation service connectors, Aligner, Spell Checker driver and dictionary drivers as sub project and build as modules.
Modules are installed in “
/modules” instead of “ /plugins”
language and characters¶
OmegaT project uses UTF-8 characters for comments in java source file in general.
You should use English for comment language.
You should use ASCII characters and 7bit clean for variable names, method names et. al.
You are allowed to use String literals in UTF-8 encoding.
You should use Bundle for localization strings.
You can not use Right-to-Left direction characters in comments and code body.
You can not use invisible characters such as non-breakable-space and tab.
When you need invisible characters in literals, please use unicode escape.
Lint check¶
OmegaT project configures a build script with several linting tools. You can check your code with;
./gradlew check
Checkstyle¶
You can check your code with Checkstyle linting tool.
A project configuration is stored in config/checkstyle/checkstyle.xml
We treat checkstyle lint error as warning, but you are recommended to
improve your code before sending your patch to the core team.
Spotless code formatter¶
Spotless is a general purpose code formatting tool that makes code spotless. It will help you to format your changed code just a command
./gradlew spotlessChangedApply
OmegaT uses Spotless plugin for gradle and configured with [eclipse formatting configuration](assets/eclipse-formatting. xml) This XML file is project-standard indent configuration for Eclipse IDE, but also uses as spotless formatting rule.
There is other sample config file for IDE such as [JetBrains IntelliJ Project configuration](assets/intellij-Project. xml).