CodeNavi自定义规则节点属性(基础节点)

举报
yd_296685231 发表于 2024/06/27 10:56:02 2024/06/27
【摘要】 CodeNavi自定义规则的基础节点

节点


描述


示例


属性

名称

描述

值类型

示例

DSL 规则

annotation


注解


public class Test extends ArrayList {
@TheAnnotation(isOk = false, num = 3, str = Test.test1)
    public void functionWithAnnotation() {

    }
}


name

名称

字符串

@TheAnnotation(isOk = false)

annotation ann where ann.name == "TheAnnotation";

annoMembers

注解的注解项

annomember节点集合

@TheAnnotation(isOk = false, num = 3, str = Test.test1)

annotation ann where
    ann.annoMembers contain am where
        am.name == "isOk";

annoMember


注解项


@TheAnnotation(isOk = false, num = 3, str = Test.test1)


name

名称

字符串

@TheAnnotation(isOk = false, num = 3, str = Test.test1)

annotation ann where
    ann.annoMembers contain am where
        am.name == "str";

annoValue

注解项的具体值

literalenumConstantAccessfieldAcccess节点

@TheAnnotation(isOk = false, num = 3, str = Test.test1)

annotation ann where
    ann.annoMembers contain am where
        am.annoValue amv where and(
            amv is fieldAccess,
            amv.name == "test1"
        );

recordDeclaration








类/接口声明








public class MyClass { }

public interface MyInterface { };








name

类名,包含包名

字符串

package com.huawei.secbrella.kirin.test.sourcefile.record;

public class TypeTest {

}

recordDeclaration rd where
    rd.name == "com.huawei.secbrella.kirin.test.sourcefile.record.TypeTest";

comments

注释

comment节点集合

// 注释
public class TypeTest {

}

recordDeclaration rd where
    rd.comments contain lineComment;

kind

类类型,可能是interfaceclass

字符串

public class TypeTest {

}

recordDeclaration rd where
    rd.kind == "class";

superTypes

所有直接和间接集成的父类和接口

recordDeclartion节点集合

class MyList extends ArrayList<String> {

}

class SecondMyList extends MyList {

recordDeclaration rd where
    rd.superTypes contain sType where
        sType.name endWith "ArrayList";

directSuperTypes

直接集成的父类和接口

recordDeclartion节点集合

class MyList extends ArrayList<String> {

}

recordDeclaration rd where
    rd.directSuperTypes contain sType where
        sType.name endWith "ArrayList";

definedFields

类中定义的所有字段

fieldDeclaration节点集合

class RecordDeclarationDemo extends Father { // 告警行

    private static int COUNT = 0;
}

recordDeclaration rd where
    rd.definedFields.size() == 1;

definedConstructors

类中定义的所有构造方法

functionCall节点集合

class RecordDeclarationDemo extends Father { // 告警行

    private static int COUNT = 0;
    RecordDeclarationDemo() {}
}

recordDeclaration rd where
    rd.definedConstructors.size() == 1;

definedMethods

类中定义的所有方法

functionCall节点集合

class RecordDeclarationDemo extends Father { // 告警行

    private static int COUNT = 0;
    RecordDeclarationDemo() {}

