move members: do not escalate visibility when usages are moved together (IDEA-70796 )

This commit is contained in:
anna
2011-06-21 17:49:48 +04:00
parent 46fcb6d0a8
commit 873c9c562e
8 changed files with 139 additions and 1 deletions

View File

@@ -231,7 +231,13 @@ public class MoveMembersProcessor extends BaseRefactoringProcessor {
if (myNewVisibility == null) return;
VisibilityUtil.fixVisibility(usages, newMember, myNewVisibility);
final List<UsageInfo> filtered = new ArrayList<UsageInfo>();
for (UsageInfo usage : usages) {
if (usage instanceof MoveMembersUsageInfo && ((MoveMembersUsageInfo)usage).member == newMember) {
filtered.add(usage);
}
}
VisibilityUtil.fixVisibility(filtered.toArray(new UsageInfo[filtered.size()]), newMember, myNewVisibility);
}
protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pack1;
public class A {
}

View File

@@ -0,0 +1,23 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pack1;
public class C {
public static void foo() {
bar();
}
private static void bar(){}
}

View File

@@ -0,0 +1,22 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pack2;
import pack1.*;
public class B {
protected B(){
C.foo();
}
}

View File

@@ -0,0 +1,24 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pack1;
public class A {
public static void foo() {
bar();
}
private static void bar(){}
}

View File

@@ -0,0 +1,17 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pack1;
public class C {}

View File

@@ -0,0 +1,22 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pack2;
import pack1.*;
public class B {
protected B(){
A.foo();
}
}

View File

@@ -76,6 +76,10 @@ public class MoveMembersTest extends MultiFileTestCase {
doTest("pack1.A", "pack1.C", 0);
}
public void testUntouchedVisibility() throws Exception {
doTest("pack1.A", "pack1.C", 0, 1);
}
public void testOtherPackageImport() throws Exception {
doTest("pack1.ClassWithStaticMethod", "pack2.OtherClass", 1);
}