Use shouldInspect() method more

This commit is contained in:
Bas Leijdekkers
2015-08-25 17:36:12 +02:00
parent 5e876fb678
commit cc622018cd
16 changed files with 113 additions and 92 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2015 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.
@@ -74,6 +74,11 @@ public class EmptyStatementBodyInspection extends BaseInspection {
return panel;
}
@Override
public boolean shouldInspect(PsiFile file) {
return !FileTypeUtils.isInServerPageFile(file);
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new EmptyStatementVisitor();
@@ -106,9 +111,6 @@ public class EmptyStatementBodyInspection extends BaseInspection {
}
private void checkLoopStatement(PsiLoopStatement statement) {
if (FileTypeUtils.isInServerPageFile(statement)) {
return;
}
final PsiStatement body = statement.getBody();
if (body == null || !isEmpty(body)) {
return;
@@ -119,9 +121,6 @@ public class EmptyStatementBodyInspection extends BaseInspection {
@Override
public void visitIfStatement(@NotNull PsiIfStatement statement) {
super.visitIfStatement(statement);
if (FileTypeUtils.isInServerPageFile(statement)) {
return;
}
final PsiStatement thenBranch = statement.getThenBranch();
if (thenBranch != null && isEmpty(thenBranch)) {
registerStatementError(statement);
@@ -140,9 +139,6 @@ public class EmptyStatementBodyInspection extends BaseInspection {
@Override
public void visitSwitchStatement(PsiSwitchStatement statement) {
super.visitSwitchStatement(statement);
if (FileTypeUtils.isInServerPageFile(statement)) {
return;
}
final PsiCodeBlock body = statement.getBody();
if (body == null || !isEmpty(body)) {
return;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -17,6 +17,7 @@ package com.siyeh.ig.classlayout;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiJavaFile;
import com.intellij.psi.util.FileTypeUtils;
import com.siyeh.InspectionGadgetsBundle;
@@ -39,6 +40,11 @@ public class ClassNameDiffersFromFileNameInspectionBase extends BaseInspection {
"class.name.differs.from.file.name.problem.descriptor");
}
@Override
public boolean shouldInspect(PsiFile file) {
return !FileTypeUtils.isInServerPageFile(file);
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new ClassNameDiffersFromFileNameVisitor();
@@ -50,9 +56,6 @@ public class ClassNameDiffersFromFileNameInspectionBase extends BaseInspection {
@Override
public void visitClass(@NotNull PsiClass aClass) {
// no call to super, so that it doesn't drill down to inner classes
if (FileTypeUtils.isInServerPageFile(aClass)) {
return;
}
final PsiElement parent = aClass.getParent();
if (!(parent instanceof PsiJavaFile)) {
return;
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2015 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.
@@ -61,6 +61,11 @@ public class UnnecessaryContinueInspection extends BaseInspection {
return new UnnecessaryContinueVisitor();
}
@Override
public boolean shouldInspect(PsiFile file) {
return !FileTypeUtils.isInServerPageFile(file);
}
@Override
public InspectionGadgetsFix buildFix(Object... infos) {
return new DeleteUnnecessaryStatementFix("continue");
@@ -70,9 +75,6 @@ public class UnnecessaryContinueInspection extends BaseInspection {
@Override
public void visitContinueStatement(@NotNull PsiContinueStatement statement) {
if (FileTypeUtils.isInServerPageFile(statement.getContainingFile())) {
return;
}
final PsiStatement continuedStatement = statement.findContinuedStatement();
PsiStatement body = null;
if (continuedStatement instanceof PsiForeachStatement) {
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2015 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.
@@ -17,6 +17,7 @@ package com.siyeh.ig.controlflow;
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
import com.intellij.psi.*;
import com.intellij.psi.util.FileTypeUtils;
import com.intellij.psi.util.PsiTreeUtil;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
@@ -24,7 +25,6 @@ import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
import com.siyeh.ig.fixes.DeleteUnnecessaryStatementFix;
import com.siyeh.ig.psiutils.ControlFlowUtils;
import com.intellij.psi.util.FileTypeUtils;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
@@ -71,6 +71,11 @@ public class UnnecessaryReturnInspection extends BaseInspection {
return new DeleteUnnecessaryStatementFix("return");
}
@Override
public boolean shouldInspect(PsiFile file) {
return !FileTypeUtils.isInServerPageFile(file);
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new UnnecessaryReturnVisitor();
@@ -80,9 +85,6 @@ public class UnnecessaryReturnInspection extends BaseInspection {
@Override
public void visitReturnStatement(@NotNull PsiReturnStatement statement) {
super.visitReturnStatement(statement);
if (FileTypeUtils.isInServerPageFile(statement.getContainingFile())) {
return;
}
if (statement.getReturnValue() != null) {
return;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2015 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.
@@ -25,7 +25,6 @@ import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
import com.siyeh.ig.psiutils.TestUtils;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -113,6 +112,11 @@ public class EmptyCatchBlockInspectionBase extends BaseInspection {
}
}
@Override
public boolean shouldInspect(PsiFile file) {
return !FileTypeUtils.isInServerPageFile(file);
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new EmptyCatchBlockVisitor();
@@ -123,9 +127,6 @@ public class EmptyCatchBlockInspectionBase extends BaseInspection {
@Override
public void visitTryStatement(@NotNull PsiTryStatement statement) {
super.visitTryStatement(statement);
if (FileTypeUtils.isInServerPageFile(statement.getContainingFile())) {
return;
}
final PsiCatchSection[] catchSections = statement.getCatchSections();
for (final PsiCatchSection section : catchSections) {
checkCatchSection(section);
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2015 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.
@@ -143,6 +143,11 @@ public class EmptyFinallyBlockInspection extends BaseInspection {
}
}
@Override
public boolean shouldInspect(PsiFile file) {
return !FileTypeUtils.isInServerPageFile(file);
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new EmptyFinallyBlockVisitor();
@@ -152,9 +157,6 @@ public class EmptyFinallyBlockInspection extends BaseInspection {
@Override
public void visitTryStatement(@NotNull PsiTryStatement statement) {
super.visitTryStatement(statement);
if (FileTypeUtils.isInServerPageFile(statement.getContainingFile())) {
return;
}
final PsiCodeBlock finallyBlock = statement.getFinallyBlock();
if (finallyBlock == null) {
return;
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2015 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.errorhandling;
import com.intellij.psi.PsiCodeBlock;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiTryStatement;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
@@ -43,6 +44,11 @@ public class EmptyTryBlockInspection extends BaseInspection {
"empty.try.block.problem.descriptor");
}
@Override
public boolean shouldInspect(PsiFile file) {
return !FileTypeUtils.isInServerPageFile(file);
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new EmptyTryBlockVisitor();
@@ -54,9 +60,6 @@ public class EmptyTryBlockInspection extends BaseInspection {
@Override
public void visitTryStatement(@NotNull PsiTryStatement statement) {
super.visitTryStatement(statement);
if (FileTypeUtils.isInServerPageFile(statement.getContainingFile())) {
return;
}
final PsiCodeBlock finallyBlock = statement.getTryBlock();
if (finallyBlock == null) {
return;
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2015 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.
@@ -48,6 +48,11 @@ public class JavaLangImportInspection extends BaseInspection implements CleanupL
return new DeleteImportFix();
}
@Override
public boolean shouldInspect(PsiFile file) {
return !FileTypeUtils.isInServerPageFile(file);
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new JavaLangImportVisitor();
@@ -61,9 +66,6 @@ public class JavaLangImportInspection extends BaseInspection implements CleanupL
if (!(aClass.getParent() instanceof PsiJavaFile)) {
return;
}
if (FileTypeUtils.isInServerPageFile(aClass.getContainingFile())) {
return;
}
final PsiJavaFile file = (PsiJavaFile)aClass.getContainingFile();
if (!file.getClasses()[0].equals(aClass)) {
return;
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2015 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.
@@ -36,6 +36,11 @@ public class OnDemandImportInspection extends BaseInspection {
return InspectionGadgetsBundle.message("import.problem.descriptor");
}
@Override
public boolean shouldInspect(PsiFile file) {
return !FileTypeUtils.isInServerPageFile(file);
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new PackageImportVisitor();
@@ -51,9 +56,6 @@ public class OnDemandImportInspection extends BaseInspection {
return;
}
final PsiJavaFile file = (PsiJavaFile)parent;
if (FileTypeUtils.isInServerPageFile(aClass.getContainingFile())) {
return;
}
if (!file.getClasses()[0].equals(aClass)) {
return;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2015 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.
@@ -17,12 +17,12 @@ package com.siyeh.ig.imports;
import com.intellij.codeInspection.CleanupLocalInspectionTool;
import com.intellij.psi.*;
import com.intellij.psi.util.FileTypeUtils;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
import com.siyeh.ig.fixes.DeleteImportFix;
import com.intellij.psi.util.FileTypeUtils;
import org.jetbrains.annotations.NotNull;
public class SamePackageImportInspection extends BaseInspection implements CleanupLocalInspectionTool {
@@ -46,6 +46,11 @@ public class SamePackageImportInspection extends BaseInspection implements Clean
return new DeleteImportFix();
}
@Override
public boolean shouldInspect(PsiFile file) {
return !FileTypeUtils.isInServerPageFile(file);
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new SamePackageImportVisitor();
@@ -60,9 +65,6 @@ public class SamePackageImportInspection extends BaseInspection implements Clean
if (!(parent instanceof PsiJavaFile)) {
return;
}
if (FileTypeUtils.isInServerPageFile(importList)) {
return;
}
final PsiJavaFile javaFile = (PsiJavaFile)parent;
final String packageName = javaFile.getPackageName();
final PsiImportStatement[] importStatements =
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2015 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,14 +15,11 @@
*/
package com.siyeh.ig.imports;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiImportList;
import com.intellij.psi.PsiImportStatement;
import com.intellij.psi.PsiJavaFile;
import com.intellij.psi.*;
import com.intellij.psi.util.FileTypeUtils;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.intellij.psi.util.FileTypeUtils;
import org.jetbrains.annotations.NotNull;
public class SingleClassImportInspection extends BaseInspection {
@@ -41,6 +38,11 @@ public class SingleClassImportInspection extends BaseInspection {
"single.class.import.problem.descriptor");
}
@Override
public boolean shouldInspect(PsiFile file) {
return !FileTypeUtils.isInServerPageFile(file);
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new PackageImportVisitor();
@@ -51,16 +53,11 @@ public class SingleClassImportInspection extends BaseInspection {
@Override
public void visitClass(@NotNull PsiClass aClass) {
// no call to super, so it doesn't drill down
if (!(aClass.getParent() instanceof PsiJavaFile)) {
return;
}
if (FileTypeUtils.isInServerPageFile(aClass.getContainingFile())) {
return;
}
final PsiJavaFile file = (PsiJavaFile)aClass.getParent();
if (file == null) {
final PsiElement parent = aClass.getParent();
if (!(parent instanceof PsiJavaFile)) {
return;
}
final PsiJavaFile file = (PsiJavaFile)parent;
if (!file.getClasses()[0].equals(aClass)) {
return;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -56,6 +56,11 @@ public class StaticImportInspectionBase extends BaseInspection {
"static.import.problem.descriptor");
}
@Override
public boolean shouldInspect(PsiFile file) {
return !FileTypeUtils.isInServerPageFile(file);
}
@Override
protected InspectionGadgetsFix buildFix(Object... infos) {
return new StaticImportFix();
@@ -245,9 +250,6 @@ public class StaticImportInspectionBase extends BaseInspection {
return;
}
final PsiJavaFile file = (PsiJavaFile)parent;
if (FileTypeUtils.isInServerPageFile(file)) {
return;
}
if (!file.getClasses()[0].equals(aClass)) {
return;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2014 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2015 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,12 +16,12 @@
package com.siyeh.ig.imports;
import com.intellij.psi.*;
import com.intellij.psi.util.FileTypeUtils;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
import com.siyeh.ig.fixes.DeleteImportFix;
import com.intellij.psi.util.FileTypeUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -49,6 +49,11 @@ public class UnusedImportInspection extends BaseInspection {
return new DeleteImportFix();
}
@Override
public boolean shouldInspect(PsiFile file) {
return !FileTypeUtils.isInServerPageFile(file);
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new UnusedImportVisitor();
@@ -58,9 +63,6 @@ public class UnusedImportInspection extends BaseInspection {
@Override
public void visitJavaFile(PsiJavaFile file) {
if (FileTypeUtils.isInServerPageFile(file)) {
return;
}
final PsiClass[] classes = file.getClasses();
final PsiPackageStatement packageStatement = file.getPackageStatement();
final PsiModifierList annotationList;
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2015 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.
@@ -19,12 +19,12 @@ import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.util.FileTypeUtils;
import com.intellij.util.IncorrectOperationException;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
import com.intellij.psi.util.FileTypeUtils;
import org.jetbrains.annotations.NotNull;
public class ClassWithoutConstructorInspection extends BaseInspection {
@@ -98,6 +98,11 @@ public class ClassWithoutConstructorInspection extends BaseInspection {
}
}
@Override
public boolean shouldInspect(PsiFile file) {
return !FileTypeUtils.isInServerPageFile(file);
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new ClassWithoutConstructorVisitor();
@@ -109,12 +114,10 @@ public class ClassWithoutConstructorInspection extends BaseInspection {
@Override
public void visitClass(@NotNull PsiClass aClass) {
// no call to super, so it doesn't drill down
if (aClass.isInterface() || aClass.isEnum() ||
aClass.isAnnotationType() || FileTypeUtils.isInServerPageFile(aClass)) {
if (aClass.isInterface() || aClass.isEnum() || aClass.isAnnotationType()) {
return;
}
if (aClass instanceof PsiTypeParameter ||
aClass instanceof PsiAnonymousClass) {
if (aClass instanceof PsiTypeParameter || aClass instanceof PsiAnonymousClass) {
return;
}
final PsiMethod[] constructors = aClass.getConstructors();
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2014 Dave Griffith, Bas Leijdekkers
* Copyright 2006-2015 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.
@@ -85,6 +85,11 @@ public class DesignForExtensionInspection extends BaseInspection {
}
}
@Override
public boolean shouldInspect(PsiFile file) {
return !FileTypeUtils.isInServerPageFile(file); // IDEADEV-25538
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new DesignForExtensionVisitor();
@@ -94,10 +99,6 @@ public class DesignForExtensionInspection extends BaseInspection {
@Override
public void visitMethod(PsiMethod method) {
if (FileTypeUtils.isInServerPageFile(method)) {
// IDEADEV-25538
return;
}
super.visitMethod(method);
if (method.isConstructor()) {
return;
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2015 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,12 +16,13 @@
package com.siyeh.ig.threading;
import com.intellij.psi.PsiCodeBlock;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiStatement;
import com.intellij.psi.PsiSynchronizedStatement;
import com.intellij.psi.util.FileTypeUtils;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.intellij.psi.util.FileTypeUtils;
import org.jetbrains.annotations.NotNull;
public class EmptySynchronizedStatementInspection extends BaseInspection {
@@ -40,21 +41,21 @@ public class EmptySynchronizedStatementInspection extends BaseInspection {
"empty.synchronized.statement.problem.descriptor");
}
@Override
public boolean shouldInspect(PsiFile file) {
return !FileTypeUtils.isInServerPageFile(file);
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new EmptySynchronizedStatementVisitor();
}
private static class EmptySynchronizedStatementVisitor
extends BaseInspectionVisitor {
private static class EmptySynchronizedStatementVisitor extends BaseInspectionVisitor {
@Override
public void visitSynchronizedStatement(
@NotNull PsiSynchronizedStatement statement) {
public void visitSynchronizedStatement(@NotNull PsiSynchronizedStatement statement) {
super.visitSynchronizedStatement(statement);
if (FileTypeUtils.isInServerPageFile(statement.getContainingFile())) {
return;
}
final PsiCodeBlock body = statement.getBody();
if (body == null) {
return;