mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
anonymous->inner: do not generate public static class inside interface
This commit is contained in:
@@ -44,7 +44,7 @@ class AnonymousToInnerDialog extends DialogWrapper{
|
||||
|
||||
private final Project myProject;
|
||||
private final PsiAnonymousClass myAnonClass;
|
||||
private final boolean myNeedsThis;
|
||||
private final boolean myShowCanBeStatic;
|
||||
|
||||
private NameSuggestionsField myNameField;
|
||||
private final ParameterTablePanel.VariableData[] myVariableData;
|
||||
@@ -52,11 +52,11 @@ class AnonymousToInnerDialog extends DialogWrapper{
|
||||
private JCheckBox myCbMakeStatic;
|
||||
|
||||
public AnonymousToInnerDialog(Project project, PsiAnonymousClass anonClass, final VariableInfo[] variableInfos,
|
||||
boolean needsThis) {
|
||||
boolean showCanBeStatic) {
|
||||
super(project, true);
|
||||
myProject = project;
|
||||
myAnonClass = anonClass;
|
||||
myNeedsThis = needsThis;
|
||||
myShowCanBeStatic = showCanBeStatic;
|
||||
|
||||
setTitle(AnonymousToInnerHandler.REFACTORING_NAME);
|
||||
|
||||
@@ -108,12 +108,7 @@ class AnonymousToInnerDialog extends DialogWrapper{
|
||||
}
|
||||
|
||||
public boolean isMakeStatic() {
|
||||
if(myNeedsThis) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return myCbMakeStatic.isSelected();
|
||||
}
|
||||
return myCbMakeStatic.isSelected();
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
@@ -203,7 +198,7 @@ class AnonymousToInnerDialog extends DialogWrapper{
|
||||
gbConstraints.gridy = 0;
|
||||
panel.add(myNameField, gbConstraints);
|
||||
|
||||
if(!myNeedsThis) {
|
||||
if(!myShowCanBeStatic) {
|
||||
myCbMakeStatic = new NonFocusableCheckBox();
|
||||
myCbMakeStatic.setText(RefactoringBundle.message("anonymousToInner.make.class.static.checkbox.text"));
|
||||
//myCbMakeStatic.setDisplayedMnemonicIndex(11);
|
||||
|
||||
@@ -133,19 +133,20 @@ public class AnonymousToInnerHandler implements RefactoringActionHandler {
|
||||
}
|
||||
|
||||
protected boolean showRefactoringDialog() {
|
||||
final boolean anInterface = myTargetClass.isInterface();
|
||||
final boolean needsThis = needsThis() || PsiUtil.isInnerClass(myTargetClass);
|
||||
final AnonymousToInnerDialog dialog = new AnonymousToInnerDialog(
|
||||
myProject,
|
||||
myAnonClass,
|
||||
myVariableInfos,
|
||||
needsThis);
|
||||
needsThis || anInterface);
|
||||
dialog.show();
|
||||
if (!dialog.isOK()) {
|
||||
return false;
|
||||
}
|
||||
myNewClassName = dialog.getClassName();
|
||||
myVariableInfos = dialog.getVariableInfos();
|
||||
myMakeStatic = dialog.isMakeStatic();
|
||||
myMakeStatic = !needsThis && (anInterface || dialog.isMakeStatic());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -305,10 +306,12 @@ public class AnonymousToInnerHandler implements RefactoringActionHandler {
|
||||
|
||||
if (!myTargetClass.isInterface()) {
|
||||
PsiUtil.setModifierProperty(aClass, PsiModifier.PRIVATE, true);
|
||||
}
|
||||
PsiModifierListOwner owner = PsiTreeUtil.getParentOfType(myAnonClass, PsiModifierListOwner.class);
|
||||
if (owner != null && owner.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
PsiUtil.setModifierProperty(aClass, PsiModifier.STATIC, true);
|
||||
PsiModifierListOwner owner = PsiTreeUtil.getParentOfType(myAnonClass, PsiModifierListOwner.class);
|
||||
if (owner != null && owner.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
PsiUtil.setModifierProperty(aClass, PsiModifier.STATIC, true);
|
||||
}
|
||||
} else {
|
||||
PsiUtil.setModifierProperty(aClass, PsiModifier.PACKAGE_LOCAL, true);
|
||||
}
|
||||
PsiJavaCodeReferenceElement baseClassRef = myAnonClass.getBaseClassReference();
|
||||
PsiClass baseClass = (PsiClass)baseClassRef.resolve();
|
||||
@@ -352,7 +355,7 @@ public class AnonymousToInnerHandler implements RefactoringActionHandler {
|
||||
aClass.add(constructor);
|
||||
}
|
||||
|
||||
if (!needsThis() && myMakeStatic) {
|
||||
if (!needsThis() && myMakeStatic && !myTargetClass.isInterface()) {
|
||||
PsiUtil.setModifierProperty(aClass, PsiModifier.STATIC, true);
|
||||
}
|
||||
PsiElement lastChild = aClass.getLastChild();
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
interface M {
|
||||
Runnable r = new Runnable() {<caret>
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
interface M {
|
||||
Runnable r = new MyRunnable();
|
||||
|
||||
class MyRunnable implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,10 @@ public class AnonymousToInnerTest extends LightCodeInsightTestCase {
|
||||
doTest("MyIterator", true);
|
||||
}
|
||||
|
||||
public void testInsideInterface() throws Exception { // IDEADEV-29446
|
||||
doTest("MyRunnable", true);
|
||||
}
|
||||
|
||||
private void doTest(final String newClassName, final boolean makeStatic) throws Exception {
|
||||
configureByFile(TEST_ROOT + getTestName(true) + ".java");
|
||||
AnonymousToInnerHandler handler = new AnonymousToInnerHandler() {
|
||||
|
||||
Reference in New Issue
Block a user