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.JPAAnnotations; 30 import org.netbeans.modules.j2ee.jpa.verification.JPAClassRule; 31 import org.netbeans.modules.j2ee.jpa.verification.JPAClassRule.ClassConstraints; 32 import org.netbeans.modules.j2ee.jpa.verification.common.ProblemContext; 33 import org.netbeans.modules.j2ee.jpa.verification.common.Utilities; 34 import org.netbeans.spi.editor.hints.ErrorDescription; 35 import org.openide.util.NbBundle; 36 37 45 public class NoIdClassOnEntitySubclass extends JPAClassRule { 46 47 48 public NoIdClassOnEntitySubclass() { 49 setClassContraints(Collections.singleton(ClassConstraints.ENTITY)); 51 } 52 53 @Override public ErrorDescription[] apply(TypeElement subject, ProblemContext ctx){ 54 if (!Utilities.hasAnnotation(subject, JPAAnnotations.ID_CLASS)){ 55 56 TypeMirror superClassType = subject.getSuperclass(); 57 58 if (superClassType.getKind() == TypeKind.DECLARED){ 59 Element superClassElem = ((DeclaredType)superClassType).asElement(); 60 61 if (Utilities.hasAnnotation(superClassElem, JPAAnnotations.ENTITY)){ 62 return new ErrorDescription[]{createProblem(subject, ctx)}; 63 } 64 } 65 } 66 67 return null; 68 } 69 70 @Override public String getDescription(){ 71 return NbBundle.getMessage(IdDefinedInHierarchy.class, "MSG_EntitySubclassHasIdClass"); 72 } 73 74 } 75 | Popular Tags |