Skip to content

(doc) Simplify CompilationFailureException #19

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

Merged
merged 3 commits into from
Aug 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,45 +34,50 @@ public class CompilationFailureException
{
private static final String LS = System.getProperty( "line.separator" );

/**
* Wrap error messages from the compiler
*
* @param messages the messages, not null
* @since 2.0
*/
public CompilationFailureException( List<CompilerMessage> messages )
{
super( null, shortMessage( messages ), longMessage( messages ) );
}

/**
* Long message will have all messages, one per line
*
* @param messages the messages, not null
* @return the long error message
* @since 2.0
*/
public static String longMessage( List<CompilerMessage> messages )
{
StringBuilder sb = new StringBuilder();

if ( messages != null )
for ( CompilerMessage compilerError : messages )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use this opportunity to improve javadoc as well and to make clear that messages cannot be null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me - how's it looking now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these methods be private static or just inlined into the constructor? They have no other callers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it's not possible to inline them because of the super() call

{
for ( CompilerMessage compilerError : messages )
{
sb.append( compilerError ).append( LS );
}
sb.append( compilerError ).append( LS );
}

return sb.toString();
}

/**
* Short message will have the error message if there's only one, useful for errors forking the compiler
*
* @param messages the messages
* @param messages the messages, not null
* @return the short error message
* @since 2.0.2
*/
public static String shortMessage( List<CompilerMessage> messages )
{
StringBuilder sb = new StringBuilder();

sb.append( "Compilation failure" );
StringBuilder sb = new StringBuilder( "Compilation failure" );

if ( messages.size() == 1 )
{
sb.append( LS );

CompilerMessage compilerError = messages.get( 0 );

sb.append( compilerError ).append( LS );
sb.append( LS ).append( messages.get( 0 ) ).append( LS );
}

return sb.toString();
Expand Down