1. Summary
  2. Files
  3. Support
  4. Report Spam
  5. Create account
  6. Log in

Coding style

From jedit

Revision as of 09:01, 4 April 2012 by Jarekczek (Talk | contribs)
Jump to: navigation, search

This page describe the coding style to use in jEdit's core. It could also be used in plugins if you like it.

Contents

Modifiers

Modifier order is

  • public|protected|private
  • abstract
  • static
  • final
  • transient
  • volatile
  • synchronized
  • native
  • strictfp

ref: http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html sections 8.1.1, 8.3.1, 8.4.3


Spaces

operators

There are spaces around operators

separators

separators like , ; : do not have a space before, but have a space after them if it is not the end of the line.

Indentation

Tabs are used to indent code.

Braces

Braces are placed on next line at the same indentation level. The code between the braces is indented ex:

if (something)
{
	//some code
}

for (int i = 0; i < 10; i++)
{
	//some code
}

public class Foo
{
	private String test;
}

Array declarations

Declaration

Arrays are declared using java style, not C.

//valid
String[] xxx;
Object[] yyy;

//invalid
String xxx[]

Initialization

An empty array is initialized using the following syntax

String[] xxx = new String[3];

Initialize an array with values:

// There is a space after the opening brace and a space before the closing brace.
String[] xxx = { "val1", "val2" };
String[] yyy = new String[] { "val1", "val2" };

Annotations

@Deprecated

Deprecated elements must have a @Deprecated annotation.

@Override

A method that override a method of a superclass or implement a method from an interface must have a @Override annotation.

Folding

Explicit fold is used in jEdit's core.

Imports

Imports are surrounded by an explicit fold named "Imports" ex:

//{{{ Imports
import java.util.*;
//}}}

Imports should be sorted by:

  1. package name
  2. class name

Constructor(s)

Constructors are surrounded by an explicit fold named "XXX constructor" where XXX is the class name. ex:

//{{{ TextArea constructor
public TextArea()
{
} //}}}

If there are several constructors, all of them should be in only one explicit fold named "XXX constructors" where XXX is the class name. ex:

//{{{ TextArea constructors
public TextArea()
{
}

public TextArea(String s)
{
} //}}}

method(s)

Methods are surrounded by an explicit fold named "XXX() method" where XXX is the method name. The arguments are not added in the explicit fold, only (). ex:

//{{{ toString() method
public void toString()
{
} //}}}

If there are several methods with the same name, all of them should be in only one explicit fold named "XXX() methods" where XXX is the method name. The arguments are not added in the explicit fold, only (). ex:

//{{{ toString() methods
public void toString()
{
}

public void toString(Object o)
{
} //}}}

Inner class(es)

Inner classes are surrounded by an explicit fold named "XXX class" where XXX is the class name. ex:

//{{{ Foo class
public static class Foo
{
} //}}}

CHANGELOG

The changelog of jEdit is doc/CHANGES.txt file.

Here are the allowed format

If there is no bug or no patch

- some description (Developper Name)

If there is a bug

- some description (#bugID Developper Name)

If there are several bugs fixed in one time

- some description (#bugID, #bugID2 Developper Name)

For a patch

- some description (patch #patchID Patch author)

A patch that fixes a bug

- some description (#bugId, patch #patchID Patch author)
  • In jedit core put a new entry at the top of the list, to make merging easier (related post).
Personal tools