From 34110d7b027ae497f03499df56f042d992eb9224 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 23 Sep 2011 21:36:11 +0200 Subject: [PATCH] cleanup --- .../src/com/siyeh/ig/psiutils/FinalUtils.java | 2 +- .../style/ImplicitCallToSuperInspection.java | 14 ++------ .../ig/style/NestedMethodCallInspection.java | 33 ++++++++++--------- ...aitNotInSynchronizedContextInspection.java | 4 +-- 4 files changed, 23 insertions(+), 30 deletions(-) diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/FinalUtils.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/FinalUtils.java index 7089c78c675f..047cc4de256a 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/FinalUtils.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/FinalUtils.java @@ -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; } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/style/ImplicitCallToSuperInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/style/ImplicitCallToSuperInspection.java index 80557649207e..62c84a810bce 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/style/ImplicitCallToSuperInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/style/ImplicitCallToSuperInspection.java @@ -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); } } } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/style/NestedMethodCallInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/style/NestedMethodCallInspection.java index 55773441f9c7..59b671737021 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/style/NestedMethodCallInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/style/NestedMethodCallInspection.java @@ -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 = diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/threading/WaitNotInSynchronizedContextInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/threading/WaitNotInSynchronizedContextInspection.java index 32a3c2c9db2e..bb4c6a862226 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/threading/WaitNotInSynchronizedContextInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/threading/WaitNotInSynchronizedContextInspection.java @@ -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);