    public void recordDeclarationMethod01() {

    }
}

recordDeclaration rd where
    and(
        rd.definedMethods.size() == 1,
        rd.definedMethods contain fd where
            fd.name == "recordDeclarationMethod01"
);

anonymousInnerClassExpression


匿名内部类表达式


public static void main(String[] args) {
        new MemberClass() {  // 告警行
            @Override
            public void f() {
                int i = 0;
                System.out.println("aaaaa");
            }

        }.f();
}


name

 

字符串

public static void main(String[] args) {
        new MemberClass() {  // 告警行
            @Override
            public void f() {
            }
        }.f();
}

anonymousInnerClassExpression ac where and(
    ac.name == "MemberClass",
    ac.enclosingFunctionName == "main"
  );

anonymousClassBody

 

任意节点集合

public static void main(String[] args) {
        new MemberClass() {  // 告警行
            @Override
            public void f() {
            }
        }.f();
}

anonymousInnerClassExpression ac where
        ac.anonymousClassBody ab contain functionDeclaration;

arrayAccess




数组访问表达式




int a = arr[3];
log.info(arr2[1][3]);




arrayIndex

 

literal、任意access类节点、functionCall节点等

Integer[] arr = {0,1,2,3,4};
Integer i = arr[3];

arrayAccess aa where and(
    aa.arrayIndex is numLiteral,
    aa.arrayIndex.value == 3
);

base

 

variableAccess等任意access类节点、functionCall节点等

int a = arr[3];
log.info(arr2[1][3]);

arrayAccess arr where or(
    arr.base is variableAccess,
    arr.base is arrayAccess
);

rootBase

 

variableAccess等任意access类节点、functionCall节点等

String[] a1 = arr[3];
String a2 = arr[1][3];

arrayAccess arr where arr.rootBase rb where and(
    rb is variableAccess,
    rb.name == "arr"
);

type

 

objectType节点

System.out.println(hello[1]);

arrayAccess arr where
    arr.type.name == "int";

arrayCreationExpression




数组创建表达式




int[] arr = new String[11];




dimensions

数组的维度集合

节点集合

String[] array = new String[10];

arrayCreationExpression ac where
    ac.dimensions.size() == 1;

dimensions[]

数组的维度

numLiteralaccess类节点、functionCall节点等

String[] array = new String[10][a];

arrayCreationExpression ac where and(
    ac.dimensions.size() == 2,
    ac.dimensions[0] dm where and(
        dm is numLiteral,
        dm.value == 10
    )
);

initArray

数组创建的初始化值

initArrayExpression

String[] array2 = new String[]{"abc", "dec"};

arrayCreationExpression ac where
    ac.initArray.elements contain ele where
        ele.value == "abc";

type

数组创建的类型

objectType节点

String[] array = new String[10];

arrayCreationExpression ac where
    ac.type.name == "java.lang.String";

initArrayExpression


初始化数组表达式


int[] arr = {1, 2, 4};
@Parameter(names = {"ok", "hello", "yes"})


elements

数组初始化包含的元素集合

节点集合

names = {"ok", "hello", "yes"}

initArrayExpression ia where
    ia.elements.size() == 3;

elements[]

数组初始化的元素

literal类节点、变量类

new String[] {"ok", "ey"};

initArrayExpression ia where
    ia.elements[0].value == "ok";

functionDeclaration





















方法声明





















public void fun() {
    System.out.println(" ");
}





















name

方法名

字符串

public static void debugFirst() {
}

functionDeclaration fd where
    fd.name == "debugFirst";

isConstructor

是否构造函数

布尔值

public MyTest() {}

functionDeclaration fd where
    fd.isConstructor == true;

hasBody

是否有方法体

布尔值

public static void debugFirst() {
}

functionDeclaration fd where
    fd.hasBody;

comments

方法的注释

comments节点

// 注释
public static String sayHello() {}

functionDeclaration fd where
    fd.comments contain lineComment;

type

返回值的类型

objectType节点

public static String sayHello() {
        return "hello";
    }

functionDeclaration fd where
    fd.type.name == "java.lang.String";

functionUsages

调用了该方法的位置

functionCall节点集合

public static void debugFirst() {
    }

    public void debugSecond(int param) {
        FunctionTest.debugFirst();
    }

functionDeclaration fd where and(
    fd.name == "debugFirst",
    fd.functionUsages contain fc where
        fc.enclosingFunctionName == "debugSecond"
);

callers

调用了该方法的位置所在方法声明

functionDeclaration节点集合

public static void debugFirst() {
    }

    public void debugSecond(int param) {
        FunctionTest.debugFirst();
    }

functionDeclaration fd where and(
    fd.name == "debugFirst",
    fd.callers contain cc where cc.name == "debugSecond"
);

assignStatements

方法体中的所有assignStatement节点

assignStatement节点集合

public void functionCalls_first_argument() {            String s = "hello";       

    StringBuilder sb = new StringBuilder("");

}

functionDeclaration fd where fd.assignStatements.size() == 2;

fieldAccesses

方法体中的所有fieldAccesses节点

fieldAccesses节点集合

public void fieldAccesses_boolean() {
        System.out.println(this.testFlag);
    }

functionDeclaration fd where
    fd.fieldAccesses contain fa where
        fa.name == "testFlag";

functionCalls

方法体中的所有functionCall节点

functionCall节点集合

public void assignStatements_function_call_to_variable() {
        boolean result = "hello".equals("no");
        System.out.println(result);
    }

functionDeclaration fd where
    fd.functionCalls contain fc where
        fc.name == "equals";

ifBlocks

方法体中的所有ifBlock节点

ifBlock节点集合

public void loopBlocks_for(boolean flag) {
        if (flag) {
            for (int i = 0; i < 10; i++) {
                System.out.println(i);
            }
        }
    }

functionDeclaration fd where
    fd.ifBlocks contain ib where
        ib contain forBlock;

loopBlocks

方法体中的所有loopBlock节点

loopBlock节点集合

public void loopBlocks_while(boolean flag) {
        int m = 10;
        while (m > 0) {
            m--;
        }
    }

functionDeclaration fd where
    fd.loopBlocks contain ib where
        ib is whileBlock;

parameters

方法体中的所有parameterDeclaration节点

parameterDeclaration节点集合

public void loopBlocks_for(boolean flag) {}

functionDeclaration fd where
    fd.parameters contain pa where
        pa.name == "flag";

returnStatements

方法体中的所有returnStatement节点

returnStatement节点集合

public int returnStatements_return_int(int m) {
        if (m > 10) {
            if (m < 100) {
                return randomInt();
            }
        }
        return 0;
    }

functionDeclaration fd where
    fd.returnStatements contain rs where
        rs in ifBlock;

variableAccesses

方法体中的所有variableAccess节点

variableAccess节点集合

public void loopBlocks_while(boolean flag) {
        int m = 10;
        while (m > 0) {
            m--;
        }
    }

functionDeclaration fd where
    fd.variableAccesses contain va where
        va.name == "m";

body

方法体

body语句块

public void loopBlocks_while(boolean flag) {
        int m = 10;
        while (m > 0) {
            m--;
        }
    }

functionDeclaration fd where
    fd.body contain assignStatement;

body.statementNum

方法体的语句数量

数值

public String functionCase() {
        Boolean result = validNull();
        return "";
    }

functionDeclaration fd where
    fd.body.statementNum == 2;

firstStatement

方法的第一个完整的语句

任意节点

public String functionCase() {
        Boolean result = validNull();
        return "";
    }

functionDeclaration fd where
    fd.firstStatement contain variableDeclaration;

lastStatement

方法的最后一个完整的语句

任意节点

private boolean isNumeric(String str) {
        return false;
}

functionDeclaration fd where
    fd.lastStatement contain returnStatement;

subMethods

所有重写了该方法的子类方法

functionDecalration节点集合

public class FatherDemo {
        public void fatherDemoMethod() { // 告警行
            System.out.println("father class");
        }

