All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.karneim.pojobuilder.model.MethodM Maven / Gradle / Ivy

Go to download

The PojoBuilder Generator is a Java 6 compliant annotation processor that generates a fluent builder class for POJOs (Plain Old Java Object)

There is a newer version: 4.3.0
Show newest version
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 + "]";
  }



}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy