Fix repo entity reconciling for generic type vars case
This commit is contained in:
@@ -133,8 +133,6 @@ public class EntityIdForRepoReconciler implements JdtAstReconciler {
|
||||
ITypeBinding repoType = repoTypeChain.get(i);
|
||||
ITypeBinding[] typeParams = repoType.isParameterizedType() ? repoType.getTypeArguments()
|
||||
: repoType.getTypeParameters();
|
||||
boolean domainTypeChanged = false;
|
||||
boolean idTypeChanged = false;
|
||||
if (repoType.isGenericType() || repoType.isParameterizedType()) {
|
||||
if (domainType == null || domainType.isTypeVariable()) {
|
||||
int idx = domainType == null ? -1
|
||||
@@ -145,7 +143,6 @@ public class EntityIdForRepoReconciler implements JdtAstReconciler {
|
||||
domainTypeIndex = idx;
|
||||
domainType = typeParams[domainTypeIndex];
|
||||
}
|
||||
domainTypeChanged = true;
|
||||
}
|
||||
if (idType == null || idType.isTypeVariable()) {
|
||||
int idx = idType == null ? -1
|
||||
@@ -156,31 +153,16 @@ public class EntityIdForRepoReconciler implements JdtAstReconciler {
|
||||
idTypeIndex = idx;
|
||||
idType = typeParams[idTypeIndex];
|
||||
}
|
||||
idTypeChanged = true;
|
||||
}
|
||||
} else {
|
||||
if (idType == null || idType.isTypeVariable()) {
|
||||
idType = typeParams[idTypeIndex];
|
||||
idTypeChanged = true;
|
||||
}
|
||||
if (domainType == null || domainType.isTypeVariable()) {
|
||||
domainType = typeParams[domainTypeIndex];
|
||||
domainTypeChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Adjust domainTypeIndex or idTypeIndex if needed as well as remaining expected
|
||||
// number of parameters
|
||||
if (idType != null && idTypeChanged) {
|
||||
if (domainType.isTypeVariable() && domainTypeIndex > idTypeIndex) {
|
||||
domainTypeIndex--;
|
||||
}
|
||||
}
|
||||
if (domainType != null && domainTypeChanged) {
|
||||
if (idType.isTypeVariable() && idTypeIndex > domainTypeIndex) {
|
||||
idTypeIndex--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ITypeBinding domainClassType = domainType;
|
||||
|
||||
@@ -1152,4 +1152,40 @@ public class EntityIdForRepoReconcilerTest extends BaseReconcilerTest {
|
||||
assertEquals(0, problems.size());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void gh1220() throws Exception {
|
||||
Path roleSource = createFile("BaseEntity.java", """
|
||||
package demo;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
|
||||
@MappedSuperclass
|
||||
public abstract class BaseEntity {
|
||||
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
}
|
||||
""");
|
||||
|
||||
String source = """
|
||||
package demo;
|
||||
|
||||
import org.springframework.data.jpa.repository.support.SimpleJpaRepository;
|
||||
|
||||
public abstract class RdsJpaRepository<T extends BaseEntity, ID> extends SimpleJpaRepository<T, ID> {
|
||||
}
|
||||
""";
|
||||
List<ReconcileProblem> problems = reconcile("CustomerRepository.java", source, false, roleSource);
|
||||
|
||||
assertEquals(0, problems.size());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user