org.infinispan.protostream.descriptors.AnnotationElement Maven / Gradle / Ivy
package org.infinispan.protostream.descriptors;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author [email protected]
* @since 2.0
*/
public abstract class AnnotationElement {
public static final long UNKNOWN_POSITION = 0;
private static final long LINESHIFT = 32;
private static final long COLUMNMASK = (1L << LINESHIFT) - 1;
public final long position;
public static int line(long pos) {
return (int) (pos >>> LINESHIFT);
}
public static int column(long pos) {
return (int) (pos & COLUMNMASK);
}
public static long makePosition(int line, int column) {
return ((long) line << LINESHIFT) + column;
}
public static String positionToString(long pos) {
return line(pos) + "," + column(pos);
}
protected AnnotationElement(long position) {
this.position = position;
}
public static abstract class Value extends AnnotationElement {
protected Value(long pos) {
super(pos);
}
public abstract Object getValue();
}
public static final class Annotation extends Value {
/**
* Name of default attribute.
*/
public static final String DEFAULT_ATTRIBUTE = "value";
private final String name;
private final Map attributes;
public Annotation(long pos, String name, Map attributes) {
super(pos);
this.name = name;
this.attributes = attributes;
}
public String getName() {
return name;
}
public Map getAttributes() {
return attributes;
}
@Override
public Annotation getValue() {
return this;
}
public Value getDefaultAttributeValue() {
return getAttributeValue(DEFAULT_ATTRIBUTE);
}
public Value getAttributeValue(String attributeName) {
Attribute attribute = attributes.get(attributeName);
if (attribute == null) {
throw new IllegalStateException("Attribute " + attributeName + " of annotation " + name + " is missing");
}
return attribute.value;
}
public void acceptVisitor(Visitor visitor) {
visitor.visit(this);
}
}
public static final class Attribute extends AnnotationElement {
private final String name;
private final Value value;
public Attribute(long pos, String name, Value value) {
super(pos);
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public Value getValue() {
return value;
}
public void acceptVisitor(Visitor visitor) {
visitor.visit(this);
}
}
public static final class Identifier extends Value {
private final String identifier;
public Identifier(long pos, String identifier) {
super(pos);
this.identifier = identifier;
}
public String getIdentifier() {
return identifier;
}
@Override
public String getValue() {
return identifier;
}
public void acceptVisitor(Visitor visitor) {
visitor.visit(this);
}
}
public static final class Array extends Value {
private final List values;
public Array(long pos, List values) {
super(pos);
this.values = values;
}
public List getValues() {
return values;
}
@Override
public List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy