Repo id and domain class id being a number excluded
This commit is contained in:
@@ -46,6 +46,15 @@ import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemTy
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.ReconcileProblemImpl;
|
||||
|
||||
public class EntityIdForRepoReconciler implements JdtAstReconciler {
|
||||
|
||||
private static final List<String> NUMBER_CLASS_NAMES = List.of(
|
||||
Integer.class.getName(),
|
||||
Long.class.getName(),
|
||||
Short.class.getName(),
|
||||
Float.class.getName(),
|
||||
Double.class.getName(),
|
||||
Byte.class.getName()
|
||||
);
|
||||
|
||||
@Override
|
||||
public void reconcile(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector,
|
||||
@@ -253,7 +262,10 @@ public class EntityIdForRepoReconciler implements JdtAstReconciler {
|
||||
}
|
||||
|
||||
private boolean isValidRepoIdType(ITypeBinding repoIdType, ITypeBinding idType) {
|
||||
return repoIdType.isAssignmentCompatible(idType) || idType.isAssignmentCompatible(repoIdType);
|
||||
if (NUMBER_CLASS_NAMES.contains(repoIdType.getQualifiedName()) && NUMBER_CLASS_NAMES.contains(idType.getQualifiedName())) {
|
||||
return true;
|
||||
}
|
||||
return repoIdType.isCastCompatible(idType) || idType.isCastCompatible(repoIdType);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -199,18 +199,7 @@ public class EntityIdForRepoReconcilerTest extends BaseReconcilerTest {
|
||||
""";
|
||||
List<ReconcileProblem> problems = reconcile("EmployeeRepository.java", source, false, employeeSource);
|
||||
|
||||
assertEquals(1, problems.size());
|
||||
|
||||
ReconcileProblem problem = problems.get(0);
|
||||
|
||||
assertEquals(Boot2JavaProblemType.DOMAIN_ID_FOR_REPOSITORY, problem.getType());
|
||||
|
||||
String markedStr = source.substring(problem.getOffset(), problem.getOffset() + problem.getLength());
|
||||
assertEquals("Double.class", markedStr);
|
||||
assertEquals("Expected Domain ID type is 'java.lang.Integer'", problem.getMessage());
|
||||
|
||||
assertEquals(0, problem.getQuickfixes().size());
|
||||
|
||||
assertEquals(0, problems.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1118,4 +1107,49 @@ public class EntityIdForRepoReconcilerTest extends BaseReconcilerTest {
|
||||
assertEquals("Expected Domain ID type is 'demo.CustomerId'", problem.getMessage());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void gh1159() throws Exception {
|
||||
Path roleSource = createFile("Role.java", """
|
||||
package demo;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "roles")
|
||||
public class Role {
|
||||
|
||||
@Id
|
||||
private Integer id;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
||||
""");
|
||||
|
||||
String source = """
|
||||
package demo;
|
||||
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface RoleRepository extends JpaRepository<Role, Long> {
|
||||
|
||||
}
|
||||
""";
|
||||
List<ReconcileProblem> problems = reconcile("CustomerRepository.java", source, false, roleSource);
|
||||
|
||||
assertEquals(0, problems.size());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user