merge 2.7 metadata annotations definition to 3.0 (#8305)
Co-authored-by: kalman03 <kalman03@qq.com>
This commit is contained in:
parent
4bc470ff09
commit
cecefc39e1
|
|
@ -16,6 +16,14 @@
|
|||
*/
|
||||
package org.apache.dubbo.metadata.definition;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.dubbo.metadata.definition.model.FullServiceDefinition;
|
||||
import org.apache.dubbo.metadata.definition.model.MethodDefinition;
|
||||
import org.apache.dubbo.metadata.definition.model.ServiceDefinition;
|
||||
|
|
@ -24,11 +32,6 @@ import org.apache.dubbo.metadata.definition.util.ClassUtils;
|
|||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 2015/1/27.
|
||||
*/
|
||||
|
|
@ -61,6 +64,8 @@ public final class ServiceDefinitionBuilder {
|
|||
public static <T extends ServiceDefinition> void build(T sd, final Class<?> interfaceClass) {
|
||||
sd.setCanonicalName(interfaceClass.getCanonicalName());
|
||||
sd.setCodeSource(ClassUtils.getCodeSource(interfaceClass));
|
||||
Annotation[] classAnnotations = interfaceClass.getAnnotations();
|
||||
sd.setAnnotations(annotationToStringList(classAnnotations));
|
||||
|
||||
TypeDefinitionBuilder builder = new TypeDefinitionBuilder();
|
||||
List<Method> methods = ClassUtils.getPublicNonStaticMethods(interfaceClass);
|
||||
|
|
@ -68,6 +73,9 @@ public final class ServiceDefinitionBuilder {
|
|||
MethodDefinition md = new MethodDefinition();
|
||||
md.setName(method.getName());
|
||||
|
||||
Annotation[] methodAnnotations = method.getAnnotations();
|
||||
md.setAnnotations(annotationToStringList(methodAnnotations));
|
||||
|
||||
// Process parameter types.
|
||||
Class<?>[] paramTypes = method.getParameterTypes();
|
||||
Type[] genericParamTypes = method.getGenericParameterTypes();
|
||||
|
|
@ -89,6 +97,17 @@ public final class ServiceDefinitionBuilder {
|
|||
sd.setTypes(builder.getTypeDefinitions());
|
||||
}
|
||||
|
||||
private static List<String> annotationToStringList(Annotation[] annotations) {
|
||||
if (annotations == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<String> list = new ArrayList<>();
|
||||
for (Annotation annotation : annotations) {
|
||||
list.add(annotation.toString());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describe a Java interface in Json schema.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package org.apache.dubbo.metadata.definition.model;
|
|||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
|
|
@ -41,6 +42,8 @@ public class MethodDefinition implements Serializable {
|
|||
@Deprecated
|
||||
private List<TypeDefinition> parameters;
|
||||
|
||||
private List<String> annotations;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
|
@ -76,6 +79,17 @@ public class MethodDefinition implements Serializable {
|
|||
this.returnType = formatType(returnType);
|
||||
}
|
||||
|
||||
public List<String> getAnnotations() {
|
||||
if (annotations == null) {
|
||||
annotations = Collections.emptyList();
|
||||
}
|
||||
return annotations;
|
||||
}
|
||||
|
||||
public void setAnnotations(List<String> annotations) {
|
||||
this.annotations = annotations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MethodDefinition [name=" + name + ", parameterTypes=" + Arrays.toString(parameterTypes)
|
||||
|
|
|
|||
|
|
@ -16,13 +16,14 @@
|
|||
*/
|
||||
package org.apache.dubbo.metadata.definition.model;
|
||||
|
||||
import org.apache.dubbo.metadata.definition.util.ClassUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.dubbo.metadata.definition.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* 2015/1/27.
|
||||
*/
|
||||
|
|
@ -49,6 +50,11 @@ public class ServiceDefinition implements Serializable {
|
|||
*/
|
||||
private List<TypeDefinition> types;
|
||||
|
||||
/**
|
||||
* the definitions of annotations
|
||||
*/
|
||||
private List<String> annotations;
|
||||
|
||||
public String getCanonicalName() {
|
||||
return canonicalName;
|
||||
}
|
||||
|
|
@ -91,6 +97,17 @@ public class ServiceDefinition implements Serializable {
|
|||
this.types = types;
|
||||
}
|
||||
|
||||
public List<String> getAnnotations() {
|
||||
if (annotations == null) {
|
||||
annotations = Collections.emptyList();
|
||||
}
|
||||
return annotations;
|
||||
}
|
||||
|
||||
public void setAnnotations(List<String> annotations) {
|
||||
this.annotations = annotations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ServiceDefinition [canonicalName=" + canonicalName + ", codeSource=" + codeSource + ", methods="
|
||||
|
|
|
|||
Loading…
Reference in New Issue