提交 6ab9ac35 编写于 作者: 骏烈

Redefine constant in class (NumberConstants ObjectConstants...)

上级 e7e6fcc8
......@@ -23,11 +23,16 @@ import com.intellij.openapi.util.IconLoader;
* @author caikang
* @date 2016/12/28
*/
public interface P3cIcons {
Icon ANALYSIS_ACTION = IconLoader.getIcon("/icons/ali-ide-run.png");
public final class P3cIcons {
private P3cIcons() {
throw new AssertionError("icons.P3cIcons"
+ " instances for you!");
}
Icon PROJECT_INSPECTION_ON = IconLoader.getIcon("/icons/qiyong.png");
Icon PROJECT_INSPECTION_OFF = IconLoader.getIcon("/icons/tingyong.png");
Icon LANGUAGE = IconLoader.getIcon("/icons/language.png");
Icon ALIBABA = IconLoader.getIcon("/icons/alibaba.png");
public static final Icon ANALYSIS_ACTION = IconLoader.getIcon("/icons/ali-ide-run.png");
public static final Icon PROJECT_INSPECTION_ON = IconLoader.getIcon("/icons/qiyong.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.i18n.P3cBundle
import com.alibaba.p3c.idea.inspection.AliBaseInspection
import com.alibaba.p3c.idea.util.NumberConstants
import com.beust.jcommander.internal.Lists
import com.intellij.analysis.AnalysisScope
import com.intellij.analysis.AnalysisUIOptions
......@@ -68,7 +69,7 @@ class AliInspectionAction : AnAction() {
if (psiFile != null) {
analysisScope = AnalysisScope(psiFile)
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))
projectDir = virtualFiles.any {
isBaseDir(it, project)
......
......@@ -15,9 +15,11 @@
*/
package com.alibaba.p3c.idea.compatible.inspection
import com.google.common.base.Splitter
import com.intellij.codeInspection.ex.InspectionProfileImpl
import com.intellij.codeInspection.ex.InspectionToolWrapper
import com.intellij.codeInspection.ex.ScopeToolState
import com.intellij.codeInspection.javaDoc.JavaDocLocalInspection
import com.intellij.openapi.project.Project
/**
......@@ -32,6 +34,24 @@ object Inspections {
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<*, *>> {
val method = InspectionProfileImpl::class.java.methods.first {
it.name == "getAllTools"
......
......@@ -15,6 +15,7 @@
*/
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.inspection.AliPmdInspectionInvoker
import com.alibaba.p3c.idea.pmd.SourceCodeProcessor
......@@ -30,8 +31,10 @@ import com.intellij.psi.PsiManager
* @author caikang
* @date 2016/12/13
*/
class AliProjectComponent(private val project: Project,
val p3cConfig: P3cConfig) : AliBaseProjectComponent {
class AliProjectComponent(
private val project: Project,
val p3cConfig: P3cConfig
) : AliBaseProjectComponent {
private val listener: VirtualFileListener
private val javaExtension = ".java"
private val velocityExtension = ".vm"
......@@ -56,6 +59,7 @@ class AliProjectComponent(private val project: Project,
}
override fun projectOpened() {
Inspections.addCustomTag(project, "date")
VirtualFileManager.getInstance().addVirtualFileListener(listener)
}
......
......@@ -16,6 +16,7 @@
package com.alibaba.p3c.idea.inspection
import com.alibaba.p3c.idea.inspection.AliLocalInspectionToolProvider.ShouldInspectChecker
import com.alibaba.p3c.idea.util.NumberConstants
import com.alibaba.p3c.idea.util.QuickFixes
import com.intellij.codeHighlighting.HighlightDisplayLevel
import com.intellij.codeInspection.InspectionManager
......@@ -103,8 +104,8 @@ class AliPmdInspection(private val ruleName: String)
var shortName = "Alibaba" + ruleName
val index = shortName.lastIndexOf("Rule")
if (index > com.alibaba.p3c.idea.NumberConstants.INDEX_0) {
shortName = shortName.substring(com.alibaba.p3c.idea.NumberConstants.INDEX_0, index)
if (index > NumberConstants.INDEX_0) {
shortName = shortName.substring(NumberConstants.INDEX_0, index)
}
return shortName
}
......
......@@ -17,6 +17,7 @@ package com.alibaba.p3c.idea.inspection
import com.alibaba.p3c.idea.config.P3cConfig
import com.alibaba.p3c.idea.util.HighlightDisplayLevels
import com.alibaba.p3c.idea.util.NumberConstants
import com.alibaba.p3c.pmd.I18nResources
import com.alibaba.smartfox.idea.common.util.getService
import com.google.common.base.Joiner
......@@ -177,7 +178,7 @@ object RuleInspectionUtils {
logger.info("start to find rule sets from jar " + url)
var path = URLDecoder.decode(url.path, StandardCharsets.UTF_8.name())
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)
}
val jarFile = JarFile(path)
......
......@@ -15,8 +15,8 @@
*/
package com.alibaba.p3c.idea.inspection.standalone
import com.alibaba.p3c.idea.NumberConstants
import com.alibaba.p3c.idea.ObjectConstants
import com.alibaba.p3c.idea.util.NumberConstants
import com.alibaba.p3c.idea.util.ObjectConstants
import com.alibaba.p3c.idea.i18n.P3cBundle
import com.alibaba.p3c.idea.inspection.AliBaseInspection
import com.alibaba.p3c.idea.util.HighlightDisplayLevels
......
......@@ -13,17 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.p3c.idea;
package com.alibaba.p3c.idea.util
/**
* @author caikang
* @date 2016/12/28
*/
public interface NumberConstants {
int INTEGER_SIZE_OR_LENGTH_0 = 0;
int INTEGER_SIZE_OR_LENGTH_1 = 1;
int INTEGER_SIZE_OR_LENGTH_2 = 2;
object NumberConstants {
val INTEGER_SIZE_OR_LENGTH_0 = 0
val INTEGER_SIZE_OR_LENGTH_1 = 1
val INTEGER_SIZE_OR_LENGTH_2 = 2
int INDEX_0 = 0;
int INDEX_1 = 1;
val INDEX_0 = 0
val INDEX_1 = 1
}
......@@ -13,18 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.p3c.idea;
package com.alibaba.p3c.idea.util
/**
* @author caikang
* @date 2016/12/28
*/
public interface ObjectConstants {
String METHOD_NAME_EQUALS = "equals";
String METHOD_NAME_HASHCODE = "hashCode";
String METHOD_NAME_ADD = "add";
String METHOD_NAME_PUT = "put";
String CLASS_LITERAL = "class";
String INTERFACE_LITERAL = "interface";
String ENUM_LITERAL = "enum";
object ObjectConstants {
val METHOD_NAME_EQUALS = "equals"
val METHOD_NAME_HASHCODE = "hashCode"
val METHOD_NAME_ADD = "add"
val METHOD_NAME_PUT = "put"
val CLASS_LITERAL = "class"
val INTERFACE_LITERAL = "interface"
val ENUM_LITERAL = "enum"
}
......@@ -111,9 +111,9 @@ object ProblemsUtils {
if (psiElement == null) {
return null
}
if (psiElement is PsiKeyword && psiElement.text != null && (com.alibaba.p3c.idea.ObjectConstants.CLASS_LITERAL == psiElement.text
|| com.alibaba.p3c.idea.ObjectConstants.INTERFACE_LITERAL == psiElement.text
|| com.alibaba.p3c.idea.ObjectConstants.ENUM_LITERAL == psiElement.text) && psiElement.parent is PsiClass) {
if (psiElement is PsiKeyword && psiElement.text != null && (ObjectConstants.CLASS_LITERAL == psiElement.text
|| ObjectConstants.INTERFACE_LITERAL == psiElement.text
|| ObjectConstants.ENUM_LITERAL == psiElement.text) && psiElement.parent is PsiClass) {
val parent = psiElement.parent as PsiClass
val identifier = parent.nameIdentifier
return identifier ?: psiElement
......@@ -131,4 +131,4 @@ object ProblemsUtils {
desc, ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
isOnTheFly, quickFix())
}
}
\ No newline at end of file
}
......@@ -19,13 +19,18 @@ package com.alibaba.p3c.pmd.lang.java.util;
* @author caikang
* @date 2016/12/28
*/
public interface NumberConstants {
int INTEGER_SIZE_OR_LENGTH_0 = 0;
int INTEGER_SIZE_OR_LENGTH_1 = 1;
int INTEGER_SIZE_OR_LENGTH_2 = 2;
int INTEGER_SIZE_OR_LENGTH_3 = 3;
public final class NumberConstants {
private NumberConstants() {
throw new AssertionError("com.alibaba.p3c.pmd.lang.java.util.NumberConstants"
+ " instances for you!");
}
int INDEX_0 = 0;
int INDEX_1 = 1;
int INDEX_2 = 2;
public static final int INTEGER_SIZE_OR_LENGTH_0 = 0;
public static final int INTEGER_SIZE_OR_LENGTH_1 = 1;
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
* @date 2017/03/28
*/
public interface StringAndCharConstants {
char DOT = '.';
public final class StringAndCharConstants {
private StringAndCharConstants(){
throw new AssertionError("com.alibaba.p3c.pmd.lang.java.util.StringAndCharConstants"
+ " instances for you!");
}
public static final char DOT = '.';
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册