Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dubbo-4370] Add more data to serviceMetaData #4372

Merged
merged 1 commit into from
Jun 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
public class TypeDefinitionBuilder {
private static final List<TypeBuilder> BUILDERS;

static{
static {
List<TypeBuilder> builders = new ArrayList<>();
ExtensionLoader<TypeBuilder> extensionLoader = ExtensionLoader.getExtensionLoader(TypeBuilder.class);
for(String extensionName : extensionLoader.getSupportedExtensions()){
for (String extensionName : extensionLoader.getSupportedExtensions()) {
builders.add(extensionLoader.getExtension(extensionName));
}
BUILDERS = builders;
Expand All @@ -47,8 +47,10 @@ public static TypeDefinition build(Type type, Class<?> clazz, Map<Class<?>, Type
TypeDefinition td;
if (builder != null) {
td = builder.build(type, clazz, typeCache);
td.setTypeBuilderName(builder.getClass().getName());
} else {
td = DefaultTypeBuilder.build(clazz, typeCache);
td.setTypeBuilderName(DefaultTypeBuilder.class.getName());
}
return td;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
*/
package org.apache.dubbo.metadata.definition.model;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
Expand All @@ -29,19 +27,11 @@ public class MethodDefinition {
private String name;
private String[] parameterTypes;
private String returnType;
private List<TypeDefinition> parameters;

public String getName() {
return name;
}

public List<TypeDefinition> getParameters() {
if (parameters == null) {
parameters = new ArrayList<>();
}
return parameters;
}

public String[] getParameterTypes() {
return parameterTypes;
}
Expand All @@ -54,10 +44,6 @@ public void setName(String name) {
this.name = name;
}

public void setParameters(List<TypeDefinition> parameters) {
this.parameters = parameters;
}

public void setParameterTypes(String[] parameterTypes) {
this.parameterTypes = parameterTypes;
}
Expand All @@ -83,13 +69,12 @@ public boolean equals(Object o) {
MethodDefinition that = (MethodDefinition) o;
return Objects.equals(getName(), that.getName()) &&
Arrays.equals(getParameterTypes(), that.getParameterTypes()) &&
Objects.equals(getReturnType(), that.getReturnType()) &&
Objects.equals(getParameters(), that.getParameters());
Objects.equals(getReturnType(), that.getReturnType());
}

@Override
public int hashCode() {
int result = Objects.hash(getName(), getReturnType(), getParameters());
int result = Objects.hash(getName(), getReturnType());
result = 31 * result + Arrays.hashCode(getParameterTypes());
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class TypeDefinition {
private List<String> enums;
private String $ref;
private Map<String, TypeDefinition> properties;
private String typeBuilderName;

public TypeDefinition(String type) {
this.type = type;
Expand Down Expand Up @@ -75,6 +76,10 @@ public String getType() {
return type;
}

public String getTypeBuilderName() {
return typeBuilderName;
}

public void set$ref(String $ref) {
this.$ref = $ref;
}
Expand All @@ -99,6 +104,10 @@ public void setType(String type) {
this.type = type;
}

public void setTypeBuilderName(String typeBuilderName) {
this.typeBuilderName = typeBuilderName;
}

@Override
public String toString() {
return "TypeDefinition [id=" + id + ", type=" + type + ", properties=" + properties + ", $ref=" + $ref + "]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
*/
package org.apache.dubbo.metadata.definition;

import org.apache.dubbo.metadata.definition.builder.CollectionTypeBuilder;
import org.apache.dubbo.metadata.definition.builder.DefaultTypeBuilder;
import org.apache.dubbo.metadata.definition.builder.EnumTypeBuilder;
import org.apache.dubbo.metadata.definition.builder.MapTypeBuilder;
import org.apache.dubbo.metadata.definition.common.ClassExtendsMap;
import org.apache.dubbo.metadata.definition.common.ColorEnum;
import org.apache.dubbo.metadata.definition.common.OuterClass;
Expand Down Expand Up @@ -46,7 +50,7 @@ public void testInnerClassType() {
Assertions.assertEquals("org.apache.dubbo.metadata.definition.common.OuterClass$InnerClass", td.getType());
Assertions.assertEquals(1, td.getProperties().size());
Assertions.assertNotNull(td.getProperties().get("name"));

Assertions.assertEquals(DefaultTypeBuilder.class.getName(), td.getTypeBuilderName());
ServiceDefinition sd = MetadataUtils.generateMetadata(TestService.class);
System.out.println(">> testInnerClassType: " + new Gson().toJson(sd));

Expand All @@ -73,7 +77,9 @@ public void testRawMap() {
Assertions.assertEquals("org.apache.dubbo.metadata.definition.common.ResultWithRawCollections", td.getType());
Assertions.assertEquals(2, td.getProperties().size());
Assertions.assertEquals("java.util.Map", td.getProperties().get("map").getType());
Assertions.assertEquals(MapTypeBuilder.class.getName(), td.getProperties().get("map").getTypeBuilderName());
Assertions.assertEquals("java.util.List", td.getProperties().get("list").getType());
Assertions.assertEquals(CollectionTypeBuilder.class.getName(), td.getProperties().get("list").getTypeBuilderName());

ServiceDefinition sd = MetadataUtils.generateMetadata(TestService.class);
System.out.println(">> testRawMap: " + new Gson().toJson(sd));
Expand All @@ -97,6 +103,7 @@ public void testEnum() {
System.out.println(">> testEnum: " + new Gson().toJson(td));

Assertions.assertEquals("org.apache.dubbo.metadata.definition.common.ColorEnum", td.getType());
Assertions.assertEquals(EnumTypeBuilder.class.getName(), td.getTypeBuilderName());
Assertions.assertEquals(3, td.getEnums().size());
Assertions.assertTrue(td.getEnums().contains("RED"));
Assertions.assertTrue(td.getEnums().contains("YELLOW"));
Expand Down Expand Up @@ -124,6 +131,7 @@ public void testExtendsMap() {
System.out.println(">> testExtendsMap: " + new Gson().toJson(td));

Assertions.assertEquals("org.apache.dubbo.metadata.definition.common.ClassExtendsMap", td.getType());
Assertions.assertEquals(MapTypeBuilder.class.getName(), td.getTypeBuilderName());
Assertions.assertEquals(0, td.getProperties().size());

ServiceDefinition sd = MetadataUtils.generateMetadata(TestService.class);
Expand Down