Skip to content

Commit

Permalink
Fix for #1454: this not owner qualifier for super class property
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Feb 14, 2023
1 parent 984dc4f commit db6bc79
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2022 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -59,6 +59,13 @@ final class ConvertToPropertyActionTests extends GroovyEditorTestSuite {
assertEditorContents '[].empty;'
}

@Test
void testIsserToProperty2() {
addGroovySource 'class Foo { static void isSomething() {} }', 'Foo'
convertToProperty "Foo.isSome${CARET}thing()"
assertEditorContents 'Foo.something'
}

@Test
void testSetterToProperty1() {
convertToProperty "new Date().set${CARET}Time(1234L);"
Expand Down Expand Up @@ -163,13 +170,6 @@ final class ConvertToPropertyActionTests extends GroovyEditorTestSuite {
assertEditorContents pogo + stc('def x=1\nnew C().with { delegate.x }')
}

@Test
void testImplicitIsserToProperty() {
addGroovySource 'class Foo { static void isSomething() {} }', 'Foo'
convertToProperty "Foo.isSome${CARET}thing()"
assertEditorContents 'Foo.something'
}

@Test
void testImplicitSetterToProperty() {
convertToProperty "new Date().with { set${CARET}Time(1234L) }"
Expand All @@ -196,6 +196,14 @@ final class ConvertToPropertyActionTests extends GroovyEditorTestSuite {
assertEditorContents pogo + stc('def x=1\nnew C().with { delegate.x = 0 }')
}

@Test // https://github.com/groovy/groovy-eclipse/issues/1454
void testImplicitSetterToProperty4() {
addGroovySource 'abstract class A { protected void setX(x){} }', 'A'
def pogo = { "class C extends A { C(x) { $it } }" }
convertToProperty pogo("set${CARET}X(x)")
assertEditorContents pogo( 'this.x = x' )
}

@Test
void testStaticGetterToProperty() {
convertToProperty "import java.lang.management.*; ManagementFactory.getRun${CARET}timeMXBean()"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2022 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -182,7 +182,7 @@ private static boolean isTypeChange(final TextEdit edit, final ASTNode node, fin
unit.applyTextEdit(undo, null);

if (!before.declaringType.equals(after.declaringType)) {
if (!before.declaringType.equals(before.scope.getThis())) {
if (!before.scope.getThis().isDerivedFrom(before.declaringType)) { // "this" or "super"
ASTNode call = (node instanceof MethodCall ? node : before.scope.getEnclosingNode()); // TODO: refactor side-effect solution!
call.getNodeMetaData(IMPLICIT_RECEIVER, x -> before.declaringType.equals(before.scope.getDelegate()) ? "delegate" : "owner");
}
Expand Down

0 comments on commit db6bc79

Please sign in to comment.