From 7e8935ecc397290a7a477610fee5882a4ec376dc Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Tue, 13 Sep 2016 12:46:09 +0200 Subject: [PATCH] IG: add assertions instead of silently ignoring problems --- .../src/com/siyeh/ig/BaseInspection.java | 7 ++++--- .../src/com/siyeh/ig/BaseInspectionVisitor.java | 13 +++---------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/BaseInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/BaseInspection.java index 67b1f9e1ec43..404f90983597 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/BaseInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/BaseInspection.java @@ -118,9 +118,10 @@ public abstract class BaseInspection extends BaseJavaBatchLocalInspectionTool { @Override @NotNull - public final PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, - boolean isOnTheFly) { - if (!shouldInspect(holder.getFile())) { + public final PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) { + final PsiFile file = holder.getFile(); + assert file.isPhysical(); + if (!shouldInspect(file)) { return new PsiElementVisitor() { }; } final BaseInspectionVisitor visitor = buildVisitor(); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/BaseInspectionVisitor.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/BaseInspectionVisitor.java index 4d4d8aae6fbf..4bcd01fd3536 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/BaseInspectionVisitor.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/BaseInspectionVisitor.java @@ -96,10 +96,7 @@ public abstract class BaseInspectionVisitor extends JavaElementVisitor { else { nameIdentifier = aClass.getNameIdentifier(); } - if (nameIdentifier != null && !nameIdentifier.isPhysical()) { - nameIdentifier = nameIdentifier.getNavigationElement(); - } - if (nameIdentifier == null || !nameIdentifier.isPhysical()) { + if (nameIdentifier == null) { registerError(aClass.getContainingFile(), infos); } else { @@ -182,9 +179,7 @@ public abstract class BaseInspectionVisitor extends JavaElementVisitor { protected final void registerError(@NotNull PsiElement location, final ProblemHighlightType highlightType, Object... infos) { - if (!location.isPhysical() || location.getTextLength() == 0 && !(location instanceof PsiFile)) { - return; - } + assert location.getTextLength() != 0 || location instanceof PsiFile; final LocalQuickFix[] fixes = createAndInitFixes(infos); final String description = inspection.buildErrorString(infos); holder.registerProblem(location, description, highlightType, fixes); @@ -197,9 +192,7 @@ public abstract class BaseInspectionVisitor extends JavaElementVisitor { protected final void registerErrorAtOffset(@NotNull PsiElement location, int offset, int length, ProblemHighlightType highlightType, Object... infos) { - if (location.getTextLength() == 0 || length == 0) { - return; - } + assert !(location.getTextLength() == 0 || length == 0); final LocalQuickFix[] fixes = createAndInitFixes(infos); final String description = inspection.buildErrorString(infos); final TextRange range = new TextRange(offset, offset + length);