首页 > 其他 > 详细

代码风格、代码规范----maven

时间:2014-03-02 00:54:31      阅读:674      评论:0      收藏:0      [点我收藏+]

//摘抄自:maven官网(http://maven.apache.org/developers/conventions/code.html)2014-03-01 10:43:32

Java Code Style

The Maven style for Java is mainly:

  • White space: One space after control statements and between arguments (i.e. if ( foo ) instead of if(foo)), myFunc( foo, bar, baz ) instead of myFunc(foo,bar,baz)). No spaces after methods names (i.e. void myMethod(), myMethod( "foo" ))
  • Indentation: Always use 4 space indents and never use tabs!
  • Blocks: Always enclose with a new line brace.
  • Line wrapping: Always use a 120-column line width for Java code and Javadoc.
  • Readingness: Specify code grouping members, if needed. For instance in a Mojo class, you could have:
    public class MyMojo
    {
        // ----------------------------------------------------------------------
        // Mojo components
        // ----------------------------------------------------------------------
    
        /**
         * Artifact factory.
         *
         * @component
         */
        private ArtifactFactory artifactFactory;
    
        ...
    
        // ----------------------------------------------------------------------
        // Mojo parameters
        // ----------------------------------------------------------------------
    
        /**
         * The POM.
         *
         * @parameter expression="${project}"
         * @required
         */
        private MavenProject project;
    
        ...
    
        // ----------------------------------------------------------------------
        // Mojo options
        // ----------------------------------------------------------------------
        ...
    
        // ----------------------------------------------------------------------
        // Public methods
        // ----------------------------------------------------------------------
    
        /**
         * {@inheritDoc}
         */
        public void execute()
            throws MojoExecutionException
        {
          ...
        }
    
        // ----------------------------------------------------------------------
        // Protected methods
        // ----------------------------------------------------------------------
        ...
    
        // ----------------------------------------------------------------------
        // Private methods
        // ----------------------------------------------------------------------
        ...
    
        // ----------------------------------------------------------------------
        // Static methods
        // ----------------------------------------------------------------------
        ...
    }


    XML Code Style

    The Maven style for XML files is mainly:

    • Indentation: Always use 2 space indents, unless you‘re wrapping a new XML tags line in which case you should indent 4 spaces.
    • Line Breaks: Always use a new line with indentation for complex XML types and no line break for simple XML types. Always use a new line to separate XML sections or blocks, for instance:
      <aTag>
        <simpleType>This is a simple type</simpleType>
      
        <complexType>
          <simpleType>This is a complex type</simpleType>
        </complexType>
      </aTag>

      In some cases, adding comments could improve the readability of blocks, for instance:

          <!-- Simple XML documentation                                               -->

      or

          <!-- ====================================================================== -->
          <!-- Block documentation                                                    -->
          <!-- ====================================================================== -->

代码风格、代码规范----maven,布布扣,bubuko.com

代码风格、代码规范----maven

原文:http://www.cnblogs.com/dfg-09/p/3574787.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!