All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jd.blockchain.contract.maven.ContractClass Maven / Gradle / Ivy

There is a newer version: 1.6.5.RELEASE
Show newest version
package com.jd.blockchain.contract.maven;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ContractClass extends AbstractContract {

    // 若出现同名的方法则进行合并(将两个方法中涉及到的内容合并在一起)
    private Map methods = new ConcurrentHashMap<>();

    public ContractClass(String className) {
        if (className.contains(".")) {
            this.className = className.replaceAll("\\.", "/");
        } else {
            this.className = className;
        }
    }

    /**
     * 返回构造方法
     *
     * @return
     */
    public ContractMethod constructor() {
        return methods.get(ContractConstant.METHOD_INIT);
    }

    /**
     * 返回该类的所有变量
     *
     * @return
     */
    public List fields() {

        List fields = new ArrayList<>();

        // 构造方法
        ContractMethod initMethod = constructor();
        if (initMethod != null) {
            fields.addAll(initMethod.getClassFieldList(className));
        }
        // CLINIT方法
        ContractMethod clInitMethod = methods.get(ContractConstant.METHOD_CLINIT);
        if (clInitMethod != null) {
            fields.addAll(clInitMethod.getClassFieldList(className));
        }
        return fields;
    }

    public synchronized ContractMethod method(String methodName) {
        if (methods.containsKey(methodName)) {
            return methods.get(methodName);
        }
        ContractMethod method = new ContractMethod(this.className, methodName);

        methods.put(methodName, method);

        return method;
    }

    public Map getMethods() {
        return methods;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy