1 19 20 package org.netbeans.modules.j2ee.jpa.verification.rules.entity; 21 22 import java.util.Collections ; 23 import javax.lang.model.element.Element; 24 import javax.lang.model.element.ElementKind; 25 import javax.lang.model.element.TypeElement; 26 import javax.lang.model.type.DeclaredType; 27 import javax.lang.model.type.TypeKind; 28 import javax.lang.model.type.TypeMirror; 29 import org.netbeans.modules.j2ee.jpa.model.JPAHelper; 30 import org.netbeans.modules.j2ee.jpa.verification.JPAClassRule; 31 import org.netbeans.modules.j2ee.jpa.verification.common.ProblemContext; 32 import org.netbeans.spi.editor.hints.ErrorDescription; 33 import org.openide.util.NbBundle; 34 35 44 public class IdDefinedInHierarchy extends JPAClassRule { 45 46 public IdDefinedInHierarchy(){ 47 setClassContraints(Collections.singleton(ClassConstraints.ENTITY)); 48 } 49 50 @Override public ErrorDescription[] apply(TypeElement subject, ProblemContext ctx){ 51 TypeElement javaClass = subject; 52 53 do{ 54 if (JPAHelper.isAnyMemberAnnotatedAsIdOrEmbeddedId(javaClass)){ 55 return null; } 57 58 TypeMirror parentType = javaClass.getSuperclass(); 59 javaClass = null; 60 61 if (!"java.lang.Object".equals(parentType.toString())){ if (parentType.getKind() == TypeKind.DECLARED){ 63 Element parent = ((DeclaredType)parentType).asElement(); 64 65 if (parent.getKind() == ElementKind.CLASS){ 66 javaClass = (TypeElement) parent; 67 } 68 } 69 } 70 71 } while (javaClass != null); 72 73 return new ErrorDescription[]{createProblem(subject, ctx)}; 74 } 75 76 public String getDescription(){ 77 return NbBundle.getMessage(IdDefinedInHierarchy.class, "MSG_NoIdDefinedInHierarchy"); 78 } 79 } 80 | Popular Tags |