net.karneim.pojobuilder.model.MethodM Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pojobuilder Show documentation
Show all versions of pojobuilder Show documentation
The PojoBuilder Generator is a Java 6 compliant annotation processor that generates a fluent builder class for POJOs (Plain Old Java Object)
package net.karneim.pojobuilder.model;
import static javax.lang.model.element.Modifier.PRIVATE;
import static javax.lang.model.element.Modifier.PROTECTED;
import static javax.lang.model.element.Modifier.PUBLIC;
import java.util.Set;
import javax.lang.model.element.Modifier;
public class MethodM {
private String name;
private Set modifiers;
private TypeM declaringClass;
public MethodM(String name, Set modifiers) {
super();
this.name = name;
this.modifiers = modifiers;
}
public String getName() {
return name;
}
public Set getModifiers() {
return modifiers;
}
public TypeM getDeclaringClass() {
return declaringClass;
}
@SuppressWarnings("unchecked")
public M declaredIn(TypeM type) {
this.declaringClass = type;
return (M)this;
}
public boolean isAccessibleFor(TypeM accessingClass) {
if (accessingClass == null) {
throw new NullPointerException("accessingClass==null!");
}
if (declaringClass == null) {
throw new IllegalStateException(String.format("Missing declaringClass in MethodM %s", name));
}
// TODO check modifiers PROTECTED or package protected etc.
if (modifiers.contains(PRIVATE)) {
return false;
}
if (modifiers.contains(PROTECTED)) {
return accessingClass.isInPackage(declaringClass.getPackageName());
}
if (modifiers.contains(PUBLIC)) {
return true;
}
return accessingClass.isInPackage(declaringClass.getPackageName());
}
@Override
public String toString() {
return "MethodM [name=" + name + ", modifiers=" + modifiers + ", declaringClass=" + declaringClass + "]";
}
}