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

com.hframework.beans.class0.Class Maven / Gradle / Ivy

There is a newer version: 1.0.2
Show newest version
package com.hframework.beans.class0;

import java.util.*;

/**
 * class的数据对象
 * @author zhangqh6
 *
 */
public class Class {

	private String srcFilePath;

	private boolean useLogger;

	//包路径
	private String annotation;

	//包路径
	private String classPackage;

	//类名称
	private String className;

	//类类型 type:class interface
	private String type = "class";
	//父类
	private String superClass;

	private String superClassStr = null;

	private List interfaceList = new ArrayList();

	private String implementsStr = null;

	private String javaDoc = "/**\n" +
			" * generated by hframework on " + new java.text.SimpleDateFormat("yyyy").format(new Date()) + ".\n" +
			" */";

	//导入类列表
	private List importClassList = new ArrayList();

	//类属性列表
	private List fieldList = new ArrayList();

	//构造器列表
	private List constructorList = new ArrayList();

	//方法列表
	private List methodList = new ArrayList();

	private String extMethodStr ;

	public String getFilePath() {
		return srcFilePath + classPackage.replaceAll("\\u002E", "/") + "/" + className + ".java";
	}

	private Map extendAttrMap;

	public String getSrcFilePath() {
		return srcFilePath;
	}


	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getAnnotation() {
		return annotation;
	}


	public void setAnnotation(String annotation) {
		this.annotation = annotation;
	}

	public void addAnnotation(String annotation) {
		if(this.annotation == null) {
			this.annotation = annotation;
		}else {
			this.annotation += ("\n" + annotation);
		}

	}

	public boolean isUseLogger() {
		return useLogger;
	}

	public void setUseLogger(boolean useLogger) {
		this.useLogger = useLogger;
	}

	public void setSrcFilePath(String srcFilePath) {
		this.srcFilePath = srcFilePath;
	}




	public String getExtMethodStr() {
		return extMethodStr;
	}


	public void setExtMethodStr(String extMethodStr) {
		this.extMethodStr = extMethodStr;
	}


	public String getImplementsStr() {
		return implementsStr;
	}


	public void setImplementsStr(String implementsStr) {
		this.implementsStr = implementsStr;
	}


	//添加接口
	public void addInterface(String interfaceName) {
		interfaceList.add(interfaceName);
		if(implementsStr == null) {
			implementsStr = "implements ";
		}else {
			implementsStr += ", ";
		}

		implementsStr += interfaceName;
	}

	//添加导入类
	public void addImportClass(String importClass) {
		if(!importClassList.contains(importClass)) {
			importClassList.add(importClass);
		}
	}

	//添加类属性
	public void addField(Field field) {

		//避免重复的属性添加
		for (Field field1 : fieldList) {
			if(field1.getType().equals(field.getType()) && field1.getName().equals(field.getName())) {
				return;
			}
		}
		fieldList.add(field);
	}

	//添加构造方法
	public Constructor addConstructor(Constructor constructor) {
		constructorList.add(constructor);
		return constructor;
	}

	//添加构造方法
	public Constructor addConstructor() {
		Constructor constructor = new Constructor();
		constructorList.add(constructor);
		return constructor;
	}

	//添加方法
	public void addMethod(Method method) {
		methodList.add(method);
	}

	public String getClassPackage() {
		return classPackage;
	}

	public void setClassPackage(String classPackage) {
		this.classPackage = classPackage;
	}

	public String getClassPath() {
		return classPackage + "." + className;
	}

