Chapter 5. EasyBeans Code Convention

Table of Contents

5.1. File Organization
5.1.1. Header
5.1.2. Imports
5.1.3. Class and Interface Declarations
5.2. Indentation / WhiteSpace
5.2.1. Indentation
5.2.2. WhiteSpace
5.3. JavaDoc Comments
5.4. Statements
5.4.1. If/else
5.4.2. Try/catch
5.4.3. Inline Conditionals
5.4.4. Naming Conventions
5.4.4.1. Static Final Attributes
5.4.4.2. Constants
5.4.4.3. No Magic Numbers, Use Constants
5.4.4.4. Attribute Name

Contributions should follow the EasyBeans code convention. A good document to begin with is Java code convention. Other conventions are also listed in this document.

In addition, EasyBeans uses tools to check the compliance: the checkstyle plugin and the eclipse checkstyle plugin. The configuration settings are available on EasyBeans SVN.

5.1. File Organization

5.1.1. Header

All files should have a header that contains the LGPL and the date.

If a file is modified, the modification year should be appended to the existing year, which is the year it was initially created. For example, if the create date is '1999' or '2004' it should be edited to '1999-2006' or '2004-2006', respectively.

Also, the tag $Id: code_convention.xml 314 2006-04-04 09:39:43Z pinheirg $ should be added. The following is a header example:

/**
 * EasyBeans
 * Copyright (C) 2007 Bull S.A.S.
 * Contact: easybeans@objectweb.org
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 * USA
 *
 * --------------------------------------------------------------------------
 * $Id: code_convention.xml 1786 2007-09-29 14:50:15Z benoitf $
 * --------------------------------------------------------------------------
 */

5.1.2. Imports

Imports should reference a valid class name, instead of using wildcard imports. Wildcard imports are not authorized.

For example, if the interface and class List and ArrayList are used, the imports should not be as follows:

import java.util.*;

The imports should have each class as follow:

      import java.util.List; 
      import java.util.ArrayList;

The classes should not have an unused import.

[Note] Note

The Eclipse IDE provides facilities to do this job. There is the option Organize Imports (Shift+Ctrl+O) in the menu Source that correctly inserts the imports and removes the unused imports. However, this option does not work well with 'import static'.

5.1.3. Class and Interface Declarations

The class and interface names should begin with an uppercase letter. Also, each class and interface has an @author tag in the comment. For example:

/**
 * This is an example that shows a class/interface declaration.
 * @author Gisele Pinheiro Souza
 * @author Eduardo Studzinski Estima de Castro
 */
 public class ClassExample implements InterfaceExample{
 }