mirror of
https://github.com/alibaba/p3c.git
synced 2025-10-15 15:40:26 +00:00
Redefine constant in class (NumberConstants ObjectConstants...)
This commit is contained in:
@@ -23,11 +23,16 @@ import com.intellij.openapi.util.IconLoader;
|
|||||||
* @author caikang
|
* @author caikang
|
||||||
* @date 2016/12/28
|
* @date 2016/12/28
|
||||||
*/
|
*/
|
||||||
public interface P3cIcons {
|
public final class P3cIcons {
|
||||||
Icon ANALYSIS_ACTION = IconLoader.getIcon("/icons/ali-ide-run.png");
|
private P3cIcons() {
|
||||||
|
throw new AssertionError("icons.P3cIcons"
|
||||||
|
+ " instances for you!");
|
||||||
|
}
|
||||||
|
|
||||||
Icon PROJECT_INSPECTION_ON = IconLoader.getIcon("/icons/qiyong.png");
|
public static final Icon ANALYSIS_ACTION = IconLoader.getIcon("/icons/ali-ide-run.png");
|
||||||
Icon PROJECT_INSPECTION_OFF = IconLoader.getIcon("/icons/tingyong.png");
|
|
||||||
Icon LANGUAGE = IconLoader.getIcon("/icons/language.png");
|
public static final Icon PROJECT_INSPECTION_ON = IconLoader.getIcon("/icons/qiyong.png");
|
||||||
Icon ALIBABA = IconLoader.getIcon("/icons/alibaba.png");
|
public static final Icon PROJECT_INSPECTION_OFF = IconLoader.getIcon("/icons/tingyong.png");
|
||||||
|
public static final Icon LANGUAGE = IconLoader.getIcon("/icons/language.png");
|
||||||
|
public static final Icon ALIBABA = IconLoader.getIcon("/icons/alibaba.png");
|
||||||
}
|
}
|
||||||
|
@@ -20,6 +20,7 @@ import com.alibaba.p3c.idea.compatible.inspection.Inspections
|
|||||||
import com.alibaba.p3c.idea.ep.InspectionActionExtensionPoint
|
import com.alibaba.p3c.idea.ep.InspectionActionExtensionPoint
|
||||||
import com.alibaba.p3c.idea.i18n.P3cBundle
|
import com.alibaba.p3c.idea.i18n.P3cBundle
|
||||||
import com.alibaba.p3c.idea.inspection.AliBaseInspection
|
import com.alibaba.p3c.idea.inspection.AliBaseInspection
|
||||||
|
import com.alibaba.p3c.idea.util.NumberConstants
|
||||||
import com.beust.jcommander.internal.Lists
|
import com.beust.jcommander.internal.Lists
|
||||||
import com.intellij.analysis.AnalysisScope
|
import com.intellij.analysis.AnalysisScope
|
||||||
import com.intellij.analysis.AnalysisUIOptions
|
import com.intellij.analysis.AnalysisUIOptions
|
||||||
@@ -68,7 +69,7 @@ class AliInspectionAction : AnAction() {
|
|||||||
if (psiFile != null) {
|
if (psiFile != null) {
|
||||||
analysisScope = AnalysisScope(psiFile)
|
analysisScope = AnalysisScope(psiFile)
|
||||||
projectDir = isBaseDir(psiFile.virtualFile, project)
|
projectDir = isBaseDir(psiFile.virtualFile, project)
|
||||||
} else if (virtualFiles != null && virtualFiles.size > com.alibaba.p3c.idea.NumberConstants.INTEGER_SIZE_OR_LENGTH_0) {
|
} else if (virtualFiles != null && virtualFiles.size > NumberConstants.INTEGER_SIZE_OR_LENGTH_0) {
|
||||||
analysisScope = AnalysisScope(project, Lists.newArrayList<VirtualFile>(*virtualFiles))
|
analysisScope = AnalysisScope(project, Lists.newArrayList<VirtualFile>(*virtualFiles))
|
||||||
projectDir = virtualFiles.any {
|
projectDir = virtualFiles.any {
|
||||||
isBaseDir(it, project)
|
isBaseDir(it, project)
|
||||||
|
@@ -15,9 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package com.alibaba.p3c.idea.compatible.inspection
|
package com.alibaba.p3c.idea.compatible.inspection
|
||||||
|
|
||||||
|
import com.google.common.base.Splitter
|
||||||
import com.intellij.codeInspection.ex.InspectionProfileImpl
|
import com.intellij.codeInspection.ex.InspectionProfileImpl
|
||||||
import com.intellij.codeInspection.ex.InspectionToolWrapper
|
import com.intellij.codeInspection.ex.InspectionToolWrapper
|
||||||
import com.intellij.codeInspection.ex.ScopeToolState
|
import com.intellij.codeInspection.ex.ScopeToolState
|
||||||
|
import com.intellij.codeInspection.javaDoc.JavaDocLocalInspection
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,6 +34,24 @@ object Inspections {
|
|||||||
return getAllTools(project, profile).filter(filter)
|
return getAllTools(project, profile).filter(filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun addCustomTag(project: Project, tag: String) {
|
||||||
|
val profile = InspectionProfileService.getProjectInspectionProfile(project)
|
||||||
|
val javaDocLocalInspection = profile.getInspectionTool("JavaDoc", project)?.tool
|
||||||
|
as? JavaDocLocalInspection ?: return
|
||||||
|
if (javaDocLocalInspection.myAdditionalJavadocTags.isEmpty()) {
|
||||||
|
javaDocLocalInspection.myAdditionalJavadocTags = tag
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val tags = Splitter.on(',').splitToList(javaDocLocalInspection.myAdditionalJavadocTags)
|
||||||
|
if (tags.contains(tag)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
javaDocLocalInspection.myAdditionalJavadocTags += "," + tag
|
||||||
|
profile.profileChanged()
|
||||||
|
profile.scopesChanged()
|
||||||
|
}
|
||||||
|
|
||||||
private fun getAllTools(project: Project, profile: InspectionProfileImpl): List<InspectionToolWrapper<*, *>> {
|
private fun getAllTools(project: Project, profile: InspectionProfileImpl): List<InspectionToolWrapper<*, *>> {
|
||||||
val method = InspectionProfileImpl::class.java.methods.first {
|
val method = InspectionProfileImpl::class.java.methods.first {
|
||||||
it.name == "getAllTools"
|
it.name == "getAllTools"
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.alibaba.p3c.idea.component
|
package com.alibaba.p3c.idea.component
|
||||||
|
|
||||||
|
import com.alibaba.p3c.idea.compatible.inspection.Inspections
|
||||||
import com.alibaba.p3c.idea.config.P3cConfig
|
import com.alibaba.p3c.idea.config.P3cConfig
|
||||||
import com.alibaba.p3c.idea.inspection.AliPmdInspectionInvoker
|
import com.alibaba.p3c.idea.inspection.AliPmdInspectionInvoker
|
||||||
import com.alibaba.p3c.idea.pmd.SourceCodeProcessor
|
import com.alibaba.p3c.idea.pmd.SourceCodeProcessor
|
||||||
@@ -30,8 +31,10 @@ import com.intellij.psi.PsiManager
|
|||||||
* @author caikang
|
* @author caikang
|
||||||
* @date 2016/12/13
|
* @date 2016/12/13
|
||||||
*/
|
*/
|
||||||
class AliProjectComponent(private val project: Project,
|
class AliProjectComponent(
|
||||||
val p3cConfig: P3cConfig) : AliBaseProjectComponent {
|
private val project: Project,
|
||||||
|
val p3cConfig: P3cConfig
|
||||||
|
) : AliBaseProjectComponent {
|
||||||
private val listener: VirtualFileListener
|
private val listener: VirtualFileListener
|
||||||
private val javaExtension = ".java"
|
private val javaExtension = ".java"
|
||||||
private val velocityExtension = ".vm"
|
private val velocityExtension = ".vm"
|
||||||
@@ -56,6 +59,7 @@ class AliProjectComponent(private val project: Project,
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun projectOpened() {
|
override fun projectOpened() {
|
||||||
|
Inspections.addCustomTag(project, "date")
|
||||||
VirtualFileManager.getInstance().addVirtualFileListener(listener)
|
VirtualFileManager.getInstance().addVirtualFileListener(listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
package com.alibaba.p3c.idea.inspection
|
package com.alibaba.p3c.idea.inspection
|
||||||
|
|
||||||
import com.alibaba.p3c.idea.inspection.AliLocalInspectionToolProvider.ShouldInspectChecker
|
import com.alibaba.p3c.idea.inspection.AliLocalInspectionToolProvider.ShouldInspectChecker
|
||||||
|
import com.alibaba.p3c.idea.util.NumberConstants
|
||||||
import com.alibaba.p3c.idea.util.QuickFixes
|
import com.alibaba.p3c.idea.util.QuickFixes
|
||||||
import com.intellij.codeHighlighting.HighlightDisplayLevel
|
import com.intellij.codeHighlighting.HighlightDisplayLevel
|
||||||
import com.intellij.codeInspection.InspectionManager
|
import com.intellij.codeInspection.InspectionManager
|
||||||
@@ -103,8 +104,8 @@ class AliPmdInspection(private val ruleName: String)
|
|||||||
|
|
||||||
var shortName = "Alibaba" + ruleName
|
var shortName = "Alibaba" + ruleName
|
||||||
val index = shortName.lastIndexOf("Rule")
|
val index = shortName.lastIndexOf("Rule")
|
||||||
if (index > com.alibaba.p3c.idea.NumberConstants.INDEX_0) {
|
if (index > NumberConstants.INDEX_0) {
|
||||||
shortName = shortName.substring(com.alibaba.p3c.idea.NumberConstants.INDEX_0, index)
|
shortName = shortName.substring(NumberConstants.INDEX_0, index)
|
||||||
}
|
}
|
||||||
return shortName
|
return shortName
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,7 @@ package com.alibaba.p3c.idea.inspection
|
|||||||
|
|
||||||
import com.alibaba.p3c.idea.config.P3cConfig
|
import com.alibaba.p3c.idea.config.P3cConfig
|
||||||
import com.alibaba.p3c.idea.util.HighlightDisplayLevels
|
import com.alibaba.p3c.idea.util.HighlightDisplayLevels
|
||||||
|
import com.alibaba.p3c.idea.util.NumberConstants
|
||||||
import com.alibaba.p3c.pmd.I18nResources
|
import com.alibaba.p3c.pmd.I18nResources
|
||||||
import com.alibaba.smartfox.idea.common.util.getService
|
import com.alibaba.smartfox.idea.common.util.getService
|
||||||
import com.google.common.base.Joiner
|
import com.google.common.base.Joiner
|
||||||
@@ -177,7 +178,7 @@ object RuleInspectionUtils {
|
|||||||
logger.info("start to find rule sets from jar " + url)
|
logger.info("start to find rule sets from jar " + url)
|
||||||
var path = URLDecoder.decode(url.path, StandardCharsets.UTF_8.name())
|
var path = URLDecoder.decode(url.path, StandardCharsets.UTF_8.name())
|
||||||
val index = path.lastIndexOf(URLUtil.JAR_SEPARATOR)
|
val index = path.lastIndexOf(URLUtil.JAR_SEPARATOR)
|
||||||
if (index > com.alibaba.p3c.idea.NumberConstants.INDEX_0) {
|
if (index > NumberConstants.INDEX_0) {
|
||||||
path = path.substring("file:".length, index)
|
path = path.substring("file:".length, index)
|
||||||
}
|
}
|
||||||
val jarFile = JarFile(path)
|
val jarFile = JarFile(path)
|
||||||
|
@@ -15,8 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.alibaba.p3c.idea.inspection.standalone
|
package com.alibaba.p3c.idea.inspection.standalone
|
||||||
|
|
||||||
import com.alibaba.p3c.idea.NumberConstants
|
import com.alibaba.p3c.idea.util.NumberConstants
|
||||||
import com.alibaba.p3c.idea.ObjectConstants
|
import com.alibaba.p3c.idea.util.ObjectConstants
|
||||||
import com.alibaba.p3c.idea.i18n.P3cBundle
|
import com.alibaba.p3c.idea.i18n.P3cBundle
|
||||||
import com.alibaba.p3c.idea.inspection.AliBaseInspection
|
import com.alibaba.p3c.idea.inspection.AliBaseInspection
|
||||||
import com.alibaba.p3c.idea.util.HighlightDisplayLevels
|
import com.alibaba.p3c.idea.util.HighlightDisplayLevels
|
||||||
|
@@ -13,17 +13,17 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.alibaba.p3c.idea;
|
package com.alibaba.p3c.idea.util
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author caikang
|
* @author caikang
|
||||||
* @date 2016/12/28
|
* @date 2016/12/28
|
||||||
*/
|
*/
|
||||||
public interface NumberConstants {
|
object NumberConstants {
|
||||||
int INTEGER_SIZE_OR_LENGTH_0 = 0;
|
val INTEGER_SIZE_OR_LENGTH_0 = 0
|
||||||
int INTEGER_SIZE_OR_LENGTH_1 = 1;
|
val INTEGER_SIZE_OR_LENGTH_1 = 1
|
||||||
int INTEGER_SIZE_OR_LENGTH_2 = 2;
|
val INTEGER_SIZE_OR_LENGTH_2 = 2
|
||||||
|
|
||||||
int INDEX_0 = 0;
|
val INDEX_0 = 0
|
||||||
int INDEX_1 = 1;
|
val INDEX_1 = 1
|
||||||
}
|
}
|
@@ -13,18 +13,18 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.alibaba.p3c.idea;
|
package com.alibaba.p3c.idea.util
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author caikang
|
* @author caikang
|
||||||
* @date 2016/12/28
|
* @date 2016/12/28
|
||||||
*/
|
*/
|
||||||
public interface ObjectConstants {
|
object ObjectConstants {
|
||||||
String METHOD_NAME_EQUALS = "equals";
|
val METHOD_NAME_EQUALS = "equals"
|
||||||
String METHOD_NAME_HASHCODE = "hashCode";
|
val METHOD_NAME_HASHCODE = "hashCode"
|
||||||
String METHOD_NAME_ADD = "add";
|
val METHOD_NAME_ADD = "add"
|
||||||
String METHOD_NAME_PUT = "put";
|
val METHOD_NAME_PUT = "put"
|
||||||
String CLASS_LITERAL = "class";
|
val CLASS_LITERAL = "class"
|
||||||
String INTERFACE_LITERAL = "interface";
|
val INTERFACE_LITERAL = "interface"
|
||||||
String ENUM_LITERAL = "enum";
|
val ENUM_LITERAL = "enum"
|
||||||
}
|
}
|
@@ -111,9 +111,9 @@ object ProblemsUtils {
|
|||||||
if (psiElement == null) {
|
if (psiElement == null) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
if (psiElement is PsiKeyword && psiElement.text != null && (com.alibaba.p3c.idea.ObjectConstants.CLASS_LITERAL == psiElement.text
|
if (psiElement is PsiKeyword && psiElement.text != null && (ObjectConstants.CLASS_LITERAL == psiElement.text
|
||||||
|| com.alibaba.p3c.idea.ObjectConstants.INTERFACE_LITERAL == psiElement.text
|
|| ObjectConstants.INTERFACE_LITERAL == psiElement.text
|
||||||
|| com.alibaba.p3c.idea.ObjectConstants.ENUM_LITERAL == psiElement.text) && psiElement.parent is PsiClass) {
|
|| ObjectConstants.ENUM_LITERAL == psiElement.text) && psiElement.parent is PsiClass) {
|
||||||
val parent = psiElement.parent as PsiClass
|
val parent = psiElement.parent as PsiClass
|
||||||
val identifier = parent.nameIdentifier
|
val identifier = parent.nameIdentifier
|
||||||
return identifier ?: psiElement
|
return identifier ?: psiElement
|
||||||
@@ -131,4 +131,4 @@ object ProblemsUtils {
|
|||||||
desc, ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
desc, ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||||
isOnTheFly, quickFix())
|
isOnTheFly, quickFix())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,13 +19,18 @@ package com.alibaba.p3c.pmd.lang.java.util;
|
|||||||
* @author caikang
|
* @author caikang
|
||||||
* @date 2016/12/28
|
* @date 2016/12/28
|
||||||
*/
|
*/
|
||||||
public interface NumberConstants {
|
public final class NumberConstants {
|
||||||
int INTEGER_SIZE_OR_LENGTH_0 = 0;
|
private NumberConstants() {
|
||||||
int INTEGER_SIZE_OR_LENGTH_1 = 1;
|
throw new AssertionError("com.alibaba.p3c.pmd.lang.java.util.NumberConstants"
|
||||||
int INTEGER_SIZE_OR_LENGTH_2 = 2;
|
+ " instances for you!");
|
||||||
int INTEGER_SIZE_OR_LENGTH_3 = 3;
|
}
|
||||||
|
|
||||||
int INDEX_0 = 0;
|
public static final int INTEGER_SIZE_OR_LENGTH_0 = 0;
|
||||||
int INDEX_1 = 1;
|
public static final int INTEGER_SIZE_OR_LENGTH_1 = 1;
|
||||||
int INDEX_2 = 2;
|
public static final int INTEGER_SIZE_OR_LENGTH_2 = 2;
|
||||||
|
public static final int INTEGER_SIZE_OR_LENGTH_3 = 3;
|
||||||
|
|
||||||
|
public static final int INDEX_0 = 0;
|
||||||
|
public static final int INDEX_1 = 1;
|
||||||
|
public static final int INDEX_2 = 2;
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,11 @@ package com.alibaba.p3c.pmd.lang.java.util;
|
|||||||
* @author caikang
|
* @author caikang
|
||||||
* @date 2017/03/28
|
* @date 2017/03/28
|
||||||
*/
|
*/
|
||||||
public interface StringAndCharConstants {
|
public final class StringAndCharConstants {
|
||||||
char DOT = '.';
|
private StringAndCharConstants(){
|
||||||
|
throw new AssertionError("com.alibaba.p3c.pmd.lang.java.util.StringAndCharConstants"
|
||||||
|
+ " instances for you!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final char DOT = '.';
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user