mercedes-benz / sechub

SecHub provides a central API to test software with different security tools.
https://mercedes-benz.github.io/sechub/
MIT License
259 stars 58 forks source link

Coding conventions shall contain information about ordering of methods fields etc. #3100

Open de-jcup opened 2 months ago

de-jcup commented 2 months ago

Situation

https://mercedes-benz.github.io/sechub/latest/sechub-techdoc.html#section-coding-conventions Does not contain information how fields methods etc. shall be ordered in java etc.

We normally lean on Java Code Conventions but we must clarify this in documentation.

Wanted

The link to java coding conventions should be in SecHub documentation + mentioning following:

  1. First static parts then other
  2. first fields, than methods, after this internal classes
  3. public before protected before package private and this before private
  4. Constructors always on top of other methods (except static)

An example:

package com.example.demo;

public class DemoClass1{

    public static final String PUBLIC_CONSTANT="I am public so I am before protected";
    protected static final String PROTECTED_CONSTANT="I am protected means before package private";
    static final String PACKAGE_PRIV_INTERNAL_CONSTANT="package private before private...";
    private static final String PRIV_INTERNAL_CONSTANT="private internal constant at the end";

    public String testField1;
    protected String testField2;
    String testField3;

    private String testField4;

    public static String createInfo() {
       return "from public...";
    } 

    protected static String createInfo2() {
       return "from protected...";
    } 

    public DemoClass1(){
      this("from-public");
    }

    protected DemoClass1(String from){
        SpeakerSubclass.INSTANCE.speak("I am from: "+from);
    }

    private static class SpeakerSubclass {

        private static final SpeakerSubclass INSTANCE = new SpeakerSubclass();

        private void speak(String what){
             System.out.println(what);
        }
    }

}