This is an automated email from the ASF dual-hosted git repository. sunlan pushed a commit to branch danielsun/remove-dup-codes in repository https://gitbox.apache.org/repos/asf/groovy.git
commit cdf7c9f6e8470d8f4d600c204f39405bbdd7ef3d Author: Daniel Sun <[email protected]> AuthorDate: Sat Apr 11 17:48:19 2020 +0800 Eliminate duplicated code in `BindableASTTransformation` --- .../java/groovy/beans/BindableASTTransformation.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/java/groovy/beans/BindableASTTransformation.java b/src/main/java/groovy/beans/BindableASTTransformation.java index 60474f9..026cd11 100644 --- a/src/main/java/groovy/beans/BindableASTTransformation.java +++ b/src/main/java/groovy/beans/BindableASTTransformation.java @@ -115,10 +115,7 @@ public class BindableASTTransformation implements ASTTransformation, Opcodes { ClassNode declaringClass = parent.getDeclaringClass(); if (parent instanceof FieldNode) { if ((((FieldNode) parent).getModifiers() & Opcodes.ACC_FINAL) != 0) { - source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage( - new SyntaxException("@groovy.beans.Bindable cannot annotate a final property.", - node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), - source)); + addErrorAndContinue(source, node, "@groovy.beans.Bindable cannot annotate a final property."); } if (VetoableASTTransformation.hasVetoableAnnotation(parent.getDeclaringClass())) { @@ -137,10 +134,7 @@ public class BindableASTTransformation implements ASTTransformation, Opcodes { if (propertyNode.getName().equals(fieldName)) { if (field.isStatic()) { //noinspection ThrowableInstanceNeverThrown - source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage( - new SyntaxException("@groovy.beans.Bindable cannot annotate a static property.", - node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), - source)); + addErrorAndContinue(source, node, "@groovy.beans.Bindable cannot annotate a static property."); } else { if (needsPropertyChangeSupport(declaringClass, source)) { addPropertyChangeSupport(declaringClass); @@ -151,8 +145,12 @@ public class BindableASTTransformation implements ASTTransformation, Opcodes { } } //noinspection ThrowableInstanceNeverThrown + addErrorAndContinue(source, node, "@groovy.beans.Bindable must be on a property, not a field. Try removing the private, protected, or public modifier."); + } + + private void addErrorAndContinue(SourceUnit source, AnnotationNode node, String s) { source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage( - new SyntaxException("@groovy.beans.Bindable must be on a property, not a field. Try removing the private, protected, or public modifier.", + new SyntaxException(s, node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), source)); }