	public void setClassPath(String classPath) {
		classPackage = classPath.substring(0,classPath.lastIndexOf("."));
		className = classPath.substring(classPath.lastIndexOf(".")+1);
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	public String getSuperClass() {
		return superClass;
	}

	public void setSuperClass(String superClass) {
		this.superClass = superClass;
		superClassStr = "extends " + superClass;
	}

	public List getInterfaceList() {
		return interfaceList;
	}

	public List getImportClassList() {
		return importClassList;
	}


	public List getFieldList() {
		return fieldList;
	}

	public List getConstructorList() {
		return constructorList;
	}

	public List getMethodList() {
		return methodList;
	}


	public String getSuperClassStr() {
		return superClassStr;
	}


	public void setSuperClassStr(String superClassStr) {
		this.superClassStr = superClassStr;
	}





//	//成员变量列表-单个类型成员变量
//	List> sigleVarList = new ArrayList>();
//	
//	//成员变量列表-集合类型成员变量
//	List> multiVarList = new ArrayList>();
//	
//	//构造方法类表
//	List>> constrauctorListList = new ArrayList>>();
//	

//	/**
//	 * 添加引入类
//	 * @param importClass
//	 */
//	public void addImportClass(String importClass){
//		importClassList.add(importClass);
//	}
//	
//	/**
//	 * 添加成员变量-单个
//	 * @param varInfo
//	 */
//	public void addSigleVar(String[] varInfo){
//		sigleVarList.add(Arrays.asList(varInfo));
//	}
//	
//	/**
//	 * 添加成员变量-单个
//	 * @param varInfo
//	 */
//	public void addSigleVar(List varInfo){
//		sigleVarList.add(varInfo);
//	}
//
//	/**
//	 * 添加成员变量-列表
//	 * @param varInfo
//	 */
//	public void addMultiVar(String[] varInfo){
//		multiVarList.add(Arrays.asList(varInfo));
//	}
//	
//	/**
//	 * 添加成员变量-列表
//	 * @param varInfo
//	 */
//	public void addMultiVar(List varInfo){
//		multiVarList.add(varInfo);
//	}

//	/**
//	 * 获得一个构造器
//	 * @return
//	 */
//	public Constrauctor getConstrauctor(){
//		Constrauctor constrauctor = new Constrauctor();
//		constrauctorListList.add(constrauctor.getConstrauctorList());
//		return constrauctor;
//	}
//	
//	class  Constrauctor{
//		List> constrauctorList = new ArrayList>();
//
//		public List> getConstrauctorList() {
//			return constrauctorList;
//		}
//		
//		public void addInVar(String[] varInfo){
//			constrauctorList.add(Arrays.asList(varInfo));
//		}
//		
//		public void addInVar(List varInfo){
//			constrauctorList.add(varInfo);
//		}
//		
//		public void addCodeLine(String[] code){
//			constrauctorList.add(Arrays.asList(code));
//		}
//		
//		public void addCodeLine(List code){
//			constrauctorList.add(code);
//		}
//		
//	}

	/**
     * class的数据对象
     * @author zhangqh6
     *
     */
    public static class ClassDescData {

        //引用类列表
        List importClassList = new ArrayList();

        //成员变量列表-单个类型成员变量
        List> sigleVarList = new ArrayList>();

        //成员变量列表-集合类型成员变量
        List> multiVarList = new ArrayList>();

        //构造方法类表
        List>> constrauctorListList = new ArrayList>>();


        /**
         * 添加引入类
         * @param importClass
         */
        public void addImportClass(String importClass){
            importClassList.add(importClass);
        }

        /**
         * 添加成员变量-单个
         * @param varInfo
         */
        public void addSigleVar(String[] varInfo){
            sigleVarList.add(Arrays.asList(varInfo));
        }

        /**
         * 添加成员变量-单个
         * @param varInfo
         */
        public void addSigleVar(List varInfo){
            sigleVarList.add(varInfo);
        }

        /**
         * 添加成员变量-列表
         * @param varInfo
         */
        public void addMultiVar(String[] varInfo){
            multiVarList.add(Arrays.asList(varInfo));
        }

        /**
         * 添加成员变量-列表
         * @param varInfo
         */
        public void addMultiVar(List varInfo){
            multiVarList.add(varInfo);
        }

        /**
         * 获得一个构造器
         * @return
         */
        public Constrauctor getConstrauctor(){
            Constrauctor constrauctor = new Constrauctor();
            constrauctorListList.add(constrauctor.getConstrauctorList());
            return constrauctor;
        }

        class  Constrauctor{
            List> constrauctorList = new ArrayList>();

            public List> getConstrauctorList() {
                return constrauctorList;
            }

            public void addInVar(String[] varInfo){
                constrauctorList.add(Arrays.asList(varInfo));
            }

            public void addInVar(List varInfo){
                constrauctorList.add(varInfo);
            }

            public void addCodeLine(String[] code){
                constrauctorList.add(Arrays.asList(code));
            }

            public void addCodeLine(List code){
                constrauctorList.add(code);
            }

        }
    }

	public Map getExtendAttrMap() {
		return extendAttrMap;
	}

	public void setExtendAttrMap(Map extendAttrMap) {
		this.extendAttrMap = extendAttrMap;
	}

	public void addExtendAttr(ExtendAttrCode key, String value) {
		if(extendAttrMap == null) {
			extendAttrMap = new HashMap();
		}
		extendAttrMap.put(key,value);
	}

	public String getExtendAttr(ExtendAttrCode key) {
		if(extendAttrMap == null) {
			return null;
		}
		return extendAttrMap.get(key);
	}

	public enum ExtendAttrCode {
		MESSAGE_ANNOTATION_TYPE
	}

	public String getJavaDoc() {
		return javaDoc;
	}

	public void setJavaDoc(String javaDoc) {
		this.javaDoc = javaDoc;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy