Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
de-jcup opened this issue Apr 25, 2024 · 0 comments

Comments

@de-jcup
Copy link
Member

de-jcup commented Apr 25, 2024

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);
        }
    }
    
   
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant