Class LanguageRuntime


  • public abstract class LanguageRuntime
    extends Object
    Runtime representation of a language, extension point for various language aspects. Dependency from typesystem, find usages and other language aspects is transitional, eventually (after 3.2) this class shall be generic and aware of ILanguageAspect only. It shall not load any classes through reflection (any class-loading of generated code/aspects is responsibility of generated language runtime class).

    Language runtime keeps track of aspects queried (instantiates them lazily).

    • Constructor Detail

      • LanguageRuntime

        public LanguageRuntime()
    • Method Detail

      • getNamespace

        public abstract String getNamespace()
        Returns:
        full name of the language, never null.
      • getId

        public abstract SLanguageId getId()
        Returns:
        identity of the language, never null. Generated LanguageRuntime classes shall override return value
      • getIdentity

        public final SLanguage getIdentity()
        Returns:
        persistable identity of a deployed language
      • getVersion

        public abstract int getVersion()
        Generated LanguageRuntime classes shall override this method
        Since:
        3.2
      • getAspect

        public final <T extends ILanguageAspect> T getAspect​(@NotNull
                                                             Class<T> aspectClass)
        Provide aspect instance associated with the language. Aspect is instantiated only once, lazily (the first time asked) and the same instance is returned for each subsequent calls.

        At the moment, sole mechanism to supply new aspect is code in generated language runtime subclass (i.e. there's no mechanism yet to add aspects dynamically).

        Calls LanguageRuntimeAware.setLanguageRuntime(LanguageRuntime) on aspects implementing LanguageRuntimeAware after creation, passing itself as the parameter.

        Type Parameters:
        T - subtype of ILanguageAspect
        Parameters:
        aspectClass - identifies aspect to retrieve
        Returns:
        instance of aspect implementation if there's one for the language
        See Also:
        createAspect(Class), ILanguageAspect
      • createAspect

        protected abstract <T extends ILanguageAspect> T createAspect​(Class<T> aspectClass)
        Method every language shall implement to tell its capabilities. Implementation doesn't need to keep state, getAspect(Class) does that.
        Type Parameters:
        T - aspect class
        Parameters:
        aspectClass - never null identifying interface of the aspect
        Returns:
        may return null indicating language has no such aspect
      • populateRegisteredGenerators

        protected final void populateRegisteredGenerators​(List<? super GeneratorRuntime> consumer)
      • getExtendingLanguages

        @NotNull
        public Iterable<LanguageRuntime> getExtendingLanguages()
        Closure of all languages that extend this one, exclusive. FIXME why Iterable?
        Returns:
        unmodifiable collection of languages
      • getExtendedLanguages

        @NotNull
        public Collection<LanguageRuntime> getExtendedLanguages()
        Closure of all languages this language extends, exclusive. Referenced languages are from the same LanguageRegistry as this one. (Although there's only one LanguageRegistry at the moment, it's likely to change in the future)

        Collection captures only languages actually available, and might not reflect all dependencies of the language, i.e. presents state of language relationship through a LanguageRegistry perspective. E.g. if language descriptor states 'extends' dependency from a language missing in the LanguageRegistry instance, that extended language will be ignored and collection returned won't mention it.

        Returns:
        unmodifiable collection of languages
      • fillExtendedLanguages

        protected void fillExtendedLanguages​(Collection<SLanguage> extendedLanguages)
        Subclasses shall override to report languages they extend (fill in supplied collection). It's not necessary to override the method if language doesn't extend any other, not to invoke super, this method is no-op.

        DESIGN NOTE: while it's sufficient to know SLanguageId only, I stick to SLanguage to keep namespace as debug information. Perhaps, shall pass an object that could take different alternatives (e.g. SLanguageId, (long,long), module reference)?