String Attribute Renderer called for all text - not just attributes
- Dominant language
- Java
- Stars
- 1k
- Forks
- 234
- PR merge metrics
- No merged PRs in 30d
Description
In version 3 we could code so that an `AttributeRenderer` applied to `String.class` was only called for attributes set onto the template. We are trying to create the same behaviour with version 4. However, the `AttributeRenderer` seems to be called now for all text in the file.
We are unsure if this is a bug or we are making the wrong assumption
See test below to reproduce:
``` java
import static org.junit.Assert.fail;
import java.util.Locale;
import org.junit.Test;
import org.stringtemplate.v4.AttributeRenderer;
import org.stringtemplate.v4.ST;
import org.stringtemplate.v4.STGroupString;
public class StringTemplateRenderDoesNotGetAppliedToWholeStringTemplateTest {
@Test
public void rendererNotCalledWhenNoAttributesSet() {
STGroupString group = new STGroupString("stringTemplateWithNoAttributes() ::= << 1 >>");
group.registerRenderer(String.class, new AttributeRenderer() {
@Override
public String toString(Object o, String formatString, Locale locale) {
fail("The renderer must not get called. Object passed in was '" + o.toString() + "'");
throw new UnsupportedOperationException();
}
});
ST template = group.getInstanceOf("stringTemplateWithNoAttributes");
template.render();
}
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.