        public void demoMethod() {

        }
    }

    public class SonDemo extends FatherDemo {
        public void fatherDemoMethod() {
            System.out.println("Son class");
        }
    }

functionDeclaration fd where
    and(
        fd.name == "fatherDemoMethod",
        fd.subMethods contain fd2 where
            fd2.name == "fatherDemoMethod"
);

superMethods

该方法重写的父类方法

functionDecalration节点集合

public class FatherDemo {
        public void fatherDemoMethod() { // 告警行
            System.out.println("father class");
        }

        public void demoMethod() {

        }
    }

    public class SonDemo extends FatherDemo {
        public void fatherDemoMethod() {
            System.out.println("Son class");
        }
    }

functionDeclaration fd where
    and(
        fd.name == "fatherDemoMethod",
        fd.superMethods contain fd2 where
            fd2.name == "fatherDemoMethod"
);

paramDeclaration


参数声明,方法定义中的参数定义


public void fun(String name) {
    System.out.println(name);
}


name

参数的名字

字符串

public void fun(String name) {
    System.out.println(name);
}

paramDeclaration pa where pa.name == "name";

type

参数的类型

objectType节点

public void fun(String name) {
    System.out.println(name);
}

paramDeclaration pa where pa.type.name == "java.lang.String";

functionCall







方法调用







Objects.isNull(str);
String name = person.getName();







name

方法名

字符串

Objects.isNull(str);

functionCall fc where
    fc.name == "isNull";

function

调用的方法

functionDeclaration节点

public String functionCase() {
        Boolean result = validNull();
        return "";
    }

