diff --git a/core/che-core-typescript-dto-maven-plugin/src/main/java/org/eclipse/che/plugin/typescript/dto/model/DtoModel.java b/core/che-core-typescript-dto-maven-plugin/src/main/java/org/eclipse/che/plugin/typescript/dto/model/DtoModel.java index 980a9840d4..ed8386d22b 100644 --- a/core/che-core-typescript-dto-maven-plugin/src/main/java/org/eclipse/che/plugin/typescript/dto/model/DtoModel.java +++ b/core/che-core-typescript-dto-maven-plugin/src/main/java/org/eclipse/che/plugin/typescript/dto/model/DtoModel.java @@ -75,13 +75,17 @@ public class DtoModel { .filter(method -> !method.isBridge() && (isDtoGetter(method) || isDtoSetter(method) || isDtoWith(method))) .forEach(method -> { MethodModel methodModel = new MethodModel(method); - methods.add(methodModel); - if (isDtoGetter(method)) { - analyzeDtoGetterMethod(method, methodModel); - } else if (isDtoSetter(method)) { - analyzeDtoSetterMethod(method, methodModel); - } else if (isDtoWith(method)) { - analyzeDtoWithMethod(method, methodModel); + + // check method with same name already exist + if (!methods.contains(methodModel)) { + methods.add(methodModel); + if (isDtoGetter(method)) { + analyzeDtoGetterMethod(method, methodModel); + } else if (isDtoSetter(method)) { + analyzeDtoSetterMethod(method, methodModel); + } else if (isDtoWith(method)) { + analyzeDtoWithMethod(method, methodModel); + } } }); diff --git a/core/che-core-typescript-dto-maven-plugin/src/main/java/org/eclipse/che/plugin/typescript/dto/model/MethodModel.java b/core/che-core-typescript-dto-maven-plugin/src/main/java/org/eclipse/che/plugin/typescript/dto/model/MethodModel.java index 8ddad316e7..974851d88b 100644 --- a/core/che-core-typescript-dto-maven-plugin/src/main/java/org/eclipse/che/plugin/typescript/dto/model/MethodModel.java +++ b/core/che-core-typescript-dto-maven-plugin/src/main/java/org/eclipse/che/plugin/typescript/dto/model/MethodModel.java @@ -12,9 +12,11 @@ package org.eclipse.che.plugin.typescript.dto.model; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.stream.IntStream; +import static java.util.Objects.hash; import static org.eclipse.che.plugin.typescript.dto.DTOHelper.convertType; /** @@ -143,4 +145,21 @@ public class MethodModel { public String getFieldType() { return fieldType; } + + public int hashCode() { + return hash(this.parameters.toString(), this.returnType); + } + + public boolean equals(Object other) { + if (other == null) { + return false; + } + if (!(other instanceof MethodModel)) { + return false; + } + MethodModel methodModelOther = (MethodModel) other; + return this.getName().equals(methodModelOther.getName()) + && this.returnType.equals(methodModelOther.returnType) + && Arrays.equals(this.parameters.toArray(), methodModelOther.parameters.toArray()); + } } \ No newline at end of file diff --git a/core/che-core-typescript-dto-maven-plugin/src/main/java/org/eclipse/che/plugin/typescript/dto/model/ParameterMethodModel.java b/core/che-core-typescript-dto-maven-plugin/src/main/java/org/eclipse/che/plugin/typescript/dto/model/ParameterMethodModel.java index 9177d8644a..7cf1d0a09f 100644 --- a/core/che-core-typescript-dto-maven-plugin/src/main/java/org/eclipse/che/plugin/typescript/dto/model/ParameterMethodModel.java +++ b/core/che-core-typescript-dto-maven-plugin/src/main/java/org/eclipse/che/plugin/typescript/dto/model/ParameterMethodModel.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.che.plugin.typescript.dto.model; +import static java.util.Objects.hash; + /** * Defines the model link to parameter of a method * @@ -58,4 +60,24 @@ public class ParameterMethodModel { return this.parameterType; } + public int hashCode() { + return hash(this.parameterName, this.parameterType); + } + + public boolean equals(Object other) { + if (other == null) { + return false; + } + if (!(other instanceof ParameterMethodModel)) { + return false; + } + ParameterMethodModel parameterMethodModelOther = (ParameterMethodModel) other; + return this.parameterName.equals(parameterMethodModelOther.parameterName) && this.parameterType.equals(((ParameterMethodModel)other).parameterType); + } + + public String toString() { + return "ParameterMethodModel[" + this.parameterName + "/" + this.parameterType + "]"; + } + + } diff --git a/core/che-core-typescript-dto-maven-plugin/src/test/java/org/eclipse/che/plugin/typescript/dto/MyOtherDTO.java b/core/che-core-typescript-dto-maven-plugin/src/test/java/org/eclipse/che/plugin/typescript/dto/MyOtherDTO.java index eb5a0780b8..35dcb9aba0 100644 --- a/core/che-core-typescript-dto-maven-plugin/src/test/java/org/eclipse/che/plugin/typescript/dto/MyOtherDTO.java +++ b/core/che-core-typescript-dto-maven-plugin/src/test/java/org/eclipse/che/plugin/typescript/dto/MyOtherDTO.java @@ -16,9 +16,8 @@ import org.eclipse.che.dto.shared.DTO; * @author Florent Benoit */ @DTO -public interface MyOtherDTO { +public interface MyOtherDTO extends MySuperClassDTO, MySuperSuperClass { - String getName(); void setName(String name); MyOtherDTO withName(String name); diff --git a/core/che-core-typescript-dto-maven-plugin/src/test/java/org/eclipse/che/plugin/typescript/dto/MySuperClassDTO.java b/core/che-core-typescript-dto-maven-plugin/src/test/java/org/eclipse/che/plugin/typescript/dto/MySuperClassDTO.java new file mode 100644 index 0000000000..02b578c9e0 --- /dev/null +++ b/core/che-core-typescript-dto-maven-plugin/src/test/java/org/eclipse/che/plugin/typescript/dto/MySuperClassDTO.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2012-2016 Codenvy, S.A. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.typescript.dto; + +import org.eclipse.che.api.core.factory.FactoryParameter; +import org.eclipse.che.dto.shared.DTO; + +import static org.eclipse.che.api.core.factory.FactoryParameter.Obligation.OPTIONAL; + +/** + * @author Florent Benoit + */ +@DTO +public interface MySuperClassDTO extends MySuperSuperClass { + + @Override + @FactoryParameter(obligation = OPTIONAL) + String getName(); + + void setName(String name); + MySuperClassDTO withName(String name); + +} diff --git a/core/che-core-typescript-dto-maven-plugin/src/test/java/org/eclipse/che/plugin/typescript/dto/MySuperSuperClass.java b/core/che-core-typescript-dto-maven-plugin/src/test/java/org/eclipse/che/plugin/typescript/dto/MySuperSuperClass.java new file mode 100644 index 0000000000..1575bf75ad --- /dev/null +++ b/core/che-core-typescript-dto-maven-plugin/src/test/java/org/eclipse/che/plugin/typescript/dto/MySuperSuperClass.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2012-2016 Codenvy, S.A. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.typescript.dto; + +/** + * @author Florent Benoit + */ +public interface MySuperSuperClass { + + String getName(); + +}