-
1. Re: How do I set the line length in code generated using Roaster?
gastaldi Aug 29, 2016 12:07 AM (in response to bfancher)Hi Bruce,
You need to call the format method that takes a Properties as a param.
Something like the following:
String source = javaClass.toUnformattedString(); Properties props = new Properties(); props.setProperty(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "100"); source = Roaster.format(props,source)
PS: DefaultCodeFormatterConstants is an Eclipse JDT class.
-
2. Re: How do I set the line length in code generated using Roaster?
bfancher Aug 29, 2016 12:30 AM (in response to gastaldi)Thanks, but that doesn't seem to work. I also tried a few other variations based on the constants I found defined. Still no luck.
String source = javaClass.toUnformattedString();
Properties props = new Properties();
props.setProperty(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "160");
props.setProperty(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, "160");
props.setProperty(DefaultCodeFormatterConstants.FORMATTER_JOIN_WRAPPED_LINES, "TRUE");
String formatted = Roaster.format(props, source);
-
3. Re: How do I set the line length in code generated using Roaster?
gastaldi Aug 29, 2016 5:04 PM (in response to bfancher)1 of 1 people found this helpfulLooks like the JDT formatter requires some attributes that I forgot to specify in my example. Try adding these to your properties object:
props.setProperty(JavaCore.COMPILER_SOURCE, CompilerOptions.VERSION_1_8); props.setProperty(JavaCore.COMPILER_COMPLIANCE, CompilerOptions.VERSION_1_8); props.setProperty(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, CompilerOptions.VERSION_1_8);
-
4. Re: How do I set the line length in code generated using Roaster?
gastaldi Aug 29, 2016 5:06 PM (in response to gastaldi)1 of 1 people found this helpfulAnother option is to export your code format to an XML file and use the FormatterProfileReader class to create the properties object from it.
-
5. Re: How do I set the line length in code generated using Roaster?
bfancher Sep 3, 2016 7:13 PM (in response to gastaldi)Thanks!