feat: 代码一键生成类的引入
代码一键生成类的引入代码一键生成类的引入
This commit is contained in:
+1
-1
@@ -19,7 +19,7 @@ import java.util.function.BiConsumer;
|
||||
public class PropertiesPropertySource implements PropertySource {
|
||||
|
||||
/** PREFIX */
|
||||
private static final String PREFIX = "fkh.";
|
||||
private static final String PREFIX = "aos.";
|
||||
|
||||
/** Properties */
|
||||
private final Properties properties;
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.aos.element.common.exception;
|
||||
|
||||
import com.aos.starter.core.exception.BaseException;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.3
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.01.26 20:42
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class PropertiesException extends BaseException {
|
||||
/** serialVersionUID */
|
||||
private static final long serialVersionUID = -6498727260647427447L;
|
||||
|
||||
/**
|
||||
* Properties exception
|
||||
*
|
||||
* @param msg msg
|
||||
* @param args args
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public PropertiesException(String msg, Object... args) {
|
||||
super(msg, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Properties exception
|
||||
*
|
||||
* @param cause cause
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public PropertiesException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package com.aos.starter.core.reflection.property;
|
||||
|
||||
import com.aos.starter.core.reflection.Reflector;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.3.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.04.12 11:47
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public final class PropertyCopier {
|
||||
|
||||
/**
|
||||
* Property copier
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
private PropertyCopier() {
|
||||
// Prevent Instantiation of Static Class
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy bean properties *
|
||||
*
|
||||
* @param type type
|
||||
* @param sourceBean source bean
|
||||
* @param destinationBean destination bean
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static void copyBeanProperties(Class<?> type, Object sourceBean, Object destinationBean) {
|
||||
Class<?> parent = type;
|
||||
while (parent != null) {
|
||||
Field[] fields = parent.getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
try {
|
||||
try {
|
||||
field.set(destinationBean, field.get(sourceBean));
|
||||
} catch (IllegalAccessException e) {
|
||||
if (Reflector.canControlMemberAccessible()) {
|
||||
field.setAccessible(true);
|
||||
field.set(destinationBean, field.get(sourceBean));
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Nothing useful to do, will only fail on final fields, which will be ignored.
|
||||
}
|
||||
}
|
||||
parent = parent.getSuperclass();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
package com.aos.starter.core.reflection.property;
|
||||
|
||||
|
||||
|
||||
import com.aos.starter.core.reflection.ReflectionException;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.3.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.04.12 11:47
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public final class PropertyNamer {
|
||||
/** BOOLEAN_FIELD_PREFIX */
|
||||
private static final String BOOLEAN_FIELD_PREFIX = "is";
|
||||
/** GET_FIELD_PREFIX */
|
||||
private static final String GET_FIELD_PREFIX = "get";
|
||||
/** SET_FIELD_PREFIX */
|
||||
private static final String SET_FIELD_PREFIX = "set";
|
||||
|
||||
/**
|
||||
* Property namer
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
private PropertyNamer() {
|
||||
// Prevent Instantiation of Static Class
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to property string
|
||||
*
|
||||
* @param name name
|
||||
* @return the string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static @NotNull String methodToProperty(@NotNull String name) {
|
||||
if (name.startsWith(BOOLEAN_FIELD_PREFIX)) {
|
||||
name = name.substring(2);
|
||||
} else if (name.startsWith(GET_FIELD_PREFIX) || name.startsWith(SET_FIELD_PREFIX)) {
|
||||
name = name.substring(3);
|
||||
} else {
|
||||
throw new ReflectionException("Error parsing property name '{}' . Didn't start with 'is', 'get' or 'set'.", name);
|
||||
}
|
||||
|
||||
boolean matched = name.length() > 1 && !Character.isUpperCase(name.charAt(1));
|
||||
if (name.length() == 1 || matched) {
|
||||
name = name.substring(0, 1).toLowerCase(Locale.ENGLISH) + name.substring(1);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is property boolean
|
||||
*
|
||||
* @param name name
|
||||
* @return the boolean
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static boolean isProperty(String name) {
|
||||
return isGetter(name) || isSetter(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is getter boolean
|
||||
*
|
||||
* @param name name
|
||||
* @return the boolean
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static boolean isGetter(@NotNull String name) {
|
||||
return (name.startsWith("get") && name.length() > 3) || (name.startsWith("is") && name.length() > 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is setter boolean
|
||||
*
|
||||
* @param name name
|
||||
* @return the boolean
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static boolean isSetter(@NotNull String name) {
|
||||
return name.startsWith("set") && name.length() > 3;
|
||||
}
|
||||
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
package com.aos.starter.core.reflection.property;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.3.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.04.12 11:50
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class PropertyTokenizer implements Iterator<PropertyTokenizer> {
|
||||
/** Indexed name */
|
||||
@Getter
|
||||
private final String indexedName;
|
||||
/** Children */
|
||||
@Getter
|
||||
private final String children;
|
||||
/** Name */
|
||||
@Getter
|
||||
private String name;
|
||||
/** Index */
|
||||
@Getter
|
||||
private String index;
|
||||
|
||||
/**
|
||||
* Property tokenizer
|
||||
*
|
||||
* @param fullname fullname
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public PropertyTokenizer(@NotNull String fullname) {
|
||||
int delim = fullname.indexOf('.');
|
||||
if (delim > -1) {
|
||||
this.name = fullname.substring(0, delim);
|
||||
this.children = fullname.substring(delim + 1);
|
||||
} else {
|
||||
this.name = fullname;
|
||||
this.children = null;
|
||||
}
|
||||
this.indexedName = this.name;
|
||||
delim = this.name.indexOf('[');
|
||||
if (delim > -1) {
|
||||
this.index = this.name.substring(delim + 1, this.name.length() - 1);
|
||||
this.name = this.name.substring(0, delim);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Has next boolean
|
||||
*
|
||||
* @return the boolean
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return this.children != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Next property tokenizer
|
||||
*
|
||||
* @return the property tokenizer
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Override
|
||||
public PropertyTokenizer next() {
|
||||
return new PropertyTokenizer(this.children);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException("Remove is not supported, as it has no meaning in the context of properties.");
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
package com.aos.starter.devtools;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: 自动生成配置文件相关配置, 使用 @Accessors(chain = true) 生成链式调用方法 </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.3
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.01.27 14:09
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class PropertiesConfig {
|
||||
/** EMAIL */
|
||||
public static final String EMAIL = "email";
|
||||
/** WEBSOCKET */
|
||||
public static final String WEBSOCKET = "websocket";
|
||||
/** WEBSERVICE */
|
||||
public static final String WEBSERVICE = "webservice";
|
||||
/** ACTIVEMQ */
|
||||
public static final String ACTIVEMQ = "activemq";
|
||||
/** ROCKTEMQ */
|
||||
public static final String ROCKTEMQ = "rocktemq";
|
||||
/** REDIS */
|
||||
public static final String REDIS = "redis";
|
||||
/** MYBATIS */
|
||||
public static final String MYBATIS = "mybatis";
|
||||
/** ADMIN */
|
||||
public static final String ADMIN = "admin";
|
||||
/** REST */
|
||||
public static final String REST = "rest";
|
||||
/** DUBBO */
|
||||
public static final String DUBBO = "dubbo";
|
||||
/** BOOT_CONFIG */
|
||||
public static final String BOOT_CONFIG = "boot";
|
||||
/** CLOUD_CONFIG */
|
||||
public static final String CLOUD_CONFIG = "cloud";
|
||||
|
||||
/** Email */
|
||||
private boolean email = false;
|
||||
/** Websocket */
|
||||
private boolean websocket = false;
|
||||
/** Webservice */
|
||||
private boolean webservice = false;
|
||||
/** Activemq */
|
||||
private boolean activemq = false;
|
||||
/** Rocktemq */
|
||||
private boolean rocktemq = false;
|
||||
/** Redis */
|
||||
private boolean redis = false;
|
||||
/** Mybatis */
|
||||
private boolean mybatis = false;
|
||||
/** Admin */
|
||||
private boolean admin = false;
|
||||
/** Rest */
|
||||
private boolean rest = false;
|
||||
/** Dubbo */
|
||||
private boolean dubbo = false;
|
||||
/** Boot config */
|
||||
private boolean bootConfig = false;
|
||||
/** Cloud config */
|
||||
private boolean cloudConfig = false;
|
||||
}
|
||||
Reference in New Issue
Block a user