/** * Appends an attribute to the list of attributes. * * @param attr */ public void addAttribute(Attribute<?> attr) { if (attributes == null) attributes = new Attributes(); attributes.add(attr); }
/** * @param key * @return whether the attribute key occurs in the list of attributes. */ public boolean containsAttribute(Key<?> key) { if (attributes == null) return false; return attributes.containsKey(key); }
@Override public String toString() { if (isEmpty()) return ""; String content = "["; for (Attribute<?> t : contents.values()) content += t + ", "; return content.substring(0, content.length() - 2) + "]"; }
public static org.kframework.attributes.Att convertAttributes(ASTNode t) { Attributes attributes = t.getAttributes(); Map<String, String> attributesSet = attributes .keySet() .stream() .map(key -> { String keyString = key.toString(); String valueString = attributes.get(key).getValue().toString(); if (keyString.equals("klabel")) { return Tuple2.apply("klabel", valueString); } else { return Tuple2.apply(keyString, valueString); } }).collect(Collectors.toMap(Tuple2::_1, Tuple2::_2)); return Att().addAll(attributesSet) .addAll(attributesFromLocation(t.getLocation())) .addAll(attributesFromSource(t.getSource())); }
/** * Retrieves the attribute by key from the list of attributes */ public <T> T getAttr(Key<T> key) { final Attribute<T> value = (Attribute<T>) get(key); if (value == null) return null; return value.getValue(); }
/** * @return the attributes object associated to this ASTNode. Constructs one if it is * not already created. */ public Attributes getAttributes() { if (attributes == null) { attributes = new Attributes(); } return attributes; }
public <T> T typeSafeGet(Class<T> cls, String string) { return typeSafeGet(Key.get(cls, Names.named(string))); }
public <T> void add(Class<T> cls, String string, T value) { add(new Attribute<T>(Key.get(cls, Names.named(string)), value)); }
/** * Copies attributes from another node into this node. * Use this in preference to {@link ASTNode#getAttributes} where appropriate because * the latter will create a new object if no attributes exist. * @param node The ASTNode to copy all attributes from. */ public void copyAttributesFrom(ASTNode node) { if (node.attributes == null) return; this.getAttributes().putAll(node.attributes); }
public String getAttr(String key) { return getAttr(Attribute.keyOf(key)); }
public void removeAttribute(String key) { getAttributes().remove(Attribute.keyOf(key)); }
public <T> T typeSafeGet(Key<T> key) { Attribute<?> attr = get(key); if (attr == null) return null; return (T) attr.getValue(); }
@Override public Attributes shallowCopy() { Attributes result = new Attributes(); result.contents.putAll(contents); return result; }
public <T> T typeSafeGet(Class<T> cls) { return typeSafeGet(Key.get(cls)); }
public <T> void add(Class<T> cls, T value) { add(new Attribute<T>(Key.get(cls), value)); }
/** * Retrieves the attribute by key from the list of attributes * * @param key * @return a value for key in the list of attributes or the default value. */ public <T> T getAttribute(Key<T> key) { if (attributes == null) return null; final Attribute<T> value = (Attribute<T>) attributes.get(key); if (value == null) return null; return value.getValue(); }
/** * @param key * @return whether the attribute key occurs in the list of attributes. */ public boolean containsAttribute(String key) { if (attributes == null) return false; return attributes.containsKey(Attribute.keyOf(key)); }