mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 19:02:13 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -352,7 +352,7 @@ string.concatenation.ignore.system.err.option=Ignore for 'System.err.print' argu
|
||||
string.concatenation.ignore.assert.option=Ignore for assert statement arguments
|
||||
string.concatenation.ignore.exceptions.option=Ignore for throwable arguments
|
||||
string.concatenation.ignore.constant.initializers.option=Ignore for initializers of constants
|
||||
string.concatenation.ignore.in.test.code=Ignore in test code
|
||||
ignore.in.test.code=Ignore in test code
|
||||
string.equalsignorecase.call.display.name=Call to 'String.equalsIgnoreCase()'
|
||||
string.equalsignorecase.call.problem.descriptor=<code>String.#ref()</code> using internationalized strings #loc
|
||||
string.equals.call.display.name=Call to 'String.equals()'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2012 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.
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package com.siyeh.ig.abstraction;
|
||||
|
||||
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
|
||||
import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
@@ -26,16 +26,19 @@ import com.siyeh.ig.fixes.IntroduceConstantFix;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import com.siyeh.ig.psiutils.MethodUtils;
|
||||
import com.siyeh.ig.psiutils.TestUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.*;
|
||||
|
||||
public class MagicNumberInspection extends BaseInspection {
|
||||
|
||||
/**
|
||||
* @noinspection PublicField
|
||||
*/
|
||||
public boolean m_ignoreInHashCode = true;
|
||||
public boolean ignoreInHashCode = true;
|
||||
|
||||
public boolean ignoreInTestCode = false;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
@@ -46,16 +49,15 @@ public class MagicNumberInspection extends BaseInspection {
|
||||
@Override
|
||||
@NotNull
|
||||
public String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"magic.number.problem.descriptor");
|
||||
return InspectionGadgetsBundle.message("magic.number.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
return new SingleCheckboxOptionsPanel(
|
||||
InspectionGadgetsBundle.message(
|
||||
"magic.number.ignore.option"),
|
||||
this, "m_ignoreInHashCode");
|
||||
final MultipleCheckboxOptionsPanel panel = new MultipleCheckboxOptionsPanel(this);
|
||||
panel.addCheckbox(InspectionGadgetsBundle.message("magic.number.ignore.option"), "ignoreInHashCode");
|
||||
panel.addCheckbox(InspectionGadgetsBundle.message("ignore.in.test.code"), "ignoreInTestCode");
|
||||
return panel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,8 +78,7 @@ public class MagicNumberInspection extends BaseInspection {
|
||||
private class MagicNumberVisitor extends BaseInspectionVisitor {
|
||||
|
||||
@Override
|
||||
public void visitLiteralExpression(
|
||||
@NotNull PsiLiteralExpression expression) {
|
||||
public void visitLiteralExpression(@NotNull PsiLiteralExpression expression) {
|
||||
super.visitLiteralExpression(expression);
|
||||
final PsiType type = expression.getType();
|
||||
if (!ClassUtils.isPrimitiveNumericType(type)) {
|
||||
@@ -92,14 +93,15 @@ public class MagicNumberInspection extends BaseInspection {
|
||||
if (ExpressionUtils.isDeclaredConstant(expression)) {
|
||||
return;
|
||||
}
|
||||
if (m_ignoreInHashCode) {
|
||||
final PsiMethod containingMethod =
|
||||
PsiTreeUtil.getParentOfType(expression,
|
||||
PsiMethod.class);
|
||||
if (ignoreInHashCode) {
|
||||
final PsiMethod containingMethod = PsiTreeUtil.getParentOfType(expression, PsiMethod.class);
|
||||
if (MethodUtils.isHashCode(containingMethod)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (ignoreInTestCode && TestUtils.isInTestCode(expression)) {
|
||||
return;
|
||||
}
|
||||
final PsiElement parent = expression.getParent();
|
||||
if (parent instanceof PsiPrefixExpression) {
|
||||
registerError(parent);
|
||||
@@ -110,8 +112,7 @@ public class MagicNumberInspection extends BaseInspection {
|
||||
}
|
||||
|
||||
private boolean isSpecialCaseLiteral(PsiLiteralExpression expression) {
|
||||
final Object object =
|
||||
ExpressionUtils.computeConstantExpression(expression);
|
||||
final Object object = ExpressionUtils.computeConstantExpression(expression);
|
||||
if (object instanceof Integer) {
|
||||
final int i = ((Integer)object).intValue();
|
||||
return i >= 0 && i <= 10 || i == 100 || i == 1000;
|
||||
|
||||
+5
-17
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2012 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.
|
||||
@@ -15,12 +15,10 @@
|
||||
*/
|
||||
package com.siyeh.ig.errorhandling;
|
||||
|
||||
import com.intellij.codeInsight.TestFrameworks;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
@@ -128,25 +126,15 @@ public class EmptyCatchBlockInspection extends BaseInspection {
|
||||
private class EmptyCatchBlockVisitor extends BaseInspectionVisitor {
|
||||
|
||||
@Override
|
||||
public void visitTryStatement(
|
||||
@NotNull PsiTryStatement statement) {
|
||||
public void visitTryStatement(@NotNull PsiTryStatement statement) {
|
||||
super.visitTryStatement(statement);
|
||||
if (JspPsiUtil.isInJspFile(statement.getContainingFile())) {
|
||||
return;
|
||||
}
|
||||
if (m_ignoreTestCases) {
|
||||
if (TestUtils.isPartOfJUnitTestMethod(statement)) {
|
||||
return;
|
||||
}
|
||||
final PsiClass containingClass =
|
||||
PsiTreeUtil.getParentOfType(statement, PsiClass.class);
|
||||
if (containingClass != null &&
|
||||
TestFrameworks.getInstance().isTestClass(containingClass)) {
|
||||
return;
|
||||
}
|
||||
if (m_ignoreTestCases && TestUtils.isInTestCode(statement)) {
|
||||
return;
|
||||
}
|
||||
final PsiCatchSection[] catchSections =
|
||||
statement.getCatchSections();
|
||||
final PsiCatchSection[] catchSections = statement.getCatchSections();
|
||||
for (final PsiCatchSection section : catchSections) {
|
||||
checkCatchSection(section);
|
||||
}
|
||||
|
||||
+56
-63
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2012 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.
|
||||
@@ -16,7 +16,7 @@
|
||||
package com.siyeh.ig.errorhandling;
|
||||
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
|
||||
import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ScrollType;
|
||||
@@ -31,6 +31,7 @@ import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.psiutils.ExceptionUtils;
|
||||
import com.siyeh.ig.psiutils.TestUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -41,6 +42,9 @@ public class TooBroadCatchInspection extends BaseInspection {
|
||||
@SuppressWarnings({"PublicField"})
|
||||
public boolean onlyWarnOnRootExceptions = false;
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public boolean ignoreInTestCode = false;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getID() {
|
||||
@@ -91,12 +95,14 @@ public class TooBroadCatchInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
return new SingleCheckboxOptionsPanel(
|
||||
InspectionGadgetsBundle.message("too.broad.catch.option"),
|
||||
this, "onlyWarnOnRootExceptions");
|
||||
final MultipleCheckboxOptionsPanel panel = new MultipleCheckboxOptionsPanel(this);
|
||||
panel.addCheckbox(InspectionGadgetsBundle.message("too.broad.catch.option"), "onlyWarnOnRootExceptions");
|
||||
panel.addCheckbox(InspectionGadgetsBundle.message("ignore.in.test.code"), "ignoreInTestCode");
|
||||
return panel;
|
||||
}
|
||||
|
||||
private static class AddCatchSectionFix extends InspectionGadgetsFix {
|
||||
|
||||
private final SmartPsiElementPointer<PsiClass> myThrown;
|
||||
private final String myText;
|
||||
|
||||
@@ -105,57 +111,54 @@ public class TooBroadCatchInspection extends BaseInspection {
|
||||
myText = thrown.getName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return InspectionGadgetsBundle.message("too.broad.catch.quickfix", myText);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doFix(Project project, ProblemDescriptor descriptor)
|
||||
throws IncorrectOperationException {
|
||||
PsiElement typeElement = descriptor.getPsiElement();
|
||||
if (typeElement == null) return;
|
||||
PsiElement catchParameter = typeElement.getParent();
|
||||
if (!(catchParameter instanceof PsiParameter)) return;
|
||||
PsiElement catchBlock = ((PsiParameter)catchParameter).getDeclarationScope();
|
||||
if (!(catchBlock instanceof PsiCatchSection)) return;
|
||||
protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
|
||||
final PsiElement typeElement = descriptor.getPsiElement();
|
||||
if (typeElement == null) {
|
||||
return;
|
||||
}
|
||||
final PsiElement catchParameter = typeElement.getParent();
|
||||
if (!(catchParameter instanceof PsiParameter)) {
|
||||
return;
|
||||
}
|
||||
final PsiElement catchBlock = ((PsiParameter)catchParameter).getDeclarationScope();
|
||||
if (!(catchBlock instanceof PsiCatchSection)) {
|
||||
return;
|
||||
}
|
||||
final PsiCatchSection myBeforeCatchSection = (PsiCatchSection)catchBlock;
|
||||
final PsiTryStatement myTryStatement = myBeforeCatchSection.getTryStatement();
|
||||
final JavaCodeStyleManager codeStyleManager =
|
||||
JavaCodeStyleManager.getInstance(project);
|
||||
final String name = codeStyleManager.suggestUniqueVariableName("e",
|
||||
myTryStatement.getTryBlock(), false);
|
||||
final PsiElementFactory factory =
|
||||
JavaPsiFacade.getInstance(project).getElementFactory();
|
||||
PsiClass aClass = myThrown.getElement();
|
||||
if (aClass == null) return;
|
||||
final PsiCatchSection section =
|
||||
factory.createCatchSection(factory.createType(aClass), name,
|
||||
myTryStatement);
|
||||
final PsiCatchSection element = (PsiCatchSection)
|
||||
myTryStatement.addBefore(section, myBeforeCatchSection);
|
||||
final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);
|
||||
final String name = codeStyleManager.suggestUniqueVariableName("e", myTryStatement.getTryBlock(), false);
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory();
|
||||
final PsiClass aClass = myThrown.getElement();
|
||||
if (aClass == null) {
|
||||
return;
|
||||
}
|
||||
final PsiCatchSection section = factory.createCatchSection(factory.createType(aClass), name, myTryStatement);
|
||||
final PsiCatchSection element = (PsiCatchSection)myTryStatement.addBefore(section, myBeforeCatchSection);
|
||||
codeStyleManager.shortenClassReferences(element);
|
||||
|
||||
if (isOnTheFly()) {
|
||||
final TextRange range = getRangeToSelect(element.getCatchBlock());
|
||||
final PsiFile file = element.getContainingFile();
|
||||
final Editor editor = FileEditorManager.getInstance(project)
|
||||
.getSelectedTextEditor();
|
||||
final Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
|
||||
if (editor == null) {
|
||||
return;
|
||||
}
|
||||
final Document document = PsiDocumentManager
|
||||
.getInstance(project).getDocument(file);
|
||||
final Document document = PsiDocumentManager.getInstance(project).getDocument(file);
|
||||
if (editor.getDocument() != document) {
|
||||
return;
|
||||
}
|
||||
editor.getCaretModel().moveToOffset(range.getStartOffset());
|
||||
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
|
||||
editor.getSelectionModel().setSelection(range.getStartOffset(),
|
||||
range.getEndOffset());
|
||||
editor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset());
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return InspectionGadgetsBundle.message("too.broad.catch.quickfix",
|
||||
myText);
|
||||
}
|
||||
}
|
||||
|
||||
private static TextRange getRangeToSelect(PsiCodeBlock block) {
|
||||
@@ -187,24 +190,22 @@ public class TooBroadCatchInspection extends BaseInspection {
|
||||
return new TooBroadCatchVisitor();
|
||||
}
|
||||
|
||||
private class TooBroadCatchVisitor
|
||||
extends BaseInspectionVisitor {
|
||||
private class TooBroadCatchVisitor extends BaseInspectionVisitor {
|
||||
|
||||
@Override
|
||||
public void visitTryStatement(
|
||||
@NotNull PsiTryStatement statement) {
|
||||
public void visitTryStatement(@NotNull PsiTryStatement statement) {
|
||||
super.visitTryStatement(statement);
|
||||
final PsiCodeBlock tryBlock = statement.getTryBlock();
|
||||
if (tryBlock == null) {
|
||||
return;
|
||||
}
|
||||
final Set<PsiClassType> exceptionsThrown =
|
||||
ExceptionUtils.calculateExceptionsThrown(tryBlock);
|
||||
if (ignoreInTestCode && TestUtils.isInTestCode(statement)) {
|
||||
return;
|
||||
}
|
||||
final Set<PsiClassType> exceptionsThrown = ExceptionUtils.calculateExceptionsThrown(tryBlock);
|
||||
final int numExceptionsThrown = exceptionsThrown.size();
|
||||
final Set<PsiType> exceptionsCaught =
|
||||
new HashSet<PsiType>(numExceptionsThrown);
|
||||
final PsiCatchSection[] catchSections =
|
||||
statement.getCatchSections();
|
||||
final Set<PsiType> exceptionsCaught = new HashSet<PsiType>(numExceptionsThrown);
|
||||
final PsiCatchSection[] catchSections = statement.getCatchSections();
|
||||
for (final PsiCatchSection catchSection : catchSections) {
|
||||
final PsiParameter parameter = catchSection.getParameter();
|
||||
if (parameter == null) {
|
||||
@@ -212,10 +213,8 @@ public class TooBroadCatchInspection extends BaseInspection {
|
||||
}
|
||||
final PsiType typeCaught = parameter.getType();
|
||||
if (typeCaught instanceof PsiDisjunctionType) {
|
||||
final PsiDisjunctionType disjunctionType =
|
||||
(PsiDisjunctionType)typeCaught;
|
||||
final List<PsiType> types =
|
||||
disjunctionType.getDisjunctions();
|
||||
final PsiDisjunctionType disjunctionType = (PsiDisjunctionType)typeCaught;
|
||||
final List<PsiType> types = disjunctionType.getDisjunctions();
|
||||
for (PsiType type : types) {
|
||||
register(exceptionsThrown, exceptionsCaught, parameter, type);
|
||||
}
|
||||
@@ -227,29 +226,23 @@ public class TooBroadCatchInspection extends BaseInspection {
|
||||
}
|
||||
|
||||
private void register(Set<PsiClassType> exceptionsThrown, Set<PsiType> exceptionsCaught, PsiParameter parameter, PsiType type) {
|
||||
final List<PsiClass> maskedExceptions =
|
||||
findMaskedExceptions(exceptionsThrown,
|
||||
exceptionsCaught, type);
|
||||
final List<PsiClass> maskedExceptions = findMaskedExceptions(exceptionsThrown, exceptionsCaught, type);
|
||||
if (!maskedExceptions.isEmpty()) {
|
||||
final PsiTypeElement typeElement =
|
||||
parameter.getTypeElement();
|
||||
final PsiTypeElement typeElement = parameter.getTypeElement();
|
||||
registerError(typeElement, maskedExceptions);
|
||||
}
|
||||
}
|
||||
|
||||
private List<PsiClass> findMaskedExceptions(
|
||||
Set<PsiClassType> exceptionsThrown,
|
||||
Set<PsiType> exceptionsCaught, PsiType typeCaught) {
|
||||
private List<PsiClass> findMaskedExceptions(Set<PsiClassType> exceptionsThrown, Set<PsiType> exceptionsCaught, PsiType typeCaught) {
|
||||
if (exceptionsThrown.contains(typeCaught)) {
|
||||
exceptionsCaught.add(typeCaught);
|
||||
exceptionsThrown.remove(typeCaught);
|
||||
}
|
||||
final List<PsiClass> typesMasked = new ArrayList();
|
||||
for (PsiClassType typeThrown : exceptionsThrown) {
|
||||
if (!exceptionsCaught.contains(typeThrown) &&
|
||||
typeCaught.isAssignableFrom(typeThrown)) {
|
||||
if (!exceptionsCaught.contains(typeThrown) && typeCaught.isAssignableFrom(typeThrown)) {
|
||||
exceptionsCaught.add(typeThrown);
|
||||
PsiClass aClass = typeThrown.resolve();
|
||||
final PsiClass aClass = typeThrown.resolve();
|
||||
if (aClass != null) {
|
||||
typesMasked.add(aClass);
|
||||
}
|
||||
|
||||
+14
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2011 Bas Leijdekkers
|
||||
* Copyright 2010-2012 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,7 @@
|
||||
package com.siyeh.ig.errorhandling;
|
||||
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
|
||||
import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
@@ -26,6 +26,7 @@ import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.psiutils.ExceptionUtils;
|
||||
import com.siyeh.ig.psiutils.TestUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -36,6 +37,9 @@ public class TooBroadThrowsInspection extends BaseInspection {
|
||||
@SuppressWarnings({"PublicField"})
|
||||
public boolean onlyWarnOnRootExceptions = false;
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public boolean ignoreInTestCode = false;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getID() {
|
||||
@@ -77,7 +81,10 @@ public class TooBroadThrowsInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
return new SingleCheckboxOptionsPanel(InspectionGadgetsBundle.message("too.broad.catch.option"), this, "onlyWarnOnRootExceptions");
|
||||
final MultipleCheckboxOptionsPanel panel = new MultipleCheckboxOptionsPanel(this);
|
||||
panel.addCheckbox(InspectionGadgetsBundle.message("too.broad.catch.option"), "onlyWarnOnRootExceptions");
|
||||
panel.addCheckbox(InspectionGadgetsBundle.message("ignore.in.test.code"), "ignoreInTestCode");
|
||||
return panel;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -137,8 +144,7 @@ public class TooBroadThrowsInspection extends BaseInspection {
|
||||
return new TooBroadThrowsVisitor();
|
||||
}
|
||||
|
||||
private class TooBroadThrowsVisitor
|
||||
extends BaseInspectionVisitor {
|
||||
private class TooBroadThrowsVisitor extends BaseInspectionVisitor {
|
||||
|
||||
@Override
|
||||
public void visitMethod(PsiMethod method) {
|
||||
@@ -155,6 +161,9 @@ public class TooBroadThrowsInspection extends BaseInspection {
|
||||
if (body == null) {
|
||||
return;
|
||||
}
|
||||
if (ignoreInTestCode && TestUtils.isInTestCode(method)) {
|
||||
return;
|
||||
}
|
||||
final Set<PsiClassType> exceptionsThrown = ExceptionUtils.calculateExceptionsThrown(body);
|
||||
final PsiClassType[] referencedExceptions = throwsList.getReferencedTypes();
|
||||
final Set<PsiClassType> exceptionsDeclared = new HashSet(referencedExceptions.length);
|
||||
|
||||
+5
-17
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2012 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.
|
||||
@@ -15,10 +15,8 @@
|
||||
*/
|
||||
package com.siyeh.ig.errorhandling;
|
||||
|
||||
import com.intellij.codeInsight.TestFrameworks;
|
||||
import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
@@ -93,22 +91,12 @@ public class UnusedCatchParameterInspection extends BaseInspection {
|
||||
private class UnusedCatchParameterVisitor extends BaseInspectionVisitor {
|
||||
|
||||
@Override
|
||||
public void visitTryStatement(
|
||||
@NotNull PsiTryStatement statement) {
|
||||
public void visitTryStatement(@NotNull PsiTryStatement statement) {
|
||||
super.visitTryStatement(statement);
|
||||
if (m_ignoreTestCases) {
|
||||
final PsiClass containingClass =
|
||||
PsiTreeUtil.getParentOfType(statement, PsiClass.class);
|
||||
if (containingClass != null &&
|
||||
TestFrameworks.getInstance().isTestClass(containingClass)) {
|
||||
return;
|
||||
}
|
||||
if (TestUtils.isPartOfJUnitTestMethod(statement)) {
|
||||
return;
|
||||
}
|
||||
if (m_ignoreTestCases && TestUtils.isInTestCode(statement)) {
|
||||
return;
|
||||
}
|
||||
final PsiCatchSection[] catchSections =
|
||||
statement.getCatchSections();
|
||||
final PsiCatchSection[] catchSections = statement.getCatchSections();
|
||||
for (PsiCatchSection catchSection : catchSections) {
|
||||
checkCatchSection(catchSection);
|
||||
}
|
||||
|
||||
+10
-31
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2012 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.
|
||||
@@ -16,7 +16,6 @@
|
||||
package com.siyeh.ig.internationalization;
|
||||
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
import com.intellij.codeInsight.TestFrameworks;
|
||||
import com.intellij.codeInsight.intention.AddAnnotationFix;
|
||||
import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel;
|
||||
import com.intellij.psi.*;
|
||||
@@ -149,26 +148,14 @@ public class StringConcatenationInspection extends BaseInspection {
|
||||
@Override
|
||||
@Nullable
|
||||
public JComponent createOptionsPanel() {
|
||||
final MultipleCheckboxOptionsPanel optionsPanel =
|
||||
new MultipleCheckboxOptionsPanel(this);
|
||||
optionsPanel.addCheckbox(InspectionGadgetsBundle.message(
|
||||
"string.concatenation.ignore.assert.option"),
|
||||
"ignoreAsserts");
|
||||
optionsPanel.addCheckbox(InspectionGadgetsBundle.message(
|
||||
"string.concatenation.ignore.system.out.option"),
|
||||
"ignoreSystemOuts");
|
||||
optionsPanel.addCheckbox(InspectionGadgetsBundle.message(
|
||||
"string.concatenation.ignore.system.err.option"),
|
||||
"ignoreSystemErrs");
|
||||
optionsPanel.addCheckbox(InspectionGadgetsBundle.message(
|
||||
"string.concatenation.ignore.exceptions.option"),
|
||||
"ignoreThrowableArguments");
|
||||
optionsPanel.addCheckbox(InspectionGadgetsBundle.message(
|
||||
"string.concatenation.ignore.constant.initializers.option"),
|
||||
final MultipleCheckboxOptionsPanel optionsPanel = new MultipleCheckboxOptionsPanel(this);
|
||||
optionsPanel.addCheckbox(InspectionGadgetsBundle.message("string.concatenation.ignore.assert.option"), "ignoreAsserts");
|
||||
optionsPanel.addCheckbox(InspectionGadgetsBundle.message("string.concatenation.ignore.system.out.option"), "ignoreSystemOuts");
|
||||
optionsPanel.addCheckbox(InspectionGadgetsBundle.message("string.concatenation.ignore.system.err.option"), "ignoreSystemErrs");
|
||||
optionsPanel.addCheckbox(InspectionGadgetsBundle.message("string.concatenation.ignore.exceptions.option"), "ignoreThrowableArguments");
|
||||
optionsPanel.addCheckbox(InspectionGadgetsBundle.message("string.concatenation.ignore.constant.initializers.option"),
|
||||
"ignoreConstantInitializers");
|
||||
optionsPanel.addCheckbox(InspectionGadgetsBundle.message(
|
||||
"string.concatenation.ignore.in.test.code"),
|
||||
"ignoreInTestCode");
|
||||
optionsPanel.addCheckbox(InspectionGadgetsBundle.message("ignore.in.test.code"), "ignoreInTestCode");
|
||||
return optionsPanel;
|
||||
}
|
||||
|
||||
@@ -201,16 +188,8 @@ public class StringConcatenationInspection extends BaseInspection {
|
||||
if (isInsideAnnotation(expression)) {
|
||||
return;
|
||||
}
|
||||
if (ignoreInTestCode) {
|
||||
if (TestUtils.isPartOfJUnitTestMethod(expression)) {
|
||||
return;
|
||||
}
|
||||
final PsiClass containingClass =
|
||||
PsiTreeUtil.getParentOfType(expression, PsiClass.class);
|
||||
if (containingClass != null &&
|
||||
TestFrameworks.getInstance().isTestClass(containingClass)) {
|
||||
return;
|
||||
}
|
||||
if (ignoreInTestCode && TestUtils.isInTestCode(expression)) {
|
||||
return;
|
||||
}
|
||||
if (ignoreAsserts) {
|
||||
final PsiAssertStatement assertStatement =
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2012 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.
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.siyeh.ig.psiutils;
|
||||
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
import com.intellij.codeInsight.TestFrameworks;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
@@ -49,8 +50,7 @@ public class TestUtils {
|
||||
}
|
||||
|
||||
public static boolean isPartOfJUnitTestMethod(@NotNull PsiElement element) {
|
||||
final PsiMethod method = PsiTreeUtil.getParentOfType(element,
|
||||
PsiMethod.class);
|
||||
final PsiMethod method = PsiTreeUtil.getParentOfType(element, PsiMethod.class, false);
|
||||
return method != null && isJUnitTestMethod(method);
|
||||
}
|
||||
|
||||
@@ -98,13 +98,18 @@ public class TestUtils {
|
||||
}
|
||||
|
||||
public static boolean isJUnit4TestMethod(@Nullable PsiMethod method) {
|
||||
return method != null &&
|
||||
AnnotationUtil.isAnnotated(method, "org.junit.Test", true);
|
||||
return method != null && AnnotationUtil.isAnnotated(method, "org.junit.Test", true);
|
||||
}
|
||||
|
||||
public static boolean isJUnitTestClass(@Nullable PsiClass targetClass) {
|
||||
return targetClass != null &&
|
||||
InheritanceUtil.isInheritor(targetClass,
|
||||
"junit.framework.TestCase");
|
||||
return targetClass != null && InheritanceUtil.isInheritor(targetClass, "junit.framework.TestCase");
|
||||
}
|
||||
|
||||
public static boolean isInTestCode(PsiElement element) {
|
||||
if (isPartOfJUnitTestMethod(element)) {
|
||||
return true;
|
||||
}
|
||||
final PsiClass containingClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);
|
||||
return containingClass != null && TestFrameworks.getInstance().isTestClass(containingClass);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@ This inspection reports "magic numbers", literal numeric constants used without
|
||||
number" is changed in one code location but not another. The numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 1000, 0L, 1L, 2L,
|
||||
0.0, 1.0, 0.0F and 1.0F are not reported by this inspection.
|
||||
<p>
|
||||
Use the checkbox below to disable this inspection within 'hashCode()' methods.
|
||||
Use the first checkbox below to disable this inspection within <b>hashCode()</b> methods.
|
||||
<p>
|
||||
Use the second checkbox below to ignore magic numbers in test code.
|
||||
<p>
|
||||
<small>Powered by InspectionGadgets</small>
|
||||
</body>
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
This inspection reports <b>catch</b> blocks which have parameters which are more generic than the
|
||||
exceptions thrown by the corresponding <b>try</b> block.
|
||||
<p>
|
||||
Use the first checkbox below to have this inspection only warn on the most generic exceptions.
|
||||
<p>
|
||||
Use the second checkbox below to ignore overly broad <b>catch</b> blocks in test code.
|
||||
<p>
|
||||
<small>Powered by InspectionGadgets</small>
|
||||
</body>
|
||||
</html>
|
||||
@@ -3,6 +3,10 @@
|
||||
This inspection reports <b>throws</b> clauses which contain exceptions which are more generic than the
|
||||
exceptions actually thrown by the method.
|
||||
<p>
|
||||
Use the first checkbox below to have this inspection only warn on the most generic exceptions.
|
||||
<p>
|
||||
Use the second checkbox below to ignore overly broad <b>throws</b> clauses in test code.
|
||||
<p>
|
||||
<small>New in 10, Powered by InspectionGadgets</small>
|
||||
</body>
|
||||
</html>
|
||||
@@ -5,8 +5,9 @@ corresponding blocks. This inspection will not report any <b>catch</b> parameter
|
||||
named "ignore" or "ignored". Conversely this inspection will warn on any
|
||||
<b>catch</b> parameters named "ignore" or "ignored" that are actually used.
|
||||
<p>
|
||||
Use the checkboxes below to disable this inspection for <b>catch</b>
|
||||
blocks with comments, catch blocks in test code.
|
||||
Use the first checkbox below to disable this inspection for <b>catch</b> blocks with comments.
|
||||
<p>
|
||||
Use the second checkbox below to ignore catch blocks in test code.
|
||||
<p>
|
||||
<small>Powered by InspectionGadgets</small>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user