This commit is contained in:
Bas Leijdekkers
2011-09-23 21:36:11 +02:00
parent 5db5bdc4fd
commit 34110d7b02
4 changed files with 23 additions and 30 deletions
@@ -569,7 +569,7 @@ public class FinalUtils {
}
@NonNls final String referenceName =
methodExpression.getReferenceName();
if ("this".equals(referenceName)) {
if (PsiKeyword.THIS.equals(referenceName)) {
definitelyUnassigned = false;
definitelyAssigned = true;
}
@@ -25,9 +25,10 @@ import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
import com.siyeh.ig.psiutils.ExpressionUtils;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.JComponent;
public class ImplicitCallToSuperInspection extends BaseInspection {
@@ -145,16 +146,7 @@ public class ImplicitCallToSuperInspection extends BaseInspection {
(PsiExpressionStatement)statement;
final PsiExpression expression =
expressionStatement.getExpression();
if (!(expression instanceof PsiMethodCallExpression)) {
return false;
}
final PsiMethodCallExpression methodCall =
(PsiMethodCallExpression)expression;
final PsiReferenceExpression methodExpression =
methodCall.getMethodExpression();
final String text = methodExpression.getText();
return PsiKeyword.SUPER.equals(text) ||
PsiKeyword.THIS.equals(text);
return ExpressionUtils.isConstructorInvocation(expression);
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,27 +29,31 @@ import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
import com.siyeh.ig.psiutils.ExpressionUtils;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.JComponent;
public class NestedMethodCallInspection extends BaseInspection {
/** @noinspection PublicField */
public boolean m_ignoreFieldInitializations = true;
@Override
@NotNull
public String getDisplayName() {
return InspectionGadgetsBundle.message(
"nested.method.call.display.name");
}
@Override
@NotNull
protected String buildErrorString(Object... infos) {
return InspectionGadgetsBundle.message(
"nested.method.call.problem.descriptor");
}
@Override
public JComponent createOptionsPanel() {
return new SingleCheckboxOptionsPanel(
InspectionGadgetsBundle.message(
@@ -57,26 +61,31 @@ public class NestedMethodCallInspection extends BaseInspection {
this, "m_ignoreFieldInitializations");
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new NestedMethodCallVisitor();
}
@Override
protected InspectionGadgetsFix buildFix(Object... infos) {
return new NestedMethodCallFix();
}
@Override
protected boolean buildQuickFixesOnlyForOnTheFlyErrors() {
return true;
}
private static class NestedMethodCallFix extends InspectionGadgetsFix {
@Override
@NotNull
public String getName() {
return InspectionGadgetsBundle.message(
"introduce.variable.quickfix");
}
@Override
public void doFix(final Project project, ProblemDescriptor descriptor) {
final JavaRefactoringActionHandlerFactory factory =
JavaRefactoringActionHandlerFactory.getInstance();
@@ -101,7 +110,8 @@ public class NestedMethodCallInspection extends BaseInspection {
runnable.run();
}
else {
ApplicationManager.getApplication().invokeLater(runnable, project.getDisposed());
ApplicationManager.getApplication().invokeLater(runnable,
project.getDisposed());
}
}
}
@@ -127,19 +137,10 @@ public class NestedMethodCallInspection extends BaseInspection {
if (!(grandParent instanceof PsiCallExpression)) {
return;
}
if (grandParent instanceof PsiMethodCallExpression) {
final PsiMethodCallExpression surroundingCall =
(PsiMethodCallExpression)grandParent;
final PsiReferenceExpression methodExpression =
surroundingCall.getMethodExpression();
final String callName = methodExpression.getReferenceName();
if (PsiKeyword.THIS.equals(callName) ||
PsiKeyword.SUPER.equals(callName)) {
//ignore nested method calls at the start of a constructor,
//where they can't be extracted
return;
}
if (ExpressionUtils.isConstructorInvocation(grandParent)) {
//ignore nested method calls at the start of a constructor,
//where they can't be extracted
return;
}
if (m_ignoreFieldInitializations) {
final PsiElement field =
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,7 +49,7 @@ public class WaitNotInSynchronizedContextInspection
final PsiElement element = (PsiElement)infos[0];
text = element.getText();
} else {
text = "this";
text = PsiKeyword.THIS;
}
return InspectionGadgetsBundle.message(
"wait.not.in.synchronized.context.problem.descriptor", text);