Skip to content

Commit

Permalink
ObjectTag#refreshState
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 23, 2022
1 parent 15bacea commit 19506b7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
Expand Up @@ -168,7 +168,11 @@ else if (attribute.getAttributeWithoutParam(2).equals("expiration")) {
attribute.fulfill(1);
return new DurationTag((time.millis() - TimeTag.now().millis()) / 1000.0);
}
return getFlagValue(attribute.getParam());
ObjectTag retVal = getFlagValue(attribute.getParam());
if (retVal == null) {
return null;
}
return retVal.refreshState();
}

public TimeTag doFlagExpirationTag(Attribute attribute) {
Expand Down
Expand Up @@ -255,4 +255,12 @@ default boolean tryAdvancedMatcher(String matcher) {
}
return advancedMatches(matcher);
}

/**
* If this object has unusual behavior when being read back (eg from a flag or def tag), override this method to apply that behavior.
* For example, noted objects might re-get the current note value instead of returning a broken formerly-noted raw object.
*/
default ObjectTag refreshState() {
return this;
}
}
Expand Up @@ -29,14 +29,6 @@ public static boolean isSaved(Notable object) {
return objectToName.containsKey(object);
}

public static boolean isExactSavedObject(Notable object) {
String id = objectToName.get(object);
if (id == null) {
return false;
}
return nameToObject.get(id) == object;
}

public static Notable getSavedObject(String id) {
return nameToObject.get(CoreUtilities.toLowerCase(id));
}
Expand Down
Expand Up @@ -46,7 +46,7 @@ public DefinitionTagBase() {
return null;
}
if (attribute.attributes.length == 1) {
return def;
return def.refreshState();
}
return CoreUtilities.fixType(def, attribute.context);
};
Expand Down
Expand Up @@ -248,7 +248,7 @@ public static ObjectTag fixType(ObjectTag input, TagContext context) {
if (input instanceof ElementTag && !((ElementTag) input).isPlainText) {
return ObjectFetcher.pickObjectFor(input.toString(), context);
}
return input;
return input.refreshState();
}

public static void autoPropertyMechanism(ObjectTag object, Mechanism mechanism) {
Expand Down

0 comments on commit 19506b7

Please sign in to comment.