javax0.jamal.api.Identified Maven / Gradle / Ivy
Show all versions of jamal-api Show documentation
package javax0.jamal.api;
/**
* Something that is usually defined by the user and as such has an identifier.
*
* The typical user defined things are
*
*
* - user defined macros
* - user defined scripts
*
*
* Some macros also want to implement something similar things that may or may not be accessed from the processed
* jamal text, but are available and managed by the code. A good example is how the macro
* {@code javax0.jamal.builtins.Options} is implemented. When the options is first defined it creates an instance of
* {@code javax0.jamal.tools.OptionsStore}, which is neither a script, nor a macro and it cannot be evaluated, but
* it has an identifier, which is {@code `options}. This object is stored along with the scripts and user defined
* macros with the same life cycle as those. If an option was set in a local environment it will no affect environments
* above unless it is exported.
*/
@FunctionalInterface
public interface Identified {
/**
* Get the string identifier of the identifiable.
*
* @return the string representation of the identifier. Usually a human readable name.
*/
String getId();
String DEFAULT_MACRO = "default";
String MACRO_NAME_ARG1 = "$macro";
String MACRO_NAME_ARG2 = "$_";
/**
* A special placeholder for Identified enties that get undefined.
*
* When an entity (typically a user defined macro) is not defined it is nowhere in the different layers. If it were
* defined in any fo the layers then the current layer would inherit it and then it is defined.
*
* When we explicitly want to undefine a macro we should not delete the definition from the structure, because the
* effect of undefining a macro should have the same locality as defining it. For this reason we insert a dummy
* definition, which is an instance of this class.
*
* This "undefined" definition is local, can be exported and behaves exactly the same way as a "normal" defined
* macro.
*/
class Undefined implements Identified {
private final String id;
public Undefined(String id) {
this.id = id;
}
@Override
public String getId() {
return id;
}
}
}