1 19 20 package org.netbeans.modules.j2ee.jpa.verification.rules.entity; 21 22 import java.util.Arrays ; 23 import javax.lang.model.element.Element; 24 import javax.lang.model.element.ElementKind; 25 import javax.lang.model.element.ExecutableElement; 26 import javax.lang.model.element.Modifier; 27 import javax.lang.model.element.TypeElement; 28 import org.netbeans.modules.j2ee.jpa.verification.JPAClassRule; 29 import org.netbeans.modules.j2ee.jpa.verification.common.ProblemContext; 30 import org.netbeans.spi.editor.hints.ErrorDescription; 31 import org.openide.util.NbBundle; 32 33 39 public class HasNoArgConstructor extends JPAClassRule { 40 41 42 public HasNoArgConstructor() { 43 setClassContraints(Arrays.asList(ClassConstraints.ENTITY, 44 ClassConstraints.EMBEDDABLE, ClassConstraints.IDCLASS)); 45 } 46 47 @Override public ErrorDescription[] apply(TypeElement subject, ProblemContext ctx){ 48 for (Element element : subject.getEnclosedElements()){ 49 if (element.getKind() == ElementKind.CONSTRUCTOR){ 50 ExecutableElement constr = (ExecutableElement) element; 51 52 if (constr.getParameters().size() == 0 53 && (constr.getModifiers().contains(Modifier.PUBLIC) 54 || constr.getModifiers().contains(Modifier.PROTECTED))){ 55 return null; } 57 } 58 } 59 60 return new ErrorDescription[]{createProblem(subject, ctx)}; 61 } 62 63 public String getDescription(){ 64 return NbBundle.getMessage(IdDefinedInHierarchy.class, "MSG_HasNoNoArgConstructor"); 65 } 66 } 67 | Popular Tags |