mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
create from usage: do not suggest to create static methods in interfaces (IDEA-98147)
This commit is contained in:
+1
-1
@@ -83,7 +83,7 @@ public class CreateFieldFromUsageFix extends CreateVarFromUsageFix {
|
||||
|
||||
setupVisibility(parentClass, targetClass, field.getModifierList());
|
||||
|
||||
if (shouldCreateStaticMember(myReferenceExpression, targetClass)) {
|
||||
if (!targetClass.isInterface() && shouldCreateStaticMember(myReferenceExpression, targetClass)) {
|
||||
PsiUtil.setModifierProperty(field, PsiModifier.STATIC, true);
|
||||
}
|
||||
|
||||
|
||||
+1
-4
@@ -179,10 +179,7 @@ public abstract class CreateFromUsageBaseFix extends BaseIntentionAction {
|
||||
}
|
||||
|
||||
protected static boolean shouldCreateStaticMember(PsiReferenceExpression ref, PsiClass targetClass) {
|
||||
if (targetClass.isInterface()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
PsiExpression qualifierExpression = ref.getQualifierExpression();
|
||||
while (qualifierExpression instanceof PsiParenthesizedExpression) {
|
||||
qualifierExpression = ((PsiParenthesizedExpression) qualifierExpression).getExpression();
|
||||
|
||||
+2
-1
@@ -120,6 +120,7 @@ public class CreateMethodFromUsageFix extends CreateFromUsageBaseFix {
|
||||
PsiMethodCallExpression call = getMethodCall();
|
||||
if (call == null) return Collections.emptyList();
|
||||
for (PsiClass target : targets) {
|
||||
if (target.isInterface() && shouldCreateStaticMember(call.getMethodExpression(), target)) continue;
|
||||
if (!isMethodSignatureExists(call, target)) {
|
||||
result.add(target);
|
||||
}
|
||||
@@ -186,7 +187,7 @@ public class CreateMethodFromUsageFix extends CreateFromUsageBaseFix {
|
||||
expression = getMethodCall();
|
||||
LOG.assertTrue(expression.isValid());
|
||||
|
||||
if (shouldCreateStaticMember(expression.getMethodExpression(), targetClass) && !shouldBeAbstract(targetClass)) {
|
||||
if (!targetClass.isInterface() && shouldCreateStaticMember(expression.getMethodExpression(), targetClass) && !shouldBeAbstract(targetClass)) {
|
||||
PsiUtil.setModifierProperty(method, PsiModifier.STATIC, true);
|
||||
}
|
||||
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Create Method 'f'" "true"
|
||||
interface I {}
|
||||
class A implements I {
|
||||
{
|
||||
A.f();
|
||||
}
|
||||
|
||||
private static void f() {
|
||||
<selection>//To change body of created methods use File | Settings | File Templates.</selection>
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Create Method 'f'" "true"
|
||||
interface I {}
|
||||
class A implements I {
|
||||
{
|
||||
A.<caret>f();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user