From commits-return-10170-archive-asf-public=cust-asf.ponee.io@groovy.apache.org Mon Dec 9 07:08:34 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 199FF180680 for ; Mon, 9 Dec 2019 08:08:33 +0100 (CET) Received: (qmail 51314 invoked by uid 500); 9 Dec 2019 07:08:33 -0000 Mailing-List: contact commits-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list commits@groovy.apache.org Received: (qmail 51212 invoked by uid 99); 9 Dec 2019 07:08:33 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Dec 2019 07:08:33 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 99F288D809; Mon, 9 Dec 2019 07:08:32 +0000 (UTC) Date: Mon, 09 Dec 2019 07:08:34 +0000 To: "commits@groovy.apache.org" Subject: [groovy] 02/04: fix generics handling and other minor edits MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: sunlan@apache.org In-Reply-To: <157587531206.18450.13676442878756440215@gitbox.apache.org> References: <157587531206.18450.13676442878756440215@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: groovy X-Git-Refname: refs/heads/GROOVY_3_0_X X-Git-Reftype: branch X-Git-Rev: 007e77c24562a75c1b8405cf12ba6f8858611c5e X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20191209070832.99F288D809@gitbox.apache.org> This is an automated email from the ASF dual-hosted git repository. sunlan pushed a commit to branch GROOVY_3_0_X in repository https://gitbox.apache.org/repos/asf/groovy.git commit 007e77c24562a75c1b8405cf12ba6f8858611c5e Author: Eric Milles AuthorDate: Sat Dec 7 13:33:21 2019 -0600 fix generics handling and other minor edits (cherry picked from commit 17185c94fe17148492dd5b0c1a1112a2427fd19d) --- .../codehaus/groovy/control/ErrorCollector.java | 269 ++++++++++----------- 1 file changed, 122 insertions(+), 147 deletions(-) diff --git a/src/main/java/org/codehaus/groovy/control/ErrorCollector.java b/src/main/java/org/codehaus/groovy/control/ErrorCollector.java index 232d3df..60fb05e 100644 --- a/src/main/java/org/codehaus/groovy/control/ErrorCollector.java +++ b/src/main/java/org/codehaus/groovy/control/ErrorCollector.java @@ -39,75 +39,74 @@ import java.util.List; public class ErrorCollector implements Serializable { private static final long serialVersionUID = 2844774170905056755L; + /** - * WarningMessages collected during processing + * ErrorMessages collected during processing */ - protected LinkedList warnings; + protected LinkedList errors; + /** - * ErrorMessages collected during processing + * WarningMessages collected during processing */ - protected LinkedList errors; + protected LinkedList warnings; + /** * Configuration and other settings that control processing */ - protected CompilerConfiguration configuration; + protected final CompilerConfiguration configuration; /** * Initialize the ErrorReporter. */ - public ErrorCollector(CompilerConfiguration configuration) { - this.warnings = null; - this.errors = null; - + public ErrorCollector(final CompilerConfiguration configuration) { this.configuration = configuration; } - - public void addCollectorContents(ErrorCollector er) { - if (er.errors!=null) { - if (errors==null) { - errors = er.errors; + + public void addCollectorContents(final ErrorCollector that) { + if (that.errors != null) { + if (this.errors == null) { + this.errors = that.errors; } else { - errors.addAll(er.errors); + this.errors.addAll(that.errors); } } - if (er.warnings!=null) { - if (warnings==null) { - warnings = er.warnings; + if (that.warnings != null) { + if (this.warnings == null) { + this.warnings = that.warnings; } else { - warnings.addAll(er.warnings); - } + this.warnings.addAll(that.warnings); + } } } - public void addErrorAndContinue(SyntaxException error, SourceUnit source) throws CompilationFailedException { + public void addErrorAndContinue(final SyntaxException error, final SourceUnit source) throws CompilationFailedException { addErrorAndContinue(Message.create(error, source)); } - + /** * Adds an error to the message set, but does not cause a failure. The message is not required to have a source - * line and column specified, but it is best practice to try and include that information. + * line and column specified, but it is best practice to try and include that information. */ - public void addErrorAndContinue(Message message) { - if (this.errors == null) { - this.errors = new LinkedList(); + public void addErrorAndContinue(final Message message) { + if (errors == null) { + errors = new LinkedList<>(); } - - this.errors.add(message); + errors.add(message); } - + /** * Adds a non-fatal error to the message set, which may cause a failure if the error threshold is exceeded. * The message is not required to have a source line and column specified, but it is best practice to try * and include that information. */ - public void addError(Message message) throws CompilationFailedException { + public void addError(final Message message) throws CompilationFailedException { addErrorAndContinue(message); - if (errors!=null && this.errors.size() >= configuration.getTolerance()) { + if (errors != null && errors.size() >= configuration.getTolerance()) { failIfErrors(); } } - + /** * Adds an optionally-fatal error to the message set. * The message is not required to have a source line and column specified, but it is best practice to try @@ -115,52 +114,63 @@ public class ErrorCollector implements Serializable { * @param fatal * if true then then processing will stop */ - public void addError(Message message, boolean fatal) throws CompilationFailedException { + public void addError(final Message message, final boolean fatal) throws CompilationFailedException { if (fatal) { addFatalError(message); - } - else { + } else { addError(message); } } - - /** - * Convenience wrapper for addError(). - */ - public void addError(SyntaxException error, SourceUnit source) throws CompilationFailedException { + public void addError(final SyntaxException error, final SourceUnit source) throws CompilationFailedException { addError(Message.create(error, source), error.isFatal()); } + public void addError(final String error, final CSTNode context, final SourceUnit source) throws CompilationFailedException { + addError(new LocatedMessage(error, context, source)); + } - /** - * Convenience wrapper for addError(). - */ - public void addError(String text, CSTNode context, SourceUnit source) throws CompilationFailedException { - addError(new LocatedMessage(text, context, source)); + public void addException(final Exception exception, final SourceUnit source) throws CompilationFailedException { + addError(new ExceptionMessage(exception, configuration.getDebug(), source)); + failIfErrors(); } - - + /** - * Adds a fatal exception to the message set and throws - * the unit as a PhaseFailedException. + * Adds an error to the message set and throws CompilationFailedException. */ - public void addFatalError(Message message) throws CompilationFailedException { + public void addFatalError(final Message message) throws CompilationFailedException { addError(message); failIfErrors(); } + /** + * Adds a warning to the message set. + */ + public void addWarning(final WarningMessage message) { + if (message.isRelevant(configuration.getWarningLevel())) { + if (warnings == null) { + warnings = new LinkedList<>(); + } + warnings.add(message); + } + } - public void addException(Exception cause, SourceUnit source) throws CompilationFailedException { - addError(new ExceptionMessage(cause,configuration.getDebug(),source)); - failIfErrors(); + /** + * Adds a warning to the message set if it is relevant. + */ + public void addWarning(final int importance, final String text, final CSTNode context, final SourceUnit source) { + if (WarningMessage.isRelevant(importance, configuration.getWarningLevel())) { + addWarning(new WarningMessage(importance, text, context, source)); + } } /** - * Returns true if there are any errors pending. + * Adds a warning to the message set if it is relevant. */ - public boolean hasErrors() { - return this.errors != null; + public void addWarning(final int importance, final String text, final Object data, final CSTNode context, final SourceUnit source) { + if (WarningMessage.isRelevant(importance, configuration.getWarningLevel())) { + addWarning(new WarningMessage(importance, text, data, context, source)); + } } /** @@ -171,94 +181,86 @@ public class ErrorCollector implements Serializable { } /** - * Returns true if there are any warnings pending. + * Returns the number of errors. */ - public boolean hasWarnings() { - return this.warnings != null; + public int getErrorCount() { + return (hasErrors() ? errors.size() : 0); } - + /** - * Returns the list of warnings, or null if there are none. + * Returns the specified error message, or null. */ - public List getWarnings() { - return this.warnings; + public Message getError(final int index) { + if (index < getErrorCount()) { + return errors.get(index); + } + return null; } /** * Returns the list of errors, or null if there are none. */ - public List getErrors() { - return this.errors; + public List getErrors() { + return errors; } /** - * Returns the number of warnings. + * Returns true if there are any errors pending. */ - public int getWarningCount() { - return ((this.warnings == null) ? 0 : this.warnings.size()); + public boolean hasErrors() { + return (errors != null); } /** - * Returns the number of errors. + * Returns the number of warnings. */ - public int getErrorCount() { - return ((this.errors == null) ? 0 : this.errors.size()); + public int getWarningCount() { + return (hasWarnings() ? warnings.size() : 0); } /** * Returns the specified warning message, or null. */ - public WarningMessage getWarning(int index) { + public WarningMessage getWarning(final int index) { if (index < getWarningCount()) { - return (WarningMessage) this.warnings.get(index); + return warnings.get(index); } return null; } /** - * Returns the specified error message, or null. + * Returns the list of warnings, or null if there are none. */ - public Message getError(int index) { - if (index < getErrorCount()) { - return (Message) this.errors.get(index); - } - return null; + public List getWarnings() { + return warnings; } /** - * Returns the last error reported + * Returns true if there are any warnings pending. */ - public Message getLastError() { - return (Message) this.errors.getLast(); + public boolean hasWarnings() { + return (warnings != null); } - + + // + /** - * Convenience routine to return the specified error's - * underlying SyntaxException, or null if it isn't one. + * Returns the last error reported. */ - public SyntaxException getSyntaxError(int index) { - SyntaxException exception = null; - - Message message = getError(index); - if (message instanceof SyntaxErrorMessage) { - exception = ((SyntaxErrorMessage) message).getCause(); - } - return exception; + public Message getLastError() { + return errors.getLast(); } /** - * Convenience routine to return the specified error's - * underlying Exception, or null if it isn't one. + * Returns the specified error's underlying Exception, or null if it isn't one. */ - public Exception getException(int index) { + public Exception getException(final int index) { Exception exception = null; - Message message = getError(index); if (message != null) { if (message instanceof ExceptionMessage) { exception = ((ExceptionMessage) message).getCause(); - } - else if (message instanceof SyntaxErrorMessage) { + } else if (message instanceof SyntaxErrorMessage) { exception = ((SyntaxErrorMessage) message).getCause(); } } @@ -266,80 +268,53 @@ public class ErrorCollector implements Serializable { } /** - * Adds a WarningMessage to the message set. - */ - public void addWarning(WarningMessage message) { - if (message.isRelevant(configuration.getWarningLevel())) { - if (this.warnings == null) { - this.warnings = new LinkedList(); - } - - this.warnings.add(message); - } - } - - - /** - * Convenience wrapper for addWarning() that won't create an object - * unless it is relevant. - */ - public void addWarning(int importance, String text, CSTNode context, SourceUnit source) { - if (WarningMessage.isRelevant(importance, configuration.getWarningLevel())) { - addWarning(new WarningMessage(importance, text, context, source)); - } - } - - - /** - * Convenience wrapper for addWarning() that won't create an object - * unless it is relevant. + * Returns the specified error's underlying SyntaxException, or null if it isn't one. */ - public void addWarning(int importance, String text, Object data, CSTNode context, SourceUnit source) { - if (WarningMessage.isRelevant(importance, configuration.getWarningLevel())) { - addWarning(new WarningMessage(importance, text, data, context, source)); + public SyntaxException getSyntaxError(final int index) { + SyntaxException exception = null; + Message message = getError(index); + if (message instanceof SyntaxErrorMessage) { + exception = ((SyntaxErrorMessage) message).getCause(); } + return exception; } - /** - * Causes the current phase to fail by throwing a - * CompilationFailedException. + * Causes the current phase to fail by throwing a CompilationFailedException. */ protected void failIfErrors() throws CompilationFailedException { if (hasErrors()) { throw new MultipleCompilationErrorsException(this); } } - + //--------------------------------------------------------------------------- // OUTPUT + private void write(final PrintWriter writer, final Janitor janitor, final List messages, final String txt) { + if (messages == null || messages.isEmpty()) return; - private void write(PrintWriter writer, Janitor janitor, List messages, String txt) { - if (messages==null || messages.isEmpty()) return; - for (Object o : messages) { - Message message = (Message) o; + for (Message message : messages) { message.write(writer, janitor); - if (configuration.getDebug() && (message instanceof SyntaxErrorMessage)) { - SyntaxErrorMessage sem = (SyntaxErrorMessage) message; - sem.getCause().printStackTrace(writer); + ((SyntaxErrorMessage) message).getCause().printStackTrace(writer); } writer.println(); } writer.print(messages.size()); - writer.print(" "+txt); - if (messages.size()>1) writer.print("s"); + writer.print(" " + txt); + if (messages.size() > 1) { + writer.print("s"); + } writer.println(); } - + /** * Writes error messages to the specified PrintWriter. */ - public void write(PrintWriter writer, Janitor janitor) { - write(writer,janitor,warnings,"warning"); - write(writer,janitor,errors,"error"); + public void write(final PrintWriter writer, final Janitor janitor) { + write(writer, janitor, warnings, "warning"); + write(writer, janitor, errors, "error"); } - }