Stylesheet - ProjectUrutau/urutau GitHub Wiki

1. Name of the File

All the project file's content must be named in English. The name of the files in Java must have the same name of the Class. Java establishes an order that must be used in the file:

  • Package
  • Imports
  • Class and it's methods.

2. Classes

The name of the classes must begin with capital letter in the singular, and must not be abbreviated. The following rules must be followed:

  • Names made by multiple letters must follow the standard UpperCamelCase, where each word will begin with a capital letter.
  • The name must not have any characters other than the letter of the alphabet.

The functional order of the components of the class are:

  • Attributes of the class
  • Constants
  • Attributes of the instance
  • Constructors
  • Public methods
    • business logic
    • view methods
  • Private methods

One good class to demonstrate it is the UserController

3. Methods

All methods will have their initial & final parameters without a space between the opening and closing of their parenthesis. Each aditional parameter will have a comma at the end of the following and a ' '(space) for the beginning of the new parameter.

When you open the keys to start your method, you'll have to insert a space between the past parameters.

The closing of the function needs to be aligned with the line in which it was open.

private void correctMethod(int firstParameter, int secondParameter, int thirdParameter) {

}

private void firstIncorrectMethod(int firstParameter,int secondParameter,int thirdParameter) {

}

private void secondIncorrectMethod(int firstParameter, int secondParameter, int thirdParameter){

}

4. Attributes

The attributes must follow this formatting standard:

  • Only one declaration in each line.
  • The names must follow the standard lowerCamelCase.
  • They can't be abbreviated.
  • They can't have special characters.
  • For constant names with two names, they need to be separated with the underscore and be written all with capital letters.
public class StyleSheet {
   private String sampleAtributte;
}

5. Comments

Comments must be the second type of information that is being declared.

The comments must be initialized first with capital letter. At their end, it must be add a '.' (dot) to indicate it's end.

To document a method or a class outside then, you must use '/**'. If technical comments exceed one line they must be changed from '//' to /* & /. To Attributes just use '/'. Some cases:

/**
 * This controller have business logic about users of system
 */
@Controller
public class UserController {
...
    /**
     * Gets a Entity by a field with certain value
     * 
     * @param field
     *            Column name into database
     * @param value
     *            Simple data
     * @return Object correspondent to Entity defined by DAO
     */
    @SuppressWarnings("unchecked")
    public List<Entity> get(String field, Object value) {
    ...
    /* It should be a simple description about artifact */
    @Size(min = 5, max = 255, message = "{artifact.description.size}")
    private String description;

6. Keys & Indent:

6.1 General Rules

All keys must be in the same line of command. The value of a tab must be equivalent to 4 spaces.

for() {
    if() {
    } else if() {
    } else {
    }
}

6.2 Blank Lines

The variable declarations and methods must be separated each by a blank line. Between the sentences package & import, must have a blank line. Between imports from different API's there must be a blank line.

6.3 Blank Spaces

Each attribution, with the operator '=' must be followed with an unitary space before & after. In the use of a comma, there must be an empty space after. There must be space between the closing of parenthesis and method keys. In logical & arithmetic operations, there must be a blank space between the operators and operands.

for(i = 1; i <= 12; i++) {
    if (i == 9) {
        System.out.println("September");
    }
}

6.4 Line Breakers

Instructions that break the line must be aligned with the operator '+' in the next line. In parameters, the line breaker (if necessary) must be after a comma.

String text = "That's a really long string that will need to be "
                 + "broken";

void methodWithManyParameters (String text, int firstNumber, String anotherString,
                              int age, int social_number){
{

6.5 Annotations

Annotations should be write in previous line, see samples:

// Correct way
@Inject
private User user;
...

// Wrong way
@Inject private User user;

It should be used in any kind of annotation and any place.

If an attribute have biggest annotations, you're need apply breaklines between two attributes. See:

@TableGenerator(name = "ARTIFACT_GEN", table = "ID_GEN", pkColumnName = "GEN_NAME", valueColumnName = "GEN_VAL")
	@Id
	@GeneratedValue(generator = "ARTIFACT_GEN", strategy = GenerationType.TABLE)
	private Long id;
	
	@OneToOne(fetch = FetchType.LAZY, orphanRemoval=true, optional=false)
	private User author;

7. Exception handling

When using resources for exception handling for the methods or logic & arithmetic expressions, these rules apply.

When you finish the 'try', must start in the same line with the 'catch' with a space of the end of one and the beginning of the other.

try {
	return this.test;
} catch(NullPointerException nullPointerException) {
	throw new NullPointerException("Test Failed");
} catch(RuntimeException runtimeException) {
	throw new RuntimeException("Improvement Necessary");
}

8. Test

The name of the test classes must have the name of the tested class followed by "Test"

BrandTest.java

The name of the methods must sugest the funcionality witch is being tested.

public void testShouldSaveBrandFromDatabase() throws SQLException, ClassNotFoundException, NotNullableException {
        assertEquals(2, Brand.getAll().size());
        Brand brand3 = new Brand("CHEVROLET");
        brand3.save();
        assertEquals(3, Brand.getAll().size());
        brand3.delete();
    }
⚠️ **GitHub.com Fallback** ⚠️