    public Boolean validNull() {
        return false;
    }

functionCall fc where fc.function fd where and(
    fd is functionDeclaration,
    fd.name == "validNull",
    fd.returnStatements contain rs where
        rs.returnValue.value == false
);

possibleFunctions

调用的方法及其重写与被重写的方法,用于多态类创建对象时,声明类型为父类,实例化类型为子类型,调用对象方法时function属性应定位到子类的方法中,但实际会定位到父类方法中,用此属性规避这种问题导致的漏报

functionDeclaration节点

public static void main(String[] args) {
        Son sg = new GrandSon();
        sg.run();  //父类和子类都有这个方法
}

functionCall fc2 where and(
    fc2.base.name == "sg",
    fc2.possibleFuncs contain fun where and(
        fun.enclosingClass.name endWith "GrandSon",
        fun contain stringLiteral sl1 where
                sl1.value == "Grandson is running"
    )
);

base

直接调用者

valueAccess类节点、functionCall节点等

MyRandom.aa();

functionCall fc where and(
    fc.name == "aa",
    fc.base.name == "MyRandom"
);

rootBase

根调用者

valueAccess类节点、functionCall节点等

a().b().c();

functionCall fc where and(    fc.name == "c",    fc.rootBase is functionCall,    fc.rootBase.name == "a");

arguments

入参集合

valueAccess类节点、functionCall节点等的集合

sb.append(s.toUpperCase(Locale.ENGLISH));

functionCall fc where fc.arguments contain arg where
and(
     arg is functionCall,
     arg.name == "toUpperCase",
     arg.arguments contain fieldAccess
);

arguments[n]

第n个入参

valueAccess类节点、functionCall节点等的集合

add(a, b);

functionCall fc where
    fc.arguments[1].name == "b";

argument



函数入参



JSON.parseObject("{\"name\":\"A\"}", Demo.class);



name

参数名

字符串

System.out.println(i)

argument arg where arg.name == "i";

argumentIndex

参数的index

数值

System.out.println(i)

argument arg where arg.argumentIndex == 0;

argumentHolder

使用该参数的方法调用

functionCall节点

System.out.println(i)

argument arg where arg.argumentHolder.name == "println";

methodReferenceExpression



方法引用表达式



List::stream



name

方法名

字符串

Supplier<Integer> size = list::size;

methodReferenceExpression mf where
mf.name == "size";

function

调用的方法

functionDeclaration节点

Supplier<Integer> size = list::size;

methodReferenceExpression mf where
mf.function.name == "size";

type

方法返回值类型

objectType节点

Supplier<Integer> size = list::size;

methodReferenceExpression mf where
mf.type.name == "int";

objectCreationExpression





对象创建表达式





new ArrayList();





name

方法名

字符串

new MethodRefTypeTest();

objectCreationExpression obc where
obc.name == "MethodRefTypeTest";

type

返回值类型

objectType节点

new MethodRefTypeTest();

objectCreationExpression obc where
obc.type.name == "com.huawei.secbrella.kirin.test.sourcefile.methodRefType.MethodRefTypeTest";

function

调用的构造方法

functionDeclaration节点

public class MethodRefTypeTest {
    MethodRefTypeTest() {
       
    }
    public static void main(String[] args) {
        new MethodRefTypeTest();
    }
}

objectCreationExpression obc where
    obc.function.name == "MethodRefTypeTest";

arguments

入参集合

valueAccess类节点、functionCall节点等的集合

new String("Hello");

objectCreationExpression obc where
obc.arguments.size() == 1;

arguments[n]

第n个入参

valueAccess类节点、functionCall节点等的集合

new String("Hello");

objectCreationExpression obc where
obc.arguments[0].value == "Hello";

assignStatement


赋值语句,同时也是二元表达式


a = 10;


lhs

赋值语句的左值

valueAccess类节点

a = 10;

assignStatement ass where ass.lhs.name == "a";

rhs

赋值语句的右值

literal类节点、valueAccess类节点、functionCall类节点

a = 10;

assignStatement ass where ass.rhs.value == 10;

binaryOperation




二元表达式,包括 +、-、*、/运算、=赋值运算等




a = 10;
a + b;




lhs

二元表达式的左值

literal类节点、valueAccess类节点、functionCall类节点

int i = 1;

binaryOperation bo where bo.lhs.name == "i";

operator

二元表达式的操作符

字符串

while (i == 1)

binaryOperation bo where bo.operator == "==";

rhs

二元表达式的右值

literal类节点、valueAccess类节点、functionCall类节点

a > b;

binaryOperation bo where bo.rhs.name == "b";

operands

二元表达的操作对象(左值和右值)

节点集合

a > b;

binaryOperation bo where
bo.operands contain op where
op.name == "a";

castExpression


强制类型转换


Son sonFromDad = (Son) dad;


castType

目标类型

node

ArrayList second = (ArrayList) list;

castExpression ce where
ce.castType.name == "java.util.ArrayList";

operand

操作对象

node

ArrayList second = (ArrayList) list;

castExpression ce where
ce.operand.name == "list";

fieldDeclaration




字段定义(声明)




public static int count = 0;
private String name




name

字段名

字符串

private int aes_key = 3;

fieldDeclaration fd where fd.name == "aes_key";

comments

注释

comment节点集合

// 注释
private int aes_key = 3;

fieldDeclaration fd where fd.comments contain lineComment;

initializer

初始化值

任意节点

private int aes_key = 3;

fieldDeclaration fd where fd.initializer.value == 3;

valueUsages

使用该字段的节点

valueAccess类节点、functionCall节点等

private int aes_key = 3;
   
public void test() {
        this.aes_key = 10;
}

fieldDeclaration fed where
fed.valueUsages contain va where
va in functionDeclaration fd where fd.name == "test";

fieldAccess



字段(成员变量)访问



System.out.println(Person.name);



name

字段名

字符串

Person.name

fieldAccess fa where fa.name == "name";

field

字段定义

fieldDeclaration节点

private int aes_key = 3;
   
public void test() {
        this.aes_key = 10;
}

fieldAccess fa where fa.field.initializer.value == 3;

base

访问者

任意节点

Person.name

fieldAccess fa where fa.base.name == "Person";

enumDeclaration




枚举类声明




enum MyEnum {
}




name

枚举全类名

字符串

enum TheEnum {
    PUT, HEAD, DELETE;
}

enumDeclaration ed where ed.name == "com.huawei.secbrella.kirin.test.sourcefile.enumConstantTest.TheEnum";

definedFields

定义的所有字段

fieldDeclaration节点集合

enum Planet {
    MERCURY(3.303e+23, 2.4397e6),

    VENUS(1, 6.0518e6),
    public static final double G = 6.67300E-11;

    private final double mass; // in kilograms

    private final double radius; // in meters
}

enumDeclaration ed where
    ed.definedFields.size() == 3;

definedMethods

定义的所有方法

functionDeclaration节点集合

enum Planet {
    private final double radius; // in meters

    Planet(double mass, double radius) {
        this.mass = mass;
        this.radius = radius;
    }
}

enumDeclaration ed where
    ed.definedMethods.size() == 1;

enumConstants

定义的所有枚举常量

enumConstant节点集合

enum Planet {
    MERCURY(3.303e+23, 2.4397e6),

    VENUS(1, 6.0518e6),

    EARTH(5.976e+24, 6.37814e7),

    MARS(6.421e+23, 3.3972e7),

