mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
moved to analysis
This commit is contained in:
+126
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.errorhandling;
|
||||
|
||||
import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.TestUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class UnusedCatchParameterInspectionBase extends BaseInspection {
|
||||
/**
|
||||
* @noinspection PublicField
|
||||
*/
|
||||
public boolean m_ignoreCatchBlocksWithComments = false;
|
||||
/**
|
||||
* @noinspection PublicField
|
||||
*/
|
||||
public boolean m_ignoreTestCases = false;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"unused.catch.parameter.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
final MultipleCheckboxOptionsPanel optionsPanel =
|
||||
new MultipleCheckboxOptionsPanel(this);
|
||||
optionsPanel.addCheckbox(InspectionGadgetsBundle.message(
|
||||
"unused.catch.parameter.ignore.catch.option"),
|
||||
"m_ignoreCatchBlocksWithComments");
|
||||
optionsPanel.addCheckbox(InspectionGadgetsBundle.message(
|
||||
"unused.catch.parameter.ignore.empty.option"),
|
||||
"m_ignoreTestCases");
|
||||
return optionsPanel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
final boolean namedIgnoreButUsed = ((Boolean)infos[0]).booleanValue();
|
||||
if (namedIgnoreButUsed) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"used.catch.parameter.named.ignore.problem.descriptor"
|
||||
);
|
||||
}
|
||||
return InspectionGadgetsBundle.message(
|
||||
"unused.catch.parameter.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new UnusedCatchParameterVisitor();
|
||||
}
|
||||
|
||||
private class UnusedCatchParameterVisitor extends BaseInspectionVisitor {
|
||||
|
||||
@Override
|
||||
public void visitTryStatement(@NotNull PsiTryStatement statement) {
|
||||
super.visitTryStatement(statement);
|
||||
if (m_ignoreTestCases && TestUtils.isInTestCode(statement)) {
|
||||
return;
|
||||
}
|
||||
final PsiCatchSection[] catchSections = statement.getCatchSections();
|
||||
for (PsiCatchSection catchSection : catchSections) {
|
||||
checkCatchSection(catchSection);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkCatchSection(PsiCatchSection section) {
|
||||
final PsiParameter parameter = section.getParameter();
|
||||
if (parameter == null) {
|
||||
return;
|
||||
}
|
||||
@NonNls final String parameterName = parameter.getName();
|
||||
final PsiCodeBlock block = section.getCatchBlock();
|
||||
if (block == null) {
|
||||
return;
|
||||
}
|
||||
if (m_ignoreCatchBlocksWithComments) {
|
||||
final PsiElement[] children = block.getChildren();
|
||||
for (final PsiElement child : children) {
|
||||
if (child instanceof PsiComment) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
final CatchParameterUsedVisitor visitor =
|
||||
new CatchParameterUsedVisitor(parameter);
|
||||
block.accept(visitor);
|
||||
final boolean namedIgnore = PsiUtil.isIgnoredName(parameterName);
|
||||
if (visitor.isUsed()) {
|
||||
if (namedIgnore) {
|
||||
registerVariableError(parameter, Boolean.TRUE);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (namedIgnore) {
|
||||
return;
|
||||
}
|
||||
registerVariableError(parameter, Boolean.FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-108
@@ -15,64 +15,11 @@
|
||||
*/
|
||||
package com.siyeh.ig.errorhandling;
|
||||
|
||||
import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.fixes.RenameFix;
|
||||
import com.siyeh.ig.psiutils.TestUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class UnusedCatchParameterInspection extends BaseInspection {
|
||||
|
||||
/**
|
||||
* @noinspection PublicField
|
||||
*/
|
||||
public boolean m_ignoreCatchBlocksWithComments = false;
|
||||
/**
|
||||
* @noinspection PublicField
|
||||
*/
|
||||
public boolean m_ignoreTestCases = false;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"unused.catch.parameter.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
final MultipleCheckboxOptionsPanel optionsPanel =
|
||||
new MultipleCheckboxOptionsPanel(this);
|
||||
optionsPanel.addCheckbox(InspectionGadgetsBundle.message(
|
||||
"unused.catch.parameter.ignore.catch.option"),
|
||||
"m_ignoreCatchBlocksWithComments");
|
||||
optionsPanel.addCheckbox(InspectionGadgetsBundle.message(
|
||||
"unused.catch.parameter.ignore.empty.option"),
|
||||
"m_ignoreTestCases");
|
||||
return optionsPanel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
final boolean namedIgnoreButUsed = ((Boolean)infos[0]).booleanValue();
|
||||
if (namedIgnoreButUsed) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"used.catch.parameter.named.ignore.problem.descriptor"
|
||||
);
|
||||
}
|
||||
return InspectionGadgetsBundle.message(
|
||||
"unused.catch.parameter.problem.descriptor");
|
||||
}
|
||||
public class UnusedCatchParameterInspection extends UnusedCatchParameterInspectionBase {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
@@ -83,58 +30,4 @@ public class UnusedCatchParameterInspection extends BaseInspection {
|
||||
}
|
||||
return new RenameFix("ignored", false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new UnusedCatchParameterVisitor();
|
||||
}
|
||||
|
||||
private class UnusedCatchParameterVisitor extends BaseInspectionVisitor {
|
||||
|
||||
@Override
|
||||
public void visitTryStatement(@NotNull PsiTryStatement statement) {
|
||||
super.visitTryStatement(statement);
|
||||
if (m_ignoreTestCases && TestUtils.isInTestCode(statement)) {
|
||||
return;
|
||||
}
|
||||
final PsiCatchSection[] catchSections = statement.getCatchSections();
|
||||
for (PsiCatchSection catchSection : catchSections) {
|
||||
checkCatchSection(catchSection);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkCatchSection(PsiCatchSection section) {
|
||||
final PsiParameter parameter = section.getParameter();
|
||||
if (parameter == null) {
|
||||
return;
|
||||
}
|
||||
@NonNls final String parameterName = parameter.getName();
|
||||
final PsiCodeBlock block = section.getCatchBlock();
|
||||
if (block == null) {
|
||||
return;
|
||||
}
|
||||
if (m_ignoreCatchBlocksWithComments) {
|
||||
final PsiElement[] children = block.getChildren();
|
||||
for (final PsiElement child : children) {
|
||||
if (child instanceof PsiComment) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
final CatchParameterUsedVisitor visitor =
|
||||
new CatchParameterUsedVisitor(parameter);
|
||||
block.accept(visitor);
|
||||
final boolean namedIgnore = PsiUtil.isIgnoredName(parameterName);
|
||||
if (visitor.isUsed()) {
|
||||
if (namedIgnore) {
|
||||
registerVariableError(parameter, Boolean.valueOf(true));
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (namedIgnore) {
|
||||
return;
|
||||
}
|
||||
registerVariableError(parameter, Boolean.valueOf(false));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user