Fix Typescript DTO generation

--> there was issue with super interfaces implemented directly and through super classes

Change-Id: I27111cd6f97c227b1e1ce8202d4c5cefbcb60d8b
Signed-off-by: Florent BENOIT <fbenoit@codenvy.com>
6.19.x
Florent BENOIT 2016-12-11 18:05:00 +01:00
parent f24f16f725
commit 43e40ae800
6 changed files with 104 additions and 9 deletions

View File

@ -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);
}
}
});

View File

@ -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());
}
}

View File

@ -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 + "]";
}
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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();
}