    public static final double G = 6.67300E-11;
}

enumDeclaration ed where ed.enumConstants.size() == 4;

enumConstantDeclaration




枚举常量声明, 枚举类中用逗号分隔的常量




public enum DayOfWeek {
        MONDAY, TUESDAY, WEDNESDAY
}

enum Planet {
    MERCURY(3.303e+23, 2.4397e6),
    VENUS(1, 6.0518e6),
    EARTH(5.976e+24, 6.37814e7);
    public static final double G = 6.67300E-11; // 成员变量声明
}




name

枚举常量名

字符串

public enum DayOfWeek {
    MONDAY, TUESDAY, WEDNESDAY
}

enumConstantDeclaration ed where ed.name == "Monday";

definedEnumConstantFields

枚举常量中定义的所有字段

fieldDeclaration节点的集合

enum Week3 { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday { private String tmp = "test"; }}

enumConstantDeclaration ed where ed.definedEnumConstantFields.size() == 1;

definedEnumConstantMethods

枚举常量中定义的所有方法

functionDeclaration节点的集合

enum Week3 {
    Monday, Tuesday, Wednesday, Thursday, Friday,
    Saturday {
        private String tmp = "test";
    },
    Sunday {
        public void work() {
            System.out.println("休息");
        }
    };
}

enumConstantDeclaration ed where
    ed.definedEnumConstantMethods contain fd where
        fd.name == "work";

enumConstantArguments

枚举常量中的入参

literal节点、valueAccess类节点、functionCall节点等的集合

enum Planet {
    MERCURY(3.303e+23, 2.4397e6)

    NEPTUNE(1.024e+26, 2.4746e6);

    public static final double G = 6.67300E-11;

    private final double mass; // in kilograms

    private final double radius; // in meters

