create from usage: do not suggest to create static methods in interfaces (IDEA-98147)

This commit is contained in:
anna
2012-12-28 15:32:08 +01:00
parent e8d6602585
commit 299e587bc4
5 changed files with 22 additions and 6 deletions
@@ -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);
}
@@ -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();
@@ -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);
}
@@ -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>
}
}
@@ -0,0 +1,7 @@
// "Create Method 'f'" "true"
interface I {}
class A implements I {
{
A.<caret>f();
}
}