向下兼容IDEA171版本

This commit is contained in:
makejava 2021-08-07 17:44:48 +08:00
parent 54cf144638
commit 3ffb11cc57
1 changed files with 13 additions and 8 deletions

View File

@ -22,12 +22,10 @@ public final class PsiClassGenerateUtils {
if("id".equals(field.getName())) {
return true;
}
PsiAnnotation idAnnotation = field.getAnnotation("org.springframework.data.annotation.Id");
if (idAnnotation != null) {
if (existsAnnotation(field, "org.springframework.data.annotation.Id")) {
return true;
}
idAnnotation = field.getAnnotation("javax.persistence.Id");
if (idAnnotation != null) {
if (existsAnnotation(field, "javax.persistence.Id")) {
return true;
}
return false;
@ -41,14 +39,21 @@ public final class PsiClassGenerateUtils {
if(modifierList != null && modifierList.hasExplicitModifier(PsiModifier.STATIC)) {
return true;
}
PsiAnnotation annotation = field.getAnnotation("org.springframework.data.annotation.Transient");
if (annotation != null) {
if (existsAnnotation(field, "org.springframework.data.annotation.Transient")) {
return true;
}
annotation = field.getAnnotation("javax.persistence.Transient");
if (annotation != null) {
if (existsAnnotation(field, "javax.persistence.Transient")) {
return true;
}
return false;
}
private static boolean existsAnnotation(PsiField field, String clsName) {
return getAnnotation(field, clsName) != null;
}
private static PsiAnnotation getAnnotation(PsiField field, String clsName) {
PsiModifierList list = field.getModifierList();
return list == null ? null : list.findAnnotation(clsName);
}
}