Skip to content

Commit

Permalink
Fix repo entity reconciling for generic type vars case
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex committed Apr 21, 2024
1 parent 0c8644b commit 131336a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ private void handleRepoType(TypeDeclaration typeDecl) {
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
Expand All @@ -145,7 +143,6 @@ private void handleRepoType(TypeDeclaration typeDecl) {
domainTypeIndex = idx;
domainType = typeParams[domainTypeIndex];
}
domainTypeChanged = true;
}
if (idType == null || idType.isTypeVariable()) {
int idx = idType == null ? -1
Expand All @@ -156,31 +153,16 @@ private void handleRepoType(TypeDeclaration typeDecl) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1152,4 +1152,40 @@ public interface RoleRepository extends JpaRepository<Role, Long> {
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());

}

}

0 comments on commit 131336a

Please sign in to comment.