标签:2.0 点击 dex lca new tty 直接 imp 信息
Settings ->Plugins
在搜索框输入alibaba
即可看到Alibaba Java Code Guidelines
插件,点击Install
进行安装,然后重启IDE生效,安装完成后如图:
在项目名称上单击右键,在弹出菜单上选择编码规约扫描
,出现下图内容:
不规范的地方,有中文提示并且定位到了行,alibaba把问题分为block/critical/major三个等级,有些规则可以一键修复
if(conditions)statement;
/**
* CodeStandard
* @author zyh20175322
* @date 2019/5/2
*/
public class CodeStandard {
public static void main(String[] args) {
StringBuffer buffer = new StringBuffer();
buffer.append('S');
buffer.append("tringBuffer");
System.out.println(buffer.charAt(1));
System.out.println(buffer.capacity());
System.out.println(buffer.indexOf("tring"));
System.out.println("buffer = " + buffer.toString());
int n = 20;
if (buffer.capacity() < n){
buffer.append("1234567");
}
for (int i = 0; i < buffer.length(); i++){
System.out.println(buffer.charAt(i));
}
}
}
- 规范后显示`No suspicious code found. 1 files processed in File...`表明未发现可疑代码,规范成功
重写覆盖方法(Override Methods):Ctrl + O
Ctrl + I
Alt + Insert
Ctrl+Alt+T
Ctrl + Shift + 空格
Alt + /
Alt + Shift + /
Ctrl + 加号
Ctrl + 减号
Ctrl + Shift + 加号
Ctrl + Shift + 减号
Ctrl + /
Ctrl + Shift + /
Ctrl + Alt + L
Ctrl + Alt + Shift + L
重新整理代码 (Rearrange Code)
打开码云,进入仓库,点击管理 -> 添加仓库成员 -> 邀请用户
效果:
搭档的Complex代码:
public class Complex { //a + bi
private double a;
private double b;
public Complex(){ //构造方法,置0
this.a = 0;
this.b = 0;
}
public Complex(double a, double b) { //构造方法,初始化一个复数
this.a = a;
this.b = b;
}
public double getA(){ //获取实部
return this.a;
}
public double getB(){ //获取虚部
return this.b;
}
public double setA(double a){ //设置实部
this.a = a;
return a;
}
public double setB(double b){ //设置虚部
this.b = b;
return b;
}
Complex ComplexAdd(Complex c){//复数相加
double a = c.getA();
double b = c.getB();
double newA = a + this.a;
double newB = b + this.b;
Complex Result = new Complex(newA,newB);
return Result;
}
Complex ComplexMinus(Complex c){//复数相减
double a = c.getA();
double b = c.getB();
double newA = a - this.a;
double newB = b - this.b;
Complex Result = new Complex(newA,newB);
return Result;
}
Complex ComplexMulti(Complex c){//复数相乘
double a = c.getA();
double b = c.getB();
double newA = a * this.a;
double newB = b * this.b;
Complex Result = new Complex(newA,newB);
return Result;
}
Complex ComplexDiv(Complex c){//复数相乘
double a = c.getA();
double b = c.getB();
double newA = a / this.a;
double newB = b / this.b;
Complex Result = new Complex(newA,newB);
return Result;
}
public String toString() {
String s = " ";
if (b > 0)
s = a + "+" + b + "i";
if (b == 0)
s = a + "";
if (b < 0)
s = a + " " + b + "i";
return s;
}
}
- 搭档测试代码:
import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.*;
public class ComplexTest extends TestCase {
Complex c1 = new Complex(0, 3);
Complex c2 = new Complex(-1, -1);
Complex c3 = new Complex(2,1);
@Test
public void testgetRealPart() throws Exception {
assertEquals(-1.0, new Complex().setA(-1.0));
assertEquals(5.0, new Complex().setA(5.0));
assertEquals(0.0, new Complex().setA(0.0));
}
@Test
public void testgetImagePart() throws Exception {
assertEquals(-1.0, new Complex().setB(-1.0));
assertEquals(5.0, new Complex().setB(5.0));
assertEquals(0.0, new Complex().setB(0.0));
}
@Test
public void testComplexAdd() throws Exception {
assertEquals("-1.0+2.0i", c1.ComplexAdd(c2).toString());
assertEquals("2.0+4.0i", c1.ComplexAdd(c3).toString());
assertEquals("1.0", c2.ComplexAdd(c3).toString());
}
@Test
public void testComplexSub() throws Exception {
assertEquals("-1.0 -4.0i", c1.ComplexMinus(c2).toString());
assertEquals("2.0 -2.0i", c1.ComplexMinus(c3).toString());
assertEquals("3.0+2.0i", c2.ComplexMinus(c3).toString());
}
@Test
public void testComplexMulti() throws Exception {
assertEquals("-0.0 -3.0i", c1.ComplexMulti(c2).toString());
assertEquals("0.0+3.0i", c1.ComplexMulti(c3).toString());
assertEquals("-2.0 -1.0i", c2.ComplexMulti(c3).toString());
}
@Test
public void testComplexComplexDiv() throws Exception {
assertEquals("-0.0 -3.0i", c2.ComplexDiv(c1).toString());
assertEquals("-0.0 -3.0i", c2.ComplexDiv(c1).toString());
assertEquals("-2.0 -1.0i", c2.ComplexDiv(c3).toString());
}
}
- 测试结果:
添加创建者信息
给覆写方法加上@Override注解
方法名,参数名,成员变量,局部变量都统一使用lowerCamelCase,遵从驼峰形式
在if/else/for/while/do语句中必须使用大括号,即使只有一行代码
规范结果:
2018-2019-20175322 实验三敏捷开发与XP实践《Java开发环境的熟悉》实验报告
标签:2.0 点击 dex lca new tty 直接 imp 信息
原文地址:https://www.cnblogs.com/zyh5322/p/10803626.html