Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix signature of STGroup.getAttributeRenderer #237

Merged
merged 4 commits into from Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/org/stringtemplate/v4/Interpreter.java
Expand Up @@ -792,7 +792,7 @@ protected int writeIterator(STWriter out, InstanceScope scope, Object o, String[
protected int writePOJO(STWriter out, InstanceScope scope, Object o, String[] options) throws IOException {
String formatString = null;
if ( options!=null ) formatString = options[Option.FORMAT.ordinal()];
String v = renderObject(scope, formatString, o, o.getClass());
String v = renderObject(scope, formatString, o);
Clashsoft marked this conversation as resolved.
Show resolved Hide resolved
int n;
if ( options!=null && options[Option.WRAP.ordinal()]!=null ) {
n = out.write(v, options[Option.WRAP.ordinal()]);
Expand All @@ -803,9 +803,10 @@ protected int writePOJO(STWriter out, InstanceScope scope, Object o, String[] op
return n;
}

private <T> String renderObject(InstanceScope scope, String formatString, T o, Class<? extends T> attributeType) {
@SuppressWarnings({ "rawtypes", "unchecked" })
private String renderObject(InstanceScope scope, String formatString, Object o) {
Clashsoft marked this conversation as resolved.
Show resolved Hide resolved
// ask the native group defining the surrounding template for the renderer
AttributeRenderer<? super T> r = scope.st.impl.nativeGroup.getAttributeRenderer(attributeType);
AttributeRenderer r = scope.st.impl.nativeGroup.getAttributeRenderer(o.getClass());
Clashsoft marked this conversation as resolved.
Show resolved Hide resolved
if ( r!=null ) {
return r.toString(o, formatString, locale);
Clashsoft marked this conversation as resolved.
Show resolved Hide resolved
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/org/stringtemplate/v4/STGroup.java
Expand Up @@ -789,7 +789,7 @@ public <T> void registerRenderer(Class<T> attributeType, AttributeRenderer<? sup
* have multiple renderers for {@code String}, say, then just make uber combined
* renderer with more specific format names.</p>
*/
public <T> AttributeRenderer<? super T> getAttributeRenderer(Class<? extends T> attributeType) {
public <T> AttributeRenderer<? super T> getAttributeRenderer(Class<T> attributeType) {
if ( renderers==null ) {
return null;
}
Expand Down