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/06/26 17:11:09 UTC
[groovy] 01/01: Minor tweak: ignore abstract methods when running
`doFindClassMember`
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch danielsun/minor-tweak-20200627
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 953bbd52dbefef23024ea1a69c9574721411b4f0
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Jun 27 01:10:34 2020 +0800
Minor tweak: ignore abstract methods when running `doFindClassMember`
---
.../groovy/classgen/VariableScopeVisitor.java | 3 +++
src/test/groovy/PropertyTest.groovy | 26 ++++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java b/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
index 536630a..5fb5678 100644
--- a/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
+++ b/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
@@ -189,6 +189,9 @@ public class VariableScopeVisitor extends ClassCodeVisitorSupport {
}
for (MethodNode mn : cn.getMethods()) {
+ if (mn.isAbstract()) {
+ continue;
+ }
if (name.equals(getPropertyName(mn))) {
PropertyNode property = new PropertyNode(name, mn.getModifiers(), ClassHelper.OBJECT_TYPE, cn, null, null, null);
final FieldNode field = property.getField();
diff --git a/src/test/groovy/PropertyTest.groovy b/src/test/groovy/PropertyTest.groovy
index 39dafd0..010b33c 100644
--- a/src/test/groovy/PropertyTest.groovy
+++ b/src/test/groovy/PropertyTest.groovy
@@ -235,6 +235,31 @@ class PropertyTest extends GroovyTestCase {
'''
}
+ void testPropertyWithOverrideGetterAndSetter() {
+ assertScript '''
+ abstract class Base {
+ abstract String getName()
+ abstract void setName(String name)
+ }
+ class A extends Base {
+ private String name = 'AA'
+
+ @Override
+ String getName() {
+ this.name
+ }
+ @Override
+ void setName(String name) {
+ this.name = name
+ }
+ }
+ Base a = new A()
+ assert 'AA' == a.name
+ a.name = 'BB'
+ assert 'BB' == a.name
+ '''
+ }
+
void testOverrideMultiSetterThroughMetaClass() {
assertScript '''
class A {
@@ -250,6 +275,7 @@ class PropertyTest extends GroovyTestCase {
assert a.field == '100100'
'''
}
+
}
class Base {