Chapter 5. EasyBeans Code Convention

Table of Contents

5.1. Files 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 number, use constants
5.4.4.4. Attribute name

The contributions should follow the EasyBeans code convention. An good document to get started is Java code convention. Besides, there is others conventions that are listed in this document.

In addition, the 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. Files Organization

5.1.1. Header

All files should have the header which contains the LGPL and the date.

If a file is modified, the modification year should be appended in the existing year. For example, if there was '1999' or '2004' put '1999-2006' or '2004-2006', respectively.

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

/**
 * EasyBeans
 * Copyright (C) 2006 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 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * --------------------------------------------------------------------------
 * $Id: code_convention.xml 314 2006-04-04 09:39:43Z pinheirg $
 * --------------------------------------------------------------------------
 */

5.1.2. Imports

The imports should reference a correct class name, instead of the wildcard imports. The wildcard imports is not authorized.

For example, if the classes List and ArrayList are used, the imports should not be like this:

import java.util.*;

But the imports should have each class as follow:

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

The classes should not have a 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 inserts correctly 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 name should begin with an uppercase. Also, each class and interface has a @author tag in the comment. For example:

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