-
Notifications
You must be signed in to change notification settings - Fork 0
Project Code Convention
[Naming Files][1]
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.
Example:
package mds.gpp.saudeemcasa.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
import mds.gpp.saudeemcasa.R;
import mds.gpp.saudeemcasa.model.Hospital;
public class HospitalAdapter extends ArrayAdapter<Hospital> {
private Context context = null;
private ArrayList<Hospital> lista = null;
public static final int COUNT = 15;
public HospitalAdapter(Context context, ArrayList<Hospital> lista){
super(context, 0, lista);
this.context = context;
this.lista = lista;
}
...
}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:
- Constants
- Attributes of the class
- Attributes of the instance
- Constructors
- Main methods
- Helper methods
Example of Code:
public class Stablishment {
}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.
public void onStatusChanged(String provider, int status, Bundle extras) {
}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.
- Global variables should not be used, but if it must then it shall follow the java pattern: name_name
public class Stablishment {
private String latitude = "";
private String longitude = "";
private String type = "";
private String postalCode = "";
}public class Search extends Bean {
public static int course_search = 0;
public static int institution_search = 1;
}Avoid lines longer than 80 characters. When a statement won't fill in a single line, it may be necessary to break it.
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, you must use the type '/** & */, and to start typing there must be a space.
/**
* Starts the application being inside the if for the first usage
* and the else for the times after that. Receives the response
* from server, take objects out of json and add to database.
**/
public void initControllerHospital() throws IOException, JSONException,
ConnectionErrorException {
}
...For comments inside methods, must use // for single declaration to short comments.
public void requestRating() throws ConnectionErrorException {
HttpConnection httpConnection = new HttpConnection(); // New Connection.
}If technical comments exceed one line they must be changed from '//' to /* & */, jumping a line to start and a line to finish.
/*
* Return the unique instance of DrugstoreController active in the
* project.
*/
return instance;
}7.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 {
}
}7.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.
package mds.gpp.saudeemcasa.view;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import mds.gpp.saudeemcasa.R;
import mds.gpp.saudeemcasa.controller.DrugStoreController;
public class GoogleMapDrugStore extends FragmentActivity {
private GoogleMap mMap;
DrugStoreController controller = DrugStoreController.getInstance(this);
@Override
protected void onCreate(Bundle savedInstanceState) 7.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.
private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1;
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this);7.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.
textViewDistance.setText(convertToKM(this.lista.get(position).getDistance()).toString()
+ " Km");7.5 Annotations
Annotations should be written in previous line, see samples:
/* Correct way */
@Override
public int getCount() {
...
}
/* Wrong way */
@Override public int getCount() {
...
}It should be used in any kind of annotation and any place.
The name of the test classes must have "Test" followed by the name of the tested class.
TestHospitalDao.javaThe name of the methods must sugest the funcionality witch is being tested.
@Test
public void testGetPostalCode() {
DrugStore drugStore = new DrugStore();
drugStore.setPostalCode("2034");
assertEquals("2034", drugStore.getPostalCode());
}