diff options
Diffstat (limited to 'plugins/InspectionGadgets/src/com/siyeh/ig')
4 files changed, 170 insertions, 29 deletions
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/ClassWithOnlyPrivateConstructorsInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/ClassWithOnlyPrivateConstructorsInspection.java new file mode 100644 index 000000000000..3aeebcd724e8 --- /dev/null +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/ClassWithOnlyPrivateConstructorsInspection.java @@ -0,0 +1,33 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.siyeh.ig.classlayout; + +import com.intellij.psi.PsiClass; +import com.siyeh.ig.InspectionGadgetsFix; +import com.siyeh.ig.fixes.MakeClassFinalFix; +import org.jetbrains.annotations.Nullable; + +/** + * @author Bas Leijdekkers + */ +public class ClassWithOnlyPrivateConstructorsInspection extends ClassWithOnlyPrivateConstructorsInspectionBase { + + @Nullable + @Override + protected InspectionGadgetsFix buildFix(Object... infos) { + return new MakeClassFinalFix((PsiClass)infos[0]); + } +} diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/InlineCallFix.java b/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/InlineCallFix.java index 43e57741bbe3..b9503e220c68 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/InlineCallFix.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/InlineCallFix.java @@ -16,52 +16,54 @@ package com.siyeh.ig.fixes; import com.intellij.codeInspection.ProblemDescriptor; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiMethod; import com.intellij.psi.PsiMethodCallExpression; import com.intellij.psi.PsiReferenceExpression; -import com.intellij.refactoring.JavaRefactoringActionHandlerFactory; -import com.intellij.refactoring.RefactoringActionHandler; +import com.intellij.refactoring.JavaRefactoringSettings; +import com.intellij.refactoring.inline.InlineMethodProcessor; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.InspectionGadgetsFix; import org.jetbrains.annotations.NotNull; public class InlineCallFix extends InspectionGadgetsFix { - @Override - @NotNull - public String getFamilyName() { - return getName(); - } + private String myName; + + public InlineCallFix(String name) { + myName = name; + } + + public InlineCallFix() { + this(InspectionGadgetsBundle.message("inline.call.quickfix")); + } + + @Override + @NotNull + public String getFamilyName() { + return myName; + } @Override @NotNull public String getName() { - return InspectionGadgetsBundle.message("inline.call.quickfix"); + return getFamilyName(); } @Override public void doFix(final Project project, ProblemDescriptor descriptor) { final PsiElement nameElement = descriptor.getPsiElement(); - final PsiReferenceExpression methodExpression = - (PsiReferenceExpression)nameElement.getParent(); - assert methodExpression != null; - final PsiMethodCallExpression methodCallExpression = - (PsiMethodCallExpression)methodExpression.getParent(); - final JavaRefactoringActionHandlerFactory factory = - JavaRefactoringActionHandlerFactory.getInstance(); - final RefactoringActionHandler inlineHandler = factory.createInlineHandler(); - final Runnable runnable = new Runnable() { - @Override - public void run() { - inlineHandler.invoke(project, new PsiElement[]{methodCallExpression}, null); - } - }; - if (ApplicationManager.getApplication().isUnitTestMode()) { - runnable.run(); - } - else { - ApplicationManager.getApplication().invokeLater(runnable, project.getDisposed()); - } + final PsiReferenceExpression methodExpression = (PsiReferenceExpression)nameElement.getParent(); + if (methodExpression == null) return; + final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)methodExpression.getParent(); + final PsiMethod method = methodCallExpression.resolveMethod(); + if (method == null) return; + inline(project, methodExpression, method); + } + + protected void inline(Project project, PsiReferenceExpression methodExpression, PsiMethod method) { + new InlineMethodProcessor(project, method, methodExpression, null, true, + JavaRefactoringSettings.getInstance().RENAME_SEARCH_IN_COMMENTS_FOR_METHOD, + JavaRefactoringSettings.getInstance().RENAME_SEARCH_FOR_TEXT_FOR_METHOD).inlineMethodCall(methodExpression); } } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/CallToSimpleGetterInClassInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/CallToSimpleGetterInClassInspection.java new file mode 100644 index 000000000000..c550093cef63 --- /dev/null +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/CallToSimpleGetterInClassInspection.java @@ -0,0 +1,63 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.siyeh.ig.performance; + +import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiExpressionStatement; +import com.intellij.psi.PsiMethod; +import com.intellij.psi.PsiReferenceExpression; +import com.siyeh.InspectionGadgetsBundle; +import com.siyeh.ig.InspectionGadgetsFix; +import com.siyeh.ig.fixes.InlineCallFix; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; + +public class CallToSimpleGetterInClassInspection extends CallToSimpleGetterInClassInspectionBase { + @Override + @Nullable + public JComponent createOptionsPanel() { + final MultipleCheckboxOptionsPanel optionsPanel = new MultipleCheckboxOptionsPanel(this); + optionsPanel.addCheckbox(InspectionGadgetsBundle.message("call.to.simple.getter.in.class.ignore.option"), + "ignoreGetterCallsOnOtherObjects"); + optionsPanel.addCheckbox(InspectionGadgetsBundle.message("call.to.private.simple.getter.in.class.option"), + "onlyReportPrivateGetter"); + return optionsPanel; + } + + @Override + public InspectionGadgetsFix buildFix(Object... infos) { + return new InlineOrDeleteCallFix(InspectionGadgetsBundle.message("call.to.simple.getter.in.class.inline.quickfix")); + } + + private static class InlineOrDeleteCallFix extends InlineCallFix { + public InlineOrDeleteCallFix(String name) { + super(name); + } + + @Override + protected void inline(Project project, PsiReferenceExpression methodExpression, PsiMethod method) { + final PsiElement statement = methodExpression.getParent().getParent(); + if (statement instanceof PsiExpressionStatement) { + statement.delete(); + } else { + super.inline(project, methodExpression, method); + } + } + } +}
\ No newline at end of file diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/CallToSimpleSetterInClassInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/CallToSimpleSetterInClassInspection.java new file mode 100644 index 000000000000..652a8e89ea98 --- /dev/null +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/CallToSimpleSetterInClassInspection.java @@ -0,0 +1,43 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.siyeh.ig.performance; + +import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel; +import com.siyeh.InspectionGadgetsBundle; +import com.siyeh.ig.InspectionGadgetsFix; +import com.siyeh.ig.fixes.InlineCallFix; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; + +public class CallToSimpleSetterInClassInspection extends CallToSimpleSetterInClassInspectionBase { + + @Override + @Nullable + public JComponent createOptionsPanel() { + final MultipleCheckboxOptionsPanel optionsPanel = new MultipleCheckboxOptionsPanel(this); + optionsPanel.addCheckbox(InspectionGadgetsBundle.message("call.to.simple.setter.in.class.ignore.option"), + "ignoreSetterCallsOnOtherObjects"); + optionsPanel.addCheckbox(InspectionGadgetsBundle.message("call.to.private.setter.in.class.option"), + "onlyReportPrivateSetter"); + return optionsPanel; + } + + @Override + public InspectionGadgetsFix buildFix(Object... infos) { + return new InlineCallFix(InspectionGadgetsBundle.message("call.to.simple.setter.in.class.inline.quickfix")); + } +}
\ No newline at end of file |