manifold-systems / manifold

Manifold is a Java compiler plugin, its features include Metaprogramming, Properties, Extension Methods, Operator Overloading, Templates, a Preprocessor, and more.
http://manifold.systems/
Apache License 2.0
2.43k stars 125 forks source link

Template inheritance (extends) documentation is incorrect #448

Closed shai-almog closed 1 year ago

shai-almog commented 1 year ago

This page: https://github.com/manifold-systems/manifold/blob/master/manifold-deps-parent/manifold-templates/README.md

Includes this example code:


import model.Contact;
import manifold.templates.rt.runtime.BaseTemplate;

public class ExampleTemplate extends BaseTemplate {

  public String displayContact(Contact c) {
    if(c.hasName()) {
      return c.getName();
    } else {
      return c.getEmail();
    }
  }

}

Unfortunately getTemplateResourceAsStream() is abstract and missing from that sample. I wanted to fix the code but I'm a bit baffled about the default implementation. I looked here, but that code seems to relate to compile time processing. Not to runtime which is where the template should be relevant.

rsmckinney commented 1 year ago

@shai-almog Hi. Yep, looks like an error in the example. The class should be declared abstract. In fact, all custom BaseTemplate subclasses should be declared abstract since the implementation for getTemplateResourceAsStream() is generated in the final class.

For instance, in the example ShowContact is generated and extends ExampleTemplate. Since getTemplateResourceAsStream() is abstract and generated in ShowContact, ExampleTemplate should be declared abstract.

I'll correct the docs shortly. Apologies for the mix-up and thanks for reporting this!

shai-almog commented 1 year ago

That makes a lot of sense. Thanks!