Coding Standards

Coding standards

  • these are additions to the JBoss standards
  • Don't use section comments like "// Constructors". They add as much utility as those /** @see */ javadoc comments we are avoiding now.
  • Abbreviation is evil (in most cases)... do not hurt readability to save three characters. Someone two years from now isn't going to know what the hell an SRN is. Don't abbreviate packages, classes or members. "em" is not a valid member name for an injected "entityManager". Even abbreviations that seem obvious cause problems because of inconsistent usage. If you choose to shorten configuration to config, others may choose not to. Only use abbreviations that are already the global standard. (E.g. URL is fine)
  • Use injection in ejb3. Don't use messy manual JNDI lookups where you don't need to.
  • Use a header like below for class and interface javadoc. (Don't use email addresses in the author tag and don't use @version $Revision$)
    /**
     * Description goes here
     *
     * @author John Mazzitelli
     * @author Ian Springer
     */
    

    If no author tag is specified for a class, Joseph Marques is most likely the author.

  • Use the following import order. Do not use * imports
    java
    <blank line>
    javax
    <blank line>
    <all other imports>
    <blank line>
    com
    <blank line>
    org
    <blank line>
    org.jboss
    <blank line>
    net.hyperic
    <blank line>
    org.jboss.on
    <blank line>
    org.rhq
    

In Eclipse you can use the following import file:

There are currently no attachments on this page.

The image shows where to put it / how to apply the import order:

  • Use the following file header.
    /*
     * RHQ Management Platform
     * Copyright 2010, Red Hat Middleware LLC, and individual contributors
     * as indicated by the @author tags. See the copyright.txt file in the
     * distribution for a full listing of individual contributors.
     *
     * This program is free software; you can redistribute it and/or modify
     * it under the terms of the GNU General Public License as published by
     * the Free Software Foundation version 2 of the License.
     *
     * This program 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 General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License
     * along with this program; if not, write to the Free Software
     * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     */
    
  • Naming
    EJB3 Stateless Session Beans
      <BusinessName>Bean: Implementation class
      <BusinessName>Local: Local interface
      <BusinessName>Remote: Remote interface
    
    BusinessNames:
      <PrimaryEntity>Manager: For code that deals primarily with one entity
      <UseCaseGroup>Boss: For code that is use case oriented
    
    Examples:
      DiscoveryBossBean, DiscoveryBossRemote, DiscoveryBossLocal (Deals with the use case of inventory discovery)
      ResourceManagerBean, ResourceManagerLocal (Deals in the storage of and access to Resource and its dependent entities)
    
  • Use constants for the names of all NamedQueries. This helps us three ways... a) avoid typing the wrong name for a query and not knowing until runtime, b) be able to "Find Usages" to see everyone using a query and c) Autocomplete to find the available queries.
    @NamedQueries({
       /* ResourceManagerBean queries */
       @NamedQuery(name = QUERY_FIND_BY_PARENT_AND_INVENTORY_STATUS,
                   query = "SELECT res ...
    ...
    
    public static final String QUERY_FIND_BY_PARENT_AND_INVENTORY_STATUS = "Resource.findByParentAndInventoryStatus";
    

Importing the RHQ Code Style into IntelliJ IDEA

  1. Save rhq-idea-settings.jar to a local directory.
  2. Start IntelliJ.
  3. Select File>Import Settings, then select rhq-idea-settings.jar and click OK.
  4. Restart IntelliJ.
  5. Go to Settings>Code Style, select Use global settings, select Scheme name "RHQ", then click OK.
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.