calculate default inspection name by trimming Inspection or InspectionBase

This commit is contained in:
Alexey Kudravtsev
2014-06-05 16:30:30 +04:00
parent 4a0d396b81
commit 67c4e4bb7a
2 changed files with 6 additions and 10 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* 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.
@@ -135,7 +135,7 @@ public abstract class InspectionProfileEntry {
@NotNull
public static String getShortName(@NotNull String className) {
return StringUtil.trimEnd(className, "Inspection");
return StringUtil.trimEnd(StringUtil.trimEnd(className, "Inspection"),"InspectionBase");
}
/**
@@ -17,6 +17,7 @@ package com.siyeh.ig;
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
import com.intellij.codeInspection.BaseJavaBatchLocalInspectionTool;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.LocalInspectionToolSession;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.codeInspection.ex.InspectionProfileImpl;
@@ -55,14 +56,9 @@ public abstract class BaseInspection extends BaseJavaBatchLocalInspectionTool {
public String getShortName() {
if (m_shortName == null) {
final Class<? extends BaseInspection> aClass = getClass();
final String name = aClass.getName();
if (name.endsWith(INSPECTION)) {
m_shortName = name.substring(name.lastIndexOf((int)'.') + 1, name.length() - INSPECTION.length());
}
else if (name.endsWith(INSPECTION_BASE)) {
m_shortName = name.substring(name.lastIndexOf((int)'.') + 1, name.length() - INSPECTION_BASE.length());
}
else {
final String name = aClass.getSimpleName();
m_shortName = InspectionProfileEntry.getShortName(name);
if (m_shortName.equals(name)) {
throw new AssertionError("class name must end with 'Inspection' to correctly calculate the short name: " + name);
}
}