You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/04/11 09:48:35 UTC

[groovy] branch danielsun/remove-dup-codes created (now cdf7c9f)

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a change to branch danielsun/remove-dup-codes
in repository https://gitbox.apache.org/repos/asf/groovy.git.


      at cdf7c9f  Eliminate duplicated code in `BindableASTTransformation`

This branch includes the following new commits:

     new cdf7c9f  Eliminate duplicated code in `BindableASTTransformation`

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[groovy] 01/01: Eliminate duplicated code in `BindableASTTransformation`

Posted by su...@apache.org.
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 <su...@apache.org>
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));
     }