Skip to content

Commit

Permalink
minor items
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed May 7, 2024
1 parent f9b4eee commit 2202988
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 20 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ allprojects {
}
}

clean.doFirst {
delete "${rootDir}/build-logic"
}

task(copyTestResources, type: Copy)
.from('src/test')
.into("$buildDir/classes/test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.GenericsType;
import org.codehaus.groovy.ast.GenericsType.GenericsTypeName;
import org.codehaus.groovy.ast.InnerClassNode;
import org.codehaus.groovy.ast.MethodNode;
import org.codehaus.groovy.ast.Parameter;
import org.codehaus.groovy.ast.Variable;
Expand Down Expand Up @@ -2033,24 +2032,22 @@ private static Map<GenericsTypeName, GenericsType> mergeGenerics(Map<GenericsTyp
}

/**
* Filter methods according to visibility
* Filters methods according to visibility.
*
* @param methodNodeList method nodes to filter
* @param enclosingClassNode the enclosing class
* @return filtered method nodes
* @param enclosingClassNode the enclosing type
* @return filtered method nodes (new list)
* @since 3.0.0
*/
public static List<MethodNode> filterMethodsByVisibility(final List<MethodNode> methodNodeList, final ClassNode enclosingClassNode) {
if (!asBoolean(methodNodeList)) {
return StaticTypeCheckingVisitor.EMPTY_METHODNODE_LIST;
return Collections.emptyList();
}

List<MethodNode> result = new LinkedList<>();
List< ClassNode> outers = enclosingClassNode.getOuterClasses();

boolean isEnclosingInnerClass = enclosingClassNode instanceof InnerClassNode;
List<ClassNode> outerClasses = enclosingClassNode.getOuterClasses();

outer:
next_method:
for (MethodNode methodNode : methodNodeList) {
if (methodNode instanceof ExtensionMethodNode) {
result.add(methodNode);
Expand All @@ -2059,23 +2056,23 @@ public static List<MethodNode> filterMethodsByVisibility(final List<MethodNode>

ClassNode declaringClass = methodNode.getDeclaringClass();

if (isEnclosingInnerClass) {
for (ClassNode outerClass : outerClasses) {
if (asBoolean(outers)) {
for (ClassNode outerClass : outers) {
if (outerClass.isDerivedFrom(declaringClass)) {
if (outerClass.equals(declaringClass)) {
result.add(methodNode);
continue outer;
continue next_method;
} else {
if (methodNode.isPublic() || methodNode.isProtected()) {
result.add(methodNode);
continue outer;
continue next_method;
}
}
}
}
}

if (declaringClass instanceof InnerClassNode) {
if (declaringClass.getOuterClass() != null) {
if (declaringClass.getOuterClasses().contains(enclosingClassNode)) {
result.add(methodNode);
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,7 @@ protected boolean existsProperty(final PropertyExpression pexp, final boolean ch
protected boolean existsProperty(final PropertyExpression pexp, final boolean readMode, final ClassCodeVisitorSupport visitor) {
super.visitPropertyExpression(pexp);

String propertyName = pexp.getPropertyAsString();
final String propertyName = pexp.getPropertyAsString();
if (propertyName == null) return false;

Expression objectExpression = pexp.getObjectExpression();
Expand Down Expand Up @@ -1613,7 +1613,7 @@ protected boolean existsProperty(final PropertyExpression pexp, final boolean re

if (field != null && storeField(field, pexp, receiverType, visitor, receiver.getData(), !readMode)) return true;

foundGetterOrSetter = (foundGetterOrSetter || !setters.isEmpty() || getter != null);
foundGetterOrSetter = (foundGetterOrSetter || getter != null || !setters.isEmpty());
}

// GROOVY-5568: the property may be defined by DGM
Expand Down
51 changes: 47 additions & 4 deletions src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,44 @@ class FieldsAndPropertiesSTCTest extends StaticTypeCheckingTestCase {
'No such property: x for class: C'
}

// GROOVY-11319
@NotYetImplemented
void testShouldComplainAboutMissingProperty3() {
shouldFailWithMessages '''
class C {
private int getX() { 1 }
}
class D extends C {
void test() {
super.x
}
}
new D().test()
''',
'No such property: x for class: C'
}

// GROOVY-11319
@NotYetImplemented
void testShouldComplainAboutMissingProperty4() {
shouldFailWithMessages '''
class C {
private void setX(int i) {
assert false : 'cannot access'
}
}
class D extends C {
void test() {
super.x = 1
}
}
new D().test()
''',
'No such property: x for class: C'
}

@NotYetImplemented
void testShouldComplainAboutMissingProperty5() {
shouldFailWithMessages '''
class C {
private x
Expand All @@ -206,8 +242,9 @@ class FieldsAndPropertiesSTCTest extends StaticTypeCheckingTestCase {
this.x
}
}
new D().test()
''',
'Cannot access field: x of class: C'
'No such property: x for class: D'
}

void testShouldComplainAboutMissingAttribute() {
Expand Down Expand Up @@ -624,16 +661,22 @@ class FieldsAndPropertiesSTCTest extends StaticTypeCheckingTestCase {
'''
}

// GROOVY-5988
void testMapPropertyAccess3() {
assertScript '''
String key = 'foo'
Map map = [(key): 123]
String key = 'name'
Map<String, Integer> map = [:]
map[key] = 123
@ASTTest(phase=INSTRUCTION_SELECTION, value={
assert node.getNodeMetaData(INFERRED_TYPE) == Integer_TYPE
})
def val = map[key]
assert val == 123
'''
assertScript '''
def names = [:].getProperties().keySet()
assert names.toSorted() == ['class', 'empty'] // TODO: remove?
'''
}

// GROOVY-5797
Expand Down Expand Up @@ -777,7 +820,7 @@ class FieldsAndPropertiesSTCTest extends StaticTypeCheckingTestCase {
assert map.metaClass == null
'''
assertScript type + '''
def test(C map) {
def test(C map) { // no diff
assert map.entry == null
assert map.empty == null
assert map.class == null
Expand Down

0 comments on commit 2202988

Please sign in to comment.