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

xapi.source.impl.ImmutableAnnotationValue Maven / Gradle / Ivy

Go to download

Everything needed to run a comprehensive dev environment. Just type X_ and pick a service from autocomplete; new dev modules will be added as they are built. The only dev service not included in the uber jar is xapi-dev-maven, as it includes all runtime dependencies of maven, adding ~4 seconds to build time, and 6 megabytes to the final output jar size (without xapi-dev-maven, it's ~1MB).

The newest version!
package xapi.source.impl;

import xapi.source.X_Modifier;
import xapi.source.api.IsAnnotationValue;
import xapi.util.api.ConvertsValue;
import xapi.util.converters.ConvertsStringValue;

public class ImmutableAnnotationValue implements IsAnnotationValue{

  private final Object value;
  private final String type;
  private final int modifier;
  private final ConvertsValue toString;

  public ImmutableAnnotationValue(String type, Object value, int modifier) {
    this(type, value, new ConvertsStringValue(),  modifier);
  }
  public ImmutableAnnotationValue(String type, Object value, ConvertsValue toString, int modifier) {
    this.type = type;
    this.value = value;
    this.toString = toString;
    this.modifier = modifier;
  }

  @Override
  public boolean isArray() {
    return type.contains("[]");
  }

  @Override
  public boolean isEnum() {
    return modifier == X_Modifier.ENUM;
  }

  @Override
  public boolean isClass() {
    return type.contains("java.lang.Class");
  }

  @Override
  public boolean isAnnotation() {
    return modifier == X_Modifier.ANNOTATION;
  }

  @Override
  public boolean isString() {
    return type.contains("java.lang.String");
  }

  @Override
  public boolean isPrimitive() {
    return modifier == -1;
  }

  @Override
  public String getType() {
    return type;
  }

  @Override
  public Object getRawValue() {
    return value;
  }
  @Override
  public Object loadValue(ClassLoader loader) {
    if (isArray()) {
      // 
    }
    throw new UnsupportedOperationException("loadValue not yet supported");
  }
  
  @Override
  public String toString() {
    return toString.convert(value);
  }
  
}