    Planet(double mass, double radius) {
        this.mass = mass;
        this.radius = radius;
    }
}

enumConstantDeclaration ed where
ed.enumConstantArguments.size() == 2;

enumConstantAccess



枚举常量访问



public void fun(DayOfWeek n) {
System.out.println(DayOfWeek.MONDAY);
System.out.println(n.MONDAY);
}



name

枚举常量名

字符串

Planet.EARTH

enumConstantAccess ea where ea.name == "EARTH";

enumConstant

访问的枚举常量所在声明

enumConstant节点

Planet.EARTH

enumConstantAccess ea where ea.enumConstant.name == "EARTH";

base

访问者

任意节点

Planet.EARTH;

enumConstantAccess ea where ea.base.name == "Planet";

exceptionBlock



异常捕捉代码块,包括tryBlock、catchBlock、finallyBlock



try {
    int num = 1/0;
} catch (Exception e) {
    throw new RuntimeException(e);
} finally {
    System.out.println("finally");
}



tryBlock

try语句块

tryBlock节点

try {
    int num = 1/0;
} catch (Exception e) {
    throw new RuntimeException(e);
} finally {
    System.out.println("finally");
}

exceptionBlock eb where
eb.tryBlock contain variableDeclaration;

catchBlocks

所有的catch语句块

catchBlock节点的集合

try {
    int num = 1/0;
} catch (Exception e) {
    throw new RuntimeException(e);
} finally {
    System.out.println("finally");
}

exceptionBlock eb where
eb.catchBlocks contain cb where cb contain throwStatement;

finallyBlock

finally语句块

finallyBlock节点

try {
    int num = 1/0;
} catch (Exception e) {
    throw new RuntimeException(e);
} finally {
    System.out.println("finally");
}

exceptionBlock eb where
    eb.finallyBlock contain functionCall fc where
        fc.name == "println";

tryBlock

try语句块

try { }

_

try语句块

tryBlock节点

try {
    int num = 1/0;
} catch (Exception e) {
    throw new RuntimeException(e);
} finally {
    System.out.println("finally");
}

tryBlock tb where
tb contain variableDeclaration;

catchBlock

catch语句块

try {
int num = 1/0;
} catch (Exception e) {
System.out.println(e);
}

parameters

 

node list

try {
    int num = 1/0;
} catch (Exception e) {
    System.out.println(e);
}

catchBlock cb where
    cb.parameters contain p where
        p.name == "e";

finallyBlock

finally代码块

finally {
}

_

finally语句块

finallyBlock节点

try {
    int num = 1/0;
} catch (Exception e) {
    throw new RuntimeException(e);
} finally {
    System.out.println("finally");
}

finallyBlock fb where
    fb contain functionCall fc where
        fc.name == "println";

tryWithResources




tryWithResources异常捕捉代码块




try (Statement stmt = con.createStatement()) {
            System.out.println("try-with-resources block");
        } catch (SQLException e1) {
            System.out.println(e);
        } catch (Exception e2) {
            System.out.println(e2);
        }




tryBlock

try语句块

tryBlock节点

try (Statement stmt = con.createStatement()) {
    System.out.println("try-with-resources block");
} catch (SQLException e1) {
    System.out.println(e);
} catch (Exception e2) {
    System.out.println(e2);
}

tryWithResources eb where
    eb.tryBlock contain variableDeclaration;

catchBlocks

所有的catch语句块

catchBlock节点的集合

try (Statement stmt = con.createStatement()) {
    System.out.println("try-with-resources block");
} catch (SQLException e1) {
    System.out.println(e);
} catch (Exception e2) {
    System.out.println(e2);
}

tryWithResources eb where
    eb.catchBlocks contain cb where cb contain throwStatement;

finallyBlock

finally语句块

finallyBlock节点

try (Statement stmt = con.createStatement()) {
    System.out.println("try-with-resources block");
} catch (SQLException e1) {
    System.out.println(e);
} finally {
    System.out.println(e2);
}

tryWithResources eb where
    eb.finallyBlock contain functionCall fc where
        fc.name == "println";

resources

任意节点

若干statements节点的集合

try (Statement stmt = con.createStatement()) {
    System.out.println("try-with-resources block");
} catch (SQLException e1) {
    System.out.println(e);
} catch (Exception e2) {
    System.out.println(e2);
}

tryWithResources twr where
    twr.resources contain re where
        re contain functionCall fc where
                    fc.name == "createStatement";

throwStatement

throw语句,异常抛出语句

try {
throw new Exception();
}

operand

 

node

throw new Exception();

throwStatement tr where
tr.operand is objectCreationExpression;

forBlock







for循环代码块







for (int i = 0; i < list.size(); i++) {
}







initialization

变量初始化

variableDeclaration variableAccess节点

for (int i = 0; i < list.size(); i++) {
}

forBlock fb where fb.initialization.name == "i";

condition

循环条件

binaryOperation

for (int i = 0; i < list.size(); i++) {
}

forBlock fb where fb.condition.rhs is functionCall;

iteration

迭代操作

unaryOperation节点

for (int i = 0; i < list.size(); i++) {
}

forBlock fb where fb.iteration.operator == "++";

body

循环体

body语句块

for (int i = 0; i < list.size(); i++) {
i++
}

forBlock fb where
fb.body contain variableAccess vs where
vs.name == "i";

body.statementNum

body语句块的语句数量

数值

for (int i = 0; i < list.size(); i++) {
i++
}

forBlock fb where
fb.body.statementNum == 1;

firstStatement

forBlock的第一条语句

任意节点

for (int i = 0; i < list.size(); i++) {
i++
}

forBlock fb where
fb.firstStatement contain unaryOperation;

lastStatement

forBlock的最后一条语句

任意节点

for (int j1 = 1; j1 < 50 && k1 < 50; j1++, k1++) {
System.out.println(j1);
k1++;
}

forBlock fb where
fb.lastStatement contain unaryOperation;

forEachBlock






forEach循环代码块






for (Integer integer : list) {
}






variable

循环变量

variableDeclaration节点

for (String str : list) {
System.out.println(str);
}

forEachBlock fb where and(
fb.variable is variableDeclaration,
fb.variable.name == "str"
);

iterable

被循环的变量

任意节点

for (String str : list) {
System.out.println(str);
}

forEachBlock fb where
fb.iterable.name == "list";

body

循环体

body语句块

for (String str : list) {
System.out.println(str);
}

forEachBlock fb where
fb.body contain functionCall;

body.statementNum

body语句块的语句数量

数值

for (String str : list) {
System.out.println(str);
}

forEachBlock fb where
fb.body.statementNum == 1;

firstStatement

forEachBlock的第一条语句

任意节点

for (String str : list) {
System.out.println(str);
}

forEachBlock fb where
fb.body contain functionCall;

lastStatement

forEachBlock的最后一条语句

任意节点

for (String str : list) {
System.out.println(str);
System.out.print(’ ‘);
}

forEachBlock fb where
fb.lastStatement contain functionCall;

whileBlock





while循环语句块





while() {
}





condition

循环条件

任意节点

while(i > list.size()) {
i++;
}

whileBlock wb where
wb.condition contain binaryOperation bo where
bo.lhs.name == "i";

body

循环体

body语句块

while(i > list.size()) { i++;}

whileBlock wb where wb.body contain unaryOperation;

body.statementNum

body语句块的语句数量

数值

while(i > list.size()) {
i++;
System.out.print(’ ‘);
}

whileBlock wb where
wb.body.statementNum == 2;

firstStatement

whileBlock的第一条语句

任意节点

while(i > list.size()) {
i++;
System.out.print(’ ‘);
}

whileBlock wb where
wb.firstStatement contain unaryOperation;

lastStatement

whileBlock的最后一条语句

任意节点

while(i > list.size()) {
i++;
System.out.print(’ ‘);
}

whileBlock wb where
wb.lastStatement contain functionCall;

doWhileBlock





do…while语句块





do {
} while ();





condition

循环条件

任意节点

do {
i++;
} while (i < 10);

doWhileBlock wb where
wb.condition contain binaryOperation bo where
bo.lhs.name == "i";

body

循环体

body语句块

do {
i++;
} while (i < 10);

doWhileBlock wb where
wb.body contain unaryOperation;

body.statementNum

body语句块的语句数量

数值

do {
i++;
System.out.print(i);
} while (i < 10);

whileBlock wb where
wb.body.statementNum == 2;

firstStatement

forBlock的第一条语句

任意节点

do {
i++;
System.out.print(i);
} while (i < 10);

doWhileBlock wb where
wb.firstStatement contain unaryOperation;

lastStatement

forBlock的最后一条语句

任意节点

do {
i++;
System.out.print(i);
} while (i < 10);

doWhileBlock wb where
wb.lastStatement contain functionCall;

loopBlock





循环语句块,包括forBlock, forEachBlock, doWhileBlock, whileBlock





for() {};
while() {};





condition

循环条件

任意节点

while(i > list.size()) {
i++;
}

whileBlock wb where
wb.condition contain binaryOperation bo where
bo.lhs.name == "i";

body

循环体

body语句块

while(i > list.size()) {
i++;
}

whileBlock wb where
wb.body contain unaryOperation;

body.statementNum

body语句块的语句数量

数值

while(i > list.size()) {
i++;
System.out.print(’ ‘);
}

whileBlock wb where
wb.body.statementNum == 2;

firstStatement

loopBlock的第一条语句

任意节点

while(i > list.size()) {
i++;
System.out.print(’ ‘);
}

whileBlock wb where
wb.firstStatement contain unaryOperation;

lastStatement

loopBlock的最后一条语句

任意节点

while(i > list.size()) {
i++;
System.out.print(’ ‘);
}

whileBlock wb where
wb.lastStatement contain functionCall;

ifBlock



if语句块



if(num > 10) {

} else {
}



condition

if条件

binaryOperation节点

if (m > 10) {
System.out.println("m > 10");
} else {
System.out.println("m <= 10");
}

ifBlock ib where
ib.condition contain binaryOperation bo where
bo.operator == ">";

thenBlock

if条件为true执行的语句

block语句块

if (m > 10) {
System.out.println("m > 10");
} else {
System.out.println("m <= 10");
}

ifBlock ib where
ib.thenBlock contain stringLiteral ss where
ss.value == "m > 10";

elseBlock

if条件为false执行的语句

block语句块

if (m > 10) {
System.out.println("m > 10");
} else {
System.out.println("m <= 10");
}

ifBlock ib where
ib.elseBlock contain stringLiteral ss where
ss.value == "m <= 10";

thenBlock

then语句块,if 条件成立后执行

if(num > 10) {
do();
}

_

if条件为true执行的语句

block语句块

if (m > 10) {
System.out.println("m > 10");
} else {
System.out.println("m <= 10");
}

thenBlock tb where
tb contain stringLiteral ss where
ss.value == "m > 10";

elseBlock

else语句块

else {
};

_

if条件为false执行的语句

block语句块

if (m > 10) {
System.out.println("m > 10");
} else {
System.out.println("m <= 10");
}

elseBlock eb where
eb contain stringLiteral ss where
ss.value == "m <= 10";

importDeclaration


import声明


import com.huawei.java….


name

import的类名

字符串

import static java.lang.String.valueOf;

importDeclaration im where
im.name == "java.lang.String.valueOf";

isStatic

import是否为静态

布尔值

import static java.lang.String.valueOf;

importDeclaration im where
im.isStatic;

instanceofExpression


类型判断表达式


if(father instanceof Father) {

}


lhs

左值

任意节点

father instanceof Father

instanceofExpression ie where
ie.lhs.name == "father";

rhs

右值,类型值

全类名常量

list instanceof List

instanceofExpression ie where
ie.rhs.name == "java.util.List";

lambdaExpression





lambda表达式





list.forEach(integer -> {
if (integer == 1) {
System.out.println("单数");
}
});





parameters

参数

paramDeclaration节点

list.forEach(integer -> {
    if (integer == 1) {
        System.out.println("单数");
    }
});

lambdaExpression le where
le.parameters contain p where p.name == "integer";

body

方法体

block语句块

list.forEach(integer -> {
    if (integer == 1) {
        System.out.println("单数");
    }
});

lambdaExpression le where
le.body contain variableAccess va where va.name == "integer";

body.statementNum

body语句块的语句数量

数值

list.forEach(integer -> {
    if (integer == 1) {
        System.out.println("单数");
    }
});

lambdaExpression le where
le.body.statementNum == 1;

firstStatement

lambdaExpression的第一条语句

任意节点

list.forEach(integer -> {
    if (integer == 2) {
        System.out.println("单数");
    }
});

lambdaExpression le where
le.firstStatement contain ifBlock;

lastStatement

lambdaExpression的最后一条语句

任意节点

list.forEach(integer -> {
    if (integer == 3) {
        System.out.println("单数");
    }
     System.out.print("双数");
});

lambdaExpression le where
    le.lastStatement contain functionCall fc where
        fc.name == "print";

literal

常量,包括字符串、布尔、数字常量

Constant appeared in source code

value

常量值

字符串、数值、布尔值等

int a = 1;

literal ll where ll.value == 1;

stringLiteral


字符串常量


System.out.println("aaa");


length

字符串长度

数值

System.out.println("aaa");

stringLiteral l where l.length == 3;

value

字符串值

字符串

System.out.println("aaa");

stringLiteral l where l.value == "aaa";

boolLiteral

布尔常量

System.out.println(true);

value

布尔值

布尔值

System.out.println(true);

boolLiteral l where l.value == true;

numLiteral

数字常量

System.out.println(1);

value

数值

数值

System.out.println(1);

numLiteral l where l.value == 1;

returnStatement

return语句

return a;

returnValue

返回值

任意节点

return a;

returnStatement rs where rs.returnValue.name == "a";

breakStatement

break语句

break;

_

_

_

break;

breakStatement;

continueStatement

continue语句

continue;

_

_

_

continue;

continueStatement;

staticBlock

静态语句块

class A {
{ }
}

_

_

block语句块

static {
int n = 5;
}

staticBlock sb where sb contain variableDeclaration;

switchBlock

Switch语句块

switch (n) {
case 1:
do();
...
}

selector

switch语句的判断条件

任意节点

switch (m) {
}

switchBlock swb where
swb.selector.name == "m";

caseStatement

case语句块

switch (m) {
case 12:
System.out.println("hello");
break;
default:
System.out.println("default value");
break;
}

_

_

caseStatement节点

switch (m) {
    case 12:
        System.out.println("hello");
        break;
    default:
         System.out.println("default value");
         break;
}

caseStatement cs where cs contain literal;

defaultStatement

default语句块

switch (m) {
case 12:
System.out.println("hello");
break;
default:
System.out.println("default value");
break;
}

_

_

defaultStatement节点

switch (m) {
    case 12:
        System.out.println("hello");
        break;
    default:
         System.out.println("default value");
         break;
}

switchBlock swb where swb contain defaultStatement;

synchronizedBlock





同步代码块





synchronized(i){
do();
}





lock

任意节点

synchronized (i1) {
    System.out.println("hello");
}

synchronizedBlock sy where
sy.lock contain variableAccess va where
va.name == "i1";

body

执行语句

block语句块

synchronized (i2) {
    System.out.println("hello");
}

synchronizedBlock sy where
sy.body contain functionCall fc where
fc.name == "println";

body.statementNum

body语句块的语句数量

数值

synchronized (i2) { System.out.println("hello");}

synchronizedBlock sb where sb.body.statementNum == 1;

firstStatement

synchronizedBlock的第一条语句

任意节点

synchronized (i) {
    i++;
    System.out.println("hello");
}

synchronizedBlock sb where
sb.firstStatement contain unaryOperation;

lastStatement

synchronizedBlock的最后一条语句

任意节点

synchronized (i) {
    i++;
    System.out.println("hello");
}

synchronizedBlock sb where
sb.lastStatement contain functionCall;

ternaryOperation



条件表达式/三目运算



res = 2 > 2 ? true : false;



condition

三目运算的判断条件

binaryOperation

boolean res = num > 1 ? true : false;

ternaryOperation tp where
tp.condition.lhs.name == "num";

thenExpression

三目运算条件为真的操作

任意节点

boolean res = num > 1 ? true : false;

ternaryOperation tp where
tp.thenExpression contain literal ll where
ll.value == true;

elseExpression

三目运算条件为假的操作

任意节点

String str = num > 1 ? "true" : "false";

ternaryOperation tp where
tp.elseExpression contain literal ll where
ll.value == "false";

unaryOperation



一元表达式



a++;
--b;



isPrefix

是否运算符前置

布尔值

a++;

unaryOperation uo where uo.isPrefix == false;

operand

操作对象

任意节点

i++;

unaryOperation uo where uo.operand.name == "i";

operator

运算符

字符串

i++;

unaryOperation uo where uo.operator == "++";

variableAccess


变量访问


int a = arr[3];
log.info(a);


name

变量名

字符串

int a = arr[3];
log.info(a);

variableAccess va where va.name == "a";

variable

被访问的变量的定义

variableDeclaration

int a = arr[3];
log.info(a);

variableAccess va where va.variable.name == "a";

variableDeclaration



变量声明



int a = arr[3];
int b;
log.info(a);



name

变量名

字符串

int a = arr[3];

variableDeclaration vd where vd.name == "a";

initializer

初始化值

任意节点

int a = arr[3];

variableDeclaration vd where vd.initializer is arrayAccess;

valueUsages

使用该变量的所有位置

任意节点

int a = arr[3];
log.info(a);

variableDeclaration vd where
    vd.valueUsages contain vu where
        vu in functionCall;

comment


注释,包括行注释、块注释、javaDoc注释


// xxx
/* xxx */
/** xxx */


content

注释的内容

字符串

// function declaration
public void getInstance(String des) {}

comment cm where cm.content match ".*";

commentedNode

被注释的节点

节点

// function declaration
public void getInstance(String des) {}

lineComment cm where cm.commentedNode is functionDeclaration;

lineComment


行注释


// 注释


content

注释的内容

字符串

// function declaration
public void getInstance(String des) {}

comment cm where cm.content match ".*function.*";

commentedNode

被注释的节点

节点

// function declaration
public void getInstance(String des) {}

lineComment cm where cm.commentedNode is functionDeclaration;

blockComment


块注释


/* 注释 */


content

注释的内容

字符串

/* block comment */

blockComment bc where bc.content contain "block comment";

commentedNode

被注释的节点

节点

/* block comment */
int a = 2;

blockComment bc where bc.commentedNode contain variableDeclaration;

javadocComment


javadoc注释


/**
注释
*/


content

注释的内容

字符串

/**
* 功能描述
*
* @since 2023-03-20
*/
public class EncryptCommon {}

javadocComment jd where jd.content contain "@since";

commentedNode

被注释的节点

节点

/**
* 功能描述
*
* @since 2023-03-20
*/
public class EncryptCommon {}

javadocComment jd where
    jd.commentedNode is recordDeclaration;


【版权声明】本文为华为云社区用户原创内容,未经允许不得转载,如需转载请自行联系原作者进行